-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathutil.cpp
More file actions
110 lines (86 loc) · 3.05 KB
/
util.cpp
File metadata and controls
110 lines (86 loc) · 3.05 KB
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
#include "util/include/util.hpp"
#include <gtest/gtest.h>
#include <libenvpp/detail/environment.hpp>
#include <libenvpp/detail/get.hpp>
#include <string>
#include "omp.h"
namespace my::nested {
struct Type {};
} // namespace my::nested
TEST(util_tests, extracts_correct_namespace) {
std::string k_ns = ppc::util::GetNamespace<my::nested::Type>();
EXPECT_EQ(k_ns, "my::nested");
}
TEST(util_tests, threads_control_check_openmp_disabled_valgrind) {
const auto num_threads_env_var = env::get<int>("PPC_NUM_THREADS");
EXPECT_EQ(ppc::util::GetNumThreads(), omp_get_max_threads());
}
namespace test_ns {
struct TypeInNamespace {};
} // namespace test_ns
struct PlainType {};
TEST(GetNamespaceTest, ReturnsExpectedNamespace) {
std::string k_ns = ppc::util::GetNamespace<test_ns::TypeInNamespace>();
EXPECT_EQ(k_ns, "test_ns");
}
TEST(GetNamespaceTest, ReturnsEmptyIfNoNamespace_PrimitiveType) {
std::string k_ns = ppc::util::GetNamespace<int>();
EXPECT_EQ(k_ns, "");
}
TEST(GetNamespaceTest, ReturnsEmptyIfNoNamespace_PlainStruct) {
std::string k_ns = ppc::util::GetNamespace<PlainType>();
EXPECT_EQ(k_ns, "");
}
namespace test_ns {
struct Nested {};
} // namespace test_ns
TEST(GetNamespaceTest, ReturnsNamespaceCorrectly) {
std::string k_ns = ppc::util::GetNamespace<test_ns::Nested>();
EXPECT_EQ(k_ns, "test_ns");
}
struct NoNamespaceType {};
TEST(GetNamespaceTest, NoNamespaceInType) {
std::string k_ns = ppc::util::GetNamespace<NoNamespaceType>();
EXPECT_EQ(k_ns, "");
}
template <typename T>
struct NotATemplate {};
TEST(GetNamespaceTest, NoKeyInPrettyFunction) {
std::string k_ns = ppc::util::GetNamespace<NotATemplate<void>>();
EXPECT_EQ(k_ns, "");
}
namespace crazy {
struct VeryLongTypeNameWithOnlyLettersAndUnderscores {};
} // namespace crazy
TEST(GetNamespaceTest, NoTerminatorCharactersInPrettyFunction) {
std::string k_ns = ppc::util::GetNamespace<crazy::VeryLongTypeNameWithOnlyLettersAndUnderscores>();
EXPECT_EQ(k_ns, "crazy");
}
TEST(GetTaskMaxTime, ReturnsDefaultWhenUnset) {
const auto old = env::get<double>("PPC_TASK_MAX_TIME");
if (old.has_value()) {
env::detail::delete_environment_variable("PPC_TASK_MAX_TIME");
}
EXPECT_DOUBLE_EQ(ppc::util::GetTaskMaxTime(), 1.0);
if (old.has_value()) {
env::detail::set_environment_variable("PPC_TASK_MAX_TIME", std::to_string(*old));
}
}
TEST(GetTaskMaxTime, ReadsFromEnvironment) {
env::detail::set_scoped_environment_variable scoped("PPC_TASK_MAX_TIME", "2.5");
EXPECT_DOUBLE_EQ(ppc::util::GetTaskMaxTime(), 2.5);
}
TEST(GetPerfMaxTime, ReturnsDefaultWhenUnset) {
const auto old = env::get<double>("PPC_PERF_MAX_TIME");
if (old.has_value()) {
env::detail::delete_environment_variable("PPC_PERF_MAX_TIME");
}
EXPECT_DOUBLE_EQ(ppc::util::GetPerfMaxTime(), 10.0);
if (old.has_value()) {
env::detail::set_environment_variable("PPC_PERF_MAX_TIME", std::to_string(*old));
}
}
TEST(GetPerfMaxTime, ReadsFromEnvironment) {
env::detail::set_scoped_environment_variable scoped("PPC_PERF_MAX_TIME", "12.5");
EXPECT_DOUBLE_EQ(ppc::util::GetPerfMaxTime(), 12.5);
}