Clarify terminolgy around cpu ids and array length
[lttng-ust.git] / tests / unit / libcommon / test_smp.c
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[] = {
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 },
42
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 },
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++) {
74 ret = get_max_cpuid_from_mask(parse_test_data[i].buf,
75 strlen(parse_test_data[i].buf));
76 ok(ret == parse_test_data[i].expected,
77 "get_max_cpuid_from_mask '%s', expected: '%d', result: '%d'",
78 parse_test_data[i].buf, parse_test_data[i].expected, ret);
79 }
80
81 ok(get_possible_cpus_array_len() > 0, "get_possible_cpus_array_len (%d > 0)", get_possible_cpus_array_len());
82
83 return exit_status();
84 }
This page took 0.03026 seconds and 4 git commands to generate.