support/testing: allow run-tests to be called from anywhere
authorRicardo Martincoski <ricardo.martincoski@gmail.com>
Sun, 4 Nov 2018 04:12:06 +0000 (02:12 -0200)
committerArnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Sat, 3 Aug 2019 15:17:29 +0000 (17:17 +0200)
Currently run-tests must be called from the Buildroot top directory.

Derive the top directory from the script path, so run-tests can be called from
any path.
As a consequence the test infra will always test the repo it belongs to.

Suggested-by: Yann E. MORIN <yann.morin.1998@free.fr>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Cc: Arnout Vandecappelle <arnout@mind.be>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Yann E. MORIN <yann.morin.1998@free.fr>
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
support/testing/infra/__init__.py
support/testing/infra/builder.py

index e229e9085273839493170a92b76e6d8e417e793f..1d4d18bbe98f1f48758877db1fa205bbac0e3ae6 100644 (file)
@@ -6,6 +6,7 @@ import subprocess
 from urllib2 import urlopen, HTTPError, URLError
 
 ARTIFACTS_URL = "http://autobuild.buildroot.net/artefacts/"
+BASE_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), "../../.."))
 
 
 def open_log_file(builddir, stage, logtofile=True):
@@ -21,8 +22,13 @@ def open_log_file(builddir, stage, logtofile=True):
     return fhandle
 
 
+def basepath(relpath=""):
+    """Return the absolute path for a file or directory relative to the Buildroot top directory."""
+    return os.path.join(BASE_DIR, relpath)
+
+
 def filepath(relpath):
-    return os.path.join(os.getcwd(), "support/testing", relpath)
+    return os.path.join(BASE_DIR, "support/testing", relpath)
 
 
 def download(dldir, filename):
index 018747555d9a97da73ff0ccd332f79e6848edefe..88f01d15c0574c75a3f20cd9473989d285077b98 100644 (file)
@@ -43,7 +43,7 @@ class Builder(object):
         cmd += ["olddefconfig"]
 
         ret = subprocess.call(cmd, stdout=self.logfile, stderr=self.logfile,
-                              env=env)
+                              cwd=infra.basepath(), env=env)
         if ret != 0:
             raise SystemError("Cannot olddefconfig")