]> Git Repo - J-linux.git/blob - tools/testing/selftests/mm/test_page_frag.sh
Merge tag 'vfs-6.13-rc7.fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
[J-linux.git] / tools / testing / selftests / mm / test_page_frag.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 #
4 # Copyright (C) 2024 Yunsheng Lin <[email protected]>
5 # Copyright (C) 2018 Uladzislau Rezki (Sony) <[email protected]>
6 #
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.
13
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}')
17
18 if [ $(echo $CPU_LIST | wc -w) -gt 1 ]; then
19         TEST_CPU_1=$(echo $CPU_LIST | awk '{print $2}')
20         NR_TEST=100000000
21 else
22         TEST_CPU_1=$TEST_CPU_0
23         NR_TEST=1000000
24 fi
25
26 # 1 if fails
27 exitcode=1
28
29 # Kselftest framework requirement - SKIP code is 4.
30 ksft_skip=4
31
32 check_test_failed_prefix() {
33         if dmesg | grep -q 'page_frag_test failed:';then
34                 echo "page_frag_test failed, please check dmesg"
35                 exit $exitcode
36         fi
37 }
38
39 #
40 # Static templates for testing of page_frag APIs.
41 # Also it is possible to pass any supported parameters manually.
42 #
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"
46
47 check_test_requirements()
48 {
49         uid=$(id -u)
50         if [ $uid -ne 0 ]; then
51                 echo "$0: Must be run as root"
52                 exit $ksft_skip
53         fi
54
55         if ! which insmod > /dev/null 2>&1; then
56                 echo "$0: You need insmod installed"
57                 exit $ksft_skip
58         fi
59
60         if [ ! -f $DRIVER ]; then
61                 echo "$0: You need to compile page_frag_test module"
62                 exit $ksft_skip
63         fi
64 }
65
66 run_nonaligned_check()
67 {
68         echo "Run performance tests to evaluate how fast nonaligned alloc API is."
69
70         insmod $DRIVER $NONALIGNED_PARAM > /dev/null 2>&1
71 }
72
73 run_aligned_check()
74 {
75         echo "Run performance tests to evaluate how fast aligned alloc API is."
76
77         insmod $DRIVER $ALIGNED_PARAM > /dev/null 2>&1
78 }
79
80 run_smoke_check()
81 {
82         echo "Run smoke test."
83
84         insmod $DRIVER $SMOKE_PARAM > /dev/null 2>&1
85 }
86
87 usage()
88 {
89         echo -n "Usage: $0 [ aligned ] | [ nonaligned ] | | [ smoke ] | "
90         echo "manual parameters"
91         echo
92         echo "Valid tests and parameters:"
93         echo
94         modinfo $DRIVER
95         echo
96         echo "Example usage:"
97         echo
98         echo "# Shows help message"
99         echo "$0"
100         echo
101         echo "# Smoke testing"
102         echo "$0 smoke"
103         echo
104         echo "# Performance testing for nonaligned alloc API"
105         echo "$0 nonaligned"
106         echo
107         echo "# Performance testing for aligned alloc API"
108         echo "$0 aligned"
109         echo
110         exit 0
111 }
112
113 function validate_passed_args()
114 {
115         VALID_ARGS=`modinfo $DRIVER | awk '/parm:/ {print $2}' | sed 's/:.*//'`
116
117         #
118         # Something has been passed, check it.
119         #
120         for passed_arg in $@; do
121                 key=${passed_arg//=*/}
122                 valid=0
123
124                 for valid_arg in $VALID_ARGS; do
125                         if [[ $key = $valid_arg ]]; then
126                                 valid=1
127                                 break
128                         fi
129                 done
130
131                 if [[ $valid -ne 1 ]]; then
132                         echo "Error: key is not correct: ${key}"
133                         exit $exitcode
134                 fi
135         done
136 }
137
138 function run_manual_check()
139 {
140         #
141         # Validate passed parameters. If there is wrong one,
142         # the script exists and does not execute further.
143         #
144         validate_passed_args $@
145
146         echo "Run the test with following parameters: $@"
147         insmod $DRIVER $@ > /dev/null 2>&1
148 }
149
150 function run_test()
151 {
152         if [ $# -eq 0 ]; then
153                 usage
154         else
155                 if [[ "$1" = "smoke" ]]; then
156                         run_smoke_check
157                 elif [[ "$1" = "nonaligned" ]]; then
158                         run_nonaligned_check
159                 elif [[ "$1" = "aligned" ]]; then
160                         run_aligned_check
161                 else
162                         run_manual_check $@
163                 fi
164         fi
165
166         check_test_failed_prefix
167
168         echo "Done."
169         echo "Check the kernel ring buffer to see the summary."
170 }
171
172 check_test_requirements
173 run_test $@
174
175 exit 0
This page took 0.036187 seconds and 4 git commands to generate.