From 2483a3a1b01390925a45d544653bb9b5c94604cd Mon Sep 17 00:00:00 2001 From: adamdebek Date: Wed, 12 Jul 2023 13:09:02 +0200 Subject: [PATCH] lsb-vsx: overall clean up --- lsb_vsx_posix/Makefile | 2 +- lsb_vsx_posix/lsb_vsx_posix.c | 21 ++++++++++---------- lsb_vsx_posix/lsb_vsx_posix.py | 36 ++++++++++++---------------------- trunner/harnesses/factory.py | 34 -------------------------------- 4 files changed, 25 insertions(+), 68 deletions(-) delete mode 100644 trunner/harnesses/factory.py diff --git a/lsb_vsx_posix/Makefile b/lsb_vsx_posix/Makefile index 13a3b1e1..24f5bbd3 100644 --- a/lsb_vsx_posix/Makefile +++ b/lsb_vsx_posix/Makefile @@ -1,4 +1,4 @@ NAME := lsb_vsx_posix LOCAL_SRCS := lsb_vsx_posix.c -include $(binary.mk) \ No newline at end of file +include $(binary.mk) diff --git a/lsb_vsx_posix/lsb_vsx_posix.c b/lsb_vsx_posix/lsb_vsx_posix.c index 9f59c452..a9a79248 100644 --- a/lsb_vsx_posix/lsb_vsx_posix.c +++ b/lsb_vsx_posix/lsb_vsx_posix.c @@ -5,6 +5,7 @@ #include #include #include +#include int main(int argc, char **argv) { @@ -12,7 +13,6 @@ int main(int argc, char **argv) const char *cmd_single_test = "/usr/test/lsb_vsx_posix/files/bin/tcc -p -e -s /usr/test/lsb_vsx_posix/files/test_sets/scen_single.exec -j -"; const char *cmd_clean = "/usr/test/lsb_vsx_posix/files/bin/tcc -p -c -s /usr/test/lsb_vsx_posix/files/test_sets/scen_single.exec"; const char *cwd = "/usr/test/lsb_vsx_posix/files/test_sets"; - const char *resultPath = "/usr/test/lsb_vsx_posix/files/test_sets/results"; char *line = NULL; char total[40]; @@ -27,7 +27,7 @@ int main(int argc, char **argv) return 1; } - /* Set necessary enviroment variables */ + /* Set necessary environment variables */ if (setenv("TET_ROOT", "/usr/test/lsb_vsx_posix/files", 0) != 0) { perror("setenv() - setting \"TET_ROOT\" failed"); return 1; @@ -42,17 +42,17 @@ int main(int argc, char **argv) if (argc == 2) { /* File containing all tests */ all_tests_f = fopen("/usr/test/lsb_vsx_posix/files/test_sets/scen.exec", "r"); - if (all_tests_f == -1) { + if (all_tests_f == NULL) { perror("fopen"); exit(EXIT_FAILURE); } /* File which we gonna pass to tcc, this file will contain 2 required lines and one test name */ - single_test_f = open("/usr/test/lsb_vsx_posix/files/test_sets/scen_single.exec", O_WRONLY | O_CREAT | O_TRUNC); - if (single_test_f == NULL) { - perror("fopen"); + single_test_f = open("/usr/test/lsb_vsx_posix/files/test_sets/scen_single.exec", O_WRONLY | O_CREAT | O_TRUNC, S_IFREG); + if (single_test_f == -1) { + perror("open"); exit(EXIT_FAILURE); } - /* append "all" to start of scenario file in order to follow file format*/ + /* append "all" to start of scenario file in order to follow file format */ write(single_test_f, "all\n", 5); while ((nread = getline(&line, &len, all_tests_f)) != -1) { @@ -61,7 +61,8 @@ int main(int argc, char **argv) * the line we need will reside in buffer "total". */ if (strstr(line, "total tests in") != NULL) { - strncpy(total, line, 40); + strncpy(total, line, 39); + total[39] = '\0'; } if (strstr(line, argv[1]) != NULL) { /* Write second line */ @@ -69,7 +70,7 @@ int main(int argc, char **argv) /* Write test name */ write(single_test_f, line, nread); - /*Test found, everything we need written, so close and clean */ + /* Test found, everything we need written, so close and clean */ fclose(all_tests_f); close(single_test_f); free(line); @@ -101,4 +102,4 @@ int main(int argc, char **argv) return 1; } } -} \ No newline at end of file +} diff --git a/lsb_vsx_posix/lsb_vsx_posix.py b/lsb_vsx_posix/lsb_vsx_posix.py index 035dd8fd..18b8bfcf 100644 --- a/lsb_vsx_posix/lsb_vsx_posix.py +++ b/lsb_vsx_posix/lsb_vsx_posix.py @@ -1,17 +1,9 @@ -# -# Phoenix-RTOS test runner -# -# The harness for the LSB_VSX-2.0-1 (POSIX) Test Suite -# -# Copyright 2022 Phoenix Systems -# Authors: Adam Dębek -# - +from trunner.ctx import TestContext from trunner.dut import Dut from trunner.types import TestResult, Result, Status -def harness(dut: Dut): +def harness(dut: Dut, ctx: TestContext): test_results = [] result = None msg = [] @@ -19,8 +11,7 @@ def harness(dut: Dut): test_status = Status.OK NAME = r'(.+?)Execute(.+?)T\.(?P.+?)\r+\n' - PROMPT = r'(\r+)\x1b\[0J' + r'\(psh\)% ' - #RESULT = r"(.+?)(?PPASS|UNRESOLVED|FAIL)\r+\n" no status unresolved for now + # RESULT = r"(.+?)(?PPASS|UNRESOLVED|FAIL)\r+\n" no status unresolved for now RESULT = r"(.+?)(?PPASS|FAIL)\r+\n" FINAL = r"(.+?)TCC End\r+\n" MESSAGE = r"(?P.*?)\r+\n" @@ -35,7 +26,7 @@ def harness(dut: Dut): MESSAGE ], timeout=300) parsed = dut.match.groupdict() - + if idx == 0: test_name = parsed["name"] elif idx == 1: @@ -44,22 +35,22 @@ def harness(dut: Dut): break elif idx == 3: line = parsed["line"] - #Get rid of unnecessary messages - if(line.find("IC") != -1 or line.find("TP") != -1 or line.find("TC") != -1 or line.find("Execute") != -1): + # Get rid of unnecessary messages + if (line.find("IC") != -1 or line.find("TP") != -1 or line.find("TC") != -1 or line.find("Execute") != -1): continue else: line = line[line.find("|") + 1:] line = line[line.find("|") + 1:] msg.append('\t\t' + line + '\n') - #Tests with these problems treat as fails + # Tests with these problems treat as fails if (line.find("can't acquire exclusive lock") != -1) or (line.find("can't exec") != -1): test_status = Status.FAIL result = Result(name=test_name, status=Status.FAIL) result.status = Status.FAIL - if (line.find("can't acquire exclusive lock") != -1): + if (line.find("can't acquire exclusive lock") != -1): result.msg = '\t\t' + "can't acquire exclusive lock\n" - elif(line.find("can't exec") != -1): + elif (line.find("can't exec") != -1): result.msg = '\t\t' + "compilation error\n" test_results.append(result) @@ -71,12 +62,11 @@ def harness(dut: Dut): test_status = Status.FAIL result.msg = "\n".join(msg) msg = [] - #UNRESOLVED status not added yet - #elif msg and result.status == Status.UNRESOLVED: + # UNRESOLVED status not added yet + # elif msg and result.status == Status.UNRESOLVED: # result.status = Status.UNRESOLVED - + test_results.append(result) result = None - - return TestResult(msg=Result.format_output(test_results), status=test_status) + return TestResult(msg=Result.format_output(test_results, ctx), status=test_status) diff --git a/trunner/harnesses/factory.py b/trunner/harnesses/factory.py deleted file mode 100644 index 4b63666c..00000000 --- a/trunner/harnesses/factory.py +++ /dev/null @@ -1,34 +0,0 @@ -# -# Phoenix-RTOS test runner -# -# Harnesses for test frameworks supported in the Test Runner - factory -# -# Copyright 2022 Phoenix Systems -# Authors: Damian Loewnau, Jakub Sarzyński, Piotr Nieciecki -# - -from .unity import UnitTestHarness -from .busybox import BusyboxTestHarness -from .mbedtls import MbedtlsTestHarness -from .micropython import MicropythonStandardHarness -from .micropython import MicropythonReplHarness -from .lsb_vsx_posix import LsbVsxPosixTestHarness - - -class TestHarnessFactory: - @staticmethod - def create(test_type): - if test_type == 'unit': - return UnitTestHarness() - if test_type == 'busybox': - return BusyboxTestHarness() - if test_type == 'mbedtls': - return MbedtlsTestHarness() - if test_type == 'micropython_std': - return MicropythonStandardHarness() - if test_type == 'micropython_repl': - return MicropythonReplHarness() - if test_type == 'lsb_vsx_posix': - return LsbVsxPosixTestHarness() - else: - raise ValueError(f"Unknown test type: {test_type}")