summaryrefslogtreecommitdiff
path: root/tests/ubi-tests/stress-test.sh
blob: 4e63dbe645711417d8ce47da9c92ccbf6d531651 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/sh -euf

srcdir="$(readlink -ev -- ${0%/*})"
PATH="$srcdir:$srcdir/../..:$PATH"

fatal()
{
	echo "Error: $1" 1>&2
	exit 1
}

usage()
{
	cat 1>&2 <<EOF
Stress-test an UBI device. This test is basically built on top of
'runtests.sh' and runs it several times for different configurations.

The nandsim and mtdram drivers have to be compiled as kernel modules.

Usage:
  ${0##*/} run
EOF
}

cleanup_handler()
{
	local ret="$1"
	rmmod ubi >/dev/null 2>&1 ||:
	rmmod nandsim >/dev/null 2>&1 ||:
	rmmod mtdram >/dev/null 2>&1  ||:

	# Below is magic to exit with correct exit code
	if [ "$ret" != "0" ]; then
		trap false EXIT
	else
		trap true EXIT
	fi
}
trap 'cleanup_handler $?' EXIT
trap 'cleanup_handler 1' HUP PIPE INT QUIT TERM

# Find MTD device number by pattern in /proc/mtd
# Usage: find_mtd_device <pattern>
find_mtd_device()
{
	printf "%s" "$(grep "$1" /proc/mtd | sed -e "s/^mtd\([0-9]\+\):.*$/\1/")"
}

# Just print parameters of the 'run_test' funcion in a user-friendly form.
print_params()
{
	local module="$1";    shift
	local size="$1";      shift
	local peb_size="$1";  shift
	local page_size="$1"; shift
	local vid_offs="$1";  shift
	local fastmap="$1";   shift
	local fm_str

	if [ "$fastmap" = "0" ]; then
		fm_str="disabled"
	else
		fm_str="enabled"
	fi

	printf "%s" "$module: ${size}MiB, PEB size ${peb_size}KiB, "
	if [ "$module" = "nandsim" ]; then
		printf "%s" "page size ${page_size}KiB, VID offset $vid_offs, "
	fi
	printf "%s\n" "fastmap $fm_str" 
}

print_separator()
{
	echo "======================================================================"
}

# Run a test on nandsim or mtdram with certain geometry.
# Usage: run_test <nandsim|mtdram> <flash size> <PEB size> \
#                 <Page size> <VID hdr offs> <enable fastmap>
#
# 1. Simulator type (nandsim or mtdram)
# 2. Flash size is specified in MiB 
# 3. PEB size is specified in KiB
# 4. Page size is specified in bytes (mtdram ingores this)
# 5. VID header offset (mtdram ingores this)
# 6. Whether fast-map should be enabled (pass 0 or 1)
run_test()
{
	local module="$1";
	local size="$2";
	local peb_size="$3";
	local page_size="$4";
	local vid_offs="$5"
	local fastmap="$6";  
	local fm_supported fm_str fm_param mtdnum

	print_separator

	# Check if fastmap is supported by UBI
	if modinfo ubi | grep -q fm_auto; then
		fm_supported="yes"
	else
		fm_supported="no"
	fi

	if [ "$fastmap" = "0" ]; then
		fm_str="disabled"
		fm_param=
	elif [ "$fm_supported" = "yes" ]; then
		fm_str="enabled"
		fm_param="fm_auto"
	else
		echo "Fastmap is not supported, skip"
		return 0
	fi

	if [ "$module" = "nandsim" ]; then
		print_params "$@"

		load_nandsim.sh "$size" "$peb_size" "$page_size" ||
			echo "Cannot load nandsim, test skipped"

		mtdnum="$(find_mtd_device "$nandsim_patt")"
	else
		fatal "$module is not supported"
	fi

	modprobe ubi mtd="$mtdnum,$vid_offs" $fm_param
	runtests.sh /dev/ubi0 ||:

	sudo rmmod ubi
	sudo rmmod "$module"
}

if [ "$#" -lt 1 ] || [ "$1" != "run" ]; then
	usage
	exit 1
fi

# Make sure neither mtdram nor nandsim are used
nandsim_patt="NAND simulator"
mtdram_patt="mtdram test device"
! grep -q "$nandsim_patt" /proc/mtd ||
	fatal "the nandsim driver is already used"
! grep -q "$mtdram_patt" /proc/mtd ||
	fatal "the mtdram driver is already used"

rmmod ubi >/dev/null 2>&1 ||:

for fm in 1 0; do
	for vid_factor in 1 0; do
		print_separator
		print_separator
		print_separator

		pg_size="512"
		vid_offs="$(($pg_size * $vid_factor))"

		run_test "nandsim" "16"  "16" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "32"  "16" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "64"  "16" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "128" "16" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "256" "16" "$pg_size" "$vid_offs" "$fm"

		pg_size="2048"
		vid_offs="$(($pg_size * $vid_factor))"

		run_test "nandsim" "64"   "64" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "128"  "64" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "256"  "64" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "512"  "64" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "1024" "64" "$pg_size" "$vid_offs" "$fm"

		run_test "nandsim" "64"   "128" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "128"  "128" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "256"  "128" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "512"  "128" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "1024" "128" "$pg_size" "$vid_offs" "$fm"

		run_test "nandsim" "64"   "256" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "128"  "256" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "256"  "256" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "512"  "256" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "1024" "256" "$pg_size" "$vid_offs" "$fm"

		run_test "nandsim" "64"   "512" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "128"  "512" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "256"  "512" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "512"  "512" "$pg_size" "$vid_offs" "$fm"
		run_test "nandsim" "1024" "512" "$pg_size" "$vid_offs" "$fm"
	done
done