* [Buildroot] [PATCH 1/3] support/testing: show messages in a more readable format
@ 2017-05-10 21:33 Luca Ceresoli
2017-05-10 21:33 ` [Buildroot] [PATCH 2/3] support/testing: remove unused variable Luca Ceresoli
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Luca Ceresoli @ 2017-05-10 21:33 UTC (permalink / raw)
To: buildroot
Currently messages from run-tests are quite unpleasant:
[br-tests/TestPostScripts/2017-05-09 15:51:57] Building
[br-tests/TestPostScripts/2017-05-09 15:52:23] Building done
[br-tests/TestPostScripts/2017-05-09 15:52:23] Cleaning up
.[br-tests/TestNoTimezone/2017-05-09 15:52:23] Starting
[br-tests/TestNoTimezone/2017-05-09 15:52:23] Building
[br-tests/TestNoTimezone/2017-05-09 15:53:17] Building done
[br-tests/TestNoTimezone/2017-05-09 15:53:22] Cleaning up
.[br-tests/TestGlibcNonDefaultLimitedTimezone/2017-05-09 15:53:22] Starting
[br-tests/TestGlibcNonDefaultLimitedTimezone/2017-05-09 15:53:22] Building
[br-tests/TestGlibcNonDefaultLimitedTimezone/2017-05-09 15:54:33] Building done
[br-tests/TestGlibcNonDefaultLimitedTimezone/2017-05-09 15:54:37] Cleaning up
[...]
Change them in a more readable way by removing the date and using a
columnar style:
15:12:22 TestPostScripts Starting
15:12:25 TestPostScripts Building
15:12:48 TestPostScripts Building done
15:12:48 TestPostScripts Cleaning up
.15:12:48 TestNoTimezone Starting
15:12:54 TestNoTimezone Building
15:13:44 TestNoTimezone Building done
15:13:49 TestNoTimezone Cleaning up
.15:13:49 TestGlibcNonDefaultLimitedTimezone Starting
15:14:00 TestGlibcNonDefaultLimitedTimezone Building
15:14:56 TestGlibcNonDefaultLimitedTimezone Building done
15:15:01 TestGlibcNonDefaultLimitedTimezone Cleaning up
[...]
Note the '.' and other characters presented by nose2 are still
printed. They are not affected by this change.
Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net>
---
support/testing/infra/basetest.py | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/support/testing/infra/basetest.py b/support/testing/infra/basetest.py
index eb9da90119ac..cb5d2100f44a 100644
--- a/support/testing/infra/basetest.py
+++ b/support/testing/infra/basetest.py
@@ -36,10 +36,8 @@ class BRTest(unittest.TestCase):
keepbuilds = False
def show_msg(self, msg):
- print "[%s/%s/%s] %s" % (os.path.basename(self.__class__.outputdir),
- self.testname,
- datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
- msg)
+ print "{} {:40s} {}".format(datetime.datetime.now().strftime("%H:%M:%S"),
+ self.testname, msg)
def setUp(self):
self.testname = self.__class__.__name__
self.builddir = os.path.join(self.__class__.outputdir, self.testname)
--
2.7.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* [Buildroot] [PATCH 2/3] support/testing: remove unused variable 2017-05-10 21:33 [Buildroot] [PATCH 1/3] support/testing: show messages in a more readable format Luca Ceresoli @ 2017-05-10 21:33 ` Luca Ceresoli 2017-05-10 21:42 ` Thomas Petazzoni 2017-05-10 21:33 ` [Buildroot] [PATCH 3/3] support/testing: simplify logging by keeping the log file open Luca Ceresoli 2017-05-10 21:42 ` [Buildroot] [PATCH 1/3] support/testing: show messages in a more readable format Thomas Petazzoni 2 siblings, 1 reply; 6+ messages in thread From: Luca Ceresoli @ 2017-05-10 21:33 UTC (permalink / raw) To: buildroot Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> --- support/testing/infra/basetest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/support/testing/infra/basetest.py b/support/testing/infra/basetest.py index cb5d2100f44a..557baa215c65 100644 --- a/support/testing/infra/basetest.py +++ b/support/testing/infra/basetest.py @@ -41,7 +41,6 @@ class BRTest(unittest.TestCase): def setUp(self): self.testname = self.__class__.__name__ self.builddir = os.path.join(self.__class__.outputdir, self.testname) - self.runlog = self.builddir + "-run.log" self.emulator = None self.show_msg("Starting") self.b = Builder(self.__class__.config, self.builddir, self.logtofile) -- 2.7.4 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Buildroot] [PATCH 2/3] support/testing: remove unused variable 2017-05-10 21:33 ` [Buildroot] [PATCH 2/3] support/testing: remove unused variable Luca Ceresoli @ 2017-05-10 21:42 ` Thomas Petazzoni 0 siblings, 0 replies; 6+ messages in thread From: Thomas Petazzoni @ 2017-05-10 21:42 UTC (permalink / raw) To: buildroot Hello, On Wed, 10 May 2017 23:33:45 +0200, Luca Ceresoli wrote: > Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> > --- > support/testing/infra/basetest.py | 1 - > 1 file changed, 1 deletion(-) Applied to master, thanks. Thomas -- Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Buildroot] [PATCH 3/3] support/testing: simplify logging by keeping the log file open 2017-05-10 21:33 [Buildroot] [PATCH 1/3] support/testing: show messages in a more readable format Luca Ceresoli 2017-05-10 21:33 ` [Buildroot] [PATCH 2/3] support/testing: remove unused variable Luca Ceresoli @ 2017-05-10 21:33 ` Luca Ceresoli 2017-05-17 20:00 ` Thomas Petazzoni 2017-05-10 21:42 ` [Buildroot] [PATCH 1/3] support/testing: show messages in a more readable format Thomas Petazzoni 2 siblings, 1 reply; 6+ messages in thread From: Luca Ceresoli @ 2017-05-10 21:33 UTC (permalink / raw) To: buildroot 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> --- support/testing/infra/__init__.py | 21 +++++++-------------- support/testing/infra/builder.py | 12 +++--------- support/testing/infra/emulator.py | 15 +++++---------- 3 files changed, 15 insertions(+), 33 deletions(-) diff --git a/support/testing/infra/__init__.py b/support/testing/infra/__init__.py index c3f645cf99d7..b0427e706ca6 100644 --- a/support/testing/infra/__init__.py +++ b/support/testing/infra/__init__.py @@ -8,24 +8,17 @@ from urllib2 import urlopen, HTTPError, URLError ARTIFACTS_URL = "http://autobuild.buildroot.net/artefacts/" - at contextlib.contextmanager -def smart_open(filename=None): +def open_log_file(builddir, stage, logtofile=True): """ - Return a file-like object that can be written to using the 'with' - keyword, as in the example: - with infra.smart_open("test.log") as outfile: - outfile.write("Hello, world!\n") + Open a file for logging and return its handler. + If logtofile is True, returns sys.stdout. Otherwise opens a file + with a suitable name in the build directory. """ - if filename and filename != '-': - fhandle = open(filename, 'a+') + if logtofile: + fhandle = open("{}-{}.log".format(builddir, stage), 'a+') else: fhandle = sys.stdout - - try: - yield fhandle - finally: - if fhandle is not sys.stdout: - fhandle.close() + return fhandle def filepath(relpath): return os.path.join(os.getcwd(), "support/testing", relpath) diff --git a/support/testing/infra/builder.py b/support/testing/infra/builder.py index 105da01ca2fa..a475bb0a3021 100644 --- a/support/testing/infra/builder.py +++ b/support/testing/infra/builder.py @@ -8,16 +8,12 @@ class Builder(object): def __init__(self, config, builddir, logtofile): self.config = config self.builddir = builddir - self.logtofile = logtofile + self.logfile = infra.open_log_file(builddir, "build", logtofile) def build(self): if not os.path.isdir(self.builddir): os.makedirs(self.builddir) - log = "{}-build.log".format(self.builddir) - if not self.logtofile: - log = None - config_file = os.path.join(self.builddir, ".config") with open(config_file, "w+") as cf: cf.write(self.config) @@ -25,14 +21,12 @@ class Builder(object): cmd = ["make", "O={}".format(self.builddir), "olddefconfig"] - with infra.smart_open(log) as log_fh: - ret = subprocess.call(cmd, stdout=log_fh, stderr=log_fh) + ret = subprocess.call(cmd, stdout=self.logfile, stderr=self.logfile) if ret != 0: raise SystemError("Cannot olddefconfig") cmd = ["make", "-C", self.builddir] - with infra.smart_open(log) as log_fh: - ret = subprocess.call(cmd, stdout=log_fh, stderr=log_fh) + ret = subprocess.call(cmd, stdout=self.logfile, stderr=self.logfile) if ret != 0: raise SystemError("Build failed") diff --git a/support/testing/infra/emulator.py b/support/testing/infra/emulator.py index 7c476cb0e494..2480b4654056 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") -- 2.7.4 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Buildroot] [PATCH 3/3] support/testing: simplify logging by keeping the log file open 2017-05-10 21:33 ` [Buildroot] [PATCH 3/3] support/testing: simplify logging by keeping the log file open Luca Ceresoli @ 2017-05-17 20:00 ` Thomas Petazzoni 0 siblings, 0 replies; 6+ messages in thread From: Thomas Petazzoni @ 2017-05-17 20:00 UTC (permalink / raw) To: buildroot Hello, On Wed, 10 May 2017 23:33:46 +0200, Luca Ceresoli wrote: > 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> > --- > support/testing/infra/__init__.py | 21 +++++++-------------- > support/testing/infra/builder.py | 12 +++--------- > support/testing/infra/emulator.py | 15 +++++---------- > 3 files changed, 15 insertions(+), 33 deletions(-) Applied to master, thanks. Thomas -- Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Buildroot] [PATCH 1/3] support/testing: show messages in a more readable format 2017-05-10 21:33 [Buildroot] [PATCH 1/3] support/testing: show messages in a more readable format Luca Ceresoli 2017-05-10 21:33 ` [Buildroot] [PATCH 2/3] support/testing: remove unused variable Luca Ceresoli 2017-05-10 21:33 ` [Buildroot] [PATCH 3/3] support/testing: simplify logging by keeping the log file open Luca Ceresoli @ 2017-05-10 21:42 ` Thomas Petazzoni 2 siblings, 0 replies; 6+ messages in thread From: Thomas Petazzoni @ 2017-05-10 21:42 UTC (permalink / raw) To: buildroot Hello, On Wed, 10 May 2017 23:33:44 +0200, Luca Ceresoli wrote: > Currently messages from run-tests are quite unpleasant: > > [br-tests/TestPostScripts/2017-05-09 15:51:57] Building > [br-tests/TestPostScripts/2017-05-09 15:52:23] Building done > [br-tests/TestPostScripts/2017-05-09 15:52:23] Cleaning up > .[br-tests/TestNoTimezone/2017-05-09 15:52:23] Starting > [br-tests/TestNoTimezone/2017-05-09 15:52:23] Building > [br-tests/TestNoTimezone/2017-05-09 15:53:17] Building done > [br-tests/TestNoTimezone/2017-05-09 15:53:22] Cleaning up > .[br-tests/TestGlibcNonDefaultLimitedTimezone/2017-05-09 15:53:22] Starting > [br-tests/TestGlibcNonDefaultLimitedTimezone/2017-05-09 15:53:22] Building > [br-tests/TestGlibcNonDefaultLimitedTimezone/2017-05-09 15:54:33] Building done > [br-tests/TestGlibcNonDefaultLimitedTimezone/2017-05-09 15:54:37] Cleaning up > [...] > > Change them in a more readable way by removing the date and using a > columnar style: > > 15:12:22 TestPostScripts Starting > 15:12:25 TestPostScripts Building > 15:12:48 TestPostScripts Building done > 15:12:48 TestPostScripts Cleaning up > .15:12:48 TestNoTimezone Starting > 15:12:54 TestNoTimezone Building > 15:13:44 TestNoTimezone Building done > 15:13:49 TestNoTimezone Cleaning up > .15:13:49 TestGlibcNonDefaultLimitedTimezone Starting > 15:14:00 TestGlibcNonDefaultLimitedTimezone Building > 15:14:56 TestGlibcNonDefaultLimitedTimezone Building done > 15:15:01 TestGlibcNonDefaultLimitedTimezone Cleaning up > [...] > > Note the '.' and other characters presented by nose2 are still > printed. They are not affected by this change. > > Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> > --- > support/testing/infra/basetest.py | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) Applied to master, thanks. Thomas -- Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-05-17 20:00 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-05-10 21:33 [Buildroot] [PATCH 1/3] support/testing: show messages in a more readable format Luca Ceresoli 2017-05-10 21:33 ` [Buildroot] [PATCH 2/3] support/testing: remove unused variable Luca Ceresoli 2017-05-10 21:42 ` Thomas Petazzoni 2017-05-10 21:33 ` [Buildroot] [PATCH 3/3] support/testing: simplify logging by keeping the log file open Luca Ceresoli 2017-05-17 20:00 ` Thomas Petazzoni 2017-05-10 21:42 ` [Buildroot] [PATCH 1/3] support/testing: show messages in a more readable format Thomas Petazzoni
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox