test_mkdir.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # SPDX-License-Identifier: GPL-2.0+
  2. # Copyright (c) 2018, Linaro Limited
  3. # Author: Takahiro Akashi <takahiro.akashi@linaro.org>
  4. #
  5. # U-Boot File System:mkdir Test
  6. """
  7. This test verifies mkdir operation on file system.
  8. """
  9. import pytest
  10. from fstest_helpers import assert_fs_integrity
  11. @pytest.mark.boardspec('sandbox')
  12. @pytest.mark.slow
  13. class TestMkdir(object):
  14. def test_mkdir1(self, u_boot_console, fs_obj_mkdir):
  15. """
  16. Test Case 1 - create a directory under a root
  17. """
  18. fs_type,fs_img = fs_obj_mkdir
  19. with u_boot_console.log.section('Test Case 1 - mkdir'):
  20. output = u_boot_console.run_command_list([
  21. 'host bind 0 %s' % fs_img,
  22. '%smkdir host 0:0 dir1' % fs_type,
  23. '%sls host 0:0 /' % fs_type])
  24. assert('dir1/' in ''.join(output))
  25. output = u_boot_console.run_command(
  26. '%sls host 0:0 dir1' % fs_type)
  27. assert('./' in output)
  28. assert('../' in output)
  29. assert_fs_integrity(fs_type, fs_img)
  30. def test_mkdir2(self, u_boot_console, fs_obj_mkdir):
  31. """
  32. Test Case 2 - create a directory under a sub-directory
  33. """
  34. fs_type,fs_img = fs_obj_mkdir
  35. with u_boot_console.log.section('Test Case 2 - mkdir (sub-sub directory)'):
  36. output = u_boot_console.run_command_list([
  37. 'host bind 0 %s' % fs_img,
  38. '%smkdir host 0:0 dir1/dir2' % fs_type,
  39. '%sls host 0:0 dir1' % fs_type])
  40. assert('dir2/' in ''.join(output))
  41. output = u_boot_console.run_command(
  42. '%sls host 0:0 dir1/dir2' % fs_type)
  43. assert('./' in output)
  44. assert('../' in output)
  45. assert_fs_integrity(fs_type, fs_img)
  46. def test_mkdir3(self, u_boot_console, fs_obj_mkdir):
  47. """
  48. Test Case 3 - trying to create a directory with a non-existing
  49. path should fail
  50. """
  51. fs_type,fs_img = fs_obj_mkdir
  52. with u_boot_console.log.section('Test Case 3 - mkdir (non-existing path)'):
  53. output = u_boot_console.run_command_list([
  54. 'host bind 0 %s' % fs_img,
  55. '%smkdir host 0:0 none/dir3' % fs_type])
  56. assert('Unable to create a directory' in ''.join(output))
  57. assert_fs_integrity(fs_type, fs_img)
  58. def test_mkdir4(self, u_boot_console, fs_obj_mkdir):
  59. """
  60. Test Case 4 - trying to create "." should fail
  61. """
  62. fs_type,fs_img = fs_obj_mkdir
  63. with u_boot_console.log.section('Test Case 4 - mkdir (".")'):
  64. output = u_boot_console.run_command_list([
  65. 'host bind 0 %s' % fs_img,
  66. '%smkdir host 0:0 .' % fs_type])
  67. assert('Unable to create a directory' in ''.join(output))
  68. assert_fs_integrity(fs_type, fs_img)
  69. def test_mkdir5(self, u_boot_console, fs_obj_mkdir):
  70. """
  71. Test Case 5 - trying to create ".." should fail
  72. """
  73. fs_type,fs_img = fs_obj_mkdir
  74. with u_boot_console.log.section('Test Case 5 - mkdir ("..")'):
  75. output = u_boot_console.run_command_list([
  76. 'host bind 0 %s' % fs_img,
  77. '%smkdir host 0:0 ..' % fs_type])
  78. assert('Unable to create a directory' in ''.join(output))
  79. assert_fs_integrity(fs_type, fs_img)
  80. def test_mkdir6(self, u_boot_console, fs_obj_mkdir):
  81. """
  82. 'Test Case 6 - create as many directories as amount of directory
  83. entries goes beyond a cluster size)'
  84. """
  85. fs_type,fs_img = fs_obj_mkdir
  86. with u_boot_console.log.section('Test Case 6 - mkdir (create many)'):
  87. output = u_boot_console.run_command_list([
  88. 'host bind 0 %s' % fs_img,
  89. '%smkdir host 0:0 dir6' % fs_type,
  90. '%sls host 0:0 /' % fs_type])
  91. assert('dir6/' in ''.join(output))
  92. for i in range(0, 20):
  93. output = u_boot_console.run_command(
  94. '%smkdir host 0:0 dir6/0123456789abcdef%02x'
  95. % (fs_type, i))
  96. output = u_boot_console.run_command('%sls host 0:0 dir6' % fs_type)
  97. assert('0123456789abcdef00/' in output)
  98. assert('0123456789abcdef13/' in output)
  99. output = u_boot_console.run_command(
  100. '%sls host 0:0 dir6/0123456789abcdef13/.' % fs_type)
  101. assert('./' in output)
  102. assert('../' in output)
  103. output = u_boot_console.run_command(
  104. '%sls host 0:0 dir6/0123456789abcdef13/..' % fs_type)
  105. assert('0123456789abcdef00/' in output)
  106. assert('0123456789abcdef13/' in output)
  107. assert_fs_integrity(fs_type, fs_img)