1 // SPDX-License-Identifier: GPL-2.0
2 #include <test_progs.h>
4 #include "bpf/libbpf_internal.h"
6 static int duration
= 0;
8 static void validate_mask(int case_nr
, const char *exp
, bool *mask
, int n
)
12 for (i
= 0; exp
[i
]; i
++) {
14 if (CHECK(i
+ 1 > n
, "mask_short",
15 "case #%d: mask too short, got n=%d, need at least %d\n",
18 CHECK(!mask
[i
], "cpu_not_set",
19 "case #%d: mask differs, expected cpu#%d SET\n",
22 CHECK(i
< n
&& mask
[i
], "cpu_set",
23 "case #%d: mask differs, expected cpu#%d UNSET\n",
27 CHECK(i
< n
, "mask_long",
28 "case #%d: mask too long, got n=%d, expected at most %d\n",
37 { "0\n", "1", false },
38 { "0,2\n", "101", false },
39 { "0-2\n", "111", false },
40 { "0-2,3-4\n", "11111", false },
42 { "0-2", "111", false },
43 { "0,2", "101", false },
44 { "0,1-3", "1111", false },
45 { "0,1,2,3", "1111", false },
46 { "0,2-3,5", "101101", false },
47 { "3-3", "0001", false },
48 { "2-4,6,9-10", "00111010011", false },
63 for (i
= 0; i
< ARRAY_SIZE(test_cases
); i
++) {
65 err
= parse_cpu_mask_str(test_cases
[i
].cpu_mask
, &mask
, &n
);
66 if (test_cases
[i
].fails
) {
67 CHECK(!err
, "should_fail",
68 "case #%d: parsing should fail!\n", i
+ 1);
70 if (CHECK(err
, "parse_err",
71 "case #%d: cpu mask parsing failed: %d\n",
74 validate_mask(i
+ 1, test_cases
[i
].expect
, mask
, n
);