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