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
33 #include "It_vfs_fat.h"
34
TestCase(VOID)35 static UINT32 TestCase(VOID)
36 {
37 INT32 ret;
38 INT32 i = 0;
39 INT32 j = 0;
40 CHAR pathname[FAT_STANDARD_NAME_LENGTH] = FAT_PATH_NAME;
41 CHAR filebuf[260] = "abcdeabcde0123456789abcedfghij9876550210abcdeabcde0123456789abcedfghij9876550210abcdeabcde0123"
42 "456789abcedfghij9876550210abcdeabcde0123456789abcedfghij9876550210abcdeabcde0123456789abcedfgh"
43 "ij9876550210abcdeabcde0123456789abcedfghij9876550210lalalalalalalala";
44 CHAR *bufWrite = NULL;
45 CHAR *bufWrite1 = NULL;
46 CHAR *bufWrite2 = NULL;
47 struct stat64 buf1 = { 0 };
48 struct stat64 buf2 = { 0 };
49
50 g_testCount = 0;
51
52 ret = mkdir(pathname, S_IRWXU | S_IRWXG | S_IRWXO);
53 ICUNIT_GOTO_EQUAL(ret, FAT_NO_ERROR, ret, EXIT);
54
55 bufWrite = (CHAR *)malloc(8 * BYTES_PER_MBYTES + 1); // 8 * BYTES_PER_MBYTES = 8MB
56 ICUNIT_GOTO_NOT_EQUAL(bufWrite, NULL, 0, EXIT1);
57 (void)memset_s(bufWrite, 8 * BYTES_PER_MBYTES + 1, 0, 8 * BYTES_PER_MBYTES + 1); // 8 * BYTES_PER_MBYTES = 8MB
58
59 bufWrite1 = (CHAR *)malloc(BYTES_PER_MBYTES + 1); // BYTES_PER_MBYTES = 1MB
60 ICUNIT_GOTO_NOT_EQUAL(bufWrite1, NULL, 0, EXIT2);
61 (void)memset_s(bufWrite, BYTES_PER_MBYTES, 0, BYTES_PER_MBYTES + 1); // BYTES_PER_MBYTES = 1MB
62
63 bufWrite2 = (CHAR *)malloc(16 * BYTES_PER_KBYTES + 1); // 16 * BYTES_PER_KBYTES = 16KB
64 ICUNIT_GOTO_NOT_EQUAL(bufWrite2, NULL, 0, EXIT3);
65 ret = memset_s(bufWrite2, 16 * BYTES_PER_KBYTES, 0, 16 * BYTES_PER_KBYTES + 1); // 16 kb
66 ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT3);
67
68 for (j = 0; j < 16; j++) { // loop 16 times
69 (void)strcat_s(bufWrite2, 16 * BYTES_PER_KBYTES, filebuf); // 16 * BYTES_PER_KBYTES = 16kb
70 (void)strcat_s(bufWrite2, 16 * BYTES_PER_KBYTES, filebuf); // 16 * BYTES_PER_KBYTES = 16kb
71 (void)strcat_s(bufWrite2, 16 * BYTES_PER_KBYTES, filebuf); // 16 * BYTES_PER_KBYTES = 16kb
72 (void)strcat_s(bufWrite2, 16 * BYTES_PER_KBYTES, filebuf); // 16 * BYTES_PER_KBYTES = 16kb
73 }
74
75 for (j = 0; j < 16; j++) { // loop 16 times
76 (void)strcat_s(bufWrite1, BYTES_PER_MBYTES, bufWrite2); // BYTES_PER_MBYTES = 1MB
77 (void)strcat_s(bufWrite1, BYTES_PER_MBYTES, bufWrite2); // BYTES_PER_MBYTES = 1MB
78 (void)strcat_s(bufWrite1, BYTES_PER_MBYTES, bufWrite2); // BYTES_PER_MBYTES = 1MB
79 (void)strcat_s(bufWrite1, BYTES_PER_MBYTES, bufWrite2); // BYTES_PER_MBYTES = 1MB
80 }
81
82 for (i = 0; i < 4; i++) { // loop 4 times
83 (void)strcat_s(bufWrite, 8 * BYTES_PER_MBYTES, bufWrite1); // 8 * BYTES_PER_MBYTES = 8MB
84 (void)strcat_s(bufWrite, 8 * BYTES_PER_MBYTES, bufWrite1); // 8 * BYTES_PER_MBYTES = 8MB
85 }
86
87 free(bufWrite1);
88 free(bufWrite2);
89
90 g_testCount++;
91
92 (void)memset_s(g_fatPathname1, FAT_STANDARD_NAME_LENGTH, 0, FAT_STANDARD_NAME_LENGTH);
93 (void)strcat_s(g_fatPathname1, FAT_STANDARD_NAME_LENGTH, pathname);
94 (void)strcat_s(g_fatPathname1, FAT_STANDARD_NAME_LENGTH, "/031.txt");
95
96 g_fatFd = open64(g_fatPathname1, O_NONBLOCK | O_CREAT | O_RDWR | O_EXCL, S_IRWXU | S_IRWXG | S_IRWXO);
97 ICUNIT_GOTO_NOT_EQUAL(g_fatFd, FAT_IS_ERROR, g_fatFd, EXIT2);
98
99 while (1) {
100 ret = write(g_fatFd, bufWrite, strlen(bufWrite));
101 if (ret <= 0) {
102 if (g_testCount < (4 * BYTES_PER_KBYTES / 8)) { // 4 * BYTES_PER_KBYTES MB/GB, 8MB per write
103 printf("The biggest file size is smaller than the 4GB\n");
104 goto EXIT2;
105 }
106 printf("The cycle count = :%d,the file size = :%dMB,= :%0.3lfGB\n", g_testCount,
107 g_testCount * 8, // 8MB per write
108 (g_testCount * 8) * 1.0 / BYTES_PER_KBYTES); // BYTES_PER_KBYTES MB/GB, 8MB per write
109 break;
110 }
111 if (g_testCount >= 256 + 1) { // write more than 256 times for 4GB // write more than 256 times for 4GB
112 printf("The cycle count = :%d,the file size = :%dMB,= :%0.3lfGB\n", g_testCount,
113 g_testCount * 8, // 8MB per write
114 (g_testCount * 8) * 1.0 / BYTES_PER_KBYTES); // BYTES_PER_KBYTES MB/GB, 8MB per write
115 break;
116 }
117 g_testCount++;
118 }
119
120 ret = stat64(g_fatPathname1, &buf1);
121 ICUNIT_GOTO_EQUAL(ret, FAT_NO_ERROR, ret, EXIT2);
122
123 ret = fstat64(g_fatFd, &buf2);
124 ICUNIT_GOTO_EQUAL(ret, FAT_NO_ERROR, ret, EXIT2);
125
126 ICUNIT_GOTO_EQUAL(buf1.st_size, buf2.st_size, buf1.st_size, EXIT2);
127 ICUNIT_GOTO_EQUAL(buf1.st_blksize, buf2.st_blksize, buf1.st_blksize, EXIT2);
128 ICUNIT_GOTO_EQUAL(buf1.st_ino, buf2.st_ino, buf1.st_ino, EXIT2);
129 ICUNIT_GOTO_EQUAL(buf1.st_mode, buf2.st_mode, buf1.st_mode, EXIT2);
130 ICUNIT_GOTO_EQUAL(buf1.st_mtim.tv_nsec, buf2.st_mtim.tv_nsec, buf1.st_mtim.tv_nsec, EXIT2);
131
132 ICUNIT_GOTO_EQUAL(buf1.st_size, (off64_t)g_testCount * 8 * BYTES_PER_MBYTES, // 8 mb per write
133 buf1.st_size, EXIT2);
134
135 free(bufWrite);
136
137 ret = close(g_fatFd);
138 ICUNIT_GOTO_EQUAL(ret, FAT_NO_ERROR, ret, EXIT1);
139
140 ret = remove(g_fatPathname1);
141 ICUNIT_GOTO_EQUAL(ret, FAT_NO_ERROR, ret, EXIT0);
142
143 ret = remove(pathname);
144 ICUNIT_GOTO_EQUAL(ret, FAT_NO_ERROR, ret, EXIT);
145
146 return FAT_NO_ERROR;
147 EXIT3:
148 free(bufWrite1);
149 EXIT2:
150 free(bufWrite);
151 EXIT1:
152 close(g_fatFd);
153 EXIT0:
154 remove(g_fatPathname1);
155 EXIT:
156 remove(pathname);
157 return FAT_NO_ERROR;
158 }
159
160 /* *
161 * @defgroup los_fsoperationbigfile 操作超过2G大小的文件
162 */
163
164 /* *
165 * @ingroup los_fsoperationbigfile
166 * @par type: void
167 * API test
168 * @brief function 操作超过2G大小的文件
169 * @par description:write the file size to 2GB and function it
170 * @par precon: task moudle open
171 * @par step: see decription
172 * create 2GB file \n
173 * function this file
174 * @par expect: nothing
175 * create file successful \n
176 * operator it successful,return successed
177 * @par prior: void
178 */
179
ItFsFat870(VOID)180 VOID ItFsFat870(VOID)
181 {
182 TEST_ADD_CASE("IT_FS_FAT_870", TestCase, TEST_VFS, TEST_VFAT, TEST_LEVEL3, TEST_FUNCTION);
183 }
184