test_mkdir.py 4.3 KB

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