Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: third_party/xdg-utils/tests/testrun

Issue 151098: Patch from mdm@google.com... (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Name: svn:executable
+ *
OLDNEW
(Empty)
1 #!/bin/bash
2
3 # Defaults.
4 ROOT_TEST_GROUPS="xdg-desktop-icon xdg-desktop-menu xdg-icon-resource xdg-mime x dg-utils-usecases"
5 USER_TEST_GROUPS="$ROOT_TEST_GROUPS xdg-email xdg-open xdg-screensaver"
6
7 usage() {
8 cat << _ENDUSAGE_
9 Usage:
10 $0 [-iIcChRSd:p:f:a] [test|testgroup] [...]
11
12 Options:
13 [-h] Show this message and exit.
14
15 [-I|-i] Turn off/on interactive tests. Default: on
16 (overrides XDG_TEST_NO_INTERACTIVE)
17
18 [-C|-c] Turn off/on deletion of tempfiles. Default: on
19 (overrides XDG_TEST_DONT_CLEANUP)
20
21 [-R] Turn off su to root tests.
22 You will not be prompted for the root password at the beginning o f the testrun.
23
24 [-S] Use sudo instead of su.
25
26 [-a] Run all tests. (i.e xdg-*/) Has no effect if tests are specified explicitly.
27
28 [-d dir] Set XDG_TEST_DIR to dir
29
30 [-p path] Reset PATH to path. Recommended for internal use only.
31
32 [-f pid] RESERVED -- state flag for self reference. DON'T USE.
33
34 Arguments:
35
36 After options, all arguments correspond to tests to run. The default is to run a ll tests, which consist of all files matching 'xdg-*/t.*'.
37
38 Supplied testgroups can be a list of directories or a list of individual tests.
39
40 _ENDUSAGE_
41 exit 1
42 }
43 MYARGS="$@"
44
45 if [ `whoami` == root ] ; then
46 XDG_TEST_DONT_SU="set"
47 DEFAULT_TEST_GROUPS="$ROOT_TEST_GROUPS"
48 RUNNING_AS="root"
49 else
50 DEFAULT_TEST_GROUPS="$USER_TEST_GROUPS"
51 RUNNING_AS="normal"
52 fi
53
54 ## Read options
55 while getopts "iIcChRSf:d:p:a" opt; do
56 case $opt in
57 I ) export XDG_TEST_NO_INTERACTIVE="set" ;;
58 i ) unset XDG_TEST_NO_INTERACTIVE ;;
59 C ) export XDG_TEST_DONT_CLEANUP="set" ;;
60 c ) unset XDG_TEST_DONT_CLEANUP ;;
61 R ) XDG_TEST_DONT_SU="set" ;;
62 S ) XDG_TEST_USE_SUDO="set" ;;
63 f ) XDG_TEST_SELF_LAUNCH="$OPTARG" ;;
64 d ) export XDG_TEST_DIR="$OPTARG" ;;
65 p ) export PATH="$OPTARG" ;;
66 a ) DEFAULT_TEST_GROUPS=`ls -d $XDG_TEST_DIR/xdg-*` ;;
67 h ) usage ;;
68 \? ) usage ;;
69 esac
70 done
71 shift $(($OPTIND - 1))
72
73 ## Set up prerequisites
74 if [ -z "$XDG_TEST_DIR" ] ; then
75 export XDG_TEST_DIR="$PWD"
76 echo "WARNING: guessed XDG_TEST_DIR to be $XDG_TEST_DIR"
77 fi
78 if [ -z `which xdg-mime 2>/dev/null` ] && [ -d "$XDG_TEST_DIR/../scripts" ] ; th en
79 export PATH="$PATH:$XDG_TEST_DIR/../scripts"
80 echo "WARNING: modified PATH to add '$XDG_TEST_DIR/../scripts'"
81 fi
82
83 ## Read test groups
84 if [ $# -eq 0 ] ; then
85 TEST_GROUPS="$DEFAULT_TEST_GROUPS"
86 else
87 TEST_GROUPS="$@"
88 fi
89
90 TEST_FILES=`find $TEST_GROUPS -name 't.*[^~]' | sort`
91
92 declare -i PASS=0
93 declare -i FAILCOUNT=0
94 declare -i TOTAL=0
95 declare -i ATTEMPT=0
96 TEST_LOG="$XDG_TEST_DIR/xdg-test.log"
97
98 export USING_TEST_RUNNER="true"
99
100 for MY_TEST_FILE in $TEST_FILES; do
101 . "$MY_TEST_FILE"
102 done
103
104 if [ -z "$XDG_TEST_SELF_LAUNCH" ] ; then # not self launched
105 test -d "$XDG_TEST_DIR/tmp" || mkdir "$XDG_TEST_DIR/tmp"
106 touch "$XDG_TEST_DIR/tmp/shortid"
107 chmod 666 "$XDG_TEST_DIR/tmp/shortid"
108
109 if [ "$RUNNING_AS" == root -a -z "$*" ] ; then
110 echo "WARNING: Tests are incomplete unless run as a normal (non- root) user."
111 echo "The test runner will SU as needed to run root cases."
112 fi
113
114 echo "======================================================" >> "$TEST _LOG"
115 echo "[`date`] TEST RUN START: $*" >> "$TEST_LOG"
116 "$XDG_TEST_DIR/include/system_info" >>"$TEST_LOG"
117
118 if [ -z "$XDG_TEST_DONT_SU" ] ; then
119 if [ -z "$XDG_TEST_USE_SUDO" ] ; then
120 SUCMD=
121 echo "Running su for system tests. (Use testrun -S to us e sudo instead)"
122 echo "Please enter the root password when requested."
123 else
124 SUCMD=`which sudo 2>/dev/null`
125 echo "Running ${SUCMD-su} for system tests."
126 echo "Please enter an apropriate password if requested."
127 fi
128 # Note if sudo is not found, $SUCMD will be blank, so run su dir ectly.
129 # We cannot assume su works since systems like Ubuntu require su do
130 # Yet, systems like Debian do not ship with sudo by default.
131 $SUCMD su - -c "cd $PWD && XDG_UTILS_DEBUG_LEVEL=$XDG_UTILS_DEBU G_LEVEL $0 -f $$ -d '$XDG_TEST_DIR' -p '$PATH' $MYARGS"
132 fi
133
134 TEST_STATUS_FILE="$XDG_TEST_DIR/tmp/xdgtest_status-$$"
135 USERCLASS="normal user"
136 else
137 TEST_STATUS_FILE="$XDG_TEST_DIR/tmp/xdgtest_status-$XDG_TEST_SELF_LAUNCH "
138 USERCLASS="root"
139 fi
140
141 echo "[`date`] ---- $USERCLASS run start: $*" >> "$TEST_LOG"
142 #echo "TEST_LIST: $TEST_LIST"
143
144 for t in $TEST_LIST; do
145 TOTAL=$((TOTAL + 1 ))
146 ATTEMPT=$((ATTEMPT + 1 ))
147
148 echo -n "$t: "
149
150 test_setup
151
152 # Run test - subshell is necessary to keep things contained.
153 ( "$t" ) >> "$TEST_LOG"
154 CODE="$?"
155
156 test_cleanup
157
158 # Report result
159 case "$CODE" in
160 0 ) PASS=$((PASS + 1))
161 RESULT=PASS
162 ;;
163
164 1 ) RESULT=FAIL
165 FAILCOUNT=$((FAILCOUNT +1))
166 ;;
167 5 ) RESULT=UNTESTED
168 TOTAL=$((TOTAL - 1 )) ## HACK: we don't want to count tests that don't run.
169 ;;
170 7 ) RESULT=NORESULT ;;
171 10 ) RESULT=WARN ;;
172 * ) RESULT="UNKNOWN($CODE)";;
173 esac
174 echo "$RESULT"
175 test "$RESULT" == FAIL && echo "" >> "$TEST_LOG"
176 done
177
178 echo -n "[`date`] ---- " >> "$TEST_LOG"
179 echo "$USERCLASS run end: $FAILCOUNT tests failed, $PASS of $TOTAL tests passed. ($ATTEMPT attempted)" | tee -a "$TEST_LOG"
180
181 if [ -z "$XDG_TEST_SELF_LAUNCH" ] ; then # not su'd
182 if [ -f "$TEST_STATUS_FILE" ] ; then
183 RFAIL=`grep 'FAIL' "$TEST_STATUS_FILE" | cut -d ':' -f2`
184 RPASS=`grep 'PASS' "$TEST_STATUS_FILE" | cut -d ':' -f2`
185 RTOTAL=`grep 'TOTAL' "$TEST_STATUS_FILE" | cut -d ':' -f2`
186 RATTEMPT=`grep 'ATTEMPT' "$TEST_STATUS_FILE" | cut -d ':' -f2`
187
188 rm -f "$TEST_STATUS_FILE"
189 fi
190
191 GFAIL=$(( $FAILCOUNT + ${RFAIL-0} ))
192 GPASS=$(( $PASS + ${RPASS-0} ))
193 GTOTAL=$(( $TOTAL + ${RTOTAL-0} ))
194 GATTEMPT=$(( $ATTEMPT + ${RATTEMPT-0} ))
195
196 echo -n "[`date`] TEST RUN END: $* - " >> "$TEST_LOG"
197 echo -n "TOTAL: "
198 echo "$GFAIL tests failed, $GPASS of $GTOTAL tests passed. ($GATTEMPT at tempted)" | tee -a "$TEST_LOG"
199
200 if [ $(( $GTOTAL - $GPASS )) -gt 0 ]; then
201 EC=1
202 echo "NOT OK! -- See $TEST_LOG for details."
203 else
204 EC=0
205 echo "ok"
206 fi
207 if [ -z "$*" -a -z "$XDG_TEST_NO_INTERACTIVE" ] ; then
208 echo "Please consider submitting your test report to"
209 echo "http://portland.freedesktop.org/testreport.html"
210 echo ""
211 fi
212
213 exit "$EC"
214 else ## Running su'd. save results.
215 echo "FAIL:$FAILCOUNT" > $TEST_STATUS_FILE
216 echo "PASS:$PASS" >> $TEST_STATUS_FILE
217 echo "TOTAL:$TOTAL" >> $TEST_STATUS_FILE
218 echo "ATTEMPT:$ATTEMPT" >> $TEST_STATUS_FILE
219
220 if [ $(( $TOTAL - $PASS)) -gt 0 ] ; then
221 exit -1
222 else
223 exit 0
224 fi
225 fi
226
OLDNEW
« no previous file with comments | « third_party/xdg-utils/tests/spec/test_specification.pdf ('k') | third_party/xdg-utils/tests/tet_run » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698