blob: df680a87d5780f6454feddef1d30353c86128bb6 [file] [log] [blame]
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +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:mkdir Test
6
7"""
8This test verifies mkdir operation on file system.
9"""
10
11import pytest
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +010012from fstest_helpers import assert_fs_integrity
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090013
14@pytest.mark.boardspec('sandbox')
Simon Glass3fcb8282018-11-18 08:14:29 -070015@pytest.mark.slow
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090016class TestMkdir(object):
Simon Glassddba5202025-02-09 09:07:14 -070017 def test_mkdir1(self, ubman, fs_obj_mkdir):
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090018 """
19 Test Case 1 - create a directory under a root
20 """
21 fs_type,fs_img = fs_obj_mkdir
Simon Glassddba5202025-02-09 09:07:14 -070022 with ubman.log.section('Test Case 1 - mkdir'):
23 output = ubman.run_command_list([
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090024 'host bind 0 %s' % fs_img,
25 '%smkdir host 0:0 dir1' % fs_type,
26 '%sls host 0:0 /' % fs_type])
27 assert('dir1/' in ''.join(output))
28
Simon Glassddba5202025-02-09 09:07:14 -070029 output = ubman.run_command(
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090030 '%sls host 0:0 dir1' % fs_type)
31 assert('./' in output)
32 assert('../' in output)
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +010033 assert_fs_integrity(fs_type, fs_img)
34
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090035
Simon Glassddba5202025-02-09 09:07:14 -070036 def test_mkdir2(self, ubman, fs_obj_mkdir):
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090037 """
38 Test Case 2 - create a directory under a sub-directory
39 """
40 fs_type,fs_img = fs_obj_mkdir
Simon Glassddba5202025-02-09 09:07:14 -070041 with ubman.log.section('Test Case 2 - mkdir (sub-sub directory)'):
42 output = ubman.run_command_list([
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090043 'host bind 0 %s' % fs_img,
44 '%smkdir host 0:0 dir1/dir2' % fs_type,
45 '%sls host 0:0 dir1' % fs_type])
46 assert('dir2/' in ''.join(output))
47
Simon Glassddba5202025-02-09 09:07:14 -070048 output = ubman.run_command(
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090049 '%sls host 0:0 dir1/dir2' % fs_type)
50 assert('./' in output)
51 assert('../' in output)
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +010052 assert_fs_integrity(fs_type, fs_img)
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090053
Simon Glassddba5202025-02-09 09:07:14 -070054 def test_mkdir3(self, ubman, fs_obj_mkdir):
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090055 """
56 Test Case 3 - trying to create a directory with a non-existing
57 path should fail
58 """
59 fs_type,fs_img = fs_obj_mkdir
Simon Glassddba5202025-02-09 09:07:14 -070060 with ubman.log.section('Test Case 3 - mkdir (non-existing path)'):
61 output = ubman.run_command_list([
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090062 'host bind 0 %s' % fs_img,
63 '%smkdir host 0:0 none/dir3' % fs_type])
64 assert('Unable to create a directory' in ''.join(output))
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +010065 assert_fs_integrity(fs_type, fs_img)
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090066
Simon Glassddba5202025-02-09 09:07:14 -070067 def test_mkdir4(self, ubman, fs_obj_mkdir):
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090068 """
69 Test Case 4 - trying to create "." should fail
70 """
71 fs_type,fs_img = fs_obj_mkdir
Simon Glassddba5202025-02-09 09:07:14 -070072 with ubman.log.section('Test Case 4 - mkdir (".")'):
73 output = ubman.run_command_list([
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090074 'host bind 0 %s' % fs_img,
75 '%smkdir host 0:0 .' % fs_type])
76 assert('Unable to create a directory' in ''.join(output))
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +010077 assert_fs_integrity(fs_type, fs_img)
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090078
Simon Glassddba5202025-02-09 09:07:14 -070079 def test_mkdir5(self, ubman, fs_obj_mkdir):
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090080 """
81 Test Case 5 - trying to create ".." should fail
82 """
83 fs_type,fs_img = fs_obj_mkdir
Simon Glassddba5202025-02-09 09:07:14 -070084 with ubman.log.section('Test Case 5 - mkdir ("..")'):
85 output = ubman.run_command_list([
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090086 'host bind 0 %s' % fs_img,
87 '%smkdir host 0:0 ..' % fs_type])
88 assert('Unable to create a directory' in ''.join(output))
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +010089 assert_fs_integrity(fs_type, fs_img)
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090090
Simon Glassddba5202025-02-09 09:07:14 -070091 def test_mkdir6(self, ubman, fs_obj_mkdir):
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090092 """
93 'Test Case 6 - create as many directories as amount of directory
94 entries goes beyond a cluster size)'
95 """
96 fs_type,fs_img = fs_obj_mkdir
Simon Glassddba5202025-02-09 09:07:14 -070097 with ubman.log.section('Test Case 6 - mkdir (create many)'):
98 output = ubman.run_command_list([
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090099 'host bind 0 %s' % fs_img,
100 '%smkdir host 0:0 dir6' % fs_type,
101 '%sls host 0:0 /' % fs_type])
102 assert('dir6/' in ''.join(output))
103
104 for i in range(0, 20):
Simon Glassddba5202025-02-09 09:07:14 -0700105 output = ubman.run_command(
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +0900106 '%smkdir host 0:0 dir6/0123456789abcdef%02x'
107 % (fs_type, i))
Simon Glassddba5202025-02-09 09:07:14 -0700108 output = ubman.run_command('%sls host 0:0 dir6' % fs_type)
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +0900109 assert('0123456789abcdef00/' in output)
110 assert('0123456789abcdef13/' in output)
111
Simon Glassddba5202025-02-09 09:07:14 -0700112 output = ubman.run_command(
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +0900113 '%sls host 0:0 dir6/0123456789abcdef13/.' % fs_type)
114 assert('./' in output)
115 assert('../' in output)
116
Simon Glassddba5202025-02-09 09:07:14 -0700117 output = ubman.run_command(
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +0900118 '%sls host 0:0 dir6/0123456789abcdef13/..' % fs_type)
119 assert('0123456789abcdef00/' in output)
120 assert('0123456789abcdef13/' in output)
Jean-Jacques Hiblotd2fd35c2019-02-13 12:15:23 +0100121 assert_fs_integrity(fs_type, fs_img)