commands/wc: Added new testcase to test wc
PATCH 1/2 commands/wc: Added new testcase to test wc
Test the basic functionality of wc(1) command.
--- runtest/commands | 1 + testcases/commands/wc/Makefile | 22 +++++++++++ testcases/commands/wc/wc01.sh | 87 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 testcases/commands/wc/Makefile create mode 100755 testcases/commands/wc/wc01.sh
runtest/commands +1 -0
@@ -41,3 +41,4 @@ mkfs01_ntfs mkfs01.sh -f ntfs mkswap01 mkswap01.sh which01 which01.sh lsmod01 lsmod01.sh +wc01 wc01.sh
testcases/commands/wc/Makefile new file +22 -0
@@ -0,0 +1,22 @@ +# +# Copyright (c) 2016 Fujitsu Ltd. +# Author:Xiao Yang <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +top_srcdir ?= ../../.. + +include $(top_srcdir)/include/mk/env_pre.mk + +INSTALL_TARGETS := wc01.sh + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/commands/wc/wc01.sh new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 2/2 commands/passwd: Added new testcase to test passwd
Test the basic functionality of passwd(1) command.
--- runtest/commands | 1 + testcases/commands/passwd/Makefile | 22 +++++ testcases/commands/passwd/passwd01.sh | 155 ++++++++++++++++++++++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 testcases/commands/passwd/Makefile create mode 100755 testcases/commands/passwd/passwd01.sh
runtest/commands +1 -0
@@ -42,3 +42,4 @@ mkswap01 mkswap01.sh which01 which01.sh lsmod01 lsmod01.sh wc01 wc01.sh +passwd01 passwd01.sh
testcases/commands/passwd/Makefile new file +22 -0
@@ -0,0 +1,22 @@ +# +# Copyright (c) 2016 Fujitsu Ltd. +# Author:Xiao Yang <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +top_srcdir ?= ../../.. + +include $(top_srcdir)/include/mk/env_pre.mk + +INSTALL_TARGETS := passwd01.sh + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/commands/passwd/passwd01.sh new file +155 -0
155 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 2/2 commands/passwd: Added new testcase to test passwd
Hi!
testcases/commands/passwd/passwd01.sh line 50
Quoted 4 lines
testcases/commands/passwd/passwd01.sh new file +4
-0+passwd_test() +{ + local opt=`echo "$2" | awk -F ' ' '{print $1}'` + local value=`echo "$2" | awk -F ' ' '{print $2}'`
This is ugly, why don't you just pass the option and value separately?
I.e.
...passwd_test "passwd" "-n" "1" "ltp_test"
...passwd_test "passwd" "-d" "" "ltp_test"
Quoted 12 lines
testcases/commands/passwd/passwd01.sh new file +12
-0+ local name=$3 + local pw_cmd="$1 $2 $3" + + eval $pw_cmd > temp 2>&1 + if [ $? -ne 0 ]; then + grep -q -E "unrecognized option|invalid option|unknown option" temp + if [ $? -eq 0 ]; then + tst_resm TCONF "$pw_cmd not supported" + else + tst_resm TFAIL "$pw_cmd failed" + fi + return
testcases/commands/passwd/passwd01.sh line 72
Quoted 10 lines
testcases/commands/passwd/passwd01.sh new file +10
-0+ fi + + if [ "$name" != "" ]; then + local pw=`grep "$name" /etc/shadow | awk -F ':' '{print $2}'` + local mod=`grep "$name" /etc/shadow | awk -F ':' '{print $3}'` + local min=`grep "$name" /etc/shadow | awk -F ':' '{print $4}'` + local max=`grep "$name" /etc/shadow | awk -F ':' '{print $5}'` + local war=`grep "$name" /etc/shadow | awk -F ':' '{print $6}'` + local ina=`grep "$name" /etc/shadow | awk -F ':' '{print $7}'` + fi
Hmm, I do not think that parsing /etc/shadow here is a good idea. As this only asserts that the configuration file was changed rather than testing if the system does what it should do.
For instance we should rather check that we can login without password after password was deleted with -d.
We should check that password we cannot login at all if account was locked, etc.
Quoted 42 lines
testcases/commands/passwd/passwd01.sh new file +42
-0+ case $opt in + -d|--delete) + if [ "$pw" != "" ]; then + tst_resm TFAIL "passwd failed with $opt option." + return + fi + ;; + -l|--lock) + echo "$pw" | grep -q "!!" > temp 2>&1 + if [ $? -ne 0 ]; then + tst_resm TFAIL "passwd failed with $opt option." + return + fi + ;; + -u|--unlock) + echo "$pw" | grep -q "!!" > temp 2>&1 + if [ $? -eq 0 ]; then + tst_resm TFAIL "passwd failed with $opt option." + return + fi + ;; + -n|--minimum) + if [ $min -ne $value ]; then + tst_resm TFAIL "passwd failed with $opt option." + return + fi + ;; + -x|--maximum) + if [ $max -ne $value ]; then + tst_resm TFAIL "passwd failed with $opt option." + return + fi + ;; + -w|--warning) + if [ $war -ne $value ]; then + tst_resm TFAIL "passwd failed with $opt option." + return + fi + ;; + -i|--inactive) + if [ $ina -ne $value ]; then + tst_resm TFAIL "passwd failed with $opt option."
testcases/commands/passwd/passwd01.sh line 125
Quoted 10 lines
testcases/commands/passwd/passwd01.sh new file +10
-0+ return + fi + ;; + -e|--expire) + if [ $mod -ne 0 ]; then + tst_resm TFAIL "passwd failed with $opt option." + return + fi + ;; + esac
This is ugly, why don't we rather write a function for each check and pass it as a parameter to the passwd_test.
i.e.
check_passwordless()
{
...
}passwd_test "passwd" "-d" "" ltp_test check_passwordless
and call it from the passwd_test as:
...
local check="$4"
...
if [ -n "$check" ]; then $check else tst_resm TPASS "passwd passed with $opt option." fi }
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/2 commands/wc: Added new testcase to test wc
In reply to Xiao YangHi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]