1# 2# Copyright OpenEmbedded Contributors 3# 4# SPDX-License-Identifier: MIT 5# 6 7from oeqa.selftest.case import OESelftestTestCase 8from 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 19 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 44 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 78 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.assertEqual(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) 105