diff options
Diffstat (limited to 'meta/lib/oeqa')
| -rw-r--r-- | meta/lib/oeqa/selftest/oelib/__init__.py | 0 | ||||
| -rw-r--r-- | meta/lib/oeqa/selftest/oelib/elf.py | 21 | ||||
| -rw-r--r-- | meta/lib/oeqa/selftest/oelib/license.py | 68 | ||||
| -rw-r--r-- | meta/lib/oeqa/selftest/oelib/path.py | 89 | ||||
| -rw-r--r-- | meta/lib/oeqa/selftest/oelib/types.py | 50 | ||||
| -rw-r--r-- | meta/lib/oeqa/selftest/oelib/utils.py | 51 |
6 files changed, 279 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/oelib/__init__.py b/meta/lib/oeqa/selftest/oelib/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/meta/lib/oeqa/selftest/oelib/__init__.py | |||
diff --git a/meta/lib/oeqa/selftest/oelib/elf.py b/meta/lib/oeqa/selftest/oelib/elf.py new file mode 100644 index 0000000000..1f59037ed9 --- /dev/null +++ b/meta/lib/oeqa/selftest/oelib/elf.py | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | import unittest | ||
| 2 | import oe.qa | ||
| 3 | |||
| 4 | class TestElf(unittest.TestCase): | ||
| 5 | def test_machine_name(self): | ||
| 6 | """ | ||
| 7 | Test elf_machine_to_string() | ||
| 8 | """ | ||
| 9 | self.assertEqual(oe.qa.elf_machine_to_string(0x02), "SPARC") | ||
| 10 | self.assertEqual(oe.qa.elf_machine_to_string(0x03), "x86") | ||
| 11 | self.assertEqual(oe.qa.elf_machine_to_string(0x08), "MIPS") | ||
| 12 | self.assertEqual(oe.qa.elf_machine_to_string(0x14), "PowerPC") | ||
| 13 | self.assertEqual(oe.qa.elf_machine_to_string(0x28), "ARM") | ||
| 14 | self.assertEqual(oe.qa.elf_machine_to_string(0x2A), "SuperH") | ||
| 15 | self.assertEqual(oe.qa.elf_machine_to_string(0x32), "IA-64") | ||
| 16 | self.assertEqual(oe.qa.elf_machine_to_string(0x3E), "x86-64") | ||
| 17 | self.assertEqual(oe.qa.elf_machine_to_string(0xB7), "AArch64") | ||
| 18 | |||
| 19 | self.assertEqual(oe.qa.elf_machine_to_string(0x00), "Unknown (0)") | ||
| 20 | self.assertEqual(oe.qa.elf_machine_to_string(0xDEADBEEF), "Unknown (3735928559)") | ||
| 21 | self.assertEqual(oe.qa.elf_machine_to_string("foobar"), "Unknown ('foobar')") | ||
diff --git a/meta/lib/oeqa/selftest/oelib/license.py b/meta/lib/oeqa/selftest/oelib/license.py new file mode 100644 index 0000000000..c388886184 --- /dev/null +++ b/meta/lib/oeqa/selftest/oelib/license.py | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | import unittest | ||
| 2 | import oe.license | ||
| 3 | |||
| 4 | class SeenVisitor(oe.license.LicenseVisitor): | ||
| 5 | def __init__(self): | ||
| 6 | self.seen = [] | ||
| 7 | oe.license.LicenseVisitor.__init__(self) | ||
| 8 | |||
| 9 | def visit_Str(self, node): | ||
| 10 | self.seen.append(node.s) | ||
| 11 | |||
| 12 | class TestSingleLicense(unittest.TestCase): | ||
| 13 | licenses = [ | ||
| 14 | "GPLv2", | ||
| 15 | "LGPL-2.0", | ||
| 16 | "Artistic", | ||
| 17 | "MIT", | ||
| 18 | "GPLv3+", | ||
| 19 | "FOO_BAR", | ||
| 20 | ] | ||
| 21 | invalid_licenses = ["GPL/BSD"] | ||
| 22 | |||
| 23 | @staticmethod | ||
| 24 | def parse(licensestr): | ||
| 25 | visitor = SeenVisitor() | ||
| 26 | visitor.visit_string(licensestr) | ||
| 27 | return visitor.seen | ||
| 28 | |||
| 29 | def test_single_licenses(self): | ||
| 30 | for license in self.licenses: | ||
| 31 | licenses = self.parse(license) | ||
| 32 | self.assertListEqual(licenses, [license]) | ||
| 33 | |||
| 34 | def test_invalid_licenses(self): | ||
| 35 | for license in self.invalid_licenses: | ||
| 36 | with self.assertRaises(oe.license.InvalidLicense) as cm: | ||
| 37 | self.parse(license) | ||
| 38 | self.assertEqual(cm.exception.license, license) | ||
| 39 | |||
| 40 | class TestSimpleCombinations(unittest.TestCase): | ||
| 41 | tests = { | ||
| 42 | "FOO&BAR": ["FOO", "BAR"], | ||
| 43 | "BAZ & MOO": ["BAZ", "MOO"], | ||
| 44 | "ALPHA|BETA": ["ALPHA"], | ||
| 45 | "BAZ&MOO|FOO": ["FOO"], | ||
| 46 | "FOO&BAR|BAZ": ["FOO", "BAR"], | ||
| 47 | } | ||
| 48 | preferred = ["ALPHA", "FOO", "BAR"] | ||
| 49 | |||
| 50 | def test_tests(self): | ||
| 51 | def choose(a, b): | ||
| 52 | if all(lic in self.preferred for lic in b): | ||
| 53 | return b | ||
| 54 | else: | ||
| 55 | return a | ||
| 56 | |||
| 57 | for license, expected in self.tests.items(): | ||
| 58 | licenses = oe.license.flattened_licenses(license, choose) | ||
| 59 | self.assertListEqual(licenses, expected) | ||
| 60 | |||
| 61 | class TestComplexCombinations(TestSimpleCombinations): | ||
| 62 | tests = { | ||
| 63 | "FOO & (BAR | BAZ)&MOO": ["FOO", "BAR", "MOO"], | ||
| 64 | "(ALPHA|(BETA&THETA)|OMEGA)&DELTA": ["OMEGA", "DELTA"], | ||
| 65 | "((ALPHA|BETA)&FOO)|BAZ": ["BETA", "FOO"], | ||
| 66 | "(GPL-2.0|Proprietary)&BSD-4-clause&MIT": ["GPL-2.0", "BSD-4-clause", "MIT"], | ||
| 67 | } | ||
| 68 | preferred = ["BAR", "OMEGA", "BETA", "GPL-2.0"] | ||
diff --git a/meta/lib/oeqa/selftest/oelib/path.py b/meta/lib/oeqa/selftest/oelib/path.py new file mode 100644 index 0000000000..44d068143e --- /dev/null +++ b/meta/lib/oeqa/selftest/oelib/path.py | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | import unittest | ||
| 2 | import oe, oe.path | ||
| 3 | import tempfile | ||
| 4 | import os | ||
| 5 | import errno | ||
| 6 | import shutil | ||
| 7 | |||
| 8 | class TestRealPath(unittest.TestCase): | ||
| 9 | DIRS = [ "a", "b", "etc", "sbin", "usr", "usr/bin", "usr/binX", "usr/sbin", "usr/include", "usr/include/gdbm" ] | ||
| 10 | FILES = [ "etc/passwd", "b/file" ] | ||
| 11 | LINKS = [ | ||
| 12 | ( "bin", "/usr/bin", "/usr/bin" ), | ||
| 13 | ( "binX", "usr/binX", "/usr/binX" ), | ||
| 14 | ( "c", "broken", "/broken" ), | ||
| 15 | ( "etc/passwd-1", "passwd", "/etc/passwd" ), | ||
| 16 | ( "etc/passwd-2", "passwd-1", "/etc/passwd" ), | ||
| 17 | ( "etc/passwd-3", "/etc/passwd-1", "/etc/passwd" ), | ||
| 18 | ( "etc/shadow-1", "/etc/shadow", "/etc/shadow" ), | ||
| 19 | ( "etc/shadow-2", "/etc/shadow-1", "/etc/shadow" ), | ||
| 20 | ( "prog-A", "bin/prog-A", "/usr/bin/prog-A" ), | ||
| 21 | ( "prog-B", "/bin/prog-B", "/usr/bin/prog-B" ), | ||
| 22 | ( "usr/bin/prog-C", "../../sbin/prog-C", "/sbin/prog-C" ), | ||
| 23 | ( "usr/bin/prog-D", "/sbin/prog-D", "/sbin/prog-D" ), | ||
| 24 | ( "usr/binX/prog-E", "../sbin/prog-E", None ), | ||
| 25 | ( "usr/bin/prog-F", "../../../sbin/prog-F", "/sbin/prog-F" ), | ||
| 26 | ( "loop", "a/loop", None ), | ||
| 27 | ( "a/loop", "../loop", None ), | ||
| 28 | ( "b/test", "file/foo", "/b/file/foo" ), | ||
| 29 | ] | ||
| 30 | |||
| 31 | LINKS_PHYS = [ | ||
| 32 | ( "./", "/", "" ), | ||
| 33 | ( "binX/prog-E", "/usr/sbin/prog-E", "/sbin/prog-E" ), | ||
| 34 | ] | ||
| 35 | |||
| 36 | EXCEPTIONS = [ | ||
| 37 | ( "loop", errno.ELOOP ), | ||
| 38 | ( "b/test", errno.ENOENT ), | ||
| 39 | ] | ||
| 40 | |||
| 41 | def __del__(self): | ||
| 42 | try: | ||
| 43 | #os.system("tree -F %s" % self.tmpdir) | ||
| 44 | shutil.rmtree(self.tmpdir) | ||
| 45 | except: | ||
| 46 | pass | ||
| 47 | |||
| 48 | def setUp(self): | ||
| 49 | self.tmpdir = tempfile.mkdtemp(prefix = "oe-test_path") | ||
| 50 | self.root = os.path.join(self.tmpdir, "R") | ||
| 51 | |||
| 52 | os.mkdir(os.path.join(self.tmpdir, "_real")) | ||
| 53 | os.symlink("_real", self.root) | ||
| 54 | |||
| 55 | for d in self.DIRS: | ||
| 56 | os.mkdir(os.path.join(self.root, d)) | ||
| 57 | for f in self.FILES: | ||
| 58 | open(os.path.join(self.root, f), "w") | ||
| 59 | for l in self.LINKS: | ||
| 60 | os.symlink(l[1], os.path.join(self.root, l[0])) | ||
| 61 | |||
| 62 | def __realpath(self, file, use_physdir, assume_dir = True): | ||
| 63 | return oe.path.realpath(os.path.join(self.root, file), self.root, | ||
| 64 | use_physdir, assume_dir = assume_dir) | ||
| 65 | |||
| 66 | def test_norm(self): | ||
| 67 | for l in self.LINKS: | ||
| 68 | if l[2] == None: | ||
| 69 | continue | ||
| 70 | |||
| 71 | target_p = self.__realpath(l[0], True) | ||
| 72 | target_l = self.__realpath(l[0], False) | ||
| 73 | |||
| 74 | if l[2] != False: | ||
| 75 | self.assertEqual(target_p, target_l) | ||
| 76 | self.assertEqual(l[2], target_p[len(self.root):]) | ||
| 77 | |||
| 78 | def test_phys(self): | ||
| 79 | for l in self.LINKS_PHYS: | ||
| 80 | target_p = self.__realpath(l[0], True) | ||
| 81 | target_l = self.__realpath(l[0], False) | ||
| 82 | |||
| 83 | self.assertEqual(l[1], target_p[len(self.root):]) | ||
| 84 | self.assertEqual(l[2], target_l[len(self.root):]) | ||
| 85 | |||
| 86 | def test_loop(self): | ||
| 87 | for e in self.EXCEPTIONS: | ||
| 88 | self.assertRaisesRegex(OSError, r'\[Errno %u\]' % e[1], | ||
| 89 | self.__realpath, e[0], False, False) | ||
diff --git a/meta/lib/oeqa/selftest/oelib/types.py b/meta/lib/oeqa/selftest/oelib/types.py new file mode 100644 index 0000000000..4fe2746a3b --- /dev/null +++ b/meta/lib/oeqa/selftest/oelib/types.py | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | import unittest | ||
| 2 | from oe.maketype import create | ||
| 3 | |||
| 4 | class TestBooleanType(unittest.TestCase): | ||
| 5 | def test_invalid(self): | ||
| 6 | self.assertRaises(ValueError, create, '', 'boolean') | ||
| 7 | self.assertRaises(ValueError, create, 'foo', 'boolean') | ||
| 8 | self.assertRaises(TypeError, create, object(), 'boolean') | ||
| 9 | |||
| 10 | def test_true(self): | ||
| 11 | self.assertTrue(create('y', 'boolean')) | ||
| 12 | self.assertTrue(create('yes', 'boolean')) | ||
| 13 | self.assertTrue(create('1', 'boolean')) | ||
| 14 | self.assertTrue(create('t', 'boolean')) | ||
| 15 | self.assertTrue(create('true', 'boolean')) | ||
| 16 | self.assertTrue(create('TRUE', 'boolean')) | ||
| 17 | self.assertTrue(create('truE', 'boolean')) | ||
| 18 | |||
| 19 | def test_false(self): | ||
| 20 | self.assertFalse(create('n', 'boolean')) | ||
| 21 | self.assertFalse(create('no', 'boolean')) | ||
| 22 | self.assertFalse(create('0', 'boolean')) | ||
| 23 | self.assertFalse(create('f', 'boolean')) | ||
| 24 | self.assertFalse(create('false', 'boolean')) | ||
| 25 | self.assertFalse(create('FALSE', 'boolean')) | ||
| 26 | self.assertFalse(create('faLse', 'boolean')) | ||
| 27 | |||
| 28 | def test_bool_equality(self): | ||
| 29 | self.assertEqual(create('n', 'boolean'), False) | ||
| 30 | self.assertNotEqual(create('n', 'boolean'), True) | ||
| 31 | self.assertEqual(create('y', 'boolean'), True) | ||
| 32 | self.assertNotEqual(create('y', 'boolean'), False) | ||
| 33 | |||
| 34 | class TestList(unittest.TestCase): | ||
| 35 | def assertListEqual(self, value, valid, sep=None): | ||
| 36 | obj = create(value, 'list', separator=sep) | ||
| 37 | self.assertEqual(obj, valid) | ||
| 38 | if sep is not None: | ||
| 39 | self.assertEqual(obj.separator, sep) | ||
| 40 | self.assertEqual(str(obj), obj.separator.join(obj)) | ||
| 41 | |||
| 42 | def test_list_nosep(self): | ||
| 43 | testlist = ['alpha', 'beta', 'theta'] | ||
| 44 | self.assertListEqual('alpha beta theta', testlist) | ||
| 45 | self.assertListEqual('alpha beta\ttheta', testlist) | ||
| 46 | self.assertListEqual('alpha', ['alpha']) | ||
| 47 | |||
| 48 | def test_list_usersep(self): | ||
| 49 | self.assertListEqual('foo:bar', ['foo', 'bar'], ':') | ||
| 50 | self.assertListEqual('foo:bar:baz', ['foo', 'bar', 'baz'], ':') | ||
diff --git a/meta/lib/oeqa/selftest/oelib/utils.py b/meta/lib/oeqa/selftest/oelib/utils.py new file mode 100644 index 0000000000..7deb10f3c8 --- /dev/null +++ b/meta/lib/oeqa/selftest/oelib/utils.py | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | import unittest | ||
| 2 | from oe.utils import packages_filter_out_system, trim_version | ||
| 3 | |||
| 4 | class TestPackagesFilterOutSystem(unittest.TestCase): | ||
| 5 | def test_filter(self): | ||
| 6 | """ | ||
| 7 | Test that oe.utils.packages_filter_out_system works. | ||
| 8 | """ | ||
| 9 | try: | ||
| 10 | import bb | ||
| 11 | except ImportError: | ||
| 12 | self.skipTest("Cannot import bb") | ||
| 13 | |||
| 14 | d = bb.data_smart.DataSmart() | ||
| 15 | d.setVar("PN", "foo") | ||
| 16 | |||
| 17 | d.setVar("PACKAGES", "foo foo-doc foo-dev") | ||
| 18 | pkgs = packages_filter_out_system(d) | ||
| 19 | self.assertEqual(pkgs, []) | ||
| 20 | |||
| 21 | d.setVar("PACKAGES", "foo foo-doc foo-data foo-dev") | ||
| 22 | pkgs = packages_filter_out_system(d) | ||
| 23 | self.assertEqual(pkgs, ["foo-data"]) | ||
| 24 | |||
| 25 | d.setVar("PACKAGES", "foo foo-locale-en-gb") | ||
| 26 | pkgs = packages_filter_out_system(d) | ||
| 27 | self.assertEqual(pkgs, []) | ||
| 28 | |||
| 29 | d.setVar("PACKAGES", "foo foo-data foo-locale-en-gb") | ||
| 30 | pkgs = packages_filter_out_system(d) | ||
| 31 | self.assertEqual(pkgs, ["foo-data"]) | ||
| 32 | |||
| 33 | |||
| 34 | class TestTrimVersion(unittest.TestCase): | ||
| 35 | def test_version_exception(self): | ||
| 36 | with self.assertRaises(TypeError): | ||
| 37 | trim_version(None, 2) | ||
| 38 | with self.assertRaises(TypeError): | ||
| 39 | trim_version((1, 2, 3), 2) | ||
| 40 | |||
| 41 | def test_num_exception(self): | ||
| 42 | with self.assertRaises(ValueError): | ||
| 43 | trim_version("1.2.3", 0) | ||
| 44 | with self.assertRaises(ValueError): | ||
| 45 | trim_version("1.2.3", -1) | ||
| 46 | |||
| 47 | def test_valid(self): | ||
| 48 | self.assertEqual(trim_version("1.2.3", 1), "1") | ||
| 49 | self.assertEqual(trim_version("1.2.3", 2), "1.2") | ||
| 50 | self.assertEqual(trim_version("1.2.3", 3), "1.2.3") | ||
| 51 | self.assertEqual(trim_version("1.2.3", 4), "1.2.3") | ||
