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

Side by Side Diff: util/do_tests.sh

Issue 5136001: Add new testing framework along with a few micro-tests. (Closed) Base URL: svn://coreboot.org/flashrom/trunk/util
Patch Set: asdf Created 10 years, 1 month 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
« no previous file with comments | « util/chip_size.sh ('k') | util/partial_writes_ec.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/bin/sh
2 #
3 # Copyright (C) 2010 Google Inc.
4 # Written by David Hendricks for Google Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #
20 # This is a simple test harness which contains setup and cleanup code common to
21 # all tests. The syntax for this script is:
22 # do_tests.sh --options <test1> <test2> ... <testN>
23 #
24 # Arguments which are files are assumed to be tests which are run after common
25 # setup routines and before common cleanup routines.
26 #
27 # This script exports some global variables intended for use by individual unit
28 # tests. The important ones are:
29 # EXIT_SUCCESS & EXIT_FAILURE: Exit codes
30 # DEBUG: Indicates that extra verbosity should be used.
31 # BACKUP: The backup firmware image obtained during setup.
32
33 export EXIT_SUCCESS=0
34 export EXIT_FAILURE=1
35 export DEBUG=1
36
37 show_help()
38 {
39 echo " \
40 Usage:
41 do_test.sh [OPTION] test1.sh test2.sh ... testN.sh
42
43 Environment variables:
44 FLASHROM: Path to the Flashrom binary to test
45 FLASHROM_PARAM: Parameters to pass in
46
47 OPTIONS
48 -h or --help
49 Display this message.
50
51 Arguments with one or two leading dashes are processed as options.
52 Arguments which are filenames are processed as test cases. Names of test
53 cases may not contain spaces.
54 "
55
56 exit $EXIT_SUCCESS
57 }
58
59 msg_dbg() {
60 if [ ${DEBUG} -eq 1 ]; then
61 echo "$@"
62 fi
63 }
64
65 # Parse command-line
66 OPTIONS=""
67 TESTS=""
68 for ARG in $@; do
69 if echo "${ARG}" | grep "^-.*$" >/dev/null
70 then
71 OPTIONS=${OPTIONS}" "${ARG}
72 elif [ -f ${ARG} ]; then
73 TESTS=${TESTS}" "${ARG}
74 fi
75 done
76
77 for ARG in ${OPTIONS}; do
78 case ${ARG} in
79 -h|--help)
80 show_help;
81 shift;;
82 esac;
83 done
84
85 #
86 # Setup Routine
87 #
88
89 # The copy of flashrom to test. If unset, we'll assume the user wants to test
90 # a newly built flashrom binary in the parent directory (this script should
91 # reside in flashrom/util).
92 if [ -z "${FLASHROM}" ] ; then
93 FLASHROM="./flashrom"
94 fi
95 echo "testing flashrom binary: ${FLASHROM}"
96
97 OLDDIR=$(pwd)
98
99 # test data location
100 TMPDIR=$(mktemp -d -t flashrom_test.XXXXXXXXXX)
101 if [ "$?" != "0" ] ; then
102 echo "Could not create temporary directory"
103 exit ${EXIT_FAILURE}
104 fi
105
106 which flashrom > /dev/null
107 #if [ "$?" != "0" ] ; then
108 if [ ${?} -ne 0 ] ; then
109 echo "Please install a stable version of flashrom in your path."
110 echo "This will be used to compare the test flashrom binary and "
111 echo "restore your firmware image at the end of the test."
112 exit ${EXIT_FAILURE}
113 fi
114
115 # Copy the test case files and flashrom to temporary directory.
116 cp "${FLASHROM}" "${TMPDIR}/"
117 for TEST in ${TESTS}; do
118 cp ${TEST} "${TMPDIR}/"
119 done
120
121 cd "${TMPDIR}"
122 echo "Running test in ${TMPDIR}"
123
124 # Make a backup
125 echo "Reading firmware image"
126 BACKUP="backup.bin"
127 flashrom ${FLASHROM_PARAM} -r "$BACKUP" > /dev/null
128 if [ $? -ne 0 ]; then
129 echo "Failed to create backup image"
130 exit ${EXIT_FAILURE}
131 else
132 echo "Original image saved as ${BACKUP}"
133 fi
134
135
136 # Attempt to write the backup image to ensure the system's flashrom is
137 # at least somewhat capable of restoring the image.
138 # FIXME: this requires a modification to flashrom to force blocks to be
139 # re-written, even if the content is the same.
140 #flashrom ${FLASHROM_PARAM} --force -r "$BACKUP" > /dev/null
141 #if [ $? -ne 0 ]; then
142 # echo "The installed flashrom binary is not usable for testing"
143 # exit ${EXIT_FAILURE}
144 #fi
145
146 export BACKUP=${BACKUP}
147
148 #
149 # Execute test cases
150 #
151 rc=${EXIT_SUCCESS}
152 msg_dbg "Test cases: ${TESTS}"
153 for TEST in ${TESTS}; do
154 msg_dbg "Running test: \"${TEST}\""
155 ./${TEST}
156 if [ ${?} -ne ${EXIT_SUCCESS} ]; then
157 rc=${EXIT_FAILURE}
158 break
159 fi
160 done
161
162 #
163 # Cleanup Routine
164 #
165 if [ ${rc} -ne ${EXIT_SUCCESS} ] ; then
166 echo "Result: FAILED"
167 else
168 echo "Result: PASSED"
169 fi
170
171 echo "restoring original image using system's flashrom"
172 flashrom ${FLASHROM_PARAM} -w "$BACKUP"
173 echo "test files remain in ${TMPDIR}"
174 cd "${OLDDIR}"
175 exit ${rc}
OLDNEW
« no previous file with comments | « util/chip_size.sh ('k') | util/partial_writes_ec.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698