1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
#include <library/cpp/testing/common/env.h>
#include <library/cpp/testing/common/scope.h>
#include <library/cpp/testing/gtest/gtest.h>
#include <util/folder/dirut.h>
#include <util/stream/file.h>
#include <util/system/env.h>
#include <util/system/execpath.h>
#include <util/system/fs.h>
TEST(Runtime, ArcadiaSourceRoot) {
NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename
{
auto tmpDir = ::GetSystemTempDir();
NTesting::TScopedEnvironment guard("ARCADIA_SOURCE_ROOT", tmpDir);
Singleton<NPrivate::TTestEnv>()->ReInitialize();
EXPECT_EQ(tmpDir, ArcadiaSourceRoot());
}
{
NTesting::TScopedEnvironment guard("ARCADIA_SOURCE_ROOT", "");
Singleton<NPrivate::TTestEnv>()->ReInitialize();
EXPECT_FALSE(ArcadiaSourceRoot().empty());
}
}
TEST(Runtime, BuildRoot) {
NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename
{
auto tmpDir = ::GetSystemTempDir();
NTesting::TScopedEnvironment guard("ARCADIA_BUILD_ROOT", tmpDir);
Singleton<NPrivate::TTestEnv>()->ReInitialize();
EXPECT_EQ(tmpDir, BuildRoot());
}
{
NTesting::TScopedEnvironment guard("ARCADIA_BUILD_ROOT", "");
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();
EXPECT_TRUE(TFsPath(BinaryPath("library/cpp/testing/common/ut")).Exists());
}
TEST(Runtime, GetArcadiaTestsData) {
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();
EXPECT_EQ(tmpDir, GetArcadiaTestsData());
}
{
NTesting::TScopedEnvironment guard("ARCADIA_TESTS_DATA_DIR", "");
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");
EXPECT_TRUE(ok);
}
}
TEST(Runtime, GetWorkPath) {
NTesting::TScopedEnvironment contextGuard("YA_TEST_CONTEXT_FILE", ""); // remove context filename
{
auto tmpDir = ::GetSystemTempDir();
NTesting::TScopedEnvironment guard("TEST_WORK_PATH", tmpDir);
Singleton<NPrivate::TTestEnv>()->ReInitialize();
EXPECT_EQ(tmpDir, GetWorkPath());
}
{
NTesting::TScopedEnvironment guard("TEST_WORK_PATH", "");
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();
EXPECT_EQ(GetOutputPath().Basename(), "testing_out_stuff");
}
TEST(Runtime, GetRamDrivePath) {
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();
EXPECT_EQ(tmpDir, GetRamDrivePath());
}
TEST(Runtime, GetOutputRamDrivePath) {
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();
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);
}
TEST(Runtime, GlobalResources) {
TString context = R"json({
"resources": {
"global": {
"TOOL_NAME_RESOURCE_GLOBAL": "path"
}
}
})json";
auto filename = ReInitializeContext(context);
EXPECT_EQ("path", GetGlobalResource("TOOL_NAME_RESOURCE_GLOBAL"));
}
|