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