public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] commands/wc: Added new testcase to test wc
@ 2016-05-10 10:19 Xiao Yang
  2016-05-10 10:19 ` [LTP] [PATCH 2/2] commands/passwd: Added new testcase to test passwd Xiao Yang
  2016-05-16 13:31 ` [LTP] [PATCH 1/2] commands/wc: Added new testcase to test wc Cyril Hrubis
  0 siblings, 2 replies; 4+ messages in thread
From: Xiao Yang @ 2016-05-10 10:19 UTC (permalink / raw)
  To: ltp

Test the basic functionality of wc(1) command.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 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

diff --git a/runtest/commands b/runtest/commands
index db89424..5aced8b 100644
--- a/runtest/commands
+++ b/runtest/commands
@@ -41,3 +41,4 @@ mkfs01_ntfs mkfs01.sh -f ntfs
 mkswap01 mkswap01.sh
 which01 which01.sh
 lsmod01 lsmod01.sh
+wc01 wc01.sh
diff --git a/testcases/commands/wc/Makefile b/testcases/commands/wc/Makefile
new file mode 100644
index 0000000..6571074
--- /dev/null
+++ b/testcases/commands/wc/Makefile
@@ -0,0 +1,22 @@
+#
+#    Copyright (c) 2016 Fujitsu Ltd.
+#    Author:Xiao Yang <yangx.jy@cn.fujitsu.com>
+#
+#    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
diff --git a/testcases/commands/wc/wc01.sh b/testcases/commands/wc/wc01.sh
new file mode 100755
index 0000000..9bbb14d
--- /dev/null
+++ b/testcases/commands/wc/wc01.sh
@@ -0,0 +1,87 @@
+#!/bin/sh
+#
+# Copyright (c) 2016 Fujitsu Ltd.
+# Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+#
+# 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.
+#
+# Test wc command with some basic options.
+#
+
+TCID=wc01.sh
+TST_TOTAL=12
+. test.sh
+
+setup()
+{
+	tst_check_cmds wc
+
+	tst_tmpdir
+
+	TST_CLEANUP="cleanup"
+
+	echo "hello world" > ltp_wc
+
+	echo "This is a test" >> ltp_wc
+}
+
+cleanup()
+{
+	tst_rmdir
+}
+
+wc_test()
+{
+	local wc_opt=$1
+	local wc_file=$2
+	local std_out=$3
+
+	local wc_cmd="wc $wc_opt $wc_file"
+
+	eval $wc_cmd > temp 2>&1
+	if [ $? -ne 0 ]; then
+		grep -q -E "unknown option|invalid option" temp
+		if [ $? -eq 0 ]; then
+			tst_resm TCONF "$wc_cmd not supported."
+		else
+			tst_resm TFAIL "$wc_cmd failed."
+		fi
+		return
+	fi
+
+	if [ $# -gt 1 ]; then
+		local act_out=`cat temp | awk '{printf $1}'`
+		if [ $act_out -ne $std_out ]; then
+			tst_resm TFAIL "$wc_cmd got mismatched data."
+			return
+		fi
+	fi
+
+	tst_resm TPASS "wc passed with $wc_opt option."
+}
+
+
+setup
+
+wc_test "-c" ltp_wc 27
+wc_test "--bytes" ltp_wc 27
+wc_test "-l" ltp_wc 2
+wc_test "--lines" ltp_wc 2
+wc_test "-L" ltp_wc 14
+wc_test "--max-line-length" ltp_wc 14
+wc_test "-w" ltp_wc 6
+wc_test "--words" ltp_wc 6
+wc_test "-m" ltp_wc 27
+wc_test "--chars" ltp_wc 27
+wc_test "--help"
+wc_test "--version"
+
+tst_exit
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [LTP] [PATCH 2/2] commands/passwd: Added new testcase to test passwd
  2016-05-10 10:19 [LTP] [PATCH 1/2] commands/wc: Added new testcase to test wc Xiao Yang
@ 2016-05-10 10:19 ` Xiao Yang
  2016-05-16 14:05   ` Cyril Hrubis
  2016-05-16 13:31 ` [LTP] [PATCH 1/2] commands/wc: Added new testcase to test wc Cyril Hrubis
  1 sibling, 1 reply; 4+ messages in thread
From: Xiao Yang @ 2016-05-10 10:19 UTC (permalink / raw)
  To: ltp

Test the basic functionality of passwd(1) command.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 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

diff --git a/runtest/commands b/runtest/commands
index 5aced8b..359b1ef 100644
--- a/runtest/commands
+++ b/runtest/commands
@@ -42,3 +42,4 @@ mkswap01 mkswap01.sh
 which01 which01.sh
 lsmod01 lsmod01.sh
 wc01 wc01.sh
+passwd01 passwd01.sh
diff --git a/testcases/commands/passwd/Makefile b/testcases/commands/passwd/Makefile
new file mode 100644
index 0000000..3bdd21c
--- /dev/null
+++ b/testcases/commands/passwd/Makefile
@@ -0,0 +1,22 @@
+#
+#    Copyright (c) 2016 Fujitsu Ltd.
+#    Author:Xiao Yang <yangx.jy@cn.fujitsu.com>
+#
+#    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
diff --git a/testcases/commands/passwd/passwd01.sh b/testcases/commands/passwd/passwd01.sh
new file mode 100755
index 0000000..d70f402
--- /dev/null
+++ b/testcases/commands/passwd/passwd01.sh
@@ -0,0 +1,155 @@
+#!/bin/sh
+#
+# Copyright (c) 2016 Fujitsu Ltd.
+# Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+#
+# 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.
+#
+# Test passwd command with some basic options.
+#
+
+TCID=passwd01.sh
+TST_TOTAL=22
+. test.sh
+
+setup()
+{
+	tst_check_cmds useradd userdel passwd
+
+	tst_tmpdir
+
+	TST_CLEANUP="cleanup"
+
+	useradd ltp_test
+	if [ $? -ne 0 ] && [ ! -d /home/ltp_test ]; then
+		tst_brkm TBROK "useradd failed"
+	fi
+}
+
+cleanup()
+{
+	userdel -r ltp_test
+	if [ $? -ne 0 ] && [ -d /home/ltp_test ]; then
+		tst_brkm TBROK "userdel -r failed"
+	fi
+
+	tst_rmdir
+}
+
+passwd_test()
+{
+	local opt=`echo "$2" | awk -F ' ' '{print $1}'`
+	local value=`echo "$2" | awk -F ' ' '{print $2}'`
+	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
+	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
+
+	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."
+				return
+			fi
+			;;
+		-e|--expire)
+			if [ $mod -ne 0 ]; then
+				tst_resm TFAIL "passwd failed with $opt option."
+				return
+			fi
+			;;
+	esac
+
+	tst_resm TPASS "passwd passed with $opt option."
+}
+
+setup
+
+passwd_test "passwd" "-d" ltp_test
+passwd_test "passwd" "--delete" ltp_test
+passwd_test "echo test | passwd" "--stdin" ltp_test
+passwd_test "passwd" "-l" ltp_test
+passwd_test "passwd" "-u" ltp_test
+passwd_test "passwd" "--lock" ltp_test
+passwd_test "passwd" "--unlock" ltp_test
+passwd_test "passwd" "-n 1" ltp_test
+passwd_test "passwd" "--minimum 2" ltp_test
+passwd_test "passwd" "-x 11" ltp_test
+passwd_test "passwd" "--maximum 12" ltp_test
+passwd_test "passwd" "-w 5" ltp_test
+passwd_test "passwd" "--warning 6" ltp_test
+passwd_test "passwd" "-i 15" ltp_test
+passwd_test "passwd" "--inactive 16" ltp_test
+passwd_test "passwd" "-e " ltp_test
+passwd_test "passwd" "--expire" ltp_test
+passwd_test "passwd" "-S" ltp_test
+passwd_test "passwd" "--status" ltp_test
+passwd_test "passwd" "--help"
+passwd_test "passwd" "-?"
+passwd_test "passwd" "--usage"
+
+tst_exit
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [LTP] [PATCH 1/2] commands/wc: Added new testcase to test wc
  2016-05-10 10:19 [LTP] [PATCH 1/2] commands/wc: Added new testcase to test wc Xiao Yang
  2016-05-10 10:19 ` [LTP] [PATCH 2/2] commands/passwd: Added new testcase to test passwd Xiao Yang
@ 2016-05-16 13:31 ` Cyril Hrubis
  1 sibling, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2016-05-16 13:31 UTC (permalink / raw)
  To: ltp

Hi!
Pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [LTP] [PATCH 2/2] commands/passwd: Added new testcase to test passwd
  2016-05-10 10:19 ` [LTP] [PATCH 2/2] commands/passwd: Added new testcase to test passwd Xiao Yang
@ 2016-05-16 14:05   ` Cyril Hrubis
  0 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2016-05-16 14:05 UTC (permalink / raw)
  To: ltp

Hi!
> +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"

> +	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
> +	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.

> +	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."
> +				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
}

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-05-16 14:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-10 10:19 [LTP] [PATCH 1/2] commands/wc: Added new testcase to test wc Xiao Yang
2016-05-10 10:19 ` [LTP] [PATCH 2/2] commands/passwd: Added new testcase to test passwd Xiao Yang
2016-05-16 14:05   ` Cyril Hrubis
2016-05-16 13:31 ` [LTP] [PATCH 1/2] commands/wc: Added new testcase to test wc Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox