support/testing: show messages in a more readable format
PATCH 1/3 support/testing: show messages in a more readable format
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.
--- support/testing/infra/basetest.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
support/testing/infra/basetest.py +2 -4
@@ -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)
Signature · 1 line
2.7.4
PATCH 2/3 support/testing: remove unused variable
--- support/testing/infra/basetest.py | 1 - 1 file changed, 1 deletion(-)
support/testing/infra/basetest.py +0 -1
@@ -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)
Signature · 1 line
2.7.4
Thomas Petazzoni
AppliedPATCH 2/3 support/testing: remove unused variable
Hello,
Quoted 4 lines · Luca Ceresoli
Signed-off-by Luca Ceresoli <[email protected]>--- support/testing/infra/basetest.py | 1 - 1 file changed, 1 deletion(-)
Applied to master, thanks.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH 3/3 support/testing: simplify logging by keeping the log file open
In reply to Luca CeresoliWe 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.
--- 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(-)
support/testing/infra/__init__.py +7 -14
@@ -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)
support/testing/infra/builder.py +3 -9
@@ -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")
support/testing/infra/emulator.py +5 -10
@@ -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")
Signature · 1 line
2.7.4
Thomas Petazzoni
AppliedPATCH 3/3 support/testing: simplify logging by keeping the log file open
Hello,
Quoted 10 lines · Luca Ceresoli
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_openand instead create a newopen_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.
Quoted 6 lines
Signed-off-by Luca Ceresoli <[email protected]>--- 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
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
Thomas Petazzoni
AppliedPATCH 1/3 support/testing: show messages in a more readable format
In reply to Luca CeresoliHello,
Quoted 32 lines · Luca Ceresoli
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[...]
Quoted 7 lines
Note the '.' and other characters presented by nose2 are still printed. They are not affected by this change.
Signed-off-by Luca Ceresoli <[email protected]>--- support/testing/infra/basetest.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
Applied to master, thanks.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com