• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

llnl / dftracer / 27009054001

05 Jun 2026 10:14AM UTC coverage: 18.437%. First build
27009054001

Pull #352

github

web-flow
Merge 02db0fea0 into a4a7a5cb6
Pull Request #352: fix: update logger types and improve error logging messages

7268 of 53566 branches covered (13.57%)

Branch coverage included in aggregate %.

380 of 702 new or added lines in 31 files covered. (54.13%)

4776 of 11760 relevant lines covered (40.61%)

1107.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.35
/test/unit/test_aggregated_key_hash.cpp
1
#include <dftracer/core/common/datastructure.h>
2

3
#include <cassert>
4
#include <iostream>
5
#include <unordered_map>
6

7
using namespace dftracer;
8

9
void test_hash_equality_basic() {
1✔
10
  std::cout << "=== Test: Hash Equality - Basic Fields ===\n" << std::endl;
1✔
11

12
  AggregatedKey key1("posix", "read", 100, 50, 1, nullptr, nullptr, nullptr);
1✔
13
  AggregatedKey key2("posix", "read", 100, 50, 1, nullptr, nullptr, nullptr);
1✔
14

15
  std::hash<AggregatedKey> hasher;
16
  size_t hash1 = hasher(key1);
1✔
17
  size_t hash2 = hasher(key2);
1✔
18

19
  assert(key1 == key2);
1!
20
  assert(hash1 == hash2);
1!
21

22
  std::cout << "✓ Basic hash equality test passed\n" << std::endl;
1✔
23
}
1✔
24

25
void test_hash_inequality_basic() {
1✔
26
  std::cout << "=== Test: Hash Inequality - Basic Fields ===\n" << std::endl;
1✔
27

28
  AggregatedKey key1("posix", "read", 100, 50, 1, nullptr, nullptr, nullptr);
1✔
29
  AggregatedKey key2("posix", "write", 100, 50, 1, nullptr, nullptr, nullptr);
1✔
30

31
  std::hash<AggregatedKey> hasher;
32
  size_t hash1 = hasher(key1);
1✔
33
  size_t hash2 = hasher(key2);
1✔
34

35
  assert(!(key1 == key2));
1!
36
  assert(hash1 != hash2);
1!
37

38
  std::cout << "✓ Basic hash inequality test passed\n" << std::endl;
1✔
39
}
1✔
40

41
void test_hash_equality_with_metadata() {
1✔
42
  std::cout << "=== Test: Hash Equality - With Metadata ===\n" << std::endl;
1✔
43

44
  Metadata metadata1;
1✔
45
  metadata1.insert_or_assign("rank", static_cast<int>(5));
1✔
46
  metadata1.insert_or_assign("file_size", static_cast<uint64_t>(1024));
1✔
47

48
  Metadata metadata2;
1✔
49
  metadata2.insert_or_assign("rank", static_cast<int>(5));
1✔
50
  metadata2.insert_or_assign("file_size", static_cast<uint64_t>(1024));
1✔
51

52
  AggregatedKey key1("posix", "read", 100, 50, 2, &metadata1, "app1", nullptr);
1✔
53
  AggregatedKey key2("posix", "read", 100, 50, 2, &metadata2, "app1", nullptr);
1✔
54

55
  std::hash<AggregatedKey> hasher;
56
  size_t hash1 = hasher(key1);
1✔
57
  size_t hash2 = hasher(key2);
1✔
58

59
  assert(key1 == key2);
1!
60
  assert(hash1 == hash2);
1!
61

62
  std::cout << "✓ Hash equality with metadata test passed\n" << std::endl;
1✔
63
}
1✔
64

