blob: b3fe11cf3b52f8c7230041586a12b0033145b8c7 [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
12
13@pytest.mark.boardspec('sandbox')
Simon Glass3fcb8282018-11-18 08:14:29 -070014@pytest.mark.slow
AKASHI Takahiro1e90c2c2018-09-11 15:59:21 +090015class TestMkdir(object):
16 def test_mkdir1(self, u_boot_console, fs_obj_mkdir):
17 """
18 Test Case 1 - create a directory under a root
19 """
20 fs_type,fs_img = fs_obj_mkdir
21 with u_boot_console.log.section('Test Case 1 - mkdir'):
22 output = u_boot_console.run_command_list([
23 'host bind 0 %s' % fs_img,
24 '%smkdir host 0:0 dir1' % fs_type,
25 '%sls host 0:0 /' % fs_type])
26 assert('dir1/' in ''.join(output))
27
28 output = u_boot_console.run_command(
29 '%sls host 0:0 dir1' % fs_type)
30 assert('./' in output)
31 assert('../' in output)
32
33 def test_mkdir2(self, u_boot_console, fs_obj_mkdir):
34 """
35 Test Case 2 - create a directory under a sub-directory
36 """
37 fs_type,fs_img = fs_obj_mkdir
38 with u_boot_console.log.section('Test Case 2 - mkdir (sub-sub directory)'):
39 output = u_boot_console.run_command_list([
40 'host bind 0 %s' % fs_img,
41 '%smkdir host 0:0 dir1/dir2' % fs_type,
42 '%sls host 0:0 dir1' % fs_type])
43 assert('dir2/' in ''.join(output))
44
45 output = u_boot_console.run_command(
46 '%sls host 0:0 dir1/dir2' % fs_type)
47 assert('./' in output)
48 assert('../' in output)
49
50 def test_mkdir3(self, u_boot_console, fs_obj_mkdir):
51 """
52 Test Case 3 - trying to create a directory with a non-existing
53 path should fail
54 """
55 fs_type,fs_img = fs_obj_mkdir
56 with u_boot_console.log.section('Test Case 3 - mkdir (non-existing path)'):
57 output = u_boot_console.run_command_list([
58 'host bind 0 %s' % fs_img,
59 '%smkdir host 0:0 none/dir3' % fs_type])
60 assert('Unable to create a directory' in ''.join(output))
61
62 def test_mkdir4(self, u_boot_console, fs_obj_mkdir):
63 """
64 Test Case 4 - trying to create "." should fail
65 """
66 fs_type,fs_img = fs_obj_mkdir
67 with u_boot_console.log.section('Test Case 4 - mkdir (".")'):
68 output = u_boot_console.run_command_list([
69 'host bind 0 %s' % fs_img,
70 '%smkdir host 0:0 .' % fs_type])
71 assert('Unable to create a directory' in ''.join(output))
72
73 def test_mkdir5(self, u_boot_console, fs_obj_mkdir):
74 """
75 Test Case 5 - trying to create ".." should fail
76 """
77 fs_type,fs_img = fs_obj_mkdir
78 with u_boot_console.log.section('Test Case 5 - mkdir ("..")'):
79 output = u_boot_console.run_command_list([
80 'host bind 0 %s' % fs_img,
81 '%smkdir host 0:0 ..' % fs_type])
82 assert('Unable to create a directory' in ''.join(output))
83
84 def test_mkdir6(self, u_boot_console, fs_obj_mkdir):
85 """
86 'Test Case 6 - create as many directories as amount of directory
87 entries goes beyond a cluster size)'
88 """
89 fs_type,fs_img = fs_obj_mkdir
90 with u_boot_console.log.section('Test Case 6 - mkdir (create many)'):
91 output = u_boot_console.run_command_list([
92 'host bind 0 %s' % fs_img,
93 '%smkdir host 0:0 dir6' % fs_type,
94 '%sls host 0:0 /' % fs_type])
95 assert('dir6/' in ''.join(output))
96
97 for i in range(0, 20):
98 output = u_boot_console.run_command(
99 '%smkdir host 0:0 dir6/0123456789abcdef%02x'
100 % (fs_type, i))
101 output = u_boot_console.run_command('%sls host 0:0 dir6' % fs_type)
102 assert('0123456789abcdef00/' in output)
103 assert('0123456789abcdef13/' in output)
104
105 output = u_boot_console.run_command(
106 '%sls host 0:0 dir6/0123456789abcdef13/.' % fs_type)
107 assert('./' in output)
108 assert('../' in output)
109
110 output = u_boot_console.run_command(
111 '%sls host 0:0 dir6/0123456789abcdef13/..' % fs_type)
112 assert('0123456789abcdef00/' in output)
113 assert('0123456789abcdef13/' in output)