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