fs/binfmt_misc_lib.sh: Add common remove_binary_type()
PATCH 1/2 fs/binfmt_misc_lib.sh: Add common remove_binary_type()
1) Add common remove_binary_type() so that we can remove the registered binary type by it.
2) Take use of remove_binary_type() in binfmt_misc01.sh.
--- testcases/kernel/fs/binfmt_misc/binfmt_misc01.sh | 7 ++----- testcases/kernel/fs/binfmt_misc/binfmt_misc_lib.sh | 9 +++++++++ 2 files changed, 11 insertions(+), 5 deletions(-)
testcases/kernel/fs/binfmt_misc/binfmt_misc01.sh +2 -5
@@ -42,11 +42,8 @@ verify_binfmt_misc() cat "$mntpoint/$name" >/dev/null 2>&1 tst_res TFAIL "Register a binary type successfully" - if [ -f "$mntpoint/$name" ]; then - (echo -1 >"$mntpoint/$name") 2>/dev/null - [ $? -ne 0 -o -f "$mntpoint/$name" ] && \ - tst_res TWARN "Failed to remove a binary type" - fi + [ -f "$mntpoint/$name" ] && \ + remove_binary_type "$mntpoint/$name" } do_test()
testcases/kernel/fs/binfmt_misc/binfmt_misc_lib.sh +9 -0
@@ -17,6 +17,15 @@ rmod_binfmt_misc=0 umount_binfmt_misc=0 binfmt_misc_mntpoint="ltp_binfmt_misc" +remove_binary_type() +{ + local name=$1 + + (echo -1 >"$name") 2>/dev/null + [ $? -ne 0 -o -f "$name" ] && \ + tst_res TWARN "Fail to remove a binary type" +} + get_binfmt_misc_mntpoint() { local mntpoint
Signature · 1 line
1.8.3.1
PATCH 2/2 fs/binfmt_misc02.sh: Add new test for basic functionality
Register a new binary type and then check if binfmt_misc recognises the binary type in some conditions.
--- runtest/fs | 1 + testcases/kernel/fs/binfmt_misc/Makefile | 4 +- testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh | 107 +++++++++++++++++++++ testcases/kernel/fs/binfmt_misc/datafiles/Makefile | 13 +++ .../kernel/fs/binfmt_misc/datafiles/file.extension | 1 + .../kernel/fs/binfmt_misc/datafiles/file.magic | 1 + 6 files changed, 125 insertions(+), 2 deletions(-) create mode 100755 testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh create mode 100644 testcases/kernel/fs/binfmt_misc/datafiles/Makefile create mode 100755 testcases/kernel/fs/binfmt_misc/datafiles/file.extension create mode 100755 testcases/kernel/fs/binfmt_misc/datafiles/file.magic
runtest/fs +1 -0
@@ -84,3 +84,4 @@ isofs isofs.sh fs_fill fs_fill binfmt_misc01 binfmt_misc01.sh +binfmt_misc02 binfmt_misc02.sh
testcases/kernel/fs/binfmt_misc/Makefile +2 -2
@@ -7,6 +7,6 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/env_pre.mk -INSTALL_TARGETS := binfmt_misc01.sh binfmt_misc_lib.sh +INSTALL_TARGETS := binfmt_misc01.sh binfmt_misc02.sh binfmt_misc_lib.sh -include $(top_srcdir)/include/mk/generic_leaf_target.mk +include $(top_srcdir)/include/mk/generic_trunk_target.mk
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh new file +107 -0
107 lines not on this page · raw message
testcases/kernel/fs/binfmt_misc/datafiles/Makefile new file +13 -0
@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +# Author: Xiao Yang <[email protected]> + +top_srcdir ?= ../../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk + +INSTALL_DIR := testcases/data/binfmt_misc02 +INSTALL_TARGETS := file.extension file.magic + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/fs/binfmt_misc/datafiles/file.extension new file +1 -0
@@ -0,0 +1 @@ +print "This is test for extension\n"
testcases/kernel/fs/binfmt_misc/datafiles/file.magic new file +1 -0
@@ -0,0 +1 @@ + print "This is test for magic\n"
Signature · 1 line
1.8.3.1
PATCH 2/2 fs/binfmt_misc02.sh: Add new test for basic functionality
Hi!
Quoted 2 lines
Register a new binary type and then check if
binfmt_miscrecognises the binary type in some conditions.
Generally looks good, couple of comments below.
Quoted 54 lines
Signed-off-by Xiao Yang <[email protected]>--- runtest/fs | 1 + testcases/kernel/fs/binfmt_misc/Makefile | 4 +- testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh | 107 +++++++++++++++++++++ testcases/kernel/fs/binfmt_misc/datafiles/Makefile | 13 +++ .../kernel/fs/binfmt_misc/datafiles/file.extension | 1 + .../kernel/fs/binfmt_misc/datafiles/file.magic | 1 + 6 files changed, 125 insertions(+), 2 deletions(-) create mode 100755 testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh create mode 100644 testcases/kernel/fs/binfmt_misc/datafiles/Makefile create mode 100755 testcases/kernel/fs/binfmt_misc/datafiles/file.extension create mode 100755 testcases/kernel/fs/binfmt_misc/datafiles/file.magicruntest/fs +1
-0@@ -84,3 +84,4 @@ isofs isofs.sh fs_fill fs_fill binfmt_misc01 binfmt_misc01.sh +binfmt_misc02 binfmt_misc02.shtestcases/kernel/fs/binfmt_misc/Makefile +2
-2@@ -7,6 +7,6 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/env_pre.mk -INSTALL_TARGETS := binfmt_misc01.sh binfmt_misc_lib.sh +INSTALL_TARGETS := binfmt_misc01.sh binfmt_misc02.sh binfmt_misc_lib.sh -include $(top_srcdir)/include/mk/generic_leaf_target.mk +include $(top_srcdir)/include/mk/generic_trunk_target.mktestcases/kernel/fs/binfmt_misc/binfmt_misc02.sh new file +12
-0@@ -0,0 +1,107 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +# Author: Xiao Yang <[email protected]> +# +# Description: +# Register a new binary type and then check if binfmt_misc +# recognises the binary type in some conditions. +# 1) binfmt_misc should recognise the binary type when extension +# or magic is matched. +# 2) binfmt_misc should not recognise the binary type when extension
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh line 22
Quoted 10 lines
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh new file +10
-0+# or magic is mismatched. +# 3) binfmt_misc should not recognise the binary type when it is +# disabled. +# +# Note: +# We use various delimiteris to register a new binary type. + +TST_CNT=8 +TST_TESTFUNC=do_test +TST_NEEDS_CMDS="perl"
I wonder if we can avoid perl dependency by (mis)using cat instead of proper interpreter.
Quoted 21 lines
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh new file +21
-0+. binfmt_misc_lib.sh + +expect_recognised() +{ + local file=$1 + local string=$2 + + eval $file >temp 2>&1 + if [ $? -eq 0 ] && grep -q "$string" temp; then + tst_res TPASS "Register and recognise a binary type successfully" + else + tst_res TFAIL "Fail to recognise a binary type" + fi +} + +expect_unrecognised() +{ + local file=$1 + local string=$2 + + eval $file >temp 2>&1
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh line 54
Quoted 10 lines
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh new file +10
-0+ if [ $? -ne 0 ] && ! grep -q "$string" temp; then + tst_res TPASS "Fail to recognise a binary type" + else + tst_res TFAIL "Recognise a binary type successfully" + fi +} + +verify_binfmt_misc() +{ + local delimiter=${1:0:1}
^ This is bashism should be replaced for example with $(echo "$a" | head -c1)
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh line 58
Quoted 4 lines
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh new file +4
-0+ local name=$(echo "$1" | awk -F $delimiter '{print $2}') + local ttype=$(echo "$1" | awk -F $delimiter '{print $3}') + local tfile=$2 + local disabled=$3
Can't we just run each test twice once with enabled and once with disabled binfmt handler?
Quoted 87 lines
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh new file +49
-0+ local mntpoint=$(get_binfmt_misc_mntpoint) + + (echo "$1" >"$mntpoint/register") 2>/dev/null + if [ $? -ne 0 -o ! -f "$mntpoint/$name" ]; then + tst_res TFAIL "Fail to register a binary type" + return + fi + + [ "$ttype" = "E" ] && local tstring="This is test for extension" + [ "$ttype" = "M" ] && local tstring="This is test for magic" + + if [ "$disabled" = "1" ]; then + (echo 0 >"$mntpoint/$name") 2>/dev/null + if [ $? -ne 0 ] || grep -q enable "$mntpoint/$name"; then + remove_binary_type "$mntpoint/$name" + tst_res TFAIL "Fail to disable a binary type" + return + fi + fi + + [ -z "$disabled" ] && expect_recognised "$tfile" "$tstring" + [ -n "$disabled" ] && expect_unrecognised "$tfile" "$tstring" + + remove_binary_type "$mntpoint/$name" +} + +do_test() +{ + case $1 in + 1) verify_binfmt_misc ":textension:E::extension::$(which perl):" \ + "$TST_DATAROOT/file.extension";; + 2) verify_binfmt_misc ":tmagic:M:1:print::$(which perl):" \ + "$TST_DATAROOT/file.magic";; + 3) verify_binfmt_misc ".textension.E..extension..$(which perl)." \ + "$TST_DATAROOT/file.extension";; + 4) verify_binfmt_misc ",tmagic,M,1,print,,$(which perl)," \ + "$TST_DATAROOT/file.magic";; + 5) verify_binfmt_misc ":textension:E::ltp::$(which perl):" \ + "$TST_DATAROOT/file.extension" "0";; + 6) verify_binfmt_misc ":tmagic:M:0:print::$(which perl):" \ + "$TST_DATAROOT/file.magic" "0";; + 7) verify_binfmt_misc ":textension:E::extension::$(which perl):" \ + "$TST_DATAROOT/file.extension" "1";; + 8) verify_binfmt_misc ":tmagic:M:1:print::$(which perl):" \ + "$TST_DATAROOT/file.magic" "1";; + esac +} + +tst_runtestcases/kernel/fs/binfmt_misc/datafiles/Makefile new file +13
-0@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +# Author: Xiao Yang <[email protected]> + +top_srcdir ?= ../../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk + +INSTALL_DIR := testcases/data/binfmt_misc02 +INSTALL_TARGETS := file.extension file.magic + +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/fs/binfmt_misc/datafiles/file.extension new file +1
-0@@ -0,0 +1 @@ +print "This is test for extension\n"testcases/kernel/fs/binfmt_misc/datafiles/file.magic new file +1
-0@@ -0,0 +1 @@ + print "This is test for magic\n"Signature · 1 line
1.8.3.1
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/2 fs/binfmt_misc02.sh: Add new test for basic functionality
Quoted 63 lines · Cyril Hrubis
Hi!
Quoted 2 lines
Register a new binary type and then check if
binfmt_miscrecognises the binary type in some conditions.Generally looks good, couple of comments below.
Quoted 58 lines
Signed-off-by Xiao Yang<[email protected]>--- runtest/fs | 1 + testcases/kernel/fs/binfmt_misc/Makefile | 4 +- testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh | 107 +++++++++++++++++++++ testcases/kernel/fs/binfmt_misc/datafiles/Makefile | 13 +++ .../kernel/fs/binfmt_misc/datafiles/file.extension | 1 + .../kernel/fs/binfmt_misc/datafiles/file.magic | 1 + 6 files changed, 125 insertions(+), 2 deletions(-)create mode 100755
testcases/kernel/fs/binfmt_misc/binfmt_misc02.shcreate mode 100644 testcases/kernel/fs/binfmt_misc/datafiles/Makefile create mode 100755 testcases/kernel/fs/binfmt_misc/datafiles/file.extension create mode 100755 testcases/kernel/fs/binfmt_misc/datafiles/file.magicruntest/fs +1
-0@@ -84,3 +84,4 @@ isofs isofs.sh fs_fill fs_fill binfmt_misc01 binfmt_misc01.sh +binfmt_misc02 binfmt_misc02.shtestcases/kernel/fs/binfmt_misc/Makefile +2
-2@@ -7,6 +7,6 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/env_pre.mk -INSTALL_TARGETS := binfmt_misc01.sh binfmt_misc_lib.sh +INSTALL_TARGETS := binfmt_misc01.sh binfmt_misc02.sh binfmt_misc_lib.sh -include $(top_srcdir)/include/mk/generic_leaf_target.mk +include $(top_srcdir)/include/mk/generic_trunk_target.mktestcases/kernel/fs/binfmt_misc/binfmt_misc02.sh new file +16
-0@@ -0,0 +1,107 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +# Author: Xiao Yang<[email protected]> +# +# Description: +# Register a new binary type and then check if binfmt_misc +# recognises the binary type in some conditions. +# 1) binfmt_misc should recognise the binary type when extension +# or magic is matched. +# 2) binfmt_misc should not recognise the binary type when extension +# or magic is mismatched. +# 3) binfmt_misc should not recognise the binary type when it is +# disabled. +#
Quoted 8 lines
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh line 22
Quoted 6 lines
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh new file +6
-0+# Note: +# We use various delimiteris to register a new binary type. + +TST_CNT=8 +TST_TESTFUNC=do_test +TST_NEEDS_CMDS="perl"I wonder if we can avoid perl dependency by (mis)using cat instead of proper interpreter.
Hi Cyril,
Yes, we can use cat instead. :-)
Quoted 35 lines
Quoted 21 lines
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh new file +21
-0+. binfmt_misc_lib.sh + +expect_recognised() +{ + local file=$1 + local string=$2 + + eval $file>temp 2>&1 + if [ $? -eq 0 ]&& grep -q "$string" temp; then + tst_res TPASS "Register and recognise a binary type successfully" + else + tst_res TFAIL "Fail to recognise a binary type" + fi +} + +expect_unrecognised() +{ + local file=$1 + local string=$2 + + eval $file>temp 2>&1testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh line 54
Quoted 10 lines
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh new file +10
-0+ if [ $? -ne 0 ]&& ! grep -q "$string" temp; then + tst_res TPASS "Fail to recognise a binary type" + else + tst_res TFAIL "Recognise a binary type successfully" + fi +} + +verify_binfmt_misc() +{ + local delimiter=${1:0:1}^ This is bashism should be replaced for example with $(echo "$a" | head -c1)
Quoted 6 lines
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh line 58
Quoted 4 lines
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh new file +4
-0+ local name=$(echo "$1" | awk -F $delimiter '{print $2}') + local ttype=$(echo "$1" | awk -F $delimiter '{print $3}') + local tfile=$2 + local disabled=$3Can't we just run each test twice once with enabled and once with disabled binfmt handler?
For matched binary types, we can run test twice by enabled and disabled binfmt handler.
For mismatched binary types, it seems enough to run test once by enabled binfmt handler.
Best Regards,
Xiao Yang
Quoted 87 lines
Quoted 87 lines
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh new file +49
-0+ local mntpoint=$(get_binfmt_misc_mntpoint) + + (echo "$1">"$mntpoint/register") 2>/dev/null + if [ $? -ne 0 -o ! -f "$mntpoint/$name" ]; then + tst_res TFAIL "Fail to register a binary type" + return + fi + + [ "$ttype" = "E" ]&& local tstring="This is test for extension" + [ "$ttype" = "M" ]&& local tstring="This is test for magic" + + if [ "$disabled" = "1" ]; then + (echo 0>"$mntpoint/$name") 2>/dev/null + if [ $? -ne 0 ] || grep -q enable "$mntpoint/$name"; then + remove_binary_type "$mntpoint/$name" + tst_res TFAIL "Fail to disable a binary type" + return + fi + fi + + [ -z "$disabled" ]&& expect_recognised "$tfile" "$tstring" + [ -n "$disabled" ]&& expect_unrecognised "$tfile" "$tstring" + + remove_binary_type "$mntpoint/$name" +} + +do_test() +{ + case $1 in + 1) verify_binfmt_misc ":textension:E::extension::$(which perl):" \ + "$TST_DATAROOT/file.extension";; + 2) verify_binfmt_misc ":tmagic:M:1:print::$(which perl):" \ + "$TST_DATAROOT/file.magic";; + 3) verify_binfmt_misc ".textension.E..extension..$(which perl)." \ + "$TST_DATAROOT/file.extension";; + 4) verify_binfmt_misc ",tmagic,M,1,print,,$(which perl)," \ + "$TST_DATAROOT/file.magic";; + 5) verify_binfmt_misc ":textension:E::ltp::$(which perl):" \ + "$TST_DATAROOT/file.extension" "0";; + 6) verify_binfmt_misc ":tmagic:M:0:print::$(which perl):" \ + "$TST_DATAROOT/file.magic" "0";; + 7) verify_binfmt_misc ":textension:E::extension::$(which perl):" \ + "$TST_DATAROOT/file.extension" "1";; + 8) verify_binfmt_misc ":tmagic:M:1:print::$(which perl):" \ + "$TST_DATAROOT/file.magic" "1";; + esac +} + +tst_runtestcases/kernel/fs/binfmt_misc/datafiles/Makefile new file +13
-0@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +# Author: Xiao Yang<[email protected]> + +top_srcdir ?= ../../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk + +INSTALL_DIR := testcases/data/binfmt_misc02 +INSTALL_TARGETS := file.extension file.magic + +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/fs/binfmt_misc/datafiles/file.extension new file +1
-0@@ -0,0 +1 @@ +print "This is test for extension\n"testcases/kernel/fs/binfmt_misc/datafiles/file.magic new file +1
-0@@ -0,0 +1 @@ + print "This is test for magic\n"Signature · 1 line
1.8.3.1
PATCH v2 2/2 fs/binfmt_misc02.sh: Add new test for basic functionality
In reply to Cyril HrubisRegister a new binary type and then check if binfmt_misc recognises the binary type in some conditions.
--- runtest/fs | 1 + testcases/kernel/fs/binfmt_misc/Makefile | 4 +- testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh | 107 +++++++++++++++++++++ testcases/kernel/fs/binfmt_misc/datafiles/Makefile | 13 +++ .../kernel/fs/binfmt_misc/datafiles/file.extension | 1 + .../kernel/fs/binfmt_misc/datafiles/file.magic | 1 + 6 files changed, 125 insertions(+), 2 deletions(-) create mode 100755 testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh create mode 100644 testcases/kernel/fs/binfmt_misc/datafiles/Makefile create mode 100755 testcases/kernel/fs/binfmt_misc/datafiles/file.extension create mode 100755 testcases/kernel/fs/binfmt_misc/datafiles/file.magic
runtest/fs +1 -0
@@ -84,3 +84,4 @@ isofs isofs.sh fs_fill fs_fill binfmt_misc01 binfmt_misc01.sh +binfmt_misc02 binfmt_misc02.sh
testcases/kernel/fs/binfmt_misc/Makefile +2 -2
@@ -7,6 +7,6 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/env_pre.mk -INSTALL_TARGETS := binfmt_misc01.sh binfmt_misc_lib.sh +INSTALL_TARGETS := binfmt_misc01.sh binfmt_misc02.sh binfmt_misc_lib.sh -include $(top_srcdir)/include/mk/generic_leaf_target.mk +include $(top_srcdir)/include/mk/generic_trunk_target.mk
testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh new file +107 -0
107 lines not on this page · raw message
testcases/kernel/fs/binfmt_misc/datafiles/Makefile new file +13 -0
@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +# Author: Xiao Yang <[email protected]> + +top_srcdir ?= ../../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk + +INSTALL_DIR := testcases/data/binfmt_misc02 +INSTALL_TARGETS := file.extension file.magic + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/fs/binfmt_misc/datafiles/file.extension new file +1 -0
@@ -0,0 +1 @@ +This is test for extension
testcases/kernel/fs/binfmt_misc/datafiles/file.magic new file +1 -0
@@ -0,0 +1 @@ + This is test for magic
Signature · 1 line
1.8.3.1
PATCH v2 2/2 fs/binfmt_misc02.sh: Add new test for basic functionality
Hi!
Applied, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]