@@ -5,6 +5,9 @@ import tempfile
import subprocess
from urllib2 import urlopen, HTTPError, URLError
+# make exceptions available to all tests with just 'import infra'
+import infra.exceptions
+
ARTIFACTS_URL = "http://autobuild.buildroot.net/artefacts/"
@@ -45,7 +45,7 @@ class Builder(object):
ret = subprocess.call(cmd, stdout=self.logfile, stderr=self.logfile,
env=env)
if ret != 0:
- raise SystemError("Cannot olddefconfig")
+ raise infra.exceptions.ConfigurationError("Cannot olddefconfig")
def build(self, make_extra_opts=[], make_extra_env={}):
"""Perform the build.
@@ -72,7 +72,7 @@ class Builder(object):
ret = subprocess.call(cmd, stdout=self.logfile, stderr=self.logfile,
env=env)
if ret != 0:
- raise SystemError("Build failed")
+ raise infra.exceptions.BuildError
open(self.stamp_path(), 'a').close()
@@ -84,7 +84,7 @@ class Emulator(object):
timeout=60 * self.timeout_multiplier)
if index != 0:
self.logfile.write("==> System does not boot")
- raise SystemError("System does not boot")
+ raise infra.exceptions.BootError
self.qemu.sendline("root")
if password:
@@ -92,7 +92,7 @@ class Emulator(object):
self.qemu.sendline(password)
index = self.qemu.expect(["# ", pexpect.TIMEOUT])
if index != 0:
- raise SystemError("Cannot login")
+ raise infra.exceptions.LoginError
self.run("dmesg -n 1")
# Run the given 'cmd' with a 'timeout' on the target
new file mode 100644
@@ -0,0 +1,27 @@
+"""Custom exception classes for use by the test suite."""
+
+class BootError(Exception):
+ """System does not boot correctly."""
+ pass
+
+
+class LoginError(Exception):
+ """Cannot login to system."""
+ pass
+
+
+class ConfigurationError(Exception):
+ """Cannot set Buildroot configuration."""
+ pass
+
+
+class BuildError(Exception):
+ """Build failed."""
+ pass
+
+
+class TestError(Exception):
+ """Something went wrong while executing a test.
+
+ The exact cause of this problem should be specified by the caller."""
+ pass
@@ -38,7 +38,7 @@ class GitRemote(object):
if ret == 0:
self.port = port
return
- raise SystemError("Could not find a free port to run git remote")
+ raise infra.exceptions.TestError("Could not find a free port to run git remote")
def stop(self):
if self.daemon is None:
@@ -52,7 +52,7 @@ class TestGitHash(GitTestBase):
br2_external = [infra.filepath("tests/download/br2-external/git-hash")]
def test_run(self):
- with self.assertRaises(SystemError):
+ with self.assertRaises(infra.exceptions.BuildError):
self.check_hash("bad")
self.check_hash("good")
self.check_hash("nohash")
@@ -62,9 +62,9 @@ class TestGitRefs(GitTestBase):
br2_external = [infra.filepath("tests/download/br2-external/git-refs")]
def test_run(self):
- with self.assertRaises(SystemError):
+ with self.assertRaises(infra.exceptions.BuildError):
self.check_download("git-wrong-content")
- with self.assertRaises(SystemError):
+ with self.assertRaises(infra.exceptions.BuildError):
self.check_download("git-wrong-sha1")
self.check_download("git-partial-sha1-branch-head")
self.check_download("git-partial-sha1-reachable-by-branch")
@@ -37,9 +37,5 @@ class TestScpPrimarySite(infra.basetest.BRConfigTest):
self.b.build(["{}-dirclean".format(package),
"{}-source".format(package)],
env)
- except SystemError as e: # FIXME: introduce specific Exception classes
- if str(e) == 'Build failed':
- self.assertFalse('Download error, search for ERROR in the log')
- else:
- # an unexpected error
- raise
+ except infra.exceptions.BuildError:
+ self.assertFalse('Download error, search for ERROR in the log')
@@ -17,11 +17,11 @@ class TestInitSystemNone(InitSystemBase):
index = self.emulator.qemu.expect(["/bin/sh: can't access tty; job control turned off", pexpect.TIMEOUT], timeout=60)
if index != 0:
self.emulator.logfile.write("==> System does not boot")
- raise SystemError("System does not boot")
+ raise infra.exceptions.BootError
index = self.emulator.qemu.expect(["#", pexpect.TIMEOUT], timeout=60)
if index != 0:
self.emulator.logfile.write("==> System does not boot")
- raise SystemError("System does not boot")
+ raise infra.exceptions.BootError
out, exit_code = self.emulator.run("sh -c 'echo $PPID'")
self.assertEqual(exit_code, 0)
@@ -37,7 +37,7 @@ class TestRustBase(infra.basetest.BRTest):
stderr=self.b.logfile,
env=env)
if ret != 0:
- raise SystemError("Cargo init failed")
+ raise infra.exceptions.TestError("Cargo init failed")
cmd = [
cargo, 'build', '-vv', '--target', self.target,
@@ -48,7 +48,7 @@ class TestRustBase(infra.basetest.BRTest):
stderr=self.b.logfile,
env=env)
if ret != 0:
- raise SystemError("Cargo build failed")
+ raise infra.exceptions.TestError("Cargo build failed")
shutil.copy(prog, os.path.join(self.builddir, 'target', 'usr', 'bin'))
self.b.build()