areusch commented on a change in pull request #8236:
URL: https://github.com/apache/tvm/pull/8236#discussion_r650106599



##########
File path: python/tvm/micro/contrib/zephyr.py
##########
@@ -703,6 +718,35 @@ def write(self, data, timeout_sec):
             raise TransportClosedError()
         return self.fd_transport.write(data, timeout_sec)
 
+    def _qemu_check_stdout(self):
+        for line in self.proc.stdout:
+            line = str(line)
+            _LOG.debug(line)
+            if "[QEMU] CPU" in line:
+                self._queue.put(ZephyrQemuMakeResult.QEMU_STARTED)
+            else:
+                line = re.sub("[^a-zA-Z0-9 \n]", "", line)
+                pattern = r"recipe for target (\w*) failed"
+                if re.search(pattern, line, re.IGNORECASE):
+                    self._queue.put(ZephyrQemuMakeResult.MAKE_FAILED)
+        self._queue.put("EOF")

Review comment:
       use the enum here

##########
File path: tests/micro/zephyr/test_zephyr_aot.py
##########
@@ -211,5 +213,45 @@ def test_tflite(platform, west_cmd, skip_build, tvm_debug):
     assert result == 8
 
 
+def test_qemu_make_fail(platform, west_cmd, skip_build, tvm_debug):
+    """Testing QEMU make fail."""
+    model, zephyr_board = PLATFORMS[platform]
+    build_config = {"skip_build": skip_build, "debug": tvm_debug}
+    shape = (10,)
+    dtype = "float32"
+
+    this_dir = pathlib.Path(__file__).parent
+    tvm_source_dir = this_dir / ".." / ".." / ".."
+    runtime_path = tvm_source_dir / "apps" / "microtvm" / "zephyr" / "aot_demo"
+
+    # Construct Relay program.
+    x = relay.var("x", relay.TensorType(shape=shape, dtype=dtype))
+    xx = relay.multiply(x, x)
+    z = relay.add(xx, relay.const(np.ones(shape=shape, dtype=dtype)))
+    func = relay.Function([x], z)
+
+    target = tvm.target.target.micro(model, options=["-link-params=1", 
"--executor=aot"])
+    with tvm.transform.PassContext(opt_level=3, 
config={"tir.disable_vectorize": True}):
+        lowered = relay.build(func, target)
+
+    # Generate input/output header files
+    model_files_path = os.path.join(runtime_path, "include")
+    _create_header_file((f"input_data"), np.zeros(shape=shape, dtype=dtype), 
model_files_path)
+    _create_header_file("output_data", np.zeros(shape=shape, dtype=dtype), 
model_files_path)
+
+    session_kw = _build_session_kw(
+        model, target, zephyr_board, west_cmd, lowered.lib, runtime_path, 
build_config
+    )
+
+    file_path = os.path.join(session_kw["binary"].base_dir, 
"zephyr/CMakeFiles/run.dir/build.make")
+    assert os.path.isfile(file_path), f"[{file_path}] does not exist."
+
+    # Remove a file to create make failure.
+    os.remove(file_path)
+    transport = session_kw["flasher"].flash(session_kw["binary"])
+    with pytest.raises(RuntimeError):

Review comment:
       can you assert any further on the error? This is just our generic 
"anything went wrong in C++-land" exception, so this test will allow pretty 
much any error. e.g.
   
   ```
   with pytest.raises(RuntimeError) as exc:
     transport.open()
   
   assert "QEMU setup failed" in str(exc.value)
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to