• 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, len, ret;
37     CHAR filebuf[JFFS_STANDARD_NAME_LENGTH] = "1234567890abcde&";
38     CHAR readbuf[JFFS_STANDARD_NAME_LENGTH] = {0};
39     CHAR pathname1[JFFS_STANDARD_NAME_LENGTH] = { JFFS_PATH_NAME0 };
40     long off;
41 
42     fd = open(pathname1, O_NONBLOCK | O_CREAT | O_RDWR, HIGHEST_AUTHORITY);
43     ICUNIT_GOTO_NOT_EQUAL(fd, JFFS_IS_ERROR, fd, EXIT1);
44 
45     len = write(fd, filebuf, strlen(filebuf));
46     ICUNIT_GOTO_EQUAL(len, 16, len, EXIT1);
47 
48     len = write(fd, filebuf, strlen(filebuf));
49     ICUNIT_GOTO_EQUAL(len, 16, len, EXIT1);
50 
51     len = write(fd, filebuf, strlen(filebuf));
52     ICUNIT_GOTO_EQUAL(len, 16, len, EXIT1);
53 
54     len = write(fd, "END", 3); // write length: 3
55     ICUNIT_GOTO_EQUAL(len, 3, len, EXIT1);
56 
57     off = lseek64(fd, JFFS_SHORT_ARRAY_LENGTH, SEEK_SET);
58     ICUNIT_GOTO_EQUAL(off, JFFS_SHORT_ARRAY_LENGTH, off, EXIT1);
59 
60     len = read(fd, readbuf, 6); // read length: 6
61     ICUNIT_GOTO_EQUAL(len, 6, len, EXIT1);
62     ICUNIT_GOTO_STRING_EQUAL(readbuf, "abcde&", readbuf, EXIT1);
63 
64     off = lseek64(fd, 2, SEEK_CUR); // seek offset: 2
65     ICUNIT_GOTO_EQUAL(off, 18, off, EXIT1); // file position: 18
66 
67     memset(readbuf, 0, sizeof(readbuf));
68 
69     len = read(fd, readbuf, 5); // read length: 5
70     ICUNIT_GOTO_EQUAL(len, 5, len, EXIT1);
71     ICUNIT_GOTO_STRING_EQUAL(readbuf, "34567", readbuf, EXIT1);
72 
73     off = lseek64(fd, 0, SEEK_CUR);
74     ICUNIT_GOTO_EQUAL(off, 23, off, EXIT1); // file position: 23
75 
76     len = read(fd, readbuf, 5); // read length: 5
77     ICUNIT_GOTO_EQUAL(len, 5, len, EXIT1);
78     ICUNIT_GOTO_STRING_EQUAL(readbuf, "890ab", readbuf, EXIT1);
79 
80     off = lseek64(fd, -2, SEEK_CUR); // seek offset: -2
81     ICUNIT_GOTO_EQUAL(off, 26, off, EXIT1); // file position: 26
82 
83     len = read(fd, readbuf, 6); // read length: 6
84     ICUNIT_GOTO_EQUAL(len, 6, len, EXIT1);
85     ICUNIT_GOTO_STRING_EQUAL(readbuf, "abcde&", readbuf, EXIT1);
86 
87     off = lseek64(fd, -2, SEEK_END); // seek offset: -2
88     ICUNIT_GOTO_EQUAL(off, 49, off, EXIT1); // file size: 49
89 
90     memset(readbuf, 0, sizeof(readbuf));
91     len = read(fd, readbuf, 5); // read length: 5
92     ICUNIT_GOTO_EQUAL(len, 2, len, EXIT1); // file size: 2
93     ICUNIT_GOTO_STRING_EQUAL(readbuf, "ND", readbuf, EXIT1);
94 
95     off = lseek64(fd, 0, SEEK_END);
96     ICUNIT_GOTO_EQUAL(off, 51, off, EXIT1); // file size: 51
97 
98     len = read(fd, readbuf, 6); // read length: 6
99     ICUNIT_GOTO_EQUAL(len, JFFS_NO_ERROR, len, EXIT1);
100 
101     off = lseek64(fd, 2, SEEK_END); // seek offset: 2
102     ICUNIT_GOTO_EQUAL(off, 53, off, EXIT1); // file size: 53
103     len = read(fd, readbuf, 6); // read length: 6
104     ICUNIT_GOTO_EQUAL(len, JFFS_NO_ERROR, len, EXIT1);
105 
106     len = write(fd, "mmm", 3); // write length: 3
107     ICUNIT_GOTO_EQUAL(len, 3, len, EXIT1);
108 
109     off = lseek64(fd, -3, SEEK_END); // seek offset: -3
110     ICUNIT_GOTO_EQUAL(off, 53, off, EXIT1); // file size:49
111 
112     len = read(fd, readbuf, 5); // read length: 5
113     ICUNIT_GOTO_EQUAL(len, 3, len, EXIT1); // file length: 3
114     ICUNIT_GOTO_STRING_EQUAL(readbuf, "mmm", readbuf, EXIT1);
115 
116     ret = close(fd);
117     ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
118 
119     ret = unlink(pathname1);
120     ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
121 
122     return JFFS_NO_ERROR;
123 EXIT1:
124     close(fd);
125 EXIT:
126     remove(pathname1);
127     return JFFS_NO_ERROR;
128 }
129 
ItFsJffs535(VOID)130 VOID ItFsJffs535(VOID)
131 {
132     TEST_ADD_CASE("IT_FS_JFFS_535", testcase, TEST_VFS, TEST_JFFS, TEST_LEVEL0, TEST_FUNCTION);
133 }
134