xfs: convert tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 168
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2007 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FSQA Test No. 168
6 #
7 # Check for DMAPI destroy events when removing files without attributes
8 # See PV960928 for details
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 rm -f $seqres.full
17 status=1    # failure is the default!
18 trap "exit \$status" 0 1 2 3 15
19
20 _filter_dmapi_print_event() {
21     $PERL_PROG -ne '
22 # replace session/file specific output with generic placeholders
23 s/token\s+\d+/token TOKEN/g ;
24 s/sequence\s+\d+/sequence SEQ/g ;
25 s/^\s+parent\s+dir\s+\w+/parent dir PARENT_DIR/g ;
26 s/^\s+name\s+.*/name FILE_NAME/g ;
27 s/^\s+mode\s+bits\s+mode\s+\d+:\s+/mode bits mode MODE: /g ;
28 s/perm\s+[\w|-]+\s[\w|-]+\s[\w|-]+/perm PERMISSIONS/g ;
29 s/,\s+type\s+.*/, type FILE_TYPE/g ;
30 s/^\s+object\s+\w+/object OBJECT/g ;
31 s/^\s+new\s+object\s+\w+/new object OBJECT/g ;
32 s/^\s+handle\s+\w+/handle HANDLE/g ;
33
34 # when print_event is killed, the following is output. trim it
35 s/^\s*print_event: Processing any undelivered event messages.*\n//g ;
36 s/^\s*print_event: Shutting down the session.*\n//g ;
37
38 # trim blank lines
39 s/^\s*\n//g ;
40     print ;'
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/filter
46 . ./common/dmapi
47
48 # real QA test starts here
49 _supported_fs xfs
50 _supported_os Linux
51
52 _require_scratch
53 _scratch_mkfs_xfs >/dev/null 2>&1
54 _dmapi_scratch_mount
55
56 qa_file_noattr=$SCRATCH_MNT/dmapi_file_noattr
57 qa_file_withattr=$SCRATCH_MNT/dmapi_file_withattr
58
59 # run dmapi print_event in background to capture events triggered during test
60 ${DMAPI_QASUITE1_DIR}cmd/print_event $SCRATCH_MNT > $tmp.print_event_out 2>&1 &
61 dmapi_print_event_pid=$!
62
63 # give time for print_event to start capturing events
64 sleep 2
65
66 # enable DMAPI set_return_on_destroy for $SCRATCH_MNT
67 ${DMAPI_COMMON_DIR}cmd/set_return_on_destroy -F $SCRATCH_MNT ATTR_NAME_1
68
69 echo "# create file"
70 touch $qa_file_noattr
71 echo "# remove file"
72 rm -f $qa_file_noattr
73
74 echo "# create file"
75 touch $qa_file_withattr
76 echo "# set dmapi attributes on file"
77 ${DMAPI_QASUITE1_DIR}cmd/set_dmattr $qa_file_withattr ATTR_NAME_1 ATTR_VALUE_1
78 echo "# remove file"
79 rm -f $qa_file_withattr
80
81 # kill off background dmapi print_event process
82 kill $dmapi_print_event_pid
83 # give dmapi print_event time to finish writing out any events not yet output
84 wait
85
86 # dmapi destroy events are asyncronous,  don't rely on fixed ordering of events
87 # in print_event output, use sort.
88 echo "# here comes the dmapi print_event filtered and sorted output"
89 cat $tmp.print_event_out | tee -a $seqres.full | _filter_dmapi_print_event | LC_COLLATE=POSIX sort
90 rm $tmp.print_event_out
91
92 status=0
93 exit