1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0+ or MIT
3
4NR_CPUS=`grep '^processor' /proc/cpuinfo | wc -l`
5
6EXTRA_ARGS=${@}
7
8OLDIFS="$IFS"
9IFS=$'\n'
10TEST_LIST=(
11	"-T s"
12	"-T l"
13	"-T b"
14	"-T b -M"
15	"-T m"
16	"-T m -M"
17	"-T i"
18)
19
20TEST_NAME=(
21	"spinlock"
22	"list"
23	"buffer"
24	"buffer with barrier"
25	"memcpy"
26	"memcpy with barrier"
27	"increment"
28)
29IFS="$OLDIFS"
30
31REPS=1000
32SLOW_REPS=100
33NR_THREADS=$((6*${NR_CPUS}))
34
35function do_tests()
36{
37	local i=0
38	while [ "$i" -lt "${#TEST_LIST[@]}" ]; do
39		echo "Running test ${TEST_NAME[$i]}"
40		./param_test ${TEST_LIST[$i]} -r ${REPS} -t ${NR_THREADS} ${@} ${EXTRA_ARGS} || exit 1
41		echo "Running compare-twice test ${TEST_NAME[$i]}"
42		./param_test_compare_twice ${TEST_LIST[$i]} -r ${REPS} -t ${NR_THREADS} ${@} ${EXTRA_ARGS} || exit 1
43		let "i++"
44	done
45}
46
47echo "Default parameters"
48do_tests
49
50echo "Loop injection: 10000 loops"
51
52OLDIFS="$IFS"
53IFS=$'\n'
54INJECT_LIST=(
55	"1"
56	"2"
57	"3"
58	"4"
59	"5"
60	"6"
61	"7"
62	"8"
63	"9"
64)
65IFS="$OLDIFS"
66
67NR_LOOPS=10000
68
69i=0
70while [ "$i" -lt "${#INJECT_LIST[@]}" ]; do
71	echo "Injecting at <${INJECT_LIST[$i]}>"
72	do_tests -${INJECT_LIST[i]} ${NR_LOOPS}
73	let "i++"
74done
75NR_LOOPS=
76
77function inject_blocking()
78{
79	OLDIFS="$IFS"
80	IFS=$'\n'
81	INJECT_LIST=(
82		"7"
83		"8"
84		"9"
85	)
86	IFS="$OLDIFS"
87
88	NR_LOOPS=-1
89
90	i=0
91	while [ "$i" -lt "${#INJECT_LIST[@]}" ]; do
92		echo "Injecting at <${INJECT_LIST[$i]}>"
93		do_tests -${INJECT_LIST[i]} -1 ${@}
94		let "i++"
95	done
96	NR_LOOPS=
97}
98
99echo "Yield injection (25%)"
100inject_blocking -m 4 -y
101
102echo "Yield injection (50%)"
103inject_blocking -m 2 -y
104
105echo "Yield injection (100%)"
106inject_blocking -m 1 -y
107
108echo "Kill injection (25%)"
109inject_blocking -m 4 -k
110
111echo "Kill injection (50%)"
112inject_blocking -m 2 -k
113
114echo "Kill injection (100%)"
115inject_blocking -m 1 -k
116
117echo "Sleep injection (1ms, 25%)"
118inject_blocking -m 4 -s 1
119
120echo "Sleep injection (1ms, 50%)"
121inject_blocking -m 2 -s 1
122
123echo "Sleep injection (1ms, 100%)"
124inject_blocking -m 1 -s 1
125