blob: afe8f8809f70c07c6aa6e9f14c0b2dc77d2f212c [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005from oeqa.selftest.case import OESelftestTestCase
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006from oeqa.utils.commands import get_bb_var, get_bb_vars, bitbake, runCmd
7import oe.path
8import os
9
10class LibOE(OESelftestTestCase):
11
12 @classmethod
13 def setUpClass(cls):
14 super(LibOE, cls).setUpClass()
15 cls.tmp_dir = get_bb_var('TMPDIR')
16
Brad Bishopd7bf8c12018-02-25 22:55:05 -050017 def test_copy_tree_special(self):
18 """
19 Summary: oe.path.copytree() should copy files with special character
20 Expected: 'test file with sp£c!al @nd spaces' should exist in
21 copy destination
22 Product: OE-Core
23 Author: Joshua Lock <joshua.g.lock@intel.com>
24 """
25 testloc = oe.path.join(self.tmp_dir, 'liboetests')
26 src = oe.path.join(testloc, 'src')
27 dst = oe.path.join(testloc, 'dst')
28 bb.utils.mkdirhier(testloc)
29 bb.utils.mkdirhier(src)
30 testfilename = 'test file with sp£c!al @nd spaces'
31
32 # create the test file and copy it
33 open(oe.path.join(src, testfilename), 'w+b').close()
34 oe.path.copytree(src, dst)
35
36 # ensure path exists in dest
37 fileindst = os.path.isfile(oe.path.join(dst, testfilename))
38 self.assertTrue(fileindst, "File with spaces doesn't exist in dst")
39
40 oe.path.remove(testloc)
41
Brad Bishopd7bf8c12018-02-25 22:55:05 -050042 def test_copy_tree_xattr(self):
43 """
44 Summary: oe.path.copytree() should preserve xattr on copied files
45 Expected: testxattr file in destination should have user.oetest
46 extended attribute
47 Product: OE-Core
48 Author: Joshua Lock <joshua.g.lock@intel.com>
49 """
50 testloc = oe.path.join(self.tmp_dir, 'liboetests')
51 src = oe.path.join(testloc, 'src')
52 dst = oe.path.join(testloc, 'dst')
53 bb.utils.mkdirhier(testloc)
54 bb.utils.mkdirhier(src)
55 testfilename = 'testxattr'
56
57 # ensure we have setfattr available
58 bitbake("attr-native")
59
60 bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'attr-native')
61 destdir = bb_vars['SYSROOT_DESTDIR']
62 bindir = bb_vars['bindir']
63 bindir = destdir + bindir
64
65 # create a file with xattr and copy it
66 open(oe.path.join(src, testfilename), 'w+b').close()
67 runCmd('%s/setfattr -n user.oetest -v "testing liboe" %s' % (bindir, oe.path.join(src, testfilename)))
68 oe.path.copytree(src, dst)
69
70 # ensure file in dest has user.oetest xattr
71 result = runCmd('%s/getfattr -n user.oetest %s' % (bindir, oe.path.join(dst, testfilename)))
72 self.assertIn('user.oetest="testing liboe"', result.output, 'Extended attribute not sert in dst')
73
74 oe.path.remove(testloc)
75
Brad Bishopd7bf8c12018-02-25 22:55:05 -050076 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)