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

LLNL / dftracer / 2760

02 Dec 2025 05:20AM UTC coverage: 38.87% (+9.8%) from 29.083%
2760

push

github

web-flow
Merge f1f0c2140 into 4ef0a645e

3634 of 12986 branches covered (27.98%)

Branch coverage included in aggregate %.

894 of 962 new or added lines in 7 files covered. (92.93%)

6 existing lines in 1 file now uncovered.

3085 of 4300 relevant lines covered (71.74%)

1001.98 hits per line

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

87.13
/test/unit/test_configuration.cpp
1
#include <dftracer/core/common/enumeration.h>
2
#include <dftracer/core/utils/configuration_manager.h>
3

4
#include <cassert>
5
#include <filesystem>
6
#include <fstream>
7
#include <iostream>
8

9
using namespace dftracer;
10

11
void test_default_configuration() {
1✔
12
  std::cout << "Testing default configuration..." << std::endl;
1✔
13

14
  // Clear all DFTRACER environment variables to test defaults
15
  unsetenv("DFTRACER_ENABLE");
1✔
16
  unsetenv("DFTRACER_ENABLE_AGGREGATION");
1✔
17
  unsetenv("DFTRACER_LOG_LEVEL");
1✔
18
  unsetenv("DFTRACER_AGGREGATION_TYPE");
1✔
19
  unsetenv("DFTRACER_TRACE_COMPRESSION");
1✔
20
  unsetenv("DFTRACER_INC_METADATA");
1✔
21

22
  // Create a fresh configuration instance
23
  auto config = std::make_shared<ConfigurationManager>();
1✔
24

25
  // Check defaults
26
  assert(config->enable ==
1!
27
         false);  // Defaults to false, only true if DFTRACER_ENABLE=1
28
  assert(config->aggregation_enable == false);
1!
29
  assert(config->compression == true);  // Constructor default is true
1!
30
  assert(config->metadata == false);
1!
31

32
  std::cout << "✓ Default configuration tests passed" << std::endl;
1✔
33
}
1✔
34

35
void test_environment_variables() {
1✔
36
  std::cout << "Testing environment variable configuration..." << std::endl;
1✔
37

38
  // Test DFTRACER_ENABLE
39
  setenv("DFTRACER_ENABLE", "0", 1);
1✔
40
  auto config1 = std::make_shared<ConfigurationManager>();
1✔
41
  assert(config1->enable == false);
1!
42
  unsetenv("DFTRACER_ENABLE");
1✔
43

44
  // Test DFTRACER_ENABLE_AGGREGATION (requires DFTRACER_ENABLE=1)
45
  setenv("DFTRACER_ENABLE", "1", 1);
1✔
46
  setenv("DFTRACER_ENABLE_AGGREGATION", "1", 1);
1✔
47
  auto config2 = std::make_shared<ConfigurationManager>();
1✔
48
  assert(config2->enable == true);
1!
49
  assert(config2->aggregation_enable == true);
1!
50
  assert(config2->aggregation_type == AggregationType::AGGREGATION_TYPE_FULL);
1!
51
  unsetenv("DFTRACER_ENABLE_AGGREGATION");
1✔
52
  unsetenv("DFTRACER_ENABLE");
1✔
53

54
  // Test DFTRACER_AGGREGATION_TYPE (requires DFTRACER_ENABLE=1 and
55
  // DFTRACER_ENABLE_AGGREGATION=1)
56
  setenv("DFTRACER_ENABLE", "1", 1);
1✔
57
  setenv("DFTRACER_ENABLE_AGGREGATION", "1", 1);
1✔
58
  setenv("DFTRACER_AGGREGATION_TYPE", "SELECTIVE", 1);
1✔
59
  auto config3 = std::make_shared<ConfigurationManager>();
1✔
60
  assert(config3->aggregation_enable == true);
1!
61
  assert(config3->aggregation_type ==
1!
62
         AggregationType::AGGREGATION_TYPE_SELECTIVE);
63
  unsetenv("DFTRACER_ENABLE_AGGREGATION");
1✔
64
  unsetenv("DFTRACER_AGGREGATION_TYPE");
1✔
65
  unsetenv("DFTRACER_ENABLE");
1✔
66

67
  // Test compression (requires DFTRACER_ENABLE=1)
68
  setenv("DFTRACER_ENABLE", "1", 1);
1✔
69
  setenv("DFTRACER_TRACE_COMPRESSION", "0", 1);
1✔
70
  auto config4 = std::make_shared<ConfigurationManager>();
1✔
71
  assert(config4->compression == false);
1!
72
  unsetenv("DFTRACER_TRACE_COMPRESSION");
1✔
73
  unsetenv("DFTRACER_ENABLE");
1✔
74

75
  // Test metadata (requires DFTRACER_ENABLE=1)
76
  setenv("DFTRACER_ENABLE", "1", 1);
1✔
77
  setenv("DFTRACER_INC_METADATA", "1", 1);
1✔
78
  auto config5 = std::make_shared<ConfigurationManager>();
1✔
79
  assert(config5->metadata == true);
1!
80
  unsetenv("DFTRACER_INC_METADATA");
1✔
81
  unsetenv("DFTRACER_ENABLE");
1✔
82

83
  // Test trace interval (requires DFTRACER_ENABLE=1)
84
  setenv("DFTRACER_ENABLE", "1", 1);
1✔
85
  setenv("DFTRACER_TRACE_INTERVAL_MS", "2000", 1);
1✔
86
  auto config6 = std::make_shared<ConfigurationManager>();
1✔
87
  assert(config6->trace_interval_ms == 2000);
1!
88
  unsetenv("DFTRACER_TRACE_INTERVAL_MS");
1✔
89
  unsetenv("DFTRACER_ENABLE");
1✔
90

91
  std::cout << "✓ Environment variable configuration tests passed" << std::endl;
1✔
92
}
1✔
93

