diff options
author | krock21 <krock21@yandex-team.ru> | 2022-02-10 16:46:02 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:02 +0300 |
commit | 4aae166b5d23fd02653919f43e2015cd636fa6fd (patch) | |
tree | 70e52225c1ede3476f358bc4699197ace987d46d /library/cpp/testing/common | |
parent | 9ab30620977aa96ae9e9da959e2f7e1370cb796d (diff) | |
download | ydb-4aae166b5d23fd02653919f43e2015cd636fa6fd.tar.gz |
Restoring authorship annotation for <krock21@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/testing/common')
-rw-r--r-- | library/cpp/testing/common/env.cpp | 216 | ||||
-rw-r--r-- | library/cpp/testing/common/env.h | 42 | ||||
-rw-r--r-- | library/cpp/testing/common/ut/env_ut.cpp | 40 | ||||
-rw-r--r-- | library/cpp/testing/common/ya.make | 8 |
4 files changed, 153 insertions, 153 deletions
diff --git a/library/cpp/testing/common/env.cpp b/library/cpp/testing/common/env.cpp index fa3a47fe16..9661846e82 100644 --- a/library/cpp/testing/common/env.cpp +++ b/library/cpp/testing/common/env.cpp @@ -5,15 +5,15 @@ #include <util/folder/dirut.h> #include <util/folder/path.h> #include <util/generic/singleton.h> -#include <util/stream/file.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 <library/cpp/json/json_reader.h> -#include <library/cpp/json/json_value.h> +#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_value.h> #include <library/cpp/json/json_writer.h> TString ArcadiaSourceRoot() { @@ -41,12 +41,12 @@ TString BinaryPath(TStringBuf path) { } TString GetArcadiaTestsData() { - TString atdRoot = NPrivate::GetTestEnv().ArcadiaTestsDataDir; - if (atdRoot) { - return atdRoot; + TString atdRoot = NPrivate::GetTestEnv().ArcadiaTestsDataDir; + if (atdRoot) { + return atdRoot; } - TString path = NPrivate::GetCwd(); + TString path = NPrivate::GetCwd(); const char pathsep = GetDirectorySeparator(); while (!path.empty()) { TString dataDir = path + "/arcadia_tests_data"; @@ -65,12 +65,12 @@ TString GetArcadiaTestsData() { } TString GetWorkPath() { - TString workPath = NPrivate::GetTestEnv().WorkPath; - if (workPath) { - return workPath; + TString workPath = NPrivate::GetTestEnv().WorkPath; + if (workPath) { + return workPath; } - - return NPrivate::GetCwd(); + + return NPrivate::GetCwd(); } TFsPath GetOutputPath() { @@ -78,7 +78,7 @@ TFsPath GetOutputPath() { } const TString& GetRamDrivePath() { - return NPrivate::GetTestEnv().RamDrivePath; + return NPrivate::GetTestEnv().RamDrivePath; } const TString& GetYtHddPath() { @@ -86,7 +86,7 @@ const TString& GetYtHddPath() { } const TString& GetOutputRamDrivePath() { - return NPrivate::GetTestEnv().TestOutputRamDrivePath; + return NPrivate::GetTestEnv().TestOutputRamDrivePath; } const TString& GdbPath() { @@ -144,68 +144,68 @@ void StopProcessCoreWatching(int pid) { } bool FromYaTest() { - return NPrivate::GetTestEnv().IsRunningFromTest; + return NPrivate::GetTestEnv().IsRunningFromTest; } - -namespace NPrivate { - TTestEnv::TTestEnv() { - ReInitialize(); - } - - void TTestEnv::ReInitialize() { - IsRunningFromTest = false; - ArcadiaTestsDataDir = ""; - SourceRoot = ""; - BuildRoot = ""; - WorkPath = ""; - RamDrivePath = ""; + +namespace NPrivate { + TTestEnv::TTestEnv() { + ReInitialize(); + } + + void TTestEnv::ReInitialize() { + IsRunningFromTest = false; + ArcadiaTestsDataDir = ""; + SourceRoot = ""; + BuildRoot = ""; + WorkPath = ""; + RamDrivePath = ""; YtHddPath = ""; - TestOutputRamDrivePath = ""; + TestOutputRamDrivePath = ""; GdbPath = ""; CoreSearchFile = ""; TestParameters.clear(); - - const TString contextFilename = GetEnv("YA_TEST_CONTEXT_FILE"); - if (contextFilename) { - NJson::TJsonValue context; - NJson::ReadJsonTree(TFileInput(contextFilename).ReadAll(), &context); - - NJson::TJsonValue* value; - - value = context.GetValueByPath("runtime.source_root"); - if (value) { - SourceRoot = value->GetStringSafe(""); - } - - value = context.GetValueByPath("runtime.build_root"); - if (value) { - BuildRoot = value->GetStringSafe(""); - } - - value = context.GetValueByPath("runtime.atd_root"); - if (value) { - ArcadiaTestsDataDir = value->GetStringSafe(""); - } - - value = context.GetValueByPath("runtime.work_path"); - if (value) { - WorkPath = value->GetStringSafe(""); - } - - value = context.GetValueByPath("runtime.ram_drive_path"); - if (value) { - RamDrivePath = value->GetStringSafe(""); - } - + + const TString contextFilename = GetEnv("YA_TEST_CONTEXT_FILE"); + if (contextFilename) { + NJson::TJsonValue context; + NJson::ReadJsonTree(TFileInput(contextFilename).ReadAll(), &context); + + NJson::TJsonValue* value; + + value = context.GetValueByPath("runtime.source_root"); + if (value) { + SourceRoot = value->GetStringSafe(""); + } + + value = context.GetValueByPath("runtime.build_root"); + if (value) { + BuildRoot = value->GetStringSafe(""); + } + + value = context.GetValueByPath("runtime.atd_root"); + if (value) { + ArcadiaTestsDataDir = value->GetStringSafe(""); + } + + value = context.GetValueByPath("runtime.work_path"); + if (value) { + WorkPath = value->GetStringSafe(""); + } + + value = context.GetValueByPath("runtime.ram_drive_path"); + if (value) { + RamDrivePath = value->GetStringSafe(""); + } + value = context.GetValueByPath("runtime.yt_hdd_path"); if (value) { YtHddPath = value->GetStringSafe(""); } - value = context.GetValueByPath("runtime.test_output_ram_drive_path"); - if (value) { - TestOutputRamDrivePath = value->GetStringSafe(""); - } + value = context.GetValueByPath("runtime.test_output_ram_drive_path"); + if (value) { + TestOutputRamDrivePath = value->GetStringSafe(""); + } value = context.GetValueByPath("runtime.gdb_bin"); if (value) { @@ -223,53 +223,53 @@ namespace NPrivate { if (value) { CoreSearchFile = value->GetStringSafe(""); } - } - + } + if (!YtHddPath) { YtHddPath = GetEnv("HDD_PATH"); } - if (!SourceRoot) { - SourceRoot = GetEnv("ARCADIA_SOURCE_ROOT"); - } - - if (!BuildRoot) { - BuildRoot = GetEnv("ARCADIA_BUILD_ROOT"); - } - - if (!ArcadiaTestsDataDir) { - ArcadiaTestsDataDir = GetEnv("ARCADIA_TESTS_DATA_DIR"); - } - - if (!WorkPath) { - WorkPath = GetEnv("TEST_WORK_PATH"); - } - - if (!RamDrivePath) { - RamDrivePath = GetEnv("YA_TEST_RAM_DRIVE_PATH"); - } - - if (!TestOutputRamDrivePath) { - TestOutputRamDrivePath = GetEnv("YA_TEST_OUTPUT_RAM_DRIVE_PATH"); - } - - const TString fromEnv = GetEnv("YA_TEST_RUNNER"); - IsRunningFromTest = (fromEnv == "1"); - } - + if (!SourceRoot) { + SourceRoot = GetEnv("ARCADIA_SOURCE_ROOT"); + } + + if (!BuildRoot) { + BuildRoot = GetEnv("ARCADIA_BUILD_ROOT"); + } + + if (!ArcadiaTestsDataDir) { + ArcadiaTestsDataDir = GetEnv("ARCADIA_TESTS_DATA_DIR"); + } + + if (!WorkPath) { + WorkPath = GetEnv("TEST_WORK_PATH"); + } + + if (!RamDrivePath) { + RamDrivePath = GetEnv("YA_TEST_RAM_DRIVE_PATH"); + } + + if (!TestOutputRamDrivePath) { + TestOutputRamDrivePath = GetEnv("YA_TEST_OUTPUT_RAM_DRIVE_PATH"); + } + + const TString fromEnv = GetEnv("YA_TEST_RUNNER"); + IsRunningFromTest = (fromEnv == "1"); + } + void TTestEnv::AddTestParam(TStringBuf name, TStringBuf value) { TestParameters[TString{name}] = value; } - TString GetCwd() { - try { - return NFs::CurrentWorkingDirectory(); - } catch (...) { - return {}; - } - } - - const TTestEnv& GetTestEnv() { - return *Singleton<TTestEnv>(); - } -} + TString GetCwd() { + try { + return NFs::CurrentWorkingDirectory(); + } catch (...) { + return {}; + } + } + + const TTestEnv& GetTestEnv() { + return *Singleton<TTestEnv>(); + } +} diff --git a/library/cpp/testing/common/env.h b/library/cpp/testing/common/env.h index 7b89aa1bed..aa247afb9a 100644 --- a/library/cpp/testing/common/env.h +++ b/library/cpp/testing/common/env.h @@ -55,30 +55,30 @@ void WatchProcessCore(int pid, const TFsPath& binaryPath, const TFsPath& cwd = T void StopProcessCoreWatching(int pid); #define SRC_(path) ArcadiaFromCurrentLocation(__SOURCE_FILE__, path) - -namespace NPrivate { - class TTestEnv { - public: - TTestEnv(); - - void ReInitialize(); - + +namespace NPrivate { + class TTestEnv { + public: + TTestEnv(); + + void ReInitialize(); + void AddTestParam(TStringBuf name, TStringBuf value); - bool IsRunningFromTest; - TString ArcadiaTestsDataDir; - TString SourceRoot; - TString BuildRoot; - TString WorkPath; - TString RamDrivePath; + bool IsRunningFromTest; + TString ArcadiaTestsDataDir; + TString SourceRoot; + TString BuildRoot; + TString WorkPath; + TString RamDrivePath; TString YtHddPath; - TString TestOutputRamDrivePath; + TString TestOutputRamDrivePath; TString GdbPath; TString CoreSearchFile; std::unordered_map<TString, TString> TestParameters; - }; - - TString GetCwd(); - - const TTestEnv& GetTestEnv(); -} + }; + + TString GetCwd(); + + const TTestEnv& GetTestEnv(); +} diff --git a/library/cpp/testing/common/ut/env_ut.cpp b/library/cpp/testing/common/ut/env_ut.cpp index 2aed1e4a25..64a79bb411 100644 --- a/library/cpp/testing/common/ut/env_ut.cpp +++ b/library/cpp/testing/common/ut/env_ut.cpp @@ -10,52 +10,52 @@ TEST(Runtime, ArcadiaSourceRoot) { - NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename + NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename { auto tmpDir = ::GetSystemTempDir(); NTesting::TScopedEnvironment guard("ARCADIA_SOURCE_ROOT", tmpDir); - Singleton<NPrivate::TTestEnv>()->ReInitialize(); + Singleton<NPrivate::TTestEnv>()->ReInitialize(); EXPECT_EQ(tmpDir, ArcadiaSourceRoot()); } { NTesting::TScopedEnvironment guard("ARCADIA_SOURCE_ROOT", ""); - Singleton<NPrivate::TTestEnv>()->ReInitialize(); + Singleton<NPrivate::TTestEnv>()->ReInitialize(); EXPECT_FALSE(ArcadiaSourceRoot().empty()); } } TEST(Runtime, BuildRoot) { - NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename + NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename { auto tmpDir = ::GetSystemTempDir(); NTesting::TScopedEnvironment guard("ARCADIA_BUILD_ROOT", tmpDir); - Singleton<NPrivate::TTestEnv>()->ReInitialize(); + Singleton<NPrivate::TTestEnv>()->ReInitialize(); EXPECT_EQ(tmpDir, BuildRoot()); } { NTesting::TScopedEnvironment guard("ARCADIA_BUILD_ROOT", ""); - Singleton<NPrivate::TTestEnv>()->ReInitialize(); + Singleton<NPrivate::TTestEnv>()->ReInitialize(); EXPECT_FALSE(BuildRoot().empty()); } } TEST(Runtime, BinaryPath) { - NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename - Singleton<NPrivate::TTestEnv>()->ReInitialize(); + NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename + Singleton<NPrivate::TTestEnv>()->ReInitialize(); EXPECT_TRUE(TFsPath(BinaryPath("library/cpp/testing/common/ut")).Exists()); } TEST(Runtime, GetArcadiaTestsData) { - NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename + NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename { auto tmpDir = ::GetSystemTempDir(); NTesting::TScopedEnvironment guard("ARCADIA_TESTS_DATA_DIR", tmpDir); - Singleton<NPrivate::TTestEnv>()->ReInitialize(); + Singleton<NPrivate::TTestEnv>()->ReInitialize(); EXPECT_EQ(tmpDir, GetArcadiaTestsData()); } { NTesting::TScopedEnvironment guard("ARCADIA_TESTS_DATA_DIR", ""); - Singleton<NPrivate::TTestEnv>()->ReInitialize(); + Singleton<NPrivate::TTestEnv>()->ReInitialize(); auto path = GetArcadiaTestsData(); // it is not error if path is empty const bool ok = (path.empty() || GetBaseName(path) == "arcadia_tests_data"); @@ -64,39 +64,39 @@ TEST(Runtime, GetArcadiaTestsData) { } TEST(Runtime, GetWorkPath) { - NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename + NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename { auto tmpDir = ::GetSystemTempDir(); NTesting::TScopedEnvironment guard("TEST_WORK_PATH", tmpDir); - Singleton<NPrivate::TTestEnv>()->ReInitialize(); + Singleton<NPrivate::TTestEnv>()->ReInitialize(); EXPECT_EQ(tmpDir, GetWorkPath()); } { NTesting::TScopedEnvironment guard("TEST_WORK_PATH", ""); - Singleton<NPrivate::TTestEnv>()->ReInitialize(); + Singleton<NPrivate::TTestEnv>()->ReInitialize(); EXPECT_TRUE(!GetWorkPath().empty()); } } TEST(Runtime, GetOutputPath) { - NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename - Singleton<NPrivate::TTestEnv>()->ReInitialize(); + NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename + Singleton<NPrivate::TTestEnv>()->ReInitialize(); EXPECT_EQ(GetOutputPath().Basename(), "testing_out_stuff"); } TEST(Runtime, GetRamDrivePath) { - NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename + NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename auto tmpDir = ::GetSystemTempDir(); NTesting::TScopedEnvironment guard("YA_TEST_RAM_DRIVE_PATH", tmpDir); - Singleton<NPrivate::TTestEnv>()->ReInitialize(); + Singleton<NPrivate::TTestEnv>()->ReInitialize(); EXPECT_EQ(tmpDir, GetRamDrivePath()); } TEST(Runtime, GetOutputRamDrivePath) { - NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename + NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename auto tmpDir = ::GetSystemTempDir(); NTesting::TScopedEnvironment guard("YA_TEST_OUTPUT_RAM_DRIVE_PATH", tmpDir); - Singleton<NPrivate::TTestEnv>()->ReInitialize(); + Singleton<NPrivate::TTestEnv>()->ReInitialize(); EXPECT_EQ(tmpDir, GetOutputRamDrivePath()); } diff --git a/library/cpp/testing/common/ya.make b/library/cpp/testing/common/ya.make index 2f4b0ce26e..ac83cc98ce 100644 --- a/library/cpp/testing/common/ya.make +++ b/library/cpp/testing/common/ya.make @@ -14,10 +14,10 @@ SRCS( scope.cpp ) -PEERDIR( - library/cpp/json -) - +PEERDIR( + library/cpp/json +) + END() RECURSE_FOR_TESTS(ut) |