Skip to contentSkip to conversation

commans/sar: Add new testcases for sar

PATCH New Cui Bixuan 2 participants 3 messages Oct 23, 2015 – Oct 28, 2015

lore
Share & tools
lore

Cui Bixuan

author
#0 lore raw

PATCH 1/1 commans/sar: Add new testcases for sar

Add new testcases for sar

---
 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
runtest/commands +1 -0
index e5260ba..56a326b 100644
@@ -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
testcases/commands/sar/Makefile new file +29 -0
new file mode 100644
index 0000000..ebec180
@@ -0,0 +1,29 @@
+#
+#    commands/sar testcases Makefile.
+#
+#    Copyright (C) 2015, Cui Bixuan <[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.
+#
+#    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
testcases/commands/sar/sar_tests.sh new file +153 -0

153 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#1 lore raw

PATCH 1/1 commans/sar: Add new testcases for sar

Hi!

Quoted 9 lines
testcases/commands/sar/sar_tests.sh new file +9 -0
+TCID=sar01
+TST_TOTAL=19
+. test.sh
+
+setup()
+{
+	tst_check_cmds sar
+
+	tst_tmpdir

testcases/commands/sar/sar_tests.sh line 36

Quoted 10 lines
testcases/commands/sar/sar_tests.sh new file +10 -0
+}
+
+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.

testcases/commands/sar/sar_tests.sh line 42

Quoted 6 lines
testcases/commands/sar/sar_tests.sh new file +6 -0
+	if [ $? -ne 0 ]; then
+		tst_resm TFAIL "'$1' failed."
+		return
+	fi
+
+	grep $2 ${TCID}.temp >/dev/null

Grep has -q (quiet) switch.

testcases/commands/sar/sar_tests.sh line 47

Quoted 5 lines
testcases/commands/sar/sar_tests.sh new file +5 -0
+	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.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#2 lore raw

PATCH 1/1 commans/sar: Add new testcases for sar

Quoted 4 lines · Cyril Hrubis

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

Quoted 1 line