summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-06-14 18:05:12 -0400
committerTim Foley <tfoleyNV@users.noreply.github.com>2019-06-14 15:05:12 -0700
commit1fe24d3a74a9cd51c4a025cd0e78642f3e29df79 (patch)
treea52d2b1e05f0d22accbb70eb4bea69d7c67455a4 /tools
parent8c56d83506ef92b15b15bdb5969008dd69c8d2a6 (diff)
Runtime Shared Library compilation and testing (#985)
* Removed the need for VisualStudio specific CPPCompiler Improved the version parsing for gcc/clang Removed need for slang-unix-cpp-compiler-util.cpp/.h Remove binary before compiling in the compile c tests * Moved VisualStudio calcArgs into CPPCompilerUtil - as code is not windows specific. * Set up compile time version for gcc and clang * Fix compilation on OSX - use remove instead of unlink for file deletion. * On OSX - clang uses different string format. * Removed /bin/sh invoking as not required for OSX. * First pass working testing with shared libraries.
Diffstat (limited to 'tools')
-rw-r--r--tools/slang-test/slang-test-main.cpp98
1 files changed, 95 insertions, 3 deletions
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp
index 0777c31f2..e792abe72 100644
--- a/tools/slang-test/slang-test-main.cpp
+++ b/tools/slang-test/slang-test-main.cpp
@@ -1086,7 +1086,7 @@ String getExpectedOutput(String const& outputStem)
return expectedOutput;
}
-static TestResult runExecuteC(TestContext* context, TestInput& input)
+static TestResult runCPPCompilerExecute(TestContext* context, TestInput& input)
{
CPPCompilerSet* compilerSet = context->getCPPCompilerSet();
CPPCompiler* compiler = compilerSet ? compilerSet->getDefaultCompiler() : nullptr;
@@ -1111,7 +1111,7 @@ static TestResult runExecuteC(TestContext* context, TestInput& input)
// Make the module name the same as the source file
String directory = Path::getParentDirectory(input.outputStem);
String moduleName = Path::getFileNameWithoutExt(filePath);
-
+ String ext = Path::getFileExt(filePath);
String modulePath = Path::combine(directory, moduleName);
// Remove the binary..
@@ -1125,6 +1125,8 @@ static TestResult runExecuteC(TestContext* context, TestInput& input)
// Set up the compilation options
CPPCompiler::CompileOptions options;
+ options.sourceType = (ext == "c") ? CPPCompiler::SourceType::C : CPPCompiler::SourceType::CPP;
+
// Compile this source
options.sourceFiles.add(filePath);
options.modulePath = modulePath;
@@ -1177,6 +1179,95 @@ static TestResult runExecuteC(TestContext* context, TestInput& input)
return TestResult::Pass;
}
+static TestResult runCPPCompilerSharedLibrary(TestContext* context, TestInput& input)
+{
+ CPPCompilerSet* compilerSet = context->getCPPCompilerSet();
+ CPPCompiler* compiler = compilerSet ? compilerSet->getDefaultCompiler() : nullptr;
+
+ if (!compiler)
+ {
+ return TestResult::Ignored;
+ }
+
+ // If we are just collecting requirements, say it passed
+ if (context->isCollectingRequirements())
+ {
+ return TestResult::Pass;
+ }
+
+ auto filePath = input.filePath;
+ auto outputStem = input.outputStem;
+
+ String actualOutputPath = outputStem + ".actual";
+ File::remove(actualOutputPath);
+
+ // Make the module name the same as the source file
+ String directory = Path::getParentDirectory(input.outputStem);
+ String moduleName = Path::getFileNameWithoutExt(filePath);
+ String ext = Path::getFileExt(filePath);
+
+ String modulePath = Path::combine(directory, moduleName);
+
+ // Remove the binary..
+ String sharedLibraryPath = SharedLibrary::calcPlatformPath(modulePath.getUnownedSlice());
+ File::remove(sharedLibraryPath);
+
+ // Set up the compilation options
+ CPPCompiler::CompileOptions options;
+
+ options.sourceType = (ext == "c") ? CPPCompiler::SourceType::C : CPPCompiler::SourceType::CPP;
+
+ // Build a shared library
+ options.targetType = CPPCompiler::TargetType::SharedLibrary;
+
+ // Compile this source
+ options.sourceFiles.add(filePath);
+ options.modulePath = modulePath;
+
+ options.includePaths.add(".");
+
+ ExecuteResult exeRes;
+
+ if (SLANG_FAILED(compiler->compile(options, exeRes)))
+ {
+ return TestResult::Fail;
+ }
+
+ SharedLibrary::Handle handle;
+ if (SLANG_FAILED(SharedLibrary::loadWithPlatformFilename(sharedLibraryPath.getBuffer(), handle)))
+ {
+ return TestResult::Fail;
+ }
+
+ const int inValue = 10;
+ const char inBuffer[] = "Hello World!";
+
+ char buffer[128] = "";
+ int value = 0;
+
+ typedef int (*TestFunc)(int intValue, const char* textValue, char* outTextValue);
+
+ // We could capture output if we passed in a ISlangWriter - but for that to work we'd need a
+ TestFunc testFunc = (TestFunc)SharedLibrary::findFuncByName(handle, "test");
+ if (testFunc)
+ {
+ value = testFunc(inValue, inBuffer, buffer);
+ }
+ else
+ {
+ printf("Unable to access 'test' function\n");
+ }
+
+ SharedLibrary::unload(handle);
+
+ if (!(inValue == value && strcmp(inBuffer, buffer) == 0))
+ {
+ return TestResult::Fail;
+ }
+
+ return TestResult::Pass;
+}
+
TestResult runCrossCompilerTest(TestContext* context, TestInput& input)
{
// need to execute the stand-alone Slang compiler on the file
@@ -1983,7 +2074,8 @@ static const TestCommandInfo s_testCommandInfos[] =
{ "COMPARE_RENDER_COMPUTE", &runSlangRenderComputeComparisonTest},
{ "COMPARE_GLSL", &runGLSLComparisonTest},
{ "CROSS_COMPILE", &runCrossCompilerTest},
- { "EXECUTE_C", &runExecuteC},
+ { "CPP_COMPILER_EXECUTE", &runCPPCompilerExecute},
+ { "CPP_COMPILER_SHARED_LIBRARY", &runCPPCompilerSharedLibrary},
};
TestResult runTest(