Commit | Line | Data |
---|---|---|
fb0f6ca9 | 1 | #!/bin/bash |
89a8858d MJ |
2 | |
3 | # SPDX-FileCopyrightText: 2023 EfficiOS, Inc | |
4 | # | |
fb0f6ca9 MJ |
5 | # SPDX-License-Identifier: LGPL-2.1-only |
6 | ||
7 | if [ "x${UST_TESTS_SRCDIR:-}" != "x" ]; then | |
8 | UTILSSH="$UST_TESTS_SRCDIR/utils/utils.sh" | |
9 | else | |
10 | UTILSSH="$(dirname "$0")/../../utils/utils.sh" | |
11 | fi | |
12 | ||
13 | # shellcheck source=../../utils/utils.sh | |
14 | source "$UTILSSH" | |
15 | ||
16 | # shellcheck source=../../utils/tap.sh | |
17 | source "$UST_TESTS_SRCDIR/utils/tap.sh" | |
18 | ||
19 | CURDIR="${UST_TESTS_BUILDDIR}/unit/libcommon" | |
20 | ||
21 | STD_OUTPUT="/dev/null" | |
22 | STD_ERROR="/dev/null" | |
23 | ||
24 | NUM_TESTS=13 | |
25 | ||
26 | TESTDIR=$(mktemp -d) | |
27 | ||
28 | populate_testdir() { | |
29 | local cpus=("$@") | |
30 | ||
31 | mkdir "$TESTDIR" | |
32 | ||
33 | for i in "${cpus[@]}"; do | |
34 | mkdir "$TESTDIR/$i" | |
35 | done | |
36 | } | |
37 | ||
38 | test_get_max_cpuid_from_sysfs() { | |
39 | local num_cpus=$1 | |
40 | shift | |
41 | local current_cpus=("$@") | |
42 | local result | |
43 | ||
44 | populate_testdir "${current_cpus[@]}" >"$STD_OUTPUT" 2>"$STD_ERROR" | |
45 | result=$("${CURDIR}/get_max_cpuid_from_sysfs" "$TESTDIR") | |
46 | is "$result" "$num_cpus" "get_max_cpuid_from_sysfs - cpu set: '${current_cpus[*]}', expected: '$num_cpus', result: '$result'" | |
47 | rm -rf "$TESTDIR" | |
48 | } | |
49 | ||
50 | plan_tests $NUM_TESTS | |
51 | ||
52 | diag "get_max_cpuid_from_sysfs" | |
53 | ||
54 | test_data=(0 "cpu0") | |
55 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
56 | ||
57 | test_data=(1 "cpu0" "cpu1") | |
58 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
59 | ||
60 | test_data=(1 "cpu1" "cpu0") | |
61 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
62 | ||
63 | test_data=(3 "cpu3") | |
64 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
65 | ||
66 | test_data=(99 "cpu99") | |
67 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
68 | ||
69 | test_data=(3 "cpu0" "cpu3") | |
70 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
71 | ||
72 | test_data=(3 "cpufreq" "cpuidle" "cpu0" "cpu1" "cpu2" "cpu3") | |
73 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
74 | ||
75 | test_data=(0 "cpu" "cpu0") | |
76 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
77 | ||
78 | test_data=(5 "cpu" "cpu5") | |
79 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
80 | ||
81 | ||
82 | test_data=(-1 "toto") | |
83 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
84 | ||
85 | test_data=(-1 "cpu") | |
86 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
87 | ||
88 | test_data=(-1 "cpua" "cpud") | |
89 | test_get_max_cpuid_from_sysfs "${test_data[@]}" | |
90 | ||
91 | test_data=(-1 "cpufreq" "cpuidle") | |
92 | test_get_max_cpuid_from_sysfs "${test_data[@]}" |