summaryrefslogtreecommitdiff
path: root/tests/generic/723
blob: b452de020809d338ae914c9811d01c0a36b726b2 (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (c) 2022 Oracle.  All Rights Reserved.
#
# FS QA Test No. 723
#
# Test swapext with the dry run flag doesn't change anything.

. ./common/preamble
_begin_fstest auto quick fiexchange swapext

# Override the default cleanup function.
_cleanup()
{
	cd /
	rm -r -f $tmp.* $dir
}

# Import common functions.
. ./common/filter
. ./common/reflink

# real QA test starts here
_require_test_program "punch-alternating"
_require_xfs_io_command swapext '-v exchrange'
_require_scratch

_scratch_mkfs >> $seqres.full
_scratch_mount

_pwrite_byte 0x58 0 1m $SCRATCH_MNT/a >> $seqres.full
_pwrite_byte 0x59 0 2m $SCRATCH_MNT/b >> $seqres.full
$XFS_IO_PROG -c 'truncate 2m' $SCRATCH_MNT/a
$here/src/punch-alternating $SCRATCH_MNT/a
$here/src/punch-alternating $SCRATCH_MNT/b

old_a=$(md5sum $SCRATCH_MNT/a | awk '{print $1}')
old_b=$(md5sum $SCRATCH_MNT/b | awk '{print $1}')
echo "md5 a: $old_a md5 b: $old_b" >> $seqres.full

# Test swapext with the -n option, which will do all the input parameter
# checking and return 0 without changing anything.
echo dry run swap >> $seqres.full
$XFS_IO_PROG -c "swapext -v exchrange -n -f -u $SCRATCH_MNT/a" $SCRATCH_MNT/b
_scratch_cycle_mount

new_a=$(md5sum $SCRATCH_MNT/a | awk '{print $1}')
new_b=$(md5sum $SCRATCH_MNT/b | awk '{print $1}')
echo "md5 a: $new_a md5 b: $new_b" >> $seqres.full

test $old_a = $new_a || echo "scratch file A should not have swapped"
test $old_b = $new_b || echo "scratch file B should not have swapped"

# Do it again, but without the -n option, to prove that we can actually
# swap the file contents.
echo actual swap >> $seqres.full
$XFS_IO_PROG -c "swapext -v exchrange -f -u $SCRATCH_MNT/a" $SCRATCH_MNT/b
_scratch_cycle_mount

new_a=$(md5sum $SCRATCH_MNT/a | awk '{print $1}')
new_b=$(md5sum $SCRATCH_MNT/b | awk '{print $1}')
echo "md5 a: $new_a md5 b: $new_b" >> $seqres.full

test $old_a = $new_b || echo "scratch file A should have swapped"
test $old_b = $new_a || echo "scratch file B should have swapped"

# success, all done
echo Silence is golden
status=0
exit