• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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[3] = { -1 };
37     INT32 ret, len;
38     CHAR filebuf[JFFS_STANDARD_NAME_LENGTH] = "1234567890";
39     CHAR readbuf[JFFS_STANDARD_NAME_LENGTH] = "";
40     CHAR pathname1[JFFS_STANDARD_NAME_LENGTH] = { JFFS_PATH_NAME0 };
41     off_t off;
42 
43     fd[0] = open(pathname1, O_NONBLOCK | O_CREAT | O_RDWR | O_EXCL, HIGHEST_AUTHORITY); // 0 means first fd
44     ICUNIT_GOTO_NOT_EQUAL(fd[0], JFFS_IS_ERROR, fd[0], EXIT1); // 0 means first fd
45 
46     fd[1] = open(pathname1, O_NONBLOCK | O_RDONLY, HIGHEST_AUTHORITY); // 1 means second fd
47     ICUNIT_GOTO_NOT_EQUAL(fd[1], JFFS_IS_ERROR, fd[1], EXIT2); // 1 means second fd
48 
49     ret = close(fd[1]); // 1 means second fd
50     ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT2);
51 
52     ret = close(fd[0]); // 0 means first fd
53     ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
54 
55     fd[0] = open(pathname1, O_NONBLOCK | O_CREAT | O_WRONLY, HIGHEST_AUTHORITY); // 0 means first fd
56     ICUNIT_GOTO_NOT_EQUAL(fd[0], JFFS_IS_ERROR, fd[0], EXIT1); // 0 means first fd
57 
58     fd[1] = open(pathname1, O_NONBLOCK | O_RDONLY, HIGHEST_AUTHORITY); // 1 means second fd
59     ICUNIT_GOTO_NOT_EQUAL(fd[1], JFFS_IS_ERROR, fd[1], EXIT2); // 1 means second fd
60 
61     fd[2] = open(pathname1, O_NONBLOCK | O_WRONLY, HIGHEST_AUTHORITY); // 2 means third fd
62     ICUNIT_GOTO_NOT_EQUAL(fd[2], JFFS_IS_ERROR, fd[2], EXIT3); // 2 means third fd
63 
64     ret = close(fd[2]); // 2 means third fd
65     ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT3);
66 
67     ret = close(fd[1]); // 1 means second fd
68     ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT2);
69 
70     ret = close(fd[0]); // 0 means first fd
71     ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
72 
73     fd[0] = open(pathname1, O_NONBLOCK | O_CREAT | O_RDONLY, HIGHEST_AUTHORITY); // 0 means first fd
74     ICUNIT_GOTO_NOT_EQUAL(fd[0], JFFS_IS_ERROR, fd[0], EXIT1); // 0 means first fd
75 
76     fd[1] = open(pathname1, O_NONBLOCK | O_RDONLY, HIGHEST_AUTHORITY); // 1 means second fd
77     ICUNIT_GOTO_NOT_EQUAL(fd[1], JFFS_IS_ERROR, fd[1], EXIT2); // 1 means second fd
78 
79     ret = close(fd[1]); // 1 means second fd
80     ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT2);
81 
82     ret = close(fd[0]); // 0 means first fd
83     ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
84 
85     fd[0] = open(pathname1, O_NONBLOCK | O_RDONLY, HIGHEST_AUTHORITY); // 0 means first fd
86     ICUNIT_GOTO_NOT_EQUAL(fd[0], JFFS_IS_ERROR, fd[0], EXIT1); // 0 means first fd
87 
88     fd[1] = open(pathname1, O_NONBLOCK | O_RDONLY, HIGHEST_AUTHORITY); // 1 means second fd
89     ICUNIT_GOTO_NOT_EQUAL(fd[1], JFFS_IS_ERROR, fd[1], EXIT2); // 1 means second fd
90 
91     fd[2] = open(pathname1, O_NONBLOCK | O_WRONLY, HIGHEST_AUTHORITY); // 2 means third fd
92     ICUNIT_GOTO_NOT_EQUAL(fd[2], JFFS_IS_ERROR, fd[2], EXIT3); // 2 means third fd
93 
94     len = write(fd[0], filebuf, strlen(filebuf)); // 0 means first fd
95     ICUNIT_GOTO_EQUAL(len, JFFS_IS_ERROR, len, EXIT3);
96     ICUNIT_GOTO_EQUAL(errno, EACCES, errno, EXIT3);
97 
98     len = write(fd[2], filebuf, strlen(filebuf)); // 2 means third fd
99     ICUNIT_GOTO_EQUAL(len, strlen(filebuf), len, EXIT3);
100 
101     off = lseek(fd[0], 0, SEEK_SET); // 0 means first fd
102     ICUNIT_GOTO_EQUAL(off, JFFS_NO_ERROR, off, EXIT3);
103 
104     len = read(fd[1], readbuf, JFFS_STANDARD_NAME_LENGTH); // 1 means second fd
105     ICUNIT_GOTO_EQUAL(len, strlen(filebuf), len, EXIT3);
106     ICUNIT_GOTO_STRING_EQUAL(readbuf, filebuf, readbuf, EXIT3);
107 
108     ret = close(fd[2]); // 2 means third fd
109     ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT3);
110 
111     ret = close(fd[1]); // 1 means second fd
112     ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT2);
113 
114     ret = close(fd[0]); // 0 means first fd
115     ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
116 
117     ret = unlink(pathname1);
118     ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
119 
120     return JFFS_NO_ERROR;
121 EXIT3:
122     close(fd[2]); // 2 means third fd
123 EXIT2:
124     close(fd[1]); // 1 means second fd
125 EXIT1:
126     close(fd[0]); // 0 means first fd
127 EXIT:
128     unlink(pathname1);
129     return JFFS_NO_ERROR;
130 }
131 
132 /* *
133 * -@test IT_FS_JFFS_104
134 * -@tspec The Function test for open
135 * -@ttitle Open the file several times in read-only mode
136 * -@tprecon The filesystem module is open
137 * -@tbrief
138 1. create one file and opened it in read-write mode;
139 2. open the file several times in read-only mode
140 3. write and read these fd
141 4. close and remove all the file
142 * -@texpect
143 1. Return successed
144 2. Return successed
145 3. Return successed
146 4. Sucessful operation
147 * -@tprior 1
148 * -@tauto TRUE
149 * -@tremark
150 */
151 
ItFsJffs104(VOID)152 VOID ItFsJffs104(VOID)
153 {
154     TEST_ADD_CASE("IT_FS_JFFS_104", Testcase, TEST_VFS, TEST_JFFS, TEST_LEVEL2, TEST_FUNCTION);
155 }
156 
157