test_ext.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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:Exntented Test
  6. """
  7. This test verifies extended write operation on file system.
  8. """
  9. import pytest
  10. import re
  11. from fstest_defs import *
  12. @pytest.mark.boardspec('sandbox')
  13. @pytest.mark.slow
  14. class TestFsExt(object):
  15. def test_fs_ext1(self, u_boot_console, fs_obj_ext):
  16. """
  17. Test Case 1 - write a file with absolute path
  18. """
  19. fs_type,fs_img,md5val = fs_obj_ext
  20. with u_boot_console.log.section('Test Case 1 - write with abs path'):
  21. # Test Case 1a - Check if command successfully returned
  22. output = u_boot_console.run_command_list([
  23. 'host bind 0 %s' % fs_img,
  24. '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
  25. '%swrite host 0:0 %x /dir1/%s.w1 $filesize'
  26. % (fs_type, ADDR, MIN_FILE)])
  27. assert('20480 bytes written' in ''.join(output))
  28. # Test Case 1b - Check md5 of file content
  29. output = u_boot_console.run_command_list([
  30. 'mw.b %x 00 100' % ADDR,
  31. '%sload host 0:0 %x /dir1/%s.w1' % (fs_type, ADDR, MIN_FILE),
  32. 'md5sum %x $filesize' % ADDR,
  33. 'setenv filesize'])
  34. assert(md5val[0] in ''.join(output))
  35. def test_fs_ext2(self, u_boot_console, fs_obj_ext):
  36. """
  37. Test Case 2 - write to a file with relative path
  38. """
  39. fs_type,fs_img,md5val = fs_obj_ext
  40. with u_boot_console.log.section('Test Case 2 - write with rel path'):
  41. # Test Case 2a - Check if command successfully returned
  42. output = u_boot_console.run_command_list([
  43. 'host bind 0 %s' % fs_img,
  44. '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
  45. '%swrite host 0:0 %x dir1/%s.w2 $filesize'
  46. % (fs_type, ADDR, MIN_FILE)])
  47. assert('20480 bytes written' in ''.join(output))
  48. # Test Case 2b - Check md5 of file content
  49. output = u_boot_console.run_command_list([
  50. 'mw.b %x 00 100' % ADDR,
  51. '%sload host 0:0 %x dir1/%s.w2' % (fs_type, ADDR, MIN_FILE),
  52. 'md5sum %x $filesize' % ADDR,
  53. 'setenv filesize'])
  54. assert(md5val[0] in ''.join(output))
  55. def test_fs_ext3(self, u_boot_console, fs_obj_ext):
  56. """
  57. Test Case 3 - write to a file with invalid path
  58. """
  59. fs_type,fs_img,md5val = fs_obj_ext
  60. with u_boot_console.log.section('Test Case 3 - write with invalid path'):
  61. # Test Case 3 - Check if command expectedly failed
  62. output = u_boot_console.run_command_list([
  63. 'host bind 0 %s' % fs_img,
  64. '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
  65. '%swrite host 0:0 %x /dir1/none/%s.w3 $filesize'
  66. % (fs_type, ADDR, MIN_FILE)])
  67. assert('Unable to write "/dir1/none/' in ''.join(output))
  68. def test_fs_ext4(self, u_boot_console, fs_obj_ext):
  69. """
  70. Test Case 4 - write at non-zero offset, enlarging file size
  71. """
  72. fs_type,fs_img,md5val = fs_obj_ext
  73. with u_boot_console.log.section('Test Case 4 - write at non-zero offset, enlarging file size'):
  74. # Test Case 4a - Check if command successfully returned
  75. output = u_boot_console.run_command_list([
  76. 'host bind 0 %s' % fs_img,
  77. '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
  78. '%swrite host 0:0 %x /dir1/%s.w4 $filesize'
  79. % (fs_type, ADDR, MIN_FILE)])
  80. output = u_boot_console.run_command(
  81. '%swrite host 0:0 %x /dir1/%s.w4 $filesize 0x1400'
  82. % (fs_type, ADDR, MIN_FILE))
  83. assert('20480 bytes written' in output)
  84. # Test Case 4b - Check size of written file
  85. output = u_boot_console.run_command_list([
  86. '%ssize host 0:0 /dir1/%s.w4' % (fs_type, MIN_FILE),
  87. 'printenv filesize',
  88. 'setenv filesize'])
  89. assert('filesize=6400' in ''.join(output))
  90. # Test Case 4c - Check md5 of file content
  91. output = u_boot_console.run_command_list([
  92. 'mw.b %x 00 100' % ADDR,
  93. '%sload host 0:0 %x /dir1/%s.w4' % (fs_type, ADDR, MIN_FILE),
  94. 'md5sum %x $filesize' % ADDR,
  95. 'setenv filesize'])
  96. assert(md5val[1] in ''.join(output))
  97. def test_fs_ext5(self, u_boot_console, fs_obj_ext):
  98. """
  99. Test Case 5 - write at non-zero offset, shrinking file size
  100. """
  101. fs_type,fs_img,md5val = fs_obj_ext
  102. with u_boot_console.log.section('Test Case 5 - write at non-zero offset, shrinking file size'):
  103. # Test Case 5a - Check if command successfully returned
  104. output = u_boot_console.run_command_list([
  105. 'host bind 0 %s' % fs_img,
  106. '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
  107. '%swrite host 0:0 %x /dir1/%s.w5 $filesize'
  108. % (fs_type, ADDR, MIN_FILE)])
  109. output = u_boot_console.run_command(
  110. '%swrite host 0:0 %x /dir1/%s.w5 0x1400 0x1400'
  111. % (fs_type, ADDR, MIN_FILE))
  112. assert('5120 bytes written' in output)
  113. # Test Case 5b - Check size of written file
  114. output = u_boot_console.run_command_list([
  115. '%ssize host 0:0 /dir1/%s.w5' % (fs_type, MIN_FILE),
  116. 'printenv filesize',
  117. 'setenv filesize'])
  118. assert('filesize=2800' in ''.join(output))
  119. # Test Case 5c - Check md5 of file content
  120. output = u_boot_console.run_command_list([
  121. 'mw.b %x 00 100' % ADDR,
  122. '%sload host 0:0 %x /dir1/%s.w5' % (fs_type, ADDR, MIN_FILE),
  123. 'md5sum %x $filesize' % ADDR,
  124. 'setenv filesize'])
  125. assert(md5val[2] in ''.join(output))
  126. def test_fs_ext6(self, u_boot_console, fs_obj_ext):
  127. """
  128. Test Case 6 - write nothing at the start, truncating to zero
  129. """
  130. fs_type,fs_img,md5val = fs_obj_ext
  131. with u_boot_console.log.section('Test Case 6 - write nothing at the start, truncating to zero'):
  132. # Test Case 6a - Check if command successfully returned
  133. output = u_boot_console.run_command_list([
  134. 'host bind 0 %s' % fs_img,
  135. '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
  136. '%swrite host 0:0 %x /dir1/%s.w6 $filesize'
  137. % (fs_type, ADDR, MIN_FILE)])
  138. output = u_boot_console.run_command(
  139. '%swrite host 0:0 %x /dir1/%s.w6 0 0'
  140. % (fs_type, ADDR, MIN_FILE))
  141. assert('0 bytes written' in output)
  142. # Test Case 6b - Check size of written file
  143. output = u_boot_console.run_command_list([
  144. '%ssize host 0:0 /dir1/%s.w6' % (fs_type, MIN_FILE),
  145. 'printenv filesize',
  146. 'setenv filesize'])
  147. assert('filesize=0' in ''.join(output))
  148. def test_fs_ext7(self, u_boot_console, fs_obj_ext):
  149. """
  150. Test Case 7 - write at the end (append)
  151. """
  152. fs_type,fs_img,md5val = fs_obj_ext
  153. with u_boot_console.log.section('Test Case 7 - write at the end (append)'):
  154. # Test Case 7a - Check if command successfully returned
  155. output = u_boot_console.run_command_list([
  156. 'host bind 0 %s' % fs_img,
  157. '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
  158. '%swrite host 0:0 %x /dir1/%s.w7 $filesize'
  159. % (fs_type, ADDR, MIN_FILE)])
  160. output = u_boot_console.run_command(
  161. '%swrite host 0:0 %x /dir1/%s.w7 $filesize $filesize'
  162. % (fs_type, ADDR, MIN_FILE))
  163. assert('20480 bytes written' in output)
  164. # Test Case 7b - Check size of written file
  165. output = u_boot_console.run_command_list([
  166. '%ssize host 0:0 /dir1/%s.w7' % (fs_type, MIN_FILE),
  167. 'printenv filesize',
  168. 'setenv filesize'])
  169. assert('filesize=a000' in ''.join(output))
  170. # Test Case 7c - Check md5 of file content
  171. output = u_boot_console.run_command_list([
  172. 'mw.b %x 00 100' % ADDR,
  173. '%sload host 0:0 %x /dir1/%s.w7' % (fs_type, ADDR, MIN_FILE),
  174. 'md5sum %x $filesize' % ADDR,
  175. 'setenv filesize'])
  176. assert(md5val[3] in ''.join(output))
  177. def test_fs_ext8(self, u_boot_console, fs_obj_ext):
  178. """
  179. Test Case 8 - write at offset beyond the end of file
  180. """
  181. fs_type,fs_img,md5val = fs_obj_ext
  182. with u_boot_console.log.section('Test Case 8 - write beyond the end'):
  183. # Test Case 8a - Check if command expectedly failed
  184. output = u_boot_console.run_command_list([
  185. 'host bind 0 %s' % fs_img,
  186. '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
  187. '%swrite host 0:0 %x /dir1/%s.w8 $filesize'
  188. % (fs_type, ADDR, MIN_FILE)])
  189. output = u_boot_console.run_command(
  190. '%swrite host 0:0 %x /dir1/%s.w8 0x1400 %x'
  191. % (fs_type, ADDR, MIN_FILE, 0x100000 + 0x1400))
  192. assert('Unable to write "/dir1' in output)
  193. def test_fs_ext9(self, u_boot_console, fs_obj_ext):
  194. """
  195. Test Case 9 - write to a non-existing file at non-zero offset
  196. """
  197. fs_type,fs_img,md5val = fs_obj_ext
  198. with u_boot_console.log.section('Test Case 9 - write to non-existing file with non-zero offset'):
  199. # Test Case 9a - Check if command expectedly failed
  200. output = u_boot_console.run_command_list([
  201. 'host bind 0 %s' % fs_img,
  202. '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
  203. '%swrite host 0:0 %x /dir1/%s.w9 0x1400 0x1400'
  204. % (fs_type, ADDR, MIN_FILE)])
  205. assert('Unable to write "/dir1' in ''.join(output))