diff options
author | Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com> | 2017-05-12 14:40:21 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-06-06 19:02:43 +0100 |
commit | 157c3be2ca93f076033f725ec1ee912df91f7488 (patch) | |
tree | 8ef896ff7adf78d63b34059cd5b017a4f0a3419a /meta/lib/oeqa/selftest/cases/oelib | |
parent | 10c512b60d1167122b5fe778b93838dca3def717 (diff) | |
download | poky-157c3be2ca93f076033f725ec1ee912df91f7488.tar.gz |
oeqa/selftest/cases: Migrate test cases into the new oe-qa framework
New framework has different classes/decorators so adapt current test cases to
support these. Changes include changes on base classes and decorators.
Also include paths in selftest/__init__.py isn't needed because the
loader is the standard unittest one.
(From OE-Core rev: ddbbefdd124604d10bd47dd0266b55a764fcc0ab)
Signed-off-by: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/oelib')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/oelib/__init__.py | 0 | ||||
-rw-r--r-- | meta/lib/oeqa/selftest/cases/oelib/buildhistory.py | 88 | ||||
-rw-r--r-- | meta/lib/oeqa/selftest/cases/oelib/elf.py | 21 | ||||
-rw-r--r-- | meta/lib/oeqa/selftest/cases/oelib/license.py | 68 | ||||
-rw-r--r-- | meta/lib/oeqa/selftest/cases/oelib/path.py | 89 | ||||
-rw-r--r-- | meta/lib/oeqa/selftest/cases/oelib/types.py | 50 | ||||
-rw-r--r-- | meta/lib/oeqa/selftest/cases/oelib/utils.py | 51 |
7 files changed, 367 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/oelib/__init__.py b/meta/lib/oeqa/selftest/cases/oelib/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/oelib/__init__.py | |||
diff --git a/meta/lib/oeqa/selftest/cases/oelib/buildhistory.py b/meta/lib/oeqa/selftest/cases/oelib/buildhistory.py new file mode 100644 index 0000000000..4e877517c1 --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/oelib/buildhistory.py | |||
@@ -0,0 +1,88 @@ | |||
1 | import os | ||
2 | from oeqa.selftest.case import OESelftestTestCase | ||
3 | import tempfile | ||
4 | from git import Repo | ||
5 | from oeqa.utils.commands import get_bb_var | ||
6 | from oe.buildhistory_analysis import blob_to_dict, compare_dict_blobs | ||
7 | |||
8 | class TestBlobParsing(OESelftestTestCase): | ||
9 | |||
10 | def setUp(self): | ||
11 | import time | ||
12 | self.repo_path = tempfile.mkdtemp(prefix='selftest-buildhistory', | ||
13 | dir=get_bb_var('TOPDIR')) | ||
14 | |||
15 | self.repo = Repo.init(self.repo_path) | ||
16 | self.test_file = "test" | ||
17 | self.var_map = {} | ||
18 | |||
19 | def tearDown(self): | ||
20 | import shutil | ||
21 | shutil.rmtree(self.repo_path) | ||
22 | |||
23 | def commit_vars(self, to_add={}, to_remove = [], msg="A commit message"): | ||
24 | if len(to_add) == 0 and len(to_remove) == 0: | ||
25 | return | ||
26 | |||
27 | for k in to_remove: | ||
28 | self.var_map.pop(x,None) | ||
29 | for k in to_add: | ||
30 | self.var_map[k] = to_add[k] | ||
31 | |||
32 | with open(os.path.join(self.repo_path, self.test_file), 'w') as repo_file: | ||
33 | for k in self.var_map: | ||
34 | repo_file.write("%s = %s\n" % (k, self.var_map[k])) | ||
35 | |||
36 | self.repo.git.add("--all") | ||
37 | self.repo.git.commit(message=msg) | ||
38 | |||
39 | def test_blob_to_dict(self): | ||
40 | """ | ||
41 | Test convertion of git blobs to dictionary | ||
42 | """ | ||
43 | valuesmap = { "foo" : "1", "bar" : "2" } | ||
44 | self.commit_vars(to_add = valuesmap) | ||
45 | |||
46 | blob = self.repo.head.commit.tree.blobs[0] | ||
47 | self.assertEqual(valuesmap, blob_to_dict(blob), | ||
48 | "commit was not translated correctly to dictionary") | ||
49 | |||
50 | def test_compare_dict_blobs(self): | ||
51 | """ | ||
52 | Test comparisson of dictionaries extracted from git blobs | ||
53 | """ | ||
54 | changesmap = { "foo-2" : ("2", "8"), "bar" : ("","4"), "bar-2" : ("","5")} | ||
55 | |||
56 | self.commit_vars(to_add = { "foo" : "1", "foo-2" : "2", "foo-3" : "3" }) | ||
57 | blob1 = self.repo.heads.master.commit.tree.blobs[0] | ||
58 | |||
59 | self.commit_vars(to_add = { "foo-2" : "8", "bar" : "4", "bar-2" : "5" }) | ||
60 | blob2 = self.repo.heads.master.commit.tree.blobs[0] | ||
61 | |||
62 | change_records = compare_dict_blobs(os.path.join(self.repo_path, self.test_file), | ||
63 | blob1, blob2, False, False) | ||
64 | |||
65 | var_changes = { x.fieldname : (x.oldvalue, x.newvalue) for x in change_records} | ||
66 | self.assertEqual(changesmap, var_changes, "Changes not reported correctly") | ||
67 | |||
68 | def test_compare_dict_blobs_default(self): | ||
69 | """ | ||
70 | Test default values for comparisson of git blob dictionaries | ||
71 | """ | ||
72 | defaultmap = { x : ("default", "1") for x in ["PKG", "PKGE", "PKGV", "PKGR"]} | ||
73 | |||
74 | self.commit_vars(to_add = { "foo" : "1" }) | ||
75 | blob1 = self.repo.heads.master.commit.tree.blobs[0] | ||
76 | |||
77 | self.commit_vars(to_add = { "PKG" : "1", "PKGE" : "1", "PKGV" : "1", "PKGR" : "1" }) | ||
78 | blob2 = self.repo.heads.master.commit.tree.blobs[0] | ||
79 | |||
80 | change_records = compare_dict_blobs(os.path.join(self.repo_path, self.test_file), | ||
81 | blob1, blob2, False, False) | ||
82 | |||
83 | var_changes = {} | ||
84 | for x in change_records: | ||
85 | oldvalue = "default" if ("default" in x.oldvalue) else x.oldvalue | ||
86 | var_changes[x.fieldname] = (oldvalue, x.newvalue) | ||
87 | |||
88 | self.assertEqual(defaultmap, var_changes, "Defaults not set properly") | ||
diff --git a/meta/lib/oeqa/selftest/cases/oelib/elf.py b/meta/lib/oeqa/selftest/cases/oelib/elf.py new file mode 100644 index 0000000000..0451ebaffb --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/oelib/elf.py | |||
@@ -0,0 +1,21 @@ | |||
1 | from oeqa.selftest.case import OESelftestTestCase | ||
2 | import oe.qa | ||
3 | |||
4 | class TestElf(OESelftestTestCase): | ||
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/cases/oelib/license.py b/meta/lib/oeqa/selftest/cases/oelib/license.py new file mode 100644 index 0000000000..a6d9c9ac7a --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/oelib/license.py | |||
@@ -0,0 +1,68 @@ | |||
1 | from oeqa.selftest.case import OESelftestTestCase | ||
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(OESelftestTestCase): | ||
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(OESelftestTestCase): | ||
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/cases/oelib/path.py b/meta/lib/oeqa/selftest/cases/oelib/path.py new file mode 100644 index 0000000000..2ae5eaf89e --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/oelib/path.py | |||
@@ -0,0 +1,89 @@ | |||
1 | from oeqa.selftest.case import OESelftestTestCase | ||
2 | import oe, oe.path | ||
3 | import tempfile | ||
4 | import os | ||
5 | import errno | ||
6 | import shutil | ||
7 | |||
8 | class TestRealPath(OESelftestTestCase): | ||
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/cases/oelib/types.py b/meta/lib/oeqa/selftest/cases/oelib/types.py new file mode 100644 index 0000000000..99c84044be --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/oelib/types.py | |||
@@ -0,0 +1,50 @@ | |||
1 | from oeqa.selftest.case import OESelftestTestCase | ||
2 | from oe.maketype import create | ||
3 | |||
4 | class TestBooleanType(OESelftestTestCase): | ||
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(OESelftestTestCase): | ||
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/cases/oelib/utils.py b/meta/lib/oeqa/selftest/cases/oelib/utils.py new file mode 100644 index 0000000000..5bc5fffae7 --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/oelib/utils.py | |||
@@ -0,0 +1,51 @@ | |||
1 | from oeqa.selftest.case import OESelftestTestCase | ||
2 | from oe.utils import packages_filter_out_system, trim_version | ||
3 | |||
4 | class TestPackagesFilterOutSystem(OESelftestTestCase): | ||
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(OESelftestTestCase): | ||
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") | ||