[Fuego] [PATCH v4] Add test cases for commands of module-init-tools.
Tim.Bird at sony.com
Tim.Bird at sony.com
Wed Feb 27 05:37:17 UTC 2019
> -----Original Message-----
> From: Zheng Ruoqin
>
> In default, these cases test kernel module uvesafb defined in spec.json.
> If there is no uvesafb in your board, you can modify spec.json to use an
> existing module instead of uvesafb.
>
> Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
> Signed-off-by: Zheng Ruoqin <zhengrq.fnst at cn.fujitsu.com>
> ---
> tests/Functional.module_init_tools/fuego_test.sh | 27 +++++++++++++
> .../module-init-tools_test.sh | 6 +++
> tests/Functional.module_init_tools/parser.py | 22 +++++++++++
> tests/Functional.module_init_tools/spec.json | 8 ++++
> .../tests/module-init-tools_depmod.sh | 29 ++++++++++++++
> .../tests/module-init-tools_insmod.sh | 38 +++++++++++++++++++
> .../tests/module-init-tools_lsmod.sh | 39 +++++++++++++++++++
> .../tests/module-init-tools_modinfo.sh | 15 ++++++++
> .../tests/module-init-tools_modprobe.sh | 35 +++++++++++++++++
> .../tests/module-init-tools_rmmod.sh | 44
> ++++++++++++++++++++++
> 10 files changed, 263 insertions(+)
> create mode 100644 tests/Functional.module_init_tools/fuego_test.sh
> create mode 100755 tests/Functional.module_init_tools/module-init-
> tools_test.sh
> create mode 100644 tests/Functional.module_init_tools/parser.py
> create mode 100644 tests/Functional.module_init_tools/spec.json
> create mode 100644 tests/Functional.module_init_tools/tests/module-init-
> tools_depmod.sh
> create mode 100644 tests/Functional.module_init_tools/tests/module-init-
> tools_insmod.sh
> create mode 100644 tests/Functional.module_init_tools/tests/module-init-
> tools_lsmod.sh
> create mode 100644 tests/Functional.module_init_tools/tests/module-init-
> tools_modinfo.sh
> create mode 100644 tests/Functional.module_init_tools/tests/module-init-
> tools_modprobe.sh
> create mode 100644 tests/Functional.module_init_tools/tests/module-init-
> tools_rmmod.sh
>
> diff --git a/tests/Functional.module_init_tools/fuego_test.sh
> b/tests/Functional.module_init_tools/fuego_test.sh
> new file mode 100644
> index 0000000..1e07a8f
> --- /dev/null
> +++ b/tests/Functional.module_init_tools/fuego_test.sh
> @@ -0,0 +1,27 @@
> +NEED_ROOT=1
> +MODULE_NAME=$FUNCTIONAL_MODULE_INIT_TOOLS_TEST_MODULE_N
> AME
> +
> +function test_pre_check {
> + assert_has_program depmod
> + assert_has_program insmod
> + assert_has_program lsmod
> + assert_has_program rmmod
> + assert_has_program modinfo
> + assert_has_program modprobe
> + cmd "modinfo $MODULE_NAME" || abort_job "Missing
> $MODULE_NAME.ko kernel module"
I like this approach. It's simpler and easier to understand than the
solution I suggested.
> +}
> +
> +function test_deploy {
> + put $TEST_HOME/module-init-tools_test.sh
> $BOARD_TESTDIR/fuego.$TESTDIR/
> + put $FUEGO_CORE/scripts/fuego_board_function_lib.sh
> $BOARD_TESTDIR/fuego.$TESTDIR
> + put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
> +}
> +
> +function test_run {
> + report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
> + ./module-init-tools_test.sh $MODULE_NAME"
> +}
> +
> +function test_processing {
> + log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
> +}
> diff --git a/tests/Functional.module_init_tools/module-init-tools_test.sh
> b/tests/Functional.module_init_tools/module-init-tools_test.sh
> new file mode 100755
> index 0000000..6579f7f
> --- /dev/null
> +++ b/tests/Functional.module_init_tools/module-init-tools_test.sh
> @@ -0,0 +1,6 @@
> +#!/bin/sh
> +export MODULE_NAME=$1
> +
> +for i in tests/*.sh; do
> + sh $i
> +done
> diff --git a/tests/Functional.module_init_tools/parser.py
> b/tests/Functional.module_init_tools/parser.py
> new file mode 100644
> index 0000000..db3d69b
> --- /dev/null
> +++ b/tests/Functional.module_init_tools/parser.py
> @@ -0,0 +1,22 @@
> +#!/usr/bin/python
> +# See common.py for description of command-line arguments
> +
> +import os, sys, collections
> +
> +sys.path.insert(0, os.environ['FUEGO_CORE'] + '/scripts/parser')
This is not needed, but I'll remove it with a separate patch.
> +import common as plib
> +
> +measurements = {}
> +measurements = collections.OrderedDict()
> +
> +regex_string = '^ -> (.*): TEST-(.*)$'
> +matches = plib.parse_log(regex_string)
> +
> +if matches:
> + for m in matches:
> + measurements['default.' + m[0]] = 'PASS' if m[1] == 'PASS' else 'FAIL'
> +
> +# split the output for each testcase
> +plib.split_output_per_testcase(regex_string, measurements)
> +
> +sys.exit(plib.process(measurements))
> diff --git a/tests/Functional.module_init_tools/spec.json
> b/tests/Functional.module_init_tools/spec.json
> new file mode 100644
> index 0000000..532518c
> --- /dev/null
> +++ b/tests/Functional.module_init_tools/spec.json
> @@ -0,0 +1,8 @@
> +{
> + "testName": "Functional.module_init_tools",
> + "specs": {
> + "default": {
> + "test_module_name": "uvesafb"
> + }
> + }
> +}
> diff --git a/tests/Functional.module_init_tools/tests/module-init-
> tools_depmod.sh b/tests/Functional.module_init_tools/tests/module-init-
> tools_depmod.sh
> new file mode 100644
> index 0000000..29d31b6
> --- /dev/null
> +++ b/tests/Functional.module_init_tools/tests/module-init-
> tools_depmod.sh
> @@ -0,0 +1,29 @@
> +#!/bin/sh
> +
> +# In target, run command depmod.
> +# option: none
> +
> +test="depmod"
> +
> +test_krnl_rel=$(uname -r)
> +
> +if [ -f /lib/modules/$test_krnl_rel/modules.dep ]
> +then
> + mv /lib/modules/$test_krnl_rel/modules.dep
> /lib/modules/$test_krnl_rel/modules.dep_bak
> +fi
> +
> +depmod
> +
> +if ls -l /lib/modules/$test_krnl_rel/modules.dep
> +then
> + echo " -> $test: TEST-PASS"
> +else
> + echo " -> $test: TEST-FAIL"
> +fi
> +
> +if [ -f /lib/modules/$test_krnl_rel/modules.dep_bak ]
> +then
> + mv /lib/modules/$test_krnl_rel/modules.dep_bak
> /lib/modules/$test_krnl_rel/modules.dep
> +else
> + rm /lib/modules/$test_krnl_rel/modules.dep
> +fi
> diff --git a/tests/Functional.module_init_tools/tests/module-init-
> tools_insmod.sh b/tests/Functional.module_init_tools/tests/module-init-
> tools_insmod.sh
> new file mode 100644
> index 0000000..df5fdf6
> --- /dev/null
> +++ b/tests/Functional.module_init_tools/tests/module-init-
> tools_insmod.sh
> @@ -0,0 +1,38 @@
> +#!/bin/sh
> +
> +# In target, run command insmod.
> +# option: none
> +
> +test="insmod"
> +
> +tst_mod_file="ko file of module"
> +
> +if modinfo $MODULE_NAME
> +then
> + tst_mod_file=$(modinfo $MODULE_NAME | head -n 1 | cut -d' ' -f8)
> +else
> + echo " -> module $MODULE_NAME is not exist."
> + echo " -> $test: TEST-FAIL"
> + exit
> +fi
> +
> +mkdir test_dir
> +cp $tst_mod_file test_dir/
> +
> +# If the module is already loaded, the insmod test goes pass.
> +if lsmod | grep $MODULE_NAME
> +then
> + echo " -> $test: TEST-PASS"
> + rm -fr test_dir
> + exit 0
> +fi
> +
> +if insmod test_dir/*.ko
> +then
> + echo " -> $test: TEST-PASS"
> +else
> + echo " -> $test: TEST-FAIL"
> +fi
> +
> +rmmod $tst_mod_file
> +rm -fr test_dir
> diff --git a/tests/Functional.module_init_tools/tests/module-init-
> tools_lsmod.sh b/tests/Functional.module_init_tools/tests/module-init-
> tools_lsmod.sh
> new file mode 100644
> index 0000000..9e4ed9f
> --- /dev/null
> +++ b/tests/Functional.module_init_tools/tests/module-init-tools_lsmod.sh
> @@ -0,0 +1,39 @@
> +#!/bin/sh
> +
> +# In target, run command lsmod.
> +# option: none
> +
> +test="lsmod"
> +
> +tst_mod_file="ko file of module"
> +
> +if modinfo $MODULE_NAME
> +then
> + tst_mod_file=$(modinfo $MODULE_NAME | head -n 1 | cut -d' ' -f8)
> +else
> + echo " -> module $MODULE_NAME is not exist."
> + echo " -> $test: TEST-FAIL"
> + exit
> +fi
> +
> +if lsmod | grep $MODULE_NAME
> +then
> + echo " -> $test: TEST-PASS"
> + exit
> +fi
> +
> +mkdir test_dir
> +cp $tst_mod_file test_dir/
> +
> +insmod test_dir/*.ko
> +
> +if lsmod | grep $MODULE_NAME
> +then
> + echo " -> $test: TEST-PASS"
> +else
> + echo " -> $test: TEST-FAIL"
> +fi
> +
> +rmmod $tst_mod_file
> +rm -fr test_dir
> +
> diff --git a/tests/Functional.module_init_tools/tests/module-init-
> tools_modinfo.sh b/tests/Functional.module_init_tools/tests/module-init-
> tools_modinfo.sh
> new file mode 100644
> index 0000000..85c1656
> --- /dev/null
> +++ b/tests/Functional.module_init_tools/tests/module-init-
> tools_modinfo.sh
> @@ -0,0 +1,15 @@
> +#!/bin/sh
> +
> +# In target, run command modinfo.
> +# option: none
> +
> +test="modinfo"
> +
> +if modinfo $MODULE_NAME | grep "filename"
> +then
> + echo " -> $test: TEST-PASS"
> +else
> + echo " -> module $MODULE_NAME is not exist."
> + echo " -> $test: TEST-FAIL"
> + exit
> +fi
> diff --git a/tests/Functional.module_init_tools/tests/module-init-
> tools_modprobe.sh b/tests/Functional.module_init_tools/tests/module-
> init-tools_modprobe.sh
> new file mode 100644
> index 0000000..6ae675c
> --- /dev/null
> +++ b/tests/Functional.module_init_tools/tests/module-init-
> tools_modprobe.sh
> @@ -0,0 +1,35 @@
> +#!/bin/sh
> +
> +# In target, run command modprobe.
> +# option: modprobe
> +
> +test="modprobe"
> +
> +tst_mod_file="ko file of module"
> +test_krnl_rel=$(uname -r)
> +
> +if modinfo $MODULE_NAME
> +then
> + tst_mod_file=$(modinfo $MODULE_NAME | head -n 1 | cut -d' ' -f8)
> +else
> + echo " -> module $MODULE_NAME is not exist."
> + echo " -> $test: TEST-FAIL"
> + exit
> +fi
> +
> +# '-D' means only print module dependencies and exit
> +if modprobe -D uvesafb | grep "insmod $tst_mod_file"
> +then
> + echo " -> $test: modprobe -D succeeded."
> +else
> + echo " -> $test: modprobe -D failed."
> + echo " -> $test: TEST-FAIL"
> + exit
> +fi
> +
> +if cat /lib/modules/$test_krnl_rel/modules.dep | grep
> "$MODULE_NAME.ko"
> +then
> + echo " -> $test: TEST-PASS"
> +else
> + echo " -> $test: TEST-FAIL"
> +fi
> diff --git a/tests/Functional.module_init_tools/tests/module-init-
> tools_rmmod.sh b/tests/Functional.module_init_tools/tests/module-init-
> tools_rmmod.sh
> new file mode 100644
> index 0000000..192bf4e
> --- /dev/null
> +++ b/tests/Functional.module_init_tools/tests/module-init-
> tools_rmmod.sh
> @@ -0,0 +1,44 @@
> +#!/bin/sh
> +
> +# In target, run command rmmod.
> +# option: none
> +
> +test="rmmod"
> +
> +tst_mod_file="ko file of module"
> +tst_mod_flag=0
> +
> +if modinfo $MODULE_NAME
> +then
> + tst_mod_file=$(modinfo $MODULE_NAME | sed -n 1p | cut -d' ' -f8)
> +else
> + echo " -> module $MODULE_NAME is not exist."
> + echo " -> $test: TEST-FAIL"
> + exit
> +fi
> +
> +mkdir test_dir
> +cp $tst_mod_file test_dir/
> +
> +if lsmod | grep $MODULE_NAME
> +then
> + tst_mod_flag=1
> + rmmod $tst_mod_file
> +else
> + insmod test_dir/*.ko
> + rmmod $tst_mod_file
> +fi
> +
> +
> +if lsmod | grep $MODULE_NAME
> +then
> + echo " -> $test: TEST-FAIL"
> +else
> + echo " -> $test: TEST-PASS"
> +fi
> +
> +if [ $tst_mod_flag=1 ]
> +then
> + insmod $tst_mod_file
> +fi
> +rm -fr test_dir
> --
> 1.8.3.1
Looks good. Thanks for persisting in getting this in.
Applied to the fuegotest 'next' branch.
I'm also applying a small fixup patch to remove some trailing whitespace
on a few lines, fix the wording in a few messages, and check that the
required MODULE_NAME is provided.
-- Tim
More information about the Fuego
mailing list