2 # SPDX-License-Identifier: GPL-2.0
7 # This is a test script for the kernel test driver to test the
8 # correctness and performance of page_frag's implementation.
9 # Therefore it is just a kernel module loader. You can specify
10 # and pass different parameters in order to:
11 # a) analyse performance of page fragment allocations;
12 # b) stressing and stability check of page_frag subsystem.
14 DRIVER="./page_frag/page_frag_test.ko"
15 CPU_LIST=$(grep -m 2 processor /proc/cpuinfo | cut -d ' ' -f 2)
16 TEST_CPU_0=$(echo $CPU_LIST | awk '{print $1}')
18 if [ $(echo $CPU_LIST | wc -w) -gt 1 ]; then
19 TEST_CPU_1=$(echo $CPU_LIST | awk '{print $2}')
22 TEST_CPU_1=$TEST_CPU_0
29 # Kselftest framework requirement - SKIP code is 4.
32 check_test_failed_prefix() {
33 if dmesg | grep -q 'page_frag_test failed:';then
34 echo "page_frag_test failed, please check dmesg"
40 # Static templates for testing of page_frag APIs.
41 # Also it is possible to pass any supported parameters manually.
43 SMOKE_PARAM="test_push_cpu=$TEST_CPU_0 test_pop_cpu=$TEST_CPU_1"
44 NONALIGNED_PARAM="$SMOKE_PARAM test_alloc_len=75 nr_test=$NR_TEST"
45 ALIGNED_PARAM="$NONALIGNED_PARAM test_align=1"
47 check_test_requirements()
50 if [ $uid -ne 0 ]; then
51 echo "$0: Must be run as root"
55 if ! which insmod > /dev/null 2>&1; then
56 echo "$0: You need insmod installed"
60 if [ ! -f $DRIVER ]; then
61 echo "$0: You need to compile page_frag_test module"
66 run_nonaligned_check()
68 echo "Run performance tests to evaluate how fast nonaligned alloc API is."
70 insmod $DRIVER $NONALIGNED_PARAM > /dev/null 2>&1
75 echo "Run performance tests to evaluate how fast aligned alloc API is."
77 insmod $DRIVER $ALIGNED_PARAM > /dev/null 2>&1
82 echo "Run smoke test."
84 insmod $DRIVER $SMOKE_PARAM > /dev/null 2>&1
89 echo -n "Usage: $0 [ aligned ] | [ nonaligned ] | | [ smoke ] | "
90 echo "manual parameters"
92 echo "Valid tests and parameters:"
98 echo "# Shows help message"
101 echo "# Smoke testing"
104 echo "# Performance testing for nonaligned alloc API"
107 echo "# Performance testing for aligned alloc API"
113 function validate_passed_args()
115 VALID_ARGS=`modinfo $DRIVER | awk '/parm:/ {print $2}' | sed 's/:.*//'`
118 # Something has been passed, check it.
120 for passed_arg in $@; do
121 key=${passed_arg//=*/}
124 for valid_arg in $VALID_ARGS; do
125 if [[ $key = $valid_arg ]]; then
131 if [[ $valid -ne 1 ]]; then
132 echo "Error: key is not correct: ${key}"
138 function run_manual_check()
141 # Validate passed parameters. If there is wrong one,
142 # the script exists and does not execute further.
144 validate_passed_args $@
146 echo "Run the test with following parameters: $@"
147 insmod $DRIVER $@ > /dev/null 2>&1
152 if [ $# -eq 0 ]; then
155 if [[ "$1" = "smoke" ]]; then
157 elif [[ "$1" = "nonaligned" ]]; then
159 elif [[ "$1" = "aligned" ]]; then
166 check_test_failed_prefix
169 echo "Check the kernel ring buffer to see the summary."
172 check_test_requirements