* [LTP] [PATCH] commans/sar: Add new testcases for sar
@ 2015-10-23 1:08 Cui Bixuan
2015-10-26 16:08 ` Cyril Hrubis
0 siblings, 1 reply; 3+ messages in thread
From: Cui Bixuan @ 2015-10-23 1:08 UTC (permalink / raw)
To: ltp
Add new testcases for sar
Signed-off-by: Cui Bixuan <cuibixuan@huawei.com>
---
runtest/commands | 1 +
testcases/commands/sar/Makefile | 29 +++++++
testcases/commands/sar/sar_tests.sh | 153 +++++++++++++++++++++++++++++++++++
3 files changed, 183 insertions(+), 0 deletions(-)
create mode 100644 testcases/commands/sar/Makefile
create mode 100755 testcases/commands/sar/sar_tests.sh
diff --git a/runtest/commands b/runtest/commands
index e5260ba..56a326b 100644
--- a/runtest/commands
+++ b/runtest/commands
@@ -16,6 +16,7 @@ cp_tests01 cp_tests.sh
ln_tests01 ln_tests.sh
mkdir_tests01 mkdir_tests.sh
mv_tests01 mv_tests.sh
+sar01 sar_tests.sh
size01 size01
sssd01 sssd01
sssd02 sssd02
diff --git a/testcases/commands/sar/Makefile b/testcases/commands/sar/Makefile
new file mode 100644
index 0000000..ebec180
--- /dev/null
+++ b/testcases/commands/sar/Makefile
@@ -0,0 +1,29 @@
+#
+# commands/sar testcases Makefile.
+#
+# Copyright (C) 2015, Cui Bixuan <cuibixuan@huawei.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.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+top_srcdir ?= ../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS := sar_tests.sh
+
+MAKE_TARGETS :=
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/commands/sar/sar_tests.sh b/testcases/commands/sar/sar_tests.sh
new file mode 100755
index 0000000..afc9cc7
--- /dev/null
+++ b/testcases/commands/sar/sar_tests.sh
@@ -0,0 +1,153 @@
+#!/bin/sh
+#
+# Copyright (c) 2015 Cui Bixuan <cuibixuan@huawei.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 sar command with some basic options.
+#
+
+TCID=sar01
+TST_TOTAL=19
+. test.sh
+
+setup()
+{
+ tst_check_cmds sar
+
+ tst_tmpdir
+}
+
+cleanup()
+{
+ tst_rmdir
+}
+
+sar_test()
+{
+ $1 >${TCID}.temp 2>&1
+ if [ $? -ne 0 ]; then
+ tst_resm TFAIL "'$1' failed."
+ return
+ fi
+
+ grep $2 ${TCID}.temp >/dev/null
+ if [ $? -eq 0 ]; then
+ tst_resm TPASS "'$1' passed."
+ else
+ tst_resm TFAIL "'$1' failed."
+ fi
+}
+
+test1()
+{
+ sar_test "sar -A 1 1" "CPU"
+}
+
+test2()
+{
+ sar_test "sar -b 1 1" "tps"
+}
+
+test3()
+{
+ sar_test "sar -B 1 1" "pgpgin"
+}
+
+test4()
+{
+ sar_test "sar -C 1 1" "CPU"
+}
+
+test5()
+{
+ sar_test "sar -d 1 1" "tps"
+}
+
+test6()
+{
+ sar_test "sar -p 1 1" "user"
+}
+
+test7()
+{
+ sar_test "sar -q 1 1" "plist-sz"
+}
+
+test8()
+{
+ sar_test "sar -r 1 1" "kbmemfree"
+}
+
+test9()
+{
+ sar_test "sar -R 1 1" "frmpg"
+}
+
+test10()
+{
+ sar_test "sar -S 1 1" "kbswpfree"
+}
+
+test11()
+{
+ sar_test "sar -t 1 1" "CPU"
+}
+
+test12()
+{
+ sar_test "sar -u ALL 1 1" "CPU"
+}
+
+test13()
+{
+ sar_test "sar -u -v 1 1" "CPU"
+}
+
+test14()
+{
+ sar_test "sar -u -w 1 1" "CPU"
+}
+
+test15()
+{
+ sar_test "sar -u -W 1 1" "CPU"
+}
+
+test16()
+{
+ sar_test "sar -u -y 1 1" "CPU"
+}
+
+test17()
+{
+ sar_test "sar -I ALL 1 1" "INTR"
+}
+
+test18()
+{
+ sar_test "sar -P ALL 1 1" "CPU"
+}
+
+test19()
+{
+ sar_test "sar -A 1 1 -o sar_tmpfile" "CPU"
+}
+
+setup
+TST_CLEANUP="cleanup"
+
+for i in $(seq 1 ${TST_TOTAL})
+do
+ test$i
+done
+
+tst_exit
--
1.6.0.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [LTP] [PATCH] commans/sar: Add new testcases for sar
2015-10-23 1:08 [LTP] [PATCH] commans/sar: Add new testcases for sar Cui Bixuan
@ 2015-10-26 16:08 ` Cyril Hrubis
2015-10-28 3:56 ` Cui Bixuan
0 siblings, 1 reply; 3+ messages in thread
From: Cyril Hrubis @ 2015-10-26 16:08 UTC (permalink / raw)
To: ltp
Hi!
> +TCID=sar01
> +TST_TOTAL=19
> +. test.sh
> +
> +setup()
> +{
> + tst_check_cmds sar
> +
> + tst_tmpdir
> +}
> +
> +cleanup()
> +{
> + tst_rmdir
> +}
> +
> +sar_test()
> +{
> + $1 >${TCID}.temp 2>&1
Since we call tst_tmpdir() in setup we are guaranteed to be executed in
unique temorary directory. So we can just do:
$1 >temp 2>&1
And we do not need to worry about some other test rewriting our file.
> + if [ $? -ne 0 ]; then
> + tst_resm TFAIL "'$1' failed."
> + return
> + fi
> +
> + grep $2 ${TCID}.temp >/dev/null
Grep has -q (quiet) switch.
> + if [ $? -eq 0 ]; then
> + tst_resm TPASS "'$1' passed."
> + else
> + tst_resm TFAIL "'$1' failed."
> + fi
Grepping one word is pretty loose criteria for pass/fail for a program
that actually prints several pages of statistics.
A few things that can be done here are:
* Number of cpus is detected correctly
* The CPU load sums to 100%
More complicated tests can also do:
* Run a program with bussy loop on a background and check that
it consumes CPU cycles (load at least 100/NCPU over all cpus)
* Run a program that reads and writes files on background
and check that corresponding I/O statistics are reasonable
* ...
Getting this right would require substantial amount of effort, but
as this test is now it's not much useful as it would pass even if sar
was broken really badly.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 3+ messages in thread
* [LTP] [PATCH] commans/sar: Add new testcases for sar
2015-10-26 16:08 ` Cyril Hrubis
@ 2015-10-28 3:56 ` Cui Bixuan
0 siblings, 0 replies; 3+ messages in thread
From: Cui Bixuan @ 2015-10-28 3:56 UTC (permalink / raw)
To: ltp
On 2015/10/27 0:08, Cyril Hrubis wrote:
>
> Getting this right would require substantial amount of effort, but
> as this test is now it's not much useful as it would pass even if sar
> was broken really badly.
Yes, Maybe I should think about other ways.
Thank you very much
Cui Bixuan
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-10-28 3:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-23 1:08 [LTP] [PATCH] commans/sar: Add new testcases for sar Cui Bixuan
2015-10-26 16:08 ` Cyril Hrubis
2015-10-28 3:56 ` Cui Bixuan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox