/** * Copyright 2022 AntGroup CO., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ #pragma once #include #include "fma-common/configuration.h" #include "fma-common/logger.h" #include "fma-common/file_system.h" #include "fma-common/type_traits.h" #include "./ut_utils.h" #include "tiny-process-library/process.hpp" #include "core/global_config.h" namespace lgraph { inline std::unique_ptr StartLGraphServer(const GlobalConfig& conf, bool wait_till_up = true, bool skip_license_check = true) { std::string server_cmd = fma_common::StringFormatter::Format( "./lgraph_server -c lgraph_standalone.json" " --host {}" " --port {}" " --rpc_port {}" " --enable_backup_log {}" " --enable_ip_check {}" " --verbose {}" " --directory {}" " --ssl_auth {}" " --server_cert {}" " --server_key {}", conf.bind_host, conf.http_port, conf.rpc_port, conf.enable_backup_log, conf.enable_ip_check, conf.verbose, conf.db_dir, conf.enable_ssl, conf.server_cert_file, conf.server_key_file); UT_LOG() << "Starting lgraph_server with command: " << server_cmd; auto server = std::unique_ptr(new SubProcess(server_cmd)); if (wait_till_up && !server->ExpectOutput("Server started.", 10000)) { UT_WARN() << "Server failed to start, stderr:\n" << server->Stderr(); } return server; } inline void WriteCertFiles(const std::string& cert_path, const std::string& key_path) { static const std::string key = R"(-----BEGIN RSA PRIVATE KEY----- MIISJwIBAAKCBAEAsO/kA4wMREKkPXM4DN4qOECP8cZuqft7lojYN3z0RAv8No/1 5Y1QEfrjBdLhcw3WijJFXg6PFffsD68Sc+hUa7gDDPwAFUpj6X3zuwKDlDN9hrXA 48yVdFU4YvvjOMciv9cBhvX8f2T9XcfQjN/kW5c2dm+snq9mz2Fq2UF/rKyoMY9s XLc1uivddSA8ugo37TIZENmf52cnHf87M8e5tz1pMbYw+IO5mij25qWYk71fWpc9 XHsk36ryq8n9hwipFdDy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VmsONvgXECoDWSgaF681992dRheC25pd5SvaniAL rCe5q5wx9hgTABBQupXv5aJRXbHQgegHLoaOTVN0+e9Rh8vx+tDlHdQQ1PffH4Uc BasXxMrNfKrRNufEsNGMSD6/o4Btt/0Ae2IR7wBMgtbjbd4g7Yvl5GGL2lJ+4YDF JElVtDHgRlW1484xan1Q5BpvJBFytKTWytduYTMKmhpCXowRkj9jwRweG9XGhZgP lImiDB193JAqCRSasm4kPP/E4gAzH1GXkoJUA9vvjezPbByJv5ES0XZk3UQbnbh/ wK3vSsnXYvRUbvbBI/dhdd5wSAF1NjV7goHv0DfFhjOfV1Bvs1YP/erhJnHcQHMh M5MzF6QhnZsfYytSBNkB//gSYAlJ3Yx2YHpfpKU9ngjO9qRm0r5LHzgmw5vOCF4C /1UbHjeBCH4OO5/3/PUPeozE88FzgJu+Ii8DHDKjAfA0dB9IQcxSttlc8vDJOUBO eVtkfZxUfsQOosSFRcuGeaE2cDfOKAI/tmIj59kkv8otX/HmPEdu/vV4Lg== -----END RSA PRIVATE KEY----- )"; static const std::string cert = R"(-----BEGIN CERTIFICATE----- MIIJjTCCBXWgAwIBAgIUEpCR/xpm1eHdH2Z1/ryDNQ8pvdgwDQYJKoZIhvcNAQEL BQAwVjELMAkGA1UEBhMCQ04xEDAOBgNVBAgMB0JlaWppbmcxITAfBgNVBAoMGElu dGVybmV0IFdpZGdpdHMgUHR5IEx0ZDESMBAGA1UEAwwJVHVHcmFwaAgIMB4XDTIw MTAxMDA1MTUxNloXDTIwMTEwOTA1MTUxNlowVjELMAkGA1UEBhMCQ04xEDAOBgNV BAgMB0JlaWppbmcxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDES MBAGA1UEAwwJVHVHcmFwaAgIMIIEIjANBgkqhkiG9w0BAQEFAAOCBA8AMIIECgKC BAEAsO/kA4wMREKkPXM4DN4qOECP8cZuqft7lojYN3z0RAv8No/15Y1QEfrjBdLh cw3WijJFXg6PFffsD68Sc+hUa7gD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fafYmHg2gwYgRPkyfZBMBNI rp4d6sxM9QH7eXUh2lNSr1RGZo1o1Teo/qAdGAoDIyxOcyIks2cSlVY5poFn6fZH AMcxEHiQrZZhKJuKt6sgOGv3fUQRPw56S3Z4SKB4r4o+fryp5YvX4M+Wwc46Dj40 +VOnE2nQCYv5kvKGSWRAhRtgjtkG0JKmbIiimCFnzkREhWg9CsG0QSXQ7T3SUbsF z8z2X9MiB8N3j/gj4zkn0SoJzP55kp5M19m20a0tRvfZisMEx9G3/yhh+ZVwdpN2 49p6f3KFdeuaipwMCwxDP9K6AWnMOZgSawIDvNB6SUCeu9+eIibFSBpbjc9FHrCk s5wIkK6Mx9RcDkHh2sJMKWkVinoiTlh42vEOlMvRbVrR+aZTZWXDqSZRtBJ/Iou5 6gxQXnhCWHHecY2jXk9GS3ascWKkFDuHqIMZSDSFsXtM0W+zFNPwiL8FPnOiVB4Y V1Jb98rZU6zkcUSqnuVXK9JAdmXIwB2C4F0GUPOqc0cS3Ti67hD/MiS2i5qCJYHR AhGxAmOYswrx6w5bUF7gfYqWtD3RXiTjtEQs4oxm6pO/OAI8n7BfgBAa2Am6Q1C+ gXFA/V9UUWweDP57NZ7m3jvLdzLKJHaXgPXNCU5NFZa2lkjm6CeYxFOHpS6ifmyr rw== -----END CERTIFICATE----- )"; fma_common::OutputFmaStream key_file(key_path); key_file.Write(key.data(), key.size()); fma_common::OutputFmaStream cert_file(cert_path); cert_file.Write(cert.data(), cert.size()); } #define UT_FMT fma_common::StringFormatter::Format #define FMA_FMT fma_common::StringFormatter::Format class TestMarker { static int& GetLevel() { static int level = 0; return level; } std::string test_name_; int level_ = 0; public: explicit TestMarker(const std::string& test_name) { test_name_ = test_name; level_ = GetLevel()++; UT_LOG() << "\n" << std::string((level_ + 1) * 2, '*') << " BEGIN Testing " << test_name_; } ~TestMarker() { GetLevel()--; UT_LOG() << "\n" << std::string((level_ + 1) * 2, '*') << " END Testing " << test_name_; } }; } // namespace lgraph inline std::set& _Tests() { static std::set t; return t; } inline std::set& _Skips() { static std::set s; return s; } inline void _ParseTests(int* argc, char*** argv) { std::string tests = "all"; std::string skips; fma_common::Configuration conf; conf.Add(tests, "tests", true); conf.Add(skips, "skip", true); conf.ParseAndRemove(argc, argv); conf.Finalize(); auto ts = fma_common::Split(tests, ","); _Tests().insert(ts.begin(), ts.end()); auto ss = fma_common::Split(skips, ","); _Skips().insert(ss.begin(), ss.end()); for (auto& s : _Skips()) _Tests().erase(s); } #define ParseTestAndSkips(argc, argv) _ParseTests(&argc, &argv) #define MarkTestBegin(name) auto __t_marker__ = lgraph::TestMarker(name) #define DefineTest(name) \ if ((_Tests().find("all") != _Tests().end() || _Tests().find(name) != _Tests().end()) && \ _Skips().find(name) == _Skips().end()) class Barrier { size_t n_threads_; size_t waiting_threads_ = 0; size_t released_threads_ = 0; std::mutex mu_; std::condition_variable cond_; public: explicit Barrier(size_t n_threads) :n_threads_(n_threads), waiting_threads_(0) {} void Wait() { std::unique_lock lock(mu_); waiting_threads_++; if (waiting_threads_ == n_threads_) { released_threads_ = 1; cond_.notify_all(); while (released_threads_ != n_threads_) cond_.wait(lock); // all released, reset lock waiting_threads_ = 0; } else { while (waiting_threads_ != n_threads_) cond_.wait(lock); released_threads_++; cond_.notify_one(); } } };