unit tests: add tests for prepare_cmdline

prepare_cmdline is totally broken. For example if the remove list ($2)
is empty it removes all white spaces or if a parameter has a quoted
value containing a white space it only removes the first part of the
parameter up to the first space. Thus add a test case that shows what the
function should do in order to fix it in subsequent patches.

Signed-off-by: Philipp Rudo <prudo@redhat.com>
Reviewed-by: Coiby Xu <coxu@redhat.com>
This commit is contained in:
Philipp Rudo 2023-01-12 16:31:05 +01:00 committed by Coiby Xu
parent 88919b73f0
commit 269c26972d

View File

@ -48,4 +48,36 @@ Describe 'kdump-lib'
End End
End End
Describe 'prepare_cmdline()'
get_bootcpu_apicid() {
echo 1
}
get_watchdog_drvs() {
echo foo
}
add="disable_cpu_apicid=1 foo.pretimeout=0"
Parameters
#test cmdline remove add result
"#1" "a b c" "" "" "a b c"
"#2" "a b c" "b" "" "a c"
"#3" "a b=x c" "b" "" "a c"
"#4" "a b='x y' c" "b" "" "a c"
"#5" "a b='x y' c" "b=x" "" "a c"
"#6" "a b='x y' c" "b='x y'" "" "a c"
"#7" "a b c" "" "x" "a b c x"
"#8" "a b c" "" "x=1" "a b c x=1"
"#9" "a b c" "" "x='1 2'" "a b c x='1 2'"
"#10" "a b c" "a" "x='1 2'" "b c x='1 2'"
"#11" "a b c" "x" "x='1 2'" "a b c x='1 2'"
End
It "Test $1: should generate the correct kernel command line"
When call prepare_cmdline "$2" "$3" "$4"
The output should equal "$5 $add"
End
End
End End