diff options
author | Aleksandr <ivansduck@gmail.com> | 2022-02-10 16:47:52 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:52 +0300 |
commit | ea6c5b7f172becca389cacaff7d5f45f6adccbe6 (patch) | |
tree | d16cef493ac1e092b4a03ab9437ec06ffe3d188f /library/cpp | |
parent | 37de222addabbef336dcaaea5f7c7645a629fc6d (diff) | |
download | ydb-ea6c5b7f172becca389cacaff7d5f45f6adccbe6.tar.gz |
Restoring authorship annotation for Aleksandr <ivansduck@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp')
22 files changed, 416 insertions, 416 deletions
diff --git a/library/cpp/accurate_accumulate/benchmark/metrics/ya.make b/library/cpp/accurate_accumulate/benchmark/metrics/ya.make index 5d532e1479..9c62aad212 100644 --- a/library/cpp/accurate_accumulate/benchmark/metrics/ya.make +++ b/library/cpp/accurate_accumulate/benchmark/metrics/ya.make @@ -2,12 +2,12 @@ OWNER(yazevnul) PY2TEST() -SIZE(LARGE) +SIZE(LARGE) TAG( ya:force_sandbox sb:intel_e5_2660v1 - ya:fat + ya:fat ) TEST_SRCS(main.py) diff --git a/library/cpp/actors/interconnect/ut_fat/ya.make b/library/cpp/actors/interconnect/ut_fat/ya.make index 6e58d08154..5218401045 100644 --- a/library/cpp/actors/interconnect/ut_fat/ya.make +++ b/library/cpp/actors/interconnect/ut_fat/ya.make @@ -7,7 +7,7 @@ OWNER( SIZE(LARGE) -TAG(ya:fat) +TAG(ya:fat) SRCS( main.cpp diff --git a/library/cpp/digest/argonish/ut_fat/ya.make b/library/cpp/digest/argonish/ut_fat/ya.make index 94ebda9225..605524bedb 100644 --- a/library/cpp/digest/argonish/ut_fat/ya.make +++ b/library/cpp/digest/argonish/ut_fat/ya.make @@ -16,6 +16,6 @@ TAG( ya:force_sandbox ) -SIZE(LARGE) +SIZE(LARGE) END() diff --git a/library/cpp/http/io/fuzz/ya.make b/library/cpp/http/io/fuzz/ya.make index 8b3ccb1969..d4d4b8cdbf 100644 --- a/library/cpp/http/io/fuzz/ya.make +++ b/library/cpp/http/io/fuzz/ya.make @@ -9,8 +9,8 @@ PEERDIR( library/cpp/http/io ) -SIZE(MEDIUM) - +SIZE(MEDIUM) + SRCS( main.cpp ) diff --git a/library/cpp/http/io/stream_ut.cpp b/library/cpp/http/io/stream_ut.cpp index 1ea35df675..48c9307dd4 100644 --- a/library/cpp/http/io/stream_ut.cpp +++ b/library/cpp/http/io/stream_ut.cpp @@ -84,8 +84,8 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) { Y_UNIT_TEST(TestHttpInput) { TString res = "I'm a teapot"; - TPortManager pm; - const ui16 port = pm.GetPort(); + TPortManager pm; + const ui16 port = pm.GetPort(); TTestHttpServer serverImpl(res); THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true).EnableCompression(true)); @@ -238,8 +238,8 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) { Y_UNIT_TEST(TestMinRequest) { TString res = "qqqqqq"; - TPortManager pm; - const ui16 port = pm.GetPort(); + TPortManager pm; + const ui16 port = pm.GetPort(); TTestHttpServer serverImpl(res); THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true).EnableCompression(true)); @@ -264,8 +264,8 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) { Y_UNIT_TEST(TestResponseWithBlanks) { TString res = "qqqqqq\r\n\r\nsdasdsad\r\n"; - TPortManager pm; - const ui16 port = pm.GetPort(); + TPortManager pm; + const ui16 port = pm.GetPort(); TTestHttpServer serverImpl(res); THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true).EnableCompression(true)); diff --git a/library/cpp/http/server/http_ut.cpp b/library/cpp/http/server/http_ut.cpp index cc62bb988e..cf6f9c2c63 100644 --- a/library/cpp/http/server/http_ut.cpp +++ b/library/cpp/http/server/http_ut.cpp @@ -322,8 +322,8 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { Y_UNIT_TEST(TestEchoServer) { TString res = TestData(); - TPortManager pm; - const ui16 port = pm.GetPort(); + TPortManager pm; + const ui16 port = pm.GetPort(); const bool trueFalse[] = {true, false}; TEchoServer serverImpl(res); @@ -428,8 +428,8 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { * Data should be large enough not to fit into socket buffer **/ TString res = TestData(10 * 1024 * 1024); - TPortManager portManager; - const ui16 port = portManager.GetPort(); + TPortManager portManager; + const ui16 port = portManager.GetPort(); TEchoServer serverImpl(res); THttpServer::TOptions options(port); options.EnableKeepAlive(true); diff --git a/library/cpp/json/yson/ut/ya.make b/library/cpp/json/yson/ut/ya.make index 4ceb65b279..1a4a193b55 100644 --- a/library/cpp/json/yson/ut/ya.make +++ b/library/cpp/json/yson/ut/ya.make @@ -15,10 +15,10 @@ PEERDIR( library/cpp/testing/unittest ) -SIZE(LARGE) - -TAG(ya:fat) +SIZE(LARGE) +TAG(ya:fat) + TIMEOUT(600) SRCS( diff --git a/library/cpp/scheme/tests/fuzz_json/ya.make b/library/cpp/scheme/tests/fuzz_json/ya.make index 0d91c70585..e398cfc5dd 100644 --- a/library/cpp/scheme/tests/fuzz_json/ya.make +++ b/library/cpp/scheme/tests/fuzz_json/ya.make @@ -7,8 +7,8 @@ OWNER( velavokr ) -SIZE(MEDIUM) - +SIZE(MEDIUM) + SRCS( fuzz_json.cpp ) diff --git a/library/cpp/string_utils/base64/bench/metrics/ya.make b/library/cpp/string_utils/base64/bench/metrics/ya.make index b0406516c3..7185c725b6 100644 --- a/library/cpp/string_utils/base64/bench/metrics/ya.make +++ b/library/cpp/string_utils/base64/bench/metrics/ya.make @@ -5,12 +5,12 @@ OWNER( PY2TEST() -SIZE(LARGE) +SIZE(LARGE) TAG( ya:force_sandbox sb:intel_e5_2660v1 - ya:fat + ya:fat ) TEST_SRCS(main.py) diff --git a/library/cpp/testing/benchmark/examples/metrics/ya.make b/library/cpp/testing/benchmark/examples/metrics/ya.make index a9dbdca9fa..0ba17e4545 100644 --- a/library/cpp/testing/benchmark/examples/metrics/ya.make +++ b/library/cpp/testing/benchmark/examples/metrics/ya.make @@ -5,12 +5,12 @@ OWNER( PY2TEST() -SIZE(LARGE) +SIZE(LARGE) TAG( ya:force_sandbox sb:intel_e5_2660v1 - ya:fat + ya:fat ) TEST_SRCS(main.py) diff --git a/library/cpp/testing/common/env.cpp b/library/cpp/testing/common/env.cpp index fa3a47fe16..436af91845 100644 --- a/library/cpp/testing/common/env.cpp +++ b/library/cpp/testing/common/env.cpp @@ -3,19 +3,19 @@ #include <build/scripts/c_templates/svnversion.h> #include <util/folder/dirut.h> -#include <util/folder/path.h> -#include <util/generic/singleton.h> +#include <util/folder/path.h> +#include <util/generic/singleton.h> #include <util/stream/file.h> -#include <util/stream/fwd.h> -#include <util/system/env.h> -#include <util/system/file.h> -#include <util/system/file_lock.h> -#include <util/system/guard.h> - +#include <util/stream/fwd.h> +#include <util/system/env.h> +#include <util/system/file.h> +#include <util/system/file_lock.h> +#include <util/system/guard.h> + #include <library/cpp/json/json_reader.h> #include <library/cpp/json/json_value.h> -#include <library/cpp/json/json_writer.h> - +#include <library/cpp/json/json_writer.h> + TString ArcadiaSourceRoot() { if (const auto& sourceRoot = NPrivate::GetTestEnv().SourceRoot) { return sourceRoot; @@ -63,89 +63,89 @@ TString GetArcadiaTestsData() { return {}; } - + TString GetWorkPath() { TString workPath = NPrivate::GetTestEnv().WorkPath; if (workPath) { return workPath; - } + } return NPrivate::GetCwd(); -} - +} + TFsPath GetOutputPath() { return GetWorkPath() + "/testing_out_stuff"; } -const TString& GetRamDrivePath() { +const TString& GetRamDrivePath() { return NPrivate::GetTestEnv().RamDrivePath; -} - +} + const TString& GetYtHddPath() { return NPrivate::GetTestEnv().YtHddPath; } -const TString& GetOutputRamDrivePath() { +const TString& GetOutputRamDrivePath() { return NPrivate::GetTestEnv().TestOutputRamDrivePath; -} - -const TString& GdbPath() { - return NPrivate::GetTestEnv().GdbPath; -} - -const TString& GetTestParam(TStringBuf name) { - const static TString def = ""; - return GetTestParam(name, def); -} - -const TString& GetTestParam(TStringBuf name, const TString& def) { - auto& testParameters = NPrivate::GetTestEnv().TestParameters; - auto it = testParameters.find(name.data()); - if (it != testParameters.end()) { - return it->second; - } - return def; -} - -void AddEntryToCoreSearchFile(const TString& filename, TStringBuf cmd, int pid, const TFsPath& binaryPath = TFsPath(), const TFsPath& cwd = TFsPath()) { - auto lock = TFileLock(filename); - TGuard<TFileLock> guard(lock); - - TOFStream output(TFile(filename, WrOnly | ForAppend | OpenAlways)); - - NJson::TJsonWriter writer(&output, false); - writer.OpenMap(); - writer.Write("cmd", cmd); - writer.Write("pid", pid); - if (binaryPath) { - writer.Write("binary_path", binaryPath); - } - if (cwd) { - writer.Write("cwd", cwd); - } - writer.CloseMap(); - writer.Flush(); - - output.Write("\n"); -} - -void WatchProcessCore(int pid, const TFsPath& binaryPath, const TFsPath& cwd) { - auto& filename = NPrivate::GetTestEnv().CoreSearchFile; - if (filename) { - AddEntryToCoreSearchFile(filename, "add", pid, binaryPath, cwd); - } -} - -void StopProcessCoreWatching(int pid) { - auto& filename = NPrivate::GetTestEnv().CoreSearchFile; - if (filename) { - AddEntryToCoreSearchFile(filename, "drop", pid); - } -} - +} + +const TString& GdbPath() { + return NPrivate::GetTestEnv().GdbPath; +} + +const TString& GetTestParam(TStringBuf name) { + const static TString def = ""; + return GetTestParam(name, def); +} + +const TString& GetTestParam(TStringBuf name, const TString& def) { + auto& testParameters = NPrivate::GetTestEnv().TestParameters; + auto it = testParameters.find(name.data()); + if (it != testParameters.end()) { + return it->second; + } + return def; +} + +void AddEntryToCoreSearchFile(const TString& filename, TStringBuf cmd, int pid, const TFsPath& binaryPath = TFsPath(), const TFsPath& cwd = TFsPath()) { + auto lock = TFileLock(filename); + TGuard<TFileLock> guard(lock); + + TOFStream output(TFile(filename, WrOnly | ForAppend | OpenAlways)); + + NJson::TJsonWriter writer(&output, false); + writer.OpenMap(); + writer.Write("cmd", cmd); + writer.Write("pid", pid); + if (binaryPath) { + writer.Write("binary_path", binaryPath); + } + if (cwd) { + writer.Write("cwd", cwd); + } + writer.CloseMap(); + writer.Flush(); + + output.Write("\n"); +} + +void WatchProcessCore(int pid, const TFsPath& binaryPath, const TFsPath& cwd) { + auto& filename = NPrivate::GetTestEnv().CoreSearchFile; + if (filename) { + AddEntryToCoreSearchFile(filename, "add", pid, binaryPath, cwd); + } +} + +void StopProcessCoreWatching(int pid) { + auto& filename = NPrivate::GetTestEnv().CoreSearchFile; + if (filename) { + AddEntryToCoreSearchFile(filename, "drop", pid); + } +} + bool FromYaTest() { return NPrivate::GetTestEnv().IsRunningFromTest; -} +} namespace NPrivate { TTestEnv::TTestEnv() { @@ -161,9 +161,9 @@ namespace NPrivate { RamDrivePath = ""; YtHddPath = ""; TestOutputRamDrivePath = ""; - GdbPath = ""; - CoreSearchFile = ""; - TestParameters.clear(); + GdbPath = ""; + CoreSearchFile = ""; + TestParameters.clear(); const TString contextFilename = GetEnv("YA_TEST_CONTEXT_FILE"); if (contextFilename) { @@ -206,23 +206,23 @@ namespace NPrivate { if (value) { TestOutputRamDrivePath = value->GetStringSafe(""); } - - value = context.GetValueByPath("runtime.gdb_bin"); - if (value) { - GdbPath = value->GetStringSafe(""); - } - - value = context.GetValueByPath("runtime.test_params"); - if (value) { - for (const auto& entry : context.GetValueByPath("runtime.test_params")->GetMap()) { - TestParameters[entry.first] = entry.second.GetStringSafe(""); - } - } - - value = context.GetValueByPath("internal.core_search_file"); - if (value) { - CoreSearchFile = value->GetStringSafe(""); - } + + value = context.GetValueByPath("runtime.gdb_bin"); + if (value) { + GdbPath = value->GetStringSafe(""); + } + + value = context.GetValueByPath("runtime.test_params"); + if (value) { + for (const auto& entry : context.GetValueByPath("runtime.test_params")->GetMap()) { + TestParameters[entry.first] = entry.second.GetStringSafe(""); + } + } + + value = context.GetValueByPath("internal.core_search_file"); + if (value) { + CoreSearchFile = value->GetStringSafe(""); + } } if (!YtHddPath) { @@ -257,10 +257,10 @@ namespace NPrivate { IsRunningFromTest = (fromEnv == "1"); } - void TTestEnv::AddTestParam(TStringBuf name, TStringBuf value) { - TestParameters[TString{name}] = value; - } - + void TTestEnv::AddTestParam(TStringBuf name, TStringBuf value) { + TestParameters[TString{name}] = value; + } + TString GetCwd() { try { return NFs::CurrentWorkingDirectory(); diff --git a/library/cpp/testing/common/env.h b/library/cpp/testing/common/env.h index 7b89aa1bed..9f405145f1 100644 --- a/library/cpp/testing/common/env.h +++ b/library/cpp/testing/common/env.h @@ -1,7 +1,7 @@ #pragma once -#include <unordered_map> - +#include <unordered_map> + #include <util/folder/path.h> #include <util/generic/string.h> #include <util/generic/strbuf.h> @@ -14,7 +14,7 @@ TString ArcadiaSourceRoot(); // for the instance: there is 2 files in folder test example_ut.cpp and example.data, so full path to test/example.data can be obtained // from example_ut.cpp as ArcadiaFromCurrentLocation(__SOURCE_FILE__, "example.data") TString ArcadiaFromCurrentLocation(TStringBuf where, TStringBuf path); - + // @brief return build folder path TString BuildRoot(); @@ -34,26 +34,26 @@ TString GetWorkPath(); TFsPath GetOutputPath(); // @brief return path from env:YA_TEST_RAM_DRIVE_PATH -const TString& GetRamDrivePath(); - +const TString& GetRamDrivePath(); + // @brief return path from env:YA_TEST_OUTPUT_RAM_DRIVE_PATH -const TString& GetOutputRamDrivePath(); - -// @brief return test parameter by name. If not exists, return an empty string -const TString& GetTestParam(TStringBuf name); - -// @brief return test parameter by name. If not exists, return specified default value -const TString& GetTestParam(TStringBuf name, const TString& def); - -// @brief return path to the gdb -const TString& GdbPath(); - -// @brief register the process. Test suite will be marked as failed if the process is terminated with a core dump file after testing -void WatchProcessCore(int pid, const TFsPath& binaryPath, const TFsPath& cwd = TFsPath()); - -// @brief mark the process as successfully completed - a test machinery won't try to recover core dump file for the process -void StopProcessCoreWatching(int pid); - +const TString& GetOutputRamDrivePath(); + +// @brief return test parameter by name. If not exists, return an empty string +const TString& GetTestParam(TStringBuf name); + +// @brief return test parameter by name. If not exists, return specified default value +const TString& GetTestParam(TStringBuf name, const TString& def); + +// @brief return path to the gdb +const TString& GdbPath(); + +// @brief register the process. Test suite will be marked as failed if the process is terminated with a core dump file after testing +void WatchProcessCore(int pid, const TFsPath& binaryPath, const TFsPath& cwd = TFsPath()); + +// @brief mark the process as successfully completed - a test machinery won't try to recover core dump file for the process +void StopProcessCoreWatching(int pid); + #define SRC_(path) ArcadiaFromCurrentLocation(__SOURCE_FILE__, path) namespace NPrivate { @@ -63,8 +63,8 @@ namespace NPrivate { void ReInitialize(); - void AddTestParam(TStringBuf name, TStringBuf value); - + void AddTestParam(TStringBuf name, TStringBuf value); + bool IsRunningFromTest; TString ArcadiaTestsDataDir; TString SourceRoot; @@ -73,9 +73,9 @@ namespace NPrivate { TString RamDrivePath; TString YtHddPath; TString TestOutputRamDrivePath; - TString GdbPath; - TString CoreSearchFile; - std::unordered_map<TString, TString> TestParameters; + TString GdbPath; + TString CoreSearchFile; + std::unordered_map<TString, TString> TestParameters; }; TString GetCwd(); diff --git a/library/cpp/testing/common/ut/env_ut.cpp b/library/cpp/testing/common/ut/env_ut.cpp index 2aed1e4a25..408661d84d 100644 --- a/library/cpp/testing/common/ut/env_ut.cpp +++ b/library/cpp/testing/common/ut/env_ut.cpp @@ -1,12 +1,12 @@ #include <library/cpp/testing/common/env.h> #include <library/cpp/testing/common/scope.h> -#include <library/cpp/testing/gtest/gtest.h> +#include <library/cpp/testing/gtest/gtest.h> #include <util/folder/dirut.h> -#include <util/stream/file.h> +#include <util/stream/file.h> #include <util/system/env.h> #include <util/system/execpath.h> -#include <util/system/fs.h> +#include <util/system/fs.h> TEST(Runtime, ArcadiaSourceRoot) { @@ -99,64 +99,64 @@ TEST(Runtime, GetOutputRamDrivePath) { Singleton<NPrivate::TTestEnv>()->ReInitialize(); EXPECT_EQ(tmpDir, GetOutputRamDrivePath()); } - -#ifdef _linux_ -TEST(Runtime, GdbPath) { - Singleton<NPrivate::TTestEnv>()->ReInitialize(); - EXPECT_TRUE(NFs::Exists(::GdbPath())); -} -#endif - -TString ReInitializeContext(TStringBuf data) { - auto tmpDir = ::GetSystemTempDir(); - auto filename = tmpDir + "/context.json"; - TOFStream stream(filename); - stream.Write(data.data(), data.size()); - stream.Finish(); - - NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", filename); - Singleton<NPrivate::TTestEnv>()->ReInitialize(); - - return filename; -} - -TEST(Runtime, GetTestParam) { - TString context = R"json({ - "runtime": { - "test_params": { - "a": "b", - "c": "d" - } - } - })json"; - auto filename = ReInitializeContext(context); - - EXPECT_EQ("b", GetTestParam("a")); - EXPECT_EQ("d", GetTestParam("c")); - EXPECT_EQ("", GetTestParam("e")); - EXPECT_EQ("w", GetTestParam("e", "w")); - - Singleton<NPrivate::TTestEnv>()->AddTestParam("e", "e"); - EXPECT_EQ("e", GetTestParam("e")); -} - -TEST(Runtime, WatchProcessCore) { - TString context = R"json({ - "internal": { - "core_search_file": "watch_core.txt" - } - })json"; - auto filename = ReInitializeContext(context); - - WatchProcessCore(1, "bin1", "pwd"); - WatchProcessCore(2, "bin1"); - StopProcessCoreWatching(2); - - TIFStream file("watch_core.txt"); - auto data = file.ReadAll(); - TString expected = R"json({"cmd":"add","pid":1,"binary_path":"bin1","cwd":"pwd"} -{"cmd":"add","pid":2,"binary_path":"bin1"} -{"cmd":"drop","pid":2} -)json"; - EXPECT_EQ(expected, data); -} + +#ifdef _linux_ +TEST(Runtime, GdbPath) { + Singleton<NPrivate::TTestEnv>()->ReInitialize(); + EXPECT_TRUE(NFs::Exists(::GdbPath())); +} +#endif + +TString ReInitializeContext(TStringBuf data) { + auto tmpDir = ::GetSystemTempDir(); + auto filename = tmpDir + "/context.json"; + TOFStream stream(filename); + stream.Write(data.data(), data.size()); + stream.Finish(); + + NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", filename); + Singleton<NPrivate::TTestEnv>()->ReInitialize(); + + return filename; +} + +TEST(Runtime, GetTestParam) { + TString context = R"json({ + "runtime": { + "test_params": { + "a": "b", + "c": "d" + } + } + })json"; + auto filename = ReInitializeContext(context); + + EXPECT_EQ("b", GetTestParam("a")); + EXPECT_EQ("d", GetTestParam("c")); + EXPECT_EQ("", GetTestParam("e")); + EXPECT_EQ("w", GetTestParam("e", "w")); + + Singleton<NPrivate::TTestEnv>()->AddTestParam("e", "e"); + EXPECT_EQ("e", GetTestParam("e")); +} + +TEST(Runtime, WatchProcessCore) { + TString context = R"json({ + "internal": { + "core_search_file": "watch_core.txt" + } + })json"; + auto filename = ReInitializeContext(context); + + WatchProcessCore(1, "bin1", "pwd"); + WatchProcessCore(2, "bin1"); + StopProcessCoreWatching(2); + + TIFStream file("watch_core.txt"); + auto data = file.ReadAll(); + TString expected = R"json({"cmd":"add","pid":1,"binary_path":"bin1","cwd":"pwd"} +{"cmd":"add","pid":2,"binary_path":"bin1"} +{"cmd":"drop","pid":2} +)json"; + EXPECT_EQ(expected, data); +} diff --git a/library/cpp/testing/unittest/fat/test_port_manager.cpp b/library/cpp/testing/unittest/fat/test_port_manager.cpp index f77d2e3a25..472a66249e 100644 --- a/library/cpp/testing/unittest/fat/test_port_manager.cpp +++ b/library/cpp/testing/unittest/fat/test_port_manager.cpp @@ -1,36 +1,36 @@ #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/testing/unittest/tests_data.h> - -bool IsFreePort(ui16 port) { - TInet6StreamSocket sock; - TSockAddrInet6 addr("::", port); - Y_ENSURE(SetSockOpt(sock, SOL_SOCKET, SO_REUSEADDR, 1) == 0); - SetReuseAddressAndPort(sock); - if (sock.Bind(&addr) == 0) { - return true; - } - return false; -} - -void get_port_ranges() { + +bool IsFreePort(ui16 port) { + TInet6StreamSocket sock; + TSockAddrInet6 addr("::", port); + Y_ENSURE(SetSockOpt(sock, SOL_SOCKET, SO_REUSEADDR, 1) == 0); + SetReuseAddressAndPort(sock); + if (sock.Bind(&addr) == 0) { + return true; + } + return false; +} + +void get_port_ranges() { for (int i = 1; i < 10; ++i) { - TPortManager pm; - ui16 port = pm.GetPortsRange(1024, i); - for (int p = port; p < port + i; ++p) { - UNIT_ASSERT(IsFreePort(p)); - } - } -} - -Y_UNIT_TEST_SUITE(TestTPortManager) { - Y_UNIT_TEST(ParallelRun0) {get_port_ranges();} - Y_UNIT_TEST(ParallelRun1) {get_port_ranges();} - Y_UNIT_TEST(ParallelRun2) {get_port_ranges();} - Y_UNIT_TEST(ParallelRun3) {get_port_ranges();} - Y_UNIT_TEST(ParallelRun4) {get_port_ranges();} - Y_UNIT_TEST(ParallelRun5) {get_port_ranges();} - Y_UNIT_TEST(ParallelRun6) {get_port_ranges();} - Y_UNIT_TEST(ParallelRun7) {get_port_ranges();} - Y_UNIT_TEST(ParallelRun8) {get_port_ranges();} - Y_UNIT_TEST(ParallelRun9) {get_port_ranges();} -} + TPortManager pm; + ui16 port = pm.GetPortsRange(1024, i); + for (int p = port; p < port + i; ++p) { + UNIT_ASSERT(IsFreePort(p)); + } + } +} + +Y_UNIT_TEST_SUITE(TestTPortManager) { + Y_UNIT_TEST(ParallelRun0) {get_port_ranges();} + Y_UNIT_TEST(ParallelRun1) {get_port_ranges();} + Y_UNIT_TEST(ParallelRun2) {get_port_ranges();} + Y_UNIT_TEST(ParallelRun3) {get_port_ranges();} + Y_UNIT_TEST(ParallelRun4) {get_port_ranges();} + Y_UNIT_TEST(ParallelRun5) {get_port_ranges();} + Y_UNIT_TEST(ParallelRun6) {get_port_ranges();} + Y_UNIT_TEST(ParallelRun7) {get_port_ranges();} + Y_UNIT_TEST(ParallelRun8) {get_port_ranges();} + Y_UNIT_TEST(ParallelRun9) {get_port_ranges();} +} diff --git a/library/cpp/testing/unittest/fat/ya.make b/library/cpp/testing/unittest/fat/ya.make index d405e599ee..6eb68767b4 100644 --- a/library/cpp/testing/unittest/fat/ya.make +++ b/library/cpp/testing/unittest/fat/ya.make @@ -1,19 +1,19 @@ -UNITTEST() - -OWNER(g:yatool) - -SRCS( - test_port_manager.cpp -) - -SIZE(LARGE) - -# We need to run tests at the same time on the single machine -FORK_SUBTESTS() - +UNITTEST() + +OWNER(g:yatool) + +SRCS( + test_port_manager.cpp +) + +SIZE(LARGE) + +# We need to run tests at the same time on the single machine +FORK_SUBTESTS() + TAG( ya:fat ya:force_sandbox ) -END() +END() diff --git a/library/cpp/testing/unittest/registar.cpp b/library/cpp/testing/unittest/registar.cpp index 3679b768ed..06882dd1ae 100644 --- a/library/cpp/testing/unittest/registar.cpp +++ b/library/cpp/testing/unittest/registar.cpp @@ -106,10 +106,10 @@ struct TDiffColorizer { } }; -struct TTraceDiffFormatter { +struct TTraceDiffFormatter { bool Reverse = false; - explicit TTraceDiffFormatter(bool reverse = false) + explicit TTraceDiffFormatter(bool reverse = false) : Reverse(reverse) { } @@ -123,26 +123,26 @@ struct TTraceDiffFormatter { } TString Left(TArrayRef<const char> str) const { - return NUnitTest::GetFormatTag("good") + + return NUnitTest::GetFormatTag("good") + TString(str.begin(), str.end()) + NUnitTest::GetResetTag(); } TString Right(TArrayRef<const char> str) const { - return NUnitTest::GetFormatTag("bad") + + return NUnitTest::GetFormatTag("bad") + TString(str.begin(), str.end()) + NUnitTest::GetResetTag(); } }; TString NUnitTest::GetFormatTag(const char* name) { - return Sprintf("[[%s]]", name); -} - + return Sprintf("[[%s]]", name); +} + TString NUnitTest::GetResetTag() { return TString("[[rst]]"); -} - +} + TString NUnitTest::ColoredDiff(TStringBuf s1, TStringBuf s2, const TString& delims, bool reverse) { TStringStream res; TVector<NDiff::TChunk<char>> chunks; @@ -150,8 +150,8 @@ TString NUnitTest::ColoredDiff(TStringBuf s1, TStringBuf s2, const TString& deli if (NUnitTest::ShouldColorizeDiff) { NDiff::PrintChunks(res, TDiffColorizer(reverse), chunks); } else { - res << NUnitTest::GetResetTag(); - NDiff::PrintChunks(res, TTraceDiffFormatter(reverse), chunks); + res << NUnitTest::GetResetTag(); + NDiff::PrintChunks(res, TTraceDiffFormatter(reverse), chunks); } return res.Str(); } @@ -478,18 +478,18 @@ unsigned NUnitTest::TTestFactory::Execute() { #ifdef _unix_ // on Windows RTTI causes memory leaks TString type = test->TypeId(); if (types.insert(type).second == false) { - warnx("Duplicate suite found: %s (%s). Probably you have copy-pasted suite without changing it name", factory->Name().c_str(), type.c_str()); + warnx("Duplicate suite found: %s (%s). Probably you have copy-pasted suite without changing it name", factory->Name().c_str(), type.c_str()); return 1; } #endif // _unix_ test->Parent_ = this; -#ifdef UT_SKIP_EXCEPTIONS +#ifdef UT_SKIP_EXCEPTIONS try { #endif test->Execute(); -#ifdef UT_SKIP_EXCEPTIONS +#ifdef UT_SKIP_EXCEPTIONS } catch (...) { } #endif @@ -497,7 +497,7 @@ unsigned NUnitTest::TTestFactory::Execute() { Processor_->End(); - return bool(Processor_->FailTests()); + return bool(Processor_->FailTests()); } void NUnitTest::TTestFactory::SetProcessor(ITestSuiteProcessor* processor) { diff --git a/library/cpp/testing/unittest/tests_data.cpp b/library/cpp/testing/unittest/tests_data.cpp index b51cbc4b87..d1edd84196 100644 --- a/library/cpp/testing/unittest/tests_data.cpp +++ b/library/cpp/testing/unittest/tests_data.cpp @@ -6,52 +6,52 @@ #include <util/system/env.h> #include <util/system/mutex.h> -class TPortManager::TPortManagerImpl { -public: +class TPortManager::TPortManagerImpl { +public: TPortManagerImpl(bool reservePortsForCurrentTest) : EnableReservePortsForCurrentTest(reservePortsForCurrentTest) , DisableRandomPorts(!GetEnv("NO_RANDOM_PORTS").empty()) { - } - - ui16 GetPort(ui16 port) { + } + + ui16 GetPort(ui16 port) { if (port && DisableRandomPorts) { - return port; - } - + return port; + } + TAtomicSharedPtr<NTesting::IPort> holder(NTesting::GetFreePort().Release()); ReservePortForCurrentTest(holder); - + TGuard<TMutex> g(Lock); ReservedPorts.push_back(holder); return holder->Get(); } - + ui16 GetUdpPort(ui16 port) { return GetPort(port); } - + ui16 GetTcpPort(ui16 port) { return GetPort(port); - } - + } + ui16 GetTcpAndUdpPort(ui16 port) { return GetPort(port); } - ui16 GetPortsRange(const ui16 startPort, const ui16 range) { + ui16 GetPortsRange(const ui16 startPort, const ui16 range) { Y_UNUSED(startPort); auto ports = NTesting::NLegacy::GetFreePortsRange(range); ui16 first = ports[0]; - TGuard<TMutex> g(Lock); + TGuard<TMutex> g(Lock); for (auto& port : ports) { ReservedPorts.emplace_back(port.Release()); ReservePortForCurrentTest(ReservedPorts.back()); - } + } return first; - } - -private: + } + +private: void ReservePortForCurrentTest(const TAtomicSharedPtr<NTesting::IPort>& portGuard) { if (EnableReservePortsForCurrentTest) { TTestBase* currentTest = NUnitTest::NPrivate::GetCurrentTest(); @@ -64,40 +64,40 @@ private: } private: - TMutex Lock; + TMutex Lock; TVector<TAtomicSharedPtr<NTesting::IPort>> ReservedPorts; const bool EnableReservePortsForCurrentTest; const bool DisableRandomPorts; -}; - +}; + TPortManager::TPortManager(bool reservePortsForCurrentTest) : Impl_(new TPortManagerImpl(reservePortsForCurrentTest)) -{ -} - -TPortManager::~TPortManager() { -} - -ui16 TPortManager::GetPort(ui16 port) { - return Impl_->GetTcpPort(port); -} +{ +} + +TPortManager::~TPortManager() { +} + +ui16 TPortManager::GetPort(ui16 port) { + return Impl_->GetTcpPort(port); +} ui16 TPortManager::GetTcpPort(ui16 port) { - return Impl_->GetTcpPort(port); + return Impl_->GetTcpPort(port); } ui16 TPortManager::GetUdpPort(ui16 port) { - return Impl_->GetUdpPort(port); + return Impl_->GetUdpPort(port); } ui16 TPortManager::GetTcpAndUdpPort(ui16 port) { - return Impl_->GetTcpAndUdpPort(port); -} - -ui16 TPortManager::GetPortsRange(const ui16 startPort, const ui16 range) { - return Impl_->GetPortsRange(startPort, range); + return Impl_->GetTcpAndUdpPort(port); } +ui16 TPortManager::GetPortsRange(const ui16 startPort, const ui16 range) { + return Impl_->GetPortsRange(startPort, range); +} + ui16 GetRandomPort() { TPortManager* pm = Singleton<TPortManager>(false); return pm->GetPort(); diff --git a/library/cpp/testing/unittest/tests_data.h b/library/cpp/testing/unittest/tests_data.h index 6536bc1ae6..dac65dfc72 100644 --- a/library/cpp/testing/unittest/tests_data.h +++ b/library/cpp/testing/unittest/tests_data.h @@ -2,8 +2,8 @@ #include <library/cpp/testing/common/env.h> -#include <util/generic/noncopyable.h> -#include <util/generic/ptr.h> +#include <util/generic/noncopyable.h> +#include <util/generic/ptr.h> #include <util/generic/string.h> #include <util/network/sock.h> @@ -28,12 +28,12 @@ void SetReuseAddressAndPort(const TSocketType& sock) { } class TPortManager: public TNonCopyable { -public: +public: TPortManager(bool reservePortsForCurrentTest = true); - ~TPortManager(); + ~TPortManager(); // Gets free TCP port - ui16 GetPort(ui16 port = 0); + ui16 GetPort(ui16 port = 0); // Gets free TCP port ui16 GetTcpPort(ui16 port = 0); @@ -44,11 +44,11 @@ public: // Gets one free port for use in both TCP and UDP protocols ui16 GetTcpAndUdpPort(ui16 port = 0); - ui16 GetPortsRange(const ui16 startPort, const ui16 range); - -private: - class TPortManagerImpl; - THolder<TPortManagerImpl> Impl_; + ui16 GetPortsRange(const ui16 startPort, const ui16 range); + +private: + class TPortManagerImpl; + THolder<TPortManagerImpl> Impl_; }; ui16 GetRandomPort(); diff --git a/library/cpp/testing/unittest/ut/main.cpp b/library/cpp/testing/unittest/ut/main.cpp index e303e21e30..0614e77fe2 100644 --- a/library/cpp/testing/unittest/ut/main.cpp +++ b/library/cpp/testing/unittest/ut/main.cpp @@ -1,11 +1,11 @@ #include <library/cpp/testing/unittest/gtest.h> #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/testing/unittest/tests_data.h> - -#include <util/generic/set.h> -#include <util/network/sock.h> -#include <util/system/env.h> -#include <util/system/fs.h> + +#include <util/generic/set.h> +#include <util/network/sock.h> +#include <util/system/env.h> +#include <util/system/fs.h> TEST(GTest, Test1) { UNIT_ASSERT_EQUAL(1, 1); @@ -60,7 +60,7 @@ TEST(ETest, Test1) { UNIT_CHECK_GENERATED_EXCEPTION(ythrow yexception(), yexception); UNIT_CHECK_GENERATED_NO_EXCEPTION(true, yexception); } - + Y_UNIT_TEST_SUITE(TestSingleTestFixture) { Y_UNIT_TEST_F(Test3, TSimpleFixture) { diff --git a/library/cpp/testing/unittest/utmain.cpp b/library/cpp/testing/unittest/utmain.cpp index 305bc6b40f..e5c4185001 100644 --- a/library/cpp/testing/unittest/utmain.cpp +++ b/library/cpp/testing/unittest/utmain.cpp @@ -6,7 +6,7 @@ #include <library/cpp/json/writer/json.h> #include <library/cpp/json/writer/json_value.h> -#include <library/cpp/testing/common/env.h> +#include <library/cpp/testing/common/env.h> #include <library/cpp/testing/hook/hook.h> #include <util/datetime/base.h> @@ -19,9 +19,9 @@ #include <util/network/init.h> -#include <util/stream/file.h> +#include <util/stream/file.h> #include <util/stream/output.h> -#include <util/string/join.h> +#include <util/string/join.h> #include <util/string/util.h> #include <util/system/defaults.h> @@ -46,8 +46,8 @@ #define NOTE_IN_VALGRIND(test) #endif -const size_t MAX_COMMENT_MESSAGE_LENGTH = 1024 * 1024; // 1 MB - +const size_t MAX_COMMENT_MESSAGE_LENGTH = 1024 * 1024; // 1 MB + using namespace NUnitTest; class TNullTraceWriterProcessor: public ITestSuiteProcessor { @@ -56,8 +56,8 @@ class TNullTraceWriterProcessor: public ITestSuiteProcessor { class TTraceWriterProcessor: public ITestSuiteProcessor { public: inline TTraceWriterProcessor(const char* traceFilePath, EOpenMode mode) - : PrevTime(TInstant::Now()) - { + : PrevTime(TInstant::Now()) + { TraceFile = new TUnbufferedFileOutput(TFile(traceFilePath, mode | WrOnly | Seq)); } @@ -68,17 +68,17 @@ private: TVector<TString> ErrorMessages; inline void Trace(const TString eventName, const NJson::TJsonValue eventValue) { - NJsonWriter::TBuf json(NJsonWriter::HEM_UNSAFE); - json.BeginObject(); - - json.WriteKey("name").WriteString(eventName); - json.WriteKey("value").WriteJsonValue(&eventValue); - json.WriteKey("timestamp").WriteDouble(TInstant::Now().SecondsFloat(), PREC_NDIGITS, 14); - - json.EndObject(); - - json.FlushTo(TraceFile.Get()); - *TraceFile << "\n"; + NJsonWriter::TBuf json(NJsonWriter::HEM_UNSAFE); + json.BeginObject(); + + json.WriteKey("name").WriteString(eventName); + json.WriteKey("value").WriteJsonValue(&eventValue); + json.WriteKey("timestamp").WriteDouble(TInstant::Now().SecondsFloat(), PREC_NDIGITS, 14); + + json.EndObject(); + + json.FlushTo(TraceFile.Get()); + *TraceFile << "\n"; } inline void TraceSubtestFinished(const char* className, const char* subtestName, const char* status, const TString comment, const TTestContext* context) { @@ -88,43 +88,43 @@ private: event.InsertValue("subtest", subtestName); event.InsertValue("status", status); event.InsertValue("comment", comment.data()); - event.InsertValue("time", (now - PrevTime).SecondsFloat()); + event.InsertValue("time", (now - PrevTime).SecondsFloat()); if (context) { for (const auto& metric : context->Metrics) { event["metrics"].InsertValue(metric.first, metric.second); } } Trace("subtest-finished", event); - + PrevTime = now; TString marker = Join("", "\n###subtest-finished:", className, "::", subtestName, "\n"); - Cout << marker; - Cout.Flush(); - Cerr << comment; - Cerr << marker; - Cerr.Flush(); + Cout << marker; + Cout.Flush(); + Cerr << comment; + Cerr << marker; + Cerr.Flush(); } virtual TString BuildComment(const char* message, const char* backTrace) { - return NUnitTest::GetFormatTag("bad") + + return NUnitTest::GetFormatTag("bad") + TString(message).substr(0, MAX_COMMENT_MESSAGE_LENGTH) + NUnitTest::GetResetTag() + TString("\n") + NUnitTest::GetFormatTag("alt1") + TString(backTrace).substr(0, MAX_COMMENT_MESSAGE_LENGTH) + NUnitTest::GetResetTag(); - } - + } + void OnBeforeTest(const TTest* test) override { NJson::TJsonValue event; event.InsertValue("class", test->unit->name); event.InsertValue("subtest", test->name); Trace("subtest-started", event); TString marker = Join("", "\n###subtest-started:", test->unit->name, "::", test->name, "\n"); - Cout << marker; - Cout.Flush(); - Cerr << marker; - Cerr.Flush(); + Cout << marker; + Cout.Flush(); + Cerr << marker; + Cerr.Flush(); } void OnUnitStart(const TUnit* unit) override { @@ -552,13 +552,13 @@ public: if (Verbose_) { return true; } else { - Stream_ << name << "\n"; + Stream_ << name << "\n"; return false; } } bool CheckAccessTest(TString suite, const char* name) override { - Stream_ << suite << "::" << name << "\n"; + Stream_ << suite << "::" << name << "\n"; return false; } @@ -601,7 +601,7 @@ static const TWinEnvironment Instance; #endif // _win_ static int DoList(bool verbose, IOutputStream& stream) { - TEnumeratingProcessor eproc(verbose, stream); + TEnumeratingProcessor eproc(verbose, stream); TTestFactory::Instance().SetProcessor(&eproc); TTestFactory::Instance().Execute(); return 0; @@ -625,28 +625,28 @@ static int DoUsage(const char* progname) { return 0; } -#if defined(_linux_) && defined(CLANG_COVERAGE) -extern "C" int __llvm_profile_write_file(void); - -static void GracefulShutdownHandler(int) { - try { - __llvm_profile_write_file(); - } catch (...) { - } - abort(); -} -#endif - +#if defined(_linux_) && defined(CLANG_COVERAGE) +extern "C" int __llvm_profile_write_file(void); + +static void GracefulShutdownHandler(int) { + try { + __llvm_profile_write_file(); + } catch (...) { + } + abort(); +} +#endif + int NUnitTest::RunMain(int argc, char** argv) { -#if defined(_linux_) && defined(CLANG_COVERAGE) - { - struct sigaction sa; - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = GracefulShutdownHandler; - sa.sa_flags = SA_SIGINFO | SA_RESTART; - Y_VERIFY(!sigaction(SIGUSR2, &sa, nullptr)); - } -#endif +#if defined(_linux_) && defined(CLANG_COVERAGE) + { + struct sigaction sa; + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = GracefulShutdownHandler; + sa.sa_flags = SA_SIGINFO | SA_RESTART; + Y_VERIFY(!sigaction(SIGUSR2, &sa, nullptr)); + } +#endif NTesting::THook::CallBeforeInit(); InitNetworkSubSystem(); @@ -668,13 +668,13 @@ int NUnitTest::RunMain(int argc, char** argv) { IOutputStream* listStream = &Cout; THolder<IOutputStream> listFile; - enum EListType { - DONT_LIST, - LIST, - LIST_VERBOSE - }; - EListType listTests = DONT_LIST; - + enum EListType { + DONT_LIST, + LIST, + LIST_VERBOSE + }; + EListType listTests = DONT_LIST; + for (size_t i = 1; i < (size_t)argc; ++i) { const char* name = argv[i]; @@ -682,9 +682,9 @@ int NUnitTest::RunMain(int argc, char** argv) { if (strcmp(name, "--help") == 0 || strcmp(name, "-h") == 0) { return DoUsage(argv[0]); } else if (strcmp(name, "--list") == 0 || strcmp(name, "-l") == 0) { - listTests = LIST; + listTests = LIST; } else if (strcmp(name, "--list-verbose") == 0 || strcmp(name, "-A") == 0) { - listTests = LIST_VERBOSE; + listTests = LIST_VERBOSE; } else if (strcmp(name, "--print-before-suite=false") == 0) { processor.SetPrintBeforeSuite(false); } else if (strcmp(name, "--print-before-test=false") == 0) { @@ -718,20 +718,20 @@ int NUnitTest::RunMain(int argc, char** argv) { processor.BeQuiet(); NUnitTest::ShouldColorizeDiff = false; processor.SetTraceProcessor(new TTraceWriterProcessor(argv[i], CreateAlways)); - } else if (strcmp(name, "--trace-path-append") == 0) { + } else if (strcmp(name, "--trace-path-append") == 0) { ++i; processor.BeQuiet(); NUnitTest::ShouldColorizeDiff = false; - processor.SetTraceProcessor(new TTraceWriterProcessor(argv[i], OpenAlways | ForAppend)); - } else if (strcmp(name, "--list-path") == 0) { - ++i; + processor.SetTraceProcessor(new TTraceWriterProcessor(argv[i], OpenAlways | ForAppend)); + } else if (strcmp(name, "--list-path") == 0) { + ++i; listFile = MakeHolder<TFixedBufferFileOutput>(argv[i]); - listStream = listFile.Get(); + listStream = listFile.Get(); } else if (strcmp(name, "--test-param") == 0) { ++i; TString param(argv[i]); size_t assign = param.find('='); - Singleton<::NPrivate::TTestEnv>()->AddTestParam(param.substr(0, assign), param.substr(assign + 1)); + Singleton<::NPrivate::TTestEnv>()->AddTestParam(param.substr(0, assign), param.substr(assign + 1)); } else if (TString(name).StartsWith("--")) { return DoUsage(argv[0]), 1; } else if (*name == '-') { @@ -743,9 +743,9 @@ int NUnitTest::RunMain(int argc, char** argv) { } } } - if (listTests != DONT_LIST) { - return DoList(listTests == LIST_VERBOSE, *listStream); - } + if (listTests != DONT_LIST) { + return DoList(listTests == LIST_VERBOSE, *listStream); + } TTestFactory::Instance().SetProcessor(&processor); diff --git a/library/cpp/testing/ya.make b/library/cpp/testing/ya.make index 6a57ac2ee6..bff91ef52d 100644 --- a/library/cpp/testing/ya.make +++ b/library/cpp/testing/ya.make @@ -6,7 +6,7 @@ RECURSE( benchmark/main boost_test boost_test_main - dump_clang_coverage + dump_clang_coverage gbenchmark_main gmock gmock_in_unittest diff --git a/library/cpp/ya.make b/library/cpp/ya.make index 8c1193b007..48e44aea55 100644 --- a/library/cpp/ya.make +++ b/library/cpp/ya.make @@ -29,14 +29,14 @@ RECURSE( bucket_quoter build_info cache - case_insensitive_string + case_insensitive_string cgiparam cgiparam/fuzz cgiparam/ut charset charset/ut chromium_trace - clang_tidy + clang_tidy clickhouse clustered_hnsw clustered_hnsw/ut @@ -60,8 +60,8 @@ RECURSE( config config/extra config/ut - consistent_hash_ring - consistent_hash_ring/ut + consistent_hash_ring + consistent_hash_ring/ut consistent_hashing consistent_hashing/ut containers @@ -142,7 +142,7 @@ RECURSE( getopt/last_getopt_demo getopt/small getopt/ut - getoptpb + getoptpb gettimeofday gradient_optimize gradient_optimize/ut @@ -290,7 +290,7 @@ RECURSE( proto_config/plugin proto_config/protos proto_config/ut - protobuf + protobuf pybind pybind/example pybind/example/dynamic @@ -342,7 +342,7 @@ RECURSE( sqlite3/ut sse ssh - ssh/ut + ssh/ut ssh_sign ssh_sign/ut stat-handle @@ -372,9 +372,9 @@ RECURSE( token/serialization token/serialization/ut token/ut - tokenclassifiers - tokenizer - tokenizer/ut + tokenclassifiers + tokenizer + tokenizer/ut trace_usage trace_usage/benchmark trace_usage/ut |