test_mkdir.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. @pytest.mark.boardspec('sandbox')
  11. @pytest.mark.slow
  12. class TestMkdir(object):
  13. def test_mkdir1(self, u_boot_console, fs_obj_mkdir):
  14. """
  15. Test Case 1 - create a directory under a root
  16. """
  17. fs_type,fs_img = fs_obj_mkdir
  18. with u_boot_console.log.section('Test Case 1 - mkdir'):
  19. output = u_boot_console.run_command_list([
  20. 'host bind 0 %s' % fs_img,
  21. '%smkdir host 0:0 dir1' % fs_type,
  22. '%sls host 0:0 /' % fs_type])
  23. assert('dir1/' in ''.join(output))
  24. output = u_boot_console.run_command(
  25. '%sls host 0:0 dir1' % fs_type)
  26. assert('./' in output)
  27. assert('../' in output)
  28. def test_mkdir2(self, u_boot_console, fs_obj_mkdir):
  29. """
  30. Test Case 2 - create a directory under a sub-directory
  31. """
  32. fs_type,fs_img = fs_obj_mkdir
  33. with u_boot_console.log.section('Test Case 2 - mkdir (sub-sub directory)'):
  34. output = u_boot_console.run_command_list([
  35. 'host bind 0 %s' % fs_img,
  36. '%smkdir host 0:0 dir1/dir2' % fs_type,
  37. '%sls host 0:0 dir1' % fs_type])
  38. assert('dir2/' in ''.join(output))
  39. output = u_boot_console.run_command(
  40. '%sls host 0:0 dir1/dir2' % fs_type)
  41. assert('./' in output)
  42. assert('../' in output)
  43. def test_mkdir3(self, u_boot_console, fs_obj_mkdir):
  44. """
  45. Test Case 3 - trying to create a directory with a non-existing
  46. path should fail
  47. """
  48. fs_type,fs_img = fs_obj_mkdir
  49. with u_boot_console.log.section('Test Case 3 - mkdir (non-existing path)'):
  50. output = u_boot_console.run_command_list([
  51. 'host bind 0 %s' % fs_img,
  52. '%smkdir host 0:0 none/dir3' % fs_type])
  53. assert('Unable to create a directory' in ''.join(output))
  54. def test_mkdir4(self, u_boot_console, fs_obj_mkdir):
  55. """
  56. Test Case 4 - trying to create "." should fail
  57. """
  58. fs_type,fs_img = fs_obj_mkdir
  59. with u_boot_console.log.section('Test Case 4 - mkdir (".")'):
  60. output = u_boot_console.run_command_list([
  61. 'host bind 0 %s' % fs_img,
  62. '%smkdir host 0:0 .' % fs_type])
  63. assert('Unable to create a directory' in ''.join(output))
  64. def test_mkdir5(self, u_boot_console, fs_obj_mkdir):
  65. """
  66. Test Case 5 - trying to create ".." should fail
  67. """
  68. fs_type,fs_img = fs_obj_mkdir
  69. with u_boot_console.log.section('Test Case 5 - mkdir ("..")'):
  70. output = u_boot_console.run_command_list([
  71. 'host bind 0 %s' % fs_img,
  72. '%smkdir host 0:0 ..' % fs_type])
  73. assert('Unable to create a directory' in ''.join(output))
  74. def test_mkdir6(self, u_boot_console, fs_obj_mkdir):
  75. """
  76. 'Test Case 6 - create as many directories as amount of directory
  77. entries goes beyond a cluster size)'
  78. """
  79. fs_type,fs_img = fs_obj_mkdir
  80. with u_boot_console.log.section('Test Case 6 - mkdir (create many)'):
  81. output = u_boot_console.run_command_list([
  82. 'host bind 0 %s' % fs_img,
  83. '%smkdir host 0:0 dir6' % fs_type,
  84. '%sls host 0:0 /' % fs_type])
  85. assert('dir6/' in ''.join(output))
  86. for i in range(0, 20):
  87. output = u_boot_console.run_command(
  88. '%smkdir host 0:0 dir6/0123456789abcdef%02x'
  89. % (fs_type, i))
  90. output = u_boot_console.run_command('%sls host 0:0 dir6' % fs_type)
  91. assert('0123456789abcdef00/' in output)
  92. assert('0123456789abcdef13/' in output)
  93. output = u_boot_console.run_command(
  94. '%sls host 0:0 dir6/0123456789abcdef13/.' % fs_type)
  95. assert('./' in output)
  96. assert('../' in output)
  97. output = u_boot_console.run_command(
  98. '%sls host 0:0 dir6/0123456789abcdef13/..' % fs_type)
  99. assert('0123456789abcdef00/' in output)
  100. assert('0123456789abcdef13/' in output)