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