blob: 5a02348bb947424d83e0471dd43d7cb837f8d640 [file] [log] [blame]
AKASHI Takahiro615af9a2018-09-11 15:59:19 +09001# 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:Basic Test
6
7"""
8This test verifies basic read/write operation on file system.
9"""
10
11import pytest
12import re
13from fstest_defs import *
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +010014from fstest_helpers import assert_fs_integrity
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090015
16@pytest.mark.boardspec('sandbox')
Simon Glass3fcb8282018-11-18 08:14:29 -070017@pytest.mark.slow
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090018class TestFsBasic(object):
Simon Glassddba5202025-02-09 09:07:14 -070019 def test_fs1(self, ubman, fs_obj_basic):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090020 """
21 Test Case 1 - ls command, listing a root directory and invalid directory
22 """
23 fs_type,fs_img,md5val = fs_obj_basic
Simon Glassddba5202025-02-09 09:07:14 -070024 with ubman.log.section('Test Case 1a - ls'):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090025 # Test Case 1 - ls
Simon Glassddba5202025-02-09 09:07:14 -070026 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090027 'host bind 0 %s' % fs_img,
28 '%sls host 0:0' % fs_type])
29 assert(re.search('2621440000 *%s' % BIG_FILE, ''.join(output)))
30 assert(re.search('1048576 *%s' % SMALL_FILE, ''.join(output)))
31
Simon Glassddba5202025-02-09 09:07:14 -070032 with ubman.log.section('Test Case 1b - ls (invalid dir)'):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090033 # In addition, test with a nonexistent directory to see if we crash.
Simon Glassddba5202025-02-09 09:07:14 -070034 output = ubman.run_command(
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090035 '%sls host 0:0 invalid_d' % fs_type)
Heinrich Schuchardt19c781d2024-10-26 08:40:48 +020036 assert('' == output)
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090037
Simon Glassddba5202025-02-09 09:07:14 -070038 def test_fs2(self, ubman, fs_obj_basic):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090039 """
40 Test Case 2 - size command for a small file
41 """
42 fs_type,fs_img,md5val = fs_obj_basic
Simon Glassddba5202025-02-09 09:07:14 -070043 with ubman.log.section('Test Case 2a - size (small)'):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090044 # 1MB is 0x0010 0000
45 # Test Case 2a - size of small file
Simon Glassddba5202025-02-09 09:07:14 -070046 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090047 'host bind 0 %s' % fs_img,
48 '%ssize host 0:0 /%s' % (fs_type, SMALL_FILE),
49 'printenv filesize',
50 'setenv filesize'])
51 assert('filesize=100000' in ''.join(output))
52
Simon Glassddba5202025-02-09 09:07:14 -070053 with ubman.log.section('Test Case 2b - size (/../<file>)'):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090054 # Test Case 2b - size of small file via a path using '..'
Simon Glassddba5202025-02-09 09:07:14 -070055 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090056 '%ssize host 0:0 /SUBDIR/../%s' % (fs_type, SMALL_FILE),
57 'printenv filesize',
58 'setenv filesize'])
59 assert('filesize=100000' in ''.join(output))
60
Simon Glassddba5202025-02-09 09:07:14 -070061 def test_fs3(self, ubman, fs_obj_basic):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090062 """
63 Test Case 3 - size command for a large file
64 """
65 fs_type,fs_img,md5val = fs_obj_basic
Simon Glassddba5202025-02-09 09:07:14 -070066 with ubman.log.section('Test Case 3 - size (large)'):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090067 # 2.5GB (1024*1024*2500) is 0x9C40 0000
68 # Test Case 3 - size of big file
Simon Glassddba5202025-02-09 09:07:14 -070069 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090070 'host bind 0 %s' % fs_img,
71 '%ssize host 0:0 /%s' % (fs_type, BIG_FILE),
72 'printenv filesize',
73 'setenv filesize'])
74 assert('filesize=9c400000' in ''.join(output))
75
Simon Glassddba5202025-02-09 09:07:14 -070076 def test_fs4(self, ubman, fs_obj_basic):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090077 """
78 Test Case 4 - load a small file, 1MB
79 """
80 fs_type,fs_img,md5val = fs_obj_basic
Simon Glassddba5202025-02-09 09:07:14 -070081 with ubman.log.section('Test Case 4 - load (small)'):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090082 # Test Case 4a - Read full 1MB of small file
Simon Glassddba5202025-02-09 09:07:14 -070083 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090084 'host bind 0 %s' % fs_img,
85 '%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE),
86 'printenv filesize'])
87 assert('filesize=100000' in ''.join(output))
88
89 # Test Case 4b - Read full 1MB of small file
Simon Glassddba5202025-02-09 09:07:14 -070090 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090091 'md5sum %x $filesize' % ADDR,
92 'setenv filesize'])
93 assert(md5val[0] in ''.join(output))
94
Simon Glassddba5202025-02-09 09:07:14 -070095 def test_fs5(self, ubman, fs_obj_basic):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +090096 """
97 Test Case 5 - load, reading first 1MB of 3GB file
98 """
99 fs_type,fs_img,md5val = fs_obj_basic
Simon Glassddba5202025-02-09 09:07:14 -0700100 with ubman.log.section('Test Case 5 - load (first 1MB)'):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900101 # Test Case 5a - First 1MB of big file
Simon Glassddba5202025-02-09 09:07:14 -0700102 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900103 'host bind 0 %s' % fs_img,
104 '%sload host 0:0 %x /%s %x 0x0' % (fs_type, ADDR, BIG_FILE, LENGTH),
105 'printenv filesize'])
106 assert('filesize=100000' in ''.join(output))
107
108 # Test Case 5b - First 1MB of big file
Simon Glassddba5202025-02-09 09:07:14 -0700109 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900110 'md5sum %x $filesize' % ADDR,
111 'setenv filesize'])
112 assert(md5val[1] in ''.join(output))
113
Simon Glassddba5202025-02-09 09:07:14 -0700114 def test_fs6(self, ubman, fs_obj_basic):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900115 """
116 Test Case 6 - load, reading last 1MB of 3GB file
117 """
118 fs_type,fs_img,md5val = fs_obj_basic
Simon Glassddba5202025-02-09 09:07:14 -0700119 with ubman.log.section('Test Case 6 - load (last 1MB)'):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900120 # fails for ext as no offset support
121 # Test Case 6a - Last 1MB of big file
Simon Glassddba5202025-02-09 09:07:14 -0700122 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900123 'host bind 0 %s' % fs_img,
124 '%sload host 0:0 %x /%s %x 0x9c300000'
125 % (fs_type, ADDR, BIG_FILE, LENGTH),
126 'printenv filesize'])
127 assert('filesize=100000' in ''.join(output))
128
129 # Test Case 6b - Last 1MB of big file
Simon Glassddba5202025-02-09 09:07:14 -0700130 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900131 'md5sum %x $filesize' % ADDR,
132 'setenv filesize'])
133 assert(md5val[2] in ''.join(output))
134
Simon Glassddba5202025-02-09 09:07:14 -0700135 def test_fs7(self, ubman, fs_obj_basic):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900136 """
137 Test Case 7 - load, 1MB from the last 1MB in 2GB
138 """
139 fs_type,fs_img,md5val = fs_obj_basic
Simon Glassddba5202025-02-09 09:07:14 -0700140 with ubman.log.section('Test Case 7 - load (last 1MB in 2GB)'):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900141 # fails for ext as no offset support
142 # Test Case 7a - One from the last 1MB chunk of 2GB
Simon Glassddba5202025-02-09 09:07:14 -0700143 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900144 'host bind 0 %s' % fs_img,
145 '%sload host 0:0 %x /%s %x 0x7ff00000'
146 % (fs_type, ADDR, BIG_FILE, LENGTH),
147 'printenv filesize'])
148 assert('filesize=100000' in ''.join(output))
149
150 # Test Case 7b - One from the last 1MB chunk of 2GB
Simon Glassddba5202025-02-09 09:07:14 -0700151 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900152 'md5sum %x $filesize' % ADDR,
153 'setenv filesize'])
154 assert(md5val[3] in ''.join(output))
155
Simon Glassddba5202025-02-09 09:07:14 -0700156 def test_fs8(self, ubman, fs_obj_basic):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900157 """
158 Test Case 8 - load, reading first 1MB in 2GB
159 """
160 fs_type,fs_img,md5val = fs_obj_basic
Simon Glassddba5202025-02-09 09:07:14 -0700161 with ubman.log.section('Test Case 8 - load (first 1MB in 2GB)'):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900162 # fails for ext as no offset support
163 # Test Case 8a - One from the start 1MB chunk from 2GB
Simon Glassddba5202025-02-09 09:07:14 -0700164 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900165 'host bind 0 %s' % fs_img,
166 '%sload host 0:0 %x /%s %x 0x80000000'
167 % (fs_type, ADDR, BIG_FILE, LENGTH),
168 'printenv filesize'])
169 assert('filesize=100000' in ''.join(output))
170
171 # Test Case 8b - One from the start 1MB chunk from 2GB
Simon Glassddba5202025-02-09 09:07:14 -0700172 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900173 'md5sum %x $filesize' % ADDR,
174 'setenv filesize'])
175 assert(md5val[4] in ''.join(output))
176
Simon Glassddba5202025-02-09 09:07:14 -0700177 def test_fs9(self, ubman, fs_obj_basic):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900178 """
179 Test Case 9 - load, 1MB crossing 2GB boundary
180 """
181 fs_type,fs_img,md5val = fs_obj_basic
Simon Glassddba5202025-02-09 09:07:14 -0700182 with ubman.log.section('Test Case 9 - load (crossing 2GB boundary)'):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900183 # fails for ext as no offset support
184 # Test Case 9a - One 1MB chunk crossing the 2GB boundary
Simon Glassddba5202025-02-09 09:07:14 -0700185 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900186 'host bind 0 %s' % fs_img,
187 '%sload host 0:0 %x /%s %x 0x7ff80000'
188 % (fs_type, ADDR, BIG_FILE, LENGTH),
189 'printenv filesize'])
190 assert('filesize=100000' in ''.join(output))
191
192 # Test Case 9b - One 1MB chunk crossing the 2GB boundary
Simon Glassddba5202025-02-09 09:07:14 -0700193 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900194 'md5sum %x $filesize' % ADDR,
195 'setenv filesize'])
196 assert(md5val[5] in ''.join(output))
197
Simon Glassddba5202025-02-09 09:07:14 -0700198 def test_fs10(self, ubman, fs_obj_basic):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900199 """
200 Test Case 10 - load, reading beyond file end'):
201 """
202 fs_type,fs_img,md5val = fs_obj_basic
Simon Glassddba5202025-02-09 09:07:14 -0700203 with ubman.log.section('Test Case 10 - load (beyond file end)'):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900204 # Generic failure case
205 # Test Case 10 - 2MB chunk from the last 1MB of big file
Simon Glassddba5202025-02-09 09:07:14 -0700206 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900207 'host bind 0 %s' % fs_img,
208 '%sload host 0:0 %x /%s 0x00200000 0x9c300000'
209 % (fs_type, ADDR, BIG_FILE),
210 'printenv filesize',
211 'md5sum %x $filesize' % ADDR,
212 'setenv filesize'])
213 assert('filesize=100000' in ''.join(output))
214
Simon Glassddba5202025-02-09 09:07:14 -0700215 def test_fs11(self, ubman, fs_obj_basic):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900216 """
217 Test Case 11 - write'
218 """
219 fs_type,fs_img,md5val = fs_obj_basic
Simon Glassddba5202025-02-09 09:07:14 -0700220 with ubman.log.section('Test Case 11 - write'):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900221 # Read 1MB from small file
222 # Write it back to test the writes
223 # Test Case 11a - Check that the write succeeded
Simon Glassddba5202025-02-09 09:07:14 -0700224 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900225 'host bind 0 %s' % fs_img,
226 '%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE),
227 '%swrite host 0:0 %x /%s.w $filesize'
228 % (fs_type, ADDR, SMALL_FILE)])
229 assert('1048576 bytes written' in ''.join(output))
230
231 # Test Case 11b - Check md5 of written to is same
232 # as the one read from
Simon Glassddba5202025-02-09 09:07:14 -0700233 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900234 '%sload host 0:0 %x /%s.w' % (fs_type, ADDR, SMALL_FILE),
235 'md5sum %x $filesize' % ADDR,
236 'setenv filesize'])
237 assert(md5val[0] in ''.join(output))
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +0100238 assert_fs_integrity(fs_type, fs_img)
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900239
Simon Glassddba5202025-02-09 09:07:14 -0700240 def test_fs12(self, ubman, fs_obj_basic):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900241 """
242 Test Case 12 - write to "." directory
243 """
244 fs_type,fs_img,md5val = fs_obj_basic
Simon Glassddba5202025-02-09 09:07:14 -0700245 with ubman.log.section('Test Case 12 - write (".")'):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900246 # Next test case checks writing a file whose dirent
247 # is the first in the block, which is always true for "."
248 # The write should fail, but the lookup should work
249 # Test Case 12 - Check directory traversal
Simon Glassddba5202025-02-09 09:07:14 -0700250 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900251 'host bind 0 %s' % fs_img,
252 '%swrite host 0:0 %x /. 0x10' % (fs_type, ADDR)])
253 assert('Unable to write' in ''.join(output))
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +0100254 assert_fs_integrity(fs_type, fs_img)
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900255
Simon Glassddba5202025-02-09 09:07:14 -0700256 def test_fs13(self, ubman, fs_obj_basic):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900257 """
258 Test Case 13 - write to a file with "/./<filename>"
259 """
260 fs_type,fs_img,md5val = fs_obj_basic
Simon Glassddba5202025-02-09 09:07:14 -0700261 with ubman.log.section('Test Case 13 - write ("./<file>")'):
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900262 # Read 1MB from small file
263 # Write it via "same directory", i.e. "." dirent
264 # Test Case 13a - Check directory traversal
Simon Glassddba5202025-02-09 09:07:14 -0700265 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900266 'host bind 0 %s' % fs_img,
267 '%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE),
268 '%swrite host 0:0 %x /./%s2 $filesize'
269 % (fs_type, ADDR, SMALL_FILE)])
270 assert('1048576 bytes written' in ''.join(output))
271
272 # Test Case 13b - Check md5 of written to is same
273 # as the one read from
Simon Glassddba5202025-02-09 09:07:14 -0700274 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900275 'mw.b %x 00 100' % ADDR,
276 '%sload host 0:0 %x /./%s2' % (fs_type, ADDR, SMALL_FILE),
277 'md5sum %x $filesize' % ADDR,
278 'setenv filesize'])
279 assert(md5val[0] in ''.join(output))
280
281 # Test Case 13c - Check md5 of written to is same
282 # as the one read from
Simon Glassddba5202025-02-09 09:07:14 -0700283 output = ubman.run_command_list([
AKASHI Takahiro615af9a2018-09-11 15:59:19 +0900284 'mw.b %x 00 100' % ADDR,
285 '%sload host 0:0 %x /%s2' % (fs_type, ADDR, SMALL_FILE),
286 'md5sum %x $filesize' % ADDR,
287 'setenv filesize'])
288 assert(md5val[0] in ''.join(output))
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +0100289 assert_fs_integrity(fs_type, fs_img)