summaryrefslogtreecommitdiff
path: root/meta-arm/meta-arm/lib/oeqa/controllers/fvp.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta-arm/meta-arm/lib/oeqa/controllers/fvp.py')
-rw-r--r--meta-arm/meta-arm/lib/oeqa/controllers/fvp.py127
1 files changed, 59 insertions, 68 deletions
diff --git a/meta-arm/meta-arm/lib/oeqa/controllers/fvp.py b/meta-arm/meta-arm/lib/oeqa/controllers/fvp.py
index c8dcf2982d..e8a094f1df 100644
--- a/meta-arm/meta-arm/lib/oeqa/controllers/fvp.py
+++ b/meta-arm/meta-arm/lib/oeqa/controllers/fvp.py
@@ -1,4 +1,3 @@
-import asyncio
import pathlib
import pexpect
import os
@@ -13,7 +12,7 @@ class OEFVPSSHTarget(OESSHTarget):
Contains common logic to start and stop an FVP.
"""
def __init__(self, logger, target_ip, server_ip, timeout=300, user='root',
- port=None, dir_image=None, rootfs=None, **kwargs):
+ port=None, dir_image=None, rootfs=None, bootlog=None, **kwargs):
super().__init__(logger, target_ip, server_ip, timeout, user, port)
image_dir = pathlib.Path(dir_image)
# rootfs may have multiple extensions so we need to strip *all* suffixes
@@ -21,36 +20,40 @@ class OEFVPSSHTarget(OESSHTarget):
basename = basename.name.replace("".join(basename.suffixes), "")
self.fvpconf = image_dir / (basename + ".fvpconf")
self.config = conffile.load(self.fvpconf)
+ self.bootlog = bootlog
if not self.fvpconf.exists():
raise FileNotFoundError(f"Cannot find {self.fvpconf}")
- async def boot_fvp(self):
- self.fvp = runner.FVPRunner(self.logger)
- await self.fvp.start(self.config)
- self.logger.debug(f"Started FVP PID {self.fvp.pid()}")
- await self._after_start()
-
- async def _after_start(self):
+ def _after_start(self):
pass
- async def _after_stop(self):
- pass
-
- async def stop_fvp(self):
- returncode = await self.fvp.stop()
- await self._after_stop()
-
- self.logger.debug(f"Stopped FVP with return code {returncode}")
-
def start(self, **kwargs):
- # When we can assume Py3.7+, this can simply be asyncio.run()
- loop = asyncio.get_event_loop()
- loop.run_until_complete(asyncio.gather(self.boot_fvp()))
+ self.fvp_log = self._create_logfile("fvp")
+ self.fvp = runner.FVPRunner(self.logger)
+ self.fvp.start(self.config, stdout=self.fvp_log)
+ self.logger.debug(f"Started FVP PID {self.fvp.pid()}")
+ self._after_start()
def stop(self, **kwargs):
- loop = asyncio.get_event_loop()
- loop.run_until_complete(asyncio.gather(self.stop_fvp()))
+ returncode = self.fvp.stop()
+ self.logger.debug(f"Stopped FVP with return code {returncode}")
+
+ def _create_logfile(self, name):
+ if not self.bootlog:
+ return None
+
+ test_log_path = pathlib.Path(self.bootlog).parent
+ test_log_suffix = pathlib.Path(self.bootlog).suffix
+ fvp_log_file = f"{name}_log{test_log_suffix}"
+ fvp_log_path = pathlib.Path(test_log_path, fvp_log_file)
+ fvp_log_symlink = pathlib.Path(test_log_path, f"{name}_log")
+ try:
+ os.remove(fvp_log_symlink)
+ except:
+ pass
+ os.symlink(fvp_log_file, fvp_log_symlink)
+ return open(fvp_log_path, 'wb')
class OEFVPTarget(OEFVPSSHTarget):
@@ -59,31 +62,34 @@ class OEFVPTarget(OEFVPSSHTarget):
waits for a Linux shell before returning to ensure that SSH commands work
with the default test dependencies.
"""
- def __init__(self, logger, target_ip, server_ip, bootlog=None, **kwargs):
+ def __init__(self, logger, target_ip, server_ip, **kwargs):
super().__init__(logger, target_ip, server_ip, **kwargs)
- self.logfile = bootlog and open(bootlog, "wb") or None
+ self.logfile = self.bootlog and open(self.bootlog, "wb") or None
# FVPs boot slowly, so allow ten minutes
self.boot_timeout = 10 * 60
- async def _after_start(self):
- self.logger.debug(f"Awaiting console on terminal {self.config['consoles']['default']}")
- console = await self.fvp.create_pexpect(self.config['consoles']['default'])
- try:
- console.expect("login\\:", timeout=self.boot_timeout)
- self.logger.debug("Found login prompt")
- except pexpect.TIMEOUT:
- self.logger.info("Timed out waiting for login prompt.")
- self.logger.info("Boot log follows:")
- self.logger.info(b"\n".join(console.before.splitlines()[-200:]).decode("utf-8", errors="replace"))
- raise RuntimeError("Failed to start FVP.")
+ def _after_start(self):
+ with open(self.fvp_log.name, 'rb') as logfile:
+ parser = runner.ConsolePortParser(logfile)
+ self.logger.debug(f"Awaiting console on terminal {self.config['consoles']['default']}")
+ port = parser.parse_port(self.config['consoles']['default'])
+ console = self.fvp.create_pexpect(port)
+ try:
+ console.expect("login\\:", timeout=self.boot_timeout)
+ self.logger.debug("Found login prompt")
+ except pexpect.TIMEOUT:
+ self.logger.info("Timed out waiting for login prompt.")
+ self.logger.info("Boot log follows:")
+ self.logger.info(b"\n".join(console.before.splitlines()[-200:]).decode("utf-8", errors="replace"))
+ raise RuntimeError("Failed to start FVP.")
class OEFVPSerialTarget(OEFVPSSHTarget):
"""
This target is intended for interaction with the target over one or more
telnet consoles using pexpect.
-
+
This still depends on OEFVPSSHTarget so SSH commands can still be run on
the target, but note that this class does not inherently guarantee that
the SSH server is running prior to running test cases. Test cases that use
@@ -92,40 +98,25 @@ class OEFVPSerialTarget(OEFVPSSHTarget):
"""
DEFAULT_CONSOLE = "default"
- def __init__(self, logger, target_ip, server_ip, bootlog=None, **kwargs):
+ def __init__(self, logger, target_ip, server_ip, **kwargs):
super().__init__(logger, target_ip, server_ip, **kwargs)
self.terminals = {}
- self.test_log_path = pathlib.Path(bootlog).parent
- self.test_log_suffix = pathlib.Path(bootlog).suffix
- self.bootlog = bootlog
-
- async def _add_terminal(self, name, fvp_name):
- logfile = self._create_logfile(name)
- self.logger.info(f'Creating terminal {name} on {fvp_name}')
- self.terminals[name] = \
- await self.fvp.create_pexpect(fvp_name, logfile=logfile)
-
- def _create_logfile(self, name):
- fvp_log_file = f"{name}_log{self.test_log_suffix}"
- fvp_log_path = pathlib.Path(self.test_log_path, fvp_log_file)
- fvp_log_symlink = pathlib.Path(self.test_log_path, f"{name}_log")
- try:
- os.remove(fvp_log_symlink)
- except:
- pass
- os.symlink(fvp_log_file, fvp_log_symlink)
- return open(fvp_log_path, 'wb')
-
- async def _after_start(self):
- for name, console in self.config["consoles"].items():
- await self._add_terminal(name, console)
-
- # testimage.bbclass expects to see a log file at `bootlog`,
- # so make a symlink to the 'default' log file
- if name == 'default':
- default_test_file = f"{name}_log{self.test_log_suffix}"
- os.symlink(default_test_file, self.bootlog)
+ def _after_start(self):
+ with open(self.fvp_log.name, 'rb') as logfile:
+ parser = runner.ConsolePortParser(logfile)
+ for name, console in self.config["consoles"].items():
+ logfile = self._create_logfile(name)
+ self.logger.info(f'Creating terminal {name} on {console}')
+ port = parser.parse_port(console)
+ self.terminals[name] = \
+ self.fvp.create_pexpect(port, logfile=logfile)
+
+ # testimage.bbclass expects to see a log file at `bootlog`,
+ # so make a symlink to the 'default' log file
+ if name == 'default':
+ default_test_file = f"{name}_log{self.test_log_suffix}"
+ os.symlink(default_test_file, self.bootlog)
def _get_terminal(self, name):
return self.terminals[name]