test_unlink.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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:unlink Test
  6. """
  7. This test verifies unlink operation (deleting a file or a directory)
  8. on file system.
  9. """
  10. import pytest
  11. @pytest.mark.boardspec('sandbox')
  12. @pytest.mark.slow
  13. class TestUnlink(object):
  14. def test_unlink1(self, u_boot_console, fs_obj_unlink):
  15. """
  16. Test Case 1 - delete a file
  17. """
  18. fs_type,fs_img = fs_obj_unlink
  19. with u_boot_console.log.section('Test Case 1 - unlink (file)'):
  20. output = u_boot_console.run_command_list([
  21. 'host bind 0 %s' % fs_img,
  22. '%srm host 0:0 dir1/file1' % fs_type,
  23. '%sls host 0:0 dir1/file1' % fs_type])
  24. assert('' == ''.join(output))
  25. output = u_boot_console.run_command(
  26. '%sls host 0:0 dir1/' % fs_type)
  27. assert(not 'file1' in output)
  28. assert('file2' in output)
  29. def test_unlink2(self, u_boot_console, fs_obj_unlink):
  30. """
  31. Test Case 2 - delete many files
  32. """
  33. fs_type,fs_img = fs_obj_unlink
  34. with u_boot_console.log.section('Test Case 2 - unlink (many)'):
  35. output = u_boot_console.run_command('host bind 0 %s' % fs_img)
  36. for i in range(0, 20):
  37. output = u_boot_console.run_command_list([
  38. '%srm host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i),
  39. '%sls host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i)])
  40. assert('' == ''.join(output))
  41. output = u_boot_console.run_command(
  42. '%sls host 0:0 dir2' % fs_type)
  43. assert('0 file(s), 2 dir(s)' in output)
  44. def test_unlink3(self, u_boot_console, fs_obj_unlink):
  45. """
  46. Test Case 3 - trying to delete a non-existing file should fail
  47. """
  48. fs_type,fs_img = fs_obj_unlink
  49. with u_boot_console.log.section('Test Case 3 - unlink (non-existing)'):
  50. output = u_boot_console.run_command_list([
  51. 'host bind 0 %s' % fs_img,
  52. '%srm host 0:0 dir1/nofile' % fs_type])
  53. assert('nofile: doesn\'t exist' in ''.join(output))
  54. def test_unlink4(self, u_boot_console, fs_obj_unlink):
  55. """
  56. Test Case 4 - delete an empty directory
  57. """
  58. fs_type,fs_img = fs_obj_unlink
  59. with u_boot_console.log.section('Test Case 4 - unlink (directory)'):
  60. output = u_boot_console.run_command_list([
  61. 'host bind 0 %s' % fs_img,
  62. '%srm host 0:0 dir4' % fs_type])
  63. assert('' == ''.join(output))
  64. output = u_boot_console.run_command(
  65. '%sls host 0:0 /' % fs_type)
  66. assert(not 'dir4' in output)
  67. def test_unlink5(self, u_boot_console, fs_obj_unlink):
  68. """
  69. Test Case 5 - trying to deleting a non-empty directory ".."
  70. should fail
  71. """
  72. fs_type,fs_img = fs_obj_unlink
  73. with u_boot_console.log.section('Test Case 5 - unlink ("non-empty directory")'):
  74. output = u_boot_console.run_command_list([
  75. 'host bind 0 %s' % fs_img,
  76. '%srm host 0:0 dir5' % fs_type])
  77. assert('directory is not empty' in ''.join(output))
  78. def test_unlink6(self, u_boot_console, fs_obj_unlink):
  79. """
  80. Test Case 6 - trying to deleting a "." should fail
  81. """
  82. fs_type,fs_img = fs_obj_unlink
  83. with u_boot_console.log.section('Test Case 6 - unlink (".")'):
  84. output = u_boot_console.run_command_list([
  85. 'host bind 0 %s' % fs_img,
  86. '%srm host 0:0 dir5/.' % fs_type])
  87. assert('directory is not empty' in ''.join(output))
  88. def test_unlink7(self, u_boot_console, fs_obj_unlink):
  89. """
  90. Test Case 7 - trying to deleting a ".." should fail
  91. """
  92. fs_type,fs_img = fs_obj_unlink
  93. with u_boot_console.log.section('Test Case 7 - unlink ("..")'):
  94. output = u_boot_console.run_command_list([
  95. 'host bind 0 %s' % fs_img,
  96. '%srm host 0:0 dir5/..' % fs_type])
  97. assert('directory is not empty' in ''.join(output))