diff --git a/scripts/sanity_chk/hwmap-schema.yaml b/scripts/sanity_chk/hwmap-schema.yaml index 43616468b567ee..21baf1af4705df 100644 --- a/scripts/sanity_chk/hwmap-schema.yaml +++ b/scripts/sanity_chk/hwmap-schema.yaml @@ -27,6 +27,9 @@ sequence: "post_script": type: str required: false + "post_flash_script": + type: str + required: false "pre_script": type: str required: false \ No newline at end of file diff --git a/scripts/sanitycheck b/scripts/sanitycheck index 8cc85e81000d84..0544d96c35fd18 100755 --- a/scripts/sanitycheck +++ b/scripts/sanitycheck @@ -564,6 +564,7 @@ class BinaryHandler(Handler): env.get("ASAN_OPTIONS", "") if not self.lsan: env["ASAN_OPTIONS"] += "detect_leaks=0" + with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.build_dir, env=env) as proc: logger.debug("Spawning BinaryHandler Thread for %s" % self.name) @@ -575,6 +576,9 @@ class BinaryHandler(Handler): t.join() proc.wait() self.returncode = proc.returncode + _, stderr = proc.communicate(timeout=30) + if stderr: + logger.error(stderr.decode()) handler_time = time.time() - start_time @@ -681,6 +685,18 @@ class DeviceHandler(Handler): if i['serial'] == serial: i['available'] = True + @staticmethod + def run_custom_script(script, timeout): + with subprocess.Popen(script, stderr=subprocess.PIPE, stdout=subprocess.PIPE) as proc: + try: + stdout, _ = proc.communicate(timeout=timeout) + logger.debug(stdout.decode()) + + except subprocess.TimeoutExpired: + proc.kill() + proc.communicate() + logger.error("{} timed out".format(script)) + def handle(self): out_state = "failed" @@ -703,6 +719,7 @@ class DeviceHandler(Handler): command = [get_generator()[0], "-C", self.build_dir, "flash"] while not self.device_is_available(self.instance.platform.name): + logger.debug("Waiting for device {} to become available".format(self.instance.platform.name)) time.sleep(1) hardware = self.get_available_device(self.instance.platform.name) @@ -759,20 +776,12 @@ class DeviceHandler(Handler): read_pipe, write_pipe = os.pipe() start_time = time.time() - pre_script = hardware.get('pre_script') + post_flash_script = hardware.get('post_flash_script') post_script = hardware.get('post_script') if pre_script: - with subprocess.Popen(pre_script, stderr=subprocess.PIPE, stdout=subprocess.PIPE) as proc: - try: - (stdout, stderr) = proc.communicate(timeout=30) - logger.debug(stdout.decode()) - - except subprocess.TimeoutExpired: - proc.kill() - (stdout, stderr) = proc.communicate() - logger.error("{} timed out".format(post_script)) + self.run_custom_script(pre_script, 30) t = threading.Thread(target=self.monitor_serial, daemon=True, args=(ser, read_pipe, harness)) @@ -802,13 +811,21 @@ class DeviceHandler(Handler): except subprocess.CalledProcessError: os.write(write_pipe, b'x') # halt the thread + if post_flash_script: + self.run_custom_script(post_flash_script, 30) + + t.join(self.timeout) if t.is_alive(): + logger.debug("Timed out while monitoring serial output on {}".format(self.instance.platform.name)) out_state = "timeout" if ser.isOpen(): ser.close() + os.close(write_pipe) + os.close(read_pipe) + handler_time = time.time() - start_time if out_state == "timeout": @@ -828,15 +845,7 @@ class DeviceHandler(Handler): self.set_state(out_state, handler_time) if post_script: - with subprocess.Popen(post_script, stderr=subprocess.PIPE, stdout=subprocess.PIPE) as proc: - try: - (stdout, stderr) = proc.communicate(timeout=30) - logger.debug(stdout.decode()) - - except subprocess.TimeoutExpired: - proc.kill() - (stdout, stderr) = proc.communicate() - logger.error("{} timed out".format(post_script)) + self.run_custom_script(post_script, 30) self.make_device_available(serial_device) @@ -1645,7 +1654,7 @@ class TestInstance: self.platform = platform self.status = None - self.reason = "N/A" + self.reason = "Unknown" self.metrics = dict() self.handler = None self.outdir = outdir @@ -1830,14 +1839,12 @@ class CMake(): with open(os.path.join(self.build_dir, self.log), "a") as log: log.write(log_msg) - overflow_flash = "region `FLASH' overflowed by" - overflow_ram = "region `RAM' overflowed by" - if log_msg: - if log_msg.find(overflow_flash) > 0 or log_msg.find(overflow_ram) > 0: - logger.debug("RAM/ROM Overflow") + res = re.findall("region `(FLASH|RAM|SRAM)' overflowed by", log_msg) + if res: + logger.debug("Test skipped due to {} Overflow".format(res[0])) self.instance.status = "skipped" - self.instance.reason = "overflow" + self.instance.reason = "{} overflow".format(res[0]) else: self.instance.status = "failed" self.instance.reason = "Build failure" @@ -1891,12 +1898,13 @@ class CMake(): if p.returncode == 0: filter_results = self.parse_generated() msg = "Finished building %s for %s" % (self.source_dir, self.platform.name) - + logger.debug(msg) results = {'msg': msg, 'filter': filter_results} else: self.instance.status = "failed" self.instance.reason = "Cmake build failure" + logger.error("Cmake build failure: %s for %s" % (self.source_dir, self.platform.name)) results = {"returncode": p.returncode} if out: @@ -2021,10 +2029,10 @@ class ProjectBuilder(FilterBuilder): if os.path.exists(v_log) and "Valgrind" in self.instance.reason: self.log_info("{}".format(v_log), inline_logs) - elif os.path.exists(d_log) and os.path.getsize(d_log) > 0: - self.log_info("{}".format(d_log), inline_logs) elif os.path.exists(h_log) and os.path.getsize(h_log) > 0: self.log_info("{}".format(h_log), inline_logs) + elif os.path.exists(d_log) and os.path.getsize(d_log) > 0: + self.log_info("{}".format(d_log), inline_logs) else: self.log_info("{}".format(b_log), inline_logs) @@ -2464,7 +2472,7 @@ class TestSuite: board_root) for file in glob.glob(os.path.join(board_root, "*", "*", "*.yaml")): - logger.debug("Found plaform configuration " + file) + logger.debug("Found platform configuration " + file) try: platform = Platform() platform.load(file) @@ -2890,6 +2898,7 @@ class TestSuite: try: data = future.result() except Exception as exc: + logger.error('%r generated an exception: %s' % (test, exc)) sys.exit('%r generated an exception: %s' % (test, exc)) else: @@ -3785,7 +3794,8 @@ class HardwareMap: 'Silicon Labs', 'NXP Semiconductors', 'Microchip Technology Inc.', - 'FTDI' + 'FTDI', + 'Digilent' ] runner_mapping = {