Commit | Line | Data |
---|---|---|
fe9615ba MJ |
1 | /* |
2 | * SPDX-License-Identifier: LGPL-2.1-only | |
3 | * | |
fb0f6ca9 | 4 | * Copyright (C) 2022 Michael Jeanson <mjeanson@efficios.com> |
fe9615ba MJ |
5 | */ |
6 | ||
fe9615ba MJ |
7 | #include <string.h> |
8 | ||
9 | #include "tap.h" | |
10 | ||
11 | #include "common/smp.h" | |
12 | ||
13 | struct parse_test_data { | |
14 | const char *buf; | |
15 | int expected; | |
16 | }; | |
17 | ||
18 | static struct parse_test_data parse_test_data[] = { | |
a616fb4e MJ |
19 | { "", -1 }, |
20 | { "abc", -1 }, | |
21 | { ",,,", -1 }, | |
22 | { "--", -1 }, | |
23 | { ",", -1 }, | |
24 | { "-", -1 }, | |
25 | { "2147483647", -1 }, | |
26 | { "18446744073709551615", -1 }, | |
27 | { "0-2147483647", -1 }, | |
28 | { "0-18446744073709551615", -1 }, | |
29 | { "0", 0 }, | |
30 | { "1", 1 }, | |
31 | { "0-1", 1 }, | |
32 | { "1-3", 3 }, | |
33 | { "0,2", 2 }, | |
34 | { "1,2", 2 }, | |
35 | { "0,4-6,127", 127 }, | |
36 | { "0-4095", 4095 }, | |
fe9615ba | 37 | |
a616fb4e MJ |
38 | { "\n", -1 }, |
39 | { "abc\n", -1 }, | |
40 | { ",,,\n", -1 }, | |
41 | { "--\n", -1 }, | |
42 | { ",\n", -1 }, | |
43 | { "-\n", -1 }, | |
44 | { "2147483647\n", -1 }, | |
45 | { "18446744073709551615\n", -1 }, | |
46 | { "0-2147483647\n", -1 }, | |
47 | { "0-18446744073709551615\n", -1 }, | |
48 | { "0\n", 0 }, | |
49 | { "1\n", 1 }, | |
50 | { "0-1\n", 1 }, | |
51 | { "1-3\n", 3 }, | |
52 | { "0,2\n", 2 }, | |
53 | { "1,2\n", 2 }, | |
54 | { "0,4-6,127\n", 127 }, | |
55 | { "0-4095\n", 4095 }, | |
fe9615ba MJ |
56 | }; |
57 | ||
58 | static int parse_test_data_len = sizeof(parse_test_data) / sizeof(parse_test_data[0]); | |
59 | ||
60 | int main(void) | |
61 | { | |
62 | int ret, i; | |
63 | ||
fb0f6ca9 | 64 | plan_tests(parse_test_data_len); |
fe9615ba MJ |
65 | |
66 | diag("Testing smp helpers"); | |
67 | ||
68 | for (i = 0; i < parse_test_data_len; i++) { | |
a616fb4e | 69 | ret = get_max_cpuid_from_mask(parse_test_data[i].buf, |
fe9615ba MJ |
70 | strlen(parse_test_data[i].buf)); |
71 | ok(ret == parse_test_data[i].expected, | |
a616fb4e | 72 | "get_max_cpuid_from_mask '%s', expected: '%d', result: '%d'", |
fe9615ba MJ |
73 | parse_test_data[i].buf, parse_test_data[i].expected, ret); |
74 | } | |
75 | ||
fe9615ba MJ |
76 | return exit_status(); |
77 | } |