blob: e36cff99bb7b1b5949d147559acded2cc89e3750 [file] [log] [blame]
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -05001# SPDX-License-Identifier: GPL-2.0+
2# Copyright 2025 Gabriel Dalimonte <gabriel.dalimonte@gmail.com>
3#
4# U-Boot File System:rename Test
5
6
7import pytest
8
9from fstest_defs import *
10from fstest_helpers import assert_fs_integrity
11
12@pytest.mark.boardspec('sandbox')
13@pytest.mark.slow
14class TestRename(object):
Simon Glassddba5202025-02-09 09:07:14 -070015 def test_rename1(self, ubman, fs_obj_rename):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -050016 """
17 Test Case 1 - rename a file (successful mv)
18 """
19 fs_type, fs_img, md5val = fs_obj_rename
Simon Glassddba5202025-02-09 09:07:14 -070020 with ubman.log.section('Test Case 1 - rename a file'):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -050021 d = 'test1'
22 src = '%s/file1' % d
23 dst = '%s/file2' % d
Simon Glassddba5202025-02-09 09:07:14 -070024 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -050025 'host bind 0 %s' % fs_img,
26 'setenv filesize',
27 'mv host 0:0 %s %s' % (src, dst),
28 ])
29 assert('' == ''.join(output))
30
Simon Glassddba5202025-02-09 09:07:14 -070031 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -050032 'load host 0:0 %x /%s' % (ADDR, dst),
33 'printenv filesize'])
34 assert('filesize=400' in output)
35
Simon Glassddba5202025-02-09 09:07:14 -070036 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -050037 'ls host 0:0 %s' % (d),
38 ])
39 assert('file1' not in ''.join(output))
40
Simon Glassddba5202025-02-09 09:07:14 -070041 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -050042 'md5sum %x $filesize' % ADDR,
43 'setenv filesize'])
44 assert(md5val['test1'] in ''.join(output))
45 assert_fs_integrity(fs_type, fs_img)
46
Simon Glassddba5202025-02-09 09:07:14 -070047 def test_rename2(self, ubman, fs_obj_rename):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -050048 """
49 Test Case 2 - rename a file to an existing file (successful mv)
50 """
51 fs_type, fs_img, md5val = fs_obj_rename
Simon Glassddba5202025-02-09 09:07:14 -070052 with ubman.log.section('Test Case 2 - rename a file to an existing file'):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -050053 d = 'test2'
54 src = '%s/file1' % d
55 dst = '%s/file_exist' % d
Simon Glassddba5202025-02-09 09:07:14 -070056 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -050057 'host bind 0 %s' % fs_img,
58 'setenv filesize',
59 'mv host 0:0 %s %s' % (src, dst),
60 ])
61 assert('' == ''.join(output))
62
Simon Glassddba5202025-02-09 09:07:14 -070063 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -050064 'load host 0:0 %x /%s' % (ADDR, dst),
65 'printenv filesize'])
66 assert('filesize=400' in output)
67
Simon Glassddba5202025-02-09 09:07:14 -070068 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -050069 'ls host 0:0 %s' % (d),
70 ])
71 assert('file1' not in ''.join(output))
72
Simon Glassddba5202025-02-09 09:07:14 -070073 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -050074 'md5sum %x $filesize' % ADDR,
75 'setenv filesize'])
76 assert(md5val['test2'] in ''.join(output))
77 assert_fs_integrity(fs_type, fs_img)
78
Simon Glassddba5202025-02-09 09:07:14 -070079 def test_rename3(self, ubman, fs_obj_rename):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -050080 """
81 Test Case 3 - rename a directory (successful mv)
82 """
83 fs_type, fs_img, md5val = fs_obj_rename
Simon Glassddba5202025-02-09 09:07:14 -070084 with ubman.log.section('Test Case 3 - rename a directory'):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -050085 d = 'test3'
86 src = '%s/dir1' % d
87 dst = '%s/dir2' % d
Simon Glassddba5202025-02-09 09:07:14 -070088 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -050089 'host bind 0 %s' % fs_img,
90 'setenv filesize',
91 'mv host 0:0 %s %s' % (src, dst),
92 ])
93 assert('' == ''.join(output))
94
Simon Glassddba5202025-02-09 09:07:14 -070095 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -050096 'load host 0:0 %x /%s/file1' % (ADDR, dst),
97 'printenv filesize'])
98 assert('filesize=400' in output)
99
Simon Glassddba5202025-02-09 09:07:14 -0700100 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500101 'ls host 0:0 %s' % (d),
102 ])
103 assert('dir1' not in ''.join(output))
104
Simon Glassddba5202025-02-09 09:07:14 -0700105 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500106 'md5sum %x $filesize' % ADDR,
107 'setenv filesize'])
108 assert(md5val['test3'] in ''.join(output))
109 assert_fs_integrity(fs_type, fs_img)
110
Simon Glassddba5202025-02-09 09:07:14 -0700111 def test_rename4(self, ubman, fs_obj_rename):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500112 """
113 Test Case 4 - rename a directory to an existing directory (successful
114 mv)
115 """
116 fs_type, fs_img, md5val = fs_obj_rename
Simon Glassddba5202025-02-09 09:07:14 -0700117 with ubman.log.section('Test Case 4 - rename a directory to an existing directory'):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500118 d = 'test4'
119 src = '%s/dir1' % d
120 dst = '%s/dir2' % d
Simon Glassddba5202025-02-09 09:07:14 -0700121 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500122 'host bind 0 %s' % fs_img,
123 'setenv filesize',
124 'mv host 0:0 %s %s' % (src, dst),
125 ])
126 assert('' == ''.join(output))
127
Simon Glassddba5202025-02-09 09:07:14 -0700128 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500129 'load host 0:0 %x /%s/dir1/file1' % (ADDR, dst),
130 'printenv filesize'])
131 assert('filesize=400' in output)
132
Simon Glassddba5202025-02-09 09:07:14 -0700133 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500134 'ls host 0:0 %s' % (d),
135 ])
136 assert('dir1' not in ''.join(output))
137
Simon Glassddba5202025-02-09 09:07:14 -0700138 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500139 'md5sum %x $filesize' % ADDR,
140 'setenv filesize'])
141 assert(md5val['test4'] in ''.join(output))
142 assert_fs_integrity(fs_type, fs_img)
143
Simon Glassddba5202025-02-09 09:07:14 -0700144 def test_rename5(self, ubman, fs_obj_rename):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500145 """
146 Test Case 5 - rename a directory to an existing file (failed mv)
147 """
148 fs_type, fs_img, md5val = fs_obj_rename
Simon Glassddba5202025-02-09 09:07:14 -0700149 with ubman.log.section('Test Case 5 - rename a directory to an existing file'):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500150 d = 'test5'
151 src = '%s/dir1' % d
152 dst = '%s/file2' % d
Simon Glassddba5202025-02-09 09:07:14 -0700153 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500154 'host bind 0 %s' % fs_img,
155 'setenv filesize',
156 'mv host 0:0 %s %s' % (src, dst),
157 ])
158 assert('' == ''.join(output))
159
Simon Glassddba5202025-02-09 09:07:14 -0700160 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500161 'ls host 0:0 %s' % (d),
162 ])
163 assert('dir1' in ''.join(output))
164 assert('file2' in ''.join(output))
165
Simon Glassddba5202025-02-09 09:07:14 -0700166 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500167 'load host 0:0 %x /%s' % (ADDR, dst),
168 'printenv filesize'])
169 assert('filesize=400' in output)
170
Simon Glassddba5202025-02-09 09:07:14 -0700171 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500172 'md5sum %x $filesize' % ADDR,
173 'setenv filesize'])
174 assert(md5val['test5'] in ''.join(output))
175 assert_fs_integrity(fs_type, fs_img)
176
Simon Glassddba5202025-02-09 09:07:14 -0700177 def test_rename6(self, ubman, fs_obj_rename):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500178 """
179 Test Case 6 - rename a file to an existing empty directory (failed mv)
180 """
181 fs_type, fs_img, md5val = fs_obj_rename
Simon Glassddba5202025-02-09 09:07:14 -0700182 with ubman.log.section('Test Case 6 - rename a file to an existing empty directory'):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500183 d = 'test6'
184 src = '%s/existing' % d
185 dst = '%s/dir2' % d
Simon Glassddba5202025-02-09 09:07:14 -0700186 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500187 'host bind 0 %s' % fs_img,
188 'setenv filesize',
189 'mv host 0:0 %s %s' % (src, dst),
190 ])
191 assert('' == ''.join(output))
192
Simon Glassddba5202025-02-09 09:07:14 -0700193 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500194 'load host 0:0 %x /%s' % (ADDR, src),
195 'printenv filesize'])
196 assert('filesize=400' in output)
197
Simon Glassddba5202025-02-09 09:07:14 -0700198 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500199 'ls host 0:0 %s' % (d),
200 ])
201 assert('dir2' in ''.join(output))
202 assert('existing' in ''.join(output))
203
Simon Glassddba5202025-02-09 09:07:14 -0700204 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500205 'md5sum %x $filesize' % ADDR,
206 'setenv filesize'])
207 assert(md5val['test6'] in ''.join(output))
208 assert_fs_integrity(fs_type, fs_img)
209
Simon Glassddba5202025-02-09 09:07:14 -0700210 def test_rename7(self, ubman, fs_obj_rename):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500211 """
212 Test Case 7 - rename a directory to a non-empty directory (failed mv)
213 """
214 fs_type, fs_img, md5val = fs_obj_rename
Simon Glassddba5202025-02-09 09:07:14 -0700215 with ubman.log.section('Test Case 7 - rename a directory to a non-empty directory'):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500216 d = 'test7'
217 src = '%s/dir1' % d
218 dst = '%s/dir2' % d
Simon Glassddba5202025-02-09 09:07:14 -0700219 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500220 'host bind 0 %s' % fs_img,
221 'setenv filesize',
222 'mv host 0:0 %s %s' % (src, dst),
223 ])
224 assert('' == ''.join(output))
225
Simon Glassddba5202025-02-09 09:07:14 -0700226 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500227 'load host 0:0 %x /%s/dir1/file1' % (ADDR, dst),
228 'printenv filesize'])
229 assert('filesize=400' in output)
230
Simon Glassddba5202025-02-09 09:07:14 -0700231 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500232 'ls host 0:0 %s' % (d),
233 ])
234 assert('dir1' in ''.join(output))
235 assert('dir2' in ''.join(output))
236
Simon Glassddba5202025-02-09 09:07:14 -0700237 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500238 'md5sum %x $filesize' % ADDR,
239 'setenv filesize'])
240 assert(md5val['test7'] in ''.join(output))
241 assert_fs_integrity(fs_type, fs_img)
242
Simon Glassddba5202025-02-09 09:07:14 -0700243 def test_rename8(self, ubman, fs_obj_rename):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500244 """
245 Test Case 8 - rename a directory inside itself (failed mv)
246 """
247 fs_type, fs_img, md5val = fs_obj_rename
Simon Glassddba5202025-02-09 09:07:14 -0700248 with ubman.log.section('Test Case 8 - rename a directory inside itself'):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500249 d = 'test8'
250 src = '%s/dir1' % d
251 dst = '%s/dir1/dir1' % d
Simon Glassddba5202025-02-09 09:07:14 -0700252 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500253 'host bind 0 %s' % fs_img,
254 'setenv filesize',
255 'mv host 0:0 %s %s' % (src, dst),
256 ])
257 assert('' == ''.join(output))
258
Simon Glassddba5202025-02-09 09:07:14 -0700259 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500260 'load host 0:0 %x /%s/file1' % (ADDR, src),
261 'printenv filesize'])
262 assert('filesize=400' in output)
263
Simon Glassddba5202025-02-09 09:07:14 -0700264 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500265 'ls host 0:0 %s' % (d),
266 ])
267 assert('dir1' in ''.join(output))
268
Simon Glassddba5202025-02-09 09:07:14 -0700269 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500270 'ls host 0:0 %s' % (src),
271 ])
272 assert('file1' in ''.join(output))
273 assert('dir1' not in ''.join(output))
274
Simon Glassddba5202025-02-09 09:07:14 -0700275 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500276 'md5sum %x $filesize' % ADDR,
277 'setenv filesize'])
278 assert(md5val['test8'] in ''.join(output))
279 assert_fs_integrity(fs_type, fs_img)
280
Simon Glassddba5202025-02-09 09:07:14 -0700281 def test_rename9(self, ubman, fs_obj_rename):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500282 """
283 Test Case 9 - rename a directory inside itself with backtracks (failed
284 mv)
285 """
286 fs_type, fs_img, md5val = fs_obj_rename
Simon Glassddba5202025-02-09 09:07:14 -0700287 with ubman.log.section('Test Case 9 - rename a directory inside itself with backtracks'):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500288 d = 'test9'
289 src = '%s/dir1/nested' % d
290 dst = '%s/dir1/nested/inner/./../../../dir1/nested/inner/another' % d
Simon Glassddba5202025-02-09 09:07:14 -0700291 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500292 'host bind 0 %s' % fs_img,
293 'setenv filesize',
294 'mv host 0:0 %s %s' % (src, dst),
295 ])
296 assert('' == ''.join(output))
297
Simon Glassddba5202025-02-09 09:07:14 -0700298 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500299 'ls host 0:0 %s/dir1' % (d),
300 ])
301 assert('nested' in ''.join(output))
302
Simon Glassddba5202025-02-09 09:07:14 -0700303 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500304 'ls host 0:0 %s' % (src),
305 ])
306 assert('inner' in ''.join(output))
307 assert('nested' not in ''.join(output))
308 assert_fs_integrity(fs_type, fs_img)
309
Simon Glassddba5202025-02-09 09:07:14 -0700310 def test_rename10(self, ubman, fs_obj_rename):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500311 """
312 Test Case 10 - rename a file to itself (successful mv)
313 """
314 fs_type, fs_img, md5val = fs_obj_rename
Simon Glassddba5202025-02-09 09:07:14 -0700315 with ubman.log.section('Test Case 10 - rename a file to itself'):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500316 d = 'test10'
317 src = '%s/file1' % d
Simon Glassddba5202025-02-09 09:07:14 -0700318 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500319 'host bind 0 %s' % fs_img,
320 'setenv filesize',
321 'mv host 0:0 %s %s' % (src, src),
322 ])
323 assert('' == ''.join(output))
324
Simon Glassddba5202025-02-09 09:07:14 -0700325 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500326 'load host 0:0 %x /%s' % (ADDR, src),
327 'printenv filesize'])
328 assert('filesize=400' in output)
329
Simon Glassddba5202025-02-09 09:07:14 -0700330 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500331 'ls host 0:0 %s' % (d),
332 ])
333 assert('file1' in ''.join(output))
334
Simon Glassddba5202025-02-09 09:07:14 -0700335 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500336 'md5sum %x $filesize' % ADDR,
337 'setenv filesize'])
338 assert(md5val['test10'] in ''.join(output))
339 assert_fs_integrity(fs_type, fs_img)
340
Simon Glassddba5202025-02-09 09:07:14 -0700341 def test_rename11(self, ubman, fs_obj_rename):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500342 """
343 Test Case 11 - rename a directory to itself (successful mv)
344 """
345 fs_type, fs_img, md5val = fs_obj_rename
Simon Glassddba5202025-02-09 09:07:14 -0700346 with ubman.log.section('Test Case 11 - rename a directory to itself'):
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500347 # / at the end here is intentional. Ensures trailing / doesn't
348 # affect mv producing an updated dst path for fs_rename
349 d = 'test11/'
350 src = '%sdir1' % d
Simon Glassddba5202025-02-09 09:07:14 -0700351 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500352 'host bind 0 %s' % fs_img,
353 'setenv filesize',
354 'mv host 0:0 %s %s' % (src, d),
355 ])
356 assert('' == ''.join(output))
357
Simon Glassddba5202025-02-09 09:07:14 -0700358 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500359 'load host 0:0 %x /%s/file1' % (ADDR, src),
360 'printenv filesize'])
361 assert('filesize=400' in output)
362
Simon Glassddba5202025-02-09 09:07:14 -0700363 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500364 'ls host 0:0 %s' % (d),
365 ])
366 assert('dir1' in ''.join(output))
367
Simon Glassddba5202025-02-09 09:07:14 -0700368 output = ubman.run_command_list([
Gabriel Dalimonte4b93d6e2025-02-17 13:26:44 -0500369 'md5sum %x $filesize' % ADDR,
370 'setenv filesize'])
371 assert(md5val['test11'] in ''.join(output))
372 assert_fs_integrity(fs_type, fs_img)