1 /*
2 * Copyright (c) 2020 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include "test_fs.h"
8 /* amount of file system */
9 #define NUM_FS 2
10 #define TEST_FS_NAND1 "/NAND:"
11 #define TEST_FS_NAND2 "/MMCBLOCK:"
12
13 static struct test_fs_data test_data;
14
15 static struct fs_mount_t test_fs_mnt_1 = {
16 .type = TEST_FS_1,
17 .mnt_point = TEST_FS_NAND1,
18 .fs_data = &test_data,
19 };
20
21 static struct fs_mount_t test_fs_mnt_2 = {
22 .type = TEST_FS_2,
23 .mnt_point = TEST_FS_NAND2,
24 .fs_data = &test_data,
25 };
26
test_fs_init(void)27 static int test_fs_init(void)
28 {
29 if (fs_register(TEST_FS_1, &temp_fs)) {
30 return -EINVAL;
31 }
32
33 /* Attempt to re-register a file system */
34 if (fs_register(TEST_FS_1, &temp_fs) != -EALREADY) {
35 return -EINVAL;
36 }
37
38 if (fs_mount(&test_fs_mnt_1)) {
39 return -EINVAL;
40 }
41
42 if (fs_register(TEST_FS_2, &temp_fs)) {
43 return -EINVAL;
44 }
45
46 if (fs_mount(&test_fs_mnt_2)) {
47 return -EINVAL;
48 }
49
50 return 0;
51 }
52
test_fs_readmount(void)53 static int test_fs_readmount(void)
54 {
55 int ret;
56 int mnt_nbr = 0;
57 const char *mnt_name;
58
59 do {
60 ret = fs_readmount(&mnt_nbr, &mnt_name);
61 if (ret < 0) {
62 break;
63 }
64
65
66 } while (true);
67
68 if (mnt_nbr == NUM_FS) {
69 return 0;
70 }
71
72 return TC_FAIL;
73 }
74
test_fs_deinit(void)75 static int test_fs_deinit(void)
76 {
77 /* NULL parameter */
78 if (fs_unregister(TEST_FS_1, NULL) == 0) {
79 return -EINVAL;
80 }
81
82 if (fs_unregister(TEST_FS_1, &temp_fs)) {
83 return -EINVAL;
84 }
85
86 if (fs_unmount(&test_fs_mnt_1)) {
87 return -EINVAL;
88 }
89
90 if (fs_unregister(TEST_FS_2, &temp_fs)) {
91 return -EINVAL;
92 }
93
94 if (fs_unmount(&test_fs_mnt_2)) {
95 return -EINVAL;
96 }
97 return 0;
98 }
99
test_fs_external(void)100 static int test_fs_external(void)
101 {
102 /* There is no way to statically determine whether a file
103 * system is unsupported, but */
104 if (fs_register(FS_TYPE_EXTERNAL_BASE, &temp_fs) != -ENOSPC) {
105 return TC_FAIL;
106 }
107
108 if (fs_unregister(FS_TYPE_EXTERNAL_BASE, &temp_fs) != -EINVAL) {
109 return TC_FAIL;
110 }
111
112 return 0;
113 }
114
115 /**
116 * @brief Multi file systems register and unregister
117 *
118 * @details
119 * Register and unregister two file systems to test the system support
120 * multiple file system simultaneously
121 *
122 *@addtogroup filesystem_api
123 *@{
124 */
125
ZTEST(fs_api_register_mount,test_fs_register)126 ZTEST(fs_api_register_mount, test_fs_register)
127 {
128 zassert_true(test_fs_init() == 0, "Failed to register filesystems");
129 zassert_true(test_fs_readmount() == 0, "Failed to readmount");
130 zassert_true(test_fs_external() == 0, "Supported other file system");
131 zassert_true(test_fs_deinit() == 0, "Failed to unregister filesystems");
132 }
133
134 /**
135 * @}
136 */
137