Skip to content

Commit

Permalink
Rename harness-tests.py to run-tests.py and fix boolean return
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexodia committed May 22, 2023
1 parent 9fa2c3f commit 149d536
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- name: 'Test: DumpulatorTests'
run: |
cd tests
python harness-tests.py
python run-tests.py
- name: 'Test: ExceptionTest_x64'
run: |
Expand Down
2 changes: 1 addition & 1 deletion tests/DumpulatorTests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Prefix>_<description>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 <Prefix>_<description>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 <Prefix>Environment(TestEnvironment):
Expand Down
7 changes: 4 additions & 3 deletions tests/DumpulatorTests/Tests/HandleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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(
Expand All @@ -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;
}
11 changes: 7 additions & 4 deletions tests/harness-tests.py → tests/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 149d536

Please sign in to comment.