summaryrefslogtreecommitdiff
path: root/tests/generic/579
blob: 2667585ca97df3fe4b37d4ce41d9808051f4a216 (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright 2019 Google LLC
#
# FS QA Test generic/579
#
# Stress test for fs-verity.  This tests enabling fs-verity on multiple files
# concurrently with concurrent readers on those files (with reads occurring
# before, during, and after the fs-verity enablement), while fsstress is also
# running on the same filesystem.
#
. ./common/preamble
_begin_fstest auto stress verity

# Override the default cleanup function.
_cleanup()
{
	# Stop all subprocesses.
	$KILLALL_PROG -q $FSSTRESS_PROG
	touch $tmp.done
	wait

	_restore_fsverity_signatures
	rm -f $tmp.*
}

# Import common functions.
. ./common/filter
. ./common/verity

# real QA test starts here
_supported_fs generic
_require_scratch_verity
_require_command "$KILLALL_PROG" killall
_disable_fsverity_signatures

_scratch_mkfs_verity &>> $seqres.full
_scratch_mount

fsv_file_size=10000000
nproc_enabler=$((4 * LOAD_FACTOR))
nproc_reader=$((6 * LOAD_FACTOR))
nproc_stress=$((3 * LOAD_FACTOR))
runtime=$((20 * TIME_FACTOR))

# Create the test files and start the fs-verity enabler processes.
for ((proc = 0; proc < nproc_enabler; proc++)); do
	orig_file=$SCRATCH_MNT/orig$proc
	fsv_file=$SCRATCH_MNT/fsv$proc
	head -c $fsv_file_size /dev/urandom > $orig_file
	(
		while [ ! -e $tmp.done ]; do
			rm -f $fsv_file
			cp $orig_file $fsv_file
			_fsv_enable $fsv_file
			# Give the readers some time to read from the file.
			sleep 0.$((RANDOM % 100))
		done
	) &
done

# Start the reader processes.
for ((proc = 0; proc < nproc_reader; proc++)); do
	(
		while [ ! -e $tmp.done ]; do
			# Choose a random file for each iteration, so that
			# sometimes multiple processes read from the same file.
			i=$((RANDOM % nproc_enabler))
			orig_file=$SCRATCH_MNT/orig$i
			fsv_file=$SCRATCH_MNT/fsv$i

			# After the copy from $orig_file to $fsv_file has
			# completed, the contents of these two files should
			# match, regardless of whether verity has been enabled
			# or not yet (or is currently being enabled).
			cmp $orig_file $fsv_file |& _filter_scratch | \
				grep -v "SCRATCH_MNT/fsv$i: No such file or directory" | \
				grep -v "EOF on SCRATCH_MNT/fsv$i"

			_fsv_measure $fsv_file 2>&1 >/dev/null | \
				grep -v "No such file or directory" | \
				grep -v "No data available"
		done
	) &
done

# Start a process that occasionally runs 'sync && drop_caches'.  This makes more
# reads go through fs-verity for real, rather than just returning pagecache.
(
	while [ ! -e $tmp.done ]; do
		sleep 2.$((RANDOM % 100))
		sync && echo 3 > /proc/sys/vm/drop_caches
	done
) &

# Start the fsstress processes.
$FSSTRESS_PROG $FSSTRESS_AVOID -p $nproc_stress -l 0 -d $SCRATCH_MNT/stressdir \
	>> $seqres.full 2>&1 &

# Run for a while.
sleep $runtime

echo "Silence is golden"

# success, all done
status=0
exit