tests: use SPDX identifiers
[urcu.git] / tests / unit / test_get_max_cpuid_from_sysfs
CommitLineData
da56d5ca 1#!/usr/bin/env bash
ce29b371
MJ
2
3# SPDX-FileCopyrightText: 2023 EfficiOS Inc.
4#
4de89c11
MJ
5# SPDX-License-Identifier: GPL-2.0-or-later
6
7if [ "x${URCU_TESTS_SRCDIR:-}" != "x" ]; then
8 UTILSSH="$URCU_TESTS_SRCDIR/utils/utils.sh"
9else
10 UTILSSH="$(dirname "$0")/../utils/utils.sh"
11fi
12
13# shellcheck source=../utils/utils.sh
14source "$UTILSSH"
15
16# shellcheck source=../../utils/tap.sh
17source "$URCU_TESTS_SRCDIR/utils/tap.sh"
18
19CURDIR="${URCU_TESTS_BUILDDIR}/unit"
20
21STD_OUTPUT="/dev/null"
22STD_ERROR="/dev/null"
23
24NUM_TESTS=13
25
26TESTDIR=$(mktemp -d)
27
28populate_testdir() {
29 local cpus=("$@")
30
31 mkdir "$TESTDIR"
32
33 for i in "${cpus[@]}"; do
34 mkdir "$TESTDIR/$i"
35 done
36}
37
38test_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
da44a943
MJ
50if [ "$URCU_TESTS_OS_TYPE" == "linux" ]; then
51 plan_tests $NUM_TESTS
4de89c11 52
da44a943 53 diag "get_max_cpuid_from_sysfs"
4de89c11 54
da44a943
MJ
55 test_data=(0 "cpu0")
56 test_get_max_cpuid_from_sysfs "${test_data[@]}"
4de89c11 57
da44a943
MJ
58 test_data=(1 "cpu0" "cpu1")
59 test_get_max_cpuid_from_sysfs "${test_data[@]}"
4de89c11 60
da44a943
MJ
61 test_data=(1 "cpu1" "cpu0")
62 test_get_max_cpuid_from_sysfs "${test_data[@]}"
4de89c11 63
da44a943
MJ
64 test_data=(3 "cpu3")
65 test_get_max_cpuid_from_sysfs "${test_data[@]}"
4de89c11 66
da44a943
MJ
67 test_data=(99 "cpu99")
68 test_get_max_cpuid_from_sysfs "${test_data[@]}"
4de89c11 69
da44a943
MJ
70 test_data=(3 "cpu0" "cpu3")
71 test_get_max_cpuid_from_sysfs "${test_data[@]}"
4de89c11 72
da44a943
MJ
73 test_data=(3 "cpufreq" "cpuidle" "cpu0" "cpu1" "cpu2" "cpu3")
74 test_get_max_cpuid_from_sysfs "${test_data[@]}"
4de89c11 75
da44a943
MJ
76 test_data=(0 "cpu" "cpu0")
77 test_get_max_cpuid_from_sysfs "${test_data[@]}"
4de89c11 78
da44a943
MJ
79 test_data=(5 "cpu" "cpu5")
80 test_get_max_cpuid_from_sysfs "${test_data[@]}"
4de89c11
MJ
81
82
da44a943
MJ
83 test_data=(-1 "toto")
84 test_get_max_cpuid_from_sysfs "${test_data[@]}"
4de89c11 85
da44a943
MJ
86 test_data=(-1 "cpu")
87 test_get_max_cpuid_from_sysfs "${test_data[@]}"
4de89c11 88
da44a943
MJ
89 test_data=(-1 "cpua" "cpud")
90 test_get_max_cpuid_from_sysfs "${test_data[@]}"
4de89c11 91
da44a943
MJ
92 test_data=(-1 "cpufreq" "cpuidle")
93 test_get_max_cpuid_from_sysfs "${test_data[@]}"
94else
95 plan_skip_all "Linux specific tests."
96fi
This page took 0.026943 seconds and 4 git commands to generate.