From 149d536cf11d536c45c0322123cc896f625af636 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Fri, 12 May 2023 20:43:58 +0200 Subject: [PATCH] Rename harness-tests.py to run-tests.py and fix boolean return --- .github/workflows/build.yml | 2 +- tests/DumpulatorTests/README.md | 2 +- tests/DumpulatorTests/Tests/HandleTest.cpp | 7 ++++--- tests/{harness-tests.py => run-tests.py} | 11 +++++++---- 4 files changed, 13 insertions(+), 9 deletions(-) rename tests/{harness-tests.py => run-tests.py} (93%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cda7b3b..b1e4fec 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -70,7 +70,7 @@ jobs: - name: 'Test: DumpulatorTests' run: | cd tests - python harness-tests.py + python run-tests.py - name: 'Test: ExceptionTest_x64' run: | diff --git a/tests/DumpulatorTests/README.md b/tests/DumpulatorTests/README.md index 0594321..803fd87 100644 --- a/tests/DumpulatorTests/README.md +++ b/tests/DumpulatorTests/README.md @@ -14,7 +14,7 @@ The harness dumps were created as follows: ## Adding a new test -Add a new `mytest.cpp` file to the `Tests` project. The tests are exported as `bool _Test();` and the result indicates whether the test was successful or not. If you need a custom environment add the following in `tests/harness-tests.py`: +Add a new `mytest.cpp` file to the `Tests` project. The tests are exported as `bool _Test();` and the result indicates whether the test was successful or not. If you need a custom environment add the following in `tests/run-tests.py`: ```python class Environment(TestEnvironment): diff --git a/tests/DumpulatorTests/Tests/HandleTest.cpp b/tests/DumpulatorTests/Tests/HandleTest.cpp index 1b64252..b225243 100644 --- a/tests/DumpulatorTests/Tests/HandleTest.cpp +++ b/tests/DumpulatorTests/Tests/HandleTest.cpp @@ -18,7 +18,7 @@ extern "C" __declspec(dllexport) bool Handle_WriteAndCreateFileTest() FILE_ATTRIBUTE_NORMAL, NULL ); - + if (file_handle == INVALID_HANDLE_VALUE) { DebugPrint(L"Failed to create file"); @@ -59,7 +59,7 @@ extern "C" __declspec(dllexport) bool Handle_ReadFileTest() if (file_handle == INVALID_HANDLE_VALUE) { DebugPrint(L"Failed to open file"); - return ret_value; + return false; } ret_value = ReadFile( @@ -70,7 +70,8 @@ extern "C" __declspec(dllexport) bool Handle_ReadFileTest() FALSE ); + CloseHandle(file_handle); - return ret_value; + return ret_value && memcmp(read_buffer, "Lorem ipsum", 11) == 0; } diff --git a/tests/harness-tests.py b/tests/run-tests.py similarity index 93% rename from tests/harness-tests.py rename to tests/run-tests.py index 0da4e01..fab9c13 100644 --- a/tests/harness-tests.py +++ b/tests/run-tests.py @@ -37,7 +37,8 @@ def collect_tests(dll_data) -> Tuple[Dict[str, List[str]], int]: module = Module(pe, "tests.dll") tests: Dict[str, List[str]] = {} for export in module.exports: - assert "_" in export.name, f"Invalid test export '{export.name}'" + if "_" not in export.name: + continue prefix = export.name.split("_")[0] if prefix not in tests: tests[prefix] = [] @@ -66,7 +67,7 @@ def run_tests(dll_path: str, harness_dump: str, filter: Callable[[str, str], boo test = module.find_export(export) assert test is not None print(f"--- Executing {test.name} at {hex(test.address)} ---") - success = dp.call(test.address) + success = dp.call(test.address) & 0xFF results[export] = success != 0 print(f"{export} -> {success}") return results @@ -166,8 +167,10 @@ def main(): parser.add_argument("--arch", choices=["x86", "x64"], help="Architecture to use (omit for both)", required=False) parser.add_argument("--tests", nargs="+", help="List of specific tests to run", required=False) parser.add_argument("--list", action="store_true", help="List all tests") - parser.add_argument("--prefix", nargs="+", help="Only run tests from this prefix", required=False) + parser.add_argument("--prefix", help="Only run tests from this prefix", required=False) args = parser.parse_args() + #if isinstance(args.tests, str): + # args.tests = [args.tests] # List all tests if args.list: @@ -178,7 +181,7 @@ def main(): tests, _ = collect_tests(dll_data) for prefix, exports in tests.items(): for export in exports: - print(f"--arch {arch} --prefix {prefix.lower()} --tests {export}") + print(f"python run-tests.py --arch {arch} --prefix {prefix.lower()} --tests {export}") return if args.arch: