Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | # SPDX-License-Identifier: GPL-2.0+ # Copyright (c) 2018, Linaro Limited # Author: Takahiro Akashi <takahiro.akashi@linaro.org> # # U-Boot File System:Basic Test """ This test verifies basic read/write operation on file system. Tests are implemented in C (test/fs/fs_basic.c) and called from here. Python handles filesystem image setup and environment variable configuration. """ import pytest from fstest_defs import SMALL_FILE, BIG_FILE from fstest_helpers import assert_fs_integrity def run_c_test(ubman, fs_type, fs_img, test_name, small=None, big=None, md5val=None): """Run a C unit test with proper setup. Args: ubman (ConsoleBase): U-Boot console manager fs_type (str): Filesystem type (ext4, fat, fs_generic, exfat) fs_img (str): Path to filesystem image test_name (str): Name of C test function (without _norun suffix) small (str): Filename of small test file (optional) big (str): Filename of big test file (optional) md5val (str): Expected MD5 value for verification (optional) Returns: bool: True if test passed, False otherwise """ # Build the command with arguments cmd = f'ut -f fs {test_name}_norun fs_type={fs_type} fs_image={fs_img}' if small: cmd += f' small={small}' if big: cmd += f' big={big}' if md5val: cmd += f' md5val={md5val}' # Run the C test ubman.run_command(cmd) # Check result result = ubman.run_command('echo $?') return result.strip() == '0' @pytest.mark.boardspec('sandbox') @pytest.mark.slow class TestFsBasic: """Test basic filesystem operations via C unit tests.""" def test_fs1(self, ubman, fs_obj_basic): """Test Case 1 - ls command, listing root and invalid directories""" fs_type, fs_img, _ = fs_obj_basic with ubman.log.section('Test Case 1 - ls'): assert run_c_test(ubman, fs_type, fs_img, 'fs_test_ls', small=SMALL_FILE, big=BIG_FILE) def test_fs2(self, ubman, fs_obj_basic): """Test Case 2 - size command for a small file""" fs_type, fs_img, _ = fs_obj_basic with ubman.log.section('Test Case 2 - size (small)'): assert run_c_test(ubman, fs_type, fs_img, 'fs_test_size_small', small=SMALL_FILE) def test_fs3(self, ubman, fs_obj_basic): """Test Case 3 - size command for a large file""" fs_type, fs_img, _ = fs_obj_basic with ubman.log.section('Test Case 3 - size (large)'): assert run_c_test(ubman, fs_type, fs_img, 'fs_test_size_big', big=BIG_FILE) def test_fs4(self, ubman, fs_obj_basic): """Test Case 4 - load a small file, 1MB""" fs_type, fs_img, md5val = fs_obj_basic with ubman.log.section('Test Case 4 - load (small)'): assert run_c_test(ubman, fs_type, fs_img, 'fs_test_load_small', small=SMALL_FILE, md5val=md5val[0]) def test_fs5(self, ubman, fs_obj_basic): """Test Case 5 - load, reading first 1MB of 3GB file""" fs_type, fs_img, md5val = fs_obj_basic with ubman.log.section('Test Case 5 - load (first 1MB)'): assert run_c_test(ubman, fs_type, fs_img, 'fs_test_load_big_first', big=BIG_FILE, md5val=md5val[1]) def test_fs6(self, ubman, fs_obj_basic): """Test Case 6 - load, reading last 1MB of 3GB file""" fs_type, fs_img, md5val = fs_obj_basic with ubman.log.section('Test Case 6 - load (last 1MB)'): assert run_c_test(ubman, fs_type, fs_img, 'fs_test_load_big_last', big=BIG_FILE, md5val=md5val[2]) def test_fs7(self, ubman, fs_obj_basic): """Test Case 7 - load, 1MB from the last 1MB in 2GB""" fs_type, fs_img, md5val = fs_obj_basic with ubman.log.section('Test Case 7 - load (last 1MB in 2GB)'): assert run_c_test(ubman, fs_type, fs_img, 'fs_test_load_big_2g_last', big=BIG_FILE, md5val=md5val[3]) def test_fs8(self, ubman, fs_obj_basic): """Test Case 8 - load, reading first 1MB in 2GB""" fs_type, fs_img, md5val = fs_obj_basic with ubman.log.section('Test Case 8 - load (first 1MB in 2GB)'): assert run_c_test(ubman, fs_type, fs_img, 'fs_test_load_big_2g_first', big=BIG_FILE, md5val=md5val[4]) def test_fs9(self, ubman, fs_obj_basic): """Test Case 9 - load, 1MB crossing 2GB boundary""" fs_type, fs_img, md5val = fs_obj_basic with ubman.log.section('Test Case 9 - load (crossing 2GB boundary)'): assert run_c_test(ubman, fs_type, fs_img, 'fs_test_load_big_2g_cross', big=BIG_FILE, md5val=md5val[5]) def test_fs10(self, ubman, fs_obj_basic): """Test Case 10 - load, reading beyond file end""" fs_type, fs_img, _ = fs_obj_basic with ubman.log.section('Test Case 10 - load (beyond file end)'): assert run_c_test(ubman, fs_type, fs_img, 'fs_test_load_beyond', big=BIG_FILE) def test_fs11(self, ubman, fs_obj_basic): """Test Case 11 - write""" fs_type, fs_img, md5val = fs_obj_basic with ubman.log.section('Test Case 11 - write'): assert run_c_test(ubman, fs_type, fs_img, 'fs_test_write', small=SMALL_FILE, md5val=md5val[0]) assert_fs_integrity(fs_type, fs_img) def test_fs12(self, ubman, fs_obj_basic): """Test Case 12 - write to "." directory""" fs_type, fs_img, _ = fs_obj_basic with ubman.log.section('Test Case 12 - write (".")'): assert run_c_test(ubman, fs_type, fs_img, 'fs_test_write_dot') assert_fs_integrity(fs_type, fs_img) def test_fs13(self, ubman, fs_obj_basic): """Test Case 13 - write to a file with '/./<filename>'""" fs_type, fs_img, md5val = fs_obj_basic with ubman.log.section('Test Case 13 - write ("./<file>")'): assert run_c_test(ubman, fs_type, fs_img, 'fs_test_write_dotpath', small=SMALL_FILE, md5val=md5val[0]) assert_fs_integrity(fs_type, fs_img) |