fix: ifdef linux specific cpu count compat
[userspace-rcu.git] / tests / unit / test_get_max_cpuid_from_sysfs_cxx
CommitLineData
4de89c11
MJ
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0-or-later
3
4if [ "x${URCU_TESTS_SRCDIR:-}" != "x" ]; then
5 UTILSSH="$URCU_TESTS_SRCDIR/utils/utils.sh"
6else
7 UTILSSH="$(dirname "$0")/../utils/utils.sh"
8fi
9
10# shellcheck source=../utils/utils.sh
11source "$UTILSSH"
12
13# shellcheck source=../../utils/tap.sh
14source "$URCU_TESTS_SRCDIR/utils/tap.sh"
15
16CURDIR="${URCU_TESTS_BUILDDIR}/unit"
17
18STD_OUTPUT="/dev/null"
19STD_ERROR="/dev/null"
20
21NUM_TESTS=13
22
23TESTDIR=$(mktemp -d)
24
25populate_testdir() {
26 local cpus=("$@")
27
28 mkdir "$TESTDIR"
29
30 for i in "${cpus[@]}"; do
31 mkdir "$TESTDIR/$i"
32 done
33}
34
35test_get_max_cpuid_from_sysfs_cxx() {
36 local num_cpus=$1
37 shift
38 local current_cpus=("$@")
39 local result
40
41 populate_testdir "${current_cpus[@]}" >"$STD_OUTPUT" 2>"$STD_ERROR"
42 result=$("${CURDIR}/get_max_cpuid_from_sysfs_cxx" "$TESTDIR")
43 is "$result" "$num_cpus" "get_max_cpuid_from_sysfs_cxx - cpu set: '${current_cpus[*]}', expected: '$num_cpus', result: '$result'"
44 rm -rf "$TESTDIR"
45}
46
da44a943
MJ
47if [ "$URCU_TESTS_OS_TYPE" == "linux" ]; then
48 plan_tests $NUM_TESTS
4de89c11 49
da44a943 50 diag "get_max_cpuid_from_sysfs_cxx"
4de89c11 51
da44a943
MJ
52 test_data=(0 "cpu0")
53 test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
4de89c11 54
da44a943
MJ
55 test_data=(1 "cpu0" "cpu1")
56 test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
4de89c11 57
da44a943
MJ
58 test_data=(1 "cpu1" "cpu0")
59 test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
4de89c11 60
da44a943
MJ
61 test_data=(3 "cpu3")
62 test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
4de89c11 63
da44a943
MJ
64 test_data=(99 "cpu99")
65 test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
4de89c11 66
da44a943
MJ
67 test_data=(3 "cpu0" "cpu3")
68 test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
4de89c11 69
da44a943
MJ
70 test_data=(3 "cpufreq" "cpuidle" "cpu0" "cpu1" "cpu2" "cpu3")
71 test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
4de89c11 72
da44a943
MJ
73 test_data=(0 "cpu" "cpu0")
74 test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
4de89c11 75
da44a943
MJ
76 test_data=(5 "cpu" "cpu5")
77 test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
4de89c11
MJ
78
79
da44a943
MJ
80 test_data=(-1 "toto")
81 test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
4de89c11 82
da44a943
MJ
83 test_data=(-1 "cpu")
84 test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
4de89c11 85
da44a943
MJ
86 test_data=(-1 "cpua" "cpud")
87 test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
4de89c11 88
da44a943
MJ
89 test_data=(-1 "cpufreq" "cpuidle")
90 test_get_max_cpuid_from_sysfs_cxx "${test_data[@]}"
91else
92 plan_skip_all "Linux specific tests."
93fi
This page took 0.02636 seconds and 4 git commands to generate.