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