Skip to content

Commit 3bf800a

Browse files
authored
Merge pull request #508 from GameTechDev/pmc-ult-updates
PM Console ULT improvements
2 parents e851bea + 71086e1 commit 3bf800a

File tree

4 files changed

+125
-1
lines changed

4 files changed

+125
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ PresentMon/ddETWExternalEvents.h
5757
PresentMon/ddETWExternalEvents.rc
5858

5959
PresentMon/ddETWExternalEventsTEMP.BIN
60+
61+
# Local runsettings files (user-specific test configurations)
62+
*.local.runsettings

Tests/PresentMonTests.cpp

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ int wmain(
135135
{
136136
// Set defaults
137137
std::wstring goldDir(L"../../Tests/Gold");
138+
139+
// Check for additional test directory from environment variable
140+
// This allows developers to specify their own test directories without
141+
// modifying the source code. Set PRESENTMON_ADDITIONAL_TEST_DIR environment
142+
// variable or use a .runsettings.user file (see template).
143+
std::wstring additionalTestDir;
144+
wchar_t* envTestDir = nullptr;
145+
size_t envTestDirLen = 0;
146+
if (_wdupenv_s(&envTestDir, &envTestDirLen, L"PRESENTMON_ADDITIONAL_TEST_DIR") == 0 && envTestDir != nullptr) {
147+
additionalTestDir = envTestDir;
148+
free(envTestDir);
149+
}
138150

139151
{
140152
// If exe == <dir>/PresentMonTests-<ver>-<platform>.exe use
@@ -198,6 +210,7 @@ int wmain(
198210
"options:\n"
199211
" --presentmon=path Path to the PresentMon exe path to test (default=%ls).\n"
200212
" --golddir=path Path to directory of test ETLs and gold CSVs (default=%ls).\n"
213+
" --opttestdir=path Optional additional directory of test ETLs and gold CSVs.\n"
201214
" --outdir=path Path to directory for test outputs (default=%%temp%%/PresentMonTestOutput).\n"
202215
" --nodelete Keep the output directory after tests.\n"
203216
" --nowarnmissing Don't warn if a found ETL is missing a gold CSV.\n"
@@ -221,6 +234,7 @@ int wmain(
221234
// Parse remaining command line arguments for custom commands.
222235
wchar_t* presentMonPathArg = nullptr;
223236
wchar_t* goldDirArg = nullptr;
237+
wchar_t* optTestDirArg = nullptr;
224238
wchar_t* outDirArg = nullptr;
225239
bool deleteOutDir = true;
226240
for (int i = 1; i < argc; ++i) {
@@ -234,6 +248,11 @@ int wmain(
234248
continue;
235249
}
236250

251+
if (_wcsnicmp(argv[i], L"--opttestdir=", 10) == 0) {
252+
optTestDirArg = argv[i] + 13;
253+
continue;
254+
}
255+
237256
if (_wcsnicmp(argv[i], L"--outdir=", 9) == 0) {
238257
outDirArg = argv[i] + 9;
239258
continue;
@@ -267,9 +286,18 @@ int wmain(
267286
// Check command line arguments...
268287
bool goldDirExists = true;
269288
bool outDirExists = true;
289+
std::wstring optTestDir;
290+
bool optTestDirExists = false;
291+
bool hasOptTestDir = optTestDirArg != nullptr;
292+
293+
if (hasOptTestDir) {
294+
optTestDir = optTestDirArg;
295+
}
296+
270297
if (!CheckPath("--presentmon", &PresentMon::exePath_, presentMonPathArg, false, nullptr) ||
271298
!CheckPath("--golddir", &goldDir, goldDirArg, true, &goldDirExists) ||
272-
!CheckPath("--outdir", &outDir_, outDirArg, true, &outDirExists)) {
299+
!CheckPath("--outdir", &outDir_, outDirArg, true, &outDirExists) ||
300+
(hasOptTestDir && !CheckPath("--opttestdir", &optTestDir, optTestDirArg, true, &optTestDirExists))) {
273301
return 1;
274302
}
275303

@@ -281,6 +309,39 @@ int wmain(
281309
fprintf(stderr, " using the --golddir command line argument.\n");
282310
}
283311

312+
// Add tests from optional test directory if specified (command line)
313+
if (hasOptTestDir) {
314+
printf("INFO: Using optional test directory from command line: %ls\n", optTestDir.c_str());
315+
if (optTestDirExists) {
316+
printf("INFO: Adding tests from test directory: %ls\n", optTestDir.c_str());
317+
AddGoldEtlCsvTests(optTestDir, optTestDir.size());
318+
} else {
319+
fprintf(stderr, "warning: optional test directory does not exist: %ls\n", optTestDir.c_str());
320+
fprintf(stderr, " Continuing, but no tests from this directory will run.\n");
321+
}
322+
}
323+
324+
// Add tests from additional test directory (environment variable)
325+
if (!additionalTestDir.empty()) {
326+
printf("INFO: Using additional test directory from environment: %ls\n", additionalTestDir.c_str());
327+
// Ensure directory ends with backslash
328+
if (additionalTestDir.back() != L'\\') {
329+
additionalTestDir += L'\\';
330+
}
331+
332+
auto attr = GetFileAttributes(additionalTestDir.c_str());
333+
if (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY)) {
334+
printf("INFO: Adding tests from additional directory: %ls\n", additionalTestDir.c_str());
335+
AddGoldEtlCsvTests(additionalTestDir, additionalTestDir.size());
336+
} else {
337+
fprintf(stderr, "warning: additional test directory does not exist: %ls\n", additionalTestDir.c_str());
338+
}
339+
}
340+
341+
if (!hasOptTestDir && additionalTestDir.empty()) {
342+
printf("INFO: No optional test directories specified.\n");
343+
}
344+
284345
if (outDirExists) {
285346
if (deleteOutDir) {
286347
fprintf(stderr, "warning: output directory already exists: %ls\n", outDir_.c_str());
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copy this file to PresentMonTests.local.runsettings and modify the path below
4+
to point to your local test directory containing ETL and CSV files.
5+
6+
The .local.runsettings file is ignored by git, so your local paths won't be committed.
7+
-->
8+
<RunSettings>
9+
<RunConfiguration>
10+
<TargetPlatform>x64</TargetPlatform>
11+
<EnvironmentVariables>
12+
<!-- Set this to your local test directory path -->
13+
<PRESENTMON_ADDITIONAL_TEST_DIR>C:\path\to\your\test\directory</PRESENTMON_ADDITIONAL_TEST_DIR>
14+
</EnvironmentVariables>
15+
</RunConfiguration>
16+
17+
<GoogleTestAdapterSettings>
18+
<PrintTestOutput>true</PrintTestOutput>
19+
</GoogleTestAdapterSettings>
20+
</RunSettings>

Tests/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,43 @@ The following expected cases are currently missing (WIP):
4646
- PresentMode==Hardware_Legacy_Copy_To_Front_Buffer
4747
- [2,17-23] All Windows7 paths
4848
- [30] Non-Win7 Microsoft_Windows_Dwm_Core::FlipChain_(Pending|Complete|Dirty) with previous Microsoft_Windows_Dwm_Core::PresentHistory[Detailed]::Start
49+
50+
## Adding Custom Test Directories
51+
52+
To add your own test directory with ETL files and gold CSV files:
53+
54+
### Method 1: Using local runsettings file (Recommended)
55+
56+
1. Copy `PresentMonTests.runsettings.template` to `PresentMonTests.local.runsettings`
57+
2. Edit the `PRESENTMON_ADDITIONAL_TEST_DIR` path to point to your test directory
58+
3. In Visual Studio, go to **Test****Configure Run Settings****Select Solution Wide runsettings File**
59+
4. Select your `PresentMonTests.local.runsettings` file
60+
61+
### Method 2: Command Line Parameter
62+
63+
Run the test executable directly with the `--opttestdir` parameter:
64+
```
65+
PresentMonTests.exe --opttestdir="C:\path\to\your\tests"
66+
```
67+
68+
### Method 3: Environment Variable
69+
70+
Set the `PRESENTMON_ADDITIONAL_TEST_DIR` environment variable:
71+
```cmd
72+
set PRESENTMON_ADDITIONAL_TEST_DIR=C:\path\to\your\tests
73+
PresentMonTests.exe
74+
```
75+
76+
### Test Directory Structure
77+
78+
Your test directory should contain:
79+
- ETL files (e.g., `test_case.etl`)
80+
- Corresponding CSV files (e.g., `test_case.csv`, `test_case_v1.csv`, etc.)
81+
82+
The test system will automatically discover and register tests for each ETL/CSV pair.
83+
84+
### Notes
85+
86+
- The `.local.runsettings` files are ignored by git, so your local paths won't be committed
87+
- Tests are dynamically registered at runtime based on the files found
88+
- Each CSV file creates a separate test case in Test Explorer

0 commit comments

Comments
 (0)