1# 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 12from fstest_helpers import assert_fs_integrity 13 14@pytest.mark.boardspec('sandbox') 15@pytest.mark.slow 16class TestMkdir(object): 17 def test_mkdir1(self, u_boot_console, fs_obj_mkdir): 18 """ 19 Test Case 1 - create a directory under a root 20 """ 21 fs_type,fs_img = fs_obj_mkdir 22 with u_boot_console.log.section('Test Case 1 - mkdir'): 23 output = u_boot_console.run_command_list([ 24 '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 29 output = u_boot_console.run_command( 30 '%sls host 0:0 dir1' % fs_type) 31 assert('./' in output) 32 assert('../' in output) 33 assert_fs_integrity(fs_type, fs_img) 34 35 36 def test_mkdir2(self, u_boot_console, fs_obj_mkdir): 37 """ 38 Test Case 2 - create a directory under a sub-directory 39 """ 40 fs_type,fs_img = fs_obj_mkdir 41 with u_boot_console.log.section('Test Case 2 - mkdir (sub-sub directory)'): 42 output = u_boot_console.run_command_list([ 43 '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 48 output = u_boot_console.run_command( 49 '%sls host 0:0 dir1/dir2' % fs_type) 50 assert('./' in output) 51 assert('../' in output) 52 assert_fs_integrity(fs_type, fs_img) 53 54 def test_mkdir3(self, u_boot_console, fs_obj_mkdir): 55 """ 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 60 with u_boot_console.log.section('Test Case 3 - mkdir (non-existing path)'): 61 output = u_boot_console.run_command_list([ 62 '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)) 65 assert_fs_integrity(fs_type, fs_img) 66 67 def test_mkdir4(self, u_boot_console, fs_obj_mkdir): 68 """ 69 Test Case 4 - trying to create "." should fail 70 """ 71 fs_type,fs_img = fs_obj_mkdir 72 with u_boot_console.log.section('Test Case 4 - mkdir (".")'): 73 output = u_boot_console.run_command_list([ 74 'host bind 0 %s' % fs_img, 75 '%smkdir host 0:0 .' % fs_type]) 76 assert('Unable to create a directory' in ''.join(output)) 77 assert_fs_integrity(fs_type, fs_img) 78 79 def test_mkdir5(self, u_boot_console, fs_obj_mkdir): 80 """ 81 Test Case 5 - trying to create ".." should fail 82 """ 83 fs_type,fs_img = fs_obj_mkdir 84 with u_boot_console.log.section('Test Case 5 - mkdir ("..")'): 85 output = u_boot_console.run_command_list([ 86 'host bind 0 %s' % fs_img, 87 '%smkdir host 0:0 ..' % fs_type]) 88 assert('Unable to create a directory' in ''.join(output)) 89 assert_fs_integrity(fs_type, fs_img) 90 91 def test_mkdir6(self, u_boot_console, fs_obj_mkdir): 92 """ 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 97 with u_boot_console.log.section('Test Case 6 - mkdir (create many)'): 98 output = u_boot_console.run_command_list([ 99 '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): 105 output = u_boot_console.run_command( 106 '%smkdir host 0:0 dir6/0123456789abcdef%02x' 107 % (fs_type, i)) 108 output = u_boot_console.run_command('%sls host 0:0 dir6' % fs_type) 109 assert('0123456789abcdef00/' in output) 110 assert('0123456789abcdef13/' in output) 111 112 output = u_boot_console.run_command( 113 '%sls host 0:0 dir6/0123456789abcdef13/.' % fs_type) 114 assert('./' in output) 115 assert('../' in output) 116 117 output = u_boot_console.run_command( 118 '%sls host 0:0 dir6/0123456789abcdef13/..' % fs_type) 119 assert('0123456789abcdef00/' in output) 120 assert('0123456789abcdef13/' in output) 121 assert_fs_integrity(fs_type, fs_img) 122