blob: 7e911f02413996059b333a077d444ea46b2e5396 [file] [log] [blame]
Akashi, Takahirod49e7992018-09-11 16:06:03 +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:unlink Test
6
7"""
8This test verifies unlink operation (deleting a file or a directory)
9on file system.
10"""
11
12import pytest
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +010013from fstest_helpers import assert_fs_integrity
Akashi, Takahirod49e7992018-09-11 16:06:03 +090014
15@pytest.mark.boardspec('sandbox')
Simon Glass3fcb8282018-11-18 08:14:29 -070016@pytest.mark.slow
Akashi, Takahirod49e7992018-09-11 16:06:03 +090017class TestUnlink(object):
Simon Glassddba5202025-02-09 09:07:14 -070018 def test_unlink1(self, ubman, fs_obj_unlink):
Akashi, Takahirod49e7992018-09-11 16:06:03 +090019 """
20 Test Case 1 - delete a file
21 """
22 fs_type,fs_img = fs_obj_unlink
Simon Glassddba5202025-02-09 09:07:14 -070023 with ubman.log.section('Test Case 1 - unlink (file)'):
24 output = ubman.run_command_list([
Akashi, Takahirod49e7992018-09-11 16:06:03 +090025 'host bind 0 %s' % fs_img,
26 '%srm host 0:0 dir1/file1' % fs_type,
27 '%sls host 0:0 dir1/file1' % fs_type])
28 assert('' == ''.join(output))
29
Simon Glassddba5202025-02-09 09:07:14 -070030 output = ubman.run_command(
Akashi, Takahirod49e7992018-09-11 16:06:03 +090031 '%sls host 0:0 dir1/' % fs_type)
32 assert(not 'file1' in output)
33 assert('file2' in output)
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +010034 assert_fs_integrity(fs_type, fs_img)
Akashi, Takahirod49e7992018-09-11 16:06:03 +090035
Simon Glassddba5202025-02-09 09:07:14 -070036 def test_unlink2(self, ubman, fs_obj_unlink):
Akashi, Takahirod49e7992018-09-11 16:06:03 +090037 """
38 Test Case 2 - delete many files
39 """
40 fs_type,fs_img = fs_obj_unlink
Simon Glassddba5202025-02-09 09:07:14 -070041 with ubman.log.section('Test Case 2 - unlink (many)'):
42 output = ubman.run_command('host bind 0 %s' % fs_img)
Akashi, Takahirod49e7992018-09-11 16:06:03 +090043
44 for i in range(0, 20):
Simon Glassddba5202025-02-09 09:07:14 -070045 output = ubman.run_command_list([
Akashi, Takahirod49e7992018-09-11 16:06:03 +090046 '%srm host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i),
47 '%sls host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i)])
48 assert('' == ''.join(output))
49
Simon Glassddba5202025-02-09 09:07:14 -070050 output = ubman.run_command(
Akashi, Takahirod49e7992018-09-11 16:06:03 +090051 '%sls host 0:0 dir2' % fs_type)
52 assert('0 file(s), 2 dir(s)' in output)
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +010053 assert_fs_integrity(fs_type, fs_img)
Akashi, Takahirod49e7992018-09-11 16:06:03 +090054
Simon Glassddba5202025-02-09 09:07:14 -070055 def test_unlink3(self, ubman, fs_obj_unlink):
Akashi, Takahirod49e7992018-09-11 16:06:03 +090056 """
57 Test Case 3 - trying to delete a non-existing file should fail
58 """
59 fs_type,fs_img = fs_obj_unlink
Simon Glassddba5202025-02-09 09:07:14 -070060 with ubman.log.section('Test Case 3 - unlink (non-existing)'):
61 output = ubman.run_command_list([
Akashi, Takahirod49e7992018-09-11 16:06:03 +090062 'host bind 0 %s' % fs_img,
63 '%srm host 0:0 dir1/nofile' % fs_type])
64 assert('nofile: doesn\'t exist' in ''.join(output))
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +010065 assert_fs_integrity(fs_type, fs_img)
Akashi, Takahirod49e7992018-09-11 16:06:03 +090066
Simon Glassddba5202025-02-09 09:07:14 -070067 def test_unlink4(self, ubman, fs_obj_unlink):
Akashi, Takahirod49e7992018-09-11 16:06:03 +090068 """
69 Test Case 4 - delete an empty directory
70 """
71 fs_type,fs_img = fs_obj_unlink
Simon Glassddba5202025-02-09 09:07:14 -070072 with ubman.log.section('Test Case 4 - unlink (directory)'):
73 output = ubman.run_command_list([
Akashi, Takahirod49e7992018-09-11 16:06:03 +090074 'host bind 0 %s' % fs_img,
75 '%srm host 0:0 dir4' % fs_type])
76 assert('' == ''.join(output))
77
Simon Glassddba5202025-02-09 09:07:14 -070078 output = ubman.run_command(
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +010079 '%sls host 0:0 /' % fs_type)
80 assert(not 'dir4' in output)
81 assert_fs_integrity(fs_type, fs_img)
Akashi, Takahirod49e7992018-09-11 16:06:03 +090082
Simon Glassddba5202025-02-09 09:07:14 -070083 def test_unlink5(self, ubman, fs_obj_unlink):
Akashi, Takahirod49e7992018-09-11 16:06:03 +090084 """
85 Test Case 5 - trying to deleting a non-empty directory ".."
86 should fail
87 """
88 fs_type,fs_img = fs_obj_unlink
Simon Glassddba5202025-02-09 09:07:14 -070089 with ubman.log.section('Test Case 5 - unlink ("non-empty directory")'):
90 output = ubman.run_command_list([
Akashi, Takahirod49e7992018-09-11 16:06:03 +090091 'host bind 0 %s' % fs_img,
92 '%srm host 0:0 dir5' % fs_type])
93 assert('directory is not empty' in ''.join(output))
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +010094 assert_fs_integrity(fs_type, fs_img)
Akashi, Takahirod49e7992018-09-11 16:06:03 +090095
Simon Glassddba5202025-02-09 09:07:14 -070096 def test_unlink6(self, ubman, fs_obj_unlink):
Akashi, Takahirod49e7992018-09-11 16:06:03 +090097 """
98 Test Case 6 - trying to deleting a "." should fail
99 """
100 fs_type,fs_img = fs_obj_unlink
Simon Glassddba5202025-02-09 09:07:14 -0700101 with ubman.log.section('Test Case 6 - unlink (".")'):
102 output = ubman.run_command_list([
Akashi, Takahirod49e7992018-09-11 16:06:03 +0900103 'host bind 0 %s' % fs_img,
104 '%srm host 0:0 dir5/.' % fs_type])
105 assert('directory is not empty' in ''.join(output))
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +0100106 assert_fs_integrity(fs_type, fs_img)
Akashi, Takahirod49e7992018-09-11 16:06:03 +0900107
Simon Glassddba5202025-02-09 09:07:14 -0700108 def test_unlink7(self, ubman, fs_obj_unlink):
Akashi, Takahirod49e7992018-09-11 16:06:03 +0900109 """
110 Test Case 7 - trying to deleting a ".." should fail
111 """
112 fs_type,fs_img = fs_obj_unlink
Simon Glassddba5202025-02-09 09:07:14 -0700113 with ubman.log.section('Test Case 7 - unlink ("..")'):
114 output = ubman.run_command_list([
Akashi, Takahirod49e7992018-09-11 16:06:03 +0900115 'host bind 0 %s' % fs_img,
116 '%srm host 0:0 dir5/..' % fs_type])
117 assert('directory is not empty' in ''.join(output))
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +0100118 assert_fs_integrity(fs_type, fs_img)