misc: move exit status into trap handler
[xfstests-dev.git] / tests / xfs / 157
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 157
6 #
7 # Functional testing for xfs_admin to ensure that it parses arguments correctly
8 # with regards to data devices that are files, external logs, and realtime
9 # devices.
10 #
11 # Because this test synthesizes log and rt devices (by modifying the test run
12 # configuration), it does /not/ require the ability to mount the scratch
13 # filesystem.  This increases test coverage while isolating the weird bits to a
14 # single test.
15 #
16 # This is partially a regression test for "xfs_admin: pick up log arguments
17 # correctly", insofar as the issue fixed by that patch was discovered with an
18 # earlier revision of this test.
19
20 seq=`basename $0`
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
23
24 here=`pwd`
25 tmp=/tmp/$$
26 status=1    # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
28
29 _cleanup()
30 {
31         cd /
32         rm -f $tmp.* $fake_logfile $fake_rtfile $fake_datafile
33 }
34
35 # get standard environment, filters and checks
36 . ./common/rc
37 . ./common/filter
38
39 # real QA test starts here
40 _supported_fs xfs
41 _require_test
42 _require_scratch_nocheck
43 _require_command "$XFS_ADMIN_PROG" "xfs_admin"
44
45 rm -f $seqres.full
46
47 # Create some fake sparse files for testing external devices and whatnot
48 fake_datafile=$TEST_DIR/$seq.scratch.data
49 rm -f $fake_datafile
50 truncate -s 500m $fake_datafile
51
52 fake_logfile=$TEST_DIR/$seq.scratch.log
53 rm -f $fake_logfile
54 truncate -s 500m $fake_logfile
55
56 fake_rtfile=$TEST_DIR/$seq.scratch.rt
57 rm -f $fake_rtfile
58 truncate -s 500m $fake_rtfile
59
60 # Save the original variables
61 orig_ddev=$SCRATCH_DEV
62 orig_external=$USE_EXTERNAL
63 orig_logdev=$SCRATCH_LOGDEV
64 orig_rtdev=$SCRATCH_RTDEV
65
66 scenario() {
67         echo "$@" | tee -a $seqres.full
68
69         SCRATCH_DEV=$orig_ddev
70         USE_EXTERNAL=$orig_external
71         SCRATCH_LOGDEV=$orig_logdev
72         SCRATCH_RTDEV=$orig_rtdev
73 }
74
75 check_label() {
76         _scratch_mkfs -L oldlabel >> $seqres.full
77         _scratch_xfs_db -c label
78         _scratch_xfs_admin -L newlabel "$@" >> $seqres.full
79         _scratch_xfs_db -c label
80         _scratch_xfs_repair -n &>> $seqres.full || echo "Check failed?"
81 }
82
83 scenario "S1: Check that label setting with file image"
84 SCRATCH_DEV=$fake_datafile
85 check_label -f
86
87 scenario "S2: Check that setting with logdev works"
88 USE_EXTERNAL=yes
89 SCRATCH_LOGDEV=$fake_logfile
90 check_label
91
92 scenario "S3: Check that setting with rtdev works"
93 USE_EXTERNAL=yes
94 SCRATCH_RTDEV=$fake_rtfile
95 check_label
96
97 scenario "S4: Check that setting with rtdev + logdev works"
98 USE_EXTERNAL=yes
99 SCRATCH_LOGDEV=$fake_logfile
100 SCRATCH_RTDEV=$fake_rtfile
101 check_label
102
103 scenario "S5: Check that setting with nortdev + nologdev works"
104 USE_EXTERNAL=
105 SCRATCH_LOGDEV=
106 SCRATCH_RTDEV=
107 check_label
108
109 scenario "S6: Check that setting with bdev incorrectly flagged as file works"
110 check_label -f
111
112 # success, all done
113 status=0
114 exit