Skip to content

Commit

Permalink
Allow explicit test root (shader-slang#5980)
Browse files Browse the repository at this point in the history
  • Loading branch information
bspeice authored Jan 2, 2025
1 parent a13ef05 commit e3b71cf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions source/core/slang-io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,12 +992,12 @@ static SlangResult _calcExectuablePath(char* outPath, size_t* ioSize)
{
return SLANG_FAIL;
}
if (size_t(resSize) >= bufferSize)
if (size_t(resSize + 1) >= bufferSize)
{
return SLANG_E_BUFFER_TOO_SMALL;
}
// Zero terminate
outPath[resSize - 1] = 0;
outPath[resSize] = 0;
return SLANG_OK;
#else
String text = Slang::File::readAllText("/proc/self/maps");
Expand Down
15 changes: 15 additions & 0 deletions tools/slang-test/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,15 @@ static bool _isSubCommand(const char* arg)
optionsOut->expectedFailureList.add(line);
}
}
else if (strcmp(arg, "-test-dir") == 0)
{
if (argCursor == argEnd)
{
stdError.print("error: expected operand for '%s'\n", arg);
return SLANG_FAIL;
}
optionsOut->testDir = *argCursor++;
}
else
{
stdError.print("unknown option '%s'\n", arg);
Expand Down Expand Up @@ -365,5 +374,11 @@ static bool _isSubCommand(const char* arg)
}
}

if (optionsOut->testDir.getLength() == 0)
{
// If the test directory isn't set, use the "tests" directory
optionsOut->testDir = String("tests/");
}

return SLANG_OK;
}
3 changes: 3 additions & 0 deletions tools/slang-test/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ struct Options
// Directory to use when looking for binaries to run. If empty it's not set.
Slang::String binDir;

// Root directory to use when looking for test cases
Slang::String testDir;

// only run test cases with names have one of these prefixes.
Slang::List<Slang::String> testPrefixes;

Expand Down
8 changes: 3 additions & 5 deletions tools/slang-test/slang-test-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4427,10 +4427,10 @@ void runTestsInParallel(TestContext* context, int count, const F& f)
context->setTestReporter(originalReporter);
}

void runTestsInDirectory(TestContext* context, String directoryPath)
void runTestsInDirectory(TestContext* context)
{
List<String> files;
getFilesInDirectory(directoryPath, files);
getFilesInDirectory(context->options.testDir, files);
auto processFile = [&](String file)
{
if (shouldRunTest(context, file))
Expand Down Expand Up @@ -4865,9 +4865,7 @@ SlangResult innerMain(int argc, char** argv)
{
TestReporter::SuiteScope suiteScope(&reporter, "tests");
// Enumerate test files according to policy
// TODO: add more directories to this list
// TODO: allow for a command-line argument to select a particular directory
runTestsInDirectory(&context, "tests/");
runTestsInDirectory(&context);
}

// Run the unit tests (these are internal C++ tests - not specified via files in a
Expand Down

0 comments on commit e3b71cf

Please sign in to comment.