sw:vec: Fix test runner to exit with non-existing elfs

So we don't need to wait for the pexepect timeout with some expected
failed lit tests.

Fix pylint errors discovered in preupload.

Change-Id: Ie744e6a9e4fefd74a97a5e98a74f097eceb8a9fe
diff --git a/scripts/test_runner.py b/scripts/test_runner.py
index d65960a..4b905f2 100755
--- a/scripts/test_runner.py
+++ b/scripts/test_runner.py
@@ -43,6 +43,7 @@
             "main returned",
             "Exception occurred",
             "ReadByte from non existing peripheral",
+            "File does not exist"
         ]
 
     def run(self, timeout=1000):
@@ -51,13 +52,20 @@
         self.child.logfile = self.buffer
         try:
             self.child.expect(self.termination_strings, timeout=timeout)
-        except pexpect.exceptions.TIMEOUT:
+        except pexpect.exceptions.EOF as run_hit_eof:
+            self.buffer.seek(0)
+            message = ("Runner reach EOF with the execution log: \n\n" +
+                       cleanup_message(self.buffer.read()))
+            exc = pexpect.exceptions.EOF(message)
+            exc.__cause__ = None
+            raise exc from run_hit_eof
+        except pexpect.exceptions.TIMEOUT as run_hit_timeout:
             self.buffer.seek(0)
             message = ("Runner times out with the execution log: \n\n" +
                        cleanup_message(self.buffer.read()))
-            exc = pexpect.exceptions.TIMEOUT(message)
+            exc = pexpect.exceptions.EOF(message)
             exc.__cause__ = None
-            raise exc
+            raise exc from run_hit_timeout
         self.child.send("\nq\n")
         self.child.expect(pexpect.EOF, timeout=timeout)
         self.child.close()
@@ -68,7 +76,8 @@
     """ Qemu simulation """
     def __init__(self, path, elf):
         self.qemu_simulator_cmd = (
-            "%(sim)s -M springbok -nographic -d springbok -device loader,file=%(elf)s")
+            "%(sim)s -M springbok -nographic -d springbok "
+            "-device loader,file=%(elf)s")
         self.sim_params = {"sim": path, "elf": elf}
         super().__init__(self.qemu_simulator_cmd % self.sim_params)
 
@@ -98,14 +107,18 @@
 sysbus.cpu2 EnableExternalWindowMmu false
 start
 sysbus.vec_controlblock WriteDoubleWord 0xc 0"""
+
+        trace_file = ""
+        if args.trace_output:
+            trace_file = os.path.realpath(args.trace_output)
         self.script_params = {
             "elf": os.path.realpath(elf),
             "rootdir": self.rootdir,
-            "trace_file": os.path.realpath(args.trace_output) if args.trace_output else ""
+            "trace_file": trace_file
         }
         self.renode_script = renode_script % self.script_params
         self.renode_args = [
-            "%s" % path,
+            f"{path}",
             "--disable-xwt",
             " --console",
             "--plain",
@@ -119,7 +132,7 @@
             with os.fdopen(file_desc, "w") as tmp:
                 tmp.write(self.renode_script)
                 tmp.flush()
-            self.simulator_cmd += " %s" % script_path
+            self.simulator_cmd += f" {script_path}"
             test_output = super().run(timeout=timeout)
         finally:
             os.remove(script_path)
@@ -128,12 +141,17 @@
 class SpikeSimulation(Simulation): # pylint: disable=too-few-public-methods
     """ Spike Simulation """
     def __init__(self, path, elf):
+        trace_file = ""
+        if args.trace_output:
+            trace_file = os.path.realpath(args.trace_output)
         self.sim_params = {
                 "path": path,
                 "elf": elf,
-                "trace_file": os.path.realpath(args.trace_output) if args.trace_output else ""
+                "trace_file": trace_file
                 }
-        self.spike_simulator_cmd = "%(path)s -m0x32000000:0x100000,0x34000000:0x1000000 --pc=0x32000000 "
+        self.spike_simulator_cmd = (
+            "%(path)s -m0x32000000:0x100000,0x34000000:0x1000000 "
+            "--pc=0x32000000 ")
 
         if args.trace_output:
             self.spike_simulator_cmd += " -l --log=%(trace_file)s "
@@ -154,7 +172,8 @@
 }
 
 def cleanup_message(message: str) -> str:
-    """ Clean up the message to get rid of the non-ascii code generated by Mono. """
+    """ Clean up the message to get rid of the non-ascii code generated by
+    Mono. """
     ansi_escape = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
     output = ansi_escape.sub("", message)
     return output
@@ -164,8 +183,8 @@
     simulator_path = simulators_paths[args.simulator]
     if simulator_path is None:
         parser.error(
-            "Must provide path to simulator %s, use argument --%s-path" % (args.simulator,
-                                                                           args.simulator))
+            f"Must provide path to simulator {args.simulator}, "
+            f"use argument --{args.simulator}-path")
 
     simulator_class = Simulators[args.simulator]
     simulator = simulator_class(simulator_path, args.elf)
@@ -175,7 +194,8 @@
     failure_strings = [
         "FAILED",
         "Exception occurred",
-        "ReadByte from non existing peripheral"
+        "ReadByte from non existing peripheral",
+        "File does not exist"
     ]
     if any(x in output for x in failure_strings):
         sys.exit(1)