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