diff options
author | Luca Ceresoli <luca@lucaceresoli.net> | 2017-05-10 23:33:46 +0200 |
---|---|---|
committer | Thomas Petazzoni <thomas.petazzoni@free-electrons.com> | 2017-05-17 21:59:58 +0200 |
commit | d332f2c52192144d6205b68a1a2888eb63e9efb1 (patch) | |
tree | c060f16a1d7aa15db1bd013a4c50083a55d976f2 /support/testing/infra/emulator.py | |
parent | fa3c5cad44b245833612705a88101f3737d02b38 (diff) | |
download | buildroot-d332f2c52192144d6205b68a1a2888eb63e9efb1.tar.gz buildroot-d332f2c52192144d6205b68a1a2888eb63e9efb1.zip |
support/testing: simplify logging by keeping the log file open
We currently call infra.smart_open() to open log files each time we
need to write to them.
Opening the file once in the constructor of Builder and Emulator and
writing to it whenever needed is simpler and slightly more efficient.
Remove smart_open and instead create a new open_log_file() function
which just opens the logfile. Also let it compute the filename, in
order to simplify even further the Builder and Emulator code.
Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Diffstat (limited to 'support/testing/infra/emulator.py')
-rw-r--r-- | support/testing/infra/emulator.py | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/support/testing/infra/emulator.py b/support/testing/infra/emulator.py index 7c476cb0e4..2480b46540 100644 --- a/support/testing/infra/emulator.py +++ b/support/testing/infra/emulator.py @@ -14,9 +14,7 @@ class Emulator(object): self.__tn = None self.downloaddir = downloaddir self.log = "" - self.log_file = "{}-run.log".format(builddir) - if logtofile is None: - self.log_file = None + self.logfile = infra.open_log_file(builddir, "run", logtofile) # Start Qemu to boot the system # @@ -72,9 +70,8 @@ class Emulator(object): if kernel_cmdline: qemu_cmd += ["-append", " ".join(kernel_cmdline)] - with infra.smart_open(self.log_file) as lfh: - lfh.write("> starting qemu with '%s'\n" % " ".join(qemu_cmd)) - self.qemu = subprocess.Popen(qemu_cmd, stdout=lfh, stderr=lfh) + self.logfile.write("> starting qemu with '%s'\n" % " ".join(qemu_cmd)) + self.qemu = subprocess.Popen(qemu_cmd, stdout=self.logfile, stderr=self.logfile) # Wait for the telnet port to appear and connect to it. while True: @@ -88,8 +85,7 @@ class Emulator(object): def __read_until(self, waitstr, timeout=5): data = self.__tn.read_until(waitstr, timeout) self.log += data - with infra.smart_open(self.log_file) as lfh: - lfh.write(data) + self.logfile.write(data) return data def __write(self, wstr): @@ -100,8 +96,7 @@ class Emulator(object): def login(self, password=None): self.__read_until("buildroot login:", 10) if "buildroot login:" not in self.log: - with infra.smart_open(self.log_file) as lfh: - lfh.write("==> System does not boot") + self.logfile.write("==> System does not boot") raise SystemError("System does not boot") self.__write("root\n") |