1 /*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include "It_vfs_jffs.h"
33
testcase(VOID)34 static UINT32 testcase(VOID)
35 {
36 INT32 fd, fd1, fd2, ret;
37 CHAR pathname[30] = { JFFS_PATH_NAME0 };
38 DIR *dir = NULL;
39 struct dirent *ptr;
40 INT32 offset, offset1, offset2, offset3, offset4;
41
42 ret = mkdir(pathname, HIGHEST_AUTHORITY);
43 ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
44
45 strcat(pathname, "/test0");
46 ret = mkdir(pathname, HIGHEST_AUTHORITY);
47 ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1);
48
49 JffsStrcat2(pathname, "/file1", sizeof(pathname));
50 fd1 = open(pathname, O_NONBLOCK | O_CREAT | O_RDWR, HIGHEST_AUTHORITY);
51 ICUNIT_GOTO_NOT_EQUAL(fd, -1, fd, EXIT2);
52
53 JffsStrcat2(pathname, "/file0", sizeof(pathname));
54 fd = open(pathname, O_NONBLOCK | O_CREAT | O_RDWR, HIGHEST_AUTHORITY);
55 ICUNIT_GOTO_NOT_EQUAL(fd, -1, fd, EXIT3);
56
57 JffsStrcat2(pathname, "/test2", sizeof(pathname));
58 ret = mkdir(pathname, HIGHEST_AUTHORITY);
59 ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT4);
60
61 JffsStrcat2(pathname, "/file2", sizeof(pathname));
62 fd2 = open(pathname, O_NONBLOCK | O_CREAT | O_RDWR, HIGHEST_AUTHORITY);
63 ICUNIT_GOTO_NOT_EQUAL(fd, -1, fd, EXIT5);
64
65 JffsStrcat2(pathname, "/test1", sizeof(pathname));
66 ret = mkdir(pathname, HIGHEST_AUTHORITY);
67 ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT6);
68
69 dir = opendir(JFFS_PATH_NAME0);
70 ICUNIT_GOTO_NOT_EQUAL(dir, NULL, dir, EXIT7);
71
72 offset1 = 0;
73 ptr = readdir(dir);
74 ICUNIT_GOTO_STRING_EQUAL(ptr->d_name, "file0", ptr->d_name, EXIT7);
75
76 offset2 = ptr->d_off;
77 ptr = readdir(dir);
78 ICUNIT_GOTO_STRING_EQUAL(ptr->d_name, "file1", ptr->d_name, EXIT7);
79
80 offset3 = ptr->d_off;
81 ptr = readdir(dir);
82 ICUNIT_GOTO_STRING_EQUAL(ptr->d_name, "file2", ptr->d_name, EXIT7);
83
84 offset4 = ptr->d_off;
85 ptr = readdir(dir);
86 ICUNIT_GOTO_STRING_EQUAL(ptr->d_name, "test0", ptr->d_name, EXIT7);
87
88 seekdir(dir, offset2);
89 rewinddir(dir);
90 offset = telldir(dir);
91 ptr = readdir(dir);
92 ICUNIT_GOTO_NOT_EQUAL(ptr, NULL, ptr, EXIT7);
93 ICUNIT_GOTO_STRING_EQUAL(ptr->d_name, "file0", ptr->d_name, EXIT7);
94 ICUNIT_GOTO_EQUAL(offset, offset1, offset, EXIT7);
95 ICUNIT_GOTO_EQUAL(offset, ptr->d_off - 1, offset, EXIT7);
96
97 seekdir(dir, offset1);
98 rewinddir(dir);
99 offset = telldir(dir);
100 ptr = readdir(dir);
101 ICUNIT_GOTO_NOT_EQUAL(ptr, NULL, ptr, EXIT7);
102 ICUNIT_GOTO_STRING_EQUAL(ptr->d_name, "file0", ptr->d_name, EXIT7);
103 ICUNIT_GOTO_EQUAL(offset, offset1, offset, EXIT7);
104 ICUNIT_GOTO_EQUAL(offset, ptr->d_off - 1, offset, EXIT7);
105
106 seekdir(dir, offset4);
107 rewinddir(dir);
108 offset = telldir(dir);
109 ptr = readdir(dir);
110 ICUNIT_GOTO_NOT_EQUAL(ptr, NULL, ptr, EXIT7);
111 ICUNIT_GOTO_STRING_EQUAL(ptr->d_name, "file0", ptr->d_name, EXIT7);
112 ICUNIT_GOTO_EQUAL(offset, offset1, offset, EXIT7);
113 ICUNIT_GOTO_EQUAL(offset, ptr->d_off - 1, offset, EXIT7);
114
115 seekdir(dir, offset3);
116 rewinddir(dir);
117 offset = telldir(dir);
118 ptr = readdir(dir);
119 ICUNIT_GOTO_NOT_EQUAL(ptr, NULL, ptr, EXIT7);
120 ICUNIT_GOTO_STRING_EQUAL(ptr->d_name, "file0", ptr->d_name, EXIT7);
121 ICUNIT_GOTO_EQUAL(offset, offset1, offset, EXIT7);
122 ICUNIT_GOTO_EQUAL(offset, ptr->d_off - 1, offset, EXIT7);
123
124 EXIT7:
125 ret = closedir(dir);
126 ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT7);
127 EXIT6:
128 JffsStrcat2(pathname, "/test1", sizeof(pathname));
129 rmdir(pathname);
130 EXIT5:
131 JffsStrcat2(pathname, "/file2", sizeof(pathname));
132 close(fd2);
133 remove(pathname);
134 EXIT4:
135 JffsStrcat2(pathname, "/test2", sizeof(pathname));
136 rmdir(pathname);
137 EXIT3:
138 JffsStrcat2(pathname, "/file0", sizeof(pathname));
139 close(fd);
140 remove(pathname);
141 EXIT2:
142 JffsStrcat2(pathname, "/file1", sizeof(pathname));
143 close(fd1);
144 remove(pathname);
145 EXIT1:
146 JffsStrcat2(pathname, "/test0", sizeof(pathname));
147 rmdir(pathname);
148 EXIT:
149 rmdir(JFFS_PATH_NAME0);
150 return JFFS_NO_ERROR;
151 }
152
ItFsJffs005(VOID)153 VOID ItFsJffs005(VOID)
154 {
155 TEST_ADD_CASE("IT_FS_JFFS_005", testcase, TEST_VFS, TEST_JFFS, TEST_LEVEL0, TEST_FUNCTION);
156 }
157
158