GCC Code Coverage Report


Directory: ./
File: modules/util/include/util.hpp
Date: 2025-08-13 00:58:25
Exec Total Coverage
Lines: 8 8 100.0%
Functions: 10 10 100.0%
Branches: 12 21 57.1%

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