diff options
author | Timothy Knight <tknight@google.com> | 2014-06-26 03:18:55 -0700 |
---|---|---|
committer | Timothy Knight <tknight@google.com> | 2014-06-26 10:15:34 -0700 |
commit | 8be79762855388604200009c81a40287a22d57f2 (patch) | |
tree | 0492d928df49deb881e1b4ee69ff0a77c7078146 /apps | |
parent | 4fee8b2b388f923977acee676556b98f31982e7d (diff) | |
download | pdk-8be79762855388604200009c81a40287a22d57f2.tar.gz |
CameraITS: Fixed issue causing socket connection problems
Change-Id: Ic5fae0d9ac97cac26108247ba7420eba073a0682
Diffstat (limited to 'apps')
-rw-r--r-- | apps/CameraITS/pymodules/its/device.py | 6 | ||||
-rw-r--r-- | apps/CameraITS/tests/test_format_combos.py | 84 |
2 files changed, 31 insertions, 59 deletions
diff --git a/apps/CameraITS/pymodules/its/device.py b/apps/CameraITS/pymodules/its/device.py index 42053ba..be97ada 100644 --- a/apps/CameraITS/pymodules/its/device.py +++ b/apps/CameraITS/pymodules/its/device.py @@ -76,6 +76,7 @@ class ItsSession(object): def __init__(self): reboot_device_on_argv() # TODO: Figure out why "--user 0" is needed, and fix the problem + _run('%s logcat -c' % (self.ADB)) _run('%s shell am force-stop --user 0 %s' % (self.ADB, self.PACKAGE)) _run(('%s shell am startservice --user 0 -t text/plain ' '-a %s') % (self.ADB, self.INTENT_START)) @@ -92,15 +93,14 @@ class ItsSession(object): logcat = proc.stdout while True: line = logcat.readline().strip() - if line.find('Waiting for client to connect to socket'): + if line.find('Waiting for client to connect to socket') >= 0: break proc.kill() def __del__(self): if hasattr(self, 'sock') and self.sock: self.sock.close() - # TODO: Figure out why uncommenting this here causes socket errors. - #_run('%s shell am force-stop --user 0 %s' % (self.ADB, self.PACKAGE)) + _run('%s shell am force-stop --user 0 %s' % (self.ADB, self.PACKAGE)) def __enter__(self): return self diff --git a/apps/CameraITS/tests/test_format_combos.py b/apps/CameraITS/tests/test_format_combos.py index e343efe..d883685 100644 --- a/apps/CameraITS/tests/test_format_combos.py +++ b/apps/CameraITS/tests/test_format_combos.py @@ -20,17 +20,12 @@ import sys import time import os import os.path -import functools -import errno -import signal # Change this to True, to have the test break at the first failure. stop_at_first_failure = False def main(): """Test different combinations of output formats. - - Test is UNIX-only due to use of Python signal module. """ NAME = os.path.basename(__file__).split(".")[0] @@ -66,44 +61,36 @@ def main(): burst_lens = [1, # B0 3] # B1 - # There are 2x10x2=40 different combinations. Run through them all, with - # each test controlled by a 30s timeout; if it doesn't complete in 30s, - # then the test for that combination is considered a failure. For each test - # run, re-open the ITS session to the device, which restarts the ITS - # service process; this ensures a somewhat-clean initial state for each - # combo's test. + # There are 2x10x2=40 different combinations. Run through them all. n = 0 - props = None - for r,req in enumerate(reqs): - for f,fmt_combo in enumerate(fmt_combos): - for b,burst_len in enumerate(burst_lens): - try: - with Timeout(seconds=30), its.device.ItsSession() as cam: - if props is None: - props = cam.get_camera_properties() + with its.device.ItsSession() as cam: + props = cam.get_camera_properties() + for r,req in enumerate(reqs): + for f,fmt_combo in enumerate(fmt_combos): + for b,burst_len in enumerate(burst_lens): + try: caps = cam.do_capture([req]*burst_len, fmt_combo) - - print "==> Success[%02d]: R%d F%d B%d" % (n,r,f,b) - successes.append((n,r,f,b)) - - # Dump the captures out to jpegs. - if not isinstance(caps, list): - caps = [caps] - elif isinstance(caps[0], list): - caps = sum(caps, []) - for c,cap in enumerate(caps): - img = its.image.convert_capture_to_rgb_image(cap, - props=props) - its.image.write_image(img, - "%s_n%02d_r%d_f%d_b%d_c%d.jpg"%(NAME,n,r,f,b,c)) - - except Exception as e: - print e - print "==> Failure[%02d]: R%d F%d B%d" % (n,r,f,b) - failures.append((n,r,f,b)) - if stop_at_first_failure: - sys.exit(0) - n += 1 + successes.append((n,r,f,b)) + print "==> Success[%02d]: R%d F%d B%d" % (n,r,f,b) + + # Dump the captures out to jpegs. + if not isinstance(caps, list): + caps = [caps] + elif isinstance(caps[0], list): + caps = sum(caps, []) + for c,cap in enumerate(caps): + img = its.image.convert_capture_to_rgb_image(cap, + props=props) + its.image.write_image(img, + "%s_n%02d_r%d_f%d_b%d_c%d.jpg"%(NAME,n,r,f,b,c)) + + except Exception as e: + print e + print "==> Failure[%02d]: R%d F%d B%d" % (n,r,f,b) + failures.append((n,r,f,b)) + if stop_at_first_failure: + sys.exit(0) + n += 1 num_fail = len(failures) num_success = len(successes) @@ -120,21 +107,6 @@ def main(): print "\nNumber of tests not run: %d / %d" % (num_not_run, num_total) print "" -# A class to encapsulate timeout funcitonality in a way that can be used in -# a "with" block. UNIX-only since it uses signals. If the timeout elapses, -# then an exception is raised. -class Timeout: - def __init__(self, seconds): - self.seconds = seconds - self.error_message = "Timeout" - def handle_timeout(self, signum, frame): - raise its.error.Error(self.error_message) - def __enter__(self): - signal.signal(signal.SIGALRM, self.handle_timeout) - signal.alarm(self.seconds) - def __exit__(self, type, value, traceback): - signal.alarm(0) - if __name__ == '__main__': main() |