From c92733a7ee904dc8dde588ac9dc3a1a8d85f62da Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Fri, 17 Nov 2023 10:14:58 +0100 Subject: [PATCH] Pass input test name to inwer (#22) * Pass input test's name to inwer * Fix tests * Add inwer tests for passing test name as an argument * Check if 'in_file_name' exists in environ --- sio/executors/inwer.py | 5 +++++ sio/workers/test/sources/inwer_argument.c | 14 ++++++++++++++ sio/workers/test/test_executors.py | 3 +++ 3 files changed, 22 insertions(+) create mode 100644 sio/workers/test/sources/inwer_argument.c diff --git a/sio/executors/inwer.py b/sio/executors/inwer.py index 9ed90ae..a163ac0 100644 --- a/sio/executors/inwer.py +++ b/sio/executors/inwer.py @@ -33,6 +33,8 @@ def _run_in_executor(environ, command, executor, **kwargs): def _run_inwer(environ, use_sandboxes=False): command = [tempcwd('inwer')] + if 'in_file_name' in environ: + command.append(environ['in_file_name']) if use_sandboxes: executor = SupervisedExecutor() else: @@ -49,6 +51,9 @@ def run(environ): ``in_file``: the file redirected to the program's stdin + ``in_file_name``: the name of the input file. It's passed to inwer as + the second argument. + ``use_sandboxes``: if this key equals ``True``, the program is executed in the SupervisedExecutor, otherwise the UnsafeExecutor is used diff --git a/sio/workers/test/sources/inwer_argument.c b/sio/workers/test/sources/inwer_argument.c new file mode 100644 index 0000000..6283f69 --- /dev/null +++ b/sio/workers/test/sources/inwer_argument.c @@ -0,0 +1,14 @@ +#include + +int main(int argc, char *argv[]) { + if (argc != 2) { + printf("WRONG\nWrong number of arguments"); + return 1; + } + if (strcmp(argv[1], "inwer_ok") != 0) { + printf("WRONG\nWrong test name"); + return 1; + } + printf("OK\n"); + return 0; +} diff --git a/sio/workers/test/test_executors.py b/sio/workers/test/test_executors.py index 233a20f..1a43de7 100644 --- a/sio/workers/test/test_executors.py +++ b/sio/workers/test/test_executors.py @@ -436,6 +436,8 @@ def inner(env): yield '/inwer_big_output.c', '/inwer_ok', use_sandboxes, check_inwer_big_output( use_sandboxes ) + yield '/inwer_argument.c', '/inwer_ok', use_sandboxes, check_inwer_ok + yield '/inwer_argument.c', '/inwer_wrong', use_sandboxes, check_inwer_wrong @pytest.mark.parametrize( @@ -449,6 +451,7 @@ def test_inwer(inwer, in_file, use_sandboxes, callback): with TemporaryCwd(): env = { 'in_file': in_file, + 'in_file_name': os.path.basename(in_file), 'exe_file': inwer_bin, 'use_sandboxes': use_sandboxes, 'inwer_output_limit': SMALL_OUTPUT_LIMIT,