@@ -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 ());
0 commit comments