diff options
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/liboe.py')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/liboe.py | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/liboe.py b/meta/lib/oeqa/selftest/cases/liboe.py new file mode 100644 index 0000000000..01b2cab7aa --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/liboe.py | |||
@@ -0,0 +1,98 @@ | |||
1 | from oeqa.selftest.case import OESelftestTestCase | ||
2 | from oeqa.utils.commands import get_bb_var, get_bb_vars, bitbake, runCmd | ||
3 | import oe.path | ||
4 | import os | ||
5 | |||
6 | class LibOE(OESelftestTestCase): | ||
7 | |||
8 | @classmethod | ||
9 | def setUpClass(cls): | ||
10 | super(LibOE, cls).setUpClass() | ||
11 | cls.tmp_dir = get_bb_var('TMPDIR') | ||
12 | |||
13 | def test_copy_tree_special(self): | ||
14 | """ | ||
15 | Summary: oe.path.copytree() should copy files with special character | ||
16 | Expected: 'test file with sp£c!al @nd spaces' should exist in | ||
17 | copy destination | ||
18 | Product: OE-Core | ||
19 | Author: Joshua Lock <joshua.g.lock@intel.com> | ||
20 | """ | ||
21 | testloc = oe.path.join(self.tmp_dir, 'liboetests') | ||
22 | src = oe.path.join(testloc, 'src') | ||
23 | dst = oe.path.join(testloc, 'dst') | ||
24 | bb.utils.mkdirhier(testloc) | ||
25 | bb.utils.mkdirhier(src) | ||
26 | testfilename = 'test file with sp£c!al @nd spaces' | ||
27 | |||
28 | # create the test file and copy it | ||
29 | open(oe.path.join(src, testfilename), 'w+b').close() | ||
30 | oe.path.copytree(src, dst) | ||
31 | |||
32 | # ensure path exists in dest | ||
33 | fileindst = os.path.isfile(oe.path.join(dst, testfilename)) | ||
34 | self.assertTrue(fileindst, "File with spaces doesn't exist in dst") | ||
35 | |||
36 | oe.path.remove(testloc) | ||
37 | |||
38 | def test_copy_tree_xattr(self): | ||
39 | """ | ||
40 | Summary: oe.path.copytree() should preserve xattr on copied files | ||
41 | Expected: testxattr file in destination should have user.oetest | ||
42 | extended attribute | ||
43 | Product: OE-Core | ||
44 | Author: Joshua Lock <joshua.g.lock@intel.com> | ||
45 | """ | ||
46 | testloc = oe.path.join(self.tmp_dir, 'liboetests') | ||
47 | src = oe.path.join(testloc, 'src') | ||
48 | dst = oe.path.join(testloc, 'dst') | ||
49 | bb.utils.mkdirhier(testloc) | ||
50 | bb.utils.mkdirhier(src) | ||
51 | testfilename = 'testxattr' | ||
52 | |||
53 | # ensure we have setfattr available | ||
54 | bitbake("attr-native") | ||
55 | |||
56 | bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'attr-native') | ||
57 | destdir = bb_vars['SYSROOT_DESTDIR'] | ||
58 | bindir = bb_vars['bindir'] | ||
59 | bindir = destdir + bindir | ||
60 | |||
61 | # create a file with xattr and copy it | ||
62 | open(oe.path.join(src, testfilename), 'w+b').close() | ||
63 | runCmd('%s/setfattr -n user.oetest -v "testing liboe" %s' % (bindir, oe.path.join(src, testfilename))) | ||
64 | oe.path.copytree(src, dst) | ||
65 | |||
66 | # ensure file in dest has user.oetest xattr | ||
67 | result = runCmd('%s/getfattr -n user.oetest %s' % (bindir, oe.path.join(dst, testfilename))) | ||
68 | self.assertIn('user.oetest="testing liboe"', result.output, 'Extended attribute not sert in dst') | ||
69 | |||
70 | oe.path.remove(testloc) | ||
71 | |||
72 | def test_copy_hardlink_tree_count(self): | ||
73 | """ | ||
74 | Summary: oe.path.copyhardlinktree() shouldn't miss out files | ||
75 | Expected: src and dst should have the same number of files | ||
76 | Product: OE-Core | ||
77 | Author: Joshua Lock <joshua.g.lock@intel.com> | ||
78 | """ | ||
79 | testloc = oe.path.join(self.tmp_dir, 'liboetests') | ||
80 | src = oe.path.join(testloc, 'src') | ||
81 | dst = oe.path.join(testloc, 'dst') | ||
82 | bb.utils.mkdirhier(testloc) | ||
83 | bb.utils.mkdirhier(src) | ||
84 | testfiles = ['foo', 'bar', '.baz', 'quux'] | ||
85 | |||
86 | def touchfile(tf): | ||
87 | open(oe.path.join(src, tf), 'w+b').close() | ||
88 | |||
89 | for f in testfiles: | ||
90 | touchfile(f) | ||
91 | |||
92 | oe.path.copyhardlinktree(src, dst) | ||
93 | |||
94 | dstcnt = len(os.listdir(dst)) | ||
95 | srccnt = len(os.listdir(src)) | ||
96 | self.assertEquals(dstcnt, len(testfiles), "Number of files in dst (%s) differs from number of files in src(%s)." % (dstcnt, srccnt)) | ||
97 | |||
98 | oe.path.remove(testloc) | ||