25a2417f4947c91d530adcdb92e7d176840f9877
[urcu.git] / tests / unit / test_get_max_cpuid_from_mask.c
1 /*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 *
4 * Copyright (C) 2022 Michael Jeanson <mjeanson@efficios.com>
5 */
6
7 #include <string.h>
8
9 #include "tap.h"
10
11 #include "compat-smp.h"
12
13 #ifdef __linux__
14 struct parse_test_data {
15 const char *buf;
16 int expected;
17 };
18
19 static struct parse_test_data parse_test_data[] = {
20 { "", -1 },
21 { "abc", -1 },
22 { ",,,", -1 },
23 { "--", -1 },
24 { ",", -1 },
25 { "-", -1 },
26 { "2147483647", -1 },
27 { "18446744073709551615", -1 },
28 { "0-2147483647", -1 },
29 { "0-18446744073709551615", -1 },
30 { "0", 0 },
31 { "1", 1 },
32 { "0-1", 1 },
33 { "1-3", 3 },
34 { "0,2", 2 },
35 { "1,2", 2 },
36 { "0,4-6,127", 127 },
37 { "0-4095", 4095 },
38
39 { "\n", -1 },
40 { "abc\n", -1 },
41 { ",,,\n", -1 },
42 { "--\n", -1 },
43 { ",\n", -1 },
44 { "-\n", -1 },
45 { "2147483647\n", -1 },
46 { "18446744073709551615\n", -1 },
47 { "0-2147483647\n", -1 },
48 { "0-18446744073709551615\n", -1 },
49 { "0\n", 0 },
50 { "1\n", 1 },
51 { "0-1\n", 1 },
52 { "1-3\n", 3 },
53 { "0,2\n", 2 },
54 { "1,2\n", 2 },
55 { "0,4-6,127\n", 127 },
56 { "0-4095\n", 4095 },
57 };
58
59 static int parse_test_data_len = sizeof(parse_test_data) / sizeof(parse_test_data[0]);
60
61 int main(void)
62 {
63 int ret, i;
64
65 plan_tests(parse_test_data_len);
66
67 diag("Testing smp helpers");
68
69 for (i = 0; i < parse_test_data_len; i++) {
70 ret = get_max_cpuid_from_mask(parse_test_data[i].buf,
71 strlen(parse_test_data[i].buf));
72 ok(ret == parse_test_data[i].expected,
73 "get_max_cpuid_from_mask '%s', expected: '%d', result: '%d'",
74 parse_test_data[i].buf, parse_test_data[i].expected, ret);
75 }
76
77 return exit_status();
78 }
79
80 #else
81
82 int main(void)
83 {
84 plan_skip_all("Linux specific tests.");
85
86 return exit_status();
87 }
88 #endif
This page took 0.042843 seconds and 5 git commands to generate.