liboe.py 3.6 KB

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