Line | Branch | Exec | Source |
---|---|---|---|
1 | #pragma once | ||
2 | |||
3 | #include <atomic> | ||
4 | #include <cstdint> | ||
5 | #include <cstdlib> | ||
6 | #include <memory> | ||
7 | #include <string> | ||
8 | #include <typeinfo> | ||
9 | #ifdef __GNUG__ | ||
10 | # include <cxxabi.h> | ||
11 | #endif | ||
12 | |||
13 | #include "nlohmann/json_fwd.hpp" | ||
14 | |||
15 | #ifdef _MSC_VER | ||
16 | # pragma warning(push) | ||
17 | # pragma warning(disable : 4459) | ||
18 | #endif | ||
19 | |||
20 | #include <nlohmann/json.hpp> | ||
21 | |||
22 | /// @brief JSON namespace used for settings and config parsing. | ||
23 | using NlohmannJsonParseError = nlohmann::json::parse_error; | ||
24 | /// @brief JSON namespace used for settings and config typing. | ||
25 | using NlohmannJsonTypeError = nlohmann::json::type_error; | ||
26 | #ifdef _MSC_VER | ||
27 | # pragma warning(pop) | ||
28 | #endif | ||
29 | |||
30 | namespace ppc::util { | ||
31 | |||
32 | /// @brief Utility class for tracking destructor failure across tests. | ||
33 | /// @details Provides thread-safe methods to set, unset, and check the failure flag. | ||
34 | class DestructorFailureFlag { | ||
35 | public: | ||
36 | /// @brief Marks that a destructor failure has occurred. | ||
37 | static void Set() { | ||
38 | failure_flag.store(true); | ||
39 | 30 | } | |
40 | |||
41 | /// @brief Clears the destructor failure flag. | ||
42 | static void Unset() { | ||
43 | failure_flag.store(false); | ||
44 | } | ||
45 | |||
46 | /// @brief Checks if a destructor failure was recorded. | ||
47 | /// @return True if failure occurred, false otherwise. | ||
48 | static bool Get() { | ||
49 | return failure_flag.load(); | ||
50 | } | ||
51 | |||
52 | private: | ||
53 | inline static std::atomic<bool> failure_flag{false}; | ||
54 | }; | ||
55 | |||
56 | enum class GTestParamIndex : uint8_t { kTaskGetter, kNameTest, kTestParams }; | ||
57 | |||
58 | std::string GetAbsoluteTaskPath(const std::string& id_path, const std::string& relative_path); | ||
59 | int GetNumThreads(); | ||
60 | int GetNumProc(); | ||
61 | double GetTaskMaxTime(); | ||
62 | double GetPerfMaxTime(); | ||
63 | |||
64 | template <typename T> | ||
65 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 608 times.
|
1326 | std::string GetNamespace() { |
66 | 1326 | std::string name = typeid(T).name(); | |
67 | #ifdef __GNUC__ | ||
68 |
1/2✓ Branch 1 taken 628 times.
✗ Branch 2 not taken.
|
1326 | int status = 0; |
69 |
1/2✓ Branch 1 taken 628 times.
✗ Branch 2 not taken.
|
1326 | std::unique_ptr<char, void (*)(void*)> demangled{abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), |
70 | std::free}; | ||
71 |
4/8✓ Branch 0 taken 628 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 628 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 608 times.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
2652 | name = (status == 0) ? demangled.get() : name; |
72 | #endif | ||
73 | #ifdef _MSC_VER | ||
74 | const std::string prefixes[] = {"class ", "struct ", "enum ", "union "}; | ||
75 | for (const auto& prefix : prefixes) { | ||
76 | if (name.starts_with(prefix)) { | ||
77 | name = name.substr(prefix.size()); | ||
78 | break; | ||
79 | } | ||
80 | } | ||
81 | name.erase(0, name.find_first_not_of(' ')); | ||
82 | #endif | ||
83 | auto pos = name.rfind("::"); | ||
84 |
3/4✓ Branch 0 taken 608 times.
✓ Branch 1 taken 20 times.
✓ Branch 3 taken 608 times.
✗ Branch 4 not taken.
|
2652 | return (pos != std::string::npos) ? name.substr(0, pos) : std::string{}; |
85 | } | ||
86 | |||
87 | inline std::shared_ptr<nlohmann::json> InitJSONPtr() { | ||
88 |
2/3✓ Branch 1 taken 588 times.
✓ Branch 2 taken 200 times.
✗ Branch 3 not taken.
|
848 | return std::make_shared<nlohmann::json>(); |
89 | } | ||
90 | |||
91 | bool IsUnderMpirun(); | ||
92 | |||
93 | } // namespace ppc::util | ||
94 |