65
void test_hash_inequality_with_different_metadata() {
1✔
66
  std::cout << "=== Test: Hash Inequality - Different Metadata ===\n"
1✔
67
            << std::endl;
1✔
68

69
  Metadata metadata1;
1✔
70
  metadata1.insert_or_assign("rank", static_cast<int>(5));
1✔
71

72
  Metadata metadata2;
1✔
73
  metadata2.insert_or_assign("rank", static_cast<int>(7));
1✔
74

75
  AggregatedKey key1("posix", "read", 100, 50, 2, &metadata1, "app1", nullptr);
1✔
76
  AggregatedKey key2("posix", "read", 100, 50, 2, &metadata2, "app1", nullptr);
1✔
77

78
  std::hash<AggregatedKey> hasher;
79
  size_t hash1 = hasher(key1);
1✔
80
  size_t hash2 = hasher(key2);
1✔
81

82
  assert(!(key1 == key2));
1!
83
  // Different metadata should (very likely) produce different hashes
84
  // Note: hash collisions are possible but extremely unlikely
85
  assert(hash1 != hash2);
1!
86

87
  std::cout << "✓ Hash inequality with different metadata test passed\n"
1✔
88
            << std::endl;
1✔
89
}
1✔
90

91
void test_hash_in_unordered_map() {
1✔
92
  std::cout << "=== Test: Hash in Unordered Map ===\n" << std::endl;
1✔
93

94
  Metadata metadata1;
1✔
95
  metadata1.insert_or_assign("operation", std::string("read"));
1✔
96

97
  Metadata metadata2;
1✔
98
  metadata2.insert_or_assign("operation", std::string("read"));
1✔
99

100
  AggregatedKey key1("posix", "read", 100, 50, 1, &metadata1, nullptr, nullptr);
1✔
101
  AggregatedKey key2("posix", "read", 100, 50, 1, &metadata2, nullptr, nullptr);
1✔
102

103
  std::unordered_map<AggregatedKey, int> map;
1✔
104
  map[key1] = 10;
1✔
105

106
  // key2 should find the same entry since key1 == key2 and hash1 == hash2
107
  assert(map.find(key2) != map.end());
1!
108
  assert(map[key2] == 10);
1!
109

110
  std::cout << "✓ Hash in unordered map test passed\n" << std::endl;
1✔
111
}
1✔
112

113
void test_hash_contract() {
1✔
114
  std::cout << "=== Test: Hash Contract (Equal Objects Have Equal Hashes) ===\n"
1✔
115
            << std::endl;
1✔
116

117
  // Generate multiple identical keys with metadata
118
  for (int i = 0; i < 5; ++i) {
6✔
119
    Metadata metadata;
5✔
120
    metadata.insert_or_assign("batch", static_cast<int>(i));
5✔
121

122
    AggregatedKey key1("posix", "write", 200, 100, 3, &metadata, "test_app",
123
                       nullptr);
5✔
124
    AggregatedKey key2("posix", "write", 200, 100, 3, &metadata, "test_app",
125
                       nullptr);
5✔
126

127
    std::hash<AggregatedKey> hasher;
128
    size_t hash1 = hasher(key1);
5✔
129
    size_t hash2 = hasher(key2);
5✔
130

131
    assert(key1 == key2);
5!
132
    assert(hash1 == hash2);
5!
133
  }
5✔
134

135
  std::cout << "✓ Hash contract test passed\n" << std::endl;
1✔
136
}
1✔
137

138
int main() {
1✔
139
  try {
140
    test_hash_equality_basic();
1✔
141
    test_hash_inequality_basic();
1✔
142
    test_hash_equality_with_metadata();
1✔
143
    test_hash_inequality_with_different_metadata();
1✔
144
    test_hash_in_unordered_map();
1✔
145
    test_hash_contract();
1✔
146

147
    std::cout << "\n✓✓✓ All AggregatedKey hash tests passed! ✓✓✓\n"
1✔
148
              << std::endl;
1✔
149
    return 0;
1✔
NEW
150
  } catch (const std::exception& e) {
×
151
    std::cerr << "✗ Test failed with exception: " << e.what() << std::endl;
×
152
    return 1;
×
153
  }
×
154
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc