@@ -97,11 +97,6 @@ struct FileTestList
97
97
List<TestDetails> tests;
98
98
};
99
99
100
- enum class SpawnType
101
- {
102
- UseExe,
103
- UseSharedLibrary,
104
- };
105
100
106
101
struct TestInput
107
102
{
@@ -531,6 +526,8 @@ static SlangResult _gatherTestsForFile(
531
526
return SLANG_OK;
532
527
}
533
528
529
+
530
+
534
531
Result spawnAndWaitExe (TestContext* context, const String& testPath, const CommandLine& cmdLine, ExecuteResult& outRes)
535
532
{
536
533
const auto & options = context->options ;
@@ -550,6 +547,7 @@ Result spawnAndWaitExe(TestContext* context, const String& testPath, const Comma
550
547
return res;
551
548
}
552
549
550
+
553
551
Result spawnAndWaitSharedLibrary (TestContext* context, const String& testPath, const CommandLine& cmdLine, ExecuteResult& outRes)
554
552
{
555
553
const auto & options = context->options ;
@@ -620,6 +618,44 @@ Result spawnAndWaitSharedLibrary(TestContext* context, const String& testPath, c
620
618
}
621
619
622
620
621
+ Result spawnAndWaitProxy (TestContext* context, const String& testPath, const CommandLine& inCmdLine, ExecuteResult& outRes)
622
+ {
623
+ // Get the name of the thing to execute
624
+ String exeName = Path::getFileNameWithoutExt (inCmdLine.m_executable );
625
+
626
+ if (exeName == " slangc" )
627
+ {
628
+ // If the test is slangc there is a command line version we can just directly use
629
+ // return spawnAndWaitExe(context, testPath, inCmdLine, outRes);
630
+ return spawnAndWaitSharedLibrary (context, testPath, inCmdLine, outRes);
631
+ }
632
+
633
+ CommandLine cmdLine (inCmdLine);
634
+
635
+ // Make the first arg the name of the tool to invoke
636
+ cmdLine.m_args .insert (0 , exeName);
637
+
638
+ auto exePath = Path::combine (Path::getParentDirectory (inCmdLine.m_executable ), String (" test-proxy" ) + ProcessUtil::getExecutableSuffix ());
639
+ cmdLine.setExecutablePath (exePath);
640
+
641
+ const auto & options = context->options ;
642
+ if (options.shouldBeVerbose )
643
+ {
644
+ String commandLine = ProcessUtil::getCommandLineString (cmdLine);
645
+ context->reporter ->messageFormat (TestMessageType::Info, " %s\n " , commandLine.begin ());
646
+ }
647
+
648
+ // Execute
649
+ Result res = ProcessUtil::execute (cmdLine, outRes);
650
+ if (SLANG_FAILED (res))
651
+ {
652
+ // fprintf(stderr, "failed to run test '%S'\n", testPath.ToWString());
653
+ context->reporter ->messageFormat (TestMessageType::RunError, " failed to run test '%S'" , testPath.toWString ().begin ());
654
+ }
655
+
656
+ return res;
657
+ }
658
+
623
659
static SlangResult _extractArg (const CommandLine& cmdLine, const String& argName, String& outValue)
624
660
{
625
661
SLANG_ASSERT (argName.getLength () > 0 && argName[0 ] == ' -' );
@@ -972,6 +1008,11 @@ ToolReturnCode spawnAndWait(TestContext* context, const String& testPath, SpawnT
972
1008
spawnResult = spawnAndWaitSharedLibrary (context, testPath, cmdLine, outExeRes);
973
1009
break ;
974
1010
}
1011
+ case SpawnType::UseProxy:
1012
+ {
1013
+ spawnResult = spawnAndWaitProxy (context, testPath, cmdLine, outExeRes);
1014
+ break ;
1015
+ }
975
1016
default : break ;
976
1017
}
977
1018
@@ -2880,8 +2921,6 @@ TestResult runTest(
2880
2921
return TestResult::Pass;
2881
2922
}
2882
2923
2883
- const SpawnType defaultSpawnType = context->options .useExes ? SpawnType::UseExe : SpawnType::UseSharedLibrary;
2884
-
2885
2924
auto testInfo = _findTestCommandInfoByCommand (testOptions.command .getUnownedSlice ());
2886
2925
2887
2926
if (testInfo)
@@ -2890,7 +2929,7 @@ TestResult runTest(
2890
2929
testInput.filePath = filePath;
2891
2930
testInput.outputStem = outputStem;
2892
2931
testInput.testOptions = &testOptions;
2893
- testInput.spawnType = defaultSpawnType;
2932
+ testInput.spawnType = context-> options . defaultSpawnType ;
2894
2933
2895
2934
return testInfo->callback (context, testInput);
2896
2935
}
@@ -3346,8 +3385,18 @@ static void _disableCPPBackends(TestContext* context)
3346
3385
}
3347
3386
}
3348
3387
3388
+ static TestResult _asTestResult (ToolReturnCode retCode)
3389
+ {
3390
+ switch (retCode)
3391
+ {
3392
+ default : return TestResult::Fail;
3393
+ case ToolReturnCode::Success: return TestResult::Pass;
3394
+ case ToolReturnCode::Ignored: return TestResult::Ignored;
3395
+ }
3396
+ }
3397
+
3349
3398
// / Loads a DLL containing unit test functions and run them one by one.
3350
- static SlangResult runUnitTestModule (TestContext* context, TestOptions& testOptions, const char * moduleName)
3399
+ static SlangResult runUnitTestModule (TestContext* context, TestOptions& testOptions, SpawnType spawnType, const char * moduleName)
3351
3400
{
3352
3401
SharedLibrary::Handle moduleHandle;
3353
3402
SLANG_RETURN_ON_FAIL (SharedLibrary::load (
@@ -3368,6 +3417,9 @@ static SlangResult runUnitTestModule(TestContext* context, TestOptions& testOpti
3368
3417
unitTestContext.workDirectory = " " ;
3369
3418
unitTestContext.enabledApis = context->options .enabledApis ;
3370
3419
auto testCount = testModule->getTestCount ();
3420
+
3421
+ TestReporter* reporter = TestReporter::get ();
3422
+
3371
3423
for (SlangInt i = 0 ; i < testCount; i++)
3372
3424
{
3373
3425
auto testFunc = testModule->getTestFunc (i);
@@ -3382,9 +3434,50 @@ static SlangResult runUnitTestModule(TestContext* context, TestOptions& testOpti
3382
3434
{
3383
3435
if (testPassesCategoryMask (context, testOptions))
3384
3436
{
3385
- TestReporter::get ()->startTest (testOptions.command .getBuffer ());
3386
- testFunc (&unitTestContext);
3387
- TestReporter::get ()->endTest ();
3437
+ if (spawnType == SpawnType::UseProxy)
3438
+ {
3439
+ CommandLine cmdLine;
3440
+
3441
+ // The 'command' is the module
3442
+ cmdLine.setExecutablePath (Path::combine (context->exeDirectoryPath , moduleName));
3443
+
3444
+ // Pass the test name / index
3445
+ cmdLine.addArg (testName);
3446
+
3447
+ {
3448
+ StringBuilder buf;
3449
+ buf << i;
3450
+ cmdLine.addArg (buf.ProduceString ());
3451
+ }
3452
+
3453
+ // Pass the enabled apis
3454
+ {
3455
+ StringBuilder buf;
3456
+ buf << context->options .enabledApis ;
3457
+ cmdLine.addArg (buf.ProduceString ());
3458
+ }
3459
+
3460
+ {
3461
+ TestReporter::TestScope scopeTest (reporter, testOptions.command );
3462
+ ExecuteResult exeRes;
3463
+
3464
+ const auto testResult = _asTestResult (spawnAndWait (context, filePath, spawnType, cmdLine, exeRes));
3465
+
3466
+ // If the test fails, output any output - which might give information about individual tests that have failed.
3467
+ if (testResult == TestResult::Fail)
3468
+ {
3469
+ String output = getOutput (exeRes);
3470
+ reporter->message (TestMessageType::TestFailure, output.getBuffer ());
3471
+ }
3472
+
3473
+ reporter->addResult (testResult);
3474
+ }
3475
+ }
3476
+ else
3477
+ {
3478
+ TestReporter::TestScope scopeTest (reporter, testOptions.command );
3479
+ testFunc (&unitTestContext);
3480
+ }
3388
3481
}
3389
3482
}
3390
3483
}
@@ -3570,13 +3663,15 @@ SlangResult innerMain(int argc, char** argv)
3570
3663
TestOptions testOptions;
3571
3664
testOptions.categories .add (unitTestCategory);
3572
3665
testOptions.categories .add (smokeTestCategory);
3573
- runUnitTestModule (&context, testOptions, " slang-unit-test-tool" );
3666
+ runUnitTestModule (&context, testOptions, context. options . defaultSpawnType , " slang-unit-test-tool" );
3574
3667
}
3668
+
3575
3669
{
3576
3670
TestOptions testOptions;
3577
3671
testOptions.categories .add (unitTestCategory);
3578
- runUnitTestModule (&context, testOptions, " gfx-unit-test-tool" );
3672
+ runUnitTestModule (&context, testOptions, SpawnType::UseProxy, " gfx-unit-test-tool" );
3579
3673
}
3674
+
3580
3675
TestReporter::set (nullptr );
3581
3676
}
3582
3677
0 commit comments