Add unit tests for possible_cpus_array_len
[urcu.git] / tests / unit / test_get_max_cpuid_from_mask.c
CommitLineData
4de89c11
MJ
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
13struct parse_test_data {
14 const char *buf;
15 int expected;
16};
17
18static struct parse_test_data parse_test_data[] = {
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 },
37
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 },
56};
57
58static int parse_test_data_len = sizeof(parse_test_data) / sizeof(parse_test_data[0]);
59
60int main(void)
61{
62 int ret, i;
63
64 plan_tests(parse_test_data_len);
65
66 diag("Testing smp helpers");
67
68 for (i = 0; i < parse_test_data_len; i++) {
69 ret = get_max_cpuid_from_mask(parse_test_data[i].buf,
70 strlen(parse_test_data[i].buf));
71 ok(ret == parse_test_data[i].expected,
72 "get_max_cpuid_from_mask '%s', expected: '%d', result: '%d'",
73 parse_test_data[i].buf, parse_test_data[i].expected, ret);
74 }
75
76 return exit_status();
77}
This page took 0.024719 seconds and 4 git commands to generate.