liboe.py 3.7 KB

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