Merge pull request #187 from bjackman/clear-logcat-lock

AndroidTarget: prevent concurrent invocations of 'logcat -c'
diff --git a/devlib/instrument/acmecape.py b/devlib/instrument/acmecape.py
index 1053c9d..818094f 100644
--- a/devlib/instrument/acmecape.py
+++ b/devlib/instrument/acmecape.py
@@ -37,7 +37,7 @@
     mode = CONTINUOUS
 
     def __init__(self, target,
-                 iio_capture=which('iio_capture'),
+                 iio_capture=which('iio-capture'),
                  host='baylibre-acme.local',
                  iio_device='iio:device0',
                  buffer_size=256):
@@ -77,17 +77,25 @@
     def stop(self):
         self.process.terminate()
         timeout_secs = 10
+        output = ''
         for _ in xrange(timeout_secs):
             if self.process.poll() is not None:
                 break
             time.sleep(1)
         else:
-            output = _read_nonblock(self.process.stdout)
+            output += _read_nonblock(self.process.stdout)
             self.process.kill()
             self.logger.error('iio-capture did not terminate gracefully')
             if self.process.poll() is None:
                 msg = 'Could not terminate iio-capture:\n{}'
                 raise HostError(msg.format(output))
+        if self.process.returncode != 15: # iio-capture exits with 15 when killed
+            output += self.process.stdout.read()
+            self.logger.info('ACME instrument encountered an error, '
+                             'you may want to try rebooting the ACME device:\n'
+                             '  ssh root@{} reboot'.format(self.host))
+            raise HostError('iio-capture exited with an error ({}), output:\n{}'
+                            .format(self.process.returncode, output))
         if not os.path.isfile(self.raw_data_file):
             raise HostError('Output CSV not generated.')
 
diff --git a/devlib/target.py b/devlib/target.py
index 2fc64dc..b2cfd2f 100644
--- a/devlib/target.py
+++ b/devlib/target.py
@@ -215,7 +215,9 @@
         tid = id(threading.current_thread())
         self._connections[tid] = self.get_connection(timeout=timeout)
         self._resolve_paths()
-        self.busybox = self.get_installed('busybox')
+        self.execute('mkdir -p {}'.format(self.working_directory))
+        self.execute('mkdir -p {}'.format(self.executables_directory))
+        self.busybox = self.install(os.path.join(PACKAGE_BIN_DIRECTORY, self.abi, 'busybox'))
         self.platform.update_from_target(self)
         self._update_modules('connected')
         if self.platform.big_core and self.load_default_modules:
@@ -232,10 +234,6 @@
         return self.conn_cls(timeout=timeout, **self.connection_settings)  # pylint: disable=not-callable
 
     def setup(self, executables=None):
-        self.execute('mkdir -p {}'.format(self.working_directory))
-        self.execute('mkdir -p {}'.format(self.executables_directory))
-        self.busybox = self.install(os.path.join(PACKAGE_BIN_DIRECTORY, self.abi, 'busybox'))
-
         self._setup_shutils()
 
         for host_exe in (executables or []):  # pylint: disable=superfluous-parens