Skip to content

Commit f4f5618

Browse files
committed
Add unit tests.
Modify mock ssh to return failures on a given host name ("fubar"). Modify unittests to pass when the test is expected to fail and does so with an expected non-zero status code.
1 parent cf59a06 commit f4f5618

File tree

12 files changed

+158
-35
lines changed

12 files changed

+158
-35
lines changed

agent/bench-scripts/test-bin/ssh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,24 @@ echo "$0 $*" >> $_testlog
55
if [[ "$4" == "netstat" && "$5" == "-tlpn" ]]; then
66
echo "tcp 0 0 0.0.0.0:21000 0.0.0.0:* LISTEN 5830/uperf"
77
fi
8+
9+
while true ;do
10+
case $1 in
11+
-o)
12+
shift 2
13+
;;
14+
-n)
15+
shift 1
16+
;;
17+
*)
18+
break
19+
;;
20+
esac
21+
done
22+
remote=$1
23+
24+
if [[ "$remote" == "fubar" ]] ;then
25+
exit 255
26+
else
27+
exit 0
28+
fi
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
+++ Running test-12 pbench-clear-tools
2+
removing tools-default/mpstat
3+
running . /opt/pbench-agent/profile; pbench-clear-tools --group default on fubar
4+
Removing the remote remote@fubar
5+
--- Finished test-12 pbench-clear-tools (status=1}
6+
+++ pbench tree state
7+
/var/tmp/pbench-test-utils/pbench
8+
/var/tmp/pbench-test-utils/pbench/tmp
9+
/var/tmp/pbench-test-utils/pbench/tools-default
10+
--- pbench tree state
11+
+++ pbench.log file contents
12+
grep: /var/tmp/pbench-test-utils/pbench/pbench.log: No such file or directory
13+
--- pbench.log file contents
14+
+++ test-execution.log file contents
15+
/var/tmp/pbench-test-utils/test-execution.log:/var/tmp/pbench-test-utils/opt/pbench-agent/unittest-scripts/ssh -o StrictHostKeyChecking=no -o ConnectTimeout=1 -n fubar . /opt/pbench-agent/profile; pbench-clear-tools --group default
16+
--- test-execution.log file contents
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
+++ Running test-13 pbench-postprocess-tools
2+
tar: This does not look like a tar archive
3+
tar: Exiting with failure status due to previous errors
4+
--- Finished test-13 pbench-postprocess-tools (status=2}
5+
+++ pbench tree state
6+
/var/tmp/pbench-test-utils/pbench
7+
/var/tmp/pbench-test-utils/pbench/pbench.log
8+
/var/tmp/pbench-test-utils/pbench/tmp
9+
/var/tmp/pbench-test-utils/pbench/tmp/tools-default
10+
/var/tmp/pbench-test-utils/pbench/tools-default
11+
/var/tmp/pbench-test-utils/pbench/tools-default/remote@fubar
12+
/var/tmp/pbench-test-utils/pbench/tools-default/remote@fubar:
13+
--- pbench tree state
14+
+++ pbench.log file contents
15+
/var/tmp/pbench-test-utils/pbench/pbench.log:[debug][1900-01-01T00:00:00.000000] [pbench-postprocess-tools]started: --dir=/var/tmp/pbench-test-utils/pbench/tmp --group=default --iteration=1
16+
/var/tmp/pbench-test-utils/pbench/pbench.log:[debug][1900-01-01T00:00:00.000000] [pbench-postprocess-tools]running this tool on fubar: ssh -o StrictHostKeyChecking=no -n fubar pbench-postprocess-tools --iteration=1 --group=default --dir=/var/tmp/pbench-test-utils/pbench/tmp
17+
/var/tmp/pbench-test-utils/pbench/pbench.log:[debug][1900-01-01T00:00:00.000000] [pbench-postprocess-tools]started: copying tool data ( MB) from fubar
18+
/var/tmp/pbench-test-utils/pbench/pbench.log:[debug][1900-01-01T00:00:00.000000] [pbench-postprocess-tools]copying tool data failed for remote fubar
19+
/var/tmp/pbench-test-utils/pbench/pbench.log:[debug][1900-01-01T00:00:00.000000] [pbench-postprocess-tools]completed:
20+
--- pbench.log file contents
21+
+++ test-execution.log file contents
22+
/var/tmp/pbench-test-utils/test-execution.log:/var/tmp/pbench-test-utils/opt/pbench-agent/unittest-scripts/ssh -o StrictHostKeyChecking=no -n fubar pbench-postprocess-tools --iteration=1 --group=default --dir=/var/tmp/pbench-test-utils/pbench/tmp
23+
/var/tmp/pbench-test-utils/test-execution.log:/var/tmp/pbench-test-utils/opt/pbench-agent/unittest-scripts/ssh -o StrictHostKeyChecking=no -n fubar du -sm /var/tmp/pbench-test-utils/pbench/tmp/tools-default
24+
/var/tmp/pbench-test-utils/test-execution.log:/var/tmp/pbench-test-utils/opt/pbench-agent/unittest-scripts/ssh -o StrictHostKeyChecking=no -n fubar cd /var/tmp/pbench-test-utils/pbench/tmp/tools-default && tar cf - *
25+
--- test-execution.log file contents
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
+++ Running test-11 pbench-register-tool-set
2+
--- Finished test-11 pbench-register-tool-set (status=4}
3+
+++ pbench tree state
4+
/var/tmp/pbench-test-utils/pbench
5+
/var/tmp/pbench-test-utils/pbench/pbench.log
6+
/var/tmp/pbench-test-utils/pbench/tmp
7+
/var/tmp/pbench-test-utils/pbench/tools-default
8+
/var/tmp/pbench-test-utils/pbench/tools-default/remote@fubar
9+
/var/tmp/pbench-test-utils/pbench/tools-default/remote@fubar:
10+
--- pbench tree state
11+
+++ pbench.log file contents
12+
/var/tmp/pbench-test-utils/pbench/pbench.log:[debug][1900-01-01T00:00:00.000000] tool_opts: --interval=3
13+
/var/tmp/pbench-test-utils/pbench/pbench.log:[debug][1900-01-01T00:00:00.000000] tool_opts[0]="--interval=3"; pbench-register-tool --name=mpstat --group=default $label_opt -- "${tool_opts[@]}" 2>&1
14+
/var/tmp/pbench-test-utils/pbench/pbench.log:[debug][1900-01-01T00:00:00.000000] tool_opts: --interval=3
15+
/var/tmp/pbench-test-utils/pbench/pbench.log:[debug][1900-01-01T00:00:00.000000] tool_opts[0]="--interval=3"; pbench-register-tool --name=vmstat --group=default $label_opt -- "${tool_opts[@]}" 2>&1
16+
/var/tmp/pbench-test-utils/pbench/pbench.log:[debug][1900-01-01T00:00:00.000000] tool_opts: --interval=3
17+
/var/tmp/pbench-test-utils/pbench/pbench.log:[debug][1900-01-01T00:00:00.000000] tool_opts[0]="--interval=3"; pbench-register-tool --name=iostat --group=default $label_opt -- "${tool_opts[@]}" 2>&1
18+
/var/tmp/pbench-test-utils/pbench/pbench.log:[debug][1900-01-01T00:00:00.000000] tool_opts: --record-opts=record -a --freq=100
19+
/var/tmp/pbench-test-utils/pbench/pbench.log:[debug][1900-01-01T00:00:00.000000] tool_opts[0]="--record-opts=record -a --freq=100"; pbench-register-tool --name=perf --group=default $label_opt -- "${tool_opts[@]}" 2>&1
20+
--- pbench.log file contents
21+
+++ test-execution.log file contents
22+
/var/tmp/pbench-test-utils/test-execution.log:/var/tmp/pbench-test-utils/opt/pbench-agent/unittest-scripts/ssh -o StrictHostKeyChecking=no fubar tool_opts[0]="--interval=3"; pbench-register-tool --name=mpstat --group=default -- "${tool_opts[@]}" 2>&1
23+
/var/tmp/pbench-test-utils/test-execution.log:/var/tmp/pbench-test-utils/opt/pbench-agent/unittest-scripts/ssh -o StrictHostKeyChecking=no fubar tool_opts[0]="--interval=3"; pbench-register-tool --name=vmstat --group=default -- "${tool_opts[@]}" 2>&1
24+
/var/tmp/pbench-test-utils/test-execution.log:/var/tmp/pbench-test-utils/opt/pbench-agent/unittest-scripts/ssh -o StrictHostKeyChecking=no fubar tool_opts[0]="--interval=3"; pbench-register-tool --name=iostat --group=default -- "${tool_opts[@]}" 2>&1
25+
/var/tmp/pbench-test-utils/test-execution.log:/var/tmp/pbench-test-utils/opt/pbench-agent/unittest-scripts/ssh -o StrictHostKeyChecking=no fubar tool_opts[0]="--record-opts=record -a --freq=100"; pbench-register-tool --name=perf --group=default -- "${tool_opts[@]}" 2>&1
26+
--- test-execution.log file contents

agent/util-scripts/gold/pbench-stop-tools/test-05.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
+++ Running test-05 pbench-stop-tools
22
[warn][1900-01-01T00:00:00.000000] Too many pids for turbostat: 123463 123464 123465 123466 123467 -- maybe old tools running? Use pbench-kill-tools.
3-
--- Finished test-05 pbench-stop-tools (status=0}
3+
--- Finished test-05 pbench-stop-tools (status=1}
44
+++ pbench tree state
55
/var/tmp/pbench-test-utils/pbench
66
/var/tmp/pbench-test-utils/pbench/pbench.log

agent/util-scripts/gold/pbench-stop-tools/test-06.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
+++ Running test-06 pbench-stop-tools
2-
--- Finished test-06 pbench-stop-tools (status=0}
2+
--- Finished test-06 pbench-stop-tools (status=1}
33
+++ pbench tree state
44
/var/tmp/pbench-test-utils/pbench
55
/var/tmp/pbench-test-utils/pbench/pbench.log

agent/util-scripts/pbench-postprocess-tools

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if [ $? -ne 0 ]; then
4040
printf -- "\t will store and process data\n"
4141
printf "\n"
4242
printf -- "\t-i str --iteration=num, num = a number representing the\n"
43-
printf -- "\t iteration data was collected for"
43+
printf -- "\t iteration data was collected for\n"
4444
exit 1
4545
fi
4646
eval set -- "$opts";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pbench/tools]
2+
default-tool-set = mpstat, vmstat, iostat
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--interval: 34

agent/util-scripts/samples/pbench-clear-tools/test-12/tools-default/remote@fubar

Whitespace-only changes.

0 commit comments

Comments
 (0)