forked from openxla/xla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_options_parsers_test.cc
104 lines (86 loc) · 3.39 KB
/
debug_options_parsers_test.cc
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
/* Copyright 2017 The OpenXLA Authors.
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.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// Test for parse_flags_from_env.cc
#include "xla/debug_options_parsers.h"
#include <string>
#include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h"
#include "xla/debug_options_flags.h"
#include "xla/parse_flags_from_env.h"
#include "xla/tsl/util/command_line_flags.h"
#include "tsl/platform/env.h"
#include "tsl/platform/test.h"
namespace xla {
namespace {
// Test that the xla_backend_extra_options flag is parsed correctly.
TEST(DebugOptionsFlags, ParseXlaBackendExtraOptions) {
absl::flat_hash_map<std::string, std::string> test_map;
std::string test_string = "aa=bb,cc,dd=,ee=ff=gg";
parse_xla_backend_extra_options(&test_map, test_string);
EXPECT_EQ(test_map.size(), 4);
EXPECT_EQ(test_map.at("aa"), "bb");
EXPECT_EQ(test_map.at("cc"), "");
EXPECT_EQ(test_map.at("dd"), "");
EXPECT_EQ(test_map.at("ee"), "ff=gg");
}
struct UppercaseStringSetterTestSpec {
std::string user_max_isa;
std::string expected_max_isa;
};
class UppercaseStringSetterTest
: public ::testing::Test,
public ::testing::WithParamInterface<UppercaseStringSetterTestSpec> {
public:
UppercaseStringSetterTest()
: flag_values_(DefaultDebugOptionsIgnoringFlags()) {
MakeDebugOptionsFlags(&flag_objects_, &flag_values_);
}
static std::string Name(
const ::testing::TestParamInfo<UppercaseStringSetterTestSpec>& info) {
return info.param.user_max_isa;
}
DebugOptions flag_values() const { return flag_values_; }
std::vector<tsl::Flag> flag_objects() { return flag_objects_; }
private:
DebugOptions flag_values_;
std::vector<tsl::Flag> flag_objects_;
};
TEST_P(UppercaseStringSetterTest, XlaCpuMaxIsa) {
UppercaseStringSetterTestSpec spec = GetParam();
tsl::setenv("XLA_FLAGS",
absl::StrCat("--xla_cpu_max_isa=", spec.user_max_isa).c_str(),
/*overwrite=*/true);
// Parse flags from the environment variable.
int* pargc;
std::vector<char*>* pargv;
ResetFlagsFromEnvForTesting("XLA_FLAGS", &pargc, &pargv);
ParseFlagsFromEnvAndDieIfUnknown("XLA_FLAGS", flag_objects());
EXPECT_EQ(flag_values().xla_cpu_max_isa(), spec.expected_max_isa);
}
std::vector<UppercaseStringSetterTestSpec> GetUppercaseStringSetterTestCases() {
return std::vector<UppercaseStringSetterTestSpec>({
UppercaseStringSetterTestSpec{"sse4_2", "SSE4_2"},
UppercaseStringSetterTestSpec{"aVx512", "AVX512"},
UppercaseStringSetterTestSpec{"AMx_fP16", "AMX_FP16"},
});
}
INSTANTIATE_TEST_SUITE_P(
UppercaseStringSetterTestInstantiation, UppercaseStringSetterTest,
::testing::ValuesIn(GetUppercaseStringSetterTestCases()),
UppercaseStringSetterTest::Name);
} // namespace
} // namespace xla
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}