summaryrefslogtreecommitdiffstats
path: root/tests/ts/blkdiscard/offsets
blob: 5e724d51b4aefe2f6d3dccc927bcb6b14d6d3834 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash

#
# Copyright (C) 2014 Federico Simoncelli <fsimonce@redhat.com>
#
# This file is part of util-linux.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
TS_TOPDIR="${0%/*}/../.."
TS_DESC="offsets"

. $TS_TOPDIR/functions.sh
ts_init "$*"

ts_check_test_command "$TS_CMD_BLKDISCARD"

ts_skip_nonroot
ts_check_losetup

ORIGPWD=$(pwd)
IMAGE_NAME="${TS_TESTNAME}-loop.img"
IMAGE_PATH="$TS_OUTDIR/$IMAGE_NAME"

truncate -s 10M $IMAGE_PATH

ts_log "create loop device from image"
DEVICE=$($TS_CMD_LOSETUP --show -f $IMAGE_PATH)
ts_register_loop_device "$DEVICE"

function run_tscmd {
	local ret
	"$@" >> $TS_OUTPUT 2>> $TS_ERRLOG
	ret=$?
	echo "ret: $ret" >> "$TS_OUTPUT"
	return $ret
}

ts_log "testing offsets with full block size"
run_tscmd $TS_CMD_BLKDISCARD -v $DEVICE
if [ "$?" != "0" ]; then
	# Skip the rest? For example loop backing files on NFS seem unsupported.
	grep -q "BLKDISCARD ioctl failed: Operation not supported" "$TS_ERRLOG" \
		&& ts_skip "BLKDISCARD not supported"
fi
run_tscmd $TS_CMD_BLKDISCARD -v -o 1 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -o 511 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -o 512 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -o 1024 $DEVICE

ts_log "testing offsets with specific length"
run_tscmd $TS_CMD_BLKDISCARD -v -l 5242880 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -l 5242881 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -l 5243391 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -o 1 -l 5242880 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -o 511 -l 5242880 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -o 512 -l 5242880 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -o 1024 -l 5242880 $DEVICE

ts_log "testing aligned steps full device"
run_tscmd $TS_CMD_BLKDISCARD -v -p 5242880 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -p 1310720 $DEVICE

ts_log "testing aligned steps with offsets and length"
run_tscmd $TS_CMD_BLKDISCARD -v -p 512 -l 1024 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -p 512 -o 1 -l 1024 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -p 512 -o 1 -l 1536 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -p 512 -o 511 -l 1536 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -p 512 -o 512 -l 1536 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -p 512 -o 1024 -l 1024 $DEVICE

ts_log "testing misaligned steps full device"
run_tscmd $TS_CMD_BLKDISCARD -v -p 1 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -p 256 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -p 511 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -p 513 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -p 768 $DEVICE

ts_log "testing misaligned steps with offsets and length"
run_tscmd $TS_CMD_BLKDISCARD -v -p 511 -l 1024 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -p 511 -o 1 -l 1536 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -p 511 -o 511 -l 1536 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -p 511 -l 10240 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -p 511 -o 1 -l 10240 $DEVICE
run_tscmd $TS_CMD_BLKDISCARD -v -p 511 -o 511 -l 10240 $DEVICE

sed -i "s#$DEVICE:\s##" $TS_OUTPUT $TS_ERRLOG

ts_log "detach loop device from image"

ts_cd "$ORIGPWD"

ts_finalize