dte test coverage


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 50.0% high: ≥ 85.0%
Coverage Exec / Excl / Total
Lines: 100.0% 18 / 0 / 18
Functions: 100.0% 2 / 0 / 2
Branches: 100.0% 10 / 0 / 10

src/util/array.c
Line Branch Exec Source
1 #include "array.h"
2 #include "log.h"
3 #include "str-util.h"
4 #include "xmalloc.h"
5
6 // This can be used to collect all prefix-matched strings from a "flat" array
7 // (i.e. an array of fixed-length char arrays; *not* pointers to char)
8 20 void collect_strings_from_flat_array (
9 const char *base,
10 size_t nr_elements,
11 size_t element_len,
12 PointerArray *a,
13 StringView prefix
14 ) {
15 20 const char *end = base + (nr_elements * element_len);
16
2/2
✓ Branch 7 → 3 taken 562 times.
✓ Branch 7 → 8 taken 20 times.
582 for (const char *str = base; str < end; str += element_len) {
17
2/2
✓ Branch 3 → 4 taken 317 times.
✓ Branch 3 → 6 taken 245 times.
562 if (str_has_sv_prefix(str, prefix)) {
18 317 ptr_array_append(a, xstrdup(str));
19 }
20 }
21 20 }
22
23 // Return bitflags corresponding to a set of comma-delimited substrings
24 // found in an array. For example, if the string is "str3,str7" and
25 // those 2 substrings are found at array[3] and array[7] respectively,
26 // the returned value will be `1 << 3 | 1 << 7`.
27 9 unsigned int str_to_bitflags (
28 StringView str,
29 const char *base, // Pointer to start of char[nstrs][size] array
30 size_t nstrs,
31 size_t size,
32 bool tolerate_errors // Whether to ignore invalid substrings
33 ) {
34 9 unsigned int flags = 0;
35
2/2
✓ Branch 12 → 3 taken 20 times.
✓ Branch 12 → 13 taken 8 times.
28 for (size_t pos = 0; pos < str.length; ) {
36 20 StringView substr = get_delim(str, &pos, ',');
37 20 ssize_t idx = find_strview_idx(substr, base, nstrs, size);
38
2/2
✓ Branch 5 → 6 taken 10 times.
✓ Branch 5 → 10 taken 10 times.
20 if (unlikely(idx < 0)) {
39
2/2
✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 8 taken 9 times.
10 if (!tolerate_errors) {
40 1 return 0;
41 }
42 9 LOG_WARNING("unrecognized flag string: '%.*s'", SV_FMT(substr));
43 9 continue;
44 }
45 10 flags |= 1u << idx;
46 }
47
48 8 return flags;
49 }
50