Skip to content

Commit 149d536

Browse files
committed
Rename harness-tests.py to run-tests.py and fix boolean return
1 parent 9fa2c3f commit 149d536

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
- name: 'Test: DumpulatorTests'
7171
run: |
7272
cd tests
73-
python harness-tests.py
73+
python run-tests.py
7474
7575
- name: 'Test: ExceptionTest_x64'
7676
run: |

tests/DumpulatorTests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The harness dumps were created as follows:
1414

1515
## Adding a new test
1616

17-
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`:
17+
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`:
1818

1919
```python
2020
class <Prefix>Environment(TestEnvironment):

tests/DumpulatorTests/Tests/HandleTest.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern "C" __declspec(dllexport) bool Handle_WriteAndCreateFileTest()
1818
FILE_ATTRIBUTE_NORMAL,
1919
NULL
2020
);
21-
21+
2222
if (file_handle == INVALID_HANDLE_VALUE)
2323
{
2424
DebugPrint(L"Failed to create file");
@@ -59,7 +59,7 @@ extern "C" __declspec(dllexport) bool Handle_ReadFileTest()
5959
if (file_handle == INVALID_HANDLE_VALUE)
6060
{
6161
DebugPrint(L"Failed to open file");
62-
return ret_value;
62+
return false;
6363
}
6464

6565
ret_value = ReadFile(
@@ -70,7 +70,8 @@ extern "C" __declspec(dllexport) bool Handle_ReadFileTest()
7070
FALSE
7171
);
7272

73+
7374
CloseHandle(file_handle);
7475

75-
return ret_value;
76+
return ret_value && memcmp(read_buffer, "Lorem ipsum", 11) == 0;
7677
}

tests/harness-tests.py renamed to tests/run-tests.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def collect_tests(dll_data) -> Tuple[Dict[str, List[str]], int]:
3737
module = Module(pe, "tests.dll")
3838
tests: Dict[str, List[str]] = {}
3939
for export in module.exports:
40-
assert "_" in export.name, f"Invalid test export '{export.name}'"
40+
if "_" not in export.name:
41+
continue
4142
prefix = export.name.split("_")[0]
4243
if prefix not in tests:
4344
tests[prefix] = []
@@ -66,7 +67,7 @@ def run_tests(dll_path: str, harness_dump: str, filter: Callable[[str, str], boo
6667
test = module.find_export(export)
6768
assert test is not None
6869
print(f"--- Executing {test.name} at {hex(test.address)} ---")
69-
success = dp.call(test.address)
70+
success = dp.call(test.address) & 0xFF
7071
results[export] = success != 0
7172
print(f"{export} -> {success}")
7273
return results
@@ -166,8 +167,10 @@ def main():
166167
parser.add_argument("--arch", choices=["x86", "x64"], help="Architecture to use (omit for both)", required=False)
167168
parser.add_argument("--tests", nargs="+", help="List of specific tests to run", required=False)
168169
parser.add_argument("--list", action="store_true", help="List all tests")
169-
parser.add_argument("--prefix", nargs="+", help="Only run tests from this prefix", required=False)
170+
parser.add_argument("--prefix", help="Only run tests from this prefix", required=False)
170171
args = parser.parse_args()
172+
#if isinstance(args.tests, str):
173+
# args.tests = [args.tests]
171174

172175
# List all tests
173176
if args.list:
@@ -178,7 +181,7 @@ def main():
178181
tests, _ = collect_tests(dll_data)
179182
for prefix, exports in tests.items():
180183
for export in exports:
181-
print(f"--arch {arch} --prefix {prefix.lower()} --tests {export}")
184+
print(f"python run-tests.py --arch {arch} --prefix {prefix.lower()} --tests {export}")
182185
return
183186

184187
if args.arch:

0 commit comments

Comments
 (0)