1 | /* $Id: FsPerf.cpp 77908 2019-03-27 10:44:32Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * FsPerf - File System (Shared Folders) Performance Benchmark.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*********************************************************************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *********************************************************************************************************************************/
|
---|
31 | #ifdef RT_OS_OS2
|
---|
32 | # define INCL_BASE
|
---|
33 | # include <os2.h>
|
---|
34 | # undef RT_MAX
|
---|
35 | #endif
|
---|
36 | #include <iprt/alloca.h>
|
---|
37 | #include <iprt/asm.h>
|
---|
38 | #include <iprt/assert.h>
|
---|
39 | #include <iprt/err.h>
|
---|
40 | #include <iprt/dir.h>
|
---|
41 | #include <iprt/file.h>
|
---|
42 | #include <iprt/getopt.h>
|
---|
43 | #include <iprt/initterm.h>
|
---|
44 | #include <iprt/list.h>
|
---|
45 | #include <iprt/mem.h>
|
---|
46 | #include <iprt/message.h>
|
---|
47 | #include <iprt/param.h>
|
---|
48 | #include <iprt/path.h>
|
---|
49 | #include <iprt/process.h>
|
---|
50 | #include <iprt/rand.h>
|
---|
51 | #include <iprt/string.h>
|
---|
52 | #include <iprt/stream.h>
|
---|
53 | #include <iprt/system.h>
|
---|
54 | #include <iprt/test.h>
|
---|
55 | #include <iprt/time.h>
|
---|
56 | #include <iprt/thread.h>
|
---|
57 | #include <iprt/zero.h>
|
---|
58 |
|
---|
59 | #ifdef RT_OS_WINDOWS
|
---|
60 | # include <iprt/nt/nt-and-windows.h>
|
---|
61 | #else
|
---|
62 | # include <errno.h>
|
---|
63 | # include <unistd.h>
|
---|
64 | # include <sys/types.h>
|
---|
65 | # include <sys/fcntl.h>
|
---|
66 | # ifndef RT_OS_OS2
|
---|
67 | # include <sys/mman.h>
|
---|
68 | # include <sys/uio.h>
|
---|
69 | # endif
|
---|
70 | # ifdef RT_OS_LINUX
|
---|
71 | # include <sys/sendfile.h>
|
---|
72 | # endif
|
---|
73 | #endif
|
---|
74 |
|
---|
75 |
|
---|
76 | /*********************************************************************************************************************************
|
---|
77 | * Defined Constants And Macros *
|
---|
78 | *********************************************************************************************************************************/
|
---|
79 | /**
|
---|
80 | * Macro for profiling @a a_fnCall (typically forced inline) for about @a a_cNsTarget ns.
|
---|
81 | *
|
---|
82 | * Always does an even number of iterations.
|
---|
83 | */
|
---|
84 | #define PROFILE_FN(a_fnCall, a_cNsTarget, a_szDesc) \
|
---|
85 | do { \
|
---|
86 | /* Estimate how many iterations we need to fill up the given timeslot: */ \
|
---|
87 | fsPerfYield(); \
|
---|
88 | uint64_t nsStart = RTTimeNanoTS(); \
|
---|
89 | uint64_t nsPrf; \
|
---|
90 | do \
|
---|
91 | nsPrf = RTTimeNanoTS(); \
|
---|
92 | while (nsPrf == nsStart); \
|
---|
93 | nsStart = nsPrf; \
|
---|
94 | \
|
---|
95 | uint64_t iIteration = 0; \
|
---|
96 | do \
|
---|
97 | { \
|
---|
98 | RTTESTI_CHECK_RC(a_fnCall, VINF_SUCCESS); \
|
---|
99 | iIteration++; \
|
---|
100 | nsPrf = RTTimeNanoTS() - nsStart; \
|
---|
101 | } while (nsPrf < RT_NS_10MS || (iIteration & 1)); \
|
---|
102 | nsPrf /= iIteration; \
|
---|
103 | if (nsPrf > g_nsPerNanoTSCall + 32) \
|
---|
104 | nsPrf -= g_nsPerNanoTSCall; \
|
---|
105 | \
|
---|
106 | uint64_t cIterations = (a_cNsTarget) / nsPrf; \
|
---|
107 | if (cIterations <= 1) \
|
---|
108 | cIterations = 2; \
|
---|
109 | else if (cIterations & 1) \
|
---|
110 | cIterations++; \
|
---|
111 | \
|
---|
112 | /* Do the actual profiling: */ \
|
---|
113 | fsPerfYield(); \
|
---|
114 | iIteration = 0; \
|
---|
115 | nsStart = RTTimeNanoTS(); \
|
---|
116 | for (; iIteration < cIterations; iIteration++) \
|
---|
117 | RTTESTI_CHECK_RC(a_fnCall, VINF_SUCCESS); \
|
---|
118 | nsPrf = RTTimeNanoTS() - nsStart; \
|
---|
119 | RTTestIValue(a_szDesc, nsPrf / cIterations, RTTESTUNIT_NS_PER_OCCURRENCE); \
|
---|
120 | if (g_fShowDuration) \
|
---|
121 | RTTestIValueF(nsPrf, RTTESTUNIT_NS, "%s duration", a_szDesc); \
|
---|
122 | if (g_fShowIterations) \
|
---|
123 | RTTestIValueF(iIteration, RTTESTUNIT_OCCURRENCES, "%s iterations", a_szDesc); \
|
---|
124 | } while (0)
|
---|
125 |
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Macro for profiling an operation on each file in the manytree directory tree.
|
---|
129 | *
|
---|
130 | * Always does an even number of tree iterations.
|
---|
131 | */
|
---|
132 | #define PROFILE_MANYTREE_FN(a_szPath, a_fnCall, a_cEstimationIterations, a_cNsTarget, a_szDesc) \
|
---|
133 | do { \
|
---|
134 | if (!g_fManyFiles) \
|
---|
135 | break; \
|
---|
136 | \
|
---|
137 | /* Estimate how many iterations we need to fill up the given timeslot: */ \
|
---|
138 | fsPerfYield(); \
|
---|
139 | uint64_t nsStart = RTTimeNanoTS(); \
|
---|
140 | uint64_t ns; \
|
---|
141 | do \
|
---|
142 | ns = RTTimeNanoTS(); \
|
---|
143 | while (ns == nsStart); \
|
---|
144 | nsStart = ns; \
|
---|
145 | \
|
---|
146 | PFSPERFNAMEENTRY pCur; \
|
---|
147 | uint64_t iIteration = 0; \
|
---|
148 | do \
|
---|
149 | { \
|
---|
150 | RTListForEach(&g_ManyTreeHead, pCur, FSPERFNAMEENTRY, Entry) \
|
---|
151 | { \
|
---|
152 | memcpy(a_szPath, pCur->szName, pCur->cchName); \
|
---|
153 | for (uint32_t i = 0; i < g_cManyTreeFilesPerDir; i++) \
|
---|
154 | { \
|
---|
155 | RTStrFormatU32(&a_szPath[pCur->cchName], sizeof(a_szPath) - pCur->cchName, i, 10, 5, 5, RTSTR_F_ZEROPAD); \
|
---|
156 | RTTESTI_CHECK_RC(a_fnCall, VINF_SUCCESS); \
|
---|
157 | } \
|
---|
158 | } \
|
---|
159 | iIteration++; \
|
---|
160 | ns = RTTimeNanoTS() - nsStart; \
|
---|
161 | } while (ns < RT_NS_10MS || (iIteration & 1)); \
|
---|
162 | ns /= iIteration; \
|
---|
163 | if (ns > g_nsPerNanoTSCall + 32) \
|
---|
164 | ns -= g_nsPerNanoTSCall; \
|
---|
165 | \
|
---|
166 | uint32_t cIterations = (a_cNsTarget) / ns; \
|
---|
167 | if (cIterations <= 1) \
|
---|
168 | cIterations = 2; \
|
---|
169 | else if (cIterations & 1) \
|
---|
170 | cIterations++; \
|
---|
171 | \
|
---|
172 | /* Do the actual profiling: */ \
|
---|
173 | fsPerfYield(); \
|
---|
174 | uint32_t cCalls = 0; \
|
---|
175 | nsStart = RTTimeNanoTS(); \
|
---|
176 | for (iIteration = 0; iIteration < cIterations; iIteration++) \
|
---|
177 | { \
|
---|
178 | RTListForEach(&g_ManyTreeHead, pCur, FSPERFNAMEENTRY, Entry) \
|
---|
179 | { \
|
---|
180 | memcpy(a_szPath, pCur->szName, pCur->cchName); \
|
---|
181 | for (uint32_t i = 0; i < g_cManyTreeFilesPerDir; i++) \
|
---|
182 | { \
|
---|
183 | RTStrFormatU32(&a_szPath[pCur->cchName], sizeof(a_szPath) - pCur->cchName, i, 10, 5, 5, RTSTR_F_ZEROPAD); \
|
---|
184 | RTTESTI_CHECK_RC(a_fnCall, VINF_SUCCESS); \
|
---|
185 | cCalls++; \
|
---|
186 | } \
|
---|
187 | } \
|
---|
188 | } \
|
---|
189 | ns = RTTimeNanoTS() - nsStart; \
|
---|
190 | RTTestIValueF(ns / cCalls, RTTESTUNIT_NS_PER_OCCURRENCE, a_szDesc); \
|
---|
191 | if (g_fShowDuration) \
|
---|
192 | RTTestIValueF(ns, RTTESTUNIT_NS, "%s duration", a_szDesc); \
|
---|
193 | if (g_fShowIterations) \
|
---|
194 | RTTestIValueF(iIteration, RTTESTUNIT_OCCURRENCES, "%s iterations", a_szDesc); \
|
---|
195 | } while (0)
|
---|
196 |
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * Execute a_fnCall for each file in the manytree.
|
---|
200 | */
|
---|
201 | #define DO_MANYTREE_FN(a_szPath, a_fnCall) \
|
---|
202 | do { \
|
---|
203 | PFSPERFNAMEENTRY pCur; \
|
---|
204 | RTListForEach(&g_ManyTreeHead, pCur, FSPERFNAMEENTRY, Entry) \
|
---|
205 | { \
|
---|
206 | memcpy(a_szPath, pCur->szName, pCur->cchName); \
|
---|
207 | for (uint32_t i = 0; i < g_cManyTreeFilesPerDir; i++) \
|
---|
208 | { \
|
---|
209 | RTStrFormatU32(&a_szPath[pCur->cchName], sizeof(a_szPath) - pCur->cchName, i, 10, 5, 5, RTSTR_F_ZEROPAD); \
|
---|
210 | a_fnCall; \
|
---|
211 | } \
|
---|
212 | } \
|
---|
213 | } while (0)
|
---|
214 |
|
---|
215 |
|
---|
216 | /** @def FSPERF_VERR_PATH_NOT_FOUND
|
---|
217 | * Hides the fact that we only get VERR_PATH_NOT_FOUND on non-unix systems. */
|
---|
218 | #if defined(RT_OS_WINDOWS) //|| defined(RT_OS_OS2) - using posix APIs IIRC, so lost in translation.
|
---|
219 | # define FSPERF_VERR_PATH_NOT_FOUND VERR_PATH_NOT_FOUND
|
---|
220 | #else
|
---|
221 | # define FSPERF_VERR_PATH_NOT_FOUND VERR_FILE_NOT_FOUND
|
---|
222 | #endif
|
---|
223 |
|
---|
224 |
|
---|
225 | /*********************************************************************************************************************************
|
---|
226 | * Structures and Typedefs *
|
---|
227 | *********************************************************************************************************************************/
|
---|
228 | typedef struct FSPERFNAMEENTRY
|
---|
229 | {
|
---|
230 | RTLISTNODE Entry;
|
---|
231 | uint16_t cchName;
|
---|
232 | char szName[RT_FLEXIBLE_ARRAY];
|
---|
233 | } FSPERFNAMEENTRY;
|
---|
234 | typedef FSPERFNAMEENTRY *PFSPERFNAMEENTRY;
|
---|
235 |
|
---|
236 |
|
---|
237 | enum
|
---|
238 | {
|
---|
239 | kCmdOpt_First = 128,
|
---|
240 |
|
---|
241 | kCmdOpt_ManyFiles = kCmdOpt_First,
|
---|
242 | kCmdOpt_NoManyFiles,
|
---|
243 | kCmdOpt_Open,
|
---|
244 | kCmdOpt_NoOpen,
|
---|
245 | kCmdOpt_FStat,
|
---|
246 | kCmdOpt_NoFStat,
|
---|
247 | kCmdOpt_FChMod,
|
---|
248 | kCmdOpt_NoFChMod,
|
---|
249 | kCmdOpt_FUtimes,
|
---|
250 | kCmdOpt_NoFUtimes,
|
---|
251 | kCmdOpt_Stat,
|
---|
252 | kCmdOpt_NoStat,
|
---|
253 | kCmdOpt_ChMod,
|
---|
254 | kCmdOpt_NoChMod,
|
---|
255 | kCmdOpt_Utimes,
|
---|
256 | kCmdOpt_NoUtimes,
|
---|
257 | kCmdOpt_Rename,
|
---|
258 | kCmdOpt_NoRename,
|
---|
259 | kCmdOpt_DirOpen,
|
---|
260 | kCmdOpt_NoDirOpen,
|
---|
261 | kCmdOpt_DirEnum,
|
---|
262 | kCmdOpt_NoDirEnum,
|
---|
263 | kCmdOpt_MkRmDir,
|
---|
264 | kCmdOpt_NoMkRmDir,
|
---|
265 | kCmdOpt_StatVfs,
|
---|
266 | kCmdOpt_NoStatVfs,
|
---|
267 | kCmdOpt_Rm,
|
---|
268 | kCmdOpt_NoRm,
|
---|
269 | kCmdOpt_ChSize,
|
---|
270 | kCmdOpt_NoChSize,
|
---|
271 | kCmdOpt_ReadPerf,
|
---|
272 | kCmdOpt_NoReadPerf,
|
---|
273 | kCmdOpt_ReadTests,
|
---|
274 | kCmdOpt_NoReadTests,
|
---|
275 | kCmdOpt_WritePerf,
|
---|
276 | kCmdOpt_NoWritePerf,
|
---|
277 | kCmdOpt_WriteTests,
|
---|
278 | kCmdOpt_NoWriteTests,
|
---|
279 | kCmdOpt_Seek,
|
---|
280 | kCmdOpt_NoSeek,
|
---|
281 | kCmdOpt_FSync,
|
---|
282 | kCmdOpt_NoFSync,
|
---|
283 | kCmdOpt_MMap,
|
---|
284 | kCmdOpt_NoMMap,
|
---|
285 | kCmdOpt_IgnoreNoCache,
|
---|
286 | kCmdOpt_NoIgnoreNoCache,
|
---|
287 | kCmdOpt_IoFileSize,
|
---|
288 | kCmdOpt_SetBlockSize,
|
---|
289 | kCmdOpt_AddBlockSize,
|
---|
290 | kCmdOpt_Copy,
|
---|
291 | kCmdOpt_NoCopy,
|
---|
292 |
|
---|
293 | kCmdOpt_ShowDuration,
|
---|
294 | kCmdOpt_NoShowDuration,
|
---|
295 | kCmdOpt_ShowIterations,
|
---|
296 | kCmdOpt_NoShowIterations,
|
---|
297 |
|
---|
298 | kCmdOpt_ManyTreeFilesPerDir,
|
---|
299 | kCmdOpt_ManyTreeSubdirsPerDir,
|
---|
300 | kCmdOpt_ManyTreeDepth,
|
---|
301 |
|
---|
302 | kCmdOpt_End
|
---|
303 | };
|
---|
304 |
|
---|
305 |
|
---|
306 | /*********************************************************************************************************************************
|
---|
307 | * Global Variables *
|
---|
308 | *********************************************************************************************************************************/
|
---|
309 | /** Command line parameters */
|
---|
310 | static const RTGETOPTDEF g_aCmdOptions[] =
|
---|
311 | {
|
---|
312 | { "--dir", 'd', RTGETOPT_REQ_STRING },
|
---|
313 | { "--seconds", 's', RTGETOPT_REQ_UINT32 },
|
---|
314 | { "--milliseconds", 'm', RTGETOPT_REQ_UINT64 },
|
---|
315 |
|
---|
316 | { "--enable-all", 'e', RTGETOPT_REQ_NOTHING },
|
---|
317 | { "--disable-all", 'z', RTGETOPT_REQ_NOTHING },
|
---|
318 |
|
---|
319 | { "--many-files", kCmdOpt_ManyFiles, RTGETOPT_REQ_UINT32 },
|
---|
320 | { "--no-many-files", kCmdOpt_NoManyFiles, RTGETOPT_REQ_NOTHING },
|
---|
321 | { "--files-per-dir", kCmdOpt_ManyTreeFilesPerDir, RTGETOPT_REQ_UINT32 },
|
---|
322 | { "--subdirs-per-dir", kCmdOpt_ManyTreeSubdirsPerDir, RTGETOPT_REQ_UINT32 },
|
---|
323 | { "--tree-depth", kCmdOpt_ManyTreeDepth, RTGETOPT_REQ_UINT32 },
|
---|
324 |
|
---|
325 | { "--open", kCmdOpt_Open, RTGETOPT_REQ_NOTHING },
|
---|
326 | { "--no-open", kCmdOpt_NoOpen, RTGETOPT_REQ_NOTHING },
|
---|
327 | { "--fstat", kCmdOpt_FStat, RTGETOPT_REQ_NOTHING },
|
---|
328 | { "--no-fstat", kCmdOpt_NoFStat, RTGETOPT_REQ_NOTHING },
|
---|
329 | { "--fchmod", kCmdOpt_FChMod, RTGETOPT_REQ_NOTHING },
|
---|
330 | { "--no-fchmod", kCmdOpt_NoFChMod, RTGETOPT_REQ_NOTHING },
|
---|
331 | { "--futimes", kCmdOpt_FUtimes, RTGETOPT_REQ_NOTHING },
|
---|
332 | { "--no-futimes", kCmdOpt_NoFUtimes, RTGETOPT_REQ_NOTHING },
|
---|
333 | { "--stat", kCmdOpt_Stat, RTGETOPT_REQ_NOTHING },
|
---|
334 | { "--no-stat", kCmdOpt_NoStat, RTGETOPT_REQ_NOTHING },
|
---|
335 | { "--chmod", kCmdOpt_ChMod, RTGETOPT_REQ_NOTHING },
|
---|
336 | { "--no-chmod", kCmdOpt_NoChMod, RTGETOPT_REQ_NOTHING },
|
---|
337 | { "--utimes", kCmdOpt_Utimes, RTGETOPT_REQ_NOTHING },
|
---|
338 | { "--no-utimes", kCmdOpt_NoUtimes, RTGETOPT_REQ_NOTHING },
|
---|
339 | { "--rename", kCmdOpt_Rename, RTGETOPT_REQ_NOTHING },
|
---|
340 | { "--no-rename", kCmdOpt_NoRename, RTGETOPT_REQ_NOTHING },
|
---|
341 | { "--dir-open", kCmdOpt_DirOpen, RTGETOPT_REQ_NOTHING },
|
---|
342 | { "--no-dir-open", kCmdOpt_NoDirOpen, RTGETOPT_REQ_NOTHING },
|
---|
343 | { "--dir-enum", kCmdOpt_DirEnum, RTGETOPT_REQ_NOTHING },
|
---|
344 | { "--no-dir-enum", kCmdOpt_NoDirEnum, RTGETOPT_REQ_NOTHING },
|
---|
345 | { "--mk-rm-dir", kCmdOpt_MkRmDir, RTGETOPT_REQ_NOTHING },
|
---|
346 | { "--no-mk-rm-dir", kCmdOpt_NoMkRmDir, RTGETOPT_REQ_NOTHING },
|
---|
347 | { "--stat-vfs", kCmdOpt_StatVfs, RTGETOPT_REQ_NOTHING },
|
---|
348 | { "--no-stat-vfs", kCmdOpt_NoStatVfs, RTGETOPT_REQ_NOTHING },
|
---|
349 | { "--rm", kCmdOpt_Rm, RTGETOPT_REQ_NOTHING },
|
---|
350 | { "--no-rm", kCmdOpt_NoRm, RTGETOPT_REQ_NOTHING },
|
---|
351 | { "--chsize", kCmdOpt_ChSize, RTGETOPT_REQ_NOTHING },
|
---|
352 | { "--no-chsize", kCmdOpt_NoChSize, RTGETOPT_REQ_NOTHING },
|
---|
353 | { "--read-tests", kCmdOpt_ReadTests, RTGETOPT_REQ_NOTHING },
|
---|
354 | { "--no-read-tests", kCmdOpt_NoReadTests, RTGETOPT_REQ_NOTHING },
|
---|
355 | { "--read-perf", kCmdOpt_ReadPerf, RTGETOPT_REQ_NOTHING },
|
---|
356 | { "--no-read-perf", kCmdOpt_NoReadPerf, RTGETOPT_REQ_NOTHING },
|
---|
357 | { "--write-tests", kCmdOpt_WriteTests, RTGETOPT_REQ_NOTHING },
|
---|
358 | { "--no-write-tests", kCmdOpt_NoWriteTests, RTGETOPT_REQ_NOTHING },
|
---|
359 | { "--write-perf", kCmdOpt_WritePerf, RTGETOPT_REQ_NOTHING },
|
---|
360 | { "--no-write-perf", kCmdOpt_NoWritePerf, RTGETOPT_REQ_NOTHING },
|
---|
361 | { "--seek", kCmdOpt_Seek, RTGETOPT_REQ_NOTHING },
|
---|
362 | { "--no-seek", kCmdOpt_NoSeek, RTGETOPT_REQ_NOTHING },
|
---|
363 | { "--fsync", kCmdOpt_FSync, RTGETOPT_REQ_NOTHING },
|
---|
364 | { "--no-fsync", kCmdOpt_NoFSync, RTGETOPT_REQ_NOTHING },
|
---|
365 | { "--mmap", kCmdOpt_MMap, RTGETOPT_REQ_NOTHING },
|
---|
366 | { "--no-mmap", kCmdOpt_NoMMap, RTGETOPT_REQ_NOTHING },
|
---|
367 | { "--ignore-no-cache", kCmdOpt_IgnoreNoCache, RTGETOPT_REQ_NOTHING },
|
---|
368 | { "--no-ignore-no-cache", kCmdOpt_NoIgnoreNoCache, RTGETOPT_REQ_NOTHING },
|
---|
369 | { "--io-file-size", kCmdOpt_IoFileSize, RTGETOPT_REQ_UINT64 },
|
---|
370 | { "--set-block-size", kCmdOpt_SetBlockSize, RTGETOPT_REQ_UINT32 },
|
---|
371 | { "--add-block-size", kCmdOpt_AddBlockSize, RTGETOPT_REQ_UINT32 },
|
---|
372 | { "--copy", kCmdOpt_Copy, RTGETOPT_REQ_NOTHING },
|
---|
373 | { "--no-copy", kCmdOpt_NoCopy, RTGETOPT_REQ_NOTHING },
|
---|
374 |
|
---|
375 | { "--show-duration", kCmdOpt_ShowDuration, RTGETOPT_REQ_NOTHING },
|
---|
376 | { "--no-show-duration", kCmdOpt_NoShowDuration, RTGETOPT_REQ_NOTHING },
|
---|
377 | { "--show-iterations", kCmdOpt_ShowIterations, RTGETOPT_REQ_NOTHING },
|
---|
378 | { "--no-show-iterations", kCmdOpt_NoShowIterations, RTGETOPT_REQ_NOTHING },
|
---|
379 |
|
---|
380 | { "--quiet", 'q', RTGETOPT_REQ_NOTHING },
|
---|
381 | { "--verbose", 'v', RTGETOPT_REQ_NOTHING },
|
---|
382 | { "--version", 'V', RTGETOPT_REQ_NOTHING },
|
---|
383 | { "--help", 'h', RTGETOPT_REQ_NOTHING } /* for Usage() */
|
---|
384 | };
|
---|
385 |
|
---|
386 | /** The test handle. */
|
---|
387 | static RTTEST g_hTest;
|
---|
388 | /** The number of nanoseconds a RTTimeNanoTS call takes.
|
---|
389 | * This is used for adjusting loop count estimates. */
|
---|
390 | static uint64_t g_nsPerNanoTSCall = 1;
|
---|
391 | /** Whether or not to display the duration of each profile run.
|
---|
392 | * This is chiefly for verify the estimate phase. */
|
---|
393 | static bool g_fShowDuration = false;
|
---|
394 | /** Whether or not to display the iteration count for each profile run.
|
---|
395 | * This is chiefly for verify the estimate phase. */
|
---|
396 | static bool g_fShowIterations = false;
|
---|
397 | /** Verbosity level. */
|
---|
398 | static uint32_t g_uVerbosity = 0;
|
---|
399 |
|
---|
400 | /** @name Selected subtest
|
---|
401 | * @{ */
|
---|
402 | static bool g_fManyFiles = true;
|
---|
403 | static bool g_fOpen = true;
|
---|
404 | static bool g_fFStat = true;
|
---|
405 | static bool g_fFChMod = true;
|
---|
406 | static bool g_fFUtimes = true;
|
---|
407 | static bool g_fStat = true;
|
---|
408 | static bool g_fChMod = true;
|
---|
409 | static bool g_fUtimes = true;
|
---|
410 | static bool g_fRename = true;
|
---|
411 | static bool g_fDirOpen = true;
|
---|
412 | static bool g_fDirEnum = true;
|
---|
413 | static bool g_fMkRmDir = true;
|
---|
414 | static bool g_fStatVfs = true;
|
---|
415 | static bool g_fRm = true;
|
---|
416 | static bool g_fChSize = true;
|
---|
417 | static bool g_fReadTests = true;
|
---|
418 | static bool g_fReadPerf = true;
|
---|
419 | static bool g_fWriteTests= true;
|
---|
420 | static bool g_fWritePerf = true;
|
---|
421 | static bool g_fSeek = true;
|
---|
422 | static bool g_fFSync = true;
|
---|
423 | static bool g_fMMap = true;
|
---|
424 | static bool g_fCopy = true;
|
---|
425 | /** @} */
|
---|
426 |
|
---|
427 | /** The length of each test run. */
|
---|
428 | static uint64_t g_nsTestRun = RT_NS_1SEC_64 * 10;
|
---|
429 |
|
---|
430 | /** For the 'manyfiles' subdir. */
|
---|
431 | static uint32_t g_cManyFiles = 10000;
|
---|
432 |
|
---|
433 | /** Number of files in the 'manytree' directory tree. */
|
---|
434 | static uint32_t g_cManyTreeFiles = 640 + 16*640 /*10880*/;
|
---|
435 | /** Number of files per directory in the 'manytree' construct. */
|
---|
436 | static uint32_t g_cManyTreeFilesPerDir = 640;
|
---|
437 | /** Number of subdirs per directory in the 'manytree' construct. */
|
---|
438 | static uint32_t g_cManyTreeSubdirsPerDir = 16;
|
---|
439 | /** The depth of the 'manytree' directory tree. */
|
---|
440 | static uint32_t g_cManyTreeDepth = 1;
|
---|
441 | /** List of directories in the many tree, creation order. */
|
---|
442 | static RTLISTANCHOR g_ManyTreeHead;
|
---|
443 |
|
---|
444 | /** Number of configured I/O block sizes. */
|
---|
445 | static uint32_t g_cIoBlocks = 8;
|
---|
446 | /** Configured I/O block sizes. */
|
---|
447 | static uint32_t g_acbIoBlocks[16] = { 1, 512, 4096, 16384, 65536, _1M, _32M, _128M };
|
---|
448 | /** The desired size of the test file we use for I/O. */
|
---|
449 | static uint64_t g_cbIoFile = _512M;
|
---|
450 | /** Whether to be less strict with non-cache file handle. */
|
---|
451 | static bool g_fIgnoreNoCache = false;
|
---|
452 |
|
---|
453 | /** The length of g_szDir. */
|
---|
454 | static size_t g_cchDir;
|
---|
455 | /** The length of g_szEmptyDir. */
|
---|
456 | static size_t g_cchEmptyDir;
|
---|
457 | /** The length of g_szDeepDir. */
|
---|
458 | static size_t g_cchDeepDir;
|
---|
459 |
|
---|
460 | /** The test directory (absolute). This will always have a trailing slash. */
|
---|
461 | static char g_szDir[RTPATH_MAX];
|
---|
462 | /** The test directory (absolute), 2nd copy for use with InDir2(). */
|
---|
463 | static char g_szDir2[RTPATH_MAX];
|
---|
464 | /** The empty test directory (absolute). This will always have a trailing slash. */
|
---|
465 | static char g_szEmptyDir[RTPATH_MAX];
|
---|
466 | /** The deep test directory (absolute). This will always have a trailing slash. */
|
---|
467 | static char g_szDeepDir[RTPATH_MAX];
|
---|
468 |
|
---|
469 |
|
---|
470 | /**
|
---|
471 | * Yield the CPU and stuff before starting a test run.
|
---|
472 | */
|
---|
473 | DECLINLINE(void) fsPerfYield(void)
|
---|
474 | {
|
---|
475 | RTThreadYield();
|
---|
476 | RTThreadYield();
|
---|
477 | }
|
---|
478 |
|
---|
479 |
|
---|
480 | /**
|
---|
481 | * Profiles the RTTimeNanoTS call, setting g_nsPerNanoTSCall.
|
---|
482 | */
|
---|
483 | static void fsPerfNanoTS(void)
|
---|
484 | {
|
---|
485 | fsPerfYield();
|
---|
486 |
|
---|
487 | /* Make sure we start off on a changing timestamp on platforms will low time resoultion. */
|
---|
488 | uint64_t nsStart = RTTimeNanoTS();
|
---|
489 | uint64_t ns;
|
---|
490 | do
|
---|
491 | ns = RTTimeNanoTS();
|
---|
492 | while (ns == nsStart);
|
---|
493 | nsStart = ns;
|
---|
494 |
|
---|
495 | /* Call it for 10 ms. */
|
---|
496 | uint32_t i = 0;
|
---|
497 | do
|
---|
498 | {
|
---|
499 | i++;
|
---|
500 | ns = RTTimeNanoTS();
|
---|
501 | }
|
---|
502 | while (ns - nsStart < RT_NS_10MS);
|
---|
503 |
|
---|
504 | g_nsPerNanoTSCall = (ns - nsStart) / i;
|
---|
505 | }
|
---|
506 |
|
---|
507 |
|
---|
508 | /**
|
---|
509 | * Construct a path relative to the base test directory.
|
---|
510 | *
|
---|
511 | * @returns g_szDir.
|
---|
512 | * @param pszAppend What to append.
|
---|
513 | * @param cchAppend How much to append.
|
---|
514 | */
|
---|
515 | DECLINLINE(char *) InDir(const char *pszAppend, size_t cchAppend)
|
---|
516 | {
|
---|
517 | Assert(g_szDir[g_cchDir - 1] == RTPATH_SLASH);
|
---|
518 | memcpy(&g_szDir[g_cchDir], pszAppend, cchAppend);
|
---|
519 | g_szDir[g_cchDir + cchAppend] = '\0';
|
---|
520 | return &g_szDir[0];
|
---|
521 | }
|
---|
522 |
|
---|
523 |
|
---|
524 | /**
|
---|
525 | * Construct a path relative to the base test directory, 2nd copy.
|
---|
526 | *
|
---|
527 | * @returns g_szDir2.
|
---|
528 | * @param pszAppend What to append.
|
---|
529 | * @param cchAppend How much to append.
|
---|
530 | */
|
---|
531 | DECLINLINE(char *) InDir2(const char *pszAppend, size_t cchAppend)
|
---|
532 | {
|
---|
533 | Assert(g_szDir[g_cchDir - 1] == RTPATH_SLASH);
|
---|
534 | memcpy(g_szDir2, g_szDir, g_cchDir);
|
---|
535 | memcpy(&g_szDir2[g_cchDir], pszAppend, cchAppend);
|
---|
536 | g_szDir2[g_cchDir + cchAppend] = '\0';
|
---|
537 | return &g_szDir2[0];
|
---|
538 | }
|
---|
539 |
|
---|
540 |
|
---|
541 | /**
|
---|
542 | * Construct a path relative to the empty directory.
|
---|
543 | *
|
---|
544 | * @returns g_szEmptyDir.
|
---|
545 | * @param pszAppend What to append.
|
---|
546 | * @param cchAppend How much to append.
|
---|
547 | */
|
---|
548 | DECLINLINE(char *) InEmptyDir(const char *pszAppend, size_t cchAppend)
|
---|
549 | {
|
---|
550 | Assert(g_szEmptyDir[g_cchEmptyDir - 1] == RTPATH_SLASH);
|
---|
551 | memcpy(&g_szEmptyDir[g_cchEmptyDir], pszAppend, cchAppend);
|
---|
552 | g_szEmptyDir[g_cchEmptyDir + cchAppend] = '\0';
|
---|
553 | return &g_szEmptyDir[0];
|
---|
554 | }
|
---|
555 |
|
---|
556 |
|
---|
557 | /**
|
---|
558 | * Construct a path relative to the deep test directory.
|
---|
559 | *
|
---|
560 | * @returns g_szDeepDir.
|
---|
561 | * @param pszAppend What to append.
|
---|
562 | * @param cchAppend How much to append.
|
---|
563 | */
|
---|
564 | DECLINLINE(char *) InDeepDir(const char *pszAppend, size_t cchAppend)
|
---|
565 | {
|
---|
566 | Assert(g_szDeepDir[g_cchDeepDir - 1] == RTPATH_SLASH);
|
---|
567 | memcpy(&g_szDeepDir[g_cchDeepDir], pszAppend, cchAppend);
|
---|
568 | g_szDeepDir[g_cchDeepDir + cchAppend] = '\0';
|
---|
569 | return &g_szDeepDir[0];
|
---|
570 | }
|
---|
571 |
|
---|
572 |
|
---|
573 | /**
|
---|
574 | * Prepares the test area.
|
---|
575 | * @returns VBox status code.
|
---|
576 | */
|
---|
577 | static int fsPrepTestArea(void)
|
---|
578 | {
|
---|
579 | /* The empty subdir and associated globals: */
|
---|
580 | static char s_szEmpty[] = "empty";
|
---|
581 | memcpy(g_szEmptyDir, g_szDir, g_cchDir);
|
---|
582 | memcpy(&g_szEmptyDir[g_cchDir], s_szEmpty, sizeof(s_szEmpty));
|
---|
583 | g_cchEmptyDir = g_cchDir + sizeof(s_szEmpty) - 1;
|
---|
584 | RTTESTI_CHECK_RC_RET(RTDirCreate(g_szEmptyDir, 0755, 0), VINF_SUCCESS, rcCheck);
|
---|
585 | g_szEmptyDir[g_cchEmptyDir++] = RTPATH_SLASH;
|
---|
586 | g_szEmptyDir[g_cchEmptyDir] = '\0';
|
---|
587 | RTTestIPrintf(RTTESTLVL_ALWAYS, "Empty dir: %s\n", g_szEmptyDir);
|
---|
588 |
|
---|
589 | /* Deep directory: */
|
---|
590 | memcpy(g_szDeepDir, g_szDir, g_cchDir);
|
---|
591 | g_cchDeepDir = g_cchDir;
|
---|
592 | do
|
---|
593 | {
|
---|
594 | static char const s_szSub[] = "d" RTPATH_SLASH_STR;
|
---|
595 | memcpy(&g_szDeepDir[g_cchDeepDir], s_szSub, sizeof(s_szSub));
|
---|
596 | g_cchDeepDir += sizeof(s_szSub) - 1;
|
---|
597 | RTTESTI_CHECK_RC_RET( RTDirCreate(g_szDeepDir, 0755, 0), VINF_SUCCESS, rcCheck);
|
---|
598 | } while (g_cchDeepDir < 176);
|
---|
599 | RTTestIPrintf(RTTESTLVL_ALWAYS, "Deep dir: %s\n", g_szDeepDir);
|
---|
600 |
|
---|
601 | /* Create known file in both deep and shallow dirs: */
|
---|
602 | RTFILE hKnownFile;
|
---|
603 | RTTESTI_CHECK_RC_RET(RTFileOpen(&hKnownFile, InDir(RT_STR_TUPLE("known-file")),
|
---|
604 | RTFILE_O_CREATE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE),
|
---|
605 | VINF_SUCCESS, rcCheck);
|
---|
606 | RTTESTI_CHECK_RC_RET(RTFileClose(hKnownFile), VINF_SUCCESS, rcCheck);
|
---|
607 |
|
---|
608 | RTTESTI_CHECK_RC_RET(RTFileOpen(&hKnownFile, InDeepDir(RT_STR_TUPLE("known-file")),
|
---|
609 | RTFILE_O_CREATE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE),
|
---|
610 | VINF_SUCCESS, rcCheck);
|
---|
611 | RTTESTI_CHECK_RC_RET(RTFileClose(hKnownFile), VINF_SUCCESS, rcCheck);
|
---|
612 |
|
---|
613 | return VINF_SUCCESS;
|
---|
614 | }
|
---|
615 |
|
---|
616 |
|
---|
617 | /**
|
---|
618 | * Create a name list entry.
|
---|
619 | * @returns Pointer to the entry, NULL if out of memory.
|
---|
620 | * @param pchName The name.
|
---|
621 | * @param cchName The name length.
|
---|
622 | */
|
---|
623 | PFSPERFNAMEENTRY fsPerfCreateNameEntry(const char *pchName, size_t cchName)
|
---|
624 | {
|
---|
625 | PFSPERFNAMEENTRY pEntry = (PFSPERFNAMEENTRY)RTMemAllocVar(RT_UOFFSETOF_DYN(FSPERFNAMEENTRY, szName[cchName + 1]));
|
---|
626 | if (pEntry)
|
---|
627 | {
|
---|
628 | RTListInit(&pEntry->Entry);
|
---|
629 | pEntry->cchName = (uint16_t)cchName;
|
---|
630 | memcpy(pEntry->szName, pchName, cchName);
|
---|
631 | pEntry->szName[cchName] = '\0';
|
---|
632 | }
|
---|
633 | return pEntry;
|
---|
634 | }
|
---|
635 |
|
---|
636 |
|
---|
637 | static int fsPerfManyTreeRecursiveDirCreator(size_t cchDir, uint32_t iDepth)
|
---|
638 | {
|
---|
639 | PFSPERFNAMEENTRY pEntry = fsPerfCreateNameEntry(g_szDir, cchDir);
|
---|
640 | RTTESTI_CHECK_RET(pEntry, VERR_NO_MEMORY);
|
---|
641 | RTListAppend(&g_ManyTreeHead, &pEntry->Entry);
|
---|
642 |
|
---|
643 | RTTESTI_CHECK_RC_RET(RTDirCreate(g_szDir, 0755, RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_DONT_SET | RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_NOT_CRITICAL),
|
---|
644 | VINF_SUCCESS, rcCheck);
|
---|
645 |
|
---|
646 | if (iDepth < g_cManyTreeDepth)
|
---|
647 | for (uint32_t i = 0; i < g_cManyTreeSubdirsPerDir; i++)
|
---|
648 | {
|
---|
649 | size_t cchSubDir = RTStrPrintf(&g_szDir[cchDir], sizeof(g_szDir) - cchDir, "d%02u" RTPATH_SLASH_STR, i);
|
---|
650 | RTTESTI_CHECK_RC_RET(fsPerfManyTreeRecursiveDirCreator(cchDir + cchSubDir, iDepth + 1), VINF_SUCCESS, rcCheck);
|
---|
651 | }
|
---|
652 |
|
---|
653 | return VINF_SUCCESS;
|
---|
654 | }
|
---|
655 |
|
---|
656 |
|
---|
657 | void fsPerfManyFiles(void)
|
---|
658 | {
|
---|
659 | RTTestISub("manyfiles");
|
---|
660 |
|
---|
661 | /*
|
---|
662 | * Create a sub-directory with like 10000 files in it.
|
---|
663 | *
|
---|
664 | * This does push the directory organization of the underlying file system,
|
---|
665 | * which is something we might not want to profile with shared folders. It
|
---|
666 | * is however useful for directory enumeration.
|
---|
667 | */
|
---|
668 | RTTESTI_CHECK_RC_RETV(RTDirCreate(InDir(RT_STR_TUPLE("manyfiles")), 0755,
|
---|
669 | RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_DONT_SET | RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_NOT_CRITICAL),
|
---|
670 | VINF_SUCCESS);
|
---|
671 |
|
---|
672 | size_t offFilename = strlen(g_szDir);
|
---|
673 | g_szDir[offFilename++] = RTPATH_SLASH;
|
---|
674 |
|
---|
675 | fsPerfYield();
|
---|
676 | RTFILE hFile;
|
---|
677 | uint64_t const nsStart = RTTimeNanoTS();
|
---|
678 | for (uint32_t i = 0; i < g_cManyFiles; i++)
|
---|
679 | {
|
---|
680 | RTStrFormatU32(&g_szDir[offFilename], sizeof(g_szDir) - offFilename, i, 10, 5, 5, RTSTR_F_ZEROPAD);
|
---|
681 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile, g_szDir, RTFILE_O_CREATE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
682 | RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
|
---|
683 | }
|
---|
684 | uint64_t const cNsElapsed = RTTimeNanoTS() - nsStart;
|
---|
685 | RTTestIValueF(cNsElapsed, RTTESTUNIT_NS, "Creating %u empty files in single directory", g_cManyFiles);
|
---|
686 | RTTestIValueF(cNsElapsed / g_cManyFiles, RTTESTUNIT_NS_PER_OCCURRENCE, "Create empty file (single dir)");
|
---|
687 |
|
---|
688 | /*
|
---|
689 | * Create a bunch of directories with exacly 32 files in each, hoping to
|
---|
690 | * avoid any directory organization artifacts.
|
---|
691 | */
|
---|
692 | /* Create the directories first, building a list of them for simplifying iteration: */
|
---|
693 | RTListInit(&g_ManyTreeHead);
|
---|
694 | InDir(RT_STR_TUPLE("manytree" RTPATH_SLASH_STR));
|
---|
695 | RTTESTI_CHECK_RC_RETV(fsPerfManyTreeRecursiveDirCreator(strlen(g_szDir), 0), VINF_SUCCESS);
|
---|
696 |
|
---|
697 | /* Create the zero byte files: */
|
---|
698 | fsPerfYield();
|
---|
699 | uint64_t const nsStart2 = RTTimeNanoTS();
|
---|
700 | uint32_t cFiles = 0;
|
---|
701 | PFSPERFNAMEENTRY pCur;
|
---|
702 | RTListForEach(&g_ManyTreeHead, pCur, FSPERFNAMEENTRY, Entry)
|
---|
703 | {
|
---|
704 | char szPath[RTPATH_MAX];
|
---|
705 | memcpy(szPath, pCur->szName, pCur->cchName);
|
---|
706 | for (uint32_t i = 0; i < g_cManyTreeFilesPerDir; i++)
|
---|
707 | {
|
---|
708 | RTStrFormatU32(&szPath[pCur->cchName], sizeof(szPath) - pCur->cchName, i, 10, 5, 5, RTSTR_F_ZEROPAD);
|
---|
709 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile, szPath, RTFILE_O_CREATE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
710 | RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
|
---|
711 | cFiles++;
|
---|
712 | }
|
---|
713 | }
|
---|
714 | uint64_t const cNsElapsed2 = RTTimeNanoTS() - nsStart2;
|
---|
715 | RTTestIValueF(cNsElapsed2, RTTESTUNIT_NS, "Creating %u empty files in tree", cFiles);
|
---|
716 | RTTestIValueF(cNsElapsed2 / cFiles, RTTESTUNIT_NS_PER_OCCURRENCE, "Create empty file (tree)");
|
---|
717 | RTTESTI_CHECK(g_cManyTreeFiles == cFiles);
|
---|
718 | }
|
---|
719 |
|
---|
720 |
|
---|
721 | DECL_FORCE_INLINE(int) fsPerfOpenExistingOnceReadonly(const char *pszFile)
|
---|
722 | {
|
---|
723 | RTFILE hFile;
|
---|
724 | RTTESTI_CHECK_RC_RET(RTFileOpen(&hFile, pszFile, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ), VINF_SUCCESS, rcCheck);
|
---|
725 | RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
|
---|
726 | return VINF_SUCCESS;
|
---|
727 | }
|
---|
728 |
|
---|
729 |
|
---|
730 | DECL_FORCE_INLINE(int) fsPerfOpenExistingOnceWriteonly(const char *pszFile)
|
---|
731 | {
|
---|
732 | RTFILE hFile;
|
---|
733 | RTTESTI_CHECK_RC_RET(RTFileOpen(&hFile, pszFile, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS, rcCheck);
|
---|
734 | RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
|
---|
735 | return VINF_SUCCESS;
|
---|
736 | }
|
---|
737 |
|
---|
738 |
|
---|
739 | /** @note tstRTFileOpenEx-1.cpp has a copy of this code. */
|
---|
740 | static void tstOpenExTest(unsigned uLine, int cbExist, int cbNext, const char *pszFilename, uint64_t fAction,
|
---|
741 | int rcExpect, RTFILEACTION enmActionExpected)
|
---|
742 | {
|
---|
743 | uint64_t const fCreateMode = (0644 << RTFILE_O_CREATE_MODE_SHIFT);
|
---|
744 | RTFILE hFile;
|
---|
745 | int rc;
|
---|
746 |
|
---|
747 | /*
|
---|
748 | * File existence and size.
|
---|
749 | */
|
---|
750 | bool fOkay = false;
|
---|
751 | RTFSOBJINFO ObjInfo;
|
---|
752 | rc = RTPathQueryInfoEx(pszFilename, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
|
---|
753 | if (RT_SUCCESS(rc))
|
---|
754 | fOkay = cbExist == (int64_t)ObjInfo.cbObject;
|
---|
755 | else
|
---|
756 | fOkay = rc == VERR_FILE_NOT_FOUND && cbExist < 0;
|
---|
757 | if (!fOkay)
|
---|
758 | {
|
---|
759 | if (cbExist >= 0)
|
---|
760 | {
|
---|
761 | rc = RTFileOpen(&hFile, pszFilename, RTFILE_O_WRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | fCreateMode);
|
---|
762 | if (RT_SUCCESS(rc))
|
---|
763 | {
|
---|
764 | while (cbExist > 0)
|
---|
765 | {
|
---|
766 | int cbToWrite = (int)strlen(pszFilename);
|
---|
767 | if (cbToWrite > cbExist)
|
---|
768 | cbToWrite = cbExist;
|
---|
769 | rc = RTFileWrite(hFile, pszFilename, cbToWrite, NULL);
|
---|
770 | if (RT_FAILURE(rc))
|
---|
771 | {
|
---|
772 | RTTestIFailed("%u: RTFileWrite(%s,%#x) -> %Rrc\n", uLine, pszFilename, cbToWrite, rc);
|
---|
773 | break;
|
---|
774 | }
|
---|
775 | cbExist -= cbToWrite;
|
---|
776 | }
|
---|
777 |
|
---|
778 | RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
|
---|
779 | }
|
---|
780 | else
|
---|
781 | RTTestIFailed("%u: RTFileDelete(%s) -> %Rrc\n", uLine, pszFilename, rc);
|
---|
782 |
|
---|
783 | }
|
---|
784 | else
|
---|
785 | {
|
---|
786 | rc = RTFileDelete(pszFilename);
|
---|
787 | if (rc != VINF_SUCCESS && rc != VERR_FILE_NOT_FOUND)
|
---|
788 | RTTestIFailed("%u: RTFileDelete(%s) -> %Rrc\n", uLine, pszFilename, rc);
|
---|
789 | }
|
---|
790 | }
|
---|
791 |
|
---|
792 | /*
|
---|
793 | * The actual test.
|
---|
794 | */
|
---|
795 | RTFILEACTION enmActuallyTaken = RTFILEACTION_END;
|
---|
796 | hFile = NIL_RTFILE;
|
---|
797 | rc = RTFileOpenEx(pszFilename, fAction | RTFILE_O_READWRITE | RTFILE_O_DENY_NONE | fCreateMode, &hFile, &enmActuallyTaken);
|
---|
798 | if ( rc != rcExpect
|
---|
799 | || enmActuallyTaken != enmActionExpected
|
---|
800 | || (RT_SUCCESS(rc) ? hFile == NIL_RTFILE : hFile != NIL_RTFILE))
|
---|
801 | RTTestIFailed("%u: RTFileOpenEx(%s, %#llx) -> %Rrc + %d (hFile=%p), expected %Rrc + %d\n",
|
---|
802 | uLine, pszFilename, fAction, rc, enmActuallyTaken, hFile, rcExpect, enmActionExpected);
|
---|
803 | if (RT_SUCCESS(rc))
|
---|
804 | {
|
---|
805 | if ( enmActionExpected == RTFILEACTION_REPLACED
|
---|
806 | || enmActionExpected == RTFILEACTION_TRUNCATED)
|
---|
807 | {
|
---|
808 | uint8_t abBuf[16];
|
---|
809 | rc = RTFileRead(hFile, abBuf, 1, NULL);
|
---|
810 | if (rc != VERR_EOF)
|
---|
811 | RTTestIFailed("%u: RTFileRead(%s,,1,) -> %Rrc, expected VERR_EOF\n", uLine, pszFilename, rc);
|
---|
812 | }
|
---|
813 |
|
---|
814 | while (cbNext > 0)
|
---|
815 | {
|
---|
816 | int cbToWrite = (int)strlen(pszFilename);
|
---|
817 | if (cbToWrite > cbNext)
|
---|
818 | cbToWrite = cbNext;
|
---|
819 | rc = RTFileWrite(hFile, pszFilename, cbToWrite, NULL);
|
---|
820 | if (RT_FAILURE(rc))
|
---|
821 | {
|
---|
822 | RTTestIFailed("%u: RTFileWrite(%s,%#x) -> %Rrc\n", uLine, pszFilename, cbToWrite, rc);
|
---|
823 | break;
|
---|
824 | }
|
---|
825 | cbNext -= cbToWrite;
|
---|
826 | }
|
---|
827 |
|
---|
828 | rc = RTFileClose(hFile);
|
---|
829 | if (RT_FAILURE(rc))
|
---|
830 | RTTestIFailed("%u: RTFileClose(%p) -> %Rrc\n", uLine, hFile, rc);
|
---|
831 | }
|
---|
832 | }
|
---|
833 |
|
---|
834 |
|
---|
835 | void fsPerfOpen(void)
|
---|
836 | {
|
---|
837 | RTTestISub("open");
|
---|
838 |
|
---|
839 | /* Opening non-existing files. */
|
---|
840 | RTFILE hFile;
|
---|
841 | RTTESTI_CHECK_RC(RTFileOpen(&hFile, InEmptyDir(RT_STR_TUPLE("no-such-file")),
|
---|
842 | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ), VERR_FILE_NOT_FOUND);
|
---|
843 | RTTESTI_CHECK_RC(RTFileOpen(&hFile, InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file")),
|
---|
844 | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
845 | RTTESTI_CHECK_RC(RTFileOpen(&hFile, InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file")),
|
---|
846 | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ), VERR_PATH_NOT_FOUND);
|
---|
847 |
|
---|
848 | /*
|
---|
849 | * The following is copied from tstRTFileOpenEx-1.cpp:
|
---|
850 | */
|
---|
851 | InDir(RT_STR_TUPLE("file1"));
|
---|
852 | tstOpenExTest(__LINE__, -1, -1, g_szDir, RTFILE_O_OPEN, VERR_FILE_NOT_FOUND, RTFILEACTION_INVALID);
|
---|
853 | tstOpenExTest(__LINE__, -1, -1, g_szDir, RTFILE_O_OPEN_CREATE, VINF_SUCCESS, RTFILEACTION_CREATED);
|
---|
854 | tstOpenExTest(__LINE__, 0, 0, g_szDir, RTFILE_O_OPEN_CREATE, VINF_SUCCESS, RTFILEACTION_OPENED);
|
---|
855 | tstOpenExTest(__LINE__, 0, 0, g_szDir, RTFILE_O_OPEN, VINF_SUCCESS, RTFILEACTION_OPENED);
|
---|
856 |
|
---|
857 | tstOpenExTest(__LINE__, 0, 0, g_szDir, RTFILE_O_OPEN | RTFILE_O_TRUNCATE, VINF_SUCCESS, RTFILEACTION_TRUNCATED);
|
---|
858 | tstOpenExTest(__LINE__, 0, 10, g_szDir, RTFILE_O_OPEN_CREATE | RTFILE_O_TRUNCATE, VINF_SUCCESS, RTFILEACTION_TRUNCATED);
|
---|
859 | tstOpenExTest(__LINE__, 10, 10, g_szDir, RTFILE_O_OPEN_CREATE | RTFILE_O_TRUNCATE, VINF_SUCCESS, RTFILEACTION_TRUNCATED);
|
---|
860 | tstOpenExTest(__LINE__, 10, -1, g_szDir, RTFILE_O_OPEN | RTFILE_O_TRUNCATE, VINF_SUCCESS, RTFILEACTION_TRUNCATED);
|
---|
861 | tstOpenExTest(__LINE__, -1, -1, g_szDir, RTFILE_O_OPEN | RTFILE_O_TRUNCATE, VERR_FILE_NOT_FOUND, RTFILEACTION_INVALID);
|
---|
862 | tstOpenExTest(__LINE__, -1, 0, g_szDir, RTFILE_O_OPEN_CREATE | RTFILE_O_TRUNCATE, VINF_SUCCESS, RTFILEACTION_CREATED);
|
---|
863 |
|
---|
864 | tstOpenExTest(__LINE__, 0, -1, g_szDir, RTFILE_O_CREATE_REPLACE, VINF_SUCCESS, RTFILEACTION_REPLACED);
|
---|
865 | tstOpenExTest(__LINE__, -1, 0, g_szDir, RTFILE_O_CREATE_REPLACE, VINF_SUCCESS, RTFILEACTION_CREATED);
|
---|
866 | tstOpenExTest(__LINE__, 0, -1, g_szDir, RTFILE_O_CREATE, VERR_ALREADY_EXISTS, RTFILEACTION_ALREADY_EXISTS);
|
---|
867 | tstOpenExTest(__LINE__, -1, -1, g_szDir, RTFILE_O_CREATE, VINF_SUCCESS, RTFILEACTION_CREATED);
|
---|
868 |
|
---|
869 | tstOpenExTest(__LINE__, -1, 10, g_szDir, RTFILE_O_CREATE | RTFILE_O_TRUNCATE, VINF_SUCCESS, RTFILEACTION_CREATED);
|
---|
870 | tstOpenExTest(__LINE__, 10, 10, g_szDir, RTFILE_O_CREATE | RTFILE_O_TRUNCATE, VERR_ALREADY_EXISTS, RTFILEACTION_ALREADY_EXISTS);
|
---|
871 | tstOpenExTest(__LINE__, 10, -1, g_szDir, RTFILE_O_CREATE_REPLACE | RTFILE_O_TRUNCATE, VINF_SUCCESS, RTFILEACTION_REPLACED);
|
---|
872 | tstOpenExTest(__LINE__, -1, -1, g_szDir, RTFILE_O_CREATE_REPLACE | RTFILE_O_TRUNCATE, VINF_SUCCESS, RTFILEACTION_CREATED);
|
---|
873 |
|
---|
874 | RTTESTI_CHECK_RC(RTFileDelete(g_szDir), VINF_SUCCESS);
|
---|
875 |
|
---|
876 | /*
|
---|
877 | * Create file1 and then try exclusivly creating it again.
|
---|
878 | * Then profile opening it for reading.
|
---|
879 | */
|
---|
880 | RTFILE hFile1;
|
---|
881 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file1")),
|
---|
882 | RTFILE_O_CREATE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
883 | RTTESTI_CHECK_RC(RTFileOpen(&hFile, g_szDir, RTFILE_O_CREATE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VERR_ALREADY_EXISTS);
|
---|
884 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
885 |
|
---|
886 | PROFILE_FN(fsPerfOpenExistingOnceReadonly(g_szDir), g_nsTestRun, "RTFileOpen/Close/Readonly");
|
---|
887 | PROFILE_FN(fsPerfOpenExistingOnceWriteonly(g_szDir), g_nsTestRun, "RTFileOpen/Close/Writeonly");
|
---|
888 |
|
---|
889 | /*
|
---|
890 | * Profile opening in the deep directory too.
|
---|
891 | */
|
---|
892 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDeepDir(RT_STR_TUPLE("file1")),
|
---|
893 | RTFILE_O_CREATE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
894 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
895 | PROFILE_FN(fsPerfOpenExistingOnceReadonly(g_szDeepDir), g_nsTestRun, "RTFileOpen/Close/deep/readonly");
|
---|
896 | PROFILE_FN(fsPerfOpenExistingOnceWriteonly(g_szDeepDir), g_nsTestRun, "RTFileOpen/Close/deep/writeonly");
|
---|
897 |
|
---|
898 | /* Manytree: */
|
---|
899 | char szPath[RTPATH_MAX];
|
---|
900 | PROFILE_MANYTREE_FN(szPath, fsPerfOpenExistingOnceReadonly(szPath), 1, g_nsTestRun, "RTFileOpen/Close/manytree/readonly");
|
---|
901 | }
|
---|
902 |
|
---|
903 |
|
---|
904 | void fsPerfFStat(void)
|
---|
905 | {
|
---|
906 | RTTestISub("fstat");
|
---|
907 | RTFILE hFile1;
|
---|
908 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file2")),
|
---|
909 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
910 | RTFSOBJINFO ObjInfo = {0};
|
---|
911 | PROFILE_FN(RTFileQueryInfo(hFile1, &ObjInfo, RTFSOBJATTRADD_NOTHING), g_nsTestRun, "RTFileQueryInfo/NOTHING");
|
---|
912 | PROFILE_FN(RTFileQueryInfo(hFile1, &ObjInfo, RTFSOBJATTRADD_UNIX), g_nsTestRun, "RTFileQueryInfo/UNIX");
|
---|
913 |
|
---|
914 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
915 | }
|
---|
916 |
|
---|
917 |
|
---|
918 | void fsPerfFChMod(void)
|
---|
919 | {
|
---|
920 | RTTestISub("fchmod");
|
---|
921 | RTFILE hFile1;
|
---|
922 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file4")),
|
---|
923 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
924 | RTFSOBJINFO ObjInfo = {0};
|
---|
925 | RTTESTI_CHECK_RC(RTFileQueryInfo(hFile1, &ObjInfo, RTFSOBJATTRADD_NOTHING), VINF_SUCCESS);
|
---|
926 | RTFMODE const fEvenMode = (ObjInfo.Attr.fMode & ~RTFS_UNIX_ALL_ACCESS_PERMS) | RTFS_DOS_READONLY | 0400;
|
---|
927 | RTFMODE const fOddMode = (ObjInfo.Attr.fMode & ~(RTFS_UNIX_ALL_ACCESS_PERMS | RTFS_DOS_READONLY)) | 0640;
|
---|
928 | PROFILE_FN(RTFileSetMode(hFile1, iIteration & 1 ? fOddMode : fEvenMode), g_nsTestRun, "RTFileSetMode");
|
---|
929 |
|
---|
930 | RTFileSetMode(hFile1, ObjInfo.Attr.fMode);
|
---|
931 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
932 | }
|
---|
933 |
|
---|
934 |
|
---|
935 | void fsPerfFUtimes(void)
|
---|
936 | {
|
---|
937 | RTTestISub("futimes");
|
---|
938 | RTFILE hFile1;
|
---|
939 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file5")),
|
---|
940 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
941 | RTTIMESPEC Time1;
|
---|
942 | RTTimeNow(&Time1);
|
---|
943 | RTTIMESPEC Time2 = Time1;
|
---|
944 | RTTimeSpecSubSeconds(&Time2, 3636);
|
---|
945 |
|
---|
946 | RTFSOBJINFO ObjInfo0 = {0};
|
---|
947 | RTTESTI_CHECK_RC(RTFileQueryInfo(hFile1, &ObjInfo0, RTFSOBJATTRADD_NOTHING), VINF_SUCCESS);
|
---|
948 |
|
---|
949 | /* Modify modification time: */
|
---|
950 | RTTESTI_CHECK_RC(RTFileSetTimes(hFile1, NULL, &Time2, NULL, NULL), VINF_SUCCESS);
|
---|
951 | RTFSOBJINFO ObjInfo1 = {0};
|
---|
952 | RTTESTI_CHECK_RC(RTFileQueryInfo(hFile1, &ObjInfo1, RTFSOBJATTRADD_NOTHING), VINF_SUCCESS);
|
---|
953 | RTTESTI_CHECK((RTTimeSpecGetSeconds(&ObjInfo1.ModificationTime) >> 2) == (RTTimeSpecGetSeconds(&Time2) >> 2));
|
---|
954 | char sz1[RTTIME_STR_LEN], sz2[RTTIME_STR_LEN]; /* Div by 1000 here for posix impl. using timeval. */
|
---|
955 | RTTESTI_CHECK_MSG(RTTimeSpecGetNano(&ObjInfo1.AccessTime) / 1000 == RTTimeSpecGetNano(&ObjInfo0.AccessTime) / 1000,
|
---|
956 | ("%s, expected %s", RTTimeSpecToString(&ObjInfo1.AccessTime, sz1, sizeof(sz1)),
|
---|
957 | RTTimeSpecToString(&ObjInfo0.AccessTime, sz2, sizeof(sz2))));
|
---|
958 |
|
---|
959 | /* Modify access time: */
|
---|
960 | RTTESTI_CHECK_RC(RTFileSetTimes(hFile1, &Time1, NULL, NULL, NULL), VINF_SUCCESS);
|
---|
961 | RTFSOBJINFO ObjInfo2 = {0};
|
---|
962 | RTTESTI_CHECK_RC(RTFileQueryInfo(hFile1, &ObjInfo2, RTFSOBJATTRADD_NOTHING), VINF_SUCCESS);
|
---|
963 | RTTESTI_CHECK((RTTimeSpecGetSeconds(&ObjInfo2.AccessTime) >> 2) == (RTTimeSpecGetSeconds(&Time1) >> 2));
|
---|
964 | RTTESTI_CHECK(RTTimeSpecGetNano(&ObjInfo2.ModificationTime) / 1000 == RTTimeSpecGetNano(&ObjInfo1.ModificationTime) / 1000);
|
---|
965 |
|
---|
966 | /* Benchmark it: */
|
---|
967 | PROFILE_FN(RTFileSetTimes(hFile1, NULL, iIteration & 1 ? &Time1 : &Time2, NULL, NULL), g_nsTestRun, "RTFileSetTimes");
|
---|
968 |
|
---|
969 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
970 | }
|
---|
971 |
|
---|
972 |
|
---|
973 | void fsPerfStat(void)
|
---|
974 | {
|
---|
975 | RTTestISub("stat");
|
---|
976 | RTFSOBJINFO ObjInfo;
|
---|
977 |
|
---|
978 | /* Non-existing files. */
|
---|
979 | RTTESTI_CHECK_RC(RTPathQueryInfoEx(InEmptyDir(RT_STR_TUPLE("no-such-file")),
|
---|
980 | &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), VERR_FILE_NOT_FOUND);
|
---|
981 | RTTESTI_CHECK_RC(RTPathQueryInfoEx(InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file")),
|
---|
982 | &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
983 | RTTESTI_CHECK_RC(RTPathQueryInfoEx(InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file")),
|
---|
984 | &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), VERR_PATH_NOT_FOUND);
|
---|
985 |
|
---|
986 | /* Shallow: */
|
---|
987 | RTFILE hFile1;
|
---|
988 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file3")),
|
---|
989 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
990 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
991 |
|
---|
992 | PROFILE_FN(RTPathQueryInfoEx(g_szDir, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), g_nsTestRun,
|
---|
993 | "RTPathQueryInfoEx/NOTHING");
|
---|
994 | PROFILE_FN(RTPathQueryInfoEx(g_szDir, &ObjInfo, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK), g_nsTestRun,
|
---|
995 | "RTPathQueryInfoEx/UNIX");
|
---|
996 |
|
---|
997 |
|
---|
998 | /* Deep: */
|
---|
999 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDeepDir(RT_STR_TUPLE("file3")),
|
---|
1000 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
1001 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
1002 |
|
---|
1003 | PROFILE_FN(RTPathQueryInfoEx(g_szDeepDir, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), g_nsTestRun,
|
---|
1004 | "RTPathQueryInfoEx/deep/NOTHING");
|
---|
1005 | PROFILE_FN(RTPathQueryInfoEx(g_szDeepDir, &ObjInfo, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK), g_nsTestRun,
|
---|
1006 | "RTPathQueryInfoEx/deep/UNIX");
|
---|
1007 |
|
---|
1008 | /* Manytree: */
|
---|
1009 | char szPath[RTPATH_MAX];
|
---|
1010 | PROFILE_MANYTREE_FN(szPath, RTPathQueryInfoEx(szPath, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK),
|
---|
1011 | 1, g_nsTestRun, "RTPathQueryInfoEx/manytree/NOTHING");
|
---|
1012 | PROFILE_MANYTREE_FN(szPath, RTPathQueryInfoEx(szPath, &ObjInfo, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK),
|
---|
1013 | 1, g_nsTestRun, "RTPathQueryInfoEx/manytree/UNIX");
|
---|
1014 | }
|
---|
1015 |
|
---|
1016 |
|
---|
1017 | void fsPerfChmod(void)
|
---|
1018 | {
|
---|
1019 | RTTestISub("chmod");
|
---|
1020 |
|
---|
1021 | /* Non-existing files. */
|
---|
1022 | RTTESTI_CHECK_RC(RTPathSetMode(InEmptyDir(RT_STR_TUPLE("no-such-file")), 0665),
|
---|
1023 | VERR_FILE_NOT_FOUND);
|
---|
1024 | RTTESTI_CHECK_RC(RTPathSetMode(InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file")), 0665),
|
---|
1025 | FSPERF_VERR_PATH_NOT_FOUND);
|
---|
1026 | RTTESTI_CHECK_RC(RTPathSetMode(InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file")), 0665), VERR_PATH_NOT_FOUND);
|
---|
1027 |
|
---|
1028 | /* Shallow: */
|
---|
1029 | RTFILE hFile1;
|
---|
1030 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file14")),
|
---|
1031 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
1032 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
1033 |
|
---|
1034 | RTFSOBJINFO ObjInfo;
|
---|
1035 | RTTESTI_CHECK_RC(RTPathQueryInfoEx(g_szDir, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), VINF_SUCCESS);
|
---|
1036 | RTFMODE const fEvenMode = (ObjInfo.Attr.fMode & ~RTFS_UNIX_ALL_ACCESS_PERMS) | RTFS_DOS_READONLY | 0400;
|
---|
1037 | RTFMODE const fOddMode = (ObjInfo.Attr.fMode & ~(RTFS_UNIX_ALL_ACCESS_PERMS | RTFS_DOS_READONLY)) | 0640;
|
---|
1038 | PROFILE_FN(RTPathSetMode(g_szDir, iIteration & 1 ? fOddMode : fEvenMode), g_nsTestRun, "RTPathSetMode");
|
---|
1039 | RTPathSetMode(g_szDir, ObjInfo.Attr.fMode);
|
---|
1040 |
|
---|
1041 | /* Deep: */
|
---|
1042 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDeepDir(RT_STR_TUPLE("file14")),
|
---|
1043 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
1044 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
1045 |
|
---|
1046 | PROFILE_FN(RTPathSetMode(g_szDeepDir, iIteration & 1 ? fOddMode : fEvenMode), g_nsTestRun, "RTPathSetMode/deep");
|
---|
1047 | RTPathSetMode(g_szDeepDir, ObjInfo.Attr.fMode);
|
---|
1048 |
|
---|
1049 | /* Manytree: */
|
---|
1050 | char szPath[RTPATH_MAX];
|
---|
1051 | PROFILE_MANYTREE_FN(szPath, RTPathSetMode(szPath, iIteration & 1 ? fOddMode : fEvenMode), 1, g_nsTestRun,
|
---|
1052 | "RTPathSetMode/manytree");
|
---|
1053 | DO_MANYTREE_FN(szPath, RTPathSetMode(szPath, ObjInfo.Attr.fMode));
|
---|
1054 | }
|
---|
1055 |
|
---|
1056 |
|
---|
1057 | void fsPerfUtimes(void)
|
---|
1058 | {
|
---|
1059 | RTTestISub("utimes");
|
---|
1060 |
|
---|
1061 | RTTIMESPEC Time1;
|
---|
1062 | RTTimeNow(&Time1);
|
---|
1063 | RTTIMESPEC Time2 = Time1;
|
---|
1064 | RTTimeSpecSubSeconds(&Time2, 3636);
|
---|
1065 |
|
---|
1066 | /* Non-existing files. */
|
---|
1067 | RTTESTI_CHECK_RC(RTPathSetTimesEx(InEmptyDir(RT_STR_TUPLE("no-such-file")), NULL, &Time1, NULL, NULL, RTPATH_F_ON_LINK),
|
---|
1068 | VERR_FILE_NOT_FOUND);
|
---|
1069 | RTTESTI_CHECK_RC(RTPathSetTimesEx(InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file")),
|
---|
1070 | NULL, &Time1, NULL, NULL, RTPATH_F_ON_LINK),
|
---|
1071 | FSPERF_VERR_PATH_NOT_FOUND);
|
---|
1072 | RTTESTI_CHECK_RC(RTPathSetTimesEx(InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file")),
|
---|
1073 | NULL, &Time1, NULL, NULL, RTPATH_F_ON_LINK),
|
---|
1074 | VERR_PATH_NOT_FOUND);
|
---|
1075 |
|
---|
1076 | /* Shallow: */
|
---|
1077 | RTFILE hFile1;
|
---|
1078 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file15")),
|
---|
1079 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
1080 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
1081 |
|
---|
1082 | RTFSOBJINFO ObjInfo0 = {0};
|
---|
1083 | RTTESTI_CHECK_RC(RTPathQueryInfoEx(g_szDir, &ObjInfo0, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), VINF_SUCCESS);
|
---|
1084 |
|
---|
1085 | /* Modify modification time: */
|
---|
1086 | RTTESTI_CHECK_RC(RTPathSetTimesEx(g_szDir, NULL, &Time2, NULL, NULL, RTPATH_F_ON_LINK), VINF_SUCCESS);
|
---|
1087 | RTFSOBJINFO ObjInfo1;
|
---|
1088 | RTTESTI_CHECK_RC(RTPathQueryInfoEx(g_szDir, &ObjInfo1, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), VINF_SUCCESS);
|
---|
1089 | RTTESTI_CHECK((RTTimeSpecGetSeconds(&ObjInfo1.ModificationTime) >> 2) == (RTTimeSpecGetSeconds(&Time2) >> 2));
|
---|
1090 | RTTESTI_CHECK(RTTimeSpecGetNano(&ObjInfo1.AccessTime) / 1000 == RTTimeSpecGetNano(&ObjInfo0.AccessTime) / 1000 /* posix timeval */);
|
---|
1091 |
|
---|
1092 | /* Modify access time: */
|
---|
1093 | RTTESTI_CHECK_RC(RTPathSetTimesEx(g_szDir, &Time1, NULL, NULL, NULL, RTPATH_F_ON_LINK), VINF_SUCCESS);
|
---|
1094 | RTFSOBJINFO ObjInfo2 = {0};
|
---|
1095 | RTTESTI_CHECK_RC(RTPathQueryInfoEx(g_szDir, &ObjInfo2, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), VINF_SUCCESS);
|
---|
1096 | RTTESTI_CHECK((RTTimeSpecGetSeconds(&ObjInfo2.AccessTime) >> 2) == (RTTimeSpecGetSeconds(&Time1) >> 2));
|
---|
1097 | RTTESTI_CHECK(RTTimeSpecGetNano(&ObjInfo2.ModificationTime) / 1000 == RTTimeSpecGetNano(&ObjInfo1.ModificationTime) / 1000 /* posix timeval */);
|
---|
1098 |
|
---|
1099 | /* Profile shallow: */
|
---|
1100 | PROFILE_FN(RTPathSetTimesEx(g_szDir, iIteration & 1 ? &Time1 : &Time2, iIteration & 1 ? &Time2 : &Time1,
|
---|
1101 | NULL, NULL, RTPATH_F_ON_LINK),
|
---|
1102 | g_nsTestRun, "RTPathSetTimesEx");
|
---|
1103 |
|
---|
1104 | /* Deep: */
|
---|
1105 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDeepDir(RT_STR_TUPLE("file15")),
|
---|
1106 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
1107 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
1108 |
|
---|
1109 | PROFILE_FN(RTPathSetTimesEx(g_szDeepDir, iIteration & 1 ? &Time1 : &Time2, iIteration & 1 ? &Time2 : &Time1,
|
---|
1110 | NULL, NULL, RTPATH_F_ON_LINK),
|
---|
1111 | g_nsTestRun, "RTPathSetTimesEx/deep");
|
---|
1112 |
|
---|
1113 | /* Manytree: */
|
---|
1114 | char szPath[RTPATH_MAX];
|
---|
1115 | PROFILE_MANYTREE_FN(szPath, RTPathSetTimesEx(szPath, iIteration & 1 ? &Time1 : &Time2, iIteration & 1 ? &Time2 : &Time1,
|
---|
1116 | NULL, NULL, RTPATH_F_ON_LINK),
|
---|
1117 | 1, g_nsTestRun, "RTPathSetTimesEx/manytree");
|
---|
1118 | }
|
---|
1119 |
|
---|
1120 |
|
---|
1121 | DECL_FORCE_INLINE(int) fsPerfRenameMany(const char *pszFile, uint32_t iIteration)
|
---|
1122 | {
|
---|
1123 | char szRenamed[RTPATH_MAX];
|
---|
1124 | strcat(strcpy(szRenamed, pszFile), "-renamed");
|
---|
1125 | if (!(iIteration & 1))
|
---|
1126 | return RTPathRename(pszFile, szRenamed, 0);
|
---|
1127 | return RTPathRename(szRenamed, pszFile, 0);
|
---|
1128 | }
|
---|
1129 |
|
---|
1130 |
|
---|
1131 | void fsPerfRename(void)
|
---|
1132 | {
|
---|
1133 | RTTestISub("rename");
|
---|
1134 | char szPath[RTPATH_MAX];
|
---|
1135 |
|
---|
1136 | /** @todo rename directories too! */
|
---|
1137 | /** @todo check overwriting files and directoris (empty ones should work on
|
---|
1138 | * unix). */
|
---|
1139 |
|
---|
1140 | /* Non-existing files. */
|
---|
1141 | strcpy(szPath, InEmptyDir(RT_STR_TUPLE("other-no-such-file")));
|
---|
1142 | RTTESTI_CHECK_RC(RTPathRename(InEmptyDir(RT_STR_TUPLE("no-such-file")), szPath, 0), VERR_FILE_NOT_FOUND);
|
---|
1143 | strcpy(szPath, InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "other-no-such-file")));
|
---|
1144 | RTTESTI_CHECK_RC(RTPathRename(InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file")), szPath, 0),
|
---|
1145 | FSPERF_VERR_PATH_NOT_FOUND);
|
---|
1146 | strcpy(szPath, InEmptyDir(RT_STR_TUPLE("other-no-such-file")));
|
---|
1147 | RTTESTI_CHECK_RC(RTPathRename(InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file")), szPath, 0), VERR_PATH_NOT_FOUND);
|
---|
1148 |
|
---|
1149 | RTFILE hFile1;
|
---|
1150 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file16")),
|
---|
1151 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
1152 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
1153 | strcat(strcpy(szPath, g_szDir), "-no-such-dir" RTPATH_SLASH_STR "file16");
|
---|
1154 | RTTESTI_CHECK_RC(RTPathRename(szPath, g_szDir, 0), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
1155 | RTTESTI_CHECK_RC(RTPathRename(g_szDir, szPath, 0), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
1156 |
|
---|
1157 | /* Shallow: */
|
---|
1158 | strcat(strcpy(szPath, g_szDir), "-other");
|
---|
1159 | PROFILE_FN(RTPathRename(iIteration & 1 ? szPath : g_szDir, iIteration & 1 ? g_szDir : szPath, 0), g_nsTestRun, "RTPathRename");
|
---|
1160 |
|
---|
1161 | /* Deep: */
|
---|
1162 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDeepDir(RT_STR_TUPLE("file15")),
|
---|
1163 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
1164 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
1165 |
|
---|
1166 | strcat(strcpy(szPath, g_szDeepDir), "-other");
|
---|
1167 | PROFILE_FN(RTPathRename(iIteration & 1 ? szPath : g_szDeepDir, iIteration & 1 ? g_szDeepDir : szPath, 0),
|
---|
1168 | g_nsTestRun, "RTPathRename/deep");
|
---|
1169 |
|
---|
1170 | /* Manytree: */
|
---|
1171 | PROFILE_MANYTREE_FN(szPath, fsPerfRenameMany(szPath, iIteration), 2, g_nsTestRun, "RTPathRename/manytree");
|
---|
1172 | }
|
---|
1173 |
|
---|
1174 |
|
---|
1175 | DECL_FORCE_INLINE(int) fsPerfOpenClose(const char *pszDir)
|
---|
1176 | {
|
---|
1177 | RTDIR hDir;
|
---|
1178 | RTTESTI_CHECK_RC_RET(RTDirOpen(&hDir, pszDir), VINF_SUCCESS, rcCheck);
|
---|
1179 | RTTESTI_CHECK_RC(RTDirClose(hDir), VINF_SUCCESS);
|
---|
1180 | return VINF_SUCCESS;
|
---|
1181 | }
|
---|
1182 |
|
---|
1183 |
|
---|
1184 | void vsPerfDirOpen(void)
|
---|
1185 | {
|
---|
1186 | RTTestISub("dir open");
|
---|
1187 | RTDIR hDir;
|
---|
1188 |
|
---|
1189 | /*
|
---|
1190 | * Non-existing files.
|
---|
1191 | */
|
---|
1192 | RTTESTI_CHECK_RC(RTDirOpen(&hDir, InEmptyDir(RT_STR_TUPLE("no-such-file"))), VERR_FILE_NOT_FOUND);
|
---|
1193 | RTTESTI_CHECK_RC(RTDirOpen(&hDir, InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file"))), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
1194 | RTTESTI_CHECK_RC(RTDirOpen(&hDir, InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file"))), VERR_PATH_NOT_FOUND);
|
---|
1195 |
|
---|
1196 | /*
|
---|
1197 | * Check that open + close works.
|
---|
1198 | */
|
---|
1199 | g_szEmptyDir[g_cchEmptyDir] = '\0';
|
---|
1200 | RTTESTI_CHECK_RC_RETV(RTDirOpen(&hDir, g_szEmptyDir), VINF_SUCCESS);
|
---|
1201 | RTTESTI_CHECK_RC(RTDirClose(hDir), VINF_SUCCESS);
|
---|
1202 |
|
---|
1203 |
|
---|
1204 | /*
|
---|
1205 | * Profile empty dir and dir with many files.
|
---|
1206 | */
|
---|
1207 | g_szEmptyDir[g_cchEmptyDir] = '\0';
|
---|
1208 | PROFILE_FN(fsPerfOpenClose(g_szEmptyDir), g_nsTestRun, "RTDirOpen/Close empty");
|
---|
1209 | if (g_fManyFiles)
|
---|
1210 | {
|
---|
1211 | InDir(RT_STR_TUPLE("manyfiles"));
|
---|
1212 | PROFILE_FN(fsPerfOpenClose(g_szDir), g_nsTestRun, "RTDirOpen/Close manyfiles");
|
---|
1213 | }
|
---|
1214 | }
|
---|
1215 |
|
---|
1216 |
|
---|
1217 | DECL_FORCE_INLINE(int) fsPerfEnumEmpty(void)
|
---|
1218 | {
|
---|
1219 | RTDIR hDir;
|
---|
1220 | g_szEmptyDir[g_cchEmptyDir] = '\0';
|
---|
1221 | RTTESTI_CHECK_RC_RET(RTDirOpen(&hDir, g_szEmptyDir), VINF_SUCCESS, rcCheck);
|
---|
1222 |
|
---|
1223 | RTDIRENTRY Entry;
|
---|
1224 | RTTESTI_CHECK_RC(RTDirRead(hDir, &Entry, NULL), VINF_SUCCESS);
|
---|
1225 | RTTESTI_CHECK_RC(RTDirRead(hDir, &Entry, NULL), VINF_SUCCESS);
|
---|
1226 | RTTESTI_CHECK_RC(RTDirRead(hDir, &Entry, NULL), VERR_NO_MORE_FILES);
|
---|
1227 |
|
---|
1228 | RTTESTI_CHECK_RC(RTDirClose(hDir), VINF_SUCCESS);
|
---|
1229 | return VINF_SUCCESS;
|
---|
1230 | }
|
---|
1231 |
|
---|
1232 |
|
---|
1233 | DECL_FORCE_INLINE(int) fsPerfEnumManyFiles(void)
|
---|
1234 | {
|
---|
1235 | RTDIR hDir;
|
---|
1236 | RTTESTI_CHECK_RC_RET(RTDirOpen(&hDir, InDir(RT_STR_TUPLE("manyfiles"))), VINF_SUCCESS, rcCheck);
|
---|
1237 | uint32_t cLeft = g_cManyFiles + 2;
|
---|
1238 | for (;;)
|
---|
1239 | {
|
---|
1240 | RTDIRENTRY Entry;
|
---|
1241 | if (cLeft > 0)
|
---|
1242 | RTTESTI_CHECK_RC_BREAK(RTDirRead(hDir, &Entry, NULL), VINF_SUCCESS);
|
---|
1243 | else
|
---|
1244 | {
|
---|
1245 | RTTESTI_CHECK_RC(RTDirRead(hDir, &Entry, NULL), VERR_NO_MORE_FILES);
|
---|
1246 | break;
|
---|
1247 | }
|
---|
1248 | cLeft--;
|
---|
1249 | }
|
---|
1250 | RTTESTI_CHECK_RC(RTDirClose(hDir), VINF_SUCCESS);
|
---|
1251 | return VINF_SUCCESS;
|
---|
1252 | }
|
---|
1253 |
|
---|
1254 |
|
---|
1255 | void vsPerfDirEnum(void)
|
---|
1256 | {
|
---|
1257 | RTTestISub("dir enum");
|
---|
1258 | RTDIR hDir;
|
---|
1259 |
|
---|
1260 | /*
|
---|
1261 | * The empty directory.
|
---|
1262 | */
|
---|
1263 | g_szEmptyDir[g_cchEmptyDir] = '\0';
|
---|
1264 | RTTESTI_CHECK_RC_RETV(RTDirOpen(&hDir, g_szEmptyDir), VINF_SUCCESS);
|
---|
1265 |
|
---|
1266 | uint32_t fDots = 0;
|
---|
1267 | RTDIRENTRY Entry;
|
---|
1268 | RTTESTI_CHECK_RC(RTDirRead(hDir, &Entry, NULL), VINF_SUCCESS);
|
---|
1269 | RTTESTI_CHECK(RTDirEntryIsStdDotLink(&Entry));
|
---|
1270 | fDots |= RT_BIT_32(Entry.cbName - 1);
|
---|
1271 |
|
---|
1272 | RTTESTI_CHECK_RC(RTDirRead(hDir, &Entry, NULL), VINF_SUCCESS);
|
---|
1273 | RTTESTI_CHECK(RTDirEntryIsStdDotLink(&Entry));
|
---|
1274 | fDots |= RT_BIT_32(Entry.cbName - 1);
|
---|
1275 | RTTESTI_CHECK(fDots == 3);
|
---|
1276 |
|
---|
1277 | RTTESTI_CHECK_RC(RTDirRead(hDir, &Entry, NULL), VERR_NO_MORE_FILES);
|
---|
1278 |
|
---|
1279 | RTTESTI_CHECK_RC(RTDirClose(hDir), VINF_SUCCESS);
|
---|
1280 |
|
---|
1281 | /*
|
---|
1282 | * The directory with many files in it.
|
---|
1283 | */
|
---|
1284 | if (g_fManyFiles)
|
---|
1285 | {
|
---|
1286 | fDots = 0;
|
---|
1287 | uint32_t const cBitmap = RT_ALIGN_32(g_cManyFiles, 64);
|
---|
1288 | void *pvBitmap = alloca(cBitmap / 8);
|
---|
1289 | RT_BZERO(pvBitmap, cBitmap / 8);
|
---|
1290 | for (uint32_t i = g_cManyFiles; i < cBitmap; i++)
|
---|
1291 | ASMBitSet(pvBitmap, i);
|
---|
1292 |
|
---|
1293 | uint32_t cFiles = 0;
|
---|
1294 | RTTESTI_CHECK_RC_RETV(RTDirOpen(&hDir, InDir(RT_STR_TUPLE("manyfiles"))), VINF_SUCCESS);
|
---|
1295 | for (;;)
|
---|
1296 | {
|
---|
1297 | int rc = RTDirRead(hDir, &Entry, NULL);
|
---|
1298 | if (rc == VINF_SUCCESS)
|
---|
1299 | {
|
---|
1300 | if (Entry.szName[0] == '.')
|
---|
1301 | {
|
---|
1302 | if (Entry.szName[1] == '.')
|
---|
1303 | {
|
---|
1304 | RTTESTI_CHECK(!(fDots & 2));
|
---|
1305 | fDots |= 2;
|
---|
1306 | }
|
---|
1307 | else
|
---|
1308 | {
|
---|
1309 | RTTESTI_CHECK(Entry.szName[1] == '\0');
|
---|
1310 | RTTESTI_CHECK(!(fDots & 1));
|
---|
1311 | fDots |= 1;
|
---|
1312 | }
|
---|
1313 | }
|
---|
1314 | else
|
---|
1315 | {
|
---|
1316 | uint32_t iFile = UINT32_MAX;
|
---|
1317 | RTTESTI_CHECK_RC(RTStrToUInt32Full(Entry.szName, 10, &iFile), VINF_SUCCESS);
|
---|
1318 | if ( iFile < g_cManyFiles
|
---|
1319 | && !ASMBitTest(pvBitmap, iFile))
|
---|
1320 | {
|
---|
1321 | ASMBitSet(pvBitmap, iFile);
|
---|
1322 | cFiles++;
|
---|
1323 | }
|
---|
1324 | else
|
---|
1325 | RTTestFailed(g_hTest, "line %u: iFile=%u g_cManyFiles=%u\n", __LINE__, iFile, g_cManyFiles);
|
---|
1326 | }
|
---|
1327 | }
|
---|
1328 | else if (rc == VERR_NO_MORE_FILES)
|
---|
1329 | break;
|
---|
1330 | else
|
---|
1331 | {
|
---|
1332 | RTTestFailed(g_hTest, "RTDirRead failed enumerating manyfiles: %Rrc\n", rc);
|
---|
1333 | RTDirClose(hDir);
|
---|
1334 | return;
|
---|
1335 | }
|
---|
1336 | }
|
---|
1337 | RTTESTI_CHECK_RC(RTDirClose(hDir), VINF_SUCCESS);
|
---|
1338 | RTTESTI_CHECK(fDots == 3);
|
---|
1339 | RTTESTI_CHECK(cFiles == g_cManyFiles);
|
---|
1340 | RTTESTI_CHECK(ASMMemIsAllU8(pvBitmap, cBitmap / 8, 0xff));
|
---|
1341 | }
|
---|
1342 |
|
---|
1343 | /*
|
---|
1344 | * Profile.
|
---|
1345 | */
|
---|
1346 | PROFILE_FN(fsPerfEnumEmpty(),g_nsTestRun, "RTDirOpen/Read/Close empty");
|
---|
1347 | if (g_fManyFiles)
|
---|
1348 | PROFILE_FN(fsPerfEnumManyFiles(), g_nsTestRun, "RTDirOpen/Read/Close manyfiles");
|
---|
1349 | }
|
---|
1350 |
|
---|
1351 |
|
---|
1352 | void fsPerfMkRmDir(void)
|
---|
1353 | {
|
---|
1354 | RTTestISub("mkdir/rmdir");
|
---|
1355 |
|
---|
1356 | /* Non-existing directories: */
|
---|
1357 | RTTESTI_CHECK_RC(RTDirRemove(InEmptyDir(RT_STR_TUPLE("no-such-dir"))), VERR_FILE_NOT_FOUND);
|
---|
1358 | RTTESTI_CHECK_RC(RTDirRemove(InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file"))), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
1359 | RTTESTI_CHECK_RC(RTDirRemove(InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file"))), VERR_PATH_NOT_FOUND);
|
---|
1360 | RTTESTI_CHECK_RC(RTDirCreate(InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file")), 0755, 0), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
1361 | RTTESTI_CHECK_RC(RTDirCreate(InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file")), 0755, 0), VERR_PATH_NOT_FOUND);
|
---|
1362 |
|
---|
1363 | /** @todo check what happens if non-final path component isn't a directory. unix
|
---|
1364 | * should return ENOTDIR and IPRT translates that to VERR_PATH_NOT_FOUND.
|
---|
1365 | * Curious what happens on windows. */
|
---|
1366 |
|
---|
1367 | /* Already existing directories and files: */
|
---|
1368 | RTTESTI_CHECK_RC(RTDirCreate(InEmptyDir(RT_STR_TUPLE(".")), 0755, 0), VERR_ALREADY_EXISTS);
|
---|
1369 | RTTESTI_CHECK_RC(RTDirCreate(InEmptyDir(RT_STR_TUPLE("..")), 0755, 0), VERR_ALREADY_EXISTS);
|
---|
1370 |
|
---|
1371 | /* Remove directory with subdirectories: */
|
---|
1372 | #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
|
---|
1373 | RTTESTI_CHECK_RC(RTDirRemove(InDir(RT_STR_TUPLE("."))), VERR_DIR_NOT_EMPTY);
|
---|
1374 | #else
|
---|
1375 | RTTESTI_CHECK_RC(RTDirRemove(InDir(RT_STR_TUPLE("."))), VERR_INVALID_PARAMETER); /* EINVAL for '.' */
|
---|
1376 | #endif
|
---|
1377 | #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
|
---|
1378 | int rc = RTDirRemove(InDir(RT_STR_TUPLE("..")));
|
---|
1379 | # ifdef RT_OS_WINDOWS
|
---|
1380 | if (rc != VERR_DIR_NOT_EMPTY /*ntfs root*/ && rc != VERR_SHARING_VIOLATION /*ntfs weird*/)
|
---|
1381 | RTTestIFailed("RTDirRemove(%s) -> %Rrc, expected VERR_DIR_NOT_EMPTY or VERR_SHARING_VIOLATION", g_szDir, rc);
|
---|
1382 | # else
|
---|
1383 | if (rc != VERR_DIR_NOT_EMPTY && rc != VERR_RESOURCE_BUSY /*IPRT/kLIBC fun*/)
|
---|
1384 | RTTestIFailed("RTDirRemove(%s) -> %Rrc, expected VERR_DIR_NOT_EMPTY or VERR_RESOURCE_BUSY", g_szDir, rc);
|
---|
1385 |
|
---|
1386 | APIRET orc;
|
---|
1387 | RTTESTI_CHECK_MSG((orc = DosDelete((PCSZ)InEmptyDir(RT_STR_TUPLE(".")))) == ERROR_ACCESS_DENIED,
|
---|
1388 | ("DosDelete(%s) -> %u, expected %u\n", g_szEmptyDir, orc, ERROR_ACCESS_DENIED));
|
---|
1389 | RTTESTI_CHECK_MSG((orc = DosDelete((PCSZ)InEmptyDir(RT_STR_TUPLE("..")))) == ERROR_ACCESS_DENIED,
|
---|
1390 | ("DosDelete(%s) -> %u, expected %u\n", g_szEmptyDir, orc, ERROR_ACCESS_DENIED));
|
---|
1391 | RTTESTI_CHECK_MSG((orc = DosDelete((PCSZ)InEmptyDir(RT_STR_TUPLE("")))) == ERROR_PATH_NOT_FOUND, /* a little weird (fsrouter) */
|
---|
1392 | ("DosDelete(%s) -> %u, expected %u\n", g_szEmptyDir, orc, ERROR_PATH_NOT_FOUND));
|
---|
1393 |
|
---|
1394 | # endif
|
---|
1395 | #else
|
---|
1396 | RTTESTI_CHECK_RC(RTDirRemove(InDir(RT_STR_TUPLE(".."))), VERR_DIR_NOT_EMPTY);
|
---|
1397 | #endif
|
---|
1398 | RTTESTI_CHECK_RC(RTDirRemove(InDir(RT_STR_TUPLE(""))), VERR_DIR_NOT_EMPTY);
|
---|
1399 |
|
---|
1400 | /* Create a directory and remove it: */
|
---|
1401 | RTTESTI_CHECK_RC(RTDirCreate(InDir(RT_STR_TUPLE("subdir-1")), 0755, 0), VINF_SUCCESS);
|
---|
1402 | RTTESTI_CHECK_RC(RTDirRemove(g_szDir), VINF_SUCCESS);
|
---|
1403 |
|
---|
1404 | /* Create a file and try remove it or create a directory with the same name: */
|
---|
1405 | RTFILE hFile1;
|
---|
1406 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file18")),
|
---|
1407 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
1408 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
1409 | RTTESTI_CHECK_RC(RTDirRemove(g_szDir), VERR_NOT_A_DIRECTORY);
|
---|
1410 | RTTESTI_CHECK_RC(RTDirCreate(g_szDir, 0755, 0), VERR_ALREADY_EXISTS);
|
---|
1411 | RTTESTI_CHECK_RC(RTDirCreate(InDir(RT_STR_TUPLE("file18" RTPATH_SLASH_STR "subdir")), 0755, 0), VERR_PATH_NOT_FOUND);
|
---|
1412 |
|
---|
1413 | /*
|
---|
1414 | * Profile alternately creating and removing a bunch of directories.
|
---|
1415 | */
|
---|
1416 | RTTESTI_CHECK_RC_RETV(RTDirCreate(InDir(RT_STR_TUPLE("subdir-2")), 0755, 0), VINF_SUCCESS);
|
---|
1417 | size_t cchDir = strlen(g_szDir);
|
---|
1418 | g_szDir[cchDir++] = RTPATH_SLASH;
|
---|
1419 | g_szDir[cchDir++] = 's';
|
---|
1420 |
|
---|
1421 | uint32_t cCreated = 0;
|
---|
1422 | uint64_t nsCreate = 0;
|
---|
1423 | uint64_t nsRemove = 0;
|
---|
1424 | for (;;)
|
---|
1425 | {
|
---|
1426 | /* Create a bunch: */
|
---|
1427 | uint64_t nsStart = RTTimeNanoTS();
|
---|
1428 | for (uint32_t i = 0; i < 998; i++)
|
---|
1429 | {
|
---|
1430 | RTStrFormatU32(&g_szDir[cchDir], sizeof(g_szDir) - cchDir, i, 10, 3, 3, RTSTR_F_ZEROPAD);
|
---|
1431 | RTTESTI_CHECK_RC_RETV(RTDirCreate(g_szDir, 0755, 0), VINF_SUCCESS);
|
---|
1432 | }
|
---|
1433 | nsCreate += RTTimeNanoTS() - nsStart;
|
---|
1434 | cCreated += 998;
|
---|
1435 |
|
---|
1436 | /* Remove the bunch: */
|
---|
1437 | nsStart = RTTimeNanoTS();
|
---|
1438 | for (uint32_t i = 0; i < 998; i++)
|
---|
1439 | {
|
---|
1440 | RTStrFormatU32(&g_szDir[cchDir], sizeof(g_szDir) - cchDir, i, 10, 3, 3, RTSTR_F_ZEROPAD);
|
---|
1441 | RTTESTI_CHECK_RC_RETV(RTDirRemove(g_szDir), VINF_SUCCESS);
|
---|
1442 | }
|
---|
1443 | nsRemove = RTTimeNanoTS() - nsStart;
|
---|
1444 |
|
---|
1445 | /* Check if we got time for another round: */
|
---|
1446 | if ( ( nsRemove >= g_nsTestRun
|
---|
1447 | && nsCreate >= g_nsTestRun)
|
---|
1448 | || nsCreate + nsRemove >= g_nsTestRun * 3)
|
---|
1449 | break;
|
---|
1450 | }
|
---|
1451 | RTTestIValue("RTDirCreate", nsCreate / cCreated, RTTESTUNIT_NS_PER_OCCURRENCE);
|
---|
1452 | RTTestIValue("RTDirRemove", nsRemove / cCreated, RTTESTUNIT_NS_PER_OCCURRENCE);
|
---|
1453 | }
|
---|
1454 |
|
---|
1455 |
|
---|
1456 | void fsPerfStatVfs(void)
|
---|
1457 | {
|
---|
1458 | RTTestISub("statvfs");
|
---|
1459 |
|
---|
1460 | g_szEmptyDir[g_cchEmptyDir] = '\0';
|
---|
1461 | RTFOFF cbTotal;
|
---|
1462 | RTFOFF cbFree;
|
---|
1463 | uint32_t cbBlock;
|
---|
1464 | uint32_t cbSector;
|
---|
1465 | RTTESTI_CHECK_RC(RTFsQuerySizes(g_szEmptyDir, &cbTotal, &cbFree, &cbBlock, &cbSector), VINF_SUCCESS);
|
---|
1466 |
|
---|
1467 | uint32_t uSerial;
|
---|
1468 | RTTESTI_CHECK_RC(RTFsQuerySerial(g_szEmptyDir, &uSerial), VINF_SUCCESS);
|
---|
1469 |
|
---|
1470 | RTFSPROPERTIES Props;
|
---|
1471 | RTTESTI_CHECK_RC(RTFsQueryProperties(g_szEmptyDir, &Props), VINF_SUCCESS);
|
---|
1472 |
|
---|
1473 | RTFSTYPE enmType;
|
---|
1474 | RTTESTI_CHECK_RC(RTFsQueryType(g_szEmptyDir, &enmType), VINF_SUCCESS);
|
---|
1475 |
|
---|
1476 | g_szDeepDir[g_cchDeepDir] = '\0';
|
---|
1477 | PROFILE_FN(RTFsQuerySizes(g_szEmptyDir, &cbTotal, &cbFree, &cbBlock, &cbSector), g_nsTestRun, "RTFsQuerySize/empty");
|
---|
1478 | PROFILE_FN(RTFsQuerySizes(g_szDeepDir, &cbTotal, &cbFree, &cbBlock, &cbSector), g_nsTestRun, "RTFsQuerySize/deep");
|
---|
1479 | }
|
---|
1480 |
|
---|
1481 |
|
---|
1482 | void fsPerfRm(void)
|
---|
1483 | {
|
---|
1484 | RTTestISub("rm");
|
---|
1485 |
|
---|
1486 | /* Non-existing files. */
|
---|
1487 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE("no-such-file"))), VERR_FILE_NOT_FOUND);
|
---|
1488 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file"))), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
1489 | RTTESTI_CHECK_RC(RTFileDelete(InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file"))), VERR_PATH_NOT_FOUND);
|
---|
1490 |
|
---|
1491 | /* Directories: */
|
---|
1492 | #if defined(RT_OS_WINDOWS)
|
---|
1493 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE("."))), VERR_ACCESS_DENIED);
|
---|
1494 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE(".."))), VERR_ACCESS_DENIED);
|
---|
1495 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE(""))), VERR_ACCESS_DENIED);
|
---|
1496 | #elif defined(RT_OS_DARWIN) /* unlink() on xnu 16.7.0 is behaviour totally werid: */
|
---|
1497 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE("."))), VERR_INVALID_PARAMETER);
|
---|
1498 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE(".."))), VINF_SUCCESS /*WTF?!?*/);
|
---|
1499 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE(""))), VERR_ACCESS_DENIED);
|
---|
1500 | #elif defined(RT_OS_OS2) /* OS/2 has a busted unlink, it think it should remove directories too. */
|
---|
1501 | RTTESTI_CHECK_RC(RTFileDelete(InDir(RT_STR_TUPLE("."))), VERR_DIR_NOT_EMPTY);
|
---|
1502 | int rc = RTFileDelete(InDir(RT_STR_TUPLE("..")));
|
---|
1503 | if (rc != VERR_DIR_NOT_EMPTY && rc != VERR_FILE_NOT_FOUND && rc != VERR_RESOURCE_BUSY)
|
---|
1504 | RTTestIFailed("RTFileDelete(%s) -> %Rrc, expected VERR_DIR_NOT_EMPTY or VERR_FILE_NOT_FOUND or VERR_RESOURCE_BUSY", g_szDir, rc);
|
---|
1505 | RTTESTI_CHECK_RC(RTFileDelete(InDir(RT_STR_TUPLE(""))), VERR_DIR_NOT_EMPTY);
|
---|
1506 | APIRET orc;
|
---|
1507 | RTTESTI_CHECK_MSG((orc = DosDelete((PCSZ)InEmptyDir(RT_STR_TUPLE(".")))) == ERROR_ACCESS_DENIED,
|
---|
1508 | ("DosDelete(%s) -> %u, expected %u\n", g_szEmptyDir, orc, ERROR_ACCESS_DENIED));
|
---|
1509 | RTTESTI_CHECK_MSG((orc = DosDelete((PCSZ)InEmptyDir(RT_STR_TUPLE("..")))) == ERROR_ACCESS_DENIED,
|
---|
1510 | ("DosDelete(%s) -> %u, expected %u\n", g_szEmptyDir, orc, ERROR_ACCESS_DENIED));
|
---|
1511 | RTTESTI_CHECK_MSG((orc = DosDelete((PCSZ)InEmptyDir(RT_STR_TUPLE("")))) == ERROR_PATH_NOT_FOUND,
|
---|
1512 | ("DosDelete(%s) -> %u, expected %u\n", g_szEmptyDir, orc, ERROR_PATH_NOT_FOUND)); /* hpfs+jfs; weird. */
|
---|
1513 |
|
---|
1514 | #else
|
---|
1515 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE("."))), VERR_IS_A_DIRECTORY);
|
---|
1516 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE(".."))), VERR_IS_A_DIRECTORY);
|
---|
1517 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE(""))), VERR_IS_A_DIRECTORY);
|
---|
1518 | #endif
|
---|
1519 |
|
---|
1520 | /* Shallow: */
|
---|
1521 | RTFILE hFile1;
|
---|
1522 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file19")),
|
---|
1523 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
1524 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
1525 | RTTESTI_CHECK_RC(RTFileDelete(g_szDir), VINF_SUCCESS);
|
---|
1526 | RTTESTI_CHECK_RC(RTFileDelete(g_szDir), VERR_FILE_NOT_FOUND);
|
---|
1527 |
|
---|
1528 | if (g_fManyFiles)
|
---|
1529 | {
|
---|
1530 | /*
|
---|
1531 | * Profile the deletion of the manyfiles content.
|
---|
1532 | */
|
---|
1533 | {
|
---|
1534 | InDir(RT_STR_TUPLE("manyfiles" RTPATH_SLASH_STR));
|
---|
1535 | size_t const offFilename = strlen(g_szDir);
|
---|
1536 | fsPerfYield();
|
---|
1537 | uint64_t const nsStart = RTTimeNanoTS();
|
---|
1538 | for (uint32_t i = 0; i < g_cManyFiles; i++)
|
---|
1539 | {
|
---|
1540 | RTStrFormatU32(&g_szDir[offFilename], sizeof(g_szDir) - offFilename, i, 10, 5, 5, RTSTR_F_ZEROPAD);
|
---|
1541 | RTTESTI_CHECK_RC_RETV(RTFileDelete(g_szDir), VINF_SUCCESS);
|
---|
1542 | }
|
---|
1543 | uint64_t const cNsElapsed = RTTimeNanoTS() - nsStart;
|
---|
1544 | RTTestIValueF(cNsElapsed, RTTESTUNIT_NS, "Deleted %u empty files from a single directory", g_cManyFiles);
|
---|
1545 | RTTestIValueF(cNsElapsed / g_cManyFiles, RTTESTUNIT_NS_PER_OCCURRENCE, "Delete file (single dir)");
|
---|
1546 | }
|
---|
1547 |
|
---|
1548 | /*
|
---|
1549 | * Ditto for the manytree.
|
---|
1550 | */
|
---|
1551 | {
|
---|
1552 | char szPath[RTPATH_MAX];
|
---|
1553 | uint64_t const nsStart = RTTimeNanoTS();
|
---|
1554 | DO_MANYTREE_FN(szPath, RTTESTI_CHECK_RC_RETV(RTFileDelete(szPath), VINF_SUCCESS));
|
---|
1555 | uint64_t const cNsElapsed = RTTimeNanoTS() - nsStart;
|
---|
1556 | RTTestIValueF(cNsElapsed, RTTESTUNIT_NS, "Deleted %u empty files in tree", g_cManyTreeFiles);
|
---|
1557 | RTTestIValueF(cNsElapsed / g_cManyTreeFiles, RTTESTUNIT_NS_PER_OCCURRENCE, "Delete file (tree)");
|
---|
1558 | }
|
---|
1559 | }
|
---|
1560 | }
|
---|
1561 |
|
---|
1562 |
|
---|
1563 | void fsPerfChSize(void)
|
---|
1564 | {
|
---|
1565 | RTTestISub("chsize");
|
---|
1566 |
|
---|
1567 | /*
|
---|
1568 | * We need some free space to perform this test.
|
---|
1569 | */
|
---|
1570 | g_szDir[g_cchDir] = '\0';
|
---|
1571 | RTFOFF cbFree = 0;
|
---|
1572 | RTTESTI_CHECK_RC_RETV(RTFsQuerySizes(g_szDir, NULL, &cbFree, NULL, NULL), VINF_SUCCESS);
|
---|
1573 | if (cbFree < _1M)
|
---|
1574 | {
|
---|
1575 | RTTestSkipped(g_hTest, "Insufficent free space: %'RU64 bytes, requires >= 1MB", cbFree);
|
---|
1576 | return;
|
---|
1577 | }
|
---|
1578 |
|
---|
1579 | /*
|
---|
1580 | * Create a file and play around with it's size.
|
---|
1581 | * We let the current file position follow the end position as we make changes.
|
---|
1582 | */
|
---|
1583 | RTFILE hFile1;
|
---|
1584 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file20")),
|
---|
1585 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_READWRITE), VINF_SUCCESS);
|
---|
1586 | uint64_t cbFile = UINT64_MAX;
|
---|
1587 | RTTESTI_CHECK_RC(RTFileGetSize(hFile1, &cbFile), VINF_SUCCESS);
|
---|
1588 | RTTESTI_CHECK(cbFile == 0);
|
---|
1589 |
|
---|
1590 | uint8_t abBuf[4096];
|
---|
1591 | static uint64_t const s_acbChanges[] =
|
---|
1592 | {
|
---|
1593 | 1023, 1024, 1024, 1025, 8192, 11111, _1M, _8M, _8M,
|
---|
1594 | _4M, _2M + 1, _1M - 1, 65537, 65536, 32768, 8000, 7999, 7998, 1024, 1, 0
|
---|
1595 | };
|
---|
1596 | uint64_t cbOld = 0;
|
---|
1597 | for (unsigned i = 0; i < RT_ELEMENTS(s_acbChanges); i++)
|
---|
1598 | {
|
---|
1599 | uint64_t cbNew = s_acbChanges[i];
|
---|
1600 | if (cbNew + _64K >= (uint64_t)cbFree)
|
---|
1601 | continue;
|
---|
1602 |
|
---|
1603 | RTTESTI_CHECK_RC(RTFileSetSize(hFile1, cbNew), VINF_SUCCESS);
|
---|
1604 | RTTESTI_CHECK_RC(RTFileGetSize(hFile1, &cbFile), VINF_SUCCESS);
|
---|
1605 | RTTESTI_CHECK_MSG(cbFile == cbNew, ("cbFile=%#RX64 cbNew=%#RX64\n", cbFile, cbNew));
|
---|
1606 |
|
---|
1607 | if (cbNew > cbOld)
|
---|
1608 | {
|
---|
1609 | /* Check that the extension is all zeroed: */
|
---|
1610 | uint64_t cbLeft = cbNew - cbOld;
|
---|
1611 | while (cbLeft > 0)
|
---|
1612 | {
|
---|
1613 | memset(abBuf, 0xff, sizeof(abBuf));
|
---|
1614 | size_t cbToRead = sizeof(abBuf);
|
---|
1615 | if (cbToRead > cbLeft)
|
---|
1616 | cbToRead = (size_t)cbLeft;
|
---|
1617 | RTTESTI_CHECK_RC(RTFileRead(hFile1, abBuf, cbToRead, NULL), VINF_SUCCESS);
|
---|
1618 | RTTESTI_CHECK(ASMMemIsZero(abBuf, cbToRead));
|
---|
1619 | cbLeft -= cbToRead;
|
---|
1620 | }
|
---|
1621 | }
|
---|
1622 | else
|
---|
1623 | {
|
---|
1624 | /* Check that reading fails with EOF because current position is now beyond the end: */
|
---|
1625 | RTTESTI_CHECK_RC(RTFileRead(hFile1, abBuf, 1, NULL), VERR_EOF);
|
---|
1626 |
|
---|
1627 | /* Keep current position at the end of the file: */
|
---|
1628 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, cbNew, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
1629 | }
|
---|
1630 | cbOld = cbNew;
|
---|
1631 | }
|
---|
1632 |
|
---|
1633 | /*
|
---|
1634 | * Profile just the file setting operation itself, keeping the changes within
|
---|
1635 | * an allocation unit to avoid needing to adjust the actual (host) FS allocation.
|
---|
1636 | * ASSUMES allocation unit >= 512 and power of two.
|
---|
1637 | */
|
---|
1638 | RTTESTI_CHECK_RC(RTFileSetSize(hFile1, _64K), VINF_SUCCESS);
|
---|
1639 | PROFILE_FN(RTFileSetSize(hFile1, _64K - (iIteration & 255) - 128), g_nsTestRun, "RTFileSetSize/noalloc");
|
---|
1640 |
|
---|
1641 | RTTESTI_CHECK_RC(RTFileSetSize(hFile1, 0), VINF_SUCCESS);
|
---|
1642 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
1643 | RTTESTI_CHECK_RC(RTFileDelete(g_szDir), VINF_SUCCESS);
|
---|
1644 | }
|
---|
1645 |
|
---|
1646 |
|
---|
1647 | int fsPerfIoPrepFile(RTFILE hFile1, uint64_t cbFile, uint8_t **ppbFree)
|
---|
1648 | {
|
---|
1649 | /*
|
---|
1650 | * Seek to the end - 4K and write the last 4K.
|
---|
1651 | * This should have the effect of filling the whole file with zeros.
|
---|
1652 | */
|
---|
1653 | RTTESTI_CHECK_RC_RET(RTFileSeek(hFile1, cbFile - _4K, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS, rcCheck);
|
---|
1654 | RTTESTI_CHECK_RC_RET(RTFileWrite(hFile1, g_abRTZero4K, _4K, NULL), VINF_SUCCESS, rcCheck);
|
---|
1655 |
|
---|
1656 | /*
|
---|
1657 | * Check that the space we searched across actually is zero filled.
|
---|
1658 | */
|
---|
1659 | RTTESTI_CHECK_RC_RET(RTFileSeek(hFile1, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS, rcCheck);
|
---|
1660 | size_t cbBuf = _1M;
|
---|
1661 | uint8_t *pbBuf = *ppbFree = (uint8_t *)RTMemAlloc(cbBuf);
|
---|
1662 | RTTESTI_CHECK_RET(pbBuf != NULL, VERR_NO_MEMORY);
|
---|
1663 | uint64_t cbLeft = cbFile;
|
---|
1664 | while (cbLeft > 0)
|
---|
1665 | {
|
---|
1666 | size_t cbToRead = cbBuf;
|
---|
1667 | if (cbToRead > cbLeft)
|
---|
1668 | cbToRead = (size_t)cbLeft;
|
---|
1669 | pbBuf[cbToRead] = 0xff;
|
---|
1670 |
|
---|
1671 | RTTESTI_CHECK_RC_RET(RTFileRead(hFile1, pbBuf, cbToRead, NULL), VINF_SUCCESS, rcCheck);
|
---|
1672 | RTTESTI_CHECK_RET(ASMMemIsZero(pbBuf, cbToRead), VERR_MISMATCH);
|
---|
1673 |
|
---|
1674 | cbLeft -= cbToRead;
|
---|
1675 | }
|
---|
1676 |
|
---|
1677 | /*
|
---|
1678 | * Fill the file with 0xf6 and insert offset markers with 1KB intervals.
|
---|
1679 | */
|
---|
1680 | RTTESTI_CHECK_RC_RET(RTFileSeek(hFile1, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS, rcCheck);
|
---|
1681 | memset(pbBuf, 0xf6, cbBuf);
|
---|
1682 | cbLeft = cbFile;
|
---|
1683 | uint64_t off = 0;
|
---|
1684 | while (cbLeft > 0)
|
---|
1685 | {
|
---|
1686 | Assert(!(off & (_1K - 1)));
|
---|
1687 | Assert(!(cbBuf & (_1K - 1)));
|
---|
1688 | for (size_t offBuf = 0; offBuf < cbBuf; offBuf += _1K, off += _1K)
|
---|
1689 | *(uint64_t *)&pbBuf[offBuf] = off;
|
---|
1690 |
|
---|
1691 | size_t cbToWrite = cbBuf;
|
---|
1692 | if (cbToWrite > cbLeft)
|
---|
1693 | cbToWrite = (size_t)cbLeft;
|
---|
1694 |
|
---|
1695 | RTTESTI_CHECK_RC_RET(RTFileWrite(hFile1, pbBuf, cbToWrite, NULL), VINF_SUCCESS, rcCheck);
|
---|
1696 |
|
---|
1697 | cbLeft -= cbToWrite;
|
---|
1698 | }
|
---|
1699 |
|
---|
1700 | return VINF_SUCCESS;
|
---|
1701 | }
|
---|
1702 |
|
---|
1703 |
|
---|
1704 | /**
|
---|
1705 | * Checks the content read from the file fsPerfIoPrepFile() prepared.
|
---|
1706 | */
|
---|
1707 | bool fsPerfCheckReadBuf(unsigned uLineNo, uint64_t off, uint8_t const *pbBuf, size_t cbBuf, uint8_t bFiller = 0xf6)
|
---|
1708 | {
|
---|
1709 | uint32_t cMismatches = 0;
|
---|
1710 | size_t offBuf = 0;
|
---|
1711 | uint32_t offBlock = (uint32_t)(off & (_1K - 1));
|
---|
1712 | while (offBuf < cbBuf)
|
---|
1713 | {
|
---|
1714 | /*
|
---|
1715 | * Check the offset marker:
|
---|
1716 | */
|
---|
1717 | if (offBlock < sizeof(uint64_t))
|
---|
1718 | {
|
---|
1719 | RTUINT64U uMarker;
|
---|
1720 | uMarker.u = off + offBuf - offBlock;
|
---|
1721 | unsigned offMarker = offBlock & (sizeof(uint64_t) - 1);
|
---|
1722 | while (offMarker < sizeof(uint64_t) && offBuf < cbBuf)
|
---|
1723 | {
|
---|
1724 | if (uMarker.au8[offMarker] != pbBuf[offBuf])
|
---|
1725 | {
|
---|
1726 | RTTestIFailed("%u: Mismatch at buffer/file offset %#zx/%#RX64: %#x, expected %#x",
|
---|
1727 | uLineNo, offBuf, off + offBuf, pbBuf[offBuf], uMarker.au8[offMarker]);
|
---|
1728 | if (cMismatches++ > 32)
|
---|
1729 | return false;
|
---|
1730 | }
|
---|
1731 | offMarker++;
|
---|
1732 | offBuf++;
|
---|
1733 | }
|
---|
1734 | offBlock = sizeof(uint64_t);
|
---|
1735 | }
|
---|
1736 |
|
---|
1737 | /*
|
---|
1738 | * Check the filling:
|
---|
1739 | */
|
---|
1740 | size_t cbFilling = RT_MIN(_1K - offBlock, cbBuf - offBuf);
|
---|
1741 | if ( cbFilling == 0
|
---|
1742 | || ASMMemIsAllU8(&pbBuf[offBuf], cbFilling, bFiller))
|
---|
1743 | offBuf += cbFilling;
|
---|
1744 | else
|
---|
1745 | {
|
---|
1746 | /* Some mismatch, locate it/them: */
|
---|
1747 | while (cbFilling > 0 && offBuf < cbBuf)
|
---|
1748 | {
|
---|
1749 | if (pbBuf[offBuf] != bFiller)
|
---|
1750 | {
|
---|
1751 | RTTestIFailed("%u: Mismatch at buffer/file offset %#zx/%#RX64: %#x, expected %#04x",
|
---|
1752 | uLineNo, offBuf, off + offBuf, pbBuf[offBuf], bFiller);
|
---|
1753 | if (cMismatches++ > 32)
|
---|
1754 | return false;
|
---|
1755 | }
|
---|
1756 | offBuf++;
|
---|
1757 | cbFilling--;
|
---|
1758 | }
|
---|
1759 | }
|
---|
1760 | offBlock = 0;
|
---|
1761 | }
|
---|
1762 | return cMismatches == 0;
|
---|
1763 | }
|
---|
1764 |
|
---|
1765 |
|
---|
1766 | /**
|
---|
1767 | * Sets up write buffer with offset markers and fillers.
|
---|
1768 | */
|
---|
1769 | void fsPerfFillWriteBuf(uint64_t off, uint8_t *pbBuf, size_t cbBuf, uint8_t bFiller = 0xf6)
|
---|
1770 | {
|
---|
1771 | uint32_t offBlock = (uint32_t)(off & (_1K - 1));
|
---|
1772 | while (cbBuf > 0)
|
---|
1773 | {
|
---|
1774 | /* The marker. */
|
---|
1775 | if (offBlock < sizeof(uint64_t))
|
---|
1776 | {
|
---|
1777 | RTUINT64U uMarker;
|
---|
1778 | uMarker.u = off + offBlock;
|
---|
1779 | if (cbBuf > sizeof(uMarker) - offBlock)
|
---|
1780 | {
|
---|
1781 | memcpy(pbBuf, &uMarker.au8[offBlock], sizeof(uMarker) - offBlock);
|
---|
1782 | pbBuf += sizeof(uMarker) - offBlock;
|
---|
1783 | cbBuf -= sizeof(uMarker) - offBlock;
|
---|
1784 | off += sizeof(uMarker) - offBlock;
|
---|
1785 | }
|
---|
1786 | else
|
---|
1787 | {
|
---|
1788 | memcpy(pbBuf, &uMarker.au8[offBlock], cbBuf);
|
---|
1789 | return;
|
---|
1790 | }
|
---|
1791 | offBlock = sizeof(uint64_t);
|
---|
1792 | }
|
---|
1793 |
|
---|
1794 | /* Do the filling. */
|
---|
1795 | size_t cbFilling = RT_MIN(_1K - offBlock, cbBuf);
|
---|
1796 | memset(pbBuf, bFiller, cbFilling);
|
---|
1797 | pbBuf += cbFilling;
|
---|
1798 | cbBuf -= cbFilling;
|
---|
1799 | off += cbFilling;
|
---|
1800 |
|
---|
1801 | offBlock = 0;
|
---|
1802 | }
|
---|
1803 | }
|
---|
1804 |
|
---|
1805 |
|
---|
1806 |
|
---|
1807 | void fsPerfIoSeek(RTFILE hFile1, uint64_t cbFile)
|
---|
1808 | {
|
---|
1809 | /*
|
---|
1810 | * Do a bunch of search tests, most which are random.
|
---|
1811 | */
|
---|
1812 | struct
|
---|
1813 | {
|
---|
1814 | int rc;
|
---|
1815 | uint32_t uMethod;
|
---|
1816 | int64_t offSeek;
|
---|
1817 | uint64_t offActual;
|
---|
1818 |
|
---|
1819 | } aSeeks[9 + 64] =
|
---|
1820 | {
|
---|
1821 | { VINF_SUCCESS, RTFILE_SEEK_BEGIN, 0, 0 },
|
---|
1822 | { VINF_SUCCESS, RTFILE_SEEK_CURRENT, 0, 0 },
|
---|
1823 | { VINF_SUCCESS, RTFILE_SEEK_END, 0, cbFile },
|
---|
1824 | { VINF_SUCCESS, RTFILE_SEEK_CURRENT, -4096, cbFile - 4096 },
|
---|
1825 | { VINF_SUCCESS, RTFILE_SEEK_CURRENT, 4096 - (int64_t)cbFile, 0 },
|
---|
1826 | { VINF_SUCCESS, RTFILE_SEEK_END, -(int64_t)cbFile/2, cbFile / 2 + (cbFile & 1) },
|
---|
1827 | { VINF_SUCCESS, RTFILE_SEEK_CURRENT, -(int64_t)cbFile/2, 0 },
|
---|
1828 | #if defined(RT_OS_WINDOWS)
|
---|
1829 | { VERR_NEGATIVE_SEEK, RTFILE_SEEK_CURRENT, -1, 0 },
|
---|
1830 | #else
|
---|
1831 | { VERR_INVALID_PARAMETER, RTFILE_SEEK_CURRENT, -1, 0 },
|
---|
1832 | #endif
|
---|
1833 | { VINF_SUCCESS, RTFILE_SEEK_CURRENT, 0, 0 },
|
---|
1834 | };
|
---|
1835 |
|
---|
1836 | uint64_t offActual = 0;
|
---|
1837 | for (unsigned i = 9; i < RT_ELEMENTS(aSeeks); i++)
|
---|
1838 | {
|
---|
1839 | switch (RTRandU32Ex(RTFILE_SEEK_BEGIN, RTFILE_SEEK_END))
|
---|
1840 | {
|
---|
1841 | default: AssertFailedBreak();
|
---|
1842 | case RTFILE_SEEK_BEGIN:
|
---|
1843 | aSeeks[i].uMethod = RTFILE_SEEK_BEGIN;
|
---|
1844 | aSeeks[i].rc = VINF_SUCCESS;
|
---|
1845 | aSeeks[i].offSeek = RTRandU64Ex(0, cbFile + cbFile / 8);
|
---|
1846 | aSeeks[i].offActual = offActual = aSeeks[i].offSeek;
|
---|
1847 | break;
|
---|
1848 |
|
---|
1849 | case RTFILE_SEEK_CURRENT:
|
---|
1850 | aSeeks[i].uMethod = RTFILE_SEEK_CURRENT;
|
---|
1851 | aSeeks[i].rc = VINF_SUCCESS;
|
---|
1852 | aSeeks[i].offSeek = (int64_t)RTRandU64Ex(0, cbFile + cbFile / 8) - (int64_t)offActual;
|
---|
1853 | aSeeks[i].offActual = offActual += aSeeks[i].offSeek;
|
---|
1854 | break;
|
---|
1855 |
|
---|
1856 | case RTFILE_SEEK_END:
|
---|
1857 | aSeeks[i].uMethod = RTFILE_SEEK_END;
|
---|
1858 | aSeeks[i].rc = VINF_SUCCESS;
|
---|
1859 | aSeeks[i].offSeek = -(int64_t)RTRandU64Ex(0, cbFile);
|
---|
1860 | aSeeks[i].offActual = offActual = cbFile + aSeeks[i].offSeek;
|
---|
1861 | break;
|
---|
1862 | }
|
---|
1863 | }
|
---|
1864 |
|
---|
1865 | for (unsigned iDoReadCheck = 0; iDoReadCheck < 2; iDoReadCheck++)
|
---|
1866 | {
|
---|
1867 | for (uint32_t i = 0; i < RT_ELEMENTS(aSeeks); i++)
|
---|
1868 | {
|
---|
1869 | offActual = UINT64_MAX;
|
---|
1870 | int rc = RTFileSeek(hFile1, aSeeks[i].offSeek, aSeeks[i].uMethod, &offActual);
|
---|
1871 | if (rc != aSeeks[i].rc)
|
---|
1872 | RTTestIFailed("Seek #%u: Expected %Rrc, got %Rrc", i, aSeeks[i].rc, rc);
|
---|
1873 | if (RT_SUCCESS(rc) && offActual != aSeeks[i].offActual)
|
---|
1874 | RTTestIFailed("Seek #%u: offActual %#RX64, expected %#RX64", i, offActual, aSeeks[i].offActual);
|
---|
1875 | if (RT_SUCCESS(rc))
|
---|
1876 | {
|
---|
1877 | uint64_t offTell = RTFileTell(hFile1);
|
---|
1878 | if (offTell != offActual)
|
---|
1879 | RTTestIFailed("Seek #%u: offActual %#RX64, RTFileTell %#RX64", i, offActual, offTell);
|
---|
1880 | }
|
---|
1881 |
|
---|
1882 | if (RT_SUCCESS(rc) && offActual + _2K <= cbFile && iDoReadCheck)
|
---|
1883 | {
|
---|
1884 | uint8_t abBuf[_2K];
|
---|
1885 | RTTESTI_CHECK_RC(rc = RTFileRead(hFile1, abBuf, sizeof(abBuf), NULL), VINF_SUCCESS);
|
---|
1886 | if (RT_SUCCESS(rc))
|
---|
1887 | {
|
---|
1888 | size_t offMarker = (size_t)(RT_ALIGN_64(offActual, _1K) - offActual);
|
---|
1889 | uint64_t uMarker = *(uint64_t *)&abBuf[offMarker]; /** @todo potentially unaligned access */
|
---|
1890 | if (uMarker != offActual + offMarker)
|
---|
1891 | RTTestIFailed("Seek #%u: Invalid marker value (@ %#RX64): %#RX64, expected %#RX64",
|
---|
1892 | i, offActual, uMarker, offActual + offMarker);
|
---|
1893 |
|
---|
1894 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, -(int64_t)sizeof(abBuf), RTFILE_SEEK_CURRENT, NULL), VINF_SUCCESS);
|
---|
1895 | }
|
---|
1896 | }
|
---|
1897 | }
|
---|
1898 | }
|
---|
1899 |
|
---|
1900 |
|
---|
1901 | /*
|
---|
1902 | * Profile seeking relative to the beginning of the file and relative
|
---|
1903 | * to the end. The latter might be more expensive in a SF context.
|
---|
1904 | */
|
---|
1905 | PROFILE_FN(RTFileSeek(hFile1, iIteration < cbFile ? iIteration : iIteration % cbFile, RTFILE_SEEK_BEGIN, NULL),
|
---|
1906 | g_nsTestRun, "RTFileSeek/BEGIN");
|
---|
1907 | PROFILE_FN(RTFileSeek(hFile1, iIteration < cbFile ? -(int64_t)iIteration : -(int64_t)(iIteration % cbFile), RTFILE_SEEK_END, NULL),
|
---|
1908 | g_nsTestRun, "RTFileSeek/END");
|
---|
1909 |
|
---|
1910 | }
|
---|
1911 |
|
---|
1912 |
|
---|
1913 | /** For fsPerfIoRead and fsPerfIoWrite. */
|
---|
1914 | #define PROFILE_IO_FN(a_szOperation, a_fnCall) \
|
---|
1915 | do \
|
---|
1916 | { \
|
---|
1917 | RTTESTI_CHECK_RC_RETV(RTFileSeek(hFile1, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS); \
|
---|
1918 | uint64_t offActual = 0; \
|
---|
1919 | uint32_t cSeeks = 0; \
|
---|
1920 | \
|
---|
1921 | /* Estimate how many iterations we need to fill up the given timeslot: */ \
|
---|
1922 | fsPerfYield(); \
|
---|
1923 | uint64_t nsStart = RTTimeNanoTS(); \
|
---|
1924 | uint64_t ns; \
|
---|
1925 | do \
|
---|
1926 | ns = RTTimeNanoTS(); \
|
---|
1927 | while (ns == nsStart); \
|
---|
1928 | nsStart = ns; \
|
---|
1929 | \
|
---|
1930 | uint64_t iIteration = 0; \
|
---|
1931 | do \
|
---|
1932 | { \
|
---|
1933 | RTTESTI_CHECK_RC(a_fnCall, VINF_SUCCESS); \
|
---|
1934 | iIteration++; \
|
---|
1935 | ns = RTTimeNanoTS() - nsStart; \
|
---|
1936 | } while (ns < RT_NS_10MS); \
|
---|
1937 | ns /= iIteration; \
|
---|
1938 | if (ns > g_nsPerNanoTSCall + 32) \
|
---|
1939 | ns -= g_nsPerNanoTSCall; \
|
---|
1940 | uint64_t cIterations = g_nsTestRun / ns; \
|
---|
1941 | if (cIterations < 2) \
|
---|
1942 | cIterations = 2; \
|
---|
1943 | else if (cIterations & 1) \
|
---|
1944 | cIterations++; \
|
---|
1945 | \
|
---|
1946 | /* Do the actual profiling: */ \
|
---|
1947 | cSeeks = 0; \
|
---|
1948 | iIteration = 0; \
|
---|
1949 | fsPerfYield(); \
|
---|
1950 | nsStart = RTTimeNanoTS(); \
|
---|
1951 | for (uint32_t iAdjust = 0; iAdjust < 4; iAdjust++) \
|
---|
1952 | { \
|
---|
1953 | for (; iIteration < cIterations; iIteration++)\
|
---|
1954 | RTTESTI_CHECK_RC(a_fnCall, VINF_SUCCESS); \
|
---|
1955 | ns = RTTimeNanoTS() - nsStart;\
|
---|
1956 | if (ns >= g_nsTestRun - (g_nsTestRun / 10)) \
|
---|
1957 | break; \
|
---|
1958 | cIterations += cIterations / 4; \
|
---|
1959 | if (cIterations & 1) \
|
---|
1960 | cIterations++; \
|
---|
1961 | nsStart += g_nsPerNanoTSCall; \
|
---|
1962 | } \
|
---|
1963 | RTTestIValueF(ns / iIteration, \
|
---|
1964 | RTTESTUNIT_NS_PER_OCCURRENCE, a_szOperation "/seq/%RU32 latency", cbBlock); \
|
---|
1965 | RTTestIValueF((uint64_t)((uint64_t)iIteration * cbBlock / ((double)ns / RT_NS_1SEC)), \
|
---|
1966 | RTTESTUNIT_BYTES_PER_SEC, a_szOperation "/seq/%RU32 throughput", cbBlock); \
|
---|
1967 | RTTestIValueF(iIteration, \
|
---|
1968 | RTTESTUNIT_CALLS, a_szOperation "/seq/%RU32 calls", cbBlock); \
|
---|
1969 | RTTestIValueF((uint64_t)iIteration * cbBlock, \
|
---|
1970 | RTTESTUNIT_BYTES, a_szOperation "/seq/%RU32 bytes", cbBlock); \
|
---|
1971 | RTTestIValueF(cSeeks, \
|
---|
1972 | RTTESTUNIT_OCCURRENCES, a_szOperation "/seq/%RU32 seeks", cbBlock); \
|
---|
1973 | if (g_fShowDuration) \
|
---|
1974 | RTTestIValueF(ns, RTTESTUNIT_NS, a_szOperation "/seq/%RU32 duration", cbBlock); \
|
---|
1975 | } while (0)
|
---|
1976 |
|
---|
1977 |
|
---|
1978 | /**
|
---|
1979 | * One RTFileRead profiling iteration.
|
---|
1980 | */
|
---|
1981 | DECL_FORCE_INLINE(int) fsPerfIoReadWorker(RTFILE hFile1, uint64_t cbFile, uint32_t cbBlock, uint8_t *pbBlock,
|
---|
1982 | uint64_t *poffActual, uint32_t *pcSeeks)
|
---|
1983 | {
|
---|
1984 | /* Do we need to seek back to the start? */
|
---|
1985 | if (*poffActual + cbBlock <= cbFile)
|
---|
1986 | { /* likely */ }
|
---|
1987 | else
|
---|
1988 | {
|
---|
1989 | RTTESTI_CHECK_RC_RET(RTFileSeek(hFile1, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS, rcCheck);
|
---|
1990 | *pcSeeks += 1;
|
---|
1991 | *poffActual = 0;
|
---|
1992 | }
|
---|
1993 |
|
---|
1994 | size_t cbActuallyRead = 0;
|
---|
1995 | RTTESTI_CHECK_RC_RET(RTFileRead(hFile1, pbBlock, cbBlock, &cbActuallyRead), VINF_SUCCESS, rcCheck);
|
---|
1996 | if (cbActuallyRead == cbBlock)
|
---|
1997 | {
|
---|
1998 | *poffActual += cbActuallyRead;
|
---|
1999 | return VINF_SUCCESS;
|
---|
2000 | }
|
---|
2001 | RTTestIFailed("RTFileRead at %#RX64 returned just %#x bytes, expected %#x", *poffActual, cbActuallyRead, cbBlock);
|
---|
2002 | *poffActual += cbActuallyRead;
|
---|
2003 | return VERR_READ_ERROR;
|
---|
2004 | }
|
---|
2005 |
|
---|
2006 |
|
---|
2007 | void fsPerfIoReadBlockSize(RTFILE hFile1, uint64_t cbFile, uint32_t cbBlock)
|
---|
2008 | {
|
---|
2009 | RTTestISubF("IO - Sequential read %RU32", cbBlock);
|
---|
2010 |
|
---|
2011 | uint8_t *pbBuf = (uint8_t *)RTMemPageAlloc(cbBlock);
|
---|
2012 | if (pbBuf)
|
---|
2013 | {
|
---|
2014 | memset(pbBuf, 0xf7, cbBlock);
|
---|
2015 | PROFILE_IO_FN("RTFileRead", fsPerfIoReadWorker(hFile1, cbFile, cbBlock, pbBuf, &offActual, &cSeeks));
|
---|
2016 | RTMemPageFree(pbBuf, cbBlock);
|
---|
2017 | }
|
---|
2018 | else
|
---|
2019 | RTTestSkipped(g_hTest, "insufficient (virtual) memory available");
|
---|
2020 | }
|
---|
2021 |
|
---|
2022 |
|
---|
2023 | /** preadv is too new to be useful, so we use the readv api via this wrapper. */
|
---|
2024 | DECLINLINE(int) myFileSgReadAt(RTFILE hFile, RTFOFF off, PRTSGBUF pSgBuf, size_t cbToRead, size_t *pcbRead)
|
---|
2025 | {
|
---|
2026 | int rc = RTFileSeek(hFile, off, RTFILE_SEEK_BEGIN, NULL);
|
---|
2027 | if (RT_SUCCESS(rc))
|
---|
2028 | rc = RTFileSgRead(hFile, pSgBuf, cbToRead, pcbRead);
|
---|
2029 | return rc;
|
---|
2030 | }
|
---|
2031 |
|
---|
2032 |
|
---|
2033 | void fsPerfRead(RTFILE hFile1, RTFILE hFileNoCache, uint64_t cbFile)
|
---|
2034 | {
|
---|
2035 | RTTestISubF("IO - RTFileRead");
|
---|
2036 |
|
---|
2037 | /*
|
---|
2038 | * Allocate a big buffer we can play around with. Min size is 1MB.
|
---|
2039 | */
|
---|
2040 | size_t cbBuf = cbFile < _64M ? (size_t)cbFile : _64M;
|
---|
2041 | uint8_t *pbBuf = (uint8_t *)RTMemPageAlloc(cbBuf);
|
---|
2042 | while (!pbBuf)
|
---|
2043 | {
|
---|
2044 | cbBuf /= 2;
|
---|
2045 | RTTESTI_CHECK_RETV(cbBuf >= _1M);
|
---|
2046 | pbBuf = (uint8_t *)RTMemPageAlloc(_32M);
|
---|
2047 | }
|
---|
2048 |
|
---|
2049 | #if 1
|
---|
2050 | /*
|
---|
2051 | * Start at the beginning and read the full buffer in random small chunks, thereby
|
---|
2052 | * checking that unaligned buffer addresses, size and file offsets work fine.
|
---|
2053 | */
|
---|
2054 | struct
|
---|
2055 | {
|
---|
2056 | uint64_t offFile;
|
---|
2057 | uint32_t cbMax;
|
---|
2058 | } aRuns[] = { { 0, 127 }, { cbFile - cbBuf, UINT32_MAX }, { 0, UINT32_MAX -1 }};
|
---|
2059 | for (uint32_t i = 0; i < RT_ELEMENTS(aRuns); i++)
|
---|
2060 | {
|
---|
2061 | memset(pbBuf, 0x55, cbBuf);
|
---|
2062 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, aRuns[i].offFile, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2063 | for (size_t offBuf = 0; offBuf < cbBuf; )
|
---|
2064 | {
|
---|
2065 | uint32_t const cbLeft = (uint32_t)(cbBuf - offBuf);
|
---|
2066 | uint32_t const cbToRead = aRuns[i].cbMax < UINT32_MAX / 2 ? RTRandU32Ex(1, RT_MIN(aRuns[i].cbMax, cbLeft))
|
---|
2067 | : aRuns[i].cbMax == UINT32_MAX ? RTRandU32Ex(RT_MAX(cbLeft / 4, 1), cbLeft)
|
---|
2068 | : RTRandU32Ex(cbLeft >= _8K ? _8K : 1, RT_MIN(_1M, cbLeft));
|
---|
2069 | size_t cbActual = 0;
|
---|
2070 | RTTESTI_CHECK_RC(RTFileRead(hFile1, &pbBuf[offBuf], cbToRead, &cbActual), VINF_SUCCESS);
|
---|
2071 | if (cbActual == cbToRead)
|
---|
2072 | {
|
---|
2073 | offBuf += cbActual;
|
---|
2074 | RTTESTI_CHECK_MSG(RTFileTell(hFile1) == aRuns[i].offFile + offBuf,
|
---|
2075 | ("%#RX64, expected %#RX64\n", RTFileTell(hFile1), aRuns[i].offFile + offBuf));
|
---|
2076 | }
|
---|
2077 | else
|
---|
2078 | {
|
---|
2079 | RTTestIFailed("Attempting to read %#x bytes at %#zx, only got %#x bytes back! (cbLeft=%#x cbBuf=%#zx)\n",
|
---|
2080 | cbToRead, offBuf, cbActual, cbLeft, cbBuf);
|
---|
2081 | if (cbActual)
|
---|
2082 | offBuf += cbActual;
|
---|
2083 | else
|
---|
2084 | pbBuf[offBuf++] = 0x11;
|
---|
2085 | }
|
---|
2086 | }
|
---|
2087 | fsPerfCheckReadBuf(__LINE__, aRuns[i].offFile, pbBuf, cbBuf);
|
---|
2088 | }
|
---|
2089 |
|
---|
2090 | /*
|
---|
2091 | * Test reading beyond the end of the file.
|
---|
2092 | */
|
---|
2093 | size_t const acbMax[] = { cbBuf, _64K, _16K, _4K, 256 };
|
---|
2094 | uint32_t const aoffFromEos[] =
|
---|
2095 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 63, 64, 127, 128, 255, 254, 256, 1023, 1024, 2048,
|
---|
2096 | 4092, 4093, 4094, 4095, 4096, 4097, 4098, 4099, 4100, 8192, 16384, 32767, 32768, 32769, 65535, 65536, _1M - 1
|
---|
2097 | };
|
---|
2098 | for (unsigned iMax = 0; iMax < RT_ELEMENTS(acbMax); iMax++)
|
---|
2099 | {
|
---|
2100 | size_t const cbMaxRead = acbMax[iMax];
|
---|
2101 | for (uint32_t iOffFromEos = 0; iOffFromEos < RT_ELEMENTS(aoffFromEos); iOffFromEos++)
|
---|
2102 | {
|
---|
2103 | uint32_t off = aoffFromEos[iOffFromEos];
|
---|
2104 | if (off >= cbMaxRead)
|
---|
2105 | continue;
|
---|
2106 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, cbFile - off, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2107 | size_t cbActual = ~(size_t)0;
|
---|
2108 | RTTESTI_CHECK_RC(RTFileRead(hFile1, pbBuf, cbMaxRead, &cbActual), VINF_SUCCESS);
|
---|
2109 | RTTESTI_CHECK(cbActual == off);
|
---|
2110 |
|
---|
2111 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, cbFile - off, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2112 | cbActual = ~(size_t)0;
|
---|
2113 | RTTESTI_CHECK_RC(RTFileRead(hFile1, pbBuf, off, &cbActual), VINF_SUCCESS);
|
---|
2114 | RTTESTI_CHECK_MSG(cbActual == off, ("%#zx vs %#zx\n", cbActual, off));
|
---|
2115 |
|
---|
2116 | cbActual = ~(size_t)0;
|
---|
2117 | RTTESTI_CHECK_RC(RTFileRead(hFile1, pbBuf, 1, &cbActual), VINF_SUCCESS);
|
---|
2118 | RTTESTI_CHECK_MSG(cbActual == 0, ("cbActual=%zu\n", cbActual));
|
---|
2119 |
|
---|
2120 | RTTESTI_CHECK_RC(RTFileRead(hFile1, pbBuf, cbMaxRead, NULL), VERR_EOF);
|
---|
2121 |
|
---|
2122 | /* Repeat using native APIs in case IPRT or other layers hid status codes: */
|
---|
2123 | #if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
|
---|
2124 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, cbFile - off, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2125 | # ifdef RT_OS_OS2
|
---|
2126 | ULONG cbActual2 = ~(ULONG)0;
|
---|
2127 | APIRET orc = DosRead((HFILE)RTFileToNative(hFile1), pbBuf, cbMaxRead, &cbActual2);
|
---|
2128 | RTTESTI_CHECK_MSG(orc == NO_ERROR, ("orc=%u, expected 0\n", orc));
|
---|
2129 | RTTESTI_CHECK_MSG(cbActual2 == off, ("%#x vs %#x\n", cbActual2, off));
|
---|
2130 | # else
|
---|
2131 | IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
|
---|
2132 | NTSTATUS rcNt = NtReadFile((HANDLE)RTFileToNative(hFile1), NULL /*hEvent*/, NULL /*ApcRoutine*/, NULL /*ApcContext*/,
|
---|
2133 | &Ios, pbBuf, (ULONG)cbMaxRead, NULL /*poffFile*/, NULL /*Key*/);
|
---|
2134 | if (off == 0)
|
---|
2135 | RTTESTI_CHECK_MSG(rcNt == STATUS_END_OF_FILE, ("rcNt=%#x, expected %#x\n", rcNt, STATUS_END_OF_FILE));
|
---|
2136 | else
|
---|
2137 | RTTESTI_CHECK_MSG(rcNt == STATUS_SUCCESS, ("rcNt=%#x, expected 0 (off=%#x cbMaxRead=%#zx)\n", rcNt, off, cbMaxRead));
|
---|
2138 | RTTESTI_CHECK_MSG(Ios.Information == off, ("%#zx vs %#x\n", Ios.Information, off));
|
---|
2139 | # endif
|
---|
2140 |
|
---|
2141 | # ifdef RT_OS_OS2
|
---|
2142 | cbActual2 = ~(ULONG)0;
|
---|
2143 | orc = DosRead((HFILE)RTFileToNative(hFile1), pbBuf, 1, &cbActual2);
|
---|
2144 | RTTESTI_CHECK_MSG(orc == NO_ERROR, ("orc=%u, expected 0\n", orc));
|
---|
2145 | RTTESTI_CHECK_MSG(cbActual2 == 0, ("cbActual2=%u\n", cbActual2));
|
---|
2146 | # else
|
---|
2147 | RTNT_IO_STATUS_BLOCK_REINIT(&Ios);
|
---|
2148 | rcNt = NtReadFile((HANDLE)RTFileToNative(hFile1), NULL /*hEvent*/, NULL /*ApcRoutine*/, NULL /*ApcContext*/,
|
---|
2149 | &Ios, pbBuf, 1, NULL /*poffFile*/, NULL /*Key*/);
|
---|
2150 | RTTESTI_CHECK_MSG(rcNt == STATUS_END_OF_FILE, ("rcNt=%#x, expected %#x\n", rcNt, STATUS_END_OF_FILE));
|
---|
2151 | # endif
|
---|
2152 |
|
---|
2153 | #endif
|
---|
2154 | }
|
---|
2155 | }
|
---|
2156 |
|
---|
2157 | /*
|
---|
2158 | * Test reading beyond end of the file.
|
---|
2159 | */
|
---|
2160 | for (unsigned iMax = 0; iMax < RT_ELEMENTS(acbMax); iMax++)
|
---|
2161 | {
|
---|
2162 | size_t const cbMaxRead = acbMax[iMax];
|
---|
2163 | for (uint32_t off = 0; off < 256; off++)
|
---|
2164 | {
|
---|
2165 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, cbFile + off, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2166 | size_t cbActual = ~(size_t)0;
|
---|
2167 | RTTESTI_CHECK_RC(RTFileRead(hFile1, pbBuf, cbMaxRead, &cbActual), VINF_SUCCESS);
|
---|
2168 | RTTESTI_CHECK(cbActual == 0);
|
---|
2169 |
|
---|
2170 | RTTESTI_CHECK_RC(RTFileRead(hFile1, pbBuf, cbMaxRead, NULL), VERR_EOF);
|
---|
2171 |
|
---|
2172 | /* Repeat using native APIs in case IPRT or other layers hid status codes: */
|
---|
2173 | #if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
|
---|
2174 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, cbFile + off, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2175 | # ifdef RT_OS_OS2
|
---|
2176 | ULONG cbActual2 = ~(ULONG)0;
|
---|
2177 | APIRET orc = DosRead((HFILE)RTFileToNative(hFile1), pbBuf, cbMaxRead, &cbActual2);
|
---|
2178 | RTTESTI_CHECK_MSG(orc == NO_ERROR, ("orc=%u, expected 0\n", orc));
|
---|
2179 | RTTESTI_CHECK_MSG(cbActual2 == 0, ("%#x vs %#x\n", cbActual2, off));
|
---|
2180 | # else
|
---|
2181 | IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
|
---|
2182 | NTSTATUS rcNt = NtReadFile((HANDLE)RTFileToNative(hFile1), NULL /*hEvent*/, NULL /*ApcRoutine*/, NULL /*ApcContext*/,
|
---|
2183 | &Ios, pbBuf, (ULONG)cbMaxRead, NULL /*poffFile*/, NULL /*Key*/);
|
---|
2184 | RTTESTI_CHECK_MSG(rcNt == STATUS_END_OF_FILE, ("rcNt=%#x, expected %#x\n", rcNt, STATUS_END_OF_FILE));
|
---|
2185 | # endif
|
---|
2186 | #endif
|
---|
2187 | }
|
---|
2188 | }
|
---|
2189 |
|
---|
2190 | /*
|
---|
2191 | * Do uncached access, must be page aligned.
|
---|
2192 | */
|
---|
2193 | uint32_t cbPage = PAGE_SIZE;
|
---|
2194 | memset(pbBuf, 0x66, cbBuf);
|
---|
2195 | if (!g_fIgnoreNoCache || hFileNoCache != NIL_RTFILE)
|
---|
2196 | {
|
---|
2197 | RTTESTI_CHECK_RC(RTFileSeek(hFileNoCache, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2198 | for (size_t offBuf = 0; offBuf < cbBuf; )
|
---|
2199 | {
|
---|
2200 | uint32_t const cPagesLeft = (uint32_t)((cbBuf - offBuf) / cbPage);
|
---|
2201 | uint32_t const cPagesToRead = RTRandU32Ex(1, cPagesLeft);
|
---|
2202 | size_t const cbToRead = cPagesToRead * (size_t)cbPage;
|
---|
2203 | size_t cbActual = 0;
|
---|
2204 | RTTESTI_CHECK_RC(RTFileRead(hFileNoCache, &pbBuf[offBuf], cbToRead, &cbActual), VINF_SUCCESS);
|
---|
2205 | if (cbActual == cbToRead)
|
---|
2206 | offBuf += cbActual;
|
---|
2207 | else
|
---|
2208 | {
|
---|
2209 | RTTestIFailed("Attempting to read %#zx bytes at %#zx, only got %#x bytes back!\n", cbToRead, offBuf, cbActual);
|
---|
2210 | if (cbActual)
|
---|
2211 | offBuf += cbActual;
|
---|
2212 | else
|
---|
2213 | {
|
---|
2214 | memset(&pbBuf[offBuf], 0x11, cbPage);
|
---|
2215 | offBuf += cbPage;
|
---|
2216 | }
|
---|
2217 | }
|
---|
2218 | }
|
---|
2219 | fsPerfCheckReadBuf(__LINE__, 0, pbBuf, cbBuf);
|
---|
2220 | }
|
---|
2221 |
|
---|
2222 | /*
|
---|
2223 | * Check reading zero bytes at the end of the file.
|
---|
2224 | * Requires native call because RTFileWrite doesn't call kernel on zero byte reads.
|
---|
2225 | */
|
---|
2226 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, 0, RTFILE_SEEK_END, NULL), VINF_SUCCESS);
|
---|
2227 | # ifdef RT_OS_WINDOWS
|
---|
2228 | IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
|
---|
2229 | NTSTATUS rcNt = NtReadFile((HANDLE)RTFileToNative(hFile1), NULL, NULL, NULL, &Ios, pbBuf, 0, NULL, NULL);
|
---|
2230 | RTTESTI_CHECK_MSG(rcNt == STATUS_SUCCESS, ("rcNt=%#x", rcNt));
|
---|
2231 | RTTESTI_CHECK(Ios.Status == STATUS_SUCCESS);
|
---|
2232 | RTTESTI_CHECK(Ios.Information == 0);
|
---|
2233 |
|
---|
2234 | RTNT_IO_STATUS_BLOCK_REINIT(&Ios);
|
---|
2235 | rcNt = NtReadFile((HANDLE)RTFileToNative(hFile1), NULL, NULL, NULL, &Ios, pbBuf, 1, NULL, NULL);
|
---|
2236 | RTTESTI_CHECK_MSG(rcNt == STATUS_END_OF_FILE, ("rcNt=%#x", rcNt));
|
---|
2237 | RTTESTI_CHECK(Ios.Status == STATUS_END_OF_FILE);
|
---|
2238 | RTTESTI_CHECK(Ios.Information == 0);
|
---|
2239 | # else
|
---|
2240 | ssize_t cbRead = read((int)RTFileToNative(hFile1), pbBuf, 0);
|
---|
2241 | RTTESTI_CHECK(cbRead == 0);
|
---|
2242 | # endif
|
---|
2243 |
|
---|
2244 | #else
|
---|
2245 | RT_NOREF(hFileNoCache);
|
---|
2246 | #endif
|
---|
2247 |
|
---|
2248 | /*
|
---|
2249 | * Scatter read function operation.
|
---|
2250 | */
|
---|
2251 | #ifdef RT_OS_WINDOWS
|
---|
2252 | /** @todo RTFileSgReadAt is just a RTFileReadAt loop for windows NT. Need
|
---|
2253 | * to use ReadFileScatter (nocache + page aligned). */
|
---|
2254 | #elif !defined(RT_OS_OS2) /** @todo implement RTFileSg using list i/o */
|
---|
2255 |
|
---|
2256 | # ifdef UIO_MAXIOV
|
---|
2257 | RTSGSEG aSegs[UIO_MAXIOV];
|
---|
2258 | # else
|
---|
2259 | RTSGSEG aSegs[512];
|
---|
2260 | # endif
|
---|
2261 | RTSGBUF SgBuf;
|
---|
2262 | uint32_t cIncr = 1;
|
---|
2263 | for (uint32_t cSegs = 1; cSegs <= RT_ELEMENTS(aSegs); cSegs += cIncr)
|
---|
2264 | {
|
---|
2265 | size_t const cbSeg = cbBuf / cSegs;
|
---|
2266 | size_t const cbToRead = cbSeg * cSegs;
|
---|
2267 | for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
|
---|
2268 | {
|
---|
2269 | aSegs[iSeg].cbSeg = cbSeg;
|
---|
2270 | aSegs[iSeg].pvSeg = &pbBuf[cbToRead - (iSeg + 1) * cbSeg];
|
---|
2271 | }
|
---|
2272 | RTSgBufInit(&SgBuf, &aSegs[0], cSegs);
|
---|
2273 | int rc = myFileSgReadAt(hFile1, 0, &SgBuf, cbToRead, NULL);
|
---|
2274 | if (RT_SUCCESS(rc))
|
---|
2275 | for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
|
---|
2276 | {
|
---|
2277 | if (!fsPerfCheckReadBuf(__LINE__, iSeg * cbSeg, &pbBuf[cbToRead - (iSeg + 1) * cbSeg], cbSeg))
|
---|
2278 | {
|
---|
2279 | cSegs = RT_ELEMENTS(aSegs);
|
---|
2280 | break;
|
---|
2281 | }
|
---|
2282 | }
|
---|
2283 | else
|
---|
2284 | {
|
---|
2285 | RTTestIFailed("myFileSgReadAt failed: %Rrc - cSegs=%u cbSegs=%#zx cbToRead=%#zx", rc, cSegs, cbSeg, cbToRead);
|
---|
2286 | break;
|
---|
2287 | }
|
---|
2288 | if (cSegs == 16)
|
---|
2289 | cIncr = 7;
|
---|
2290 | else if (cSegs == 16 * 7 + 16 /*= 128*/)
|
---|
2291 | cIncr = 64;
|
---|
2292 | }
|
---|
2293 |
|
---|
2294 | for (uint32_t iTest = 0; iTest < 128; iTest++)
|
---|
2295 | {
|
---|
2296 | uint32_t cSegs = RTRandU32Ex(1, RT_ELEMENTS(aSegs));
|
---|
2297 | uint32_t iZeroSeg = cSegs > 10 ? RTRandU32Ex(0, cSegs - 1) : UINT32_MAX / 2;
|
---|
2298 | uint32_t cZeroSegs = cSegs > 10 ? RTRandU32Ex(1, RT_MIN(cSegs - iZeroSeg, 25)) : 0;
|
---|
2299 | size_t cbToRead = 0;
|
---|
2300 | size_t cbLeft = cbBuf;
|
---|
2301 | uint8_t *pbCur = &pbBuf[cbBuf];
|
---|
2302 | for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
|
---|
2303 | {
|
---|
2304 | uint32_t iAlign = RTRandU32Ex(0, 3);
|
---|
2305 | if (iAlign & 2) /* end is page aligned */
|
---|
2306 | {
|
---|
2307 | cbLeft -= (uintptr_t)pbCur & PAGE_OFFSET_MASK;
|
---|
2308 | pbCur -= (uintptr_t)pbCur & PAGE_OFFSET_MASK;
|
---|
2309 | }
|
---|
2310 |
|
---|
2311 | size_t cbSegOthers = (cSegs - iSeg) * _8K;
|
---|
2312 | size_t cbSegMax = cbLeft > cbSegOthers ? cbLeft - cbSegOthers
|
---|
2313 | : cbLeft > cSegs ? cbLeft - cSegs
|
---|
2314 | : cbLeft;
|
---|
2315 | size_t cbSeg = cbLeft != 0 ? RTRandU32Ex(0, cbSegMax) : 0;
|
---|
2316 | if (iAlign & 1) /* start is page aligned */
|
---|
2317 | cbSeg += ((uintptr_t)pbCur - cbSeg) & PAGE_OFFSET_MASK;
|
---|
2318 |
|
---|
2319 | if (iSeg - iZeroSeg < cZeroSegs)
|
---|
2320 | cbSeg = 0;
|
---|
2321 |
|
---|
2322 | cbToRead += cbSeg;
|
---|
2323 | cbLeft -= cbSeg;
|
---|
2324 | pbCur -= cbSeg;
|
---|
2325 | aSegs[iSeg].cbSeg = cbSeg;
|
---|
2326 | aSegs[iSeg].pvSeg = pbCur;
|
---|
2327 | }
|
---|
2328 |
|
---|
2329 | uint64_t offFile = cbToRead < cbFile ? RTRandU64Ex(0, cbFile - cbToRead) : 0;
|
---|
2330 | RTSgBufInit(&SgBuf, &aSegs[0], cSegs);
|
---|
2331 | int rc = myFileSgReadAt(hFile1, offFile, &SgBuf, cbToRead, NULL);
|
---|
2332 | if (RT_SUCCESS(rc))
|
---|
2333 | for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
|
---|
2334 | {
|
---|
2335 | if (!fsPerfCheckReadBuf(__LINE__, offFile, (uint8_t *)aSegs[iSeg].pvSeg, aSegs[iSeg].cbSeg))
|
---|
2336 | {
|
---|
2337 | RTTestIFailureDetails("iSeg=%#x cSegs=%#x cbSeg=%#zx cbToRead=%#zx\n", iSeg, cSegs, aSegs[iSeg].cbSeg, cbToRead);
|
---|
2338 | iTest = _16K;
|
---|
2339 | break;
|
---|
2340 | }
|
---|
2341 | offFile += aSegs[iSeg].cbSeg;
|
---|
2342 | }
|
---|
2343 | else
|
---|
2344 | {
|
---|
2345 | RTTestIFailed("myFileSgReadAt failed: %Rrc - cSegs=%#x cbToRead=%#zx", rc, cSegs, cbToRead);
|
---|
2346 | for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
|
---|
2347 | RTTestIFailureDetails("aSeg[%u] = %p LB %#zx (last %p)\n", iSeg, aSegs[iSeg].pvSeg, aSegs[iSeg].cbSeg,
|
---|
2348 | (uint8_t *)aSegs[iSeg].pvSeg + aSegs[iSeg].cbSeg - 1);
|
---|
2349 | break;
|
---|
2350 | }
|
---|
2351 | }
|
---|
2352 |
|
---|
2353 | /* reading beyond the end of the file */
|
---|
2354 | for (uint32_t cSegs = 1; cSegs < 6; cSegs++)
|
---|
2355 | for (uint32_t iTest = 0; iTest < 128; iTest++)
|
---|
2356 | {
|
---|
2357 | uint32_t const cbToRead = RTRandU32Ex(0, cbBuf);
|
---|
2358 | uint32_t const cbBeyond = cbToRead ? RTRandU32Ex(0, cbToRead) : 0;
|
---|
2359 | uint32_t const cbSeg = cbToRead / cSegs;
|
---|
2360 | uint32_t cbLeft = cbToRead;
|
---|
2361 | uint8_t *pbCur = &pbBuf[cbToRead];
|
---|
2362 | for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
|
---|
2363 | {
|
---|
2364 | aSegs[iSeg].cbSeg = iSeg + 1 < cSegs ? cbSeg : cbLeft;
|
---|
2365 | aSegs[iSeg].pvSeg = pbCur -= aSegs[iSeg].cbSeg;
|
---|
2366 | cbLeft -= aSegs[iSeg].cbSeg;
|
---|
2367 | }
|
---|
2368 | Assert(pbCur == pbBuf);
|
---|
2369 |
|
---|
2370 | uint64_t offFile = cbFile + cbBeyond - cbToRead;
|
---|
2371 | RTSgBufInit(&SgBuf, &aSegs[0], cSegs);
|
---|
2372 | int rcExpect = cbBeyond == 0 || cbToRead == 0 ? VINF_SUCCESS : VERR_EOF;
|
---|
2373 | int rc = myFileSgReadAt(hFile1, offFile, &SgBuf, cbToRead, NULL);
|
---|
2374 | if (rc != rcExpect)
|
---|
2375 | {
|
---|
2376 | RTTestIFailed("myFileSgReadAt failed: %Rrc - cSegs=%#x cbToRead=%#zx cbBeyond=%#zx\n", rc, cSegs, cbToRead, cbBeyond);
|
---|
2377 | for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
|
---|
2378 | RTTestIFailureDetails("aSeg[%u] = %p LB %#zx (last %p)\n", iSeg, aSegs[iSeg].pvSeg, aSegs[iSeg].cbSeg,
|
---|
2379 | (uint8_t *)aSegs[iSeg].pvSeg + aSegs[iSeg].cbSeg - 1);
|
---|
2380 | }
|
---|
2381 |
|
---|
2382 | RTSgBufInit(&SgBuf, &aSegs[0], cSegs);
|
---|
2383 | size_t cbActual = 0;
|
---|
2384 | rc = myFileSgReadAt(hFile1, offFile, &SgBuf, cbToRead, &cbActual);
|
---|
2385 | if (rc != VINF_SUCCESS || cbActual != cbToRead - cbBeyond)
|
---|
2386 | RTTestIFailed("myFileSgReadAt failed: %Rrc cbActual=%#zu - cSegs=%#x cbToRead=%#zx cbBeyond=%#zx expected %#zx\n",
|
---|
2387 | rc, cbActual, cSegs, cbToRead, cbBeyond, cbToRead - cbBeyond);
|
---|
2388 | if (RT_SUCCESS(rc) && cbActual > 0)
|
---|
2389 | for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
|
---|
2390 | {
|
---|
2391 | if (!fsPerfCheckReadBuf(__LINE__, offFile, (uint8_t *)aSegs[iSeg].pvSeg, RT_MIN(cbActual, aSegs[iSeg].cbSeg)))
|
---|
2392 | {
|
---|
2393 | RTTestIFailureDetails("iSeg=%#x cSegs=%#x cbSeg=%#zx cbActual%#zx cbToRead=%#zx cbBeyond=%#zx\n",
|
---|
2394 | iSeg, cSegs, aSegs[iSeg].cbSeg, cbActual, cbToRead, cbBeyond);
|
---|
2395 | iTest = _16K;
|
---|
2396 | break;
|
---|
2397 | }
|
---|
2398 | if (cbActual <= aSegs[iSeg].cbSeg)
|
---|
2399 | break;
|
---|
2400 | cbActual -= aSegs[iSeg].cbSeg;
|
---|
2401 | offFile += aSegs[iSeg].cbSeg;
|
---|
2402 | }
|
---|
2403 | }
|
---|
2404 |
|
---|
2405 | #endif
|
---|
2406 |
|
---|
2407 | /*
|
---|
2408 | * Other OS specific stuff.
|
---|
2409 | */
|
---|
2410 | #ifdef RT_OS_WINDOWS
|
---|
2411 | /* Check that reading at an offset modifies the position: */
|
---|
2412 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, 0, RTFILE_SEEK_END, NULL), VINF_SUCCESS);
|
---|
2413 | RTTESTI_CHECK(RTFileTell(hFile1) == cbFile);
|
---|
2414 |
|
---|
2415 | RTNT_IO_STATUS_BLOCK_REINIT(&Ios);
|
---|
2416 | LARGE_INTEGER offNt;
|
---|
2417 | offNt.QuadPart = cbFile / 2;
|
---|
2418 | rcNt = NtReadFile((HANDLE)RTFileToNative(hFile1), NULL, NULL, NULL, &Ios, pbBuf, _4K, &offNt, NULL);
|
---|
2419 | RTTESTI_CHECK_MSG(rcNt == STATUS_SUCCESS, ("rcNt=%#x", rcNt));
|
---|
2420 | RTTESTI_CHECK(Ios.Status == STATUS_SUCCESS);
|
---|
2421 | RTTESTI_CHECK(Ios.Information == _4K);
|
---|
2422 | RTTESTI_CHECK(RTFileTell(hFile1) == cbFile / 2 + _4K);
|
---|
2423 | fsPerfCheckReadBuf(__LINE__, cbFile / 2, pbBuf, _4K);
|
---|
2424 | #endif
|
---|
2425 |
|
---|
2426 |
|
---|
2427 | RTMemPageFree(pbBuf, cbBuf);
|
---|
2428 | }
|
---|
2429 |
|
---|
2430 |
|
---|
2431 | /**
|
---|
2432 | * One RTFileWrite profiling iteration.
|
---|
2433 | */
|
---|
2434 | DECL_FORCE_INLINE(int) fsPerfIoWriteWorker(RTFILE hFile1, uint64_t cbFile, uint32_t cbBlock, uint8_t *pbBlock,
|
---|
2435 | uint64_t *poffActual, uint32_t *pcSeeks)
|
---|
2436 | {
|
---|
2437 | /* Do we need to seek back to the start? */
|
---|
2438 | if (*poffActual + cbBlock <= cbFile)
|
---|
2439 | { /* likely */ }
|
---|
2440 | else
|
---|
2441 | {
|
---|
2442 | RTTESTI_CHECK_RC_RET(RTFileSeek(hFile1, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS, rcCheck);
|
---|
2443 | *pcSeeks += 1;
|
---|
2444 | *poffActual = 0;
|
---|
2445 | }
|
---|
2446 |
|
---|
2447 | size_t cbActuallyWritten = 0;
|
---|
2448 | RTTESTI_CHECK_RC_RET(RTFileWrite(hFile1, pbBlock, cbBlock, &cbActuallyWritten), VINF_SUCCESS, rcCheck);
|
---|
2449 | if (cbActuallyWritten == cbBlock)
|
---|
2450 | {
|
---|
2451 | *poffActual += cbActuallyWritten;
|
---|
2452 | return VINF_SUCCESS;
|
---|
2453 | }
|
---|
2454 | RTTestIFailed("RTFileWrite at %#RX64 returned just %#x bytes, expected %#x", *poffActual, cbActuallyWritten, cbBlock);
|
---|
2455 | *poffActual += cbActuallyWritten;
|
---|
2456 | return VERR_WRITE_ERROR;
|
---|
2457 | }
|
---|
2458 |
|
---|
2459 |
|
---|
2460 | void fsPerfIoWriteBlockSize(RTFILE hFile1, uint64_t cbFile, uint32_t cbBlock)
|
---|
2461 | {
|
---|
2462 | RTTestISubF("IO - Sequential write %RU32", cbBlock);
|
---|
2463 |
|
---|
2464 | uint8_t *pbBuf = (uint8_t *)RTMemPageAlloc(cbBlock);
|
---|
2465 | if (pbBuf)
|
---|
2466 | {
|
---|
2467 | memset(pbBuf, 0xf7, cbBlock);
|
---|
2468 | PROFILE_IO_FN("RTFileWrite", fsPerfIoWriteWorker(hFile1, cbFile, cbBlock, pbBuf, &offActual, &cSeeks));
|
---|
2469 | RTMemPageFree(pbBuf, cbBlock);
|
---|
2470 | }
|
---|
2471 | else
|
---|
2472 | RTTestSkipped(g_hTest, "insufficient (virtual) memory available");
|
---|
2473 | }
|
---|
2474 |
|
---|
2475 |
|
---|
2476 | /** pwritev is too new to be useful, so we use the writev api via this wrapper. */
|
---|
2477 | DECLINLINE(int) myFileSgWriteAt(RTFILE hFile, RTFOFF off, PRTSGBUF pSgBuf, size_t cbToWrite, size_t *pcbWritten)
|
---|
2478 | {
|
---|
2479 | int rc = RTFileSeek(hFile, off, RTFILE_SEEK_BEGIN, NULL);
|
---|
2480 | if (RT_SUCCESS(rc))
|
---|
2481 | rc = RTFileSgWrite(hFile, pSgBuf, cbToWrite, pcbWritten);
|
---|
2482 | return rc;
|
---|
2483 | }
|
---|
2484 |
|
---|
2485 |
|
---|
2486 | void fsPerfWrite(RTFILE hFile1, RTFILE hFileNoCache, RTFILE hFileWriteThru, uint64_t cbFile)
|
---|
2487 | {
|
---|
2488 | RTTestISubF("IO - RTFileWrite");
|
---|
2489 |
|
---|
2490 | /*
|
---|
2491 | * Allocate a big buffer we can play around with. Min size is 1MB.
|
---|
2492 | */
|
---|
2493 | size_t cbBuf = cbFile < _64M ? (size_t)cbFile : _64M;
|
---|
2494 | uint8_t *pbBuf = (uint8_t *)RTMemPageAlloc(cbBuf);
|
---|
2495 | while (!pbBuf)
|
---|
2496 | {
|
---|
2497 | cbBuf /= 2;
|
---|
2498 | RTTESTI_CHECK_RETV(cbBuf >= _1M);
|
---|
2499 | pbBuf = (uint8_t *)RTMemPageAlloc(_32M);
|
---|
2500 | }
|
---|
2501 |
|
---|
2502 | uint8_t bFiller = 0x88;
|
---|
2503 |
|
---|
2504 | #if 1
|
---|
2505 | /*
|
---|
2506 | * Start at the beginning and write out the full buffer in random small chunks, thereby
|
---|
2507 | * checking that unaligned buffer addresses, size and file offsets work fine.
|
---|
2508 | */
|
---|
2509 | struct
|
---|
2510 | {
|
---|
2511 | uint64_t offFile;
|
---|
2512 | uint32_t cbMax;
|
---|
2513 | } aRuns[] = { { 0, 127 }, { cbFile - cbBuf, UINT32_MAX }, { 0, UINT32_MAX -1 }};
|
---|
2514 | for (uint32_t i = 0; i < RT_ELEMENTS(aRuns); i++, bFiller)
|
---|
2515 | {
|
---|
2516 | fsPerfFillWriteBuf(aRuns[i].offFile, pbBuf, cbBuf, bFiller);
|
---|
2517 | fsPerfCheckReadBuf(__LINE__, aRuns[i].offFile, pbBuf, cbBuf, bFiller);
|
---|
2518 |
|
---|
2519 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, aRuns[i].offFile, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2520 | for (size_t offBuf = 0; offBuf < cbBuf; )
|
---|
2521 | {
|
---|
2522 | uint32_t const cbLeft = (uint32_t)(cbBuf - offBuf);
|
---|
2523 | uint32_t const cbToWrite = aRuns[i].cbMax < UINT32_MAX / 2 ? RTRandU32Ex(1, RT_MIN(aRuns[i].cbMax, cbLeft))
|
---|
2524 | : aRuns[i].cbMax == UINT32_MAX ? RTRandU32Ex(RT_MAX(cbLeft / 4, 1), cbLeft)
|
---|
2525 | : RTRandU32Ex(cbLeft >= _8K ? _8K : 1, RT_MIN(_1M, cbLeft));
|
---|
2526 | size_t cbActual = 0;
|
---|
2527 | RTTESTI_CHECK_RC(RTFileWrite(hFile1, &pbBuf[offBuf], cbToWrite, &cbActual), VINF_SUCCESS);
|
---|
2528 | if (cbActual == cbToWrite)
|
---|
2529 | {
|
---|
2530 | offBuf += cbActual;
|
---|
2531 | RTTESTI_CHECK_MSG(RTFileTell(hFile1) == aRuns[i].offFile + offBuf,
|
---|
2532 | ("%#RX64, expected %#RX64\n", RTFileTell(hFile1), aRuns[i].offFile + offBuf));
|
---|
2533 | }
|
---|
2534 | else
|
---|
2535 | {
|
---|
2536 | RTTestIFailed("Attempting to write %#x bytes at %#zx (%#x left), only got %#x written!\n",
|
---|
2537 | cbToWrite, offBuf, cbLeft, cbActual);
|
---|
2538 | if (cbActual)
|
---|
2539 | offBuf += cbActual;
|
---|
2540 | else
|
---|
2541 | pbBuf[offBuf++] = 0x11;
|
---|
2542 | }
|
---|
2543 | }
|
---|
2544 |
|
---|
2545 | RTTESTI_CHECK_RC(RTFileReadAt(hFile1, aRuns[i].offFile, pbBuf, cbBuf, NULL), VINF_SUCCESS);
|
---|
2546 | fsPerfCheckReadBuf(__LINE__, aRuns[i].offFile, pbBuf, cbBuf, bFiller);
|
---|
2547 | }
|
---|
2548 |
|
---|
2549 |
|
---|
2550 | /*
|
---|
2551 | * Do uncached and write-thru accesses, must be page aligned.
|
---|
2552 | */
|
---|
2553 | RTFILE ahFiles[2] = { hFileWriteThru, hFileNoCache };
|
---|
2554 | for (unsigned iFile = 0; iFile < RT_ELEMENTS(ahFiles); iFile++, bFiller++)
|
---|
2555 | {
|
---|
2556 | if (g_fIgnoreNoCache && ahFiles[iFile] == NIL_RTFILE)
|
---|
2557 | continue;
|
---|
2558 |
|
---|
2559 | fsPerfFillWriteBuf(0, pbBuf, cbBuf, bFiller);
|
---|
2560 | fsPerfCheckReadBuf(__LINE__, 0, pbBuf, cbBuf, bFiller);
|
---|
2561 | RTTESTI_CHECK_RC(RTFileSeek(ahFiles[iFile], 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2562 |
|
---|
2563 | uint32_t cbPage = PAGE_SIZE;
|
---|
2564 | for (size_t offBuf = 0; offBuf < cbBuf; )
|
---|
2565 | {
|
---|
2566 | uint32_t const cPagesLeft = (uint32_t)((cbBuf - offBuf) / cbPage);
|
---|
2567 | uint32_t const cPagesToWrite = RTRandU32Ex(1, cPagesLeft);
|
---|
2568 | size_t const cbToWrite = cPagesToWrite * (size_t)cbPage;
|
---|
2569 | size_t cbActual = 0;
|
---|
2570 | RTTESTI_CHECK_RC(RTFileWrite(ahFiles[iFile], &pbBuf[offBuf], cbToWrite, &cbActual), VINF_SUCCESS);
|
---|
2571 | if (cbActual == cbToWrite)
|
---|
2572 | {
|
---|
2573 | RTTESTI_CHECK_RC(RTFileReadAt(hFile1, offBuf, pbBuf, cbToWrite, NULL), VINF_SUCCESS);
|
---|
2574 | fsPerfCheckReadBuf(__LINE__, offBuf, pbBuf, cbToWrite, bFiller);
|
---|
2575 | offBuf += cbActual;
|
---|
2576 | }
|
---|
2577 | else
|
---|
2578 | {
|
---|
2579 | RTTestIFailed("Attempting to read %#zx bytes at %#zx, only got %#x written!\n", cbToWrite, offBuf, cbActual);
|
---|
2580 | if (cbActual)
|
---|
2581 | offBuf += cbActual;
|
---|
2582 | else
|
---|
2583 | {
|
---|
2584 | memset(&pbBuf[offBuf], 0x11, cbPage);
|
---|
2585 | offBuf += cbPage;
|
---|
2586 | }
|
---|
2587 | }
|
---|
2588 | }
|
---|
2589 |
|
---|
2590 | RTTESTI_CHECK_RC(RTFileReadAt(ahFiles[iFile], 0, pbBuf, cbBuf, NULL), VINF_SUCCESS);
|
---|
2591 | fsPerfCheckReadBuf(__LINE__, 0, pbBuf, cbBuf, bFiller);
|
---|
2592 | }
|
---|
2593 |
|
---|
2594 | /*
|
---|
2595 | * Check the behavior of writing zero bytes to the file _4K from the end
|
---|
2596 | * using native API. In the olden days zero sized write have been known
|
---|
2597 | * to be used to truncate a file.
|
---|
2598 | */
|
---|
2599 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, -_4K, RTFILE_SEEK_END, NULL), VINF_SUCCESS);
|
---|
2600 | # ifdef RT_OS_WINDOWS
|
---|
2601 | IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
|
---|
2602 | NTSTATUS rcNt = NtWriteFile((HANDLE)RTFileToNative(hFile1), NULL, NULL, NULL, &Ios, pbBuf, 0, NULL, NULL);
|
---|
2603 | RTTESTI_CHECK_MSG(rcNt == STATUS_SUCCESS, ("rcNt=%#x", rcNt));
|
---|
2604 | RTTESTI_CHECK(Ios.Status == STATUS_SUCCESS);
|
---|
2605 | RTTESTI_CHECK(Ios.Information == 0);
|
---|
2606 | # else
|
---|
2607 | ssize_t cbWritten = write((int)RTFileToNative(hFile1), pbBuf, 0);
|
---|
2608 | RTTESTI_CHECK(cbWritten == 0);
|
---|
2609 | # endif
|
---|
2610 | RTTESTI_CHECK_RC(RTFileRead(hFile1, pbBuf, _4K, NULL), VINF_SUCCESS);
|
---|
2611 | fsPerfCheckReadBuf(__LINE__, cbFile - _4K, pbBuf, _4K, pbBuf[0x8]);
|
---|
2612 |
|
---|
2613 | #else
|
---|
2614 | RT_NOREF(hFileNoCache, hFileWriteThru);
|
---|
2615 | #endif
|
---|
2616 |
|
---|
2617 | /*
|
---|
2618 | * Gather write function operation.
|
---|
2619 | */
|
---|
2620 | #ifdef RT_OS_WINDOWS
|
---|
2621 | /** @todo RTFileSgWriteAt is just a RTFileWriteAt loop for windows NT. Need
|
---|
2622 | * to use WriteFileGather (nocache + page aligned). */
|
---|
2623 | #elif !defined(RT_OS_OS2) /** @todo implement RTFileSg using list i/o */
|
---|
2624 |
|
---|
2625 | # ifdef UIO_MAXIOV
|
---|
2626 | RTSGSEG aSegs[UIO_MAXIOV];
|
---|
2627 | # else
|
---|
2628 | RTSGSEG aSegs[512];
|
---|
2629 | # endif
|
---|
2630 | RTSGBUF SgBuf;
|
---|
2631 | uint32_t cIncr = 1;
|
---|
2632 | for (uint32_t cSegs = 1; cSegs <= RT_ELEMENTS(aSegs); cSegs += cIncr, bFiller++)
|
---|
2633 | {
|
---|
2634 | size_t const cbSeg = cbBuf / cSegs;
|
---|
2635 | size_t const cbToWrite = cbSeg * cSegs;
|
---|
2636 | for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
|
---|
2637 | {
|
---|
2638 | aSegs[iSeg].cbSeg = cbSeg;
|
---|
2639 | aSegs[iSeg].pvSeg = &pbBuf[cbToWrite - (iSeg + 1) * cbSeg];
|
---|
2640 | fsPerfFillWriteBuf(iSeg * cbSeg, (uint8_t *)aSegs[iSeg].pvSeg, cbSeg, bFiller);
|
---|
2641 | }
|
---|
2642 | RTSgBufInit(&SgBuf, &aSegs[0], cSegs);
|
---|
2643 | int rc = myFileSgWriteAt(hFile1, 0, &SgBuf, cbToWrite, NULL);
|
---|
2644 | if (RT_SUCCESS(rc))
|
---|
2645 | {
|
---|
2646 | RTTESTI_CHECK_RC(RTFileReadAt(hFile1, 0, pbBuf, cbToWrite, NULL), VINF_SUCCESS);
|
---|
2647 | fsPerfCheckReadBuf(__LINE__, 0, pbBuf, cbToWrite, bFiller);
|
---|
2648 | }
|
---|
2649 | else
|
---|
2650 | {
|
---|
2651 | RTTestIFailed("myFileSgWriteAt failed: %Rrc - cSegs=%u cbSegs=%#zx cbToWrite=%#zx", rc, cSegs, cbSeg, cbToWrite);
|
---|
2652 | break;
|
---|
2653 | }
|
---|
2654 | if (cSegs == 16)
|
---|
2655 | cIncr = 7;
|
---|
2656 | else if (cSegs == 16 * 7 + 16 /*= 128*/)
|
---|
2657 | cIncr = 64;
|
---|
2658 | }
|
---|
2659 |
|
---|
2660 | /* random stuff, including zero segments. */
|
---|
2661 | for (uint32_t iTest = 0; iTest < 128; iTest++, bFiller++)
|
---|
2662 | {
|
---|
2663 | uint32_t cSegs = RTRandU32Ex(1, RT_ELEMENTS(aSegs));
|
---|
2664 | uint32_t iZeroSeg = cSegs > 10 ? RTRandU32Ex(0, cSegs - 1) : UINT32_MAX / 2;
|
---|
2665 | uint32_t cZeroSegs = cSegs > 10 ? RTRandU32Ex(1, RT_MIN(cSegs - iZeroSeg, 25)) : 0;
|
---|
2666 | size_t cbToWrite = 0;
|
---|
2667 | size_t cbLeft = cbBuf;
|
---|
2668 | uint8_t *pbCur = &pbBuf[cbBuf];
|
---|
2669 | for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
|
---|
2670 | {
|
---|
2671 | uint32_t iAlign = RTRandU32Ex(0, 3);
|
---|
2672 | if (iAlign & 2) /* end is page aligned */
|
---|
2673 | {
|
---|
2674 | cbLeft -= (uintptr_t)pbCur & PAGE_OFFSET_MASK;
|
---|
2675 | pbCur -= (uintptr_t)pbCur & PAGE_OFFSET_MASK;
|
---|
2676 | }
|
---|
2677 |
|
---|
2678 | size_t cbSegOthers = (cSegs - iSeg) * _8K;
|
---|
2679 | size_t cbSegMax = cbLeft > cbSegOthers ? cbLeft - cbSegOthers
|
---|
2680 | : cbLeft > cSegs ? cbLeft - cSegs
|
---|
2681 | : cbLeft;
|
---|
2682 | size_t cbSeg = cbLeft != 0 ? RTRandU32Ex(0, cbSegMax) : 0;
|
---|
2683 | if (iAlign & 1) /* start is page aligned */
|
---|
2684 | cbSeg += ((uintptr_t)pbCur - cbSeg) & PAGE_OFFSET_MASK;
|
---|
2685 |
|
---|
2686 | if (iSeg - iZeroSeg < cZeroSegs)
|
---|
2687 | cbSeg = 0;
|
---|
2688 |
|
---|
2689 | cbToWrite += cbSeg;
|
---|
2690 | cbLeft -= cbSeg;
|
---|
2691 | pbCur -= cbSeg;
|
---|
2692 | aSegs[iSeg].cbSeg = cbSeg;
|
---|
2693 | aSegs[iSeg].pvSeg = pbCur;
|
---|
2694 | }
|
---|
2695 |
|
---|
2696 | uint64_t const offFile = cbToWrite < cbFile ? RTRandU64Ex(0, cbFile - cbToWrite) : 0;
|
---|
2697 | uint64_t offFill = offFile;
|
---|
2698 | for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
|
---|
2699 | if (aSegs[iSeg].cbSeg)
|
---|
2700 | {
|
---|
2701 | fsPerfFillWriteBuf(offFill, (uint8_t *)aSegs[iSeg].pvSeg, aSegs[iSeg].cbSeg, bFiller);
|
---|
2702 | offFill += aSegs[iSeg].cbSeg;
|
---|
2703 | }
|
---|
2704 |
|
---|
2705 | RTSgBufInit(&SgBuf, &aSegs[0], cSegs);
|
---|
2706 | int rc = myFileSgWriteAt(hFile1, offFile, &SgBuf, cbToWrite, NULL);
|
---|
2707 | if (RT_SUCCESS(rc))
|
---|
2708 | {
|
---|
2709 | RTTESTI_CHECK_RC(RTFileReadAt(hFile1, offFile, pbBuf, cbToWrite, NULL), VINF_SUCCESS);
|
---|
2710 | fsPerfCheckReadBuf(__LINE__, offFile, pbBuf, cbToWrite, bFiller);
|
---|
2711 | }
|
---|
2712 | else
|
---|
2713 | {
|
---|
2714 | RTTestIFailed("myFileSgWriteAt failed: %Rrc - cSegs=%#x cbToWrite=%#zx", rc, cSegs, cbToWrite);
|
---|
2715 | break;
|
---|
2716 | }
|
---|
2717 | }
|
---|
2718 |
|
---|
2719 | #endif
|
---|
2720 |
|
---|
2721 | /*
|
---|
2722 | * Other OS specific stuff.
|
---|
2723 | */
|
---|
2724 | #ifdef RT_OS_WINDOWS
|
---|
2725 | /* Check that reading at an offset modifies the position: */
|
---|
2726 | RTTESTI_CHECK_RC(RTFileReadAt(hFile1, cbFile / 2, pbBuf, _4K, NULL), VINF_SUCCESS);
|
---|
2727 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, 0, RTFILE_SEEK_END, NULL), VINF_SUCCESS);
|
---|
2728 | RTTESTI_CHECK(RTFileTell(hFile1) == cbFile);
|
---|
2729 |
|
---|
2730 | RTNT_IO_STATUS_BLOCK_REINIT(&Ios);
|
---|
2731 | LARGE_INTEGER offNt;
|
---|
2732 | offNt.QuadPart = cbFile / 2;
|
---|
2733 | rcNt = NtWriteFile((HANDLE)RTFileToNative(hFile1), NULL, NULL, NULL, &Ios, pbBuf, _4K, &offNt, NULL);
|
---|
2734 | RTTESTI_CHECK_MSG(rcNt == STATUS_SUCCESS, ("rcNt=%#x", rcNt));
|
---|
2735 | RTTESTI_CHECK(Ios.Status == STATUS_SUCCESS);
|
---|
2736 | RTTESTI_CHECK(Ios.Information == _4K);
|
---|
2737 | RTTESTI_CHECK(RTFileTell(hFile1) == cbFile / 2 + _4K);
|
---|
2738 | #endif
|
---|
2739 |
|
---|
2740 | RTMemPageFree(pbBuf, cbBuf);
|
---|
2741 | }
|
---|
2742 |
|
---|
2743 |
|
---|
2744 | /**
|
---|
2745 | * Worker for testing RTFileFlush.
|
---|
2746 | */
|
---|
2747 | DECL_FORCE_INLINE(int) fsPerfFSyncWorker(RTFILE hFile1, uint64_t cbFile, uint8_t *pbBuf, size_t cbBuf, uint64_t *poffFile)
|
---|
2748 | {
|
---|
2749 | if (*poffFile + cbBuf <= cbFile)
|
---|
2750 | { /* likely */ }
|
---|
2751 | else
|
---|
2752 | {
|
---|
2753 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2754 | *poffFile = 0;
|
---|
2755 | }
|
---|
2756 |
|
---|
2757 | RTTESTI_CHECK_RC_RET(RTFileWrite(hFile1, pbBuf, cbBuf, NULL), VINF_SUCCESS, rcCheck);
|
---|
2758 | RTTESTI_CHECK_RC_RET(RTFileFlush(hFile1), VINF_SUCCESS, rcCheck);
|
---|
2759 |
|
---|
2760 | *poffFile += cbBuf;
|
---|
2761 | return VINF_SUCCESS;
|
---|
2762 | }
|
---|
2763 |
|
---|
2764 |
|
---|
2765 | void fsPerfFSync(RTFILE hFile1, uint64_t cbFile)
|
---|
2766 | {
|
---|
2767 | RTTestISub("fsync");
|
---|
2768 |
|
---|
2769 | RTTESTI_CHECK_RC(RTFileFlush(hFile1), VINF_SUCCESS);
|
---|
2770 |
|
---|
2771 | PROFILE_FN(RTFileFlush(hFile1), g_nsTestRun, "RTFileFlush");
|
---|
2772 |
|
---|
2773 | size_t cbBuf = PAGE_SIZE;
|
---|
2774 | uint8_t *pbBuf = (uint8_t *)RTMemPageAlloc(cbBuf);
|
---|
2775 | RTTESTI_CHECK_RETV(pbBuf != NULL);
|
---|
2776 | memset(pbBuf, 0xf4, cbBuf);
|
---|
2777 |
|
---|
2778 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2779 | uint64_t offFile = 0;
|
---|
2780 | PROFILE_FN(fsPerfFSyncWorker(hFile1, cbFile, pbBuf, cbBuf, &offFile), g_nsTestRun, "RTFileWrite[Page]/RTFileFlush");
|
---|
2781 |
|
---|
2782 | RTMemPageFree(pbBuf, cbBuf);
|
---|
2783 | }
|
---|
2784 |
|
---|
2785 |
|
---|
2786 | #ifndef RT_OS_OS2
|
---|
2787 | /**
|
---|
2788 | * Worker for profiling msync.
|
---|
2789 | */
|
---|
2790 | DECL_FORCE_INLINE(int) fsPerfMSyncWorker(uint8_t *pbMapping, size_t offMapping, size_t cbFlush, size_t *pcbFlushed)
|
---|
2791 | {
|
---|
2792 | uint8_t *pbCur = &pbMapping[offMapping];
|
---|
2793 | for (size_t offFlush = 0; offFlush < cbFlush; offFlush += PAGE_SIZE)
|
---|
2794 | *(size_t volatile *)&pbCur[offFlush + 8] = cbFlush;
|
---|
2795 | # ifdef RT_OS_WINDOWS
|
---|
2796 | RTTESTI_CHECK(FlushViewOfFile(pbCur, cbFlush));
|
---|
2797 | # else
|
---|
2798 | RTTESTI_CHECK(msync(pbCur, cbFlush, MS_SYNC) == 0);
|
---|
2799 | # endif
|
---|
2800 | if (*pcbFlushed < offMapping + cbFlush)
|
---|
2801 | *pcbFlushed = offMapping + cbFlush;
|
---|
2802 | return VINF_SUCCESS;
|
---|
2803 | }
|
---|
2804 | #endif /* !RT_OS_OS2 */
|
---|
2805 |
|
---|
2806 |
|
---|
2807 | void fsPerfMMap(RTFILE hFile1, RTFILE hFileNoCache, uint64_t cbFile)
|
---|
2808 | {
|
---|
2809 | RTTestISub("mmap");
|
---|
2810 | #if !defined(RT_OS_OS2)
|
---|
2811 | static const char * const s_apszStates[] = { "readonly", "writecopy", "readwrite" };
|
---|
2812 | enum { kMMap_ReadOnly = 0, kMMap_WriteCopy, kMMap_ReadWrite, kMMap_End };
|
---|
2813 | for (int enmState = kMMap_ReadOnly; enmState < kMMap_End; enmState++)
|
---|
2814 | {
|
---|
2815 | /*
|
---|
2816 | * Do the mapping.
|
---|
2817 | */
|
---|
2818 | size_t cbMapping = (size_t)cbFile;
|
---|
2819 | if (cbMapping != cbFile)
|
---|
2820 | cbMapping = _256M;
|
---|
2821 | uint8_t *pbMapping;
|
---|
2822 |
|
---|
2823 | # ifdef RT_OS_WINDOWS
|
---|
2824 | HANDLE hSection;
|
---|
2825 | pbMapping = NULL;
|
---|
2826 | for (;; cbMapping /= 2)
|
---|
2827 | {
|
---|
2828 | hSection = CreateFileMapping((HANDLE)RTFileToNative(hFile1), NULL,
|
---|
2829 | enmState == kMMap_ReadOnly ? PAGE_READONLY
|
---|
2830 | : enmState == kMMap_WriteCopy ? PAGE_WRITECOPY : PAGE_READWRITE,
|
---|
2831 | (uint32_t)((uint64_t)cbMapping >> 32), (uint32_t)cbMapping, NULL);
|
---|
2832 | DWORD dwErr1 = GetLastError();
|
---|
2833 | DWORD dwErr2 = 0;
|
---|
2834 | if (hSection != NULL)
|
---|
2835 | {
|
---|
2836 | pbMapping = (uint8_t *)MapViewOfFile(hSection,
|
---|
2837 | enmState == kMMap_ReadOnly ? FILE_MAP_READ
|
---|
2838 | : enmState == kMMap_WriteCopy ? FILE_MAP_COPY
|
---|
2839 | : FILE_MAP_WRITE,
|
---|
2840 | 0, 0, cbMapping);
|
---|
2841 | if (pbMapping)
|
---|
2842 | break;
|
---|
2843 | dwErr2 = GetLastError();
|
---|
2844 | CloseHandle(hSection);
|
---|
2845 | }
|
---|
2846 | if (cbMapping <= _2M)
|
---|
2847 | {
|
---|
2848 | RTTestIFailed("%u/%s: CreateFileMapping or MapViewOfFile failed: %u, %u",
|
---|
2849 | enmState, s_apszStates[enmState], dwErr1, dwErr2);
|
---|
2850 | break;
|
---|
2851 | }
|
---|
2852 | }
|
---|
2853 | # else
|
---|
2854 | for (;; cbMapping /= 2)
|
---|
2855 | {
|
---|
2856 | pbMapping = (uint8_t *)mmap(NULL, cbMapping,
|
---|
2857 | enmState == kMMap_ReadOnly ? PROT_READ : PROT_READ | PROT_WRITE,
|
---|
2858 | enmState == kMMap_WriteCopy ? MAP_PRIVATE : MAP_SHARED,
|
---|
2859 | (int)RTFileToNative(hFile1), 0);
|
---|
2860 | if ((void *)pbMapping != MAP_FAILED)
|
---|
2861 | break;
|
---|
2862 | if (cbMapping <= _2M)
|
---|
2863 | {
|
---|
2864 | RTTestIFailed("%u/%s: mmap failed: %s (%u)", enmState, s_apszStates[enmState], strerror(errno), errno);
|
---|
2865 | break;
|
---|
2866 | }
|
---|
2867 | }
|
---|
2868 | # endif
|
---|
2869 | if (cbMapping <= _2M)
|
---|
2870 | continue;
|
---|
2871 |
|
---|
2872 | /*
|
---|
2873 | * Time page-ins just for fun.
|
---|
2874 | */
|
---|
2875 | size_t const cPages = cbMapping >> PAGE_SHIFT;
|
---|
2876 | size_t uDummy = 0;
|
---|
2877 | uint64_t ns = RTTimeNanoTS();
|
---|
2878 | for (size_t iPage = 0; iPage < cPages; iPage++)
|
---|
2879 | uDummy += ASMAtomicReadU8(&pbMapping[iPage << PAGE_SHIFT]);
|
---|
2880 | ns = RTTimeNanoTS() - ns;
|
---|
2881 | RTTestIValueF(ns / cPages, RTTESTUNIT_NS_PER_OCCURRENCE, "page-in %s", s_apszStates[enmState]);
|
---|
2882 |
|
---|
2883 | /* Check the content. */
|
---|
2884 | fsPerfCheckReadBuf(__LINE__, 0, pbMapping, cbMapping);
|
---|
2885 |
|
---|
2886 | if (enmState != kMMap_ReadOnly)
|
---|
2887 | {
|
---|
2888 | /* Write stuff to the first two megabytes. In the COW case, we'll detect
|
---|
2889 | corruption of shared data during content checking of the RW iterations. */
|
---|
2890 | fsPerfFillWriteBuf(0, pbMapping, _2M, 0xf7);
|
---|
2891 | if (enmState == kMMap_ReadWrite)
|
---|
2892 | {
|
---|
2893 | /* For RW we can try read back from the file handle and check if we get
|
---|
2894 | a match there first. */
|
---|
2895 | uint8_t abBuf[_4K];
|
---|
2896 | for (uint32_t off = 0; off < _2M; off += sizeof(abBuf))
|
---|
2897 | {
|
---|
2898 | RTTESTI_CHECK_RC(RTFileReadAt(hFile1, off, abBuf, sizeof(abBuf), NULL), VINF_SUCCESS);
|
---|
2899 | fsPerfCheckReadBuf(__LINE__, off, abBuf, sizeof(abBuf), 0xf7);
|
---|
2900 | }
|
---|
2901 | # ifdef RT_OS_WINDOWS
|
---|
2902 | RTTESTI_CHECK(FlushViewOfFile(pbMapping, _2M));
|
---|
2903 | # else
|
---|
2904 | RTTESTI_CHECK(msync(pbMapping, _2M, MS_SYNC) == 0);
|
---|
2905 | # endif
|
---|
2906 |
|
---|
2907 | /*
|
---|
2908 | * Time modifying and flushing a few different number of pages.
|
---|
2909 | */
|
---|
2910 | static size_t const s_acbFlush[] = { PAGE_SIZE, PAGE_SIZE * 2, PAGE_SIZE * 3, PAGE_SIZE * 8, PAGE_SIZE * 16, _2M };
|
---|
2911 | for (unsigned iFlushSize = 0 ; iFlushSize < RT_ELEMENTS(s_acbFlush); iFlushSize++)
|
---|
2912 | {
|
---|
2913 | size_t const cbFlush = s_acbFlush[iFlushSize];
|
---|
2914 | if (cbFlush > cbMapping)
|
---|
2915 | continue;
|
---|
2916 |
|
---|
2917 | char szDesc[80];
|
---|
2918 | RTStrPrintf(szDesc, sizeof(szDesc), "touch/flush/%zu", cbFlush);
|
---|
2919 | size_t const cFlushes = cbMapping / cbFlush;
|
---|
2920 | size_t const cbMappingUsed = cFlushes * cbFlush;
|
---|
2921 | size_t cbFlushed = 0;
|
---|
2922 | PROFILE_FN(fsPerfMSyncWorker(pbMapping, (iIteration * cbFlush) % cbMappingUsed, cbFlush, &cbFlushed),
|
---|
2923 | g_nsTestRun, szDesc);
|
---|
2924 |
|
---|
2925 | /*
|
---|
2926 | * Check that all the changes made it thru to the file:
|
---|
2927 | */
|
---|
2928 | if (!g_fIgnoreNoCache || hFileNoCache != NIL_RTFILE)
|
---|
2929 | {
|
---|
2930 | size_t cbBuf = _2M;
|
---|
2931 | uint8_t *pbBuf = (uint8_t *)RTMemPageAlloc(cbBuf);
|
---|
2932 | if (!pbBuf)
|
---|
2933 | {
|
---|
2934 | cbBuf = _4K;
|
---|
2935 | pbBuf = (uint8_t *)RTMemPageAlloc(cbBuf);
|
---|
2936 | }
|
---|
2937 | RTTESTI_CHECK(pbBuf != NULL);
|
---|
2938 | if (pbBuf)
|
---|
2939 | {
|
---|
2940 | RTTESTI_CHECK_RC(RTFileSeek(hFileNoCache, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2941 | size_t const cbToCheck = RT_MIN(cFlushes * cbFlush, cbFlushed);
|
---|
2942 | unsigned cErrors = 0;
|
---|
2943 | for (size_t offBuf = 0; cErrors < 32 && offBuf < cbToCheck; offBuf += cbBuf)
|
---|
2944 | {
|
---|
2945 | size_t cbToRead = RT_MIN(cbBuf, cbToCheck - offBuf);
|
---|
2946 | RTTESTI_CHECK_RC(RTFileRead(hFileNoCache, pbBuf, cbToRead, NULL), VINF_SUCCESS);
|
---|
2947 |
|
---|
2948 | for (size_t offFlush = 0; offFlush < cbToRead; offFlush += PAGE_SIZE)
|
---|
2949 | if (*(size_t volatile *)&pbBuf[offFlush + 8] != cbFlush)
|
---|
2950 | {
|
---|
2951 | RTTestIFailed("Flush issue at offset #%zx: %#zx, expected %#zx (cbFlush=%#zx, %#RX64)",
|
---|
2952 | offBuf + offFlush + 8, *(size_t volatile *)&pbBuf[offFlush + 8],
|
---|
2953 | cbFlush, cbFlush, *(uint64_t volatile *)&pbBuf[offFlush]);
|
---|
2954 | if (++cErrors > 32)
|
---|
2955 | break;
|
---|
2956 | }
|
---|
2957 | }
|
---|
2958 | RTMemPageFree(pbBuf, cbBuf);
|
---|
2959 | }
|
---|
2960 | }
|
---|
2961 | }
|
---|
2962 |
|
---|
2963 | # if 0 /* not needed, very very slow */
|
---|
2964 | /*
|
---|
2965 | * Restore the file to 0xf6 state for the next test.
|
---|
2966 | */
|
---|
2967 | RTTestIPrintf(RTTESTLVL_ALWAYS, "Restoring content...\n");
|
---|
2968 | fsPerfFillWriteBuf(0, pbMapping, cbMapping, 0xf6);
|
---|
2969 | # ifdef RT_OS_WINDOWS
|
---|
2970 | RTTESTI_CHECK(FlushViewOfFile(pbMapping, cbMapping));
|
---|
2971 | # else
|
---|
2972 | RTTESTI_CHECK(msync(pbMapping, cbMapping, MS_SYNC) == 0);
|
---|
2973 | # endif
|
---|
2974 | RTTestIPrintf(RTTESTLVL_ALWAYS, "... done\n");
|
---|
2975 | # endif
|
---|
2976 | }
|
---|
2977 | }
|
---|
2978 |
|
---|
2979 | /*
|
---|
2980 | * Obsever how regular writes affects a read-only or readwrite mapping.
|
---|
2981 | * These should ideally be immediately visible in the mapping, at least
|
---|
2982 | * when not performed thru an no-cache handle.
|
---|
2983 | */
|
---|
2984 | if (enmState == kMMap_ReadOnly || enmState == kMMap_ReadWrite)
|
---|
2985 | {
|
---|
2986 | size_t cbBuf = RT_MIN(_2M, cbMapping / 2);
|
---|
2987 | uint8_t *pbBuf = (uint8_t *)RTMemPageAlloc(cbBuf);
|
---|
2988 | if (!pbBuf)
|
---|
2989 | {
|
---|
2990 | cbBuf = _4K;
|
---|
2991 | pbBuf = (uint8_t *)RTMemPageAlloc(cbBuf);
|
---|
2992 | }
|
---|
2993 | RTTESTI_CHECK(pbBuf != NULL);
|
---|
2994 | if (pbBuf)
|
---|
2995 | {
|
---|
2996 | /* Do a number of random writes to the file (using hFile1).
|
---|
2997 | Immediately undoing them. */
|
---|
2998 | for (uint32_t i = 0; i < 128; i++)
|
---|
2999 | {
|
---|
3000 | /* Generate a randomly sized write at a random location, making
|
---|
3001 | sure it differs from whatever is there already before writing. */
|
---|
3002 | uint32_t const cbToWrite = RTRandU32Ex(1, (uint32_t)cbBuf);
|
---|
3003 | uint64_t const offToWrite = RTRandU64Ex(0, cbMapping - cbToWrite);
|
---|
3004 |
|
---|
3005 | fsPerfFillWriteBuf(offToWrite, pbBuf, cbToWrite, 0xf8);
|
---|
3006 | pbBuf[0] = ~pbBuf[0];
|
---|
3007 | if (cbToWrite > 1)
|
---|
3008 | pbBuf[cbToWrite - 1] = ~pbBuf[cbToWrite - 1];
|
---|
3009 | RTTESTI_CHECK_RC(RTFileWriteAt(hFile1, offToWrite, pbBuf, cbToWrite, NULL), VINF_SUCCESS);
|
---|
3010 |
|
---|
3011 | /* Check the mapping. */
|
---|
3012 | if (memcmp(&pbMapping[(size_t)offToWrite], pbBuf, cbToWrite) != 0)
|
---|
3013 | {
|
---|
3014 | RTTestIFailed("Write #%u @ %#RX64 LB %#x was not reflected in the mapping!\n", i, offToWrite, cbToWrite);
|
---|
3015 | }
|
---|
3016 |
|
---|
3017 | /* Restore */
|
---|
3018 | fsPerfFillWriteBuf(offToWrite, pbBuf, cbToWrite, 0xf6);
|
---|
3019 | RTTESTI_CHECK_RC(RTFileWriteAt(hFile1, offToWrite, pbBuf, cbToWrite, NULL), VINF_SUCCESS);
|
---|
3020 | }
|
---|
3021 |
|
---|
3022 | RTMemPageFree(pbBuf, cbBuf);
|
---|
3023 | }
|
---|
3024 | }
|
---|
3025 |
|
---|
3026 | /*
|
---|
3027 | * Unmap it.
|
---|
3028 | */
|
---|
3029 | # ifdef RT_OS_WINDOWS
|
---|
3030 | RTTESTI_CHECK(UnmapViewOfFile(pbMapping));
|
---|
3031 | RTTESTI_CHECK(CloseHandle(hSection));
|
---|
3032 | # else
|
---|
3033 | RTTESTI_CHECK(munmap(pbMapping, cbMapping) == 0);
|
---|
3034 | # endif
|
---|
3035 | }
|
---|
3036 |
|
---|
3037 | /*
|
---|
3038 | * Memory mappings without open handles (pretty common).
|
---|
3039 | */
|
---|
3040 | for (uint32_t i = 0; i < 32; i++)
|
---|
3041 | {
|
---|
3042 | /* Create a new file, 256 KB in size, and fill it with random bytes.
|
---|
3043 | Try uncached access if we can to force the page-in to do actual reads. */
|
---|
3044 | char szFile2[RTPATH_MAX + 32];
|
---|
3045 | memcpy(szFile2, g_szDir, g_cchDir);
|
---|
3046 | RTStrPrintf(&szFile2[g_cchDir], sizeof(szFile2) - g_cchDir, "mmap-%u.noh", i);
|
---|
3047 | RTFILE hFile2 = NIL_RTFILE;
|
---|
3048 | int rc = (i & 3) == 3 ? VERR_TRY_AGAIN
|
---|
3049 | : RTFileOpen(&hFile2, szFile2, RTFILE_O_READWRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_NO_CACHE);
|
---|
3050 | if (RT_FAILURE(rc))
|
---|
3051 | {
|
---|
3052 | RTTESTI_CHECK_RC_BREAK(RTFileOpen(&hFile2, szFile2, RTFILE_O_READWRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE),
|
---|
3053 | VINF_SUCCESS);
|
---|
3054 | }
|
---|
3055 |
|
---|
3056 | static char s_abContent[256*1024];
|
---|
3057 | RTRandBytes(s_abContent, sizeof(s_abContent));
|
---|
3058 | RTTESTI_CHECK_RC(RTFileWrite(hFile2, s_abContent, sizeof(s_abContent), NULL), VINF_SUCCESS);
|
---|
3059 | RTTESTI_CHECK_RC(RTFileClose(hFile2), VINF_SUCCESS);
|
---|
3060 |
|
---|
3061 | /* Reopen the file with normal caching. Every second time, we also
|
---|
3062 | does a read-only open of it to confuse matters. */
|
---|
3063 | RTFILE hFile3 = NIL_RTFILE;
|
---|
3064 | if ((i & 3) == 3)
|
---|
3065 | RTTESTI_CHECK_RC(RTFileOpen(&hFile3, szFile2, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE), VINF_SUCCESS);
|
---|
3066 | hFile2 = NIL_RTFILE;
|
---|
3067 | RTTESTI_CHECK_RC_BREAK(RTFileOpen(&hFile2, szFile2, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE),
|
---|
3068 | VINF_SUCCESS);
|
---|
3069 | if ((i & 3) == 1)
|
---|
3070 | RTTESTI_CHECK_RC(RTFileOpen(&hFile3, szFile2, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE), VINF_SUCCESS);
|
---|
3071 |
|
---|
3072 | /* Memory map it read-write (no COW). */
|
---|
3073 | #ifdef RT_OS_WINDOWS
|
---|
3074 | HANDLE hSection = CreateFileMapping((HANDLE)RTFileToNative(hFile2), NULL, PAGE_READWRITE, 0, sizeof(s_abContent), NULL);
|
---|
3075 | RTTESTI_CHECK_MSG(hSection != NULL, ("last error %u\n", GetLastError));
|
---|
3076 | uint8_t *pbMapping = (uint8_t *)MapViewOfFile(hSection, FILE_MAP_WRITE, 0, 0, sizeof(s_abContent));
|
---|
3077 | RTTESTI_CHECK_MSG(pbMapping != NULL, ("last error %u\n", GetLastError));
|
---|
3078 | RTTESTI_CHECK_MSG(CloseHandle(hSection), ("last error %u\n", GetLastError));
|
---|
3079 | # else
|
---|
3080 | uint8_t *pbMapping = (uint8_t *)mmap(NULL, sizeof(s_abContent), PROT_READ | PROT_WRITE, MAP_SHARED,
|
---|
3081 | (int)RTFileToNative(hFile2), 0);
|
---|
3082 | if ((void *)pbMapping == MAP_FAILED)
|
---|
3083 | pbMapping = NULL;
|
---|
3084 | RTTESTI_CHECK_MSG(pbMapping != NULL, ("errno=%s (%d)\n", strerror(errno), errno));
|
---|
3085 | # endif
|
---|
3086 |
|
---|
3087 | /* Close the file handles. */
|
---|
3088 | if ((i & 7) == 7)
|
---|
3089 | {
|
---|
3090 | RTTESTI_CHECK_RC(RTFileClose(hFile3), VINF_SUCCESS);
|
---|
3091 | hFile3 = NIL_RTFILE;
|
---|
3092 | }
|
---|
3093 | RTTESTI_CHECK_RC(RTFileClose(hFile2), VINF_SUCCESS);
|
---|
3094 | if ((i & 7) == 5)
|
---|
3095 | {
|
---|
3096 | RTTESTI_CHECK_RC(RTFileClose(hFile3), VINF_SUCCESS);
|
---|
3097 | hFile3 = NIL_RTFILE;
|
---|
3098 | }
|
---|
3099 | if (pbMapping)
|
---|
3100 | {
|
---|
3101 | RTThreadSleep(2); /* fudge for cleanup/whatever */
|
---|
3102 |
|
---|
3103 | /* Page in the mapping by comparing with the content we wrote above. */
|
---|
3104 | RTTESTI_CHECK(memcmp(pbMapping, s_abContent, sizeof(s_abContent)) == 0);
|
---|
3105 |
|
---|
3106 | /* Now dirty everything by inverting everything. */
|
---|
3107 | size_t *puCur = (size_t *)pbMapping;
|
---|
3108 | size_t cLeft = sizeof(s_abContent) / sizeof(*puCur);
|
---|
3109 | while (cLeft-- > 0)
|
---|
3110 | {
|
---|
3111 | *puCur = ~*puCur;
|
---|
3112 | puCur++;
|
---|
3113 | }
|
---|
3114 |
|
---|
3115 | /* Sync it all. */
|
---|
3116 | # ifdef RT_OS_WINDOWS
|
---|
3117 | RTTESTI_CHECK(FlushViewOfFile(pbMapping, sizeof(s_abContent)));
|
---|
3118 | # else
|
---|
3119 | RTTESTI_CHECK(msync(pbMapping, sizeof(s_abContent), MS_SYNC) == 0);
|
---|
3120 | # endif
|
---|
3121 |
|
---|
3122 | /* Unmap it. */
|
---|
3123 | # ifdef RT_OS_WINDOWS
|
---|
3124 | RTTESTI_CHECK(UnmapViewOfFile(pbMapping));
|
---|
3125 | # else
|
---|
3126 | RTTESTI_CHECK(munmap(pbMapping, sizeof(s_abContent)) == 0);
|
---|
3127 | # endif
|
---|
3128 | }
|
---|
3129 |
|
---|
3130 | if (hFile3 != NIL_RTFILE)
|
---|
3131 | RTTESTI_CHECK_RC(RTFileClose(hFile3), VINF_SUCCESS);
|
---|
3132 | RTTESTI_CHECK_RC(RTFileDelete(szFile2), VINF_SUCCESS);
|
---|
3133 | }
|
---|
3134 |
|
---|
3135 |
|
---|
3136 | #else
|
---|
3137 | RTTestSkipped(g_hTest, "not supported/implemented");
|
---|
3138 | RT_NOREF(hFile1, hFileNoCache, cbFile);
|
---|
3139 | #endif
|
---|
3140 | }
|
---|
3141 |
|
---|
3142 |
|
---|
3143 | /**
|
---|
3144 | * This does the read, write and seek tests.
|
---|
3145 | */
|
---|
3146 | void fsPerfIo(void)
|
---|
3147 | {
|
---|
3148 | RTTestISub("I/O");
|
---|
3149 |
|
---|
3150 | /*
|
---|
3151 | * Determin the size of the test file.
|
---|
3152 | */
|
---|
3153 | g_szDir[g_cchDir] = '\0';
|
---|
3154 | RTFOFF cbFree = 0;
|
---|
3155 | RTTESTI_CHECK_RC_RETV(RTFsQuerySizes(g_szDir, NULL, &cbFree, NULL, NULL), VINF_SUCCESS);
|
---|
3156 | uint64_t cbFile = g_cbIoFile;
|
---|
3157 | if (cbFile + _16M < (uint64_t)cbFree)
|
---|
3158 | cbFile = RT_ALIGN_64(cbFile, _64K);
|
---|
3159 | else if (cbFree < _32M)
|
---|
3160 | {
|
---|
3161 | RTTestSkipped(g_hTest, "Insufficent free space: %'RU64 bytes, requires >= 32MB", cbFree);
|
---|
3162 | return;
|
---|
3163 | }
|
---|
3164 | else
|
---|
3165 | {
|
---|
3166 | cbFile = cbFree - (cbFree > _128M ? _64M : _16M);
|
---|
3167 | cbFile = RT_ALIGN_64(cbFile, _64K);
|
---|
3168 | RTTestIPrintf(RTTESTLVL_ALWAYS, "Adjusted file size to %'RU64 bytes, due to %'RU64 bytes free.\n", cbFile, cbFree);
|
---|
3169 | }
|
---|
3170 | if (cbFile < _64K)
|
---|
3171 | {
|
---|
3172 | RTTestSkipped(g_hTest, "Specified test file size too small: %'RU64 bytes, requires >= 64KB", cbFile);
|
---|
3173 | return;
|
---|
3174 | }
|
---|
3175 |
|
---|
3176 | /*
|
---|
3177 | * Create a cbFile sized test file.
|
---|
3178 | */
|
---|
3179 | RTFILE hFile1;
|
---|
3180 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file21")),
|
---|
3181 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_READWRITE), VINF_SUCCESS);
|
---|
3182 | RTFILE hFileNoCache;
|
---|
3183 | if (!g_fIgnoreNoCache)
|
---|
3184 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFileNoCache, g_szDir,
|
---|
3185 | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READWRITE | RTFILE_O_NO_CACHE),
|
---|
3186 | VINF_SUCCESS);
|
---|
3187 | else
|
---|
3188 | {
|
---|
3189 | int rc = RTFileOpen(&hFileNoCache, g_szDir, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READWRITE | RTFILE_O_NO_CACHE);
|
---|
3190 | if (RT_FAILURE(rc))
|
---|
3191 | {
|
---|
3192 | RTTestIPrintf(RTTESTLVL_ALWAYS, "Unable to open I/O file with non-cache flag (%Rrc), skipping related tests.\n", rc);
|
---|
3193 | hFileNoCache = NIL_RTFILE;
|
---|
3194 | }
|
---|
3195 | }
|
---|
3196 | RTFILE hFileWriteThru;
|
---|
3197 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFileWriteThru, g_szDir,
|
---|
3198 | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READWRITE | RTFILE_O_WRITE_THROUGH),
|
---|
3199 | VINF_SUCCESS);
|
---|
3200 |
|
---|
3201 | uint8_t *pbFree = NULL;
|
---|
3202 | int rc = fsPerfIoPrepFile(hFile1, cbFile, &pbFree);
|
---|
3203 | RTMemFree(pbFree);
|
---|
3204 | if (RT_SUCCESS(rc))
|
---|
3205 | {
|
---|
3206 | /*
|
---|
3207 | * Do the testing & profiling.
|
---|
3208 | */
|
---|
3209 | if (g_fSeek)
|
---|
3210 | fsPerfIoSeek(hFile1, cbFile);
|
---|
3211 |
|
---|
3212 | if (g_fReadTests)
|
---|
3213 | fsPerfRead(hFile1, hFileNoCache, cbFile);
|
---|
3214 | if (g_fReadPerf)
|
---|
3215 | for (unsigned i = 0; i < g_cIoBlocks; i++)
|
---|
3216 | fsPerfIoReadBlockSize(hFile1, cbFile, g_acbIoBlocks[i]);
|
---|
3217 |
|
---|
3218 | if (g_fMMap)
|
---|
3219 | fsPerfMMap(hFile1, hFileNoCache, cbFile);
|
---|
3220 |
|
---|
3221 | /* This is destructive to the file content. */
|
---|
3222 | if (g_fWriteTests)
|
---|
3223 | fsPerfWrite(hFile1, hFileNoCache, hFileWriteThru, cbFile);
|
---|
3224 | if (g_fWritePerf)
|
---|
3225 | for (unsigned i = 0; i < g_cIoBlocks; i++)
|
---|
3226 | fsPerfIoWriteBlockSize(hFile1, cbFile, g_acbIoBlocks[i]);
|
---|
3227 |
|
---|
3228 | if (g_fFSync)
|
---|
3229 | fsPerfFSync(hFile1, cbFile);
|
---|
3230 | }
|
---|
3231 |
|
---|
3232 | RTTESTI_CHECK_RC(RTFileSetSize(hFile1, 0), VINF_SUCCESS);
|
---|
3233 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
3234 | if (hFileNoCache != NIL_RTFILE || !g_fIgnoreNoCache)
|
---|
3235 | RTTESTI_CHECK_RC(RTFileClose(hFileNoCache), VINF_SUCCESS);
|
---|
3236 | RTTESTI_CHECK_RC(RTFileClose(hFileWriteThru), VINF_SUCCESS);
|
---|
3237 | RTTESTI_CHECK_RC(RTFileDelete(g_szDir), VINF_SUCCESS);
|
---|
3238 | }
|
---|
3239 |
|
---|
3240 |
|
---|
3241 | DECL_FORCE_INLINE(int) fsPerfCopyWorker1(const char *pszSrc, const char *pszDst)
|
---|
3242 | {
|
---|
3243 | RTFileDelete(pszDst);
|
---|
3244 | return RTFileCopy(pszSrc, pszDst);
|
---|
3245 | }
|
---|
3246 |
|
---|
3247 |
|
---|
3248 | #ifdef RT_OS_LINUX
|
---|
3249 | DECL_FORCE_INLINE(int) fsPerfCopyWorkerSendFile(RTFILE hFile1, RTFILE hFile2, size_t cbFile)
|
---|
3250 | {
|
---|
3251 | RTTESTI_CHECK_RC_RET(RTFileSeek(hFile2, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS, rcCheck);
|
---|
3252 |
|
---|
3253 | loff_t off = 0;
|
---|
3254 | ssize_t cbSent = sendfile((int)RTFileToNative(hFile2), (int)RTFileToNative(hFile1), &off, cbFile);
|
---|
3255 | if (cbSent > 0 && (size_t)cbSent == cbFile)
|
---|
3256 | return 0;
|
---|
3257 |
|
---|
3258 | int rc = VERR_GENERAL_FAILURE;
|
---|
3259 | if (cbSent < 0)
|
---|
3260 | {
|
---|
3261 | rc = RTErrConvertFromErrno(errno);
|
---|
3262 | RTTestIFailed("sendfile(file,file,NULL,%#zx) failed (%zd): %d (%Rrc)", cbFile, cbSent, errno, rc);
|
---|
3263 | }
|
---|
3264 | else
|
---|
3265 | RTTestIFailed("sendfile(file,file,NULL,%#zx) returned %#zx, expected %#zx (diff %zd)",
|
---|
3266 | cbFile, cbSent, cbFile, cbSent - cbFile);
|
---|
3267 | return rc;
|
---|
3268 | }
|
---|
3269 | #endif /* RT_OS_LINUX */
|
---|
3270 |
|
---|
3271 |
|
---|
3272 | static void fsPerfCopy(void)
|
---|
3273 | {
|
---|
3274 | RTTestISub("copy");
|
---|
3275 |
|
---|
3276 | /*
|
---|
3277 | * Non-existing files.
|
---|
3278 | */
|
---|
3279 | RTTESTI_CHECK_RC(RTFileCopy(InEmptyDir(RT_STR_TUPLE("no-such-file")),
|
---|
3280 | InDir2(RT_STR_TUPLE("whatever"))), VERR_FILE_NOT_FOUND);
|
---|
3281 | RTTESTI_CHECK_RC(RTFileCopy(InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file")),
|
---|
3282 | InDir2(RT_STR_TUPLE("no-such-file"))), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
3283 | RTTESTI_CHECK_RC(RTFileCopy(InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file")),
|
---|
3284 | InDir2(RT_STR_TUPLE("whatever"))), VERR_PATH_NOT_FOUND);
|
---|
3285 |
|
---|
3286 | RTTESTI_CHECK_RC(RTFileCopy(InDir(RT_STR_TUPLE("known-file")),
|
---|
3287 | InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file"))), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
3288 | RTTESTI_CHECK_RC(RTFileCopy(InDir(RT_STR_TUPLE("known-file")),
|
---|
3289 | InDir2(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file"))), VERR_PATH_NOT_FOUND);
|
---|
3290 |
|
---|
3291 | /*
|
---|
3292 | * Determin the size of the test file.
|
---|
3293 | * We want to be able to make 1 copy of it.
|
---|
3294 | */
|
---|
3295 | g_szDir[g_cchDir] = '\0';
|
---|
3296 | RTFOFF cbFree = 0;
|
---|
3297 | RTTESTI_CHECK_RC_RETV(RTFsQuerySizes(g_szDir, NULL, &cbFree, NULL, NULL), VINF_SUCCESS);
|
---|
3298 | uint64_t cbFile = g_cbIoFile;
|
---|
3299 | if (cbFile + _16M < (uint64_t)cbFree)
|
---|
3300 | cbFile = RT_ALIGN_64(cbFile, _64K);
|
---|
3301 | else if (cbFree < _32M)
|
---|
3302 | {
|
---|
3303 | RTTestSkipped(g_hTest, "Insufficent free space: %'RU64 bytes, requires >= 32MB", cbFree);
|
---|
3304 | return;
|
---|
3305 | }
|
---|
3306 | else
|
---|
3307 | {
|
---|
3308 | cbFile = cbFree - (cbFree > _128M ? _64M : _16M);
|
---|
3309 | cbFile = RT_ALIGN_64(cbFile, _64K);
|
---|
3310 | RTTestIPrintf(RTTESTLVL_ALWAYS, "Adjusted file size to %'RU64 bytes, due to %'RU64 bytes free.\n", cbFile, cbFree);
|
---|
3311 | }
|
---|
3312 | if (cbFile < _512K * 2)
|
---|
3313 | {
|
---|
3314 | RTTestSkipped(g_hTest, "Specified test file size too small: %'RU64 bytes, requires >= 1MB", cbFile);
|
---|
3315 | return;
|
---|
3316 | }
|
---|
3317 | cbFile /= 2;
|
---|
3318 |
|
---|
3319 | /*
|
---|
3320 | * Create a cbFile sized test file.
|
---|
3321 | */
|
---|
3322 | RTFILE hFile1;
|
---|
3323 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file22")),
|
---|
3324 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_READWRITE), VINF_SUCCESS);
|
---|
3325 | uint8_t *pbFree = NULL;
|
---|
3326 | int rc = fsPerfIoPrepFile(hFile1, cbFile, &pbFree);
|
---|
3327 | RTMemFree(pbFree);
|
---|
3328 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
3329 | if (RT_SUCCESS(rc))
|
---|
3330 | {
|
---|
3331 | /*
|
---|
3332 | * Make copies.
|
---|
3333 | */
|
---|
3334 | /* plain */
|
---|
3335 | RTFileDelete(InDir2(RT_STR_TUPLE("file23")));
|
---|
3336 | RTTESTI_CHECK_RC(RTFileCopy(g_szDir, g_szDir2), VINF_SUCCESS);
|
---|
3337 | RTTESTI_CHECK_RC(RTFileCopy(g_szDir, g_szDir2), VERR_ALREADY_EXISTS);
|
---|
3338 | RTTESTI_CHECK_RC(RTFileCompare(g_szDir, g_szDir2), VINF_SUCCESS);
|
---|
3339 |
|
---|
3340 | /* by handle */
|
---|
3341 | hFile1 = NIL_RTFILE;
|
---|
3342 | RTTESTI_CHECK_RC(RTFileOpen(&hFile1, g_szDir, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ), VINF_SUCCESS);
|
---|
3343 | RTFILE hFile2 = NIL_RTFILE;
|
---|
3344 | RTTESTI_CHECK_RC(RTFileOpen(&hFile2, g_szDir2, RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
3345 | RTTESTI_CHECK_RC(RTFileCopyByHandles(hFile1, hFile2), VINF_SUCCESS);
|
---|
3346 | RTTESTI_CHECK_RC(RTFileClose(hFile2), VINF_SUCCESS);
|
---|
3347 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
3348 | RTTESTI_CHECK_RC(RTFileCompare(g_szDir, g_szDir2), VINF_SUCCESS);
|
---|
3349 |
|
---|
3350 | /* copy part */
|
---|
3351 | hFile1 = NIL_RTFILE;
|
---|
3352 | RTTESTI_CHECK_RC(RTFileOpen(&hFile1, g_szDir, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ), VINF_SUCCESS);
|
---|
3353 | hFile2 = NIL_RTFILE;
|
---|
3354 | RTTESTI_CHECK_RC(RTFileOpen(&hFile2, g_szDir2, RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
3355 | RTTESTI_CHECK_RC(RTFileCopyPart(hFile1, 0, hFile2, 0, cbFile / 2, 0, NULL), VINF_SUCCESS);
|
---|
3356 | RTTESTI_CHECK_RC(RTFileCopyPart(hFile1, cbFile / 2, hFile2, cbFile / 2, cbFile - cbFile / 2, 0, NULL), VINF_SUCCESS);
|
---|
3357 | RTTESTI_CHECK_RC(RTFileClose(hFile2), VINF_SUCCESS);
|
---|
3358 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
3359 | RTTESTI_CHECK_RC(RTFileCompare(g_szDir, g_szDir2), VINF_SUCCESS);
|
---|
3360 |
|
---|
3361 | #ifdef RT_OS_LINUX
|
---|
3362 | /*
|
---|
3363 | * On linux we can also use sendfile between two files, except for 2.5.x to 2.6.33.
|
---|
3364 | */
|
---|
3365 | char szRelease[64];
|
---|
3366 | RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szRelease, sizeof(szRelease));
|
---|
3367 | bool const fSendFileBetweenFiles = RTStrVersionCompare(szRelease, "2.5.0") < 0
|
---|
3368 | || RTStrVersionCompare(szRelease, "2.6.33") >= 0;
|
---|
3369 | if (fSendFileBetweenFiles)
|
---|
3370 | {
|
---|
3371 | /* Copy the whole file: */
|
---|
3372 | hFile1 = NIL_RTFILE;
|
---|
3373 | RTTESTI_CHECK_RC(RTFileOpen(&hFile1, g_szDir, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ), VINF_SUCCESS);
|
---|
3374 | RTFileDelete(g_szDir2);
|
---|
3375 | hFile2 = NIL_RTFILE;
|
---|
3376 | RTTESTI_CHECK_RC(RTFileOpen(&hFile2, g_szDir2, RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
3377 | ssize_t cbSent = sendfile((int)RTFileToNative(hFile2), (int)RTFileToNative(hFile1), NULL, cbFile);
|
---|
3378 | if (cbSent < 0)
|
---|
3379 | RTTestIFailed("sendfile(file,file,NULL,%#zx) failed (%zd): %d (%Rrc)",
|
---|
3380 | cbFile, cbSent, errno, RTErrConvertFromErrno(errno));
|
---|
3381 | else if ((size_t)cbSent != cbFile)
|
---|
3382 | RTTestIFailed("sendfile(file,file,NULL,%#zx) returned %#zx, expected %#zx (diff %zd)",
|
---|
3383 | cbFile, cbSent, cbFile, cbSent - cbFile);
|
---|
3384 | RTTESTI_CHECK_RC(RTFileClose(hFile2), VINF_SUCCESS);
|
---|
3385 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
3386 | RTTESTI_CHECK_RC(RTFileCompare(g_szDir, g_szDir2), VINF_SUCCESS);
|
---|
3387 |
|
---|
3388 | /* Try copy a little bit too much: */
|
---|
3389 | hFile1 = NIL_RTFILE;
|
---|
3390 | RTTESTI_CHECK_RC(RTFileOpen(&hFile1, g_szDir, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ), VINF_SUCCESS);
|
---|
3391 | RTFileDelete(g_szDir2);
|
---|
3392 | hFile2 = NIL_RTFILE;
|
---|
3393 | RTTESTI_CHECK_RC(RTFileOpen(&hFile2, g_szDir2, RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
3394 | size_t cbToCopy = cbFile + RTRandU32Ex(1, _64M);
|
---|
3395 | cbSent = sendfile((int)RTFileToNative(hFile2), (int)RTFileToNative(hFile1), NULL, cbToCopy);
|
---|
3396 | if (cbSent < 0)
|
---|
3397 | RTTestIFailed("sendfile(file,file,NULL,%#zx) failed (%zd): %d (%Rrc)",
|
---|
3398 | cbToCopy, cbSent, errno, RTErrConvertFromErrno(errno));
|
---|
3399 | else if ((size_t)cbSent != cbFile)
|
---|
3400 | RTTestIFailed("sendfile(file,file,NULL,%#zx) returned %#zx, expected %#zx (diff %zd)",
|
---|
3401 | cbToCopy, cbSent, cbFile, cbSent - cbFile);
|
---|
3402 | RTTESTI_CHECK_RC(RTFileClose(hFile2), VINF_SUCCESS);
|
---|
3403 | RTTESTI_CHECK_RC(RTFileCompare(g_szDir, g_szDir2), VINF_SUCCESS);
|
---|
3404 |
|
---|
3405 | /* Do partial copy: */
|
---|
3406 | hFile2 = NIL_RTFILE;
|
---|
3407 | RTTESTI_CHECK_RC(RTFileOpen(&hFile2, g_szDir2, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
3408 | for (uint32_t i = 0; i < 64; i++)
|
---|
3409 | {
|
---|
3410 | cbToCopy = RTRandU32Ex(0, cbFile - 1);
|
---|
3411 | uint32_t const offFile = RTRandU32Ex(1, (uint64_t)RT_MIN(cbFile - cbToCopy, UINT32_MAX));
|
---|
3412 | RTTESTI_CHECK_RC_BREAK(RTFileSeek(hFile2, offFile, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
3413 | loff_t offFile2 = offFile;
|
---|
3414 | cbSent = sendfile((int)RTFileToNative(hFile2), (int)RTFileToNative(hFile1), &offFile2, cbToCopy);
|
---|
3415 | if (cbSent < 0)
|
---|
3416 | RTTestIFailed("sendfile(file,file,%#x,%#zx) failed (%zd): %d (%Rrc)",
|
---|
3417 | offFile, cbToCopy, cbSent, errno, RTErrConvertFromErrno(errno));
|
---|
3418 | else if ((size_t)cbSent != cbToCopy)
|
---|
3419 | RTTestIFailed("sendfile(file,file,%#x,%#zx) returned %#zx, expected %#zx (diff %zd)",
|
---|
3420 | offFile, cbToCopy, cbSent, cbToCopy, cbSent - cbToCopy);
|
---|
3421 | else if (offFile2 != (loff_t)(offFile + cbToCopy))
|
---|
3422 | RTTestIFailed("sendfile(file,file,%#x,%#zx) returned %#zx + off=%#RX64, expected off %#x",
|
---|
3423 | offFile, cbToCopy, cbSent, offFile2, offFile + cbToCopy);
|
---|
3424 | }
|
---|
3425 | RTTESTI_CHECK_RC(RTFileClose(hFile2), VINF_SUCCESS);
|
---|
3426 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
3427 | RTTESTI_CHECK_RC(RTFileCompare(g_szDir, g_szDir2), VINF_SUCCESS);
|
---|
3428 | }
|
---|
3429 | #endif
|
---|
3430 |
|
---|
3431 | /*
|
---|
3432 | * Do some benchmarking.
|
---|
3433 | */
|
---|
3434 | #define PROFILE_COPY_FN(a_szOperation, a_fnCall) \
|
---|
3435 | do \
|
---|
3436 | { \
|
---|
3437 | /* Estimate how many iterations we need to fill up the given timeslot: */ \
|
---|
3438 | fsPerfYield(); \
|
---|
3439 | uint64_t nsStart = RTTimeNanoTS(); \
|
---|
3440 | uint64_t ns; \
|
---|
3441 | do \
|
---|
3442 | ns = RTTimeNanoTS(); \
|
---|
3443 | while (ns == nsStart); \
|
---|
3444 | nsStart = ns; \
|
---|
3445 | \
|
---|
3446 | uint64_t iIteration = 0; \
|
---|
3447 | do \
|
---|
3448 | { \
|
---|
3449 | RTTESTI_CHECK_RC(a_fnCall, VINF_SUCCESS); \
|
---|
3450 | iIteration++; \
|
---|
3451 | ns = RTTimeNanoTS() - nsStart; \
|
---|
3452 | } while (ns < RT_NS_10MS); \
|
---|
3453 | ns /= iIteration; \
|
---|
3454 | if (ns > g_nsPerNanoTSCall + 32) \
|
---|
3455 | ns -= g_nsPerNanoTSCall; \
|
---|
3456 | uint64_t cIterations = g_nsTestRun / ns; \
|
---|
3457 | if (cIterations < 2) \
|
---|
3458 | cIterations = 2; \
|
---|
3459 | else if (cIterations & 1) \
|
---|
3460 | cIterations++; \
|
---|
3461 | \
|
---|
3462 | /* Do the actual profiling: */ \
|
---|
3463 | iIteration = 0; \
|
---|
3464 | fsPerfYield(); \
|
---|
3465 | nsStart = RTTimeNanoTS(); \
|
---|
3466 | for (uint32_t iAdjust = 0; iAdjust < 4; iAdjust++) \
|
---|
3467 | { \
|
---|
3468 | for (; iIteration < cIterations; iIteration++)\
|
---|
3469 | RTTESTI_CHECK_RC(a_fnCall, VINF_SUCCESS); \
|
---|
3470 | ns = RTTimeNanoTS() - nsStart;\
|
---|
3471 | if (ns >= g_nsTestRun - (g_nsTestRun / 10)) \
|
---|
3472 | break; \
|
---|
3473 | cIterations += cIterations / 4; \
|
---|
3474 | if (cIterations & 1) \
|
---|
3475 | cIterations++; \
|
---|
3476 | nsStart += g_nsPerNanoTSCall; \
|
---|
3477 | } \
|
---|
3478 | RTTestIValueF(ns / iIteration, \
|
---|
3479 | RTTESTUNIT_NS_PER_OCCURRENCE, a_szOperation " latency"); \
|
---|
3480 | RTTestIValueF((uint64_t)((uint64_t)iIteration * cbFile / ((double)ns / RT_NS_1SEC)), \
|
---|
3481 | RTTESTUNIT_BYTES_PER_SEC, a_szOperation " throughput"); \
|
---|
3482 | RTTestIValueF((uint64_t)iIteration * cbFile, \
|
---|
3483 | RTTESTUNIT_BYTES, a_szOperation " bytes"); \
|
---|
3484 | RTTestIValueF(iIteration, \
|
---|
3485 | RTTESTUNIT_OCCURRENCES, a_szOperation " iterations"); \
|
---|
3486 | if (g_fShowDuration) \
|
---|
3487 | RTTestIValueF(ns, RTTESTUNIT_NS, a_szOperation " duration"); \
|
---|
3488 | } while (0)
|
---|
3489 |
|
---|
3490 | PROFILE_COPY_FN("RTFileCopy/Replace", fsPerfCopyWorker1(g_szDir, g_szDir2));
|
---|
3491 |
|
---|
3492 | hFile1 = NIL_RTFILE;
|
---|
3493 | RTTESTI_CHECK_RC(RTFileOpen(&hFile1, g_szDir, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ), VINF_SUCCESS);
|
---|
3494 | RTFileDelete(g_szDir2);
|
---|
3495 | hFile2 = NIL_RTFILE;
|
---|
3496 | RTTESTI_CHECK_RC(RTFileOpen(&hFile2, g_szDir2, RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
3497 | PROFILE_COPY_FN("RTFileCopyByHandles/Overwrite", RTFileCopyByHandles(hFile1, hFile2));
|
---|
3498 | RTTESTI_CHECK_RC(RTFileClose(hFile2), VINF_SUCCESS);
|
---|
3499 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
3500 |
|
---|
3501 | /* We could benchmark RTFileCopyPart with various block sizes and whatnot...
|
---|
3502 | But it's currently well covered by the two previous operations. */
|
---|
3503 |
|
---|
3504 | #ifdef RT_OS_LINUX
|
---|
3505 | if (fSendFileBetweenFiles)
|
---|
3506 | {
|
---|
3507 | hFile1 = NIL_RTFILE;
|
---|
3508 | RTTESTI_CHECK_RC(RTFileOpen(&hFile1, g_szDir, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ), VINF_SUCCESS);
|
---|
3509 | RTFileDelete(g_szDir2);
|
---|
3510 | hFile2 = NIL_RTFILE;
|
---|
3511 | RTTESTI_CHECK_RC(RTFileOpen(&hFile2, g_szDir2, RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
3512 | PROFILE_COPY_FN("sendfile/overwrite", fsPerfCopyWorkerSendFile(hFile1, hFile2, cbFile));
|
---|
3513 | RTTESTI_CHECK_RC(RTFileClose(hFile2), VINF_SUCCESS);
|
---|
3514 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
3515 | }
|
---|
3516 | #endif
|
---|
3517 |
|
---|
3518 | }
|
---|
3519 |
|
---|
3520 | /*
|
---|
3521 | * Clean up.
|
---|
3522 | */
|
---|
3523 | RTFileDelete(InDir2(RT_STR_TUPLE("file22c1")));
|
---|
3524 | RTFileDelete(InDir2(RT_STR_TUPLE("file22c2")));
|
---|
3525 | RTFileDelete(InDir2(RT_STR_TUPLE("file22c3")));
|
---|
3526 | RTTESTI_CHECK_RC(RTFileDelete(g_szDir), VINF_SUCCESS);
|
---|
3527 | }
|
---|
3528 |
|
---|
3529 |
|
---|
3530 | /**
|
---|
3531 | * Display the usage to @a pStrm.
|
---|
3532 | */
|
---|
3533 | static void Usage(PRTSTREAM pStrm)
|
---|
3534 | {
|
---|
3535 | char szExec[RTPATH_MAX];
|
---|
3536 | RTStrmPrintf(pStrm, "usage: %s <-d <testdir>> [options]\n",
|
---|
3537 | RTPathFilename(RTProcGetExecutablePath(szExec, sizeof(szExec))));
|
---|
3538 | RTStrmPrintf(pStrm, "\n");
|
---|
3539 | RTStrmPrintf(pStrm, "options: \n");
|
---|
3540 |
|
---|
3541 | for (unsigned i = 0; i < RT_ELEMENTS(g_aCmdOptions); i++)
|
---|
3542 | {
|
---|
3543 | char szHelp[80];
|
---|
3544 | const char *pszHelp;
|
---|
3545 | switch (g_aCmdOptions[i].iShort)
|
---|
3546 | {
|
---|
3547 | case 'd': pszHelp = "The directory to use for testing. default: CWD/fstestdir"; break;
|
---|
3548 | case 'e': pszHelp = "Enables all tests. default: -e"; break;
|
---|
3549 | case 'z': pszHelp = "Disables all tests. default: -e"; break;
|
---|
3550 | case 's': pszHelp = "Set benchmark duration in seconds. default: 10 sec"; break;
|
---|
3551 | case 'm': pszHelp = "Set benchmark duration in milliseconds. default: 10000 ms"; break;
|
---|
3552 | case 'v': pszHelp = "More verbose execution."; break;
|
---|
3553 | case 'q': pszHelp = "Quiet execution."; break;
|
---|
3554 | case 'h': pszHelp = "Displays this help and exit"; break;
|
---|
3555 | case 'V': pszHelp = "Displays the program revision"; break;
|
---|
3556 | case kCmdOpt_ShowDuration: pszHelp = "Show duration of profile runs. default: --no-show-duration"; break;
|
---|
3557 | case kCmdOpt_NoShowDuration: pszHelp = "Hide duration of profile runs. default: --no-show-duration"; break;
|
---|
3558 | case kCmdOpt_ShowIterations: pszHelp = "Show iteration count for profile runs. default: --no-show-iterations"; break;
|
---|
3559 | case kCmdOpt_NoShowIterations: pszHelp = "Hide iteration count for profile runs. default: --no-show-iterations"; break;
|
---|
3560 | case kCmdOpt_ManyFiles: pszHelp = "Count of files in big test dir. default: --many-files 10000"; break;
|
---|
3561 | case kCmdOpt_NoManyFiles: pszHelp = "Skip big test dir with many files. default: --many-files 10000"; break;
|
---|
3562 | case kCmdOpt_ManyTreeFilesPerDir: pszHelp = "Count of files per directory in test tree. default: 640"; break;
|
---|
3563 | case kCmdOpt_ManyTreeSubdirsPerDir: pszHelp = "Count of subdirs per directory in test tree. default: 16"; break;
|
---|
3564 | case kCmdOpt_ManyTreeDepth: pszHelp = "Depth of test tree (not counting root). default: 1"; break;
|
---|
3565 | case kCmdOpt_IgnoreNoCache: pszHelp = "Ignore error wrt no-cache handle. default: --no-ignore-no-cache"; break;
|
---|
3566 | case kCmdOpt_NoIgnoreNoCache: pszHelp = "Do not ignore error wrt no-cache handle. default: --no-ignore-no-cache"; break;
|
---|
3567 | case kCmdOpt_IoFileSize: pszHelp = "Size of file used for I/O tests. default: 512 MB"; break;
|
---|
3568 | case kCmdOpt_SetBlockSize: pszHelp = "Sets single I/O block size (in bytes)."; break;
|
---|
3569 | case kCmdOpt_AddBlockSize: pszHelp = "Adds an I/O block size (in bytes)."; break;
|
---|
3570 | default:
|
---|
3571 | if (g_aCmdOptions[i].iShort >= kCmdOpt_First)
|
---|
3572 | {
|
---|
3573 | if (RTStrStartsWith(g_aCmdOptions[i].pszLong, "--no-"))
|
---|
3574 | RTStrPrintf(szHelp, sizeof(szHelp), "Disables the '%s' test.", g_aCmdOptions[i].pszLong + 5);
|
---|
3575 | else
|
---|
3576 | RTStrPrintf(szHelp, sizeof(szHelp), "Enables the '%s' test.", g_aCmdOptions[i].pszLong + 2);
|
---|
3577 | pszHelp = szHelp;
|
---|
3578 | }
|
---|
3579 | else
|
---|
3580 | pszHelp = "Option undocumented";
|
---|
3581 | break;
|
---|
3582 | }
|
---|
3583 | if ((unsigned)g_aCmdOptions[i].iShort < 127U)
|
---|
3584 | {
|
---|
3585 | char szOpt[64];
|
---|
3586 | RTStrPrintf(szOpt, sizeof(szOpt), "%s, -%c", g_aCmdOptions[i].pszLong, g_aCmdOptions[i].iShort);
|
---|
3587 | RTStrmPrintf(pStrm, " %-19s %s\n", szOpt, pszHelp);
|
---|
3588 | }
|
---|
3589 | else
|
---|
3590 | RTStrmPrintf(pStrm, " %-19s %s\n", g_aCmdOptions[i].pszLong, pszHelp);
|
---|
3591 | }
|
---|
3592 | }
|
---|
3593 |
|
---|
3594 |
|
---|
3595 | static uint32_t fsPerfCalcManyTreeFiles(void)
|
---|
3596 | {
|
---|
3597 | uint32_t cDirs = 1;
|
---|
3598 | for (uint32_t i = 0, cDirsAtLevel = 1; i < g_cManyTreeDepth; i++)
|
---|
3599 | {
|
---|
3600 | cDirs += cDirsAtLevel * g_cManyTreeSubdirsPerDir;
|
---|
3601 | cDirsAtLevel *= g_cManyTreeSubdirsPerDir;
|
---|
3602 | }
|
---|
3603 | return g_cManyTreeFilesPerDir * cDirs;
|
---|
3604 | }
|
---|
3605 |
|
---|
3606 |
|
---|
3607 | int main(int argc, char *argv[])
|
---|
3608 | {
|
---|
3609 | /*
|
---|
3610 | * Init IPRT and globals.
|
---|
3611 | */
|
---|
3612 | int rc = RTTestInitAndCreate("FsPerf", &g_hTest);
|
---|
3613 | if (rc)
|
---|
3614 | return rc;
|
---|
3615 | RTListInit(&g_ManyTreeHead);
|
---|
3616 |
|
---|
3617 | /*
|
---|
3618 | * Default values.
|
---|
3619 | */
|
---|
3620 | rc = RTPathGetCurrent(g_szDir, sizeof(g_szDir) / 2);
|
---|
3621 | if (RT_SUCCESS(rc))
|
---|
3622 | rc = RTPathAppend(g_szDir, sizeof(g_szDir) / 2, "fstestdir-");
|
---|
3623 | if (RT_SUCCESS(rc))
|
---|
3624 | {
|
---|
3625 | g_cchDir = strlen(g_szDir);
|
---|
3626 | g_cchDir += RTStrPrintf(&g_szDir[g_cchDir], sizeof(g_szDir) - g_cchDir, "%u" RTPATH_SLASH_STR, RTProcSelf());
|
---|
3627 | }
|
---|
3628 | else
|
---|
3629 | {
|
---|
3630 | RTTestFailed(g_hTest, "RTPathGetCurrent (or RTPathAppend) failed: %Rrc\n", rc);
|
---|
3631 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
3632 | }
|
---|
3633 |
|
---|
3634 | RTGETOPTUNION ValueUnion;
|
---|
3635 | RTGETOPTSTATE GetState;
|
---|
3636 | RTGetOptInit(&GetState, argc, argv, g_aCmdOptions, RT_ELEMENTS(g_aCmdOptions), 1, 0 /* fFlags */);
|
---|
3637 | while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
|
---|
3638 | {
|
---|
3639 | switch (rc)
|
---|
3640 | {
|
---|
3641 | case 'd':
|
---|
3642 | rc = RTPathAbs(ValueUnion.psz, g_szDir, sizeof(g_szDir) / 2);
|
---|
3643 | if (RT_SUCCESS(rc))
|
---|
3644 | {
|
---|
3645 | RTPathEnsureTrailingSeparator(g_szDir, sizeof(g_szDir));
|
---|
3646 | g_cchDir = strlen(g_szDir);
|
---|
3647 | break;
|
---|
3648 | }
|
---|
3649 | RTTestFailed(g_hTest, "RTPathAbs(%s) failed: %Rrc\n", ValueUnion.psz, rc);
|
---|
3650 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
3651 |
|
---|
3652 | case 's':
|
---|
3653 | if (ValueUnion.u32 == 0)
|
---|
3654 | g_nsTestRun = RT_NS_1SEC_64 * 10;
|
---|
3655 | else
|
---|
3656 | g_nsTestRun = ValueUnion.u32 * RT_NS_1SEC_64;
|
---|
3657 | break;
|
---|
3658 |
|
---|
3659 | case 'm':
|
---|
3660 | if (ValueUnion.u64 == 0)
|
---|
3661 | g_nsTestRun = RT_NS_1SEC_64 * 10;
|
---|
3662 | else
|
---|
3663 | g_nsTestRun = ValueUnion.u64 * RT_NS_1MS;
|
---|
3664 | break;
|
---|
3665 |
|
---|
3666 | case 'e':
|
---|
3667 | g_fManyFiles = true;
|
---|
3668 | g_fOpen = true;
|
---|
3669 | g_fFStat = true;
|
---|
3670 | g_fFChMod = true;
|
---|
3671 | g_fFUtimes = true;
|
---|
3672 | g_fStat = true;
|
---|
3673 | g_fChMod = true;
|
---|
3674 | g_fUtimes = true;
|
---|
3675 | g_fRename = true;
|
---|
3676 | g_fDirOpen = true;
|
---|
3677 | g_fDirEnum = true;
|
---|
3678 | g_fMkRmDir = true;
|
---|
3679 | g_fStatVfs = true;
|
---|
3680 | g_fRm = true;
|
---|
3681 | g_fChSize = true;
|
---|
3682 | g_fReadTests = true;
|
---|
3683 | g_fReadPerf = true;
|
---|
3684 | g_fWriteTests= true;
|
---|
3685 | g_fWritePerf = true;
|
---|
3686 | g_fSeek = true;
|
---|
3687 | g_fFSync = true;
|
---|
3688 | g_fMMap = true;
|
---|
3689 | g_fCopy = true;
|
---|
3690 | break;
|
---|
3691 |
|
---|
3692 | case 'z':
|
---|
3693 | g_fManyFiles = false;
|
---|
3694 | g_fOpen = false;
|
---|
3695 | g_fFStat = false;
|
---|
3696 | g_fFChMod = false;
|
---|
3697 | g_fFUtimes = false;
|
---|
3698 | g_fStat = false;
|
---|
3699 | g_fChMod = false;
|
---|
3700 | g_fUtimes = false;
|
---|
3701 | g_fRename = false;
|
---|
3702 | g_fDirOpen = false;
|
---|
3703 | g_fDirEnum = false;
|
---|
3704 | g_fMkRmDir = false;
|
---|
3705 | g_fStatVfs = false;
|
---|
3706 | g_fRm = false;
|
---|
3707 | g_fChSize = false;
|
---|
3708 | g_fReadTests = false;
|
---|
3709 | g_fReadPerf = false;
|
---|
3710 | g_fWriteTests= false;
|
---|
3711 | g_fWritePerf = false;
|
---|
3712 | g_fSeek = false;
|
---|
3713 | g_fFSync = false;
|
---|
3714 | g_fMMap = false;
|
---|
3715 | g_fCopy = false;
|
---|
3716 | break;
|
---|
3717 |
|
---|
3718 | #define CASE_OPT(a_Stem) \
|
---|
3719 | case RT_CONCAT(kCmdOpt_,a_Stem): RT_CONCAT(g_f,a_Stem) = true; break; \
|
---|
3720 | case RT_CONCAT(kCmdOpt_No,a_Stem): RT_CONCAT(g_f,a_Stem) = false; break
|
---|
3721 | CASE_OPT(Open);
|
---|
3722 | CASE_OPT(FStat);
|
---|
3723 | CASE_OPT(FChMod);
|
---|
3724 | CASE_OPT(FUtimes);
|
---|
3725 | CASE_OPT(Stat);
|
---|
3726 | CASE_OPT(ChMod);
|
---|
3727 | CASE_OPT(Utimes);
|
---|
3728 | CASE_OPT(Rename);
|
---|
3729 | CASE_OPT(DirOpen);
|
---|
3730 | CASE_OPT(DirEnum);
|
---|
3731 | CASE_OPT(MkRmDir);
|
---|
3732 | CASE_OPT(StatVfs);
|
---|
3733 | CASE_OPT(Rm);
|
---|
3734 | CASE_OPT(ChSize);
|
---|
3735 | CASE_OPT(ReadTests);
|
---|
3736 | CASE_OPT(ReadPerf);
|
---|
3737 | CASE_OPT(WriteTests);
|
---|
3738 | CASE_OPT(WritePerf);
|
---|
3739 | CASE_OPT(Seek);
|
---|
3740 | CASE_OPT(FSync);
|
---|
3741 | CASE_OPT(MMap);
|
---|
3742 | CASE_OPT(IgnoreNoCache);
|
---|
3743 | CASE_OPT(Copy);
|
---|
3744 |
|
---|
3745 | CASE_OPT(ShowDuration);
|
---|
3746 | CASE_OPT(ShowIterations);
|
---|
3747 | #undef CASE_OPT
|
---|
3748 |
|
---|
3749 | case kCmdOpt_ManyFiles:
|
---|
3750 | g_fManyFiles = ValueUnion.u32 > 0;
|
---|
3751 | g_cManyFiles = ValueUnion.u32;
|
---|
3752 | break;
|
---|
3753 |
|
---|
3754 | case kCmdOpt_NoManyFiles:
|
---|
3755 | g_fManyFiles = false;
|
---|
3756 | break;
|
---|
3757 |
|
---|
3758 | case kCmdOpt_ManyTreeFilesPerDir:
|
---|
3759 | if (ValueUnion.u32 > 0 && ValueUnion.u32 <= _64M)
|
---|
3760 | {
|
---|
3761 | g_cManyTreeFilesPerDir = ValueUnion.u32;
|
---|
3762 | g_cManyTreeFiles = fsPerfCalcManyTreeFiles();
|
---|
3763 | break;
|
---|
3764 | }
|
---|
3765 | RTTestFailed(g_hTest, "Out of range --files-per-dir value: %u (%#x)\n", ValueUnion.u32, ValueUnion.u32);
|
---|
3766 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
3767 |
|
---|
3768 | case kCmdOpt_ManyTreeSubdirsPerDir:
|
---|
3769 | if (ValueUnion.u32 > 0 && ValueUnion.u32 <= 1024)
|
---|
3770 | {
|
---|
3771 | g_cManyTreeSubdirsPerDir = ValueUnion.u32;
|
---|
3772 | g_cManyTreeFiles = fsPerfCalcManyTreeFiles();
|
---|
3773 | break;
|
---|
3774 | }
|
---|
3775 | RTTestFailed(g_hTest, "Out of range --subdirs-per-dir value: %u (%#x)\n", ValueUnion.u32, ValueUnion.u32);
|
---|
3776 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
3777 |
|
---|
3778 | case kCmdOpt_ManyTreeDepth:
|
---|
3779 | if (ValueUnion.u32 <= 8)
|
---|
3780 | {
|
---|
3781 | g_cManyTreeDepth = ValueUnion.u32;
|
---|
3782 | g_cManyTreeFiles = fsPerfCalcManyTreeFiles();
|
---|
3783 | break;
|
---|
3784 | }
|
---|
3785 | RTTestFailed(g_hTest, "Out of range --tree-depth value: %u (%#x)\n", ValueUnion.u32, ValueUnion.u32);
|
---|
3786 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
3787 |
|
---|
3788 | case kCmdOpt_IoFileSize:
|
---|
3789 | if (ValueUnion.u64 == 0)
|
---|
3790 | g_cbIoFile = _512M;
|
---|
3791 | else
|
---|
3792 | g_cbIoFile = ValueUnion.u64;
|
---|
3793 | break;
|
---|
3794 |
|
---|
3795 | case kCmdOpt_SetBlockSize:
|
---|
3796 | if (ValueUnion.u32 > 0)
|
---|
3797 | {
|
---|
3798 | g_cIoBlocks = 1;
|
---|
3799 | g_acbIoBlocks[0] = ValueUnion.u32;
|
---|
3800 | }
|
---|
3801 | else
|
---|
3802 | {
|
---|
3803 | RTTestFailed(g_hTest, "Invalid I/O block size: %u (%#x)\n", ValueUnion.u32, ValueUnion.u32);
|
---|
3804 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
3805 | }
|
---|
3806 | break;
|
---|
3807 |
|
---|
3808 | case kCmdOpt_AddBlockSize:
|
---|
3809 | if (g_cIoBlocks >= RT_ELEMENTS(g_acbIoBlocks))
|
---|
3810 | RTTestFailed(g_hTest, "Too many I/O block sizes: max %u\n", RT_ELEMENTS(g_acbIoBlocks));
|
---|
3811 | else if (ValueUnion.u32 == 0)
|
---|
3812 | RTTestFailed(g_hTest, "Invalid I/O block size: %u (%#x)\n", ValueUnion.u32, ValueUnion.u32);
|
---|
3813 | else
|
---|
3814 | {
|
---|
3815 | g_acbIoBlocks[g_cIoBlocks++] = ValueUnion.u32;
|
---|
3816 | break;
|
---|
3817 | }
|
---|
3818 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
3819 |
|
---|
3820 | case 'q':
|
---|
3821 | g_uVerbosity = 0;
|
---|
3822 | break;
|
---|
3823 |
|
---|
3824 | case 'v':
|
---|
3825 | g_uVerbosity++;
|
---|
3826 | break;
|
---|
3827 |
|
---|
3828 | case 'h':
|
---|
3829 | Usage(g_pStdOut);
|
---|
3830 | return RTEXITCODE_SUCCESS;
|
---|
3831 |
|
---|
3832 | case 'V':
|
---|
3833 | {
|
---|
3834 | char szRev[] = "$Revision: 77908 $";
|
---|
3835 | szRev[RT_ELEMENTS(szRev) - 2] = '\0';
|
---|
3836 | RTPrintf(RTStrStrip(strchr(szRev, ':') + 1));
|
---|
3837 | return RTEXITCODE_SUCCESS;
|
---|
3838 | }
|
---|
3839 |
|
---|
3840 | default:
|
---|
3841 | return RTGetOptPrintError(rc, &ValueUnion);
|
---|
3842 | }
|
---|
3843 | }
|
---|
3844 |
|
---|
3845 | /*
|
---|
3846 | * Create the test directory with an 'empty' subdirectory under it,
|
---|
3847 | * execute the tests, and remove directory when done.
|
---|
3848 | */
|
---|
3849 | RTTestBanner(g_hTest);
|
---|
3850 | if (!RTPathExists(g_szDir))
|
---|
3851 | {
|
---|
3852 | /* The base dir: */
|
---|
3853 | rc = RTDirCreate(g_szDir, 0755,
|
---|
3854 | RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_DONT_SET | RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_NOT_CRITICAL);
|
---|
3855 | if (RT_SUCCESS(rc))
|
---|
3856 | {
|
---|
3857 | RTTestIPrintf(RTTESTLVL_ALWAYS, "Test dir: %s\n", g_szDir);
|
---|
3858 | rc = fsPrepTestArea();
|
---|
3859 | if (RT_SUCCESS(rc))
|
---|
3860 | {
|
---|
3861 | /* Profile RTTimeNanoTS(). */
|
---|
3862 | fsPerfNanoTS();
|
---|
3863 |
|
---|
3864 | /* Do tests: */
|
---|
3865 | if (g_fManyFiles)
|
---|
3866 | fsPerfManyFiles();
|
---|
3867 | if (g_fOpen)
|
---|
3868 | fsPerfOpen();
|
---|
3869 | if (g_fFStat)
|
---|
3870 | fsPerfFStat();
|
---|
3871 | if (g_fFChMod)
|
---|
3872 | fsPerfFChMod();
|
---|
3873 | if (g_fFUtimes)
|
---|
3874 | fsPerfFUtimes();
|
---|
3875 | if (g_fStat)
|
---|
3876 | fsPerfStat();
|
---|
3877 | if (g_fChMod)
|
---|
3878 | fsPerfChmod();
|
---|
3879 | if (g_fUtimes)
|
---|
3880 | fsPerfUtimes();
|
---|
3881 | if (g_fRename)
|
---|
3882 | fsPerfRename();
|
---|
3883 | if (g_fDirOpen)
|
---|
3884 | vsPerfDirOpen();
|
---|
3885 | if (g_fDirEnum)
|
---|
3886 | vsPerfDirEnum();
|
---|
3887 | if (g_fMkRmDir)
|
---|
3888 | fsPerfMkRmDir();
|
---|
3889 | if (g_fStatVfs)
|
---|
3890 | fsPerfStatVfs();
|
---|
3891 | if (g_fRm || g_fManyFiles)
|
---|
3892 | fsPerfRm(); /* deletes manyfiles and manytree */
|
---|
3893 | if (g_fChSize)
|
---|
3894 | fsPerfChSize();
|
---|
3895 | if (g_fReadPerf || g_fReadTests || g_fWritePerf || g_fWriteTests || g_fSeek || g_fFSync || g_fMMap)
|
---|
3896 | fsPerfIo();
|
---|
3897 | if (g_fCopy)
|
---|
3898 | fsPerfCopy();
|
---|
3899 | }
|
---|
3900 |
|
---|
3901 | /* Cleanup: */
|
---|
3902 | g_szDir[g_cchDir] = '\0';
|
---|
3903 | rc = RTDirRemoveRecursive(g_szDir, RTDIRRMREC_F_CONTENT_AND_DIR);
|
---|
3904 | if (RT_FAILURE(rc))
|
---|
3905 | RTTestFailed(g_hTest, "RTDirRemoveRecursive(%s,) -> %Rrc\n", g_szDir, rc);
|
---|
3906 | }
|
---|
3907 | else
|
---|
3908 | RTTestFailed(g_hTest, "RTDirCreate(%s) -> %Rrc\n", g_szDir, rc);
|
---|
3909 | }
|
---|
3910 | else
|
---|
3911 | RTTestFailed(g_hTest, "Test directory already exists: %s\n", g_szDir);
|
---|
3912 |
|
---|
3913 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
3914 | }
|
---|
3915 |
|
---|