 Chromium Code Reviews
 Chromium Code Reviews Issue 5136001:
  Add new testing framework along with a few micro-tests.  (Closed) 
  Base URL: svn://coreboot.org/flashrom/trunk/util
    
  
    Issue 5136001:
  Add new testing framework along with a few micro-tests.  (Closed) 
  Base URL: svn://coreboot.org/flashrom/trunk/util| OLD | NEW | 
|---|---|
| (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 # Assume we can set enable/disable bits (that is, SPI chip is not hardware | |
| 21 # write-protected). Also, assume output is in the form: | |
| 22 # WP: write protect is enabled | |
| 23 # WP: write protect is disabled | |
| 24 | |
| 25 LOGFILE="${0}.log" | |
| 26 WP_DISABLED=0 | |
| 27 WP_ENABLED=1 | |
| 28 MAGIC="write protect is" | |
| 29 | |
| 30 wp_toggle_fail() | |
| 31 { | |
| 32 echo "$1" >> ${LOGFILE} | |
| 33 echo "$0: failed" >> ${LOGFILE} | |
| 34 exit ${EXIT_FAILURE} | |
| 35 } | |
| 36 | |
| 37 wp_status() | |
| 38 { | |
| 39 if [ "$(printf %s\\n "$1" | sed 's/.*enabled.*/enabled/')" = "enabled" ] ; then | |
| 40 return ${WP_ENABLED} | |
| 41 elif [ "$(printf %s\\n "$1" | sed 's/.*disabled.*/disabled/')" = "disabl ed" ]; then | |
| 42 return ${WP_DISABLED} | |
| 43 else | |
| 44 wp_toggle_fail "unknown write protect status: \"$1\"" | |
| 45 fi | |
| 46 } | |
| 47 | |
| 48 # Back-up old settings | |
| 49 tmp=$(./flashrom ${FLASHROM_PARAM} --wp-status 2>/dev/null | grep "$MAGIC") | |
| 50 wp_status "$tmp" | |
| 51 old_status=$? | |
| 52 echo "old write protect status: ${old_status}" >> ${LOGFILE} | |
| 53 | |
| 54 # invert the old setting | |
| 55 if [ ${old_status} -eq ${WP_ENABLED} ]; then | |
| 56 ./flashrom ${FLASHROM_PARAM} --wp-disable 2>/dev/null | |
| 57 tmp=$(./flashrom ${FLASHROM_PARAM} --wp-status 2>/dev/null | grep "$MAGI C") | |
| 
hailfinger
2010/11/23 20:05:34
You only check that the output changed, you don't
 
Stefan Reinauer
2010/11/23 21:14:14
Wouldn't flashrom's output reflect this? If not, m
 
dhendrix
2010/11/24 02:48:14
Again, good point. I've added a FIXME near the top
 
dhendrix
2010/11/24 02:48:14
Yes, I should hope that Flashrom does not lie to u
 | |
| 58 wp_status "$tmp" | |
| 59 if [ $? = ${WP_ENABLED} ]; then | |
| 60 wp_toggle_fail "failed to disable write protection" | |
| 61 fi | |
| 62 elif [ ${old_status} -eq ${WP_DISABLED} ]; then | |
| 63 ./flashrom ${FLASHROM_PARAM} --wp-enable 2>/dev/null | |
| 64 tmp=$(./flashrom ${FLASHROM_PARAM} --wp-status 2>/dev/null | grep "$MAGI C") | |
| 65 wp_status "$tmp" | |
| 66 if [ $? = ${WP_DISABLED} ]; then | |
| 67 wp_toggle_fail "failed to enable write protection" | |
| 68 fi | |
| 69 fi | |
| 70 | |
| 71 # restore old setting | |
| 72 if [ ${old_status} -eq ${WP_ENABLED} ]; then | |
| 73 ./flashrom ${FLASHROM_PARAM} --wp-enable 2>/dev/null | |
| 74 tmp=$(./flashrom ${FLASHROM_PARAM} --wp-status 2>/dev/null | grep "$MAGI C") | |
| 75 wp_status "$tmp" | |
| 76 if [ $? != ${WP_ENABLED} ]; then | |
| 77 wp_toggle_fail "failed to enable write protection" | |
| 78 fi | |
| 79 elif [ ${old_status} -eq ${WP_DISABLED} ]; then | |
| 80 ./flashrom ${FLASHROM_PARAM} --wp-disable 2>/dev/null | |
| 81 tmp=$(./flashrom ${FLASHROM_PARAM} --wp-status 2>/dev/null | grep "$MAGI C") | |
| 82 wp_status "$tmp" | |
| 83 if [ $? != ${WP_DISABLED} ]; then | |
| 84 wp_toggle_fail "failed to disable write protection" | |
| 85 fi | |
| 86 fi | |
| 87 | |
| 88 echo "$0: passed" >> ${LOGFILE} | |
| 89 return ${EXIT_SUCCESS} | |
| OLD | NEW |