From 49ed6b60d662906f290578f802f80b0ead1a2b9d Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 12 Dec 2018 08:57:48 -0500 Subject: Running tests in slang-test process (#740) * First pass at having an interface to write text to that can be replaced. Simplifed and made more rigerous the interface used to write formatted strings. * Added AppContext to simplify setting up and parsing around of streams. * Added more simplified way to get the std error/out from AppContext. * Work in progress using dll for tools to speed up testing. * First pass at ISlangWriter interface. * Added support for writing VaArgs. Added NullWriter. * Use ISlangWriter for output. * Use ISlangWriter for output - replacing OutputCallback. Make IRDump go to ISlangWriter * SlangWriterTargetType -> SlangWriterChannel Improvements around AppContext * Shared library working with slang-reflection-test. * Dll testing working for render-test. * Include va_list definintion from header. * Fix errors from clang. * Fix typo for linux. * Added -usexes option * Fix typo. * Fix arguments problem on linux. * Fix typo for linux. * Add windows tool shared library projects. * Fix warning from x86 win build. Fix signed warning from slang-test/main.cpp * First attempt at getting premake to work on travis, and run tests. * Try moving build out into script. * Invoke bash scripts so they don't have to be executable. * Drive configuration/tests from env parameters set by travis * Try using source to run travis tests. * Remove the build.linux directory - but doing so will overwrite Makefile. * Made -fno-delete-null-pointer-checks gcc only. * Try to fix warning from -fno-delete-null-pointer-checks * Turn of warnings for unknown switches. * Try to make premake choose the correct tooling. * Disabled missing braces warning. * Disable -Wundefined-var-template on clang. * -Wunused-function disabled for clang. * Fix typo due to SlangBool. * Remove this nullptr tests. * "-Wno-unused-private-field" for clang. * Added "-Wno-undefined-bool-conversion" * Add DominatorList::end fix. * Split scripts into travis_build.sh travis_test.sh * Fix gcc/clang template pre-declaration issue around QualType. * Fix premake to build such that pthread correctly links with slang-glslang --- source/slang/compiler.cpp | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'source/slang/compiler.cpp') diff --git a/source/slang/compiler.cpp b/source/slang/compiler.cpp index 0f333aa3d..172bc33b9 100644 --- a/source/slang/compiler.cpp +++ b/source/slang/compiler.cpp @@ -862,6 +862,23 @@ SlangResult dissassembleDXILUsingDXC( } } + static void writeOutputFile( + CompileRequest* compileRequest, + ISlangWriter* writer, + String const& path, + void const* data, + size_t size) + { + + if (SLANG_FAILED(writer->write((const char*)data, size))) + { + compileRequest->mSink.diagnose( + SourceLoc(), + Diagnostics::cannotWriteOutputFile, + path); + } + } + static void writeOutputFile( CompileRequest* compileRequest, String const& path, @@ -924,14 +941,10 @@ SlangResult dissassembleDXILUsingDXC( } static void writeOutputToConsole( - CompileRequest*, + ISlangWriter* writer, String const& text) { - fwrite( - text.begin(), - text.end() - text.begin(), - 1, - stdout); + writer->write(text.Buffer(), text.Length()); } static void writeEntryPointResultToStandardOutput( @@ -941,17 +954,19 @@ SlangResult dissassembleDXILUsingDXC( { auto compileRequest = entryPoint->compileRequest; + ISlangWriter* writer = compileRequest->getWriter(WriterChannel::StdOutput); + switch (result.format) { case ResultFormat::Text: - writeOutputToConsole(compileRequest, result.outputString); + writeOutputToConsole(writer, result.outputString); break; case ResultFormat::Binary: { auto& data = result.outputBinary; - int stdoutFileDesc = _fileno(stdout); - if (_isatty(stdoutFileDesc)) + + if (writer->isConsole()) { // Writing to console, so we need to generate text output. @@ -964,7 +979,7 @@ SlangResult dissassembleDXILUsingDXC( dissassembleDXBC(compileRequest, data.begin(), data.end() - data.begin(), assembly); - writeOutputToConsole(compileRequest, assembly); + writeOutputToConsole(writer, assembly); } break; #endif @@ -977,7 +992,7 @@ SlangResult dissassembleDXILUsingDXC( data.begin(), data.end() - data.begin(), assembly); - writeOutputToConsole(compileRequest, assembly); + writeOutputToConsole(writer, assembly); } break; #endif @@ -988,7 +1003,7 @@ SlangResult dissassembleDXILUsingDXC( dissassembleSPIRV(compileRequest, data.begin(), data.end() - data.begin(), assembly); - writeOutputToConsole(compileRequest, assembly); + writeOutputToConsole(writer, assembly); } break; @@ -1000,12 +1015,11 @@ SlangResult dissassembleDXILUsingDXC( else { // Redirecting stdout to a file, so do the usual thing - #ifdef _WIN32 - _setmode(stdoutFileDesc, _O_BINARY); - #endif + writer->setMode(SLANG_WRITER_MODE_BINARY); + writeOutputFile( compileRequest, - stdout, + writer, "stdout", data.begin(), data.end() - data.begin()); -- cgit v1.2.3