File: test.sh

package info (click to toggle)
btrfs-progs 6.2-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 17,244 kB
  • sloc: ansic: 114,376; sh: 9,576; python: 1,242; makefile: 820
file content (142 lines) | stat: -rwxr-xr-x 3,262 bytes parent folder | download
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
# Tests 'btrfs fi usage' reports correct space/ratio with various RAID profiles

source "$TEST_TOP/common"

check_prereq btrfs
setup_root_helper
setup_loopdevs 4
prepare_loopdevs

TEST_DEV=${loopdevs[1]}

report_numbers()
{
	local vars

	vars=($(run_check_stdout $SUDO_HELPER "$TOP/btrfs" filesystem usage -b "$TEST_MNT" | awk '
	/Data ratio/ { ratio=$3 }
	a {dev_alloc=$2; exit}
	/Data,(DUP|RAID[0156][C34]{0,2}|single)/ { size=substr($2,6,length($2)-6); a=1 }
END {print ratio " " size " " dev_alloc}'))

	echo "${vars[@]}"
}

test_dup()
{
	local vars
	local data_chunk_size
	local used_on_dev
	local data_ratio

	run_check_mkfs_test_dev -ddup
	run_check_mount_test_dev
	vars=($(report_numbers))
	data_chunk_size=${vars[1]}
	used_on_dev=${vars[2]}
	data_ratio=${vars[0]}

	[[ $used_on_dev -eq $((2*$data_chunk_size)) ]] ||
		_fail "DUP inconsistent chunk/device usage. Chunk: $data_chunk_size Device: $used_on_dev"

	[[ "$data_ratio" = "2.00" ]] ||
		_fail "DUP: Unexpected data ratio: $data_ratio (must be 2)"
	run_check_umount_test_dev
}

test_raid1()
{
	local vars
	local data_chunk_size
	local used_on_dev
	local data_ratio

	# single is not raid1 but it has the same characteristics so put it in here
	# as well
	for i in single,1.00 raid1,2.00 raid1c3,3.00 raid1c4,4.00; do

		# this allows to set the tuples to $1 and $2 respectively
		OLDIFS=$IFS
		IFS=","
		set -- $i
		IFS=$OLDIFS

		run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d$1 ${loopdevs[@]}
		run_check_mount_test_dev
		vars=($(report_numbers))
		data_chunk_size=${vars[1]}
		used_on_dev=${vars[2]}
		data_ratio=${vars[0]}

		[[ $used_on_dev -eq $data_chunk_size ]] ||
			_fail "$1 inconsistent chunk/device usage. Chunk: $data_chunk_size Device: $used_on_dev"

		[[ "$data_ratio" = "$2" ]] ||
			_fail "$1: Unexpected data ratio: $data_ratio (must be $2)"

		run_check_umount_test_dev
	done
}

test_raid0()
{
	local vars
	local data_chunk_size
	local used_on_dev
	local data_ratio

	run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -draid0 ${loopdevs[@]}
	run_check_mount_test_dev
	vars=($(report_numbers))
	data_chunk_size=${vars[1]}
	used_on_dev=${vars[2]}
	data_ratio=${vars[0]}

	# Divide by 4 since 4 loopp devices are setup
	[[ $used_on_dev -eq $(($data_chunk_size / 4)) ]] ||
		_fail "raid0 inconsistent chunk/device usage. Chunk: $data_chunk_size Device: $used_on_dev"

	[[ $data_ratio = "1.00" ]] ||
		_fail "raid0: Unexpected data ratio: $data_ratio (must be 1.5)"
	run_check_umount_test_dev
}

test_raid56()
{
	local vars
	local data_chunk_size
	local used_on_dev
	local data_ratio

	for i in raid5,1.33,3 raid6,2.00,2; do

		# This allows to set the tuples to $1 and $2 respectively
		OLDIFS=$IFS
		IFS=","
		set -- $i
		IFS=$OLDIFS

		run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d$1 ${loopdevs[@]}
		run_check_mount_test_dev
		vars=($(report_numbers))
		data_chunk_size=${vars[1]}
		used_on_dev=${vars[2]}
		data_ratio=${vars[0]}

		[[ $used_on_dev -eq $(($data_chunk_size / $3)) ]] ||
			_fail "$i inconsistent chunk/device usage. Chunk: $data_chunk_size Device: $used_on_dev"

		[[ $data_ratio = "$2" ]] ||
			_fail "$1: Unexpected data ratio: $data_ratio (must be $2)"

		run_check_umount_test_dev
	done
}

test_dup
test_raid1
test_raid0
test_raid56

cleanup_loopdevs