94
void test_aggregation_rules_from_file() {
1✔
95
  std::cout << "Testing aggregation rules from file..." << std::endl;
1✔
96

97
  // Create a temporary YAML file with rules
98
  // Note: Keys are "inclusion" and "exclusion" at the root level
99
  std::string yaml_path = "/tmp/test_rules.yaml";
1✔
100
  std::ofstream yaml_file(yaml_path);
1✔
101
  yaml_file << "inclusion:\n";
1✔
102
  yaml_file << "  - \"cat == 'posix'\"\n";
1✔
103
  yaml_file << "  - \"name LIKE 'read%'\"\n";
1✔
104
  yaml_file << "exclusion:\n";
1✔
105
  yaml_file << "  - \"name == 'stat'\"\n";
1✔
106
  yaml_file.close();
1✔
107

108
  // Set environment variables (requires DFTRACER_ENABLE=1)
109
  setenv("DFTRACER_ENABLE", "1", 1);
1✔
110
  setenv("DFTRACER_ENABLE_AGGREGATION", "1", 1);
1✔
111
  setenv("DFTRACER_AGGREGATION_TYPE", "SELECTIVE", 1);
1✔
112
  setenv("DFTRACER_AGGREGATION_FILE", yaml_path.c_str(), 1);
1✔
113

114
  auto config = std::make_shared<ConfigurationManager>();
1✔
115

116
  // Check that rules were loaded
117
  assert(config->aggregation_inclusion_rules.size() == 2);
1!
118
  assert(config->aggregation_exclusion_rules.size() == 1);
1!
119
  assert(config->aggregation_inclusion_rules[0] == "cat == 'posix'");
1!
120
  assert(config->aggregation_inclusion_rules[1] == "name LIKE 'read%'");
1!
121
  assert(config->aggregation_exclusion_rules[0] == "name == 'stat'");
1!
122

123
  // Cleanup
124
  std::filesystem::remove(yaml_path);
1✔
125
  unsetenv("DFTRACER_ENABLE");
1✔
126
  unsetenv("DFTRACER_ENABLE_AGGREGATION");
1✔
127
  unsetenv("DFTRACER_AGGREGATION_TYPE");
1✔
128
  unsetenv("DFTRACER_AGGREGATION_FILE");
1✔
129

130
  std::cout << "✓ Aggregation rules from file tests passed" << std::endl;
1✔
131
}
1✔
132

133
void test_log_file_configuration() {
1✔
134
  std::cout << "Testing log file configuration..." << std::endl;
1✔
135

136
  const char* test_log_file = "/tmp/test_trace.pfw";
1✔
137
  setenv("DFTRACER_ENABLE", "1", 1);
1✔
138
  setenv("DFTRACER_LOG_FILE", test_log_file, 1);
1✔
139

140
  auto config = std::make_shared<ConfigurationManager>();
1✔
141
  assert(config->log_file == test_log_file);
1!
142

143
  unsetenv("DFTRACER_ENABLE");
1✔
144
  unsetenv("DFTRACER_LOG_FILE");
1✔
145

146
  std::cout << "✓ Log file configuration tests passed" << std::endl;
1✔
147
}
1✔
148

149
void test_data_dirs_configuration() {
1✔
150
  std::cout << "Testing data dirs configuration..." << std::endl;
1✔
151

152
  const char* test_dirs = "/data1:/data2:/data3";
1✔
153
  setenv("DFTRACER_ENABLE", "1", 1);
1✔
154
  setenv("DFTRACER_DATA_DIR", test_dirs, 1);
1✔
155

156
  auto config = std::make_shared<ConfigurationManager>();
1✔
157
  assert(config->data_dirs == test_dirs);
1!
158

159
  unsetenv("DFTRACER_ENABLE");
1✔
160
  unsetenv("DFTRACER_DATA_DIR");
1✔
161

162
  std::cout << "✓ Data dirs configuration tests passed" << std::endl;
1✔
163
}
1✔
164

