1 /* 2 * Copyright (c) 2018 Intel Corporation. 3 * Copyright (c) 2020 Nordic Semiconductor ASA 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 8 9 #include "test_fat.h" 10 11 /* mounting info */ 12 static struct fs_mount_t fatfs_mnt = { 13 .type = FS_FATFS, 14 .mnt_point = FATFS_MNTP, 15 .fs_data = &fat_fs, 16 }; 17 test_mount_no_format(void)18static int test_mount_no_format(void) 19 { 20 int ret = 0; 21 22 fatfs_mnt.flags = FS_MOUNT_FLAG_NO_FORMAT; 23 ret = fs_mount(&fatfs_mnt); 24 25 if (ret >= 0) { 26 TC_PRINT("Expected failure\n"); 27 return TC_FAIL; 28 } 29 fatfs_mnt.flags = 0; 30 31 return TC_PASS; 32 } 33 test_mount_rd_only_no_sys(void)34static int test_mount_rd_only_no_sys(void) 35 { 36 int ret = 0; 37 38 fatfs_mnt.flags = FS_MOUNT_FLAG_READ_ONLY; 39 ret = fs_mount(&fatfs_mnt); 40 41 if (ret >= 0) { 42 TC_PRINT("Expected failure\n"); 43 return TC_FAIL; 44 } 45 fatfs_mnt.flags = 0; 46 47 return TC_PASS; 48 } 49 test_mount_use_disk_access(void)50static int test_mount_use_disk_access(void) 51 { 52 int res; 53 54 fatfs_mnt.flags = FS_MOUNT_FLAG_USE_DISK_ACCESS; 55 res = fs_mount(&fatfs_mnt); 56 if (res < 0) { 57 TC_PRINT("Error mounting fs [%d]\n", res); 58 return TC_FAIL; 59 } 60 return ((fatfs_mnt.flags & FS_MOUNT_FLAG_USE_DISK_ACCESS) ? TC_PASS : TC_FAIL); 61 } 62 test_mount(void)63static int test_mount(void) 64 { 65 int res; 66 67 fatfs_mnt.flags = 0; 68 res = fs_mount(&fatfs_mnt); 69 if (res < 0) { 70 TC_PRINT("Error mounting fs [%d]\n", res); 71 return TC_FAIL; 72 } 73 return ((fatfs_mnt.flags & FS_MOUNT_FLAG_USE_DISK_ACCESS) ? TC_PASS : TC_FAIL); 74 } 75 test_unmount(void)76static int test_unmount(void) 77 { 78 return (fs_unmount(&fatfs_mnt) >= 0 ? TC_PASS : TC_FAIL); 79 } 80 test_fat_unmount(void)81void test_fat_unmount(void) 82 { 83 zassert_true(test_unmount() == TC_PASS); 84 } 85 test_fat_mount(void)86void test_fat_mount(void) 87 { 88 zassert_false(test_unmount() == TC_PASS); 89 zassert_true(test_mount_no_format() == TC_PASS); 90 zassert_true(test_mount_rd_only_no_sys() == TC_PASS); 91 zassert_true(test_mount_use_disk_access() == TC_PASS); 92 zassert_true(test_unmount() == TC_PASS); 93 zassert_true(test_mount() == TC_PASS); 94 zassert_false(test_mount() == TC_PASS); 95 } 96