1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2018, Linaro Limited
5 # U-Boot File System:unlink Test
8 This test verifies unlink operation (deleting a file or a directory)
14 @pytest.mark.boardspec('sandbox')
16 class TestUnlink(object):
17 def test_unlink1(self, u_boot_console, fs_obj_unlink):
19 Test Case 1 - delete a file
21 fs_type,fs_img = fs_obj_unlink
22 with u_boot_console.log.section('Test Case 1 - unlink (file)'):
23 output = u_boot_console.run_command_list([
24 'host bind 0 %s' % fs_img,
25 '%srm host 0:0 dir1/file1' % fs_type,
26 '%sls host 0:0 dir1/file1' % fs_type])
27 assert('' == ''.join(output))
29 output = u_boot_console.run_command(
30 '%sls host 0:0 dir1/' % fs_type)
31 assert(not 'file1' in output)
32 assert('file2' in output)
34 def test_unlink2(self, u_boot_console, fs_obj_unlink):
36 Test Case 2 - delete many files
38 fs_type,fs_img = fs_obj_unlink
39 with u_boot_console.log.section('Test Case 2 - unlink (many)'):
40 output = u_boot_console.run_command('host bind 0 %s' % fs_img)
42 for i in range(0, 20):
43 output = u_boot_console.run_command_list([
44 '%srm host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i),
45 '%sls host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i)])
46 assert('' == ''.join(output))
48 output = u_boot_console.run_command(
49 '%sls host 0:0 dir2' % fs_type)
50 assert('0 file(s), 2 dir(s)' in output)
52 def test_unlink3(self, u_boot_console, fs_obj_unlink):
54 Test Case 3 - trying to delete a non-existing file should fail
56 fs_type,fs_img = fs_obj_unlink
57 with u_boot_console.log.section('Test Case 3 - unlink (non-existing)'):
58 output = u_boot_console.run_command_list([
59 'host bind 0 %s' % fs_img,
60 '%srm host 0:0 dir1/nofile' % fs_type])
61 assert('nofile: doesn\'t exist' in ''.join(output))
63 def test_unlink4(self, u_boot_console, fs_obj_unlink):
65 Test Case 4 - delete an empty directory
67 fs_type,fs_img = fs_obj_unlink
68 with u_boot_console.log.section('Test Case 4 - unlink (directory)'):
69 output = u_boot_console.run_command_list([
70 'host bind 0 %s' % fs_img,
71 '%srm host 0:0 dir4' % fs_type])
72 assert('' == ''.join(output))
74 output = u_boot_console.run_command(
75 '%sls host 0:0 /' % fs_type)
76 assert(not 'dir4' in output)
78 def test_unlink5(self, u_boot_console, fs_obj_unlink):
80 Test Case 5 - trying to deleting a non-empty directory ".."
83 fs_type,fs_img = fs_obj_unlink
84 with u_boot_console.log.section('Test Case 5 - unlink ("non-empty directory")'):
85 output = u_boot_console.run_command_list([
86 'host bind 0 %s' % fs_img,
87 '%srm host 0:0 dir5' % fs_type])
88 assert('directory is not empty' in ''.join(output))
90 def test_unlink6(self, u_boot_console, fs_obj_unlink):
92 Test Case 6 - trying to deleting a "." should fail
94 fs_type,fs_img = fs_obj_unlink
95 with u_boot_console.log.section('Test Case 6 - unlink (".")'):
96 output = u_boot_console.run_command_list([
97 'host bind 0 %s' % fs_img,
98 '%srm host 0:0 dir5/.' % fs_type])
99 assert('directory is not empty' in ''.join(output))
101 def test_unlink7(self, u_boot_console, fs_obj_unlink):
103 Test Case 7 - trying to deleting a ".." should fail
105 fs_type,fs_img = fs_obj_unlink
106 with u_boot_console.log.section('Test Case 7 - unlink ("..")'):
107 output = u_boot_console.run_command_list([
108 'host bind 0 %s' % fs_img,
109 '%srm host 0:0 dir5/..' % fs_type])
110 assert('directory is not empty' in ''.join(output))