dte test coverage


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 50.0% high: ≥ 85.0%
Coverage Exec / Excl / Total
Lines: 100.0% 22 / 0 / 22
Functions: 100.0% 5 / 0 / 5
Branches: 75.0% 6 / 6 / 14

src/trace.c
Line Branch Exec Source
1 #include "trace.h"
2 #include "util/array.h"
3 #include "util/xstring.h"
4
5 #if TRACE_LOGGING_ENABLED
6
7 // NOLINTNEXTLINE(*-avoid-non-const-global-variables)
8 static TraceLoggingFlags trace_flags = 0;
9
10 static const char trace_names[][8] = {
11 "command",
12 "input",
13 "output",
14 };
15
16 24 UNITTEST {
17 24 CHECK_STRING_ARRAY(trace_names);
18 24 }
19
20 // Example valid input: "command,status,input"
21 7 TraceLoggingFlags trace_flags_from_str(const char *str)
22 {
23
3/4
✓ Branch 2 → 3 taken 7 times.
✗ Branch 2 → 6 not taken.
✓ Branch 3 → 4 taken 6 times.
✓ Branch 3 → 6 taken 1 time.
7 if (!str || str[0] == '\0') {
24 return 0;
25 }
26
27 6 bool all = streq(str, "all");
28
1/2
✓ Branch 4 → 5 taken 6 times.
✗ Branch 4 → 6 not taken.
6 return all ? TRACEFLAGS_ALL : STR_TO_BITFLAGS(str, trace_names, true);
29 }
30
31 1 void set_trace_logging_flags(TraceLoggingFlags flags)
32 {
33 1 BUG_ON(trace_flags); // Should be called at most once
34 1 BUG_ON(!flags); // ... with non-zero flags
35 1 BUG_ON(!log_level_enabled(LOG_LEVEL_TRACE)); // ... and only when enabled
36 1 trace_flags = flags;
37 1 }
38
39 // Return true if *any* 1 bits in `flags` are enabled in `trace_flags`
40 53 bool log_trace_enabled(TraceLoggingFlags flags)
41 {
42 53 return !!(trace_flags & flags);
43 }
44
45 51 void log_trace(TraceLoggingFlags flags, const char *file, int line, const char *fmt, ...)
46 {
47
2/2
✓ Branch 2 → 3 taken 9 times.
✓ Branch 2 → 4 taken 42 times.
51 if (!log_trace_enabled(flags)) {
48 9 return;
49 }
50
51 42 va_list ap;
52 42 va_start(ap, fmt);
53 42 log_msgv(LOG_LEVEL_TRACE, file, line, fmt, ap);
54 42 va_end(ap);
55 }
56
57 #endif // TRACE_LOGGING_ENABLED
58