From ace4e334bc5fb299d2890b5e3f35dfd84ea32606 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 30 Nov 2021 16:34:52 -0500 Subject: Use test-server on CI (#2034) * #include an absolute path didn't work - because paths were taken to always be relative. * Vary what SpawnType is used, if one isn't explicitly set. * Terminate on linux if exec fails. * Use a more sophisticated sleeping mechanism. * Attempt to make CI tests to work on aarch64 debug. Small fixes. --- source/core/slang-http.cpp | 49 +++++++++++++++++++++++++++++++-- source/core/unix/slang-unix-process.cpp | 16 +++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) (limited to 'source/core') diff --git a/source/core/slang-http.cpp b/source/core/slang-http.cpp index 6a4bb4f92..bb5994635 100644 --- a/source/core/slang-http.cpp +++ b/source/core/slang-http.cpp @@ -287,6 +287,46 @@ SlangResult HTTPPacketConnection::update() return m_readResult; } + +namespace { // anonymous + +// Handles binary backoff like sleeping mechanism. +struct SleepState +{ + void sleep() + { + Process::sleepCurrentThread(m_intervalInMs); + _update(); + } + void reset() + { + m_intervalInMs = 0; + m_count = 0; + } + void _update() + { + const Int maxIntervalInMs = 32; + const Int initialCountThreshold = 4; + + ++m_count; + + const Int countThreshold = (m_intervalInMs == 0) ? initialCountThreshold : 1; + + // If we hit the count change the interval + if (m_count >= countThreshold) + { + m_intervalInMs = (m_intervalInMs == 0) ? 1 : Math::Min(m_intervalInMs * 2, maxIntervalInMs); + // Reset the count + m_count = 0; + } + } + + Int m_intervalInMs = 0; + Int m_count = 0; +}; + +} // anonymous + SlangResult HTTPPacketConnection::waitForResult(Int timeOutInMs) { m_readResult = SLANG_OK; @@ -300,6 +340,8 @@ SlangResult HTTPPacketConnection::waitForResult(Int timeOutInMs) startTick = Process::getClockTick(); } + SleepState sleepState; + while (m_readState == ReadState::Header || m_readState == ReadState::Content) { @@ -320,8 +362,11 @@ SlangResult HTTPPacketConnection::waitForResult(Int timeOutInMs) if (prevCount == m_readStream->getCount()) { - // Yield if it appears nothing was read. - Process::sleepCurrentThread(0); + sleepState.sleep(); + } + else + { + sleepState.reset(); } } diff --git a/source/core/unix/slang-unix-process.cpp b/source/core/unix/slang-unix-process.cpp index 5131e37ec..4e8344486 100644 --- a/source/core/unix/slang-unix-process.cpp +++ b/source/core/unix/slang-unix-process.cpp @@ -349,6 +349,8 @@ SlangResult UnixPipeStream::write(const void* buffer, size_t length) return StringEscapeUtil::getHandler(StringEscapeUtil::Style::Space); } +static const int kCannotExecute = 126; + /* static */SlangResult Process::create(const CommandLine& commandLine, Process::Flags flags, RefPtr& outProcess) { List argPtrs; @@ -376,6 +378,12 @@ SlangResult UnixPipeStream::write(const void* buffer, size_t length) return SLANG_FAIL; } + // TODO(JS): + // Ideally we'd have a mechanism to test if execvp can be successfully executed (at least in principal) before + // doing fork. Once we have forked we then have the problem of communicating to the parent process somehow. + // + // We could do a search down PATH and test files etc, but this seems to repeat a lot of the functionality of exec. + // pid_t childPid = fork(); if (childPid == -1) { @@ -402,6 +410,11 @@ SlangResult UnixPipeStream::write(const void* buffer, size_t length) ::close(stdinPipe[0]); ::close(stdinPipe[1]); + // TODO(JS): Strictly speaking if m_executableType is 'Path' then we shouldn't be searching. Ie which + // exec we use here should be dependent on the executable type. + + // Path = execvp + // Filename = execv ::execvp(argPtrs[0], (char* const*)&argPtrs[0]); // If we get here, then `exec` failed @@ -410,6 +423,9 @@ SlangResult UnixPipeStream::write(const void* buffer, size_t length) // the terminal but in the stderrPipe. fprintf(stderr, "error: `exec` failed\n"); + // Terminate with failure. + exit(kCannotExecute); + return SLANG_FAIL; } else -- cgit v1.2.3