[Fuego] [PATCH] Add test cases for commands of module-init-tools.

Tim.Bird at sony.com Tim.Bird at sony.com
Wed Sep 12 00:37:39 UTC 2018


These tests will have to be re-worked to not use function_lib
for board-specific and lab-specific funtions, but see my other
comments inline below as well.

> -----Original Message-----
> From: Wang Mingyu
> 
> Signed-off-by: Wang Mingyu <wangmy at cn.fujitsu.com>
> ---
>  .../Functional.module-init-tools/fuego_test.sh     | 29
> ++++++++++++++++++++++
>  .../module-init-tools_test.sh                      |  4 +++
>  .../tests/Functional.module-init-tools/parser.py   | 22 ++++++++++++++++
>  .../tests/Functional.module-init-tools/spec.json   |  7 ++++++
>  .../tests/module-init-tools_depmod.sh              | 19 ++++++++++++++
>  .../tests/module-init-tools_insmod.sh              | 21 ++++++++++++++++
>  .../tests/module-init-tools_lsmod.sh               | 23 +++++++++++++++++
>  .../tests/module-init-tools_modinfo.sh             | 23 +++++++++++++++++
>  .../tests/module-init-tools_modprobe.sh            | 24 ++++++++++++++++++
>  .../tests/module-init-tools_rmmod.sh               | 22 ++++++++++++++++
>  10 files changed, 194 insertions(+)
>  create mode 100644 engine/tests/Functional.module-init-
> tools/fuego_test.sh
>  create mode 100644 engine/tests/Functional.module-init-tools/module-init-
> tools_test.sh
>  create mode 100644 engine/tests/Functional.module-init-tools/parser.py
>  create mode 100644 engine/tests/Functional.module-init-tools/spec.json
>  create mode 100644 engine/tests/Functional.module-init-
> tools/tests/module-init-tools_depmod.sh
>  create mode 100644 engine/tests/Functional.module-init-
> tools/tests/module-init-tools_insmod.sh
>  create mode 100644 engine/tests/Functional.module-init-
> tools/tests/module-init-tools_lsmod.sh
>  create mode 100644 engine/tests/Functional.module-init-
> tools/tests/module-init-tools_modinfo.sh
>  create mode 100644 engine/tests/Functional.module-init-
> tools/tests/module-init-tools_modprobe.sh
>  create mode 100644 engine/tests/Functional.module-init-
> tools/tests/module-init-tools_rmmod.sh
> 
> diff --git a/engine/tests/Functional.module-init-tools/fuego_test.sh
> b/engine/tests/Functional.module-init-tools/fuego_test.sh
> new file mode 100644
> index 0000000..f1b8a2b
> --- /dev/null
> +++ b/engine/tests/Functional.module-init-tools/fuego_test.sh
> @@ -0,0 +1,29 @@
> +function test_pre_check {
> +    is_on_target_path depmod PROGRAM_DEPMOD
> +    assert_define PROGRAM_DEPMOD "Missing 'depmod' program on target
> board"
> +    is_on_target_path insmod PROGRAM_INSMOD
> +    assert_define PROGRAM_INSMOD "Missing 'insmod' program on target
> board"
> +    is_on_target_path lsmod PROGRAM_LSMOD
> +    assert_define PROGRAM_LSMOD "Missing 'lsmod' program on target
> board"
> +    is_on_target_path rmmod PROGRAM_RMMOD
> +    assert_define PROGRAM_RMMOD "Missing 'rnmod' program on target
> board"
'rnmod' should be 'rmmod' in this error string.

> +    is_on_target_path modinfo PROGRAM_MODINFO
> +    assert_define PROGRAM_MODINFO "Missing 'modinfo' program on
> target board"
> +    is_on_target_path modprobe PROGRAM_MODPROBE
> +    assert_define PROGRAM_MODPROBE "Missing 'modprobe' program on
> target board"
> +}
> +
> +function test_deploy {
> +    put $TEST_HOME/module-init-tools_test.sh
> $BOARD_TESTDIR/fuego.$TESTDIR/
> +    put $FUEGO_CORE/engine/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;\
> +    sh -v module-init-tools_test.sh"
> +}
> +
> +function test_processing {
> +    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
> +}
> diff --git a/engine/tests/Functional.module-init-tools/module-init-
> tools_test.sh b/engine/tests/Functional.module-init-tools/module-init-
> tools_test.sh
> new file mode 100644
> index 0000000..dd5ce37
> --- /dev/null
> +++ b/engine/tests/Functional.module-init-tools/module-init-tools_test.sh
> @@ -0,0 +1,4 @@
> +#!/bin/sh
> +for i in tests/*.sh; do
> +    sh $i
> +done
> diff --git a/engine/tests/Functional.module-init-tools/parser.py
> b/engine/tests/Functional.module-init-tools/parser.py
> new file mode 100644
> index 0000000..d85abd7
> --- /dev/null
> +++ b/engine/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'] + '/engine/scripts/parser')
> +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/engine/tests/Functional.module-init-tools/spec.json
> b/engine/tests/Functional.module-init-tools/spec.json
> new file mode 100644
> index 0000000..8e45a5d
> --- /dev/null
> +++ b/engine/tests/Functional.module-init-tools/spec.json
> @@ -0,0 +1,7 @@
> +{
> +    "testName": "Functional.module-init-tools",
> +    "specs": {
> +        "default": {}
> +    }
> +}
> +
> diff --git a/engine/tests/Functional.module-init-tools/tests/module-init-
> tools_depmod.sh b/engine/tests/Functional.module-init-
> tools/tests/module-init-tools_depmod.sh
> new file mode 100644
> index 0000000..f72a1f8
> --- /dev/null
> +++ b/engine/tests/Functional.module-init-tools/tests/module-init-
> tools_depmod.sh
> @@ -0,0 +1,19 @@
> +#!/bin/sh
> +
> +#  In target, run command depmod.
> +#  option: none
> +
> +test="depmod"
> +
> +. ./fuego_board_function_lib.sh
should just do:
test_krnl_rel=$(uname -r)
locally in this file, instead of getting it from fuego_board_function_lib.sh

> +
> +rm -f /lib/modules/$test_krnl_rel/modules.dep
This is not acceptable.

If the test fails, then the machine is left without modules.dep.
Please save this off, if it exists.  You may also way to use it
to check that the data produced by depmod matches the pre-existing
file.
> +
> +depmod
Also, if there wasn't a modules.dep before, this will leave one around
on the target.  There are valid reasons (mainly having to do with size)
why a product would not want a modules.dep file on the board in
a production system.

> +
> +if ls -l /lib/modules/$test_krnl_rel/modules.dep
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi

If modules.dep did not exist before the test was run, it should be removed
here after creating it.

> diff --git a/engine/tests/Functional.module-init-tools/tests/module-init-
> tools_insmod.sh b/engine/tests/Functional.module-init-tools/tests/module-
> init-tools_insmod.sh
> new file mode 100644
> index 0000000..233d7e3
> --- /dev/null
> +++ b/engine/tests/Functional.module-init-tools/tests/module-init-
> tools_insmod.sh
> @@ -0,0 +1,21 @@
> +#!/bin/sh
> +
> +#  In target, run command insmod.
> +#  option: none
> +
> +test="insmod"
> +
> +. ./fuego_board_function_lib.sh
> +
> +mkdir test_dir
> +cp -a /lib/modules/$test_krnl_rel/kernel/$tst_mod_dir$tst_mod_file.ko

How do you know if the specified kernel module will be present?
Many embedded systems strip the modules down to just those
used by the system. You should at least check that the file exists
before trying to copy it.

And, this should either be auto-detected or specified using a board
or spec variable.

> test_dir/
> +
> +if insmod test_dir/$tst_mod_file.ko
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> +
> +rmmod $tst_mod_file
Not all modules can be safely removed.  I presume you've checked to see
if net/ipv4/ah4 can be safely loaded and removed.  (I just looked at it,
and it seems safe - but I'm not familiar with this module.)

Also, this assumes that the module was not loaded before the test.
I don't know how commonly net/ipv4/ah4 is used, but it's bad practice
to leave the machine in a different state than you found it in.

IOW, you should not rmmod if the module was already loaded before
the test.  This cleanup should probably go in the insmod PASS branch of the
if (because presumably you'll get a FAIL if the module is already loaded).

> +rm -fr test_dir
> diff --git a/engine/tests/Functional.module-init-tools/tests/module-init-
> tools_lsmod.sh b/engine/tests/Functional.module-init-tools/tests/module-
> init-tools_lsmod.sh
> new file mode 100644
> index 0000000..667681d
> --- /dev/null
> +++ b/engine/tests/Functional.module-init-tools/tests/module-init-
> tools_lsmod.sh
> @@ -0,0 +1,23 @@
> +#!/bin/sh
> +
> +#  In target, run command lsmod.
> +#  option: none
> +
> +test="lsmod"
> +
> +. ./fuego_board_function_lib.sh
> +
> +mkdir test_dir
> +cp -a /lib/modules/$test_krnl_rel/kernel/$tst_mod_dir$tst_mod_file.ko
> test_dir/
Should check that module exists before using it.
Should use board-specific or spec-specific module name.

> +
> +insmod test_dir/$tst_mod_file.ko
> +
> +if lsmod |grep $tst_mod_file | grep "$tst_mod_file  .*"
What is the second grep for?

> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> +
> +rmmod $tst_mod_file
> +rm -fr test_dir
> diff --git a/engine/tests/Functional.module-init-tools/tests/module-init-
> tools_modinfo.sh b/engine/tests/Functional.module-init-
> tools/tests/module-init-tools_modinfo.sh
> new file mode 100644
> index 0000000..8275978
> --- /dev/null
> +++ b/engine/tests/Functional.module-init-tools/tests/module-init-
> tools_modinfo.sh
> @@ -0,0 +1,23 @@
> +#!/bin/sh
> +
> +#  In target, run command modinfo.
> +#  option: none
> +
> +test="modinfo"
> +
> +. ./fuego_board_function_lib.sh
> +
> +mkdir test_dir
> +cp -a /lib/modules/$test_krnl_rel/kernel/$tst_mod_dir$tst_mod_file.ko
> test_dir/
> +
> +insmod test_dir/$tst_mod_file.ko
> +
> +if modinfo test_dir/$tst_mod_file.ko | grep -z "filename.*$test_krnl_rel.*"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi;
> +
> +rmmod $tst_mod_file
> +rm -fr test_dir
> diff --git a/engine/tests/Functional.module-init-tools/tests/module-init-
> tools_modprobe.sh b/engine/tests/Functional.module-init-
> tools/tests/module-init-tools_modprobe.sh
> new file mode 100644
> index 0000000..f71805b
> --- /dev/null
> +++ b/engine/tests/Functional.module-init-tools/tests/module-init-
> tools_modprobe.sh
> @@ -0,0 +1,24 @@
> +#!/bin/sh
> +
> +#  In target, run command modprobe.
> +#  option: modprobe
> +
> +test="modprobe"
> +
> +. ./fuego_board_function_lib.sh
> +
> +if modprobe -D $tst_mod_file | grep "insmod
shouldn't this be '-d' (little 'd')?  I don't see an option
'-D' supported by modprobe in its man page.

> /lib/modules/$test_krnl_rel/kernel/$tst_mod_dir$tst_mod_file.ko"
> +then
> +    echo " -> $test: modprobe -D is succeeded."
> +else
> +    echo " -> $test: modprobe -D is failed."
> +    echo " -> $test: TEST-FAIL"
> +    exit
> +fi
> +
> +if cat /lib/modules/$test_krnl_rel/modules.dep | grep $tst_mod_file | grep
> "kernel/$tst_mod_dir$tst_mod_file.ko:.*"
> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> diff --git a/engine/tests/Functional.module-init-tools/tests/module-init-
> tools_rmmod.sh b/engine/tests/Functional.module-init-tools/tests/module-
> init-tools_rmmod.sh
> new file mode 100644
> index 0000000..9e76f16
> --- /dev/null
> +++ b/engine/tests/Functional.module-init-tools/tests/module-init-
> tools_rmmod.sh
> @@ -0,0 +1,22 @@
> +#!/bin/sh
> +
> +#  In target, run command rmmod.
> +#  option: none
> +
> +test="rmmod"
> +
> +. ./fuego_board_function_lib.sh
> +
> +mkdir test_dir
> +cp -a /lib/modules/$test_krnl_rel/kernel/$tst_mod_dir$tst_mod_file.ko
> test_dir/
Same issues as mentioned elsewhere.
> +
> +insmod test_dir/$tst_mod_file.ko
> +
> +if rmmod $tst_mod_file
Actually, it would be better to do lsmod to make sure the module
is now gone, rather than just rely on rmmod's exit code.
(or grep /proc/modules).

> +then
> +    echo " -> $test: TEST-PASS"
> +else
> +    echo " -> $test: TEST-FAIL"
> +fi
> +
> +rm -fr test_dir
> --
> 1.8.3.1

Thanks for the submission.  Please fix up the mentioned issues and re-submit.
 -- Tim



More information about the Fuego mailing list