165
void test_io_flags() {
1✔
166
  std::cout << "Testing I/O flags configuration..." << std::endl;
1✔
167

168
  // Test POSIX disabled (default is true)
169
  setenv("DFTRACER_ENABLE", "1", 1);
1✔
170
  setenv("DFTRACER_DISABLE_POSIX", "1", 1);
1✔
171
  auto config1 = std::make_shared<ConfigurationManager>();
1✔
172
  assert(config1->posix == false);
1!
173
  unsetenv("DFTRACER_DISABLE_POSIX");
1✔
174
  unsetenv("DFTRACER_ENABLE");
1✔
175

176
  // Test STDIO disabled (default is true)
177
  setenv("DFTRACER_ENABLE", "1", 1);
1✔
178
  setenv("DFTRACER_DISABLE_STDIO", "1", 1);
1✔
179
  auto config2 = std::make_shared<ConfigurationManager>();
1✔
180
  assert(config2->stdio == false);
1!
181
  unsetenv("DFTRACER_DISABLE_STDIO");
1✔
182
  unsetenv("DFTRACER_ENABLE");
1✔
183

184
  // Test generic IO disabled (default is true)
185
  setenv("DFTRACER_ENABLE", "1", 1);
1✔
186
  setenv("DFTRACER_DISABLE_IO", "1", 1);
1✔
187
  auto config3 = std::make_shared<ConfigurationManager>();
1✔
188
  assert(config3->io == false);
1!
189
  unsetenv("DFTRACER_DISABLE_IO");
1✔
190
  unsetenv("DFTRACER_ENABLE");
1✔
191

192
  std::cout << "✓ I/O flags configuration tests passed" << std::endl;
1✔
193
}
1✔
194

195
void test_buffer_size_configuration() {
1✔
196
  std::cout << "Testing buffer size configuration..." << std::endl;
1✔
197

198
  const size_t test_size = 1024 * 1024;  // 1MB
1✔
199
  setenv("DFTRACER_ENABLE", "1", 1);
1✔
200
  setenv("DFTRACER_WRITE_BUFFER_SIZE", "1048576", 1);
1✔
201

202
  auto config = std::make_shared<ConfigurationManager>();
1✔
203
  assert(config->write_buffer_size == test_size);
1!
204

205
  unsetenv("DFTRACER_ENABLE");
1✔
206
  unsetenv("DFTRACER_WRITE_BUFFER_SIZE");
1✔
207

208
  std::cout << "✓ Buffer size configuration tests passed" << std::endl;
1✔
209
}
1✔
210

211
void test_logger_level() {
1✔
212
  std::cout << "Testing logger level configuration..." << std::endl;
1✔
213

214
  // Test DEBUG level
215
  setenv("DFTRACER_LOG_LEVEL", "DEBUG", 1);
1✔
216
  auto config1 = std::make_shared<ConfigurationManager>();
1✔
217
  assert(config1->logger_level == cpplogger::LoggerType::LOG_DEBUG);
1!
218
  unsetenv("DFTRACER_LOG_LEVEL");
1✔
219

220
  // Test INFO level
221
  setenv("DFTRACER_LOG_LEVEL", "INFO", 1);
1✔
222
  auto config2 = std::make_shared<ConfigurationManager>();
1✔
223
  assert(config2->logger_level == cpplogger::LoggerType::LOG_INFO);
1!
224
  unsetenv("DFTRACER_LOG_LEVEL");
1✔
225

226
  // Test ERROR level
227
  setenv("DFTRACER_LOG_LEVEL", "ERROR", 1);
1✔
228
  auto config3 = std::make_shared<ConfigurationManager>();
1✔
229
  assert(config3->logger_level == cpplogger::LoggerType::LOG_ERROR);
1!
230
  unsetenv("DFTRACER_LOG_LEVEL");
1✔
231

232
  std::cout << "✓ Logger level configuration tests passed" << std::endl;
1✔
233
}
1✔
234

235
int main(int argc, char* argv[]) {
1✔
236
  std::cout << "=== Running Configuration Manager Unit Tests ===" << std::endl;
1✔
237

238
  try {
239
    test_default_configuration();
1✔
240
    test_environment_variables();
1✔
241
    test_aggregation_rules_from_file();
1✔
242
    test_log_file_configuration();
1✔
243
    test_data_dirs_configuration();
1✔
244
    test_io_flags();
1✔
245
    test_buffer_size_configuration();
1✔
246
    test_logger_level();
1✔
247

248
    std::cout << "\n✓ All Configuration Manager tests passed!" << std::endl;
1✔
249
    return 0;
1✔
NEW
250
  } catch (const std::exception& e) {
×
NEW
251
    std::cerr << "✗ Test failed with exception: " << e.what() << std::endl;
×
NEW
252
    return 1;
×
NEW
253
  }
×
254
}
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