summaryrefslogtreecommitdiff
path: root/test/utils/remote_execution/main-remote-execution.cpp
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2022-02-22 17:03:21 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2022-02-22 17:03:21 +0100
commit619def44c1cca9f3cdf63544d5f24f2c7a7d9b77 (patch)
tree01868de723cb82c86842f33743fa7b14e24c1fa3 /test/utils/remote_execution/main-remote-execution.cpp
downloadjustbuild-619def44c1cca9f3cdf63544d5f24f2c7a7d9b77.tar.gz
Initial self-hosting commit
This is the initial version of our tool that is able to build itself. In can be bootstrapped by ./bin/bootstrap.py Co-authored-by: Oliver Reiche <oliver.reiche@huawei.com> Co-authored-by: Victor Moreno <victor.moreno1@huawei.com>
Diffstat (limited to 'test/utils/remote_execution/main-remote-execution.cpp')
-rwxr-xr-xtest/utils/remote_execution/main-remote-execution.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/utils/remote_execution/main-remote-execution.cpp b/test/utils/remote_execution/main-remote-execution.cpp
new file mode 100755
index 00000000..3f435dcc
--- /dev/null
+++ b/test/utils/remote_execution/main-remote-execution.cpp
@@ -0,0 +1,50 @@
+#define CATCH_CONFIG_RUNNER
+#include <chrono>
+#include <cstdlib>
+#include <iostream>
+#include <sstream>
+#include <thread>
+
+#include "catch2/catch.hpp"
+#include "src/buildtool/execution_api/remote/config.hpp"
+#include "test/utils/logging/log_config.hpp"
+#include "test/utils/test_env.hpp"
+
+namespace {
+
+void wait_for_grpc_to_shutdown() {
+ // grpc_shutdown_blocking(); // not working
+ std::this_thread::sleep_for(std::chrono::seconds(1));
+}
+
+/// \brief Configure remote execution from test environment. In case the
+/// environment variable is malformed, we write a message and stop execution.
+/// \returns true If remote execution was successfully configured.
+[[nodiscard]] auto ConfigureRemoteExecution() -> bool {
+ auto address = ReadRemoteAddressFromEnv();
+ auto& config = RemoteExecutionConfig::Instance();
+ if (address and not config.SetAddress(*address)) {
+ Logger::Log(LogLevel::Error, "parsing address '{}' failed.", *address);
+ std::exit(EXIT_FAILURE);
+ }
+ return config.IsValidAddress();
+}
+
+} // namespace
+
+auto main(int argc, char* argv[]) -> int {
+ ConfigureLogging();
+
+ // In case remote execution address is not valid, we skip tests. This is in
+ // order to avoid tests being dependent on the environment.
+ if (not ConfigureRemoteExecution()) {
+ return EXIT_SUCCESS;
+ }
+
+ int result = Catch::Session().run(argc, argv);
+
+ // valgrind fails if we terminate before grpc's async shutdown threads exit
+ wait_for_grpc_to_shutdown();
+
+ return result;
+}