From 303c9d8e40266e787cde869776af94862d23fd14 Mon Sep 17 00:00:00 2001 From: Nuvole Date: Thu, 14 Nov 2024 10:35:33 +0800 Subject: [PATCH] feat: support for custom stdin --- joj3_config_generator/models/task.py | 2 + joj3_config_generator/processers/task.py | 20 +++++- tests/convert/basic/task.json | 82 ++++++++++++------------ tests/convert/basic/task.toml | 37 +++++------ 4 files changed, 80 insertions(+), 61 deletions(-) diff --git a/joj3_config_generator/models/task.py b/joj3_config_generator/models/task.py index 969237e..0dccb01 100644 --- a/joj3_config_generator/models/task.py +++ b/joj3_config_generator/models/task.py @@ -50,6 +50,8 @@ class Stage(BaseModel): name: Optional[str] = None # Stage name command: Optional[str] = None # Command to run files: Optional[Files] = None + in_: Optional[str] = Field(None, alias="in") + out_: Optional[str] = Field(None, alias="out") score: Optional[int] = 0 parsers: Optional[list[str]] = [] # list of parsers limit: Optional[Limit] = Limit() diff --git a/joj3_config_generator/processers/task.py b/joj3_config_generator/processers/task.py index 55357be..0ca194d 100644 --- a/joj3_config_generator/processers/task.py +++ b/joj3_config_generator/processers/task.py @@ -234,12 +234,28 @@ def fix_diff( if case_stage.limit and case_stage.limit.mem is not None else 0 ) + command = ( + case_stage.command + if case_stage.command is not None + else None + ) + stdin = ( + case_stage.in_ + if case_stage.in_ is not None + else f"{case}.in" + ) + stdout = ( + case_stage.out_ + if case_stage.out_ is not None + else f"{case}.out" + ) stage_cases.append( result.OptionalCmd( stdin=result.CmdFile( - src=f"/home/tt/.config/joj/{task_conf.task.type_}/{case}.in" + src=f"/home/tt/.config/joj/{task_conf.task.type_}/{stdin}" ), + args=shlex.split(case_stage.command) if command is not None else None, cpu_limit=cpu_limit, clock_limit=clock_limit, memory_limit=memory_limit, @@ -260,7 +276,7 @@ def fix_diff( { "score": diff_output.score, "fileName": "stdout", - "answerPath": f"/home/tt/.config/joj/{task_conf.task.type_}/{case}.out", + "answerPath": f"/home/tt/.config/joj/{task_conf.task.type_}/{stdout}", "forceQuitOnDiff": diff_output.forcequit, "alwaysHide": diff_output.hide, "compareSpace": not diff_output.ignorespaces, diff --git a/tests/convert/basic/task.json b/tests/convert/basic/task.json index 9fba48c..6bd740b 100644 --- a/tests/convert/basic/task.json +++ b/tests/convert/basic/task.json @@ -145,9 +145,9 @@ ], "copyOutCached": [ "h6/build/ex3", - "h6/build/asan", - "h6/build/ubsan", - "h6/build/msan", + "h6/build/ex3-asan", + "h6/build/ex3-ubsan", + "h6/build/ex3-msan", "h6/build/compile_commands.json" ], "copyOutMax": 0, @@ -248,9 +248,9 @@ }, "copyInCached": { "h6/build/ex3": "h6/build/ex3", - "h6/build/asan": "h6/build/asan", - "h6/build/ubsan": "h6/build/ubsan", - "h6/build/msan": "h6/build/msan", + "h6/build/ex3-asan": "h6/build/ex3-asan", + "h6/build/ex3-ubsan": "h6/build/ex3-ubsan", + "h6/build/ex3-msan": "h6/build/ex3-msan", "h6/build/compile_commands.json": "h6/build/compile_commands.json" }, "copyInDir": ".", @@ -369,9 +369,9 @@ }, "copyInCached": { "h6/build/ex3": "h6/build/ex3", - "h6/build/asan": "h6/build/asan", - "h6/build/ubsan": "h6/build/ubsan", - "h6/build/msan": "h6/build/msan", + "h6/build/ex3-asan": "h6/build/ex3-asan", + "h6/build/ex3-ubsan": "h6/build/ex3-ubsan", + "h6/build/ex3-msan": "h6/build/ex3-msan", "h6/build/compile_commands.json": "h6/build/compile_commands.json" }, "copyInDir": ".", @@ -509,9 +509,9 @@ "copyIn": {}, "copyInCached": { "h6/build/ex3": "h6/build/ex3", - "h6/build/asan": "h6/build/asan", - "h6/build/ubsan": "h6/build/ubsan", - "h6/build/msan": "h6/build/msan", + "h6/build/ex3-asan": "h6/build/ex3-asan", + "h6/build/ex3-ubsan": "h6/build/ex3-ubsan", + "h6/build/ex3-msan": "h6/build/ex3-msan", "h6/build/compile_commands.json": "h6/build/compile_commands.json" }, "copyInDir": ".", @@ -625,9 +625,9 @@ "copyIn": {}, "copyInCached": { "h6/build/ex3": "h6/build/ex3", - "h6/build/asan": "h6/build/asan", - "h6/build/ubsan": "h6/build/ubsan", - "h6/build/msan": "h6/build/msan", + "h6/build/ex3-asan": "h6/build/ex3-asan", + "h6/build/ex3-ubsan": "h6/build/ex3-ubsan", + "h6/build/ex3-msan": "h6/build/ex3-msan", "h6/build/compile_commands.json": "h6/build/compile_commands.json" }, "copyInDir": ".", @@ -705,7 +705,7 @@ "with": { "default": { "args": [ - "./h6/build/asan", + "./h6/build/ex3-asan", "-a" ], "env": [ @@ -743,9 +743,9 @@ "copyIn": {}, "copyInCached": { "h6/build/ex3": "h6/build/ex3", - "h6/build/asan": "h6/build/asan", - "h6/build/ubsan": "h6/build/ubsan", - "h6/build/msan": "h6/build/msan", + "h6/build/ex3-asan": "h6/build/ex3-asan", + "h6/build/ex3-ubsan": "h6/build/ex3-ubsan", + "h6/build/ex3-msan": "h6/build/ex3-msan", "h6/build/compile_commands.json": "h6/build/compile_commands.json" }, "copyInDir": ".", @@ -795,7 +795,7 @@ "with": { "default": { "args": [ - "./h6/build/msan", + "./h6/build/ex3-msan", "-a" ], "env": [ @@ -833,9 +833,9 @@ "copyIn": {}, "copyInCached": { "h6/build/ex3": "h6/build/ex3", - "h6/build/asan": "h6/build/asan", - "h6/build/ubsan": "h6/build/ubsan", - "h6/build/msan": "h6/build/msan", + "h6/build/ex3-asan": "h6/build/ex3-asan", + "h6/build/ex3-ubsan": "h6/build/ex3-ubsan", + "h6/build/ex3-msan": "h6/build/ex3-msan", "h6/build/compile_commands.json": "h6/build/compile_commands.json" }, "copyInDir": ".", @@ -885,7 +885,7 @@ "with": { "default": { "args": [ - "./h6/build/ubsan", + "./h6/build/ex3-ubsan", "-a" ], "env": [ @@ -923,9 +923,9 @@ "copyIn": {}, "copyInCached": { "h6/build/ex3": "h6/build/ex3", - "h6/build/asan": "h6/build/asan", - "h6/build/ubsan": "h6/build/ubsan", - "h6/build/msan": "h6/build/msan", + "h6/build/ex3-asan": "h6/build/ex3-asan", + "h6/build/ex3-ubsan": "h6/build/ex3-ubsan", + "h6/build/ex3-msan": "h6/build/ex3-msan", "h6/build/compile_commands.json": "h6/build/compile_commands.json" }, "copyInDir": ".", @@ -1012,9 +1012,9 @@ "copyIn": {}, "copyInCached": { "h6/build/ex3": "h6/build/ex3", - "h6/build/asan": "h6/build/asan", - "h6/build/ubsan": "h6/build/ubsan", - "h6/build/msan": "h6/build/msan", + "h6/build/ex3-asan": "h6/build/ex3-asan", + "h6/build/ex3-ubsan": "h6/build/ex3-ubsan", + "h6/build/ex3-msan": "h6/build/ex3-msan", "h6/build/compile_commands.json": "h6/build/compile_commands.json" }, "copyInDir": ".", @@ -1040,7 +1040,7 @@ "PATH=/usr/bin:/bin:/usr/local/bin" ], "stdin": { - "src": "/home/tt/.config/joj/tests/homework/h6/e3/case0.in", + "src": "/home/tt/.config/joj/tests/homework/h6/e3/paragraph.in", "max": 419430400, "streamIn": true, "streamOut": true, @@ -1207,7 +1207,7 @@ { "outputs": [ { - "score": 0, + "score": 5, "fileName": "stdout", "answerPath": "/home/tt/.config/joj/tests/homework/h6/e3/case0.out", "forceQuitOnDiff": true, @@ -1219,7 +1219,7 @@ { "outputs": [ { - "score": 0, + "score": 5, "fileName": "stdout", "answerPath": "/home/tt/.config/joj/tests/homework/h6/e3/case1.out", "forceQuitOnDiff": true, @@ -1231,7 +1231,7 @@ { "outputs": [ { - "score": 0, + "score": 5, "fileName": "stdout", "answerPath": "/home/tt/.config/joj/tests/homework/h6/e3/case2.out", "forceQuitOnDiff": true, @@ -1243,7 +1243,7 @@ { "outputs": [ { - "score": 0, + "score": 5, "fileName": "stdout", "answerPath": "/home/tt/.config/joj/tests/homework/h6/e3/case3.out", "forceQuitOnDiff": true, @@ -1255,7 +1255,7 @@ { "outputs": [ { - "score": 0, + "score": 10, "fileName": "stdout", "answerPath": "/home/tt/.config/joj/tests/homework/h6/e3/case4.out", "forceQuitOnDiff": true, @@ -1267,7 +1267,7 @@ { "outputs": [ { - "score": 0, + "score": 10, "fileName": "stdout", "answerPath": "/home/tt/.config/joj/tests/homework/h6/e3/case5.out", "forceQuitOnDiff": true, @@ -1279,7 +1279,7 @@ { "outputs": [ { - "score": 0, + "score": 15, "fileName": "stdout", "answerPath": "/home/tt/.config/joj/tests/homework/h6/e3/case6.out", "forceQuitOnDiff": true, @@ -1291,7 +1291,7 @@ { "outputs": [ { - "score": 0, + "score": 15, "fileName": "stdout", "answerPath": "/home/tt/.config/joj/tests/homework/h6/e3/case7.out", "forceQuitOnDiff": true, @@ -1303,7 +1303,7 @@ { "outputs": [ { - "score": 0, + "score": 15, "fileName": "stdout", "answerPath": "/home/tt/.config/joj/tests/homework/h6/e3/case8.out", "forceQuitOnDiff": true, @@ -1315,7 +1315,7 @@ { "outputs": [ { - "score": 0, + "score": 15, "fileName": "stdout", "answerPath": "/home/tt/.config/joj/tests/homework/h6/e3/case9.out", "forceQuitOnDiff": true, diff --git a/tests/convert/basic/task.toml b/tests/convert/basic/task.toml index 5fa7216..e7b5d38 100644 --- a/tests/convert/basic/task.toml +++ b/tests/convert/basic/task.toml @@ -9,7 +9,7 @@ release.stages = [ "compile" ] name = "Compilation" command = "./tools/compile" # eg. script running cmake commands files.import = [ "tools/compile" ] -files.export = [ "h6/build/ex3", "h6/build/asan", "h6/build/ubsan", "h6/build/msan", "h6/build/compile_commands.json" ] +files.export = [ "h6/build/ex3", "h6/build/ex3-asan", "h6/build/ex3-ubsan", "h6/build/ex3-msan", "h6/build/compile_commands.json" ] # compile parsers parsers = [ "result-detail", "dummy", "result-status" ] @@ -80,8 +80,8 @@ result-detail.mem = false [[stages]] name = "[run] address sanitizer" group = "run" -command="./h6/build/asan -a" -files.import = [ "h6/build/asan" ] +command="./h6/build/ex3-asan -a" +files.import = [ "h6/build/ex3-asan" ] parsers = [ "result-status", "result-detail" ] result-status.score = 1 @@ -92,8 +92,8 @@ result-detail.stderr = true [[stages]] name = "[run] memory sanitizer" group = "run" -command="./h6/build/msan -a" -files.import = [ "h6/build/msan" ] +command="./h6/build/ex3-msan -a" +files.import = [ "h6/build/ex3-msan" ] parsers = [ "result-status", "result-detail" ] result-status.score = 1 @@ -103,8 +103,8 @@ result-detail.stderr = true [[stages]] name = "[run] undefined behavior sanitizer" -command="./h6/build/ubsan -a" -files.import = [ "h6/build/ubsan" ] +command="./h6/build/ex3-ubsan -a" +files.import = [ "h6/build/ex3-ubsan" ] parsers = [ "result-status", "result-detail" ] result-status.score = 1 @@ -124,53 +124,54 @@ result-detail.exitstatus = true result-detail.stderr = true # will be removed as long as the name is fixed -case0.score = 10 +case0.in = "paragraph.in" +case0.command = "Manuel Charlemagne" +case0.diff.output.score = 5 case0.limit.cpu = 30 case0.limit.mem = 32 case0.limit.stdout = 8 -case0.command = "Manuel Charlemagne" -case1.score = 10 +case1.diff.output.score = 5 case1.limit.cpu = 30 case1.limit.mem = 32 case1.limit.stdout = 8 -case2.score = 10 +case2.diff.output.score = 5 case2.limit.cpu = 30 case2.limit.mem = 32 case2.limit.stdout = 8 -case3.score = 10 +case3.diff.output.score = 5 case3.limit.cpu = 30 case3.limit.mem = 32 case3.limit.stdout = 8 -case4.score = 10 +case4.diff.output.score = 10 case4.limit.cpu = 30 case4.limit.mem = 32 case4.limit.stdout = 8 -case5.score = 10 +case5.diff.output.score = 10 case5.limit.cpu = 30 case5.limit.mem = 32 case5.limit.stdout = 8 -case6.score = 10 +case6.diff.output.score = 15 case6.limit.cpu = 30 case6.limit.mem = 32 case6.limit.stdout = 8 -case7.score = 10 +case7.diff.output.score = 15 case7.limit.cpu = 30 case7.limit.mem = 32 case7.limit.stdout = 8 -case8.score = 10 +case8.diff.output.score = 15 case8.limit.cpu = 30 case8.limit.mem = 32 case8.limit.stdout = 8 -case9.score = 10 +case9.diff.output.score = 15 case9.limit.cpu = 30 case9.limit.mem = 32 case9.limit.stdout = 8 \ No newline at end of file