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