From ea8b06df8392d71bdb694646a4e24fd29a947977 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 4 Jan 2022 20:57:55 +0800 Subject: [PATCH] unit tests: add tests for _{update,read}_kernel_arg_in_grub_etc_default in kdumpctl Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- spec/kdumpctl_general_spec.sh | 67 +++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/spec/kdumpctl_general_spec.sh b/spec/kdumpctl_general_spec.sh index 9fbc1a0..e72bf1d 100644 --- a/spec/kdumpctl_general_spec.sh +++ b/spec/kdumpctl_general_spec.sh @@ -107,4 +107,71 @@ Describe 'kdumpctl' End End + Describe '_update_kernel_arg_in_grub_etc_default()' + GRUB_ETC_DEFAULT=/tmp/default_grub + + cleanup() { + rm -rf "$GRUB_ETC_DEFAULT" + } + AfterAll 'cleanup' + + Context 'when the given parameter is in different positions' + Parameters + "crashkernel=222M fadump=on rhgb quiet" crashkernel 333M + " fadump=on crashkernel=222M rhgb quiet" crashkernel 333M + "fadump=on rhgb quiet crashkernel=222M" crashkernel 333M + "fadump=on rhgb quiet" crashkernel 333M + "fadump=on foo=bar1 rhgb quiet" foo bar2 + End + + It 'should update the kernel parameter correctly' + echo 'GRUB_CMDLINE_LINUX="'"$1"'"' >$GRUB_ETC_DEFAULT + When call _update_kernel_arg_in_grub_etc_default "$2" "$3" + # the updated kernel parameter should appear in the end + The contents of file $GRUB_ETC_DEFAULT should include "$2=$3\"" + End + End + + It 'should only update the given parameter and not update the parameter that has the given parameter as suffix' + echo 'GRUB_CMDLINE_LINUX="fadump=on rhgb quiet ckcrashkernel=222M"' >$GRUB_ETC_DEFAULT + _ck_val=1G-4G:192M,4G-64G:256M,64G-102400T:512M + When call _update_kernel_arg_in_grub_etc_default crashkernel "$_ck_val" + The contents of file $GRUB_ETC_DEFAULT should include "crashkernel=$_ck_val\"" + The contents of file $GRUB_ETC_DEFAULT should include "ckcrashkernel=222M" + End + + It 'should be able to handle the cases of there are multiple crashkernel entries' + echo 'GRUB_CMDLINE_LINUX="fadump=on rhgb quiet crashkernel=101M crashkernel=222M"' >$GRUB_ETC_DEFAULT + _ck_val=1G-4G:192M,4G-64G:256M,64G-102400T:512M + When call _update_kernel_arg_in_grub_etc_default crashkernel "$_ck_val" + The contents of file $GRUB_ETC_DEFAULT should include "crashkernel=$_ck_val\"" + The contents of file $GRUB_ETC_DEFAULT should not include "crashkernel=222M" + End + + Context 'when it removes a kernel parameter' + + It 'should remove all values for given arg' + echo 'GRUB_CMDLINE_LINUX="crashkernel=33M crashkernel=11M fadump=on crashkernel=222M"' >$GRUB_ETC_DEFAULT + When call _update_kernel_arg_in_grub_etc_default crashkernel + The contents of file $GRUB_ETC_DEFAULT should equal 'GRUB_CMDLINE_LINUX="fadump=on"' + End + + It 'should not remove args that have the given arg as suffix' + echo 'GRUB_CMDLINE_LINUX="ckcrashkernel=33M crashkernel=11M ckcrashkernel=222M"' >$GRUB_ETC_DEFAULT + When call _update_kernel_arg_in_grub_etc_default crashkernel + The contents of file $GRUB_ETC_DEFAULT should equal 'GRUB_CMDLINE_LINUX="ckcrashkernel=33M ckcrashkernel=222M"' + End + End + + End + + Describe '_read_kernel_arg_in_grub_etc_default()' + GRUB_ETC_DEFAULT=/tmp/default_grub + It 'should read the value for given arg' + echo 'GRUB_CMDLINE_LINUX="crashkernel=33M crashkernel=11M ckcrashkernel=222M"' >$GRUB_ETC_DEFAULT + When call _read_kernel_arg_in_grub_etc_default crashkernel + The output should equal '11M' + End + End + End