Add unit tests for num possible cpus
[lttng-ust.git] / tests / unit / libcommon / test_smp.c
CommitLineData
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
18struct parse_test_data {
19 const char *buf;
20 int expected;
21};
22
23static struct parse_test_data parse_test_data[] = {
24 { "", 0 },
25 { "abc", 0 },
26 { ",,,", 0 },
27 { "--", 0 },
28 { ",", 0 },
29 { "-", 0 },
30 { "2147483647", 0 },
31 { "18446744073709551615", 0 },
32 { "0-2147483647", 0 },
33 { "0-18446744073709551615", 0 },
34 { "0", 1 },
35 { "1", 2 },
36 { "0-1", 2 },
37 { "1-3", 4 },
38 { "0,2", 3 },
39 { "1,2", 3 },
40 { "0,4-6,127", 128 },
41 { "0-4095", 4096 },
42
43 { "\n", 0 },
44 { "abc\n", 0 },
45 { ",,,\n", 0 },
46 { "--\n", 0 },
47 { ",\n", 0 },
48 { "-\n", 0 },
49 { "2147483647\n", 0 },
50 { "18446744073709551615\n", 0 },
51 { "0-2147483647\n", 0 },
52 { "0-18446744073709551615\n", 0 },
53 { "0\n", 1 },
54 { "1\n", 2 },
55 { "0-1\n", 2 },
56 { "1-3\n", 4 },
57 { "0,2\n", 3 },
58 { "1,2\n", 3 },
59 { "0,4-6,127\n", 128 },
60 { "0-4095\n", 4096 },
61};
62
63static int parse_test_data_len = sizeof(parse_test_data) / sizeof(parse_test_data[0]);
64
65int 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_num_possible_cpus_from_mask(parse_test_data[i].buf,
75 strlen(parse_test_data[i].buf));
76 ok(ret == parse_test_data[i].expected,
77 "get_num_possible_cpus_from_mask '%s', expected: '%d', result: '%d'",
78 parse_test_data[i].buf, parse_test_data[i].expected, ret);
79 }
80
81 ok(num_possible_cpus() > 0, "num_possible_cpus (%d > 0)", num_possible_cpus());
82
83 return exit_status();
84}
This page took 0.030264 seconds and 5 git commands to generate.