Commit | Line | Data |
---|---|---|
4de89c11 MJ |
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 | ||
da44a943 MJ |
47 | if [ "$URCU_TESTS_OS_TYPE" == "linux" ]; then |
48 | plan_tests $NUM_TESTS | |
4de89c11 | 49 | |
da44a943 | 50 | diag "get_max_cpuid_from_sysfs" |
4de89c11 | 51 | |
da44a943 MJ |
52 | test_data=(0 "cpu0") |
53 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
4de89c11 | 54 | |
da44a943 MJ |
55 | test_data=(1 "cpu0" "cpu1") |
56 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
4de89c11 | 57 | |
da44a943 MJ |
58 | test_data=(1 "cpu1" "cpu0") |
59 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
4de89c11 | 60 | |
da44a943 MJ |
61 | test_data=(3 "cpu3") |
62 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
4de89c11 | 63 | |
da44a943 MJ |
64 | test_data=(99 "cpu99") |
65 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
4de89c11 | 66 | |
da44a943 MJ |
67 | test_data=(3 "cpu0" "cpu3") |
68 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
4de89c11 | 69 | |
da44a943 MJ |
70 | test_data=(3 "cpufreq" "cpuidle" "cpu0" "cpu1" "cpu2" "cpu3") |
71 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
4de89c11 | 72 | |
da44a943 MJ |
73 | test_data=(0 "cpu" "cpu0") |
74 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
4de89c11 | 75 | |
da44a943 MJ |
76 | test_data=(5 "cpu" "cpu5") |
77 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
4de89c11 MJ |
78 | |
79 | ||
da44a943 MJ |
80 | test_data=(-1 "toto") |
81 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
4de89c11 | 82 | |
da44a943 MJ |
83 | test_data=(-1 "cpu") |
84 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
4de89c11 | 85 | |
da44a943 MJ |
86 | test_data=(-1 "cpua" "cpud") |
87 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
4de89c11 | 88 | |
da44a943 MJ |
89 | test_data=(-1 "cpufreq" "cpuidle") |
90 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
91 | else | |
92 | plan_skip_all "Linux specific tests." | |
93 | fi |