summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-01-17 17:50:48 -0500
committerGitHub <noreply@github.com>2019-01-17 17:50:48 -0500
commit3c7e1be0098f963225afd0ebe83340a991392892 (patch)
tree4be05c44125c3378cb5278cd8f7615fc280ea0fc /tools
parent668078ac8be89e55c8e13ac429c4b0e63fb604dc (diff)
Feature/hash for source identity (#786)
* * Added COMMAND_LINE_SIMPLE test type * Made how spawning works controllable by paramter/type SpawnType * Made break-outside-loop and global-uniform run command line slangc * calcRelativePath -> calcCombinedPath * Add 64 bit version of GetHash. * Add support for Hash based mode for CacheFileSystem.
Diffstat (limited to 'tools')
-rw-r--r--tools/slang-test/slang-test-main.cpp182
1 files changed, 113 insertions, 69 deletions
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp
index 9039dbf2b..06c2aaf67 100644
--- a/tools/slang-test/slang-test-main.cpp
+++ b/tools/slang-test/slang-test-main.cpp
@@ -47,6 +47,12 @@ struct FileTestList
List<TestOptions> tests;
};
+enum class SpawnType
+{
+ UseExe,
+ UseSharedLibrary,
+};
+
struct TestInput
{
// Path to the input file for the test
@@ -63,6 +69,9 @@ struct TestInput
// The list of tests that will be run on this file
FileTestList const* testList;
+
+ // Determines how the test will be spawned
+ SpawnType spawnType;
};
typedef TestResult(*TestCallback)(TestContext* context, TestInput& input);
@@ -345,92 +354,111 @@ TestResult gatherTestsForFile(
return TestResult::Pass;
}
-OSError spawnAndWait(TestContext* context, const String& testPath, OSProcessSpawner& spawner)
+OSError spawnAndWaitExe(TestContext* context, const String& testPath, OSProcessSpawner& spawner)
{
const auto& options = context->options;
-
- if (!options.useExes)
- {
- String exeName = Path::GetFileNameWithoutEXT(spawner.executableName_);
- if (options.shouldBeVerbose)
- {
- StringBuilder builder;
+ if (options.shouldBeVerbose)
+ {
+ String commandLine = spawner.getCommandLine();
+ context->reporter->messageFormat(TestMessageType::Info, "%s\n", commandLine.begin());
+ }
- builder << "slang-test";
+ OSError err = spawner.spawnAndWaitForCompletion();
+ if (err != kOSError_None)
+ {
+ // fprintf(stderr, "failed to run test '%S'\n", testPath.ToWString());
+ context->reporter->messageFormat(TestMessageType::RunError, "failed to run test '%S'", testPath.ToWString().begin());
+ }
+ return err;
+}
- if (options.binDir)
- {
- builder << " -bindir " << options.binDir;
- }
+OSError spawnAndWaitSharedLibrary(TestContext* context, const String& testPath, OSProcessSpawner& spawner)
+{
+ const auto& options = context->options;
+ String exeName = Path::GetFileNameWithoutEXT(spawner.executableName_);
- builder << " " << exeName;
+ if (options.shouldBeVerbose)
+ {
+ StringBuilder builder;
- // TODO(js): Potentially this should handle escaping parameters for the command line if need be
- const auto& argList = spawner.argumentList_;
- for (UInt i = 0; i < argList.Count(); ++i)
- {
- builder << " " << argList[i];
- }
+ builder << "slang-test";
- context->reporter->messageFormat(TestMessageType::Info, "%s\n", builder.begin());
+ if (options.binDir)
+ {
+ builder << " -bindir " << options.binDir;
}
- auto func = context->getInnerMainFunc(String(context->options.binDir), exeName);
- if (func)
+ builder << " " << exeName;
+
+ // TODO(js): Potentially this should handle escaping parameters for the command line if need be
+ const auto& argList = spawner.argumentList_;
+ for (UInt i = 0; i < argList.Count(); ++i)
{
- StringBuilder stdErrorString;
- StringBuilder stdOutString;
+ builder << " " << argList[i];
+ }
- // Say static so not released
- StringWriter stdError(&stdErrorString, WriterFlag::IsConsole | WriterFlag::IsStatic);
- StringWriter stdOut(&stdOutString, WriterFlag::IsConsole | WriterFlag::IsStatic);
+ context->reporter->messageFormat(TestMessageType::Info, "%s\n", builder.begin());
+ }
- StdWriters* prevStdWriters = StdWriters::getSingleton();
+ auto func = context->getInnerMainFunc(String(context->options.binDir), exeName);
+ if (func)
+ {
+ StringBuilder stdErrorString;
+ StringBuilder stdOutString;
- StdWriters stdWriters;
- stdWriters.setWriter(SLANG_WRITER_CHANNEL_STD_ERROR, &stdError);
- stdWriters.setWriter(SLANG_WRITER_CHANNEL_STD_OUTPUT, &stdOut);
+ // Say static so not released
+ StringWriter stdError(&stdErrorString, WriterFlag::IsConsole | WriterFlag::IsStatic);
+ StringWriter stdOut(&stdOutString, WriterFlag::IsConsole | WriterFlag::IsStatic);
- if (exeName == "slangc")
- {
- stdWriters.setWriter(SLANG_WRITER_CHANNEL_DIAGNOSTIC, &stdError);
- }
-
- List<const char*> args;
- args.Add(exeName.Buffer());
- for (int i = 0; i < int(spawner.argumentList_.Count()); ++i)
- {
- args.Add(spawner.argumentList_[i].Buffer());
- }
+ StdWriters* prevStdWriters = StdWriters::getSingleton();
- SlangResult res = func(&stdWriters, context->getSession(), int(args.Count()), args.begin());
+ StdWriters stdWriters;
+ stdWriters.setWriter(SLANG_WRITER_CHANNEL_STD_ERROR, &stdError);
+ stdWriters.setWriter(SLANG_WRITER_CHANNEL_STD_OUTPUT, &stdOut);
- StdWriters::setSingleton(prevStdWriters);
+ if (exeName == "slangc")
+ {
+ stdWriters.setWriter(SLANG_WRITER_CHANNEL_DIAGNOSTIC, &stdError);
+ }
- spawner.standardError_ = stdErrorString;
- spawner.standardOutput_ = stdOutString;
+ List<const char*> args;
+ args.Add(exeName.Buffer());
+ for (int i = 0; i < int(spawner.argumentList_.Count()); ++i)
+ {
+ args.Add(spawner.argumentList_[i].Buffer());
+ }
- spawner.resultCode_ = TestToolUtil::getReturnCode(res);
+ SlangResult res = func(&stdWriters, context->getSession(), int(args.Count()), args.begin());
- return kOSError_None;
- }
- }
+ StdWriters::setSingleton(prevStdWriters);
- if (options.shouldBeVerbose)
- {
- String commandLine = spawner.getCommandLine();
- context->reporter->messageFormat(TestMessageType::Info, "%s\n", commandLine.begin());
+ spawner.standardError_ = stdErrorString;
+ spawner.standardOutput_ = stdOutString;
+
+ spawner.resultCode_ = TestToolUtil::getReturnCode(res);
+
+ return kOSError_None;
}
+ return kOSError_OperationFailed;
+}
- OSError err = spawner.spawnAndWaitForCompletion();
- if (err != kOSError_None)
+
+OSError spawnAndWait(TestContext* context, const String& testPath, SpawnType spawnType, OSProcessSpawner& spawner)
+{
+ switch (spawnType)
{
-// fprintf(stderr, "failed to run test '%S'\n", testPath.ToWString());
- context->reporter->messageFormat(TestMessageType::RunError, "failed to run test '%S'", testPath.ToWString().begin());
+ case SpawnType::UseExe:
+ {
+ return spawnAndWaitExe(context, testPath, spawner);
+ }
+ case SpawnType::UseSharedLibrary:
+ {
+ return spawnAndWaitSharedLibrary(context, testPath, spawner);
+ }
}
- return err;
+ return kOSError_OperationFailed;
}
String getOutput(OSProcessSpawner& spawner)
@@ -491,6 +519,7 @@ String findExpectedPath(const TestInput& input, const char* postFix)
return "";
}
+
TestResult runSimpleTest(TestContext* context, TestInput& input)
{
// need to execute the stand-alone Slang compiler on the file, and compare its output to what we expect
@@ -508,7 +537,7 @@ TestResult runSimpleTest(TestContext* context, TestInput& input)
spawner.pushArgument(arg);
}
- if (spawnAndWait(context, outputStem, spawner) != kOSError_None)
+ if (spawnAndWait(context, outputStem, input.spawnType, spawner) != kOSError_None)
{
return TestResult::Fail;
}
@@ -555,6 +584,17 @@ TestResult runSimpleTest(TestContext* context, TestInput& input)
return result;
}
+TestResult runSimpleCompareCommandLineTest(TestContext* context, TestInput& input)
+{
+ TestInput workInput(input);
+ // Use the original files input to compare with
+ workInput.outputStem = input.filePath;
+ // Force to using exes
+ workInput.spawnType = SpawnType::UseExe;
+
+ return runSimpleTest(context, workInput);
+}
+
TestResult runReflectionTest(TestContext* context, TestInput& input)
{
const auto& options = context->options;
@@ -571,7 +611,7 @@ TestResult runReflectionTest(TestContext* context, TestInput& input)
spawner.pushArgument(arg);
}
- if (spawnAndWait(context, outputStem, spawner) != kOSError_None)
+ if (spawnAndWait(context, outputStem, input.spawnType, spawner) != kOSError_None)
{
return TestResult::Fail;
}
@@ -720,7 +760,7 @@ TestResult runCrossCompilerTest(TestContext* context, TestInput& input)
expectedSpawner.pushArgument(arg);
}
- if (spawnAndWait(context, outputStem, expectedSpawner) != kOSError_None)
+ if (spawnAndWait(context, outputStem, input.spawnType, expectedSpawner) != kOSError_None)
{
return TestResult::Fail;
}
@@ -736,7 +776,7 @@ TestResult runCrossCompilerTest(TestContext* context, TestInput& input)
return TestResult::Fail;
}
- if (spawnAndWait(context, outputStem, actualSpawner) != kOSError_None)
+ if (spawnAndWait(context, outputStem, input.spawnType, actualSpawner) != kOSError_None)
{
return TestResult::Fail;
}
@@ -794,7 +834,7 @@ TestResult generateHLSLBaseline(TestContext* context, TestInput& input)
spawner.pushArgument("-pass-through");
spawner.pushArgument("fxc");
- if (spawnAndWait(context, outputStem, spawner) != kOSError_None)
+ if (spawnAndWait(context, outputStem, input.spawnType, spawner) != kOSError_None)
{
return TestResult::Fail;
}
@@ -842,7 +882,7 @@ TestResult runHLSLComparisonTest(TestContext* context, TestInput& input)
spawner.pushArgument("-target");
spawner.pushArgument("dxbc-assembly");
- if (spawnAndWait(context, outputStem, spawner) != kOSError_None)
+ if (spawnAndWait(context, outputStem, input.spawnType, spawner) != kOSError_None)
{
return TestResult::Fail;
}
@@ -951,7 +991,7 @@ TestResult doGLSLComparisonTestRun(TestContext* context,
spawner.pushArgument(arg);
}
- if (spawnAndWait(context, outputStem, spawner) != kOSError_None)
+ if (spawnAndWait(context, outputStem, input.spawnType, spawner) != kOSError_None)
{
return TestResult::Fail;
}
@@ -1040,7 +1080,7 @@ TestResult runComputeComparisonImpl(TestContext* context, TestInput& input, cons
// clear the stale actual output file first. This will allow us to detect error if render-test fails and outputs nothing.
File::WriteAllText(actualOutputFile, "");
- if (spawnAndWait(context, outputStem, spawner) != kOSError_None)
+ if (spawnAndWait(context, outputStem, input.spawnType, spawner) != kOSError_None)
{
printf("error spawning render-test\n");
return TestResult::Fail;
@@ -1139,7 +1179,7 @@ TestResult doRenderComparisonTestRun(TestContext* context, TestInput& input, cha
spawner.pushArgument("-o");
spawner.pushArgument(outputStem + outputKind + ".png");
- if (spawnAndWait(context, outputStem, spawner) != kOSError_None)
+ if (spawnAndWait(context, outputStem, input.spawnType, spawner) != kOSError_None)
{
return TestResult::Fail;
}
@@ -1499,6 +1539,7 @@ TestResult runTest(
{
{ "SIMPLE", &runSimpleTest},
{ "REFLECTION", &runReflectionTest},
+ { "COMMAND_LINE_SIMPLE", &runSimpleCompareCommandLineTest},
#if SLANG_TEST_SUPPORT_HLSL
{ "COMPARE_HLSL", &runHLSLComparisonTest},
{ "COMPARE_HLSL_RENDER", &runHLSLRenderComparisonTest},
@@ -1524,6 +1565,8 @@ TestResult runTest(
{ nullptr, nullptr },
};
+ const SpawnType defaultSpawnType = context->options.useExes ? SpawnType::UseExe : SpawnType::UseSharedLibrary;
+
for( auto ii = kTestCommands; ii->name; ++ii )
{
if(testOptions.command != ii->name)
@@ -1534,6 +1577,7 @@ TestResult runTest(
testInput.outputStem = outputStem;
testInput.testOptions = &testOptions;
testInput.testList = &testList;
+ testInput.spawnType = defaultSpawnType;
{
TestReporter* reporter = context->reporter;