test_unlink.py 4.2 KB

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