Index: client/common_lib/flashrom_util.py |
diff --git a/client/common_lib/flashrom_util.py b/client/common_lib/flashrom_util.py |
index 4cf4f1da3009f6f5e9fdad028995181fa8e82d94..6b8ffc21504495d00881cedb9522ad2b9a3cd69f 100644 |
--- a/client/common_lib/flashrom_util.py |
+++ b/client/common_lib/flashrom_util.py |
@@ -325,11 +325,16 @@ class flashrom_util(object): |
def get_size(self): |
""" Gets size of current flash ROM """ |
- # TODO(hungte) Newer version of tool (flashrom) may support --get-size |
- # command which is faster in future. Right now we use back-compatible |
- # method: read whole and then get length. |
- image = self.read_whole() |
- return len(image) |
+ cmd = '%s"%s" --get-size' % (self.cmd_prefix, self.tool_path) |
+ if self.verbose: |
+ print 'flashrom_util.get_size(): ', cmd |
+ output = utils.system_output(cmd, ignore_status=True) |
+ last_line = output.rpartition('\n')[2] |
+ try: |
+ size = long(last_line) |
+ except ValueError: |
+ raise TestError('INTERNAL ERROR: unable to get the flash size.') |
+ return size |
def detect_target_map(self): |
""" |
@@ -757,19 +762,23 @@ class mock_utils(object): |
arch = re.sub(r"i\d86", r"i386", arch, 1) |
return arch |
- def system(self, cmd, ignore_status=False): |
+ def run_command(self, cmd, ignore_status=False): |
p = subprocess.Popen(cmd, shell=True, |
stdout=subprocess.PIPE, |
stderr=subprocess.PIPE) |
p.wait() |
- if p.returncode: |
- err_msg = p.stderr.read() |
- print p.stdout.read() |
- print err_msg |
- if not ignore_status: |
- raise TestError("failed to execute: %s\nError messages: %s" % ( |
- cmd, err_msg())) |
- return p.returncode |
+ if p.returncode and not ignore_status: |
Hung-Te
2010/09/02 02:10:22
oops, please keep the print stdout.read() and err_
Tom Wai-Hong Tam
2010/09/02 02:55:24
OK. Will change it in other CL: http://codereview.
|
+ raise TestError("failed to execute: %s\nError messages: %s" % ( |
+ cmd, p.stderr.read())) |
+ return (p.returncode, p.stdout.read()) |
+ |
+ def system(self, cmd, ignore_status=False): |
+ (returncode, output) = self.run_command(cmd, ignore_status) |
+ return returncode |
+ |
+ def system_output(self, cmd, ignore_status=False): |
+ (returncode, output) = self.run_command(cmd, ignore_status) |
+ return output |
# import autotest or mock utilities |