Add unit tests for possible_cpus_array_len
[urcu.git] / tests / unit / test_get_max_cpuid_from_sysfs
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() {
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
47plan_tests $NUM_TESTS
48
49diag "get_max_cpuid_from_sysfs"
50
51test_data=(0 "cpu0")
52test_get_max_cpuid_from_sysfs "${test_data[@]}"
53
54test_data=(1 "cpu0" "cpu1")
55test_get_max_cpuid_from_sysfs "${test_data[@]}"
56
57test_data=(1 "cpu1" "cpu0")
58test_get_max_cpuid_from_sysfs "${test_data[@]}"
59
60test_data=(3 "cpu3")
61test_get_max_cpuid_from_sysfs "${test_data[@]}"
62
63test_data=(99 "cpu99")
64test_get_max_cpuid_from_sysfs "${test_data[@]}"
65
66test_data=(3 "cpu0" "cpu3")
67test_get_max_cpuid_from_sysfs "${test_data[@]}"
68
69test_data=(3 "cpufreq" "cpuidle" "cpu0" "cpu1" "cpu2" "cpu3")
70test_get_max_cpuid_from_sysfs "${test_data[@]}"
71
72test_data=(0 "cpu" "cpu0")
73test_get_max_cpuid_from_sysfs "${test_data[@]}"
74
75test_data=(5 "cpu" "cpu5")
76test_get_max_cpuid_from_sysfs "${test_data[@]}"
77
78
79test_data=(-1 "toto")
80test_get_max_cpuid_from_sysfs "${test_data[@]}"
81
82test_data=(-1 "cpu")
83test_get_max_cpuid_from_sysfs "${test_data[@]}"
84
85test_data=(-1 "cpua" "cpud")
86test_get_max_cpuid_from_sysfs "${test_data[@]}"
87
88test_data=(-1 "cpufreq" "cpuidle")
89test_get_max_cpuid_from_sysfs "${test_data[@]}"
This page took 0.02518 seconds and 4 git commands to generate.