From 3e687e5ead7ffced6e37aa33c3f292452b4e7971 Mon Sep 17 00:00:00 2001 From: Robert Tice Date: Fri, 17 May 2019 15:17:17 -0400 Subject: [PATCH 1/3] Refactoring some code. --- infrastructure/container_payload/run.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/infrastructure/container_payload/run.py b/infrastructure/container_payload/run.py index c356030..82784c6 100644 --- a/infrastructure/container_payload/run.py +++ b/infrastructure/container_payload/run.py @@ -151,26 +151,23 @@ def safe_run(workdir, mode, lab): def json_print(pdict): print(json.dumps(pdict)) - def print_stdout(msg, lab_ref=None): + def print_generic(msg, tag, lab_ref): obj = {"msg": msg} if lab_ref: obj["lab_ref"] = lab_ref - json_print({"stdout": obj}) + json_print({tag: obj}) + + def print_stdout(msg, lab_ref=None): + print_generic(msg, "stdout", lab_ref) def print_stderr(msg, lab_ref=None): - obj = {"msg": msg} - if lab_ref: - obj["lab_ref"] = lab_ref - json_print({"stderr": obj}) + print_generic(msg, "stderr", lab_ref) def print_lab(success, cases): json_print({"lab_output": {"success": success, "test_cases": cases}}) def print_console(cmd_list, lab_ref=None): - obj = {"msg": " ".join(cmd_list).replace(workdir, '.')} - if lab_ref: - obj["lab_ref"] = lab_ref - json_print({"console": obj}) + print_generic(" ".join(cmd_list).replace(workdir, '.'), "console", lab_ref) def c(cl=[], lab_ref=None): """Aux procedure, run the given command line and output to stdout. From e1c4f79fda162a80ba58736d407e16d822e7bf19 Mon Sep 17 00:00:00 2001 From: Robert Tice Date: Fri, 31 May 2019 11:33:11 -0400 Subject: [PATCH 2/3] Fixing regex in run.py that stripped initial space from expected output. --- infrastructure/container_payload/run.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/infrastructure/container_payload/run.py b/infrastructure/container_payload/run.py index 82784c6..b38aeea 100644 --- a/infrastructure/container_payload/run.py +++ b/infrastructure/container_payload/run.py @@ -14,6 +14,7 @@ import codecs import json import glob import time +import string import sys import subprocess import traceback @@ -27,7 +28,7 @@ CLI_FILE = "cli.txt" LAB_IO_FILE = "lab_io.txt" -LAB_IO_REGEX = re.compile("(in|out) *(\d+): *(.*)") +LAB_IO_REGEX = re.compile("(in|out) *(\d+): (.*)") COMMON_ADC = """ @@ -324,11 +325,18 @@ def safe_run(workdir, mode, lab): errno, stdout, retcode = run(main, workdir, test["in"].split(), index) test["actual"] = " ".join(stdout).replace('\n', '').replace('\r', '') - if retcode != 0 or test["actual"] != test["out"]: + if retcode is not None and retcode != 0: + print_stderr("Process returned non-zero result: {}".format(retcode)) test["status"] = "Failed" success = False else: - test["status"] = "Success" + + if test["actual"] == test["out"]: + test["status"] = "Success" + else: + print_stderr("Program output ({}) does not match expected output ({}).".format(' '.join(str(ord(c)) for c in test["actual"]), ' '.join(str(ord(c)) for c in test["out"]))) + test["status"] = "Failed" + success = False else: print_stderr("Malformed test IO sequence in test case #{}. Please report this issue on https://github.com/AdaCore/learn/issues".format(index)) sys.exit(1) From d9aed1e0b3e72b78ef67d5c1c1ba083430d087f3 Mon Sep 17 00:00:00 2001 From: Robert Tice Date: Fri, 31 May 2019 11:51:14 -0400 Subject: [PATCH 3/3] Removing extraneous import. --- infrastructure/container_payload/run.py | 1 - 1 file changed, 1 deletion(-) diff --git a/infrastructure/container_payload/run.py b/infrastructure/container_payload/run.py index b38aeea..571e6a0 100644 --- a/infrastructure/container_payload/run.py +++ b/infrastructure/container_payload/run.py @@ -14,7 +14,6 @@ import codecs import json import glob import time -import string import sys import subprocess import traceback