Skip to content

Commit 4460127

Browse files
committed
unit tests: Add cases for btrfs subvol
Add test cases to verify new and modified logic for handling btrfs subvolumes as kdump targets. Assisted-by: Claude (Anthropic) Signed-off-by: Lichen Liu <[email protected]>
1 parent 4562d80 commit 4460127

File tree

2 files changed

+92
-6
lines changed

2 files changed

+92
-6
lines changed

spec/kdump-lib-initramfs_spec.sh

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ Describe 'kdump-lib-initramfs'
6767
else
6868
printf '/var %s[/ostree/deploy/default/var]\n/sysroot %s\n' "$7" "$7"
6969
fi
70+
elif [[ "$7" == '/dev/nvme0n1p3' ]]; then
71+
if [[ "$8" == "-f" ]]; then
72+
printf '/ /dev/nvme0n1p3[/root]\n'
73+
else
74+
printf '/ /dev/nvme0n1p3[/root]\n/var /dev/nvme0n1p3[/var]\n'
75+
fi
7076
fi
7177
}
7278

@@ -76,19 +82,51 @@ Describe 'kdump-lib-initramfs'
7682
# - IPv6 NFS target also contain '[' in the export
7783
# - local dumping target that has '[' in the name
7884
# - has bind mint
85+
# - has subvol
7986
Parameters
80-
'eng.redhat.com:/srv/[nfs]' '/mnt'
81-
'[2620:52:0:a1:217:38ff:fe01:131]:/srv/[nfs]' '/mnt'
82-
'/dev/mapper/rhel[disk]' '/'
83-
'/dev/vda4' '/sysroot'
87+
'eng.redhat.com:/srv/[nfs]' '' '/mnt'
88+
'[2620:52:0:a1:217:38ff:fe01:131]:/srv/[nfs]' '' '/mnt'
89+
'/dev/mapper/rhel[disk]' '' '/'
90+
'/dev/vda4' '' '/sysroot'
91+
'/dev/nvme0n1p3' '/var' '/var'
8492
End
8593

8694
It 'should handle all cases correctly'
87-
When call get_mntpoint_from_target "$1"
88-
The output should equal "$2"
95+
When call get_mntpoint_from_target "$1" "$2"
96+
The output should equal "$3"
8997
End
9098
End
9199

92100
End
93101

102+
Describe 'Test get_btrfs_subvol_from_mntopt'
103+
Context 'Given different mount option formats'
104+
# Test the following cases:
105+
# - Standard subvol option at the beginning
106+
# - Standard subvol option in the middle
107+
# - Standard subvol option at the end
108+
# - Subvol with @ prefix (common btrfs pattern)
109+
# - Subvol with complex path
110+
# - No subvol option present
111+
# - Empty mount options
112+
# - Subvol option with no value
113+
# - Similar but different option names
114+
Parameters
115+
"subvol=/home,rw,relatime" "/home"
116+
"rw,subvol=/root,defaults" "/root"
117+
"rw,relatime,subvol=/root" "/root"
118+
"subvol=@home" "@home"
119+
"subvol=/path/to/subvolume,rw" "/path/to/subvolume"
120+
"rw,relatime,defaults" ""
121+
true ''
122+
"subvol=,rw" ""
123+
"rw,subvolume=@home" ""
124+
End
125+
126+
It 'should extract subvolume correctly'
127+
When call get_btrfs_subvol_from_mntopt "$1"
128+
The output should equal "$2"
129+
End
130+
End
131+
End
94132
End

spec/kdump-lib_spec.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,52 @@ Describe 'kdump-lib'
133133
End
134134
End
135135

136+
Describe "get_kdump_mntpoint_from_target with btrfs subvolume support"
137+
# Mock get_mntpoint_from_target to simulate different mount scenarios
138+
get_mntpoint_from_target() {
139+
local device="$1" subvol="$2"
140+
case "$device" in
141+
'/dev/sda1')
142+
if [[ "$subvol" == "@home" ]]; then
143+
echo "/mnt/btrfs"
144+
elif [[ "$subvol" == "/root" ]]; then
145+
echo "/"
146+
else
147+
echo "/"
148+
fi
149+
;;
150+
'/dev/sdb1')
151+
if [[ "$subvol" == "@backup" ]]; then
152+
echo "/backup"
153+
else
154+
echo "/backup"
155+
fi
156+
;;
157+
*)
158+
echo "/"
159+
;;
160+
esac
161+
}
162+
163+
Context 'Given various mount point scenarios with subvolumes'
164+
# Test the following cases:
165+
# - Root filesystem with @ subvolume -> /sysroot
166+
# - Home subvolume on non-root -> /kdumproot/mnt/btrfs
167+
# - Backup subvolume -> /kdumproot/backup
168+
# - Regular filesystem without subvolume -> /sysroot
169+
Parameters
170+
'/dev/sda1 /root /sysroot'
171+
'/dev/sda1 @home /kdumproot/mnt/btrfs'
172+
'/dev/sdb1 @backup /kdumproot/backup'
173+
'/dev/vda2 "" /sysroot'
174+
End
175+
176+
It 'should handle btrfs subvolumes correctly'
177+
# Parse parameters: device subvol expected_result
178+
read -r device subvol expected_result <<< "$1"
179+
When call get_kdump_mntpoint_from_target "$device" "$subvol"
180+
The output should equal "$expected_result"
181+
End
182+
End
183+
End
136184
End

0 commit comments

Comments
 (0)