diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2021-11-24 09:34:05 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-24 09:34:05 -0500 |
| commit | bdc61bb8db321a8d788aa739b889354540a49ee0 (patch) | |
| tree | 16c564282a28d69e77d51855a41f11bdfa80fded /tools/test-proxy/test-proxy-main.cpp | |
| parent | 9e084ffab37c276d40931a58633041a2e10de623 (diff) | |
Remove test-proxy (#2027)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Use 'Process' to communicate with an command line tool.
* Remove slang-win-stream
* Tidy up windows ProcessUtil.
* First version of BufferedReadStream.
* Windows working IPC for steams.
* Test proxy count option.
* Split Process/ProcessUtil. Process is platform dependant. ProcessUtil are functions that are platform independent.
* First implementation of Unix Process interface.
* Unix process compiles on cygwin.
* Fix typo in unix process.
* Separate unix pipe stream error of invalid access, from pipe availability.
* Fix in standard line extraction.
* Make fd non blocking.
* Fix issues with Windows Process streams.
* Added UnixPipe.
* Some fixes around UnixPipeStream.
* Make a unix stream closed explicit.
* Hack to debug linux process/stream.
* Revert to old linux pipe handling.
* Pass executable path for unit tests.
Split out CommandLine into own source.
* Small improvements in process/command line.
* Check process behavior with crash.
* Make stderr and stdout unbuffered for crash testing.
* Only turn disable buffering in crash test.
* Disable crash test on CI.
* Fix crash on clang/linux.
* Enable crash test.
Remove _appendBuffer as can use StreamUtil functionality.
* Added inital processing for http headers.
* Small improvements to HttpHeader.
* First pass HTTPPacketConnection working on windows.
* Enable other Process communication tests.
* Update comments.
* WIP JSON RPC.
* Add terminate to Process.
Made JSONRPC a Util.
* Small tidy up around HTTPPacketConnection.
* Improve process termination options.
* WIP for test-server.
* Add diagnostics error handling to test-server.
* Improved JSON support.
Parsing/creating JSON-RPC messages.
* WIP JSONRPC parsing.
* First pass RttiInfo support.
* WIP converting between JSON/native types.
* Project files.
* Split out RttiUtil.
Made RttiInfo constuction thread safe.
* WIP RTTI<->JSON.
* Add diagnostics to JSON<->native conversions.
* Make RttiInfo for structs globals. Avoids problem around derived types (like pointers), being able to cause an abort.
* Add pointer support to RTTI.
Fixed some compilation issues on linux.
* Add fixed array support.
* Added Rtti unit test.
* Add rtti unit test.
* Split out quoted/unquoted key handling.
Fix bugs in JSON value/container.
Added JSON native test.
* Make default array allocator use malloc/free.
Remove the new[] handler (doesn't work on visuals studio).
* Fix for linux warning.
* Remove some test code.
* Fix issues on x86 win.
* Fix warning on aarch64.
* Fix some bugs in JSON parsing/handling.
Make Rtti work copy/dtor/ctor struct types.
* Testing JSON<->native with fixed array.
Make makeArrayView explicit if it's just a single value.
Added array type.
* Fix getting arrayView.
* Improve JSON diagnostic name.
* First pass refactor using Rtti for JSON RPC.
* First pass of test server using RTTI/JSON-RPC.
* Added JSONRPCConnection.
* Fix some naming issues.
* First pass of test-server working.
* Added unit test support for JSON-RPC test server.
* Fix compilation issues on linux around template handling.
* Typo fix.
* Fix a bug around SourceLoc lookup with JSONContainer.
* Set the console type to console for ISlangWriters.
* Small improvements to test-server.
* Small improvements in test-server.
* Small fix.
* Remove test-proxy. Make test-process a process that can be used to unit test 'Process'.
Adding mechanism to control spawning that will create a new process for every test.
* Ability to remove source manager for JSONValue.
Diffstat (limited to 'tools/test-proxy/test-proxy-main.cpp')
| -rw-r--r-- | tools/test-proxy/test-proxy-main.cpp | 406 |
1 files changed, 0 insertions, 406 deletions
diff --git a/tools/test-proxy/test-proxy-main.cpp b/tools/test-proxy/test-proxy-main.cpp deleted file mode 100644 index bcb8f2a92..000000000 --- a/tools/test-proxy/test-proxy-main.cpp +++ /dev/null @@ -1,406 +0,0 @@ -// main.cpp - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "../../source/core/slang-secure-crt.h" - -#include "../../slang-com-helper.h" - -#include "../../source/core/slang-string.h" -#include "../../source/core/slang-io.h" -#include "../../source/core/slang-writer.h" -#include "../../source/core/slang-string-util.h" -#include "../../source/core/slang-process-util.h" - -#include "../../source/core/slang-shared-library.h" - -#include "../../source/core/slang-test-tool-util.h" -#include "../../source/core/slang-http.h" - -#include "tools/unit-test/slang-unit-test.h" - -namespace TestProxy -{ -using namespace Slang; - -class TestReporter : public ITestReporter -{ -public: - // ITestReporter - virtual SLANG_NO_THROW void SLANG_MCALL startTest(const char* testName) SLANG_OVERRIDE { } - virtual SLANG_NO_THROW void SLANG_MCALL addResult(TestResult result)SLANG_OVERRIDE; - virtual SLANG_NO_THROW void SLANG_MCALL addResultWithLocation(TestResult result, const char* testText, const char* file, int line) SLANG_OVERRIDE; - virtual SLANG_NO_THROW void SLANG_MCALL addResultWithLocation(bool testSucceeded, const char* testText, const char* file, int line) SLANG_OVERRIDE; - virtual SLANG_NO_THROW void SLANG_MCALL addExecutionTime(double time) SLANG_OVERRIDE { } - virtual SLANG_NO_THROW void SLANG_MCALL message(TestMessageType type, const char* message) SLANG_OVERRIDE; - virtual SLANG_NO_THROW void SLANG_MCALL endTest() SLANG_OVERRIDE { } - - StringBuilder m_buf; - Index m_failCount = 0; - Index m_testCount = 0; -}; - - -void TestReporter::message(TestMessageType type, const char* message) -{ - if (type == TestMessageType::RunError || - type == TestMessageType::TestFailure) - { - m_failCount++; - } - - m_buf << message << "\n"; -} - -void TestReporter::addResultWithLocation(TestResult result, const char* testText, const char* file, int line) -{ - if (result == TestResult::Fail) - { - addResultWithLocation(false, testText, file, line); - } - else - { - m_testCount++; - } -} - -void TestReporter::addResultWithLocation(bool testSucceeded, const char* testText, const char* file, int line) -{ - m_testCount++; - - if (testSucceeded) - { - return; - } - - m_buf << "[Failed]: " << testText << "\n"; - m_buf << file << ":" << line << "\n"; - - m_failCount++; -} - -void TestReporter::addResult(TestResult result) -{ - if (result == TestResult::Fail) - { - m_failCount++; - } -} - -static SlangResult _createSlangSession(const char* exePath, int argc, const char* const* argv, ComPtr<slang::IGlobalSession>& outSession) -{ - - ComPtr<slang::IGlobalSession> session; - - // The sharedSession always has a pre-loaded stdlib, is sharedSession is not nullptr. - // This differed test checks if the command line has an option to setup the stdlib. - // If so we *don't* use the sharedSession, and create a new stdlib-less session just for this compilation. - if (TestToolUtil::hasDeferredStdLib(argc, argv)) - { - SLANG_RETURN_ON_FAIL(slang_createGlobalSessionWithoutStdLib(SLANG_API_VERSION, session.writeRef())); - TestToolUtil::setSessionDefaultPreludeFromExePath(exePath, session); - } - else - { - // Just create the global session in the regular way if there isn't one set - SLANG_RETURN_ON_FAIL(slang_createGlobalSession(SLANG_API_VERSION, session.writeRef())); - TestToolUtil::setSessionDefaultPreludeFromExePath(exePath, session); - } - - outSession.swap(session); - return SLANG_OK; -} - -static void _makeStdStreamsUnbuffered() -{ - // Make these streams unbuffered - setvbuf(stdout, nullptr, _IONBF, 0); - setvbuf(stderr, nullptr, _IONBF, 0); -} - -static SlangResult _outputCount(int argc, const char* const* argv) -{ - if (argc < 3) - { - return SLANG_FAIL; - } - // Get the count - const Index count = StringToInt(argv[2]); - - // If we want to crash - Index crashIndex = -1; - if (argc > 3) - { - // When we crash, we want to make sure everything is flushed... - _makeStdStreamsUnbuffered(); - crashIndex = StringToInt(argv[3]); - } - - FILE* fileOut = stdout; - - StringBuilder buf; - for (Index i = 0; i < count; ++i) - { - buf.Clear(); - buf << i << "\n"; - - fwrite(buf.getBuffer(), 1, buf.getLength(), fileOut); - - if (i == crashIndex) - { - // Use to simulate a crash. - SLANG_BREAKPOINT(0); - throw; - } - } - - // NOTE! There is no flush here, we want to see if everything works if we just stream out. - return SLANG_OK; -} - -static SlangResult _outputReflect() -{ - // Read lines from std input. - // When hit line with just 'end', terminate - - // Get in as Stream - - RefPtr<Stream> stdinStream; - Process::getStdStream(Process::StreamType::StdIn, stdinStream); - - FILE* fileOut = stdout; - - List<Byte> buffer; - - Index lineCount = 0; - Index startIndex = 0; - - while (true) - { - SLANG_RETURN_ON_FAIL(StreamUtil::read(stdinStream, 0, buffer)); - - while (true) - { - UnownedStringSlice slice((const char*)buffer.begin() + startIndex, (const char*)buffer.end()); - UnownedStringSlice line; - - if (!StringUtil::extractLine(slice, line) || slice.begin() == nullptr) - { - break; - } - - // Process the line - if (line == UnownedStringSlice::fromLiteral("end")) - { - return SLANG_OK; - } - - // Write the text to the output stream - fwrite(line.begin(), 1, line.getLength(), fileOut); - fputc('\n', fileOut); - - lineCount++; - - // Move the start index forward - const Index newStartIndex = slice.begin() ? Index(slice.begin() - (const char*)buffer.getBuffer()) : buffer.getCount(); - SLANG_ASSERT(newStartIndex > startIndex); - startIndex = newStartIndex; - } - } -} - -static SlangResult _httpReflect(int argc, const char* const* argv) -{ - SLANG_UNUSED(argc); - SLANG_UNUSED(argv); - - RefPtr<Stream> stdinStream, stdoutStream; - - Process::getStdStream(Process::StreamType::StdIn, stdinStream); - Process::getStdStream(Process::StreamType::StdOut, stdoutStream); - - RefPtr<BufferedReadStream> readStream(new BufferedReadStream(stdinStream)); - - RefPtr<HTTPPacketConnection> connection = new HTTPPacketConnection(readStream, stdoutStream); - - while (connection->isActive()) - { - // Block waiting for content (or error/closed) - SLANG_RETURN_ON_FAIL(connection->waitForResult()); - - // If we have content do something with it - if (connection->hasContent()) - { - auto content = connection->getContent(); - - // If it just holds 'end' then we are done - const UnownedStringSlice slice((const char*)content.begin(), content.getCount()); - - if (slice == UnownedStringSlice::fromLiteral("end")) - { - break; - } - - // Else reflect it back - SLANG_RETURN_ON_FAIL(connection->write(content.begin(), content.getCount())); - - // Consume that content/packet - connection->consumeContent(); - } - } - - return SLANG_OK; -} - -static SlangResult execute(int argc, const char*const* argv) -{ - typedef Slang::TestToolUtil::InnerMainFunc InnerMainFunc; - - if (argc < 2) - { - return SLANG_FAIL; - } - - String exePath = Path::getParentDirectory(argv[0]); - - // The 'exeName' of the tool. - const String toolName = argv[1]; - - if (toolName == "reflect") - { - return _outputReflect(); - } - - if (toolName == "count") - { - return _outputCount(argc, argv); - } - - if (toolName == "http-reflect") - { - return _httpReflect(argc, argv); - } - - { - StringBuilder sharedLibToolBuilder; - sharedLibToolBuilder.append(toolName); - sharedLibToolBuilder.append("-tool"); - - auto toolPath = Path::combine(exePath, sharedLibToolBuilder); - - ComPtr<ISlangSharedLibrary> sharedLibrary; - if (SLANG_SUCCEEDED(DefaultSharedLibraryLoader::getSingleton()->loadSharedLibrary(toolPath.getBuffer(), sharedLibrary.writeRef()))) - { - // Assume we will used the shared session - ComPtr<slang::IGlobalSession> session; - SLANG_RETURN_ON_FAIL(_createSlangSession(argv[0], argc - 2, argv + 2, session)); - - auto func = (InnerMainFunc)sharedLibrary->findFuncByName("innerMain"); - if (!func) - { - return SLANG_FAIL; - } - - // Work out the args sent to the shared library - List<const char*> args; - args.add(argv[0]); - args.addRange(argv + 2, Index(argc - 2)); - - RefPtr<StdWriters> stdWriters = StdWriters::createDefault(); - - const SlangResult res = func(stdWriters, session, int(args.getCount()), args.begin()); - return res; - } - } - - // Okay lets assume it's a unit test - { - auto toolPath = Path::combine(exePath, toolName); - - ComPtr<ISlangSharedLibrary> sharedLibrary; - SLANG_RETURN_ON_FAIL(SLANG_SUCCEEDED(DefaultSharedLibraryLoader::getSingleton()->loadSharedLibrary(toolPath.getBuffer(), sharedLibrary.writeRef()))); - - // get the unit test export name - - UnitTestGetModuleFunc getModuleFunc = (UnitTestGetModuleFunc)sharedLibrary->findFuncByName("slangUnitTestGetModule"); - if (!getModuleFunc) - return SLANG_FAIL; - - IUnitTestModule* testModule = getModuleFunc(); - if (!testModule) - return SLANG_FAIL; - - // argv[0] exe, - // argv[1] tool - // argv[2] test name - // argv[3] test index - // argv[4] the enabled apis - - if (argc < 5) - { - return SLANG_FAIL; - } - - TestReporter testReporter; - - testModule->setTestReporter(&testReporter); - - Int enabledApis; - SLANG_RETURN_ON_FAIL(StringUtil::parseInt(UnownedStringSlice(argv[4]), enabledApis)); - - Int testIndex; - SLANG_RETURN_ON_FAIL(StringUtil::parseInt(UnownedStringSlice(argv[3]), testIndex)); - - // Assume we will used the shared session - ComPtr<slang::IGlobalSession> session; - SLANG_RETURN_ON_FAIL(_createSlangSession(argv[0], argc - 5, argv + 5, session)); - - UnitTestContext unitTestContext; - unitTestContext.slangGlobalSession = session; - unitTestContext.workDirectory = ""; - unitTestContext.enabledApis = RenderApiFlags(enabledApis); - unitTestContext.executableDirectory = exePath.getBuffer(); - - auto testCount = testModule->getTestCount(); - SLANG_ASSERT(testIndex >= 0 && testIndex < testCount); - - UnitTestFunc testFunc = testModule->getTestFunc(testIndex); - - try - { - testFunc(&unitTestContext); - } - catch (...) - { - testReporter.m_failCount++; - } - - if (testReporter.m_failCount > 0) - { - // Write out to stderr... - auto writers = StdWriters::createDefault(); - writers->getError().put(testReporter.m_buf.getUnownedSlice()); - return SLANG_FAIL; - } - - if (testReporter.m_testCount == 0) - { - return SLANG_E_NOT_AVAILABLE; - } - - return SLANG_OK; - } - - return SLANG_E_NOT_AVAILABLE; -} - -} // namespace TestProxy - -int main(int argc, const char* const* argv) -{ - using namespace TestProxy; - SlangResult res = execute(argc, argv); - return (int)TestToolUtil::getReturnCode(res); -} |
