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