annotate tests/pgrep.test @ 1753:0f940c4f9658 draft

Promote runcon to android (and add an android menu).
author Rob Landley <rob@landley.net>
date Mon, 23 Mar 2015 13:45:47 -0500
parents 8700cbe1cb29
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1377
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
1 #!/bin/bash
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
2
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
3 # Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
4 # Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
5
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
6 #cleaning 'yes' processes
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
7 killall yes >/dev/null 2>&1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
8
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
9 [ -f testing.sh ] && . testing.sh
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
10
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
11 #testing "name" "command" "result" "infile" "stdin"
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
12
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
13 # Starting processes to test pgrep command
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
14 yes >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
15 proc=$!
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
16 echo "# Process created with id: $proc"
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
17 sleep 1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
18 session_id=0
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
19 proc_parent=`cat /proc/${proc}/stat | awk '{ print $4 }'`
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
20 echo "# Parent Process id of $proc is $proc_parent"
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
21
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
22 # Testcases for pgrep command
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
23 testing "pgrep pattern" "pgrep yes" "$proc\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
24 testing "pgrep wildCardPattern" "pgrep ^y.*s$" "$proc\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
25 testing "pgrep -l pattern" "pgrep -l yes" "$proc yes\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
26 testing "pgrep -f pattern" "pgrep -f yes" "$proc\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
27 testing "pgrep -n pattern" "pgrep -n yes" "$proc\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
28 testing "pgrep -o pattern" "pgrep -o yes" "$proc\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
29 testing "pgrep -s" "pgrep -s $session_id yes" "$proc\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
30 testing "pgrep -P" "pgrep -P $proc_parent yes" "$proc\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
31
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
32 #Clean-up
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
33 killall yes >/dev/null 2>&1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
34
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
35 # Testcases for pkill command
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
36
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
37 yes >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
38 sleep 1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
39 testing "pkill pattern" "pkill yes && sleep 1 && (pgrep yes || echo 'yes')" \
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
40 "yes\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
41 killall yes >/dev/null 2>&1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
42
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
43 yes >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
44 yes print1 >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
45 yes print2 >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
46 sleep 1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
47 testing "pkill pattern (multiple)" "pkill yes && sleep 1 &&
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
48 (pgrep yes || echo 'yes')" "yes\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
49 killall yes >/dev/null 2>&1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
50
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
51 yes >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
52 sleep 1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
53 testing "pkill -f pattern (one)" "pkill -f yes && sleep 1 &&
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
54 (pgrep yes || echo 'yes')" "yes\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
55 killall yes >/dev/null 2>&1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
56
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
57 yes print1 >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
58 sleep 1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
59 testing "pkill -f pattern args" "pkill -f \"yes print1\" && sleep 1 &&
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
60 (pgrep yes || echo 'yes')" "yes\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
61 killall yes >/dev/null 2>&1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
62
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
63 yes >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
64 yes print1 >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
65 yes print2 >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
66 sleep 1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
67 testing "pkill -f pattern (multiple)" "pkill -f yes && sleep 1 &&
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
68 (pgrep yes || echo 'yes')" "yes\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
69 killall yes >/dev/null 2>&1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
70
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
71 yes >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
72 sleep 1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
73 testing "pkill -s 0 -f pattern (regexp)" "pkill -s 0 -f ye* && sleep 1 &&
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
74 (pgrep yes || echo 'yes')" "yes\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
75 killall yes >/dev/null 2>&1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
76
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
77 yes >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
78 proc1=$!
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
79 yes >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
80 proc2=$!
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
81 sleep 1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
82 testing "pkill -n pattern" "pkill -n yes && sleep 1 && pgrep yes" \
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
83 "$proc1\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
84 killall yes >/dev/null 2>&1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
85
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
86 yes >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
87 proc1=$!
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
88 yes >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
89 proc2=$!
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
90 sleep 1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
91 testing "pkill -o pattern" "pkill -o yes && sleep 1 && pgrep yes" \
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
92 "$proc2\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
93 killall yes >/dev/null 2>&1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
94
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
95 yes >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
96 sleep 1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
97 testing "pkill -s (blank) pattern" "pkill -s '' yes && sleep 1 &&
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
98 (pgrep yes || echo 'yes')" "yes\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
99 killall yes >/dev/null 2>&1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
100
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
101 yes >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
102 sleep 1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
103 testing "pkill -s 0 pattern" "pkill -s 0 yes && sleep 1 &&
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
104 (pgrep yes || echo 'yes')" "yes\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
105 killall yes >/dev/null 2>&1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
106
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
107 yes >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
108 proc=$!
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
109 proc_p=`cat /proc/${proc}/stat | awk '{ print $4 }'`
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
110 sleep 1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
111 testing "pkill -P parent_prodId pattern" "pkill -P $proc_p yes && sleep 1 &&
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
112 (pgrep yes || echo 'yes')" "yes\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
113 killall yes >/dev/null 2>&1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
114
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
115 yes >/dev/null &
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
116 proc=$!
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
117 proc_parent=`cat /proc/${proc}/stat | awk '{ print $4 }'`
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
118 sleep 1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
119 testing "pkill -9 pattern" "pkill -9 yes && sleep 1 &&
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
120 (pgrep yes || echo 'yes')" "yes\n" "" ""
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
121 killall yes >/dev/null 2>&1
7a2aec0876fe I have developed few testsuites for toybox commands -
Divya Kothari <divya.s.kothari@gmail.com>
parents:
diff changeset
122