fstests: move test group info to test files
[xfstests-dev.git] / tests / xfs / 506
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (c) 2019, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 506
6 #
7 # Basic tests of the xfs_spaceman health command.
8
9 . ./common/preamble
10 _begin_fstest auto quick health
11
12 # Import common functions.
13 . ./common/fuzzy
14 . ./common/filter
15
16 # real QA test starts here
17 _supported_fs xfs
18 _require_scratch_nocheck
19 _require_scrub
20 _require_xfs_spaceman_command "health"
21
22 _scratch_mkfs > $seqres.full 2>&1
23 _scratch_mount
24 _scratch_cycle_mount    # make sure we haven't run quotacheck on this mount
25
26 # Haven't checked anything, it should tell us to run scrub
27 $XFS_SPACEMAN_PROG -c "health" $SCRATCH_MNT
28
29 # Run scrub to collect health info.
30 _scratch_scrub -n >> $seqres.full
31
32 query() {
33         $XFS_SPACEMAN_PROG -c "$@" $SCRATCH_MNT | tee -a $seqres.full
34 }
35
36 query_health() {
37         query "$@" | grep -q ": ok$"
38 }
39
40 query_sick() {
41         query "$@" | grep -q ": unhealthy$"
42 }
43
44 # Let's see if we get at least one healthy rating for each health reporting
45 # group.
46 query_health "health -f" || \
47         echo "Didn't see a single healthy fs metadata?"
48
49 query_health "health -a 0" || \
50         echo "Didn't see a single healthy ag metadata?"
51
52 query_health "health $SCRATCH_MNT" || \
53         echo "Didn't see a single healthy file metadata?"
54
55 # Unmount, corrupt filesystem
56 _scratch_unmount
57 _scratch_xfs_db -x -c 'sb 1' -c 'fuzz -d magicnum random' >> $seqres.full
58
59 # Now let's see what the AG report says
60 _scratch_mount
61 _scratch_scrub -n >> $seqres.full 2>&1
62 query_sick "health -a 1" || \
63         echo "Didn't see the expected unhealthy metadata?"
64
65 # success, all done
66 status=0
67 exit