misc: move exit status into trap handler
[xfstests-dev.git] / tests / generic / 247
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2010 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 247
6 #
7 # Test for race between direct I/O and mmap
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 7 15
17
18 _cleanup()
19 {
20     cd /
21     rm -f $tmp.* $testfile
22     wait
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # real QA test starts here
30
31 # Modify as appropriate.
32 _supported_fs generic
33 _require_test
34
35 # this test leaves a 512MB file around if we abort the test during the run via a
36 # reboot or kernel panic. Hence just name the file $seq so that we can always
37 # clean up on the next run and not leave large stale files around on the testdir
38 # that can lead to ENOSPC issues over time.
39 testfile=$TEST_DIR/$seq
40 rm -f $testfile
41
42 loops=500
43 iosize=1048576
44
45 # Initialise file
46 dd if=/dev/zero of=$testfile bs=$iosize count=$loops &> /dev/null
47 [ $? -ne 0 ] && exit
48 sync
49         
50 # Direct I/O overwriter
51 dd if=/dev/zero of=$testfile oflag=direct bs=$iosize count=$loops conv=notrunc &> /dev/null &
52 [ $? -ne 0 ] && exit
53
54 # Mmap writer
55 start=`expr $loops - 1`
56 for i in `seq $start -1 0`
57 do
58         offset=`expr $i \* $iosize`
59         $XFS_IO_PROG -f -c "mmap -w $offset $iosize" -c "mwrite $offset $iosize" $testfile
60         [ $? -ne 0 ] && exit
61 done
62
63 wait
64
65 echo "Silence is golden."
66
67 # unmount and check dmesg, filtering out expected warnings about mixed
68 # mmap/dio
69 _test_unmount
70 _check_dmesg _filter_aiodio_dmesg
71
72 status=$?
73 exit