test_ext.py 10 KB

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