~lttng/lttng-ust/lttng-ust

« back to all changes in this revision

Viewing changes to tests/unit/libcommon/test_get_cpu_mask_from_sysfs

  • Committer: Mathieu Desnoyers
  • Author(s): Michael Jeanson
  • Date: 2022-07-29 14:33:10 UTC
  • Revision ID: git-v1:fb0f6ca9385e1813311cfd917c130b40bec04970
Add more unit tests for possible_cpus_array_len

Change-Id: If0b7fb9183936f00ac90349fb32f1db57f124602
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
# SPDX-License-Identifier: LGPL-2.1-only
 
3
 
 
4
if [ "x${UST_TESTS_SRCDIR:-}" != "x" ]; then
 
5
        UTILSSH="$UST_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 "$UST_TESTS_SRCDIR/utils/tap.sh"
 
15
 
 
16
CURDIR="${UST_TESTS_BUILDDIR}/unit/libcommon"
 
17
 
 
18
NUM_TESTS=8
 
19
 
 
20
TESTFILE=$(mktemp)
 
21
 
 
22
populate_testfile() {
 
23
        local cpumask="$1"
 
24
 
 
25
        # shellcheck disable=SC2059
 
26
        printf "$cpumask" > "$TESTFILE"
 
27
}
 
28
 
 
29
test_test_get_cpu_mask_from_sysfs() {
 
30
        local cpumask="$1"
 
31
        local result
 
32
 
 
33
        # Without '\n'
 
34
        populate_testfile "$cpumask"
 
35
        result=$("${CURDIR}/get_cpu_mask_from_sysfs" "$TESTFILE")
 
36
        test "$cpumask" == "$result"
 
37
        ok $? "test_get_cpu_mask_from_sysfs - without '\n' expected: '$cpumask', result: '$result'"
 
38
 
 
39
        # With '\n'
 
40
        populate_testfile "$cpumask\n"
 
41
        result=$("${CURDIR}/get_cpu_mask_from_sysfs" "$TESTFILE")
 
42
        test "$cpumask" == "$result"
 
43
        ok $? "test_get_cpu_mask_from_sysfs - with '\n' expected: '$cpumask', result: '$result'"
 
44
}
 
45
 
 
46
plan_tests $NUM_TESTS
 
47
 
 
48
test_test_get_cpu_mask_from_sysfs ""
 
49
test_test_get_cpu_mask_from_sysfs "0"
 
50
test_test_get_cpu_mask_from_sysfs "0-3"
 
51
test_test_get_cpu_mask_from_sysfs "0,3-7,9"