diff options
Diffstat (limited to 'support/testing/infra/__init__.py')
| -rw-r--r-- | support/testing/infra/__init__.py | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/support/testing/infra/__init__.py b/support/testing/infra/__init__.py index c3f645cf99..a55ad7fdf5 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/" -@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) @@ -77,6 +70,16 @@ def get_file_arch(builddir, prefix, fpath): return get_elf_arch_tag(builddir, prefix, fpath, "Tag_CPU_arch") def get_elf_prog_interpreter(builddir, prefix, fpath): + """ + Runs the cross readelf on 'fpath' to extract the program interpreter + name and returns it. + Example: + >>> get_elf_prog_interpreter('br-tests/TestExternalToolchainLinaroArm', + 'arm-linux-gnueabihf', + 'bin/busybox') + /lib/ld-linux-armhf.so.3 + >>> + """ cmd = ["host/usr/bin/{}-readelf".format(prefix), "-l", os.path.join("target", fpath)] out = subprocess.check_output(cmd, cwd=builddir, env={"LANG": "C"}) |

