Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/bin/sh | |
| 2 # | |
|
Stefan Reinauer
2010/11/23 19:05:30
With other things living in util/ too and the test
dhendrix
2010/11/24 02:48:14
I tend to agree. It would certainly make it easier
| |
| 3 # Copyright (C) 2010 Google Inc. | |
| 4 # Written by David Hendricks for Google Inc. | |
| 5 # | |
|
Stefan Reinauer
2010/11/23 19:05:30
It might also be nice to have a Makefile hook to r
| |
| 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 | |
| 28 export EXIT_SUCCESS=0 | |
| 29 export EXIT_FAILURE=1 | |
| 30 export DEBUG=1 | |
| 31 | |
| 32 show_help() | |
| 33 { | |
| 34 echo " \ | |
| 35 Usage: | |
| 36 do_test.sh [OPTION] test1.sh test2.sh ... testN.sh | |
|
Stefan Reinauer
2010/11/23 19:05:30
Given that no tests are invoked outside of do_test
hailfinger
2010/11/23 20:05:34
The .sh suffix makes it obvious that we're dealing
Stefan Reinauer
2010/11/23 21:14:14
Not sure if there is a benefit in "knowing" these
dhendrix
2010/11/24 02:48:14
I like the idea of placing the tests in a subdir..
| |
| 37 | |
| 38 Environment variables: | |
| 39 FLASHROM: Path to the Flashrom binary to test | |
| 40 FLASHROM_PARAM: Parameters to pass in | |
| 41 | |
| 42 OPTIONS | |
| 43 -h or --help | |
| 44 Display this message. | |
| 45 | |
| 46 Arguments with one or two leading dashes are processed as options. | |
| 47 Arguments which are filenames are processed as test cases. Names of test | |
| 48 cases may not contain spaces. | |
| 49 " | |
| 50 | |
| 51 exit $EXIT_SUCCESS | |
| 52 } | |
| 53 | |
| 54 msg_dbg() { | |
| 55 if [ ${DEBUG} -eq 1 ]; then | |
| 56 echo "$@" | |
| 57 fi | |
| 58 } | |
| 59 | |
| 60 # Parse command-line | |
| 61 OPTIONS="" | |
| 62 TESTS="" | |
| 63 for ARG in $@; do | |
| 64 if echo "${ARG}" | grep "^-.*$" >/dev/null | |
| 65 then | |
| 66 OPTIONS=${OPTIONS}" "${ARG} | |
| 67 elif [ -f ${ARG} ]; then | |
| 68 TESTS=${TESTS}" "${ARG} | |
| 69 fi | |
| 70 done | |
| 71 | |
| 72 for ARG in ${OPTIONS}; do | |
| 73 case ${ARG} in | |
| 74 -h|--help) | |
| 75 show_help; | |
| 76 shift;; | |
| 77 esac; | |
| 78 done | |
| 79 | |
| 80 # | |
| 81 # Setup Routine | |
| 82 # | |
| 83 | |
| 84 # The copy of flashrom to test. If unset, we'll assume the user wants to test | |
| 85 # a newly built flashrom binary in the parent directory (this script should | |
| 86 # reside in flashrom/util). | |
| 87 if [ -z "${FLASHROM}" ] ; then | |
| 88 FLASHROM="../flashrom" | |
|
Stefan Reinauer
2010/11/23 19:05:30
It would be nice to be able to run the tests from
hailfinger
2010/11/23 20:05:34
Yes, I'll probably start the tests from the top le
dhendrix
2010/11/24 02:48:14
Done.
| |
| 89 fi | |
| 90 echo "testing flashrom binary: ${FLASHROM}" | |
| 91 | |
| 92 OLDDIR=$(pwd) | |
| 93 | |
| 94 # test data location | |
| 95 TMPDIR=$(mktemp -d -t flashrom_test.XXXXXXXXXX) | |
| 96 export TMPDIR="${TMPDIR}" | |
| 97 if [ "$?" != "0" ] ; then | |
| 98 echo "Could not create temporary directory" | |
| 99 exit ${EXIT_FAILURE} | |
| 100 fi | |
| 101 | |
| 102 which flashrom > /dev/null | |
| 103 #if [ "$?" != "0" ] ; then | |
| 104 if [ ${?} -ne 0 ] ; then | |
| 105 echo "Please install a stable version of flashrom in your path." | |
| 106 echo "This will be used to compare the test flashrom binary and " | |
| 107 echo "restore your firmware image at the end of the test." | |
| 108 exit ${EXIT_FAILURE} | |
| 109 fi | |
| 110 | |
| 111 # Copy the test case files and flashrom to temporary directory. | |
| 112 cp "${FLASHROM}" "${TMPDIR}/" | |
| 113 for TEST in ${TESTS}; do | |
| 114 cp ${TEST} "${TMPDIR}/" | |
| 115 done | |
| 116 | |
| 117 cd "${TMPDIR}" | |
| 118 echo "Running test in ${TMPDIR}" | |
| 119 | |
| 120 # Make a backup | |
| 121 echo "Reading BIOS image" | |
| 122 BACKUP="backup.bin" | |
| 123 flashrom ${FLASHROM_PARAM} -r "$BACKUP" > /dev/null | |
| 124 echo "Original image saved as ${BACKUP}" | |
| 125 export BACKUP=${BACKUP} | |
| 126 | |
| 127 # | |
| 128 # Execute test cases | |
| 129 # | |
| 130 rc=${EXIT_SUCCESS} | |
| 131 msg_dbg "Test cases: ${TESTS}" | |
| 132 for TEST in ${TESTS}; do | |
| 133 msg_dbg "Running test: \"${TEST}\"" | |
| 134 ./${TEST} | |
| 135 if [ ${?} -ne ${EXIT_SUCCESS} ]; then | |
| 136 rc=${EXIT_FAILURE} | |
| 137 break | |
| 138 fi | |
| 139 done | |
| 140 | |
| 141 # | |
| 142 # Cleanup Routine | |
| 143 # | |
| 144 if [ ${rc} -ne ${EXIT_SUCCESS} ] ; then | |
| 145 echo "Result: FAILED" | |
| 146 else | |
| 147 echo "Result: PASSED" | |
| 148 fi | |
| 149 | |
| 150 echo "restoring original image using system's flashrom" | |
| 151 flashrom ${FLASHROM_PARAM} -w "$BACKUP" #FIXME: add this back in | |
|
hailfinger
2010/11/23 20:05:34
What should be added back in?
dhendrix
2010/11/24 02:48:14
stale comment -- removed.
| |
| 152 echo "test files remain in ${TMPDIR}" | |
| 153 cd "${OLDDIR}" | |
| 154 exit ${rc} | |
| OLD | NEW |