1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2018, Linaro Limited
3 # Author: Takahiro Akashi <takahiro.akashi@linaro.org>
5 # U-Boot File System:unlink Test
8 This test verifies unlink operation (deleting a file or a directory)
14 @pytest.mark.boardspec('sandbox')
15 class TestUnlink(object):
16 def test_unlink1(self, u_boot_console, fs_obj_unlink):
18 Test Case 1 - delete a file
20 fs_type,fs_img = fs_obj_unlink
21 with u_boot_console.log.section('Test Case 1 - unlink (file)'):
22 output = u_boot_console.run_command_list([
23 'host bind 0 %s' % fs_img,
24 '%srm host 0:0 dir1/file1' % fs_type,
25 '%sls host 0:0 dir1/file1' % fs_type])
26 assert('' == ''.join(output))
28 output = u_boot_console.run_command(
29 '%sls host 0:0 dir1/' % fs_type)
30 assert(not 'file1' in output)
31 assert('file2' in output)
33 def test_unlink2(self, u_boot_console, fs_obj_unlink):
35 Test Case 2 - delete many files
37 fs_type,fs_img = fs_obj_unlink
38 with u_boot_console.log.section('Test Case 2 - unlink (many)'):
39 output = u_boot_console.run_command('host bind 0 %s' % fs_img)
41 for i in range(0, 20):
42 output = u_boot_console.run_command_list([
43 '%srm host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i),
44 '%sls host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i)])
45 assert('' == ''.join(output))
47 output = u_boot_console.run_command(
48 '%sls host 0:0 dir2' % fs_type)
49 assert('0 file(s), 2 dir(s)' in output)
51 def test_unlink3(self, u_boot_console, fs_obj_unlink):
53 Test Case 3 - trying to delete a non-existing file should fail
55 fs_type,fs_img = fs_obj_unlink
56 with u_boot_console.log.section('Test Case 3 - unlink (non-existing)'):
57 output = u_boot_console.run_command_list([
58 'host bind 0 %s' % fs_img,
59 '%srm host 0:0 dir1/nofile' % fs_type])
60 assert('nofile: doesn\'t exist' in ''.join(output))
62 def test_unlink4(self, u_boot_console, fs_obj_unlink):
64 Test Case 4 - delete an empty directory
66 fs_type,fs_img = fs_obj_unlink
67 with u_boot_console.log.section('Test Case 4 - unlink (directory)'):
68 output = u_boot_console.run_command_list([
69 'host bind 0 %s' % fs_img,
70 '%srm host 0:0 dir4' % fs_type])
71 assert('' == ''.join(output))
73 output = u_boot_console.run_command(
74 '%sls host 0:0 /' % fs_type)
75 assert(not 'dir4' in output)
77 def test_unlink5(self, u_boot_console, fs_obj_unlink):
79 Test Case 5 - trying to deleting a non-empty directory ".."
82 fs_type,fs_img = fs_obj_unlink
83 with u_boot_console.log.section('Test Case 5 - unlink ("non-empty directory")'):
84 output = u_boot_console.run_command_list([
85 'host bind 0 %s' % fs_img,
86 '%srm host 0:0 dir5' % fs_type])
87 assert('directory is not empty' in ''.join(output))
89 def test_unlink6(self, u_boot_console, fs_obj_unlink):
91 Test Case 6 - trying to deleting a "." should fail
93 fs_type,fs_img = fs_obj_unlink
94 with u_boot_console.log.section('Test Case 6 - unlink (".")'):
95 output = u_boot_console.run_command_list([
96 'host bind 0 %s' % fs_img,
97 '%srm host 0:0 dir5/.' % fs_type])
98 assert('directory is not empty' in ''.join(output))
100 def test_unlink7(self, u_boot_console, fs_obj_unlink):
102 Test Case 7 - trying to deleting a ".." should fail
104 fs_type,fs_img = fs_obj_unlink
105 with u_boot_console.log.section('Test Case 7 - unlink ("..")'):
106 output = u_boot_console.run_command_list([
107 'host bind 0 %s' % fs_img,
108 '%srm host 0:0 dir5/..' % fs_type])
109 assert('directory is not empty' in ''.join(output))