class TestGitLab(GitforgeTestBase): br2_external = [infra.filepath("tests/download/br2-external/gitlab")] def test_run(self): self.check_download("gitlab-helper-hash") self.check_download("gitlab-helper-tag") self.check_download("gitlab-release")
class TestGitHash(GitTestBase): br2_external = [infra.filepath("tests/download/br2-external/git-hash")] def test_run(self): with self.assertRaises(SystemError): self.check_hash("bad") self.check_hash("good") self.check_hash("nohash")
class TestPythonPybind(TestPythonPackageBase): __test__ = True config = TestPythonPackageBase.config + \ """ BR2_PACKAGE_PYTHON3=y BR2_PACKAGE_PYTHON_PYBIND_EXAMPLE=y """ sample_scripts = ["tests/package/sample_python_pybind.py"] # ship examples macro & installs it to host br2_external = [infra.filepath("tests/package/br2-external/python-pybind")]
class TestBmapTools(BRTest): __test__ = False sample_script = "tests/package/sample_bmap_tools.sh" copy_script = 'tests/package/copy-sample-script-to-target.sh' config = \ """ BR2_arm=y BR2_cortex_a8=y BR2_TOOLCHAIN_EXTERNAL=y BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y BR2_PACKAGE_BMAP_TOOLS=y BR2_ROOTFS_POST_BUILD_SCRIPT="{}" BR2_ROOTFS_POST_SCRIPT_ARGS="{}" BR2_TARGET_ROOTFS_EXT2=y BR2_TARGET_ROOTFS_EXT2_4=y BR2_TARGET_ROOTFS_EXT2_SIZE="65536" # BR2_TARGET_ROOTFS_TAR is not set BR2_PACKAGE_UTIL_LINUX=y BR2_PACKAGE_UTIL_LINUX_FALLOCATE=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_UTIL_LINUX_LIBUUID=y """.format(infra.filepath(copy_script), infra.filepath(sample_script)) timeout = 60 def login(self): img = os.path.join(self.builddir, "images", "rootfs.ext4") self.emulator.boot(arch="armv7", kernel="builtin", kernel_cmdline=["root=/dev/mmcblk0", "rootfstype=ext4"], options=["-drive", "file={},if=sd,format=raw".format(img)]) self.emulator.login() def test_run(self): self.login() cmd = "/root/{}".format(os.path.basename(self.sample_script)) self.assertRunOk(cmd, timeout=20)
class DetectBadArchTest(infra.basetest.BRConfigTest): config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + infra.basetest.MINIMAL_CONFIG br2_external = [infra.filepath("tests/core/br2-external/detect-bad-arch")] def test_run(self): with self.assertRaises(SystemError): self.b.build() logf_path = infra.log_file_path(self.b.builddir, "build", infra.basetest.BRConfigTest.logtofile) if logf_path: s = 'ERROR: architecture for "/usr/bin/foo" is' with open(logf_path, "r") as f: lines = [line for line in f.readlines() if line.startswith(s)] self.assertEqual(len(lines), 1)
class GitTestBase(infra.basetest.BRConfigTest): config = \ """ BR2_BACKUP_SITE="" """ gitremotedir = infra.filepath("tests/download/git-remote") gitremote = None def setUp(self): super(GitTestBase, self).setUp() self.gitremote = GitRemote(self.builddir, self.gitremotedir, self.logtofile) def tearDown(self): self.show_msg("Cleaning up") if self.gitremote: self.gitremote.stop() if self.b and not self.keepbuilds: self.b.delete() def check_hash(self, package): # store downloaded tarball inside the output dir so the test infra # cleans it up at the end env = { "BR2_DL_DIR": os.path.join(self.builddir, "dl"), "GITREMOTE_PORT_NUMBER": str(self.gitremote.port) } self.b.build( ["{}-dirclean".format(package), "{}-source".format(package)], env) def check_download(self, package): # store downloaded tarball inside the output dir so the test infra # cleans it up at the end dl_dir = os.path.join(self.builddir, "dl") # enforce we test the download if os.path.exists(dl_dir): shutil.rmtree(dl_dir) env = { "BR2_DL_DIR": dl_dir, "GITREMOTE_PORT_NUMBER": str(self.gitremote.port) } self.b.build( ["{}-dirclean".format(package), "{}-legal-info".format(package)], env)
class TestGitRefs(GitTestBase): br2_external = [infra.filepath("tests/download/br2-external/git-refs")] def test_run(self): with self.assertRaises(SystemError): self.check_download("git-wrong-content") with self.assertRaises(SystemError): self.check_download("git-wrong-sha1") self.check_download("git-partial-sha1-branch-head") self.check_download("git-partial-sha1-reachable-by-branch") self.check_download("git-partial-sha1-reachable-by-tag") self.check_download("git-partial-sha1-tag-itself") self.check_download("git-partial-sha1-tag-points-to") self.check_download("git-sha1-branch-head") self.check_download("git-sha1-reachable-by-branch") self.check_download("git-sha1-reachable-by-tag") self.check_download("git-sha1-tag-itself") self.check_download("git-sha1-tag-points-to") self.check_download("git-submodule-disabled") self.check_download("git-submodule-enabled") self.check_download("git-tag")
class SSHTestBase(infra.basetest.BRConfigTest): config = infra.basetest.MINIMAL_CONFIG + ''' BR2_BACKUP_SITE="" ''' sshd_test_dir = infra.filepath("tests/download/sshd") sshd = None def setUp(self): super(SSHTestBase, self).setUp() self.show_msg("Generating keys") tests.download.sshd.generate_keys(self.builddir, self.logtofile) self.show_msg("Starting sshd") self.sshd = tests.download.sshd.OpenSSHDaemon(self.builddir, self.logtofile) def tearDown(self): self.show_msg("Stopping sshd") if self.sshd: self.sshd.stop() super(SSHTestBase, self).tearDown() def download_package(self, package): self.show_msg("Downloading {}".format(package)) # store downloaded tarball inside the output dir so the test infra # cleans it up at the end dl_dir = os.path.join(self.builddir, "dl") ssh_identity = os.path.join(self.builddir, tests.download.sshd.SSH_CLIENT_KEY) # enforce that we test the download if os.path.exists(dl_dir): shutil.rmtree(dl_dir) env = {"BR2_DL_DIR": dl_dir, "SSHD_PORT_NUMBER": str(self.sshd.port), "SSHD_TEST_DIR": self.sshd_test_dir, "SSH_IDENTITY": ssh_identity} self.b.build(["{}-dirclean".format(package), "{}-source".format(package)], env)
class CpeIdTest(infra.basetest.BRConfigTest): config = "" br2_external = [infra.filepath("tests/core/cpeid-br2-external")] def get_vars(self, var): cmd = [ "make", "--no-print-directory", "-C", self.b.builddir, "VARS=%s%%" % var, "printvars" ] lines = subprocess.check_output(cmd).splitlines() return dict([str(x, "utf-8").split("=") for x in lines]) def get_json(self, pkg): cmd = [ "make", "--no-print-directory", "-C", self.b.builddir, "%s-show-info" % pkg ] return json.loads(subprocess.check_output(cmd)) def test_pkg1(self): # this package has no CPE ID information, it should not have # any CPE_ID variable defined. pkg_vars = self.get_vars("CPE_ID_PKG1_CPE_ID") cpe_vars = [ "CPE_ID_VALID", "CPE_ID_PRODUCT", "CPE_ID_VERSION", "CPE_ID_UPDATE", "CPE_ID_PREFIX", "CPE_ID" ] for v in cpe_vars: self.assertNotIn("CPE_ID_PKG1_%s" % v, pkg_vars) pkg_json = self.get_json("cpe-id-pkg1") self.assertNotIn("cpe-id", pkg_json['cpe-id-pkg1']) pkg_vars = self.get_vars("HOST_CPE_ID_PKG1_CPE_ID") for v in cpe_vars: self.assertNotIn("HOST_CPE_ID_PKG1_%s" % v, pkg_vars) pkg_json = self.get_json("host-cpe-id-pkg1") self.assertNotIn("cpe-id", pkg_json['host-cpe-id-pkg1']) def test_pkg2(self): # this package has no CPE ID information, it should not have # any CPE_ID variable defined. pkg_vars = self.get_vars("HOST_CPE_ID_PKG2_CPE_ID") cpe_vars = [ "CPE_ID_VALID", "CPE_ID_PRODUCT", "CPE_ID_VERSION", "CPE_ID_UPDATE", "CPE_ID_PREFIX", "CPE_ID" ] for v in cpe_vars: self.assertNotIn("HOST_CPE_ID_PKG2_%s" % v, pkg_vars) pkg_json = self.get_json("host-cpe-id-pkg2") self.assertNotIn("cpe-id", pkg_json['host-cpe-id-pkg2']) def test_pkg3(self): # this package has just <pkg>_CPE_ID_VENDOR defined, so verify # it has the default CPE_ID value, and that inheritance of the # values for the host package is working pkg_vars = self.get_vars("CPE_ID_PKG3_CPE_ID") self.assertEqual( pkg_vars["CPE_ID_PKG3_CPE_ID"], "cpe:2.3:a:cpe-id-pkg3_project:cpe-id-pkg3:67:*:*:*:*:*:*:*") self.assertEqual(pkg_vars["CPE_ID_PKG3_CPE_ID_VALID"], "YES") pkg_json = self.get_json("cpe-id-pkg3") self.assertEqual( pkg_json['cpe-id-pkg3']['cpe-id'], "cpe:2.3:a:cpe-id-pkg3_project:cpe-id-pkg3:67:*:*:*:*:*:*:*") pkg_vars = self.get_vars("HOST_CPE_ID_PKG3_CPE_ID") self.assertEqual( pkg_vars["HOST_CPE_ID_PKG3_CPE_ID"], "cpe:2.3:a:cpe-id-pkg3_project:cpe-id-pkg3:67:*:*:*:*:*:*:*") self.assertEqual(pkg_vars["HOST_CPE_ID_PKG3_CPE_ID_VALID"], "YES") pkg_json = self.get_json("host-cpe-id-pkg3") self.assertEqual( pkg_json['host-cpe-id-pkg3']['cpe-id'], "cpe:2.3:a:cpe-id-pkg3_project:cpe-id-pkg3:67:*:*:*:*:*:*:*") def test_pkg4(self): # this package defines # <pkg>_CPE_ID_{VENDOR,PRODUCT,VERSION,UPDATE,PREFIX}, # make sure we get the computed <pkg>_CPE_ID, and that it is # inherited by the host variant pkg_vars = self.get_vars("CPE_ID_PKG4_CPE_ID") self.assertEqual(pkg_vars["CPE_ID_PKG4_CPE_ID"], "cpe:2.4:a:foo:bar:42:b2:*:*:*:*:*:*") self.assertEqual(pkg_vars["CPE_ID_PKG4_CPE_ID_VALID"], "YES") pkg_json = self.get_json("cpe-id-pkg4") self.assertEqual(pkg_json['cpe-id-pkg4']['cpe-id'], "cpe:2.4:a:foo:bar:42:b2:*:*:*:*:*:*") pkg_vars = self.get_vars("HOST_CPE_ID_PKG4_CPE_ID") self.assertEqual(pkg_vars["HOST_CPE_ID_PKG4_CPE_ID"], "cpe:2.4:a:foo:bar:42:b2:*:*:*:*:*:*") self.assertEqual(pkg_vars["HOST_CPE_ID_PKG4_CPE_ID_VALID"], "YES") pkg_json = self.get_json("host-cpe-id-pkg4") self.assertEqual(pkg_json['host-cpe-id-pkg4']['cpe-id'], "cpe:2.4:a:foo:bar:42:b2:*:*:*:*:*:*") def test_pkg5(self): # this package defines # <pkg>_CPE_ID_{VENDOR,PRODUCT,VERSION,UPDATE,PREFIX} and # HOST_<pkg>_CPE_ID_{VENDOR,PRODUCT,VERSION,UPDATE,PREFIX} # separately, with different values. Make sure we get the # right <pkg>_CPE_ID and HOST_<pkg>_CPE_ID values. pkg_vars = self.get_vars("CPE_ID_PKG5_CPE_ID") self.assertEqual(pkg_vars["CPE_ID_PKG5_CPE_ID"], "cpe:2.4:a:foo:bar:42:b2:*:*:*:*:*:*") self.assertEqual(pkg_vars["CPE_ID_PKG5_CPE_ID_VALID"], "YES") pkg_json = self.get_json("cpe-id-pkg5") self.assertEqual(pkg_json['cpe-id-pkg5']['cpe-id'], "cpe:2.4:a:foo:bar:42:b2:*:*:*:*:*:*") pkg_vars = self.get_vars("HOST_CPE_ID_PKG5_CPE_ID") self.assertEqual(pkg_vars["HOST_CPE_ID_PKG5_CPE_ID"], "cpe:2.5:a:baz:fuz:43:b3:*:*:*:*:*:*") self.assertEqual(pkg_vars["HOST_CPE_ID_PKG5_CPE_ID_VALID"], "YES") pkg_json = self.get_json("host-cpe-id-pkg5") self.assertEqual(pkg_json['host-cpe-id-pkg5']['cpe-id'], "cpe:2.5:a:baz:fuz:43:b3:*:*:*:*:*:*")
def test_run(self): """Test the various ways the script can be called in a simple top to bottom sequence.""" # an intree file can be checked by the script called from relative path, # absolute path and from PATH for base_script, base_file, rel_script, rel_file, rel_cwd in self.relative: abs_script = infra.basepath(base_script) abs_file = infra.basepath(base_file) cwd = infra.basepath(rel_cwd) _, m = call_script([rel_script, rel_file], self.WITH_EMPTY_PATH, cwd) self.assert_file_was_processed(m) _, m = call_script([abs_script, rel_file], self.WITH_EMPTY_PATH, cwd) self.assert_file_was_processed(m) _, m = call_script(["check-package", rel_file], self.WITH_UTILS_IN_PATH, cwd) self.assert_file_was_processed(m) _, m = call_script([rel_script, abs_file], self.WITH_EMPTY_PATH, cwd) self.assert_file_was_processed(m) _, m = call_script([abs_script, abs_file], self.WITH_EMPTY_PATH, cwd) self.assert_file_was_processed(m) _, m = call_script(["check-package", abs_file], self.WITH_UTILS_IN_PATH, cwd) self.assert_file_was_processed(m) # some intree files are ignored _, m = call_script(["./utils/check-package", "package/pkg-generic.mk"], self.WITH_EMPTY_PATH, infra.basepath()) self.assert_file_was_ignored(m) _, m = call_script( ["./utils/check-package", "-b", "package/pkg-generic.mk"], self.WITH_EMPTY_PATH, infra.basepath()) self.assert_file_was_processed(m) # an out-of-tree file can be checked by the script called from relative # path, absolute path and from PATH for base_script, base_file, rel_script, rel_file, rel_cwd in self.relative: abs_script = infra.basepath(base_script) abs_file = infra.basepath(base_file) cwd = infra.basepath(rel_cwd) _, m = call_script([rel_script, "-b", rel_file], self.WITH_EMPTY_PATH, cwd) self.assert_file_was_processed(m) _, m = call_script([abs_script, "-b", rel_file], self.WITH_EMPTY_PATH, cwd) self.assert_file_was_processed(m) _, m = call_script(["check-package", "-b", rel_file], self.WITH_UTILS_IN_PATH, cwd) self.assert_file_was_processed(m) _, m = call_script([rel_script, "-b", abs_file], self.WITH_EMPTY_PATH, cwd) self.assert_file_was_processed(m) _, m = call_script([abs_script, "-b", abs_file], self.WITH_EMPTY_PATH, cwd) self.assert_file_was_processed(m) _, m = call_script(["check-package", "-b", abs_file], self.WITH_UTILS_IN_PATH, cwd) self.assert_file_was_processed(m) # out-of-tree files are are ignored without -b but can generate warnings # with -b abs_path = infra.filepath("tests/utils/br2-external") rel_file = "Config.in" abs_file = os.path.join(abs_path, rel_file) _, m = call_script(["check-package", rel_file], self.WITH_UTILS_IN_PATH, abs_path) self.assert_file_was_ignored(m) _, m = call_script(["check-package", abs_file], self.WITH_UTILS_IN_PATH, infra.basepath()) self.assert_file_was_ignored(m) w, m = call_script(["check-package", "-b", rel_file], self.WITH_UTILS_IN_PATH, abs_path) self.assert_file_was_processed(m) self.assert_warnings_generated_for_file(m) self.assertIn("{}:1: empty line at end of file".format(rel_file), w) w, m = call_script(["check-package", "-b", abs_file], self.WITH_UTILS_IN_PATH, infra.basepath()) self.assert_file_was_processed(m) self.assert_warnings_generated_for_file(m) self.assertIn("{}:1: empty line at end of file".format(abs_file), w) # external.mk is ignored only when in the root path of a br2-external rel_file = "external.mk" abs_file = os.path.join(abs_path, rel_file) _, m = call_script(["check-package", "-b", rel_file], self.WITH_UTILS_IN_PATH, abs_path) self.assert_file_was_ignored(m) _, m = call_script(["check-package", "-b", abs_file], self.WITH_UTILS_IN_PATH, infra.basepath()) self.assert_file_was_ignored(m) abs_path = infra.filepath("tests/utils/br2-external/package/external") abs_file = os.path.join(abs_path, rel_file) w, m = call_script(["check-package", "-b", rel_file], self.WITH_UTILS_IN_PATH, abs_path) self.assert_file_was_processed(m) self.assert_warnings_generated_for_file(m) self.assertIn( "{}:1: should be 80 hashes (http://nightly.buildroot.org/#writing-rules-mk)" .format(rel_file), w) w, m = call_script(["check-package", "-b", abs_file], self.WITH_UTILS_IN_PATH, infra.basepath()) self.assert_file_was_processed(m) self.assert_warnings_generated_for_file(m) self.assertIn( "{}:1: should be 80 hashes (http://nightly.buildroot.org/#writing-rules-mk)" .format(abs_file), w)
class TestSFTP(SSHTestBase): br2_external = [infra.filepath("tests/download/br2-external/ssh")] def test_run(self): self.download_package("sftp")