1 | /* $Id: FsPerf.cpp 77052 2019-01-30 17:38:58Z 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 | #include <iprt/alloca.h>
|
---|
32 | #include <iprt/asm.h>
|
---|
33 | #include <iprt/assert.h>
|
---|
34 | #include <iprt/err.h>
|
---|
35 | #include <iprt/dir.h>
|
---|
36 | #include <iprt/file.h>
|
---|
37 | #include <iprt/getopt.h>
|
---|
38 | #include <iprt/initterm.h>
|
---|
39 | #include <iprt/list.h>
|
---|
40 | #include <iprt/mem.h>
|
---|
41 | #include <iprt/message.h>
|
---|
42 | #include <iprt/param.h>
|
---|
43 | #include <iprt/path.h>
|
---|
44 | #include <iprt/process.h>
|
---|
45 | #include <iprt/rand.h>
|
---|
46 | #include <iprt/string.h>
|
---|
47 | #include <iprt/stream.h>
|
---|
48 | #include <iprt/test.h>
|
---|
49 | #include <iprt/time.h>
|
---|
50 | #include <iprt/thread.h>
|
---|
51 | #include <iprt/zero.h>
|
---|
52 |
|
---|
53 | #ifdef RT_OS_WINDOWS
|
---|
54 | # include <iprt/nt/nt-and-windows.h>
|
---|
55 | #else
|
---|
56 | # include <errno.h>
|
---|
57 | # include <unistd.h>
|
---|
58 | # include <sys/types.h>
|
---|
59 | # include <sys/fcntl.h>
|
---|
60 | # ifndef RT_OS_OS2
|
---|
61 | # include <sys/mman.h>
|
---|
62 | # endif
|
---|
63 | #endif
|
---|
64 |
|
---|
65 |
|
---|
66 | /*********************************************************************************************************************************
|
---|
67 | * Defined Constants And Macros *
|
---|
68 | *********************************************************************************************************************************/
|
---|
69 | /**
|
---|
70 | * Macro for profiling @a a_fnCall (typically forced inline) for about @a a_cNsTarget ns.
|
---|
71 | *
|
---|
72 | * Always does an even number of iterations.
|
---|
73 | */
|
---|
74 | #define PROFILE_FN(a_fnCall, a_cNsTarget, a_szDesc) \
|
---|
75 | do { \
|
---|
76 | /* Estimate how many iterations we need to fill up the given timeslot: */ \
|
---|
77 | fsPerfYield(); \
|
---|
78 | uint64_t nsStart = RTTimeNanoTS(); \
|
---|
79 | uint64_t nsPrf; \
|
---|
80 | do \
|
---|
81 | nsPrf = RTTimeNanoTS(); \
|
---|
82 | while (nsPrf == nsStart); \
|
---|
83 | nsStart = nsPrf; \
|
---|
84 | \
|
---|
85 | uint64_t iIteration = 0; \
|
---|
86 | do \
|
---|
87 | { \
|
---|
88 | RTTESTI_CHECK_RC(a_fnCall, VINF_SUCCESS); \
|
---|
89 | iIteration++; \
|
---|
90 | nsPrf = RTTimeNanoTS() - nsStart; \
|
---|
91 | } while (nsPrf < RT_NS_10MS || (iIteration & 1)); \
|
---|
92 | nsPrf /= iIteration; \
|
---|
93 | if (nsPrf > g_nsPerNanoTSCall + 32) \
|
---|
94 | nsPrf -= g_nsPerNanoTSCall; \
|
---|
95 | \
|
---|
96 | uint64_t cIterations = (a_cNsTarget) / nsPrf; \
|
---|
97 | if (cIterations <= 1) \
|
---|
98 | cIterations = 2; \
|
---|
99 | else if (cIterations & 1) \
|
---|
100 | cIterations++; \
|
---|
101 | \
|
---|
102 | /* Do the actual profiling: */ \
|
---|
103 | fsPerfYield(); \
|
---|
104 | iIteration = 0; \
|
---|
105 | nsStart = RTTimeNanoTS(); \
|
---|
106 | for (; iIteration < cIterations; iIteration++) \
|
---|
107 | RTTESTI_CHECK_RC(a_fnCall, VINF_SUCCESS); \
|
---|
108 | nsPrf = RTTimeNanoTS() - nsStart; \
|
---|
109 | RTTestIValue(a_szDesc, nsPrf / cIterations, RTTESTUNIT_NS_PER_OCCURRENCE); \
|
---|
110 | if (g_fShowDuration) \
|
---|
111 | RTTestIValueF(nsPrf, RTTESTUNIT_NS, "%s duration", a_szDesc); \
|
---|
112 | if (g_fShowIterations) \
|
---|
113 | RTTestIValueF(iIteration, RTTESTUNIT_OCCURRENCES, "%s iterations", a_szDesc); \
|
---|
114 | } while (0)
|
---|
115 |
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Macro for profiling an operation on each file in the manytree directory tree.
|
---|
119 | *
|
---|
120 | * Always does an even number of tree iterations.
|
---|
121 | */
|
---|
122 | #define PROFILE_MANYTREE_FN(a_szPath, a_fnCall, a_cEstimationIterations, a_cNsTarget, a_szDesc) \
|
---|
123 | do { \
|
---|
124 | if (!g_fManyFiles) \
|
---|
125 | break; \
|
---|
126 | \
|
---|
127 | /* Estimate how many iterations we need to fill up the given timeslot: */ \
|
---|
128 | fsPerfYield(); \
|
---|
129 | uint64_t nsStart = RTTimeNanoTS(); \
|
---|
130 | uint64_t ns; \
|
---|
131 | do \
|
---|
132 | ns = RTTimeNanoTS(); \
|
---|
133 | while (ns == nsStart); \
|
---|
134 | nsStart = ns; \
|
---|
135 | \
|
---|
136 | PFSPERFNAMEENTRY pCur; \
|
---|
137 | uint64_t iIteration = 0; \
|
---|
138 | do \
|
---|
139 | { \
|
---|
140 | RTListForEach(&g_ManyTreeHead, pCur, FSPERFNAMEENTRY, Entry) \
|
---|
141 | { \
|
---|
142 | memcpy(a_szPath, pCur->szName, pCur->cchName); \
|
---|
143 | for (uint32_t i = 0; i < g_cManyTreeFilesPerDir; i++) \
|
---|
144 | { \
|
---|
145 | RTStrFormatU32(&a_szPath[pCur->cchName], sizeof(a_szPath) - pCur->cchName, i, 10, 5, 5, RTSTR_F_ZEROPAD); \
|
---|
146 | RTTESTI_CHECK_RC(a_fnCall, VINF_SUCCESS); \
|
---|
147 | } \
|
---|
148 | } \
|
---|
149 | iIteration++; \
|
---|
150 | ns = RTTimeNanoTS() - nsStart; \
|
---|
151 | } while (ns < RT_NS_10MS || (iIteration & 1)); \
|
---|
152 | ns /= iIteration; \
|
---|
153 | if (ns > g_nsPerNanoTSCall + 32) \
|
---|
154 | ns -= g_nsPerNanoTSCall; \
|
---|
155 | \
|
---|
156 | uint32_t cIterations = (a_cNsTarget) / ns; \
|
---|
157 | if (cIterations <= 1) \
|
---|
158 | cIterations = 2; \
|
---|
159 | else if (cIterations & 1) \
|
---|
160 | cIterations++; \
|
---|
161 | \
|
---|
162 | /* Do the actual profiling: */ \
|
---|
163 | fsPerfYield(); \
|
---|
164 | uint32_t cCalls = 0; \
|
---|
165 | nsStart = RTTimeNanoTS(); \
|
---|
166 | for (iIteration = 0; iIteration < cIterations; iIteration++) \
|
---|
167 | { \
|
---|
168 | RTListForEach(&g_ManyTreeHead, pCur, FSPERFNAMEENTRY, Entry) \
|
---|
169 | { \
|
---|
170 | memcpy(a_szPath, pCur->szName, pCur->cchName); \
|
---|
171 | for (uint32_t i = 0; i < g_cManyTreeFilesPerDir; i++) \
|
---|
172 | { \
|
---|
173 | RTStrFormatU32(&a_szPath[pCur->cchName], sizeof(a_szPath) - pCur->cchName, i, 10, 5, 5, RTSTR_F_ZEROPAD); \
|
---|
174 | RTTESTI_CHECK_RC(a_fnCall, VINF_SUCCESS); \
|
---|
175 | cCalls++; \
|
---|
176 | } \
|
---|
177 | } \
|
---|
178 | } \
|
---|
179 | ns = RTTimeNanoTS() - nsStart; \
|
---|
180 | RTTestIValueF(ns / cCalls, RTTESTUNIT_NS_PER_OCCURRENCE, a_szDesc); \
|
---|
181 | if (g_fShowDuration) \
|
---|
182 | RTTestIValueF(ns, RTTESTUNIT_NS, "%s duration", a_szDesc); \
|
---|
183 | if (g_fShowIterations) \
|
---|
184 | RTTestIValueF(iIteration, RTTESTUNIT_OCCURRENCES, "%s iterations", a_szDesc); \
|
---|
185 | } while (0)
|
---|
186 |
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * Execute a_fnCall for each file in the manytree.
|
---|
190 | */
|
---|
191 | #define DO_MANYTREE_FN(a_szPath, a_fnCall) \
|
---|
192 | do { \
|
---|
193 | PFSPERFNAMEENTRY pCur; \
|
---|
194 | RTListForEach(&g_ManyTreeHead, pCur, FSPERFNAMEENTRY, Entry) \
|
---|
195 | { \
|
---|
196 | memcpy(a_szPath, pCur->szName, pCur->cchName); \
|
---|
197 | for (uint32_t i = 0; i < g_cManyTreeFilesPerDir; i++) \
|
---|
198 | { \
|
---|
199 | RTStrFormatU32(&a_szPath[pCur->cchName], sizeof(a_szPath) - pCur->cchName, i, 10, 5, 5, RTSTR_F_ZEROPAD); \
|
---|
200 | a_fnCall; \
|
---|
201 | } \
|
---|
202 | } \
|
---|
203 | } while (0)
|
---|
204 |
|
---|
205 |
|
---|
206 | /** @def FSPERF_VERR_PATH_NOT_FOUND
|
---|
207 | * Hides the fact that we only get VERR_PATH_NOT_FOUND on non-unix systems. */
|
---|
208 | #if defined(RT_OS_WINDOWS) //|| defined(RT_OS_OS2) - using posix APIs IIRC, so lost in translation.
|
---|
209 | # define FSPERF_VERR_PATH_NOT_FOUND VERR_PATH_NOT_FOUND
|
---|
210 | #else
|
---|
211 | # define FSPERF_VERR_PATH_NOT_FOUND VERR_FILE_NOT_FOUND
|
---|
212 | #endif
|
---|
213 |
|
---|
214 |
|
---|
215 | /*********************************************************************************************************************************
|
---|
216 | * Structures and Typedefs *
|
---|
217 | *********************************************************************************************************************************/
|
---|
218 | typedef struct FSPERFNAMEENTRY
|
---|
219 | {
|
---|
220 | RTLISTNODE Entry;
|
---|
221 | uint16_t cchName;
|
---|
222 | char szName[RT_FLEXIBLE_ARRAY];
|
---|
223 | } FSPERFNAMEENTRY;
|
---|
224 | typedef FSPERFNAMEENTRY *PFSPERFNAMEENTRY;
|
---|
225 |
|
---|
226 |
|
---|
227 | enum
|
---|
228 | {
|
---|
229 | kCmdOpt_First = 128,
|
---|
230 |
|
---|
231 | kCmdOpt_ManyFiles = kCmdOpt_First,
|
---|
232 | kCmdOpt_NoManyFiles,
|
---|
233 | kCmdOpt_Open,
|
---|
234 | kCmdOpt_NoOpen,
|
---|
235 | kCmdOpt_FStat,
|
---|
236 | kCmdOpt_NoFStat,
|
---|
237 | kCmdOpt_FChMod,
|
---|
238 | kCmdOpt_NoFChMod,
|
---|
239 | kCmdOpt_FUtimes,
|
---|
240 | kCmdOpt_NoFUtimes,
|
---|
241 | kCmdOpt_Stat,
|
---|
242 | kCmdOpt_NoStat,
|
---|
243 | kCmdOpt_ChMod,
|
---|
244 | kCmdOpt_NoChMod,
|
---|
245 | kCmdOpt_Utimes,
|
---|
246 | kCmdOpt_NoUtimes,
|
---|
247 | kCmdOpt_Rename,
|
---|
248 | kCmdOpt_NoRename,
|
---|
249 | kCmdOpt_DirEnum,
|
---|
250 | kCmdOpt_NoDirEnum,
|
---|
251 | kCmdOpt_MkRmDir,
|
---|
252 | kCmdOpt_NoMkRmDir,
|
---|
253 | kCmdOpt_StatVfs,
|
---|
254 | kCmdOpt_NoStatVfs,
|
---|
255 | kCmdOpt_Rm,
|
---|
256 | kCmdOpt_NoRm,
|
---|
257 | kCmdOpt_ChSize,
|
---|
258 | kCmdOpt_NoChSize,
|
---|
259 | kCmdOpt_ReadPerf,
|
---|
260 | kCmdOpt_NoReadPerf,
|
---|
261 | kCmdOpt_ReadTests,
|
---|
262 | kCmdOpt_NoReadTests,
|
---|
263 | kCmdOpt_WritePerf,
|
---|
264 | kCmdOpt_NoWritePerf,
|
---|
265 | kCmdOpt_WriteTests,
|
---|
266 | kCmdOpt_NoWriteTests,
|
---|
267 | kCmdOpt_Seek,
|
---|
268 | kCmdOpt_NoSeek,
|
---|
269 | kCmdOpt_FSync,
|
---|
270 | kCmdOpt_NoFSync,
|
---|
271 | kCmdOpt_MMap,
|
---|
272 | kCmdOpt_NoMMap,
|
---|
273 | kCmdOpt_IgnoreNoCache,
|
---|
274 | kCmdOpt_NoIgnoreNoCache,
|
---|
275 | kCmdOpt_IoFileSize,
|
---|
276 | kCmdOpt_SetBlockSize,
|
---|
277 | kCmdOpt_AddBlockSize,
|
---|
278 |
|
---|
279 | kCmdOpt_ShowDuration,
|
---|
280 | kCmdOpt_NoShowDuration,
|
---|
281 | kCmdOpt_ShowIterations,
|
---|
282 | kCmdOpt_NoShowIterations,
|
---|
283 |
|
---|
284 | kCmdOpt_ManyTreeFilesPerDir,
|
---|
285 | kCmdOpt_ManyTreeSubdirsPerDir,
|
---|
286 | kCmdOpt_ManyTreeDepth,
|
---|
287 |
|
---|
288 | kCmdOpt_End
|
---|
289 | };
|
---|
290 |
|
---|
291 |
|
---|
292 | /*********************************************************************************************************************************
|
---|
293 | * Global Variables *
|
---|
294 | *********************************************************************************************************************************/
|
---|
295 | /** Command line parameters */
|
---|
296 | static const RTGETOPTDEF g_aCmdOptions[] =
|
---|
297 | {
|
---|
298 | { "--dir", 'd', RTGETOPT_REQ_STRING },
|
---|
299 | { "--seconds", 's', RTGETOPT_REQ_UINT32 },
|
---|
300 | { "--milliseconds", 'm', RTGETOPT_REQ_UINT64 },
|
---|
301 |
|
---|
302 | { "--enable-all", 'e', RTGETOPT_REQ_NOTHING },
|
---|
303 | { "--disable-all", 'z', RTGETOPT_REQ_NOTHING },
|
---|
304 |
|
---|
305 | { "--many-files", kCmdOpt_ManyFiles, RTGETOPT_REQ_UINT32 },
|
---|
306 | { "--no-many-files", kCmdOpt_NoManyFiles, RTGETOPT_REQ_NOTHING },
|
---|
307 | { "--files-per-dir", kCmdOpt_ManyTreeFilesPerDir, RTGETOPT_REQ_UINT32 },
|
---|
308 | { "--subdirs-per-dir", kCmdOpt_ManyTreeSubdirsPerDir, RTGETOPT_REQ_UINT32 },
|
---|
309 | { "--tree-depth", kCmdOpt_ManyTreeDepth, RTGETOPT_REQ_UINT32 },
|
---|
310 |
|
---|
311 | { "--open", kCmdOpt_Open, RTGETOPT_REQ_NOTHING },
|
---|
312 | { "--no-open", kCmdOpt_NoOpen, RTGETOPT_REQ_NOTHING },
|
---|
313 | { "--fstat", kCmdOpt_FStat, RTGETOPT_REQ_NOTHING },
|
---|
314 | { "--no-fstat", kCmdOpt_NoFStat, RTGETOPT_REQ_NOTHING },
|
---|
315 | { "--fchmod", kCmdOpt_FChMod, RTGETOPT_REQ_NOTHING },
|
---|
316 | { "--no-fchmod", kCmdOpt_NoFChMod, RTGETOPT_REQ_NOTHING },
|
---|
317 | { "--futimes", kCmdOpt_FUtimes, RTGETOPT_REQ_NOTHING },
|
---|
318 | { "--no-futimes", kCmdOpt_NoFUtimes, RTGETOPT_REQ_NOTHING },
|
---|
319 | { "--stat", kCmdOpt_Stat, RTGETOPT_REQ_NOTHING },
|
---|
320 | { "--no-stat", kCmdOpt_NoStat, RTGETOPT_REQ_NOTHING },
|
---|
321 | { "--chmod", kCmdOpt_ChMod, RTGETOPT_REQ_NOTHING },
|
---|
322 | { "--no-chmod", kCmdOpt_NoChMod, RTGETOPT_REQ_NOTHING },
|
---|
323 | { "--utimes", kCmdOpt_Utimes, RTGETOPT_REQ_NOTHING },
|
---|
324 | { "--no-utimes", kCmdOpt_NoUtimes, RTGETOPT_REQ_NOTHING },
|
---|
325 | { "--rename", kCmdOpt_Rename, RTGETOPT_REQ_NOTHING },
|
---|
326 | { "--no-rename", kCmdOpt_NoRename, RTGETOPT_REQ_NOTHING },
|
---|
327 | { "--dir-enum", kCmdOpt_DirEnum, RTGETOPT_REQ_NOTHING },
|
---|
328 | { "--no-dir-enum", kCmdOpt_NoDirEnum, RTGETOPT_REQ_NOTHING },
|
---|
329 | { "--mk-rm-dir", kCmdOpt_MkRmDir, RTGETOPT_REQ_NOTHING },
|
---|
330 | { "--no-mk-rm-dir", kCmdOpt_NoMkRmDir, RTGETOPT_REQ_NOTHING },
|
---|
331 | { "--stat-vfs", kCmdOpt_StatVfs, RTGETOPT_REQ_NOTHING },
|
---|
332 | { "--no-stat-vfs", kCmdOpt_NoStatVfs, RTGETOPT_REQ_NOTHING },
|
---|
333 | { "--rm", kCmdOpt_Rm, RTGETOPT_REQ_NOTHING },
|
---|
334 | { "--no-rm", kCmdOpt_NoRm, RTGETOPT_REQ_NOTHING },
|
---|
335 | { "--chsize", kCmdOpt_ChSize, RTGETOPT_REQ_NOTHING },
|
---|
336 | { "--no-chsize", kCmdOpt_NoChSize, RTGETOPT_REQ_NOTHING },
|
---|
337 | { "--read-tests", kCmdOpt_ReadTests, RTGETOPT_REQ_NOTHING },
|
---|
338 | { "--no-read-tests", kCmdOpt_NoReadTests, RTGETOPT_REQ_NOTHING },
|
---|
339 | { "--read-perf", kCmdOpt_ReadPerf, RTGETOPT_REQ_NOTHING },
|
---|
340 | { "--no-read-perf", kCmdOpt_NoReadPerf, RTGETOPT_REQ_NOTHING },
|
---|
341 | { "--write-tests", kCmdOpt_WriteTests, RTGETOPT_REQ_NOTHING },
|
---|
342 | { "--no-write-tests", kCmdOpt_NoWriteTests, RTGETOPT_REQ_NOTHING },
|
---|
343 | { "--write-perf", kCmdOpt_WritePerf, RTGETOPT_REQ_NOTHING },
|
---|
344 | { "--no-write-perf", kCmdOpt_NoWritePerf, RTGETOPT_REQ_NOTHING },
|
---|
345 | { "--seek", kCmdOpt_Seek, RTGETOPT_REQ_NOTHING },
|
---|
346 | { "--no-seek", kCmdOpt_NoSeek, RTGETOPT_REQ_NOTHING },
|
---|
347 | { "--fsync", kCmdOpt_FSync, RTGETOPT_REQ_NOTHING },
|
---|
348 | { "--no-fsync", kCmdOpt_NoFSync, RTGETOPT_REQ_NOTHING },
|
---|
349 | { "--mmap", kCmdOpt_MMap, RTGETOPT_REQ_NOTHING },
|
---|
350 | { "--no-mmap", kCmdOpt_NoMMap, RTGETOPT_REQ_NOTHING },
|
---|
351 | { "--ignore-no-cache", kCmdOpt_IgnoreNoCache, RTGETOPT_REQ_NOTHING },
|
---|
352 | { "--no-ignore-no-cache", kCmdOpt_NoIgnoreNoCache, RTGETOPT_REQ_NOTHING },
|
---|
353 | { "--io-file-size", kCmdOpt_IoFileSize, RTGETOPT_REQ_UINT64 },
|
---|
354 | { "--set-block-size", kCmdOpt_SetBlockSize, RTGETOPT_REQ_UINT32 },
|
---|
355 | { "--add-block-size", kCmdOpt_AddBlockSize, RTGETOPT_REQ_UINT32 },
|
---|
356 |
|
---|
357 | { "--show-duration", kCmdOpt_ShowDuration, RTGETOPT_REQ_NOTHING },
|
---|
358 | { "--no-show-duration", kCmdOpt_NoShowDuration, RTGETOPT_REQ_NOTHING },
|
---|
359 | { "--show-iterations", kCmdOpt_ShowIterations, RTGETOPT_REQ_NOTHING },
|
---|
360 | { "--no-show-iterations", kCmdOpt_NoShowIterations, RTGETOPT_REQ_NOTHING },
|
---|
361 |
|
---|
362 | { "--quiet", 'q', RTGETOPT_REQ_NOTHING },
|
---|
363 | { "--verbose", 'v', RTGETOPT_REQ_NOTHING },
|
---|
364 | { "--version", 'V', RTGETOPT_REQ_NOTHING },
|
---|
365 | { "--help", 'h', RTGETOPT_REQ_NOTHING } /* for Usage() */
|
---|
366 | };
|
---|
367 |
|
---|
368 | /** The test handle. */
|
---|
369 | static RTTEST g_hTest;
|
---|
370 | /** The number of nanoseconds a RTTimeNanoTS call takes.
|
---|
371 | * This is used for adjusting loop count estimates. */
|
---|
372 | static uint64_t g_nsPerNanoTSCall = 1;
|
---|
373 | /** Whether or not to display the duration of each profile run.
|
---|
374 | * This is chiefly for verify the estimate phase. */
|
---|
375 | static bool g_fShowDuration = false;
|
---|
376 | /** Whether or not to display the iteration count for each profile run.
|
---|
377 | * This is chiefly for verify the estimate phase. */
|
---|
378 | static bool g_fShowIterations = false;
|
---|
379 | /** Verbosity level. */
|
---|
380 | static uint32_t g_uVerbosity = 0;
|
---|
381 |
|
---|
382 | /** @name Selected subtest
|
---|
383 | * @{ */
|
---|
384 | static bool g_fManyFiles = true;
|
---|
385 | static bool g_fOpen = true;
|
---|
386 | static bool g_fFStat = true;
|
---|
387 | static bool g_fFChMod = true;
|
---|
388 | static bool g_fFUtimes = true;
|
---|
389 | static bool g_fStat = true;
|
---|
390 | static bool g_fChMod = true;
|
---|
391 | static bool g_fUtimes = true;
|
---|
392 | static bool g_fRename = true;
|
---|
393 | static bool g_fDirEnum = true;
|
---|
394 | static bool g_fMkRmDir = true;
|
---|
395 | static bool g_fStatVfs = true;
|
---|
396 | static bool g_fRm = true;
|
---|
397 | static bool g_fChSize = true;
|
---|
398 | static bool g_fReadTests = true;
|
---|
399 | static bool g_fReadPerf = true;
|
---|
400 | static bool g_fWriteTests= true;
|
---|
401 | static bool g_fWritePerf = true;
|
---|
402 | static bool g_fSeek = true;
|
---|
403 | static bool g_fFSync = true;
|
---|
404 | static bool g_fMMap = true;
|
---|
405 | /** @} */
|
---|
406 |
|
---|
407 | /** The length of each test run. */
|
---|
408 | static uint64_t g_nsTestRun = RT_NS_1SEC_64 * 10;
|
---|
409 |
|
---|
410 | /** For the 'manyfiles' subdir. */
|
---|
411 | static uint32_t g_cManyFiles = 10000;
|
---|
412 |
|
---|
413 | /** Number of files in the 'manytree' directory tree. */
|
---|
414 | static uint32_t g_cManyTreeFiles = 640 + 16*640 /*10880*/;
|
---|
415 | /** Number of files per directory in the 'manytree' construct. */
|
---|
416 | static uint32_t g_cManyTreeFilesPerDir = 640;
|
---|
417 | /** Number of subdirs per directory in the 'manytree' construct. */
|
---|
418 | static uint32_t g_cManyTreeSubdirsPerDir = 16;
|
---|
419 | /** The depth of the 'manytree' directory tree. */
|
---|
420 | static uint32_t g_cManyTreeDepth = 1;
|
---|
421 | /** List of directories in the many tree, creation order. */
|
---|
422 | static RTLISTANCHOR g_ManyTreeHead;
|
---|
423 |
|
---|
424 | /** Number of configured I/O block sizes. */
|
---|
425 | static uint32_t g_cIoBlocks = 8;
|
---|
426 | /** Configured I/O block sizes. */
|
---|
427 | static uint32_t g_acbIoBlocks[16] = { 1, 512, 4096, 16384, 65536, _1M, _32M, _128M };
|
---|
428 | /** The desired size of the test file we use for I/O. */
|
---|
429 | static uint64_t g_cbIoFile = _512M;
|
---|
430 | /** Whether to be less strict with non-cache file handle. */
|
---|
431 | static bool g_fIgnoreNoCache = false;
|
---|
432 |
|
---|
433 | /** The length of g_szDir. */
|
---|
434 | static size_t g_cchDir;
|
---|
435 | /** The length of g_szEmptyDir. */
|
---|
436 | static size_t g_cchEmptyDir;
|
---|
437 | /** The length of g_szDeepDir. */
|
---|
438 | static size_t g_cchDeepDir;
|
---|
439 |
|
---|
440 | /** The test directory (absolute). This will always have a trailing slash. */
|
---|
441 | static char g_szDir[RTPATH_MAX];
|
---|
442 | /** The empty test directory (absolute). This will always have a trailing slash. */
|
---|
443 | static char g_szEmptyDir[RTPATH_MAX];
|
---|
444 | /** The deep test directory (absolute). This will always have a trailing slash. */
|
---|
445 | static char g_szDeepDir[RTPATH_MAX];
|
---|
446 |
|
---|
447 |
|
---|
448 | /**
|
---|
449 | * Yield the CPU and stuff before starting a test run.
|
---|
450 | */
|
---|
451 | DECLINLINE(void) fsPerfYield(void)
|
---|
452 | {
|
---|
453 | RTThreadYield();
|
---|
454 | RTThreadYield();
|
---|
455 | }
|
---|
456 |
|
---|
457 |
|
---|
458 | /**
|
---|
459 | * Profiles the RTTimeNanoTS call, setting g_nsPerNanoTSCall.
|
---|
460 | */
|
---|
461 | static void fsPerfNanoTS(void)
|
---|
462 | {
|
---|
463 | fsPerfYield();
|
---|
464 |
|
---|
465 | /* Make sure we start off on a changing timestamp on platforms will low time resoultion. */
|
---|
466 | uint64_t nsStart = RTTimeNanoTS();
|
---|
467 | uint64_t ns;
|
---|
468 | do
|
---|
469 | ns = RTTimeNanoTS();
|
---|
470 | while (ns == nsStart);
|
---|
471 | nsStart = ns;
|
---|
472 |
|
---|
473 | /* Call it for 10 ms. */
|
---|
474 | uint32_t i = 0;
|
---|
475 | do
|
---|
476 | {
|
---|
477 | i++;
|
---|
478 | ns = RTTimeNanoTS();
|
---|
479 | }
|
---|
480 | while (ns - nsStart < RT_NS_10MS);
|
---|
481 |
|
---|
482 | g_nsPerNanoTSCall = (ns - nsStart) / i;
|
---|
483 | }
|
---|
484 |
|
---|
485 |
|
---|
486 | /**
|
---|
487 | * Construct a path relative to the base test directory.
|
---|
488 | *
|
---|
489 | * @returns g_szDir.
|
---|
490 | * @param pszAppend What to append.
|
---|
491 | * @param cchAppend How much to append.
|
---|
492 | */
|
---|
493 | DECLINLINE(char *) InDir(const char *pszAppend, size_t cchAppend)
|
---|
494 | {
|
---|
495 | Assert(g_szDir[g_cchDir - 1] == RTPATH_SLASH);
|
---|
496 | memcpy(&g_szDir[g_cchDir], pszAppend, cchAppend);
|
---|
497 | g_szDir[g_cchDir + cchAppend] = '\0';
|
---|
498 | return &g_szDir[0];
|
---|
499 | }
|
---|
500 |
|
---|
501 |
|
---|
502 | /**
|
---|
503 | * Construct a path relative to the empty directory.
|
---|
504 | *
|
---|
505 | * @returns g_szEmptyDir.
|
---|
506 | * @param pszAppend What to append.
|
---|
507 | * @param cchAppend How much to append.
|
---|
508 | */
|
---|
509 | DECLINLINE(char *) InEmptyDir(const char *pszAppend, size_t cchAppend)
|
---|
510 | {
|
---|
511 | Assert(g_szEmptyDir[g_cchEmptyDir - 1] == RTPATH_SLASH);
|
---|
512 | memcpy(&g_szEmptyDir[g_cchEmptyDir], pszAppend, cchAppend);
|
---|
513 | g_szEmptyDir[g_cchEmptyDir + cchAppend] = '\0';
|
---|
514 | return &g_szEmptyDir[0];
|
---|
515 | }
|
---|
516 |
|
---|
517 |
|
---|
518 | /**
|
---|
519 | * Construct a path relative to the deep test directory.
|
---|
520 | *
|
---|
521 | * @returns g_szDeepDir.
|
---|
522 | * @param pszAppend What to append.
|
---|
523 | * @param cchAppend How much to append.
|
---|
524 | */
|
---|
525 | DECLINLINE(char *) InDeepDir(const char *pszAppend, size_t cchAppend)
|
---|
526 | {
|
---|
527 | Assert(g_szDeepDir[g_cchDeepDir - 1] == RTPATH_SLASH);
|
---|
528 | memcpy(&g_szDeepDir[g_cchDeepDir], pszAppend, cchAppend);
|
---|
529 | g_szDeepDir[g_cchDeepDir + cchAppend] = '\0';
|
---|
530 | return &g_szDeepDir[0];
|
---|
531 | }
|
---|
532 |
|
---|
533 |
|
---|
534 | /**
|
---|
535 | * Prepares the test area.
|
---|
536 | * @returns VBox status code.
|
---|
537 | */
|
---|
538 | static int fsPrepTestArea(void)
|
---|
539 | {
|
---|
540 | /* The empty subdir and associated globals: */
|
---|
541 | static char s_szEmpty[] = "empty";
|
---|
542 | memcpy(g_szEmptyDir, g_szDir, g_cchDir);
|
---|
543 | memcpy(&g_szEmptyDir[g_cchDir], s_szEmpty, sizeof(s_szEmpty));
|
---|
544 | g_cchEmptyDir = g_cchDir + sizeof(s_szEmpty) - 1;
|
---|
545 | RTTESTI_CHECK_RC_RET(RTDirCreate(g_szEmptyDir, 0755, 0), VINF_SUCCESS, rcCheck);
|
---|
546 | g_szEmptyDir[g_cchEmptyDir++] = RTPATH_SLASH;
|
---|
547 | g_szEmptyDir[g_cchEmptyDir] = '\0';
|
---|
548 | RTTestIPrintf(RTTESTLVL_ALWAYS, "Empty dir: %s\n", g_szEmptyDir);
|
---|
549 |
|
---|
550 | /* Deep directory: */
|
---|
551 | memcpy(g_szDeepDir, g_szDir, g_cchDir);
|
---|
552 | g_cchDeepDir = g_cchDir;
|
---|
553 | do
|
---|
554 | {
|
---|
555 | static char const s_szSub[] = "d" RTPATH_SLASH_STR;
|
---|
556 | memcpy(&g_szDeepDir[g_cchDeepDir], s_szSub, sizeof(s_szSub));
|
---|
557 | g_cchDeepDir += sizeof(s_szSub) - 1;
|
---|
558 | RTTESTI_CHECK_RC_RET( RTDirCreate(g_szDeepDir, 0755, 0), VINF_SUCCESS, rcCheck);
|
---|
559 | } while (g_cchDeepDir < 176);
|
---|
560 | RTTestIPrintf(RTTESTLVL_ALWAYS, "Deep dir: %s\n", g_szDeepDir);
|
---|
561 |
|
---|
562 | /* Create known file in both deep and shallow dirs: */
|
---|
563 | RTFILE hKnownFile;
|
---|
564 | RTTESTI_CHECK_RC_RET(RTFileOpen(&hKnownFile, InDir(RT_STR_TUPLE("known-file")),
|
---|
565 | RTFILE_O_CREATE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE),
|
---|
566 | VINF_SUCCESS, rcCheck);
|
---|
567 | RTTESTI_CHECK_RC_RET(RTFileClose(hKnownFile), VINF_SUCCESS, rcCheck);
|
---|
568 |
|
---|
569 | RTTESTI_CHECK_RC_RET(RTFileOpen(&hKnownFile, InDeepDir(RT_STR_TUPLE("known-file")),
|
---|
570 | RTFILE_O_CREATE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE),
|
---|
571 | VINF_SUCCESS, rcCheck);
|
---|
572 | RTTESTI_CHECK_RC_RET(RTFileClose(hKnownFile), VINF_SUCCESS, rcCheck);
|
---|
573 |
|
---|
574 | return VINF_SUCCESS;
|
---|
575 | }
|
---|
576 |
|
---|
577 |
|
---|
578 | /**
|
---|
579 | * Create a name list entry.
|
---|
580 | * @returns Pointer to the entry, NULL if out of memory.
|
---|
581 | * @param pchName The name.
|
---|
582 | * @param cchName The name length.
|
---|
583 | */
|
---|
584 | PFSPERFNAMEENTRY fsPerfCreateNameEntry(const char *pchName, size_t cchName)
|
---|
585 | {
|
---|
586 | PFSPERFNAMEENTRY pEntry = (PFSPERFNAMEENTRY)RTMemAllocVar(RT_UOFFSETOF_DYN(FSPERFNAMEENTRY, szName[cchName + 1]));
|
---|
587 | if (pEntry)
|
---|
588 | {
|
---|
589 | RTListInit(&pEntry->Entry);
|
---|
590 | pEntry->cchName = (uint16_t)cchName;
|
---|
591 | memcpy(pEntry->szName, pchName, cchName);
|
---|
592 | pEntry->szName[cchName] = '\0';
|
---|
593 | }
|
---|
594 | return pEntry;
|
---|
595 | }
|
---|
596 |
|
---|
597 |
|
---|
598 | static int fsPerfManyTreeRecursiveDirCreator(size_t cchDir, uint32_t iDepth)
|
---|
599 | {
|
---|
600 | PFSPERFNAMEENTRY pEntry = fsPerfCreateNameEntry(g_szDir, cchDir);
|
---|
601 | RTTESTI_CHECK_RET(pEntry, VERR_NO_MEMORY);
|
---|
602 | RTListAppend(&g_ManyTreeHead, &pEntry->Entry);
|
---|
603 |
|
---|
604 | RTTESTI_CHECK_RC_RET(RTDirCreate(g_szDir, 0755, RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_DONT_SET | RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_NOT_CRITICAL),
|
---|
605 | VINF_SUCCESS, rcCheck);
|
---|
606 |
|
---|
607 | if (iDepth < g_cManyTreeDepth)
|
---|
608 | for (uint32_t i = 0; i < g_cManyTreeSubdirsPerDir; i++)
|
---|
609 | {
|
---|
610 | size_t cchSubDir = RTStrPrintf(&g_szDir[cchDir], sizeof(g_szDir) - cchDir, "d%02u" RTPATH_SLASH_STR, i);
|
---|
611 | RTTESTI_CHECK_RC_RET(fsPerfManyTreeRecursiveDirCreator(cchDir + cchSubDir, iDepth + 1), VINF_SUCCESS, rcCheck);
|
---|
612 | }
|
---|
613 |
|
---|
614 | return VINF_SUCCESS;
|
---|
615 | }
|
---|
616 |
|
---|
617 |
|
---|
618 | void fsPerfManyFiles(void)
|
---|
619 | {
|
---|
620 | RTTestISub("manyfiles");
|
---|
621 |
|
---|
622 | /*
|
---|
623 | * Create a sub-directory with like 10000 files in it.
|
---|
624 | *
|
---|
625 | * This does push the directory organization of the underlying file system,
|
---|
626 | * which is something we might not want to profile with shared folders. It
|
---|
627 | * is however useful for directory enumeration.
|
---|
628 | */
|
---|
629 | RTTESTI_CHECK_RC_RETV(RTDirCreate(InDir(RT_STR_TUPLE("manyfiles")), 0755,
|
---|
630 | RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_DONT_SET | RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_NOT_CRITICAL),
|
---|
631 | VINF_SUCCESS);
|
---|
632 |
|
---|
633 | size_t offFilename = strlen(g_szDir);
|
---|
634 | g_szDir[offFilename++] = RTPATH_SLASH;
|
---|
635 |
|
---|
636 | fsPerfYield();
|
---|
637 | RTFILE hFile;
|
---|
638 | uint64_t const nsStart = RTTimeNanoTS();
|
---|
639 | for (uint32_t i = 0; i < g_cManyFiles; i++)
|
---|
640 | {
|
---|
641 | RTStrFormatU32(&g_szDir[offFilename], sizeof(g_szDir) - offFilename, i, 10, 5, 5, RTSTR_F_ZEROPAD);
|
---|
642 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile, g_szDir, RTFILE_O_CREATE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
643 | RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
|
---|
644 | }
|
---|
645 | uint64_t const cNsElapsed = RTTimeNanoTS() - nsStart;
|
---|
646 | RTTestIValueF(cNsElapsed, RTTESTUNIT_NS, "Creating %u empty files in single directory", g_cManyFiles);
|
---|
647 | RTTestIValueF(cNsElapsed / g_cManyFiles, RTTESTUNIT_NS_PER_OCCURRENCE, "Create empty file (single dir)");
|
---|
648 |
|
---|
649 | /*
|
---|
650 | * Create a bunch of directories with exacly 32 files in each, hoping to
|
---|
651 | * avoid any directory organization artifacts.
|
---|
652 | */
|
---|
653 | /* Create the directories first, building a list of them for simplifying iteration: */
|
---|
654 | RTListInit(&g_ManyTreeHead);
|
---|
655 | InDir(RT_STR_TUPLE("manytree" RTPATH_SLASH_STR));
|
---|
656 | RTTESTI_CHECK_RC_RETV(fsPerfManyTreeRecursiveDirCreator(strlen(g_szDir), 0), VINF_SUCCESS);
|
---|
657 |
|
---|
658 | /* Create the zero byte files: */
|
---|
659 | fsPerfYield();
|
---|
660 | uint64_t const nsStart2 = RTTimeNanoTS();
|
---|
661 | uint32_t cFiles = 0;
|
---|
662 | PFSPERFNAMEENTRY pCur;
|
---|
663 | RTListForEach(&g_ManyTreeHead, pCur, FSPERFNAMEENTRY, Entry)
|
---|
664 | {
|
---|
665 | char szPath[RTPATH_MAX];
|
---|
666 | memcpy(szPath, pCur->szName, pCur->cchName);
|
---|
667 | for (uint32_t i = 0; i < g_cManyTreeFilesPerDir; i++)
|
---|
668 | {
|
---|
669 | RTStrFormatU32(&szPath[pCur->cchName], sizeof(szPath) - pCur->cchName, i, 10, 5, 5, RTSTR_F_ZEROPAD);
|
---|
670 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile, szPath, RTFILE_O_CREATE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
671 | RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
|
---|
672 | cFiles++;
|
---|
673 | }
|
---|
674 | }
|
---|
675 | uint64_t const cNsElapsed2 = RTTimeNanoTS() - nsStart2;
|
---|
676 | RTTestIValueF(cNsElapsed2, RTTESTUNIT_NS, "Creating %u empty files in tree", cFiles);
|
---|
677 | RTTestIValueF(cNsElapsed2 / cFiles, RTTESTUNIT_NS_PER_OCCURRENCE, "Create empty file (tree)");
|
---|
678 | RTTESTI_CHECK(g_cManyTreeFiles == cFiles);
|
---|
679 | }
|
---|
680 |
|
---|
681 |
|
---|
682 | DECL_FORCE_INLINE(int) fsPerfOpenExistingOnceReadonly(const char *pszFile)
|
---|
683 | {
|
---|
684 | RTFILE hFile;
|
---|
685 | RTTESTI_CHECK_RC_RET(RTFileOpen(&hFile, pszFile, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ), VINF_SUCCESS, rcCheck);
|
---|
686 | RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
|
---|
687 | return VINF_SUCCESS;
|
---|
688 | }
|
---|
689 |
|
---|
690 |
|
---|
691 | DECL_FORCE_INLINE(int) fsPerfOpenExistingOnceWriteonly(const char *pszFile)
|
---|
692 | {
|
---|
693 | RTFILE hFile;
|
---|
694 | RTTESTI_CHECK_RC_RET(RTFileOpen(&hFile, pszFile, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS, rcCheck);
|
---|
695 | RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
|
---|
696 | return VINF_SUCCESS;
|
---|
697 | }
|
---|
698 |
|
---|
699 |
|
---|
700 | void fsPerfOpen(void)
|
---|
701 | {
|
---|
702 | RTTestISub("open");
|
---|
703 |
|
---|
704 | /* Opening non-existing files. */
|
---|
705 | RTFILE hFile;
|
---|
706 | RTTESTI_CHECK_RC(RTFileOpen(&hFile, InEmptyDir(RT_STR_TUPLE("no-such-file")),
|
---|
707 | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ), VERR_FILE_NOT_FOUND);
|
---|
708 | RTTESTI_CHECK_RC(RTFileOpen(&hFile, InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file")),
|
---|
709 | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
710 | RTTESTI_CHECK_RC(RTFileOpen(&hFile, InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file")),
|
---|
711 | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ), VERR_PATH_NOT_FOUND);
|
---|
712 |
|
---|
713 | /*
|
---|
714 | * Create file1 and then try exclusivly creating it again.
|
---|
715 | * Then profile opening it for reading.
|
---|
716 | */
|
---|
717 | RTFILE hFile1;
|
---|
718 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file1")),
|
---|
719 | RTFILE_O_CREATE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
720 | RTTESTI_CHECK_RC(RTFileOpen(&hFile, g_szDir, RTFILE_O_CREATE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VERR_ALREADY_EXISTS);
|
---|
721 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
722 |
|
---|
723 | PROFILE_FN(fsPerfOpenExistingOnceReadonly(g_szDir), g_nsTestRun, "RTFileOpen/Close/Readonly");
|
---|
724 | PROFILE_FN(fsPerfOpenExistingOnceWriteonly(g_szDir), g_nsTestRun, "RTFileOpen/Close/Writeonly");
|
---|
725 |
|
---|
726 | /*
|
---|
727 | * Profile opening in the deep directory too.
|
---|
728 | */
|
---|
729 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDeepDir(RT_STR_TUPLE("file1")),
|
---|
730 | RTFILE_O_CREATE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
731 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
732 | PROFILE_FN(fsPerfOpenExistingOnceReadonly(g_szDeepDir), g_nsTestRun, "RTFileOpen/Close/deep/readonly");
|
---|
733 | PROFILE_FN(fsPerfOpenExistingOnceWriteonly(g_szDeepDir), g_nsTestRun, "RTFileOpen/Close/deep/writeonly");
|
---|
734 |
|
---|
735 | /* Manytree: */
|
---|
736 | char szPath[RTPATH_MAX];
|
---|
737 | PROFILE_MANYTREE_FN(szPath, fsPerfOpenExistingOnceReadonly(szPath), 1, g_nsTestRun, "RTFileOpen/Close/manytree/readonly");
|
---|
738 | }
|
---|
739 |
|
---|
740 |
|
---|
741 | void fsPerfFStat(void)
|
---|
742 | {
|
---|
743 | RTTestISub("fstat");
|
---|
744 | RTFILE hFile1;
|
---|
745 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file2")),
|
---|
746 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
747 | RTFSOBJINFO ObjInfo = {0};
|
---|
748 | PROFILE_FN(RTFileQueryInfo(hFile1, &ObjInfo, RTFSOBJATTRADD_NOTHING), g_nsTestRun, "RTFileQueryInfo/NOTHING");
|
---|
749 | PROFILE_FN(RTFileQueryInfo(hFile1, &ObjInfo, RTFSOBJATTRADD_UNIX), g_nsTestRun, "RTFileQueryInfo/UNIX");
|
---|
750 |
|
---|
751 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
752 | }
|
---|
753 |
|
---|
754 |
|
---|
755 | void fsPerfFChMod(void)
|
---|
756 | {
|
---|
757 | RTTestISub("fchmod");
|
---|
758 | RTFILE hFile1;
|
---|
759 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file4")),
|
---|
760 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
761 | RTFSOBJINFO ObjInfo = {0};
|
---|
762 | RTTESTI_CHECK_RC(RTFileQueryInfo(hFile1, &ObjInfo, RTFSOBJATTRADD_NOTHING), VINF_SUCCESS);
|
---|
763 | RTFMODE const fEvenMode = (ObjInfo.Attr.fMode & ~RTFS_UNIX_ALL_ACCESS_PERMS) | RTFS_DOS_READONLY | 0400;
|
---|
764 | RTFMODE const fOddMode = (ObjInfo.Attr.fMode & ~(RTFS_UNIX_ALL_ACCESS_PERMS | RTFS_DOS_READONLY)) | 0640;
|
---|
765 | PROFILE_FN(RTFileSetMode(hFile1, iIteration & 1 ? fOddMode : fEvenMode), g_nsTestRun, "RTFileSetMode");
|
---|
766 |
|
---|
767 | RTFileSetMode(hFile1, ObjInfo.Attr.fMode);
|
---|
768 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
769 | }
|
---|
770 |
|
---|
771 |
|
---|
772 | void fsPerfFUtimes(void)
|
---|
773 | {
|
---|
774 | RTTestISub("futimes");
|
---|
775 | RTFILE hFile1;
|
---|
776 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file5")),
|
---|
777 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
778 | RTTIMESPEC Time1;
|
---|
779 | RTTimeNow(&Time1);
|
---|
780 | RTTIMESPEC Time2 = Time1;
|
---|
781 | RTTimeSpecSubSeconds(&Time2, 3636);
|
---|
782 |
|
---|
783 | RTFSOBJINFO ObjInfo0 = {0};
|
---|
784 | RTTESTI_CHECK_RC(RTFileQueryInfo(hFile1, &ObjInfo0, RTFSOBJATTRADD_NOTHING), VINF_SUCCESS);
|
---|
785 |
|
---|
786 | /* Modify modification time: */
|
---|
787 | RTTESTI_CHECK_RC(RTFileSetTimes(hFile1, NULL, &Time2, NULL, NULL), VINF_SUCCESS);
|
---|
788 | RTFSOBJINFO ObjInfo1 = {0};
|
---|
789 | RTTESTI_CHECK_RC(RTFileQueryInfo(hFile1, &ObjInfo1, RTFSOBJATTRADD_NOTHING), VINF_SUCCESS);
|
---|
790 | RTTESTI_CHECK((RTTimeSpecGetSeconds(&ObjInfo1.ModificationTime) >> 2) == (RTTimeSpecGetSeconds(&Time2) >> 2));
|
---|
791 | char sz1[RTTIME_STR_LEN], sz2[RTTIME_STR_LEN]; /* Div by 1000 here for posix impl. using timeval. */
|
---|
792 | RTTESTI_CHECK_MSG(RTTimeSpecGetNano(&ObjInfo1.AccessTime) / 1000 == RTTimeSpecGetNano(&ObjInfo0.AccessTime) / 1000,
|
---|
793 | ("%s, expected %s", RTTimeSpecToString(&ObjInfo1.AccessTime, sz1, sizeof(sz1)),
|
---|
794 | RTTimeSpecToString(&ObjInfo0.AccessTime, sz2, sizeof(sz2))));
|
---|
795 |
|
---|
796 | /* Modify access time: */
|
---|
797 | RTTESTI_CHECK_RC(RTFileSetTimes(hFile1, &Time1, NULL, NULL, NULL), VINF_SUCCESS);
|
---|
798 | RTFSOBJINFO ObjInfo2 = {0};
|
---|
799 | RTTESTI_CHECK_RC(RTFileQueryInfo(hFile1, &ObjInfo2, RTFSOBJATTRADD_NOTHING), VINF_SUCCESS);
|
---|
800 | RTTESTI_CHECK((RTTimeSpecGetSeconds(&ObjInfo2.AccessTime) >> 2) == (RTTimeSpecGetSeconds(&Time1) >> 2));
|
---|
801 | RTTESTI_CHECK(RTTimeSpecGetNano(&ObjInfo2.ModificationTime) / 1000 == RTTimeSpecGetNano(&ObjInfo1.ModificationTime) / 1000);
|
---|
802 |
|
---|
803 | /* Benchmark it: */
|
---|
804 | PROFILE_FN(RTFileSetTimes(hFile1, NULL, iIteration & 1 ? &Time1 : &Time2, NULL, NULL), g_nsTestRun, "RTFileSetTimes");
|
---|
805 |
|
---|
806 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
807 | }
|
---|
808 |
|
---|
809 |
|
---|
810 | void fsPerfStat(void)
|
---|
811 | {
|
---|
812 | RTTestISub("stat");
|
---|
813 | RTFSOBJINFO ObjInfo;
|
---|
814 |
|
---|
815 | /* Non-existing files. */
|
---|
816 | RTTESTI_CHECK_RC(RTPathQueryInfoEx(InEmptyDir(RT_STR_TUPLE("no-such-file")),
|
---|
817 | &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), VERR_FILE_NOT_FOUND);
|
---|
818 | RTTESTI_CHECK_RC(RTPathQueryInfoEx(InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file")),
|
---|
819 | &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
820 | RTTESTI_CHECK_RC(RTPathQueryInfoEx(InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file")),
|
---|
821 | &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), VERR_PATH_NOT_FOUND);
|
---|
822 |
|
---|
823 | /* Shallow: */
|
---|
824 | RTFILE hFile1;
|
---|
825 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file3")),
|
---|
826 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
827 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
828 |
|
---|
829 | PROFILE_FN(RTPathQueryInfoEx(g_szDir, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), g_nsTestRun,
|
---|
830 | "RTPathQueryInfoEx/NOTHING");
|
---|
831 | PROFILE_FN(RTPathQueryInfoEx(g_szDir, &ObjInfo, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK), g_nsTestRun,
|
---|
832 | "RTPathQueryInfoEx/UNIX");
|
---|
833 |
|
---|
834 |
|
---|
835 | /* Deep: */
|
---|
836 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDeepDir(RT_STR_TUPLE("file3")),
|
---|
837 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
838 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
839 |
|
---|
840 | PROFILE_FN(RTPathQueryInfoEx(g_szDeepDir, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), g_nsTestRun,
|
---|
841 | "RTPathQueryInfoEx/deep/NOTHING");
|
---|
842 | PROFILE_FN(RTPathQueryInfoEx(g_szDeepDir, &ObjInfo, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK), g_nsTestRun,
|
---|
843 | "RTPathQueryInfoEx/deep/UNIX");
|
---|
844 |
|
---|
845 | /* Manytree: */
|
---|
846 | char szPath[RTPATH_MAX];
|
---|
847 | PROFILE_MANYTREE_FN(szPath, RTPathQueryInfoEx(szPath, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK),
|
---|
848 | 1, g_nsTestRun, "RTPathQueryInfoEx/manytree/NOTHING");
|
---|
849 | PROFILE_MANYTREE_FN(szPath, RTPathQueryInfoEx(szPath, &ObjInfo, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK),
|
---|
850 | 1, g_nsTestRun, "RTPathQueryInfoEx/manytree/UNIX");
|
---|
851 | }
|
---|
852 |
|
---|
853 |
|
---|
854 | void fsPerfChmod(void)
|
---|
855 | {
|
---|
856 | RTTestISub("chmod");
|
---|
857 |
|
---|
858 | /* Non-existing files. */
|
---|
859 | RTTESTI_CHECK_RC(RTPathSetMode(InEmptyDir(RT_STR_TUPLE("no-such-file")), 0665),
|
---|
860 | VERR_FILE_NOT_FOUND);
|
---|
861 | RTTESTI_CHECK_RC(RTPathSetMode(InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file")), 0665),
|
---|
862 | FSPERF_VERR_PATH_NOT_FOUND);
|
---|
863 | RTTESTI_CHECK_RC(RTPathSetMode(InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file")), 0665), VERR_PATH_NOT_FOUND);
|
---|
864 |
|
---|
865 | /* Shallow: */
|
---|
866 | RTFILE hFile1;
|
---|
867 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file14")),
|
---|
868 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
869 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
870 |
|
---|
871 | RTFSOBJINFO ObjInfo;
|
---|
872 | RTTESTI_CHECK_RC(RTPathQueryInfoEx(g_szDir, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), VINF_SUCCESS);
|
---|
873 | RTFMODE const fEvenMode = (ObjInfo.Attr.fMode & ~RTFS_UNIX_ALL_ACCESS_PERMS) | RTFS_DOS_READONLY | 0400;
|
---|
874 | RTFMODE const fOddMode = (ObjInfo.Attr.fMode & ~(RTFS_UNIX_ALL_ACCESS_PERMS | RTFS_DOS_READONLY)) | 0640;
|
---|
875 | PROFILE_FN(RTPathSetMode(g_szDir, iIteration & 1 ? fOddMode : fEvenMode), g_nsTestRun, "RTPathSetMode");
|
---|
876 | RTPathSetMode(g_szDir, ObjInfo.Attr.fMode);
|
---|
877 |
|
---|
878 | /* Deep: */
|
---|
879 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDeepDir(RT_STR_TUPLE("file14")),
|
---|
880 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
881 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
882 |
|
---|
883 | PROFILE_FN(RTPathSetMode(g_szDeepDir, iIteration & 1 ? fOddMode : fEvenMode), g_nsTestRun, "RTPathSetMode/deep");
|
---|
884 | RTPathSetMode(g_szDeepDir, ObjInfo.Attr.fMode);
|
---|
885 |
|
---|
886 | /* Manytree: */
|
---|
887 | char szPath[RTPATH_MAX];
|
---|
888 | PROFILE_MANYTREE_FN(szPath, RTPathSetMode(szPath, iIteration & 1 ? fOddMode : fEvenMode), 1, g_nsTestRun,
|
---|
889 | "RTPathSetMode/manytree");
|
---|
890 | DO_MANYTREE_FN(szPath, RTPathSetMode(szPath, ObjInfo.Attr.fMode));
|
---|
891 | }
|
---|
892 |
|
---|
893 |
|
---|
894 | void fsPerfUtimes(void)
|
---|
895 | {
|
---|
896 | RTTestISub("utimes");
|
---|
897 |
|
---|
898 | RTTIMESPEC Time1;
|
---|
899 | RTTimeNow(&Time1);
|
---|
900 | RTTIMESPEC Time2 = Time1;
|
---|
901 | RTTimeSpecSubSeconds(&Time2, 3636);
|
---|
902 |
|
---|
903 | /* Non-existing files. */
|
---|
904 | RTTESTI_CHECK_RC(RTPathSetTimesEx(InEmptyDir(RT_STR_TUPLE("no-such-file")), NULL, &Time1, NULL, NULL, RTPATH_F_ON_LINK),
|
---|
905 | VERR_FILE_NOT_FOUND);
|
---|
906 | RTTESTI_CHECK_RC(RTPathSetTimesEx(InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file")),
|
---|
907 | NULL, &Time1, NULL, NULL, RTPATH_F_ON_LINK),
|
---|
908 | FSPERF_VERR_PATH_NOT_FOUND);
|
---|
909 | RTTESTI_CHECK_RC(RTPathSetTimesEx(InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file")),
|
---|
910 | NULL, &Time1, NULL, NULL, RTPATH_F_ON_LINK),
|
---|
911 | VERR_PATH_NOT_FOUND);
|
---|
912 |
|
---|
913 | /* Shallow: */
|
---|
914 | RTFILE hFile1;
|
---|
915 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file15")),
|
---|
916 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
917 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
918 |
|
---|
919 | RTFSOBJINFO ObjInfo0 = {0};
|
---|
920 | RTTESTI_CHECK_RC(RTPathQueryInfoEx(g_szDir, &ObjInfo0, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), VINF_SUCCESS);
|
---|
921 |
|
---|
922 | /* Modify modification time: */
|
---|
923 | RTTESTI_CHECK_RC(RTPathSetTimesEx(g_szDir, NULL, &Time2, NULL, NULL, RTPATH_F_ON_LINK), VINF_SUCCESS);
|
---|
924 | RTFSOBJINFO ObjInfo1;
|
---|
925 | RTTESTI_CHECK_RC(RTPathQueryInfoEx(g_szDir, &ObjInfo1, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), VINF_SUCCESS);
|
---|
926 | RTTESTI_CHECK((RTTimeSpecGetSeconds(&ObjInfo1.ModificationTime) >> 2) == (RTTimeSpecGetSeconds(&Time2) >> 2));
|
---|
927 | RTTESTI_CHECK(RTTimeSpecGetNano(&ObjInfo1.AccessTime) / 1000 == RTTimeSpecGetNano(&ObjInfo0.AccessTime) / 1000 /* posix timeval */);
|
---|
928 |
|
---|
929 | /* Modify access time: */
|
---|
930 | RTTESTI_CHECK_RC(RTPathSetTimesEx(g_szDir, &Time1, NULL, NULL, NULL, RTPATH_F_ON_LINK), VINF_SUCCESS);
|
---|
931 | RTFSOBJINFO ObjInfo2 = {0};
|
---|
932 | RTTESTI_CHECK_RC(RTPathQueryInfoEx(g_szDir, &ObjInfo2, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK), VINF_SUCCESS);
|
---|
933 | RTTESTI_CHECK((RTTimeSpecGetSeconds(&ObjInfo2.AccessTime) >> 2) == (RTTimeSpecGetSeconds(&Time1) >> 2));
|
---|
934 | RTTESTI_CHECK(RTTimeSpecGetNano(&ObjInfo2.ModificationTime) / 1000 == RTTimeSpecGetNano(&ObjInfo1.ModificationTime) / 1000 /* posix timeval */);
|
---|
935 |
|
---|
936 | /* Profile shallow: */
|
---|
937 | PROFILE_FN(RTPathSetTimesEx(g_szDir, iIteration & 1 ? &Time1 : &Time2, iIteration & 1 ? &Time2 : &Time1,
|
---|
938 | NULL, NULL, RTPATH_F_ON_LINK),
|
---|
939 | g_nsTestRun, "RTPathSetTimesEx");
|
---|
940 |
|
---|
941 | /* Deep: */
|
---|
942 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDeepDir(RT_STR_TUPLE("file15")),
|
---|
943 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
944 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
945 |
|
---|
946 | PROFILE_FN(RTPathSetTimesEx(g_szDeepDir, iIteration & 1 ? &Time1 : &Time2, iIteration & 1 ? &Time2 : &Time1,
|
---|
947 | NULL, NULL, RTPATH_F_ON_LINK),
|
---|
948 | g_nsTestRun, "RTPathSetTimesEx/deep");
|
---|
949 |
|
---|
950 | /* Manytree: */
|
---|
951 | char szPath[RTPATH_MAX];
|
---|
952 | PROFILE_MANYTREE_FN(szPath, RTPathSetTimesEx(szPath, iIteration & 1 ? &Time1 : &Time2, iIteration & 1 ? &Time2 : &Time1,
|
---|
953 | NULL, NULL, RTPATH_F_ON_LINK),
|
---|
954 | 1, g_nsTestRun, "RTPathSetTimesEx/manytree");
|
---|
955 | }
|
---|
956 |
|
---|
957 |
|
---|
958 | DECL_FORCE_INLINE(int) fsPerfRenameMany(const char *pszFile, uint32_t iIteration)
|
---|
959 | {
|
---|
960 | char szRenamed[RTPATH_MAX];
|
---|
961 | strcat(strcpy(szRenamed, pszFile), "-renamed");
|
---|
962 | if (!(iIteration & 1))
|
---|
963 | return RTPathRename(pszFile, szRenamed, 0);
|
---|
964 | return RTPathRename(szRenamed, pszFile, 0);
|
---|
965 | }
|
---|
966 |
|
---|
967 |
|
---|
968 | void fsPerfRename(void)
|
---|
969 | {
|
---|
970 | RTTestISub("rename");
|
---|
971 | char szPath[RTPATH_MAX];
|
---|
972 |
|
---|
973 | /* Non-existing files. */
|
---|
974 | strcpy(szPath, InEmptyDir(RT_STR_TUPLE("other-no-such-file")));
|
---|
975 | RTTESTI_CHECK_RC(RTPathRename(InEmptyDir(RT_STR_TUPLE("no-such-file")), szPath, 0), VERR_FILE_NOT_FOUND);
|
---|
976 | strcpy(szPath, InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "other-no-such-file")));
|
---|
977 | RTTESTI_CHECK_RC(RTPathRename(InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file")), szPath, 0),
|
---|
978 | FSPERF_VERR_PATH_NOT_FOUND);
|
---|
979 | strcpy(szPath, InEmptyDir(RT_STR_TUPLE("other-no-such-file")));
|
---|
980 | RTTESTI_CHECK_RC(RTPathRename(InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file")), szPath, 0), VERR_PATH_NOT_FOUND);
|
---|
981 |
|
---|
982 | RTFILE hFile1;
|
---|
983 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file16")),
|
---|
984 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
985 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
986 | strcat(strcpy(szPath, g_szDir), "-no-such-dir" RTPATH_SLASH_STR "file16");
|
---|
987 | RTTESTI_CHECK_RC(RTPathRename(szPath, g_szDir, 0), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
988 | RTTESTI_CHECK_RC(RTPathRename(g_szDir, szPath, 0), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
989 |
|
---|
990 | /* Shallow: */
|
---|
991 | strcat(strcpy(szPath, g_szDir), "-other");
|
---|
992 | PROFILE_FN(RTPathRename(iIteration & 1 ? szPath : g_szDir, iIteration & 1 ? g_szDir : szPath, 0), g_nsTestRun, "RTPathRename");
|
---|
993 |
|
---|
994 | /* Deep: */
|
---|
995 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDeepDir(RT_STR_TUPLE("file15")),
|
---|
996 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
997 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
998 |
|
---|
999 | strcat(strcpy(szPath, g_szDeepDir), "-other");
|
---|
1000 | PROFILE_FN(RTPathRename(iIteration & 1 ? szPath : g_szDeepDir, iIteration & 1 ? g_szDeepDir : szPath, 0),
|
---|
1001 | g_nsTestRun, "RTPathRename/deep");
|
---|
1002 |
|
---|
1003 | /* Manytree: */
|
---|
1004 | PROFILE_MANYTREE_FN(szPath, fsPerfRenameMany(szPath, iIteration), 2, g_nsTestRun, "RTPathRename/manytree");
|
---|
1005 | }
|
---|
1006 |
|
---|
1007 |
|
---|
1008 | DECL_FORCE_INLINE(int) fsPerfEnumEmpty(void)
|
---|
1009 | {
|
---|
1010 | RTDIR hDir;
|
---|
1011 | g_szEmptyDir[g_cchEmptyDir] = '\0';
|
---|
1012 | RTTESTI_CHECK_RC_RET(RTDirOpen(&hDir, g_szEmptyDir), VINF_SUCCESS, rcCheck);
|
---|
1013 |
|
---|
1014 | RTDIRENTRY Entry;
|
---|
1015 | RTTESTI_CHECK_RC(RTDirRead(hDir, &Entry, NULL), VINF_SUCCESS);
|
---|
1016 | RTTESTI_CHECK_RC(RTDirRead(hDir, &Entry, NULL), VINF_SUCCESS);
|
---|
1017 | RTTESTI_CHECK_RC(RTDirRead(hDir, &Entry, NULL), VERR_NO_MORE_FILES);
|
---|
1018 |
|
---|
1019 | RTTESTI_CHECK_RC(RTDirClose(hDir), VINF_SUCCESS);
|
---|
1020 | return VINF_SUCCESS;
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 |
|
---|
1024 | DECL_FORCE_INLINE(int) fsPerfEnumManyFiles(void)
|
---|
1025 | {
|
---|
1026 | RTDIR hDir;
|
---|
1027 | RTTESTI_CHECK_RC_RET(RTDirOpen(&hDir, InDir(RT_STR_TUPLE("manyfiles"))), VINF_SUCCESS, rcCheck);
|
---|
1028 | uint32_t cLeft = g_cManyFiles + 2;
|
---|
1029 | for (;;)
|
---|
1030 | {
|
---|
1031 | RTDIRENTRY Entry;
|
---|
1032 | if (cLeft > 0)
|
---|
1033 | RTTESTI_CHECK_RC_BREAK(RTDirRead(hDir, &Entry, NULL), VINF_SUCCESS);
|
---|
1034 | else
|
---|
1035 | {
|
---|
1036 | RTTESTI_CHECK_RC(RTDirRead(hDir, &Entry, NULL), VERR_NO_MORE_FILES);
|
---|
1037 | break;
|
---|
1038 | }
|
---|
1039 | cLeft--;
|
---|
1040 | }
|
---|
1041 | RTTESTI_CHECK_RC(RTDirClose(hDir), VINF_SUCCESS);
|
---|
1042 | return VINF_SUCCESS;
|
---|
1043 | }
|
---|
1044 |
|
---|
1045 |
|
---|
1046 | void vsPerfDirEnum(void)
|
---|
1047 | {
|
---|
1048 | RTTestISub("dir enum");
|
---|
1049 | RTDIR hDir;
|
---|
1050 |
|
---|
1051 | /* Non-existing files. */
|
---|
1052 | RTTESTI_CHECK_RC(RTDirOpen(&hDir, InEmptyDir(RT_STR_TUPLE("no-such-file"))), VERR_FILE_NOT_FOUND);
|
---|
1053 | RTTESTI_CHECK_RC(RTDirOpen(&hDir, InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file"))), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
1054 | RTTESTI_CHECK_RC(RTDirOpen(&hDir, InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file"))), VERR_PATH_NOT_FOUND);
|
---|
1055 |
|
---|
1056 | /*
|
---|
1057 | * The empty directory.
|
---|
1058 | */
|
---|
1059 | g_szEmptyDir[g_cchEmptyDir] = '\0';
|
---|
1060 | RTTESTI_CHECK_RC_RETV(RTDirOpen(&hDir, g_szEmptyDir), VINF_SUCCESS);
|
---|
1061 |
|
---|
1062 | uint32_t fDots = 0;
|
---|
1063 | RTDIRENTRY Entry;
|
---|
1064 | RTTESTI_CHECK_RC(RTDirRead(hDir, &Entry, NULL), VINF_SUCCESS);
|
---|
1065 | RTTESTI_CHECK(RTDirEntryIsStdDotLink(&Entry));
|
---|
1066 | fDots |= RT_BIT_32(Entry.cbName - 1);
|
---|
1067 |
|
---|
1068 | RTTESTI_CHECK_RC(RTDirRead(hDir, &Entry, NULL), VINF_SUCCESS);
|
---|
1069 | RTTESTI_CHECK(RTDirEntryIsStdDotLink(&Entry));
|
---|
1070 | fDots |= RT_BIT_32(Entry.cbName - 1);
|
---|
1071 | RTTESTI_CHECK(fDots == 3);
|
---|
1072 |
|
---|
1073 | RTTESTI_CHECK_RC(RTDirRead(hDir, &Entry, NULL), VERR_NO_MORE_FILES);
|
---|
1074 |
|
---|
1075 | RTTESTI_CHECK_RC(RTDirClose(hDir), VINF_SUCCESS);
|
---|
1076 |
|
---|
1077 | /*
|
---|
1078 | * The directory with many files in it.
|
---|
1079 | */
|
---|
1080 | if (g_fManyFiles)
|
---|
1081 | {
|
---|
1082 | fDots = 0;
|
---|
1083 | uint32_t const cBitmap = RT_ALIGN_32(g_cManyFiles, 64);
|
---|
1084 | void *pvBitmap = alloca(cBitmap / 8);
|
---|
1085 | RT_BZERO(pvBitmap, cBitmap / 8);
|
---|
1086 | for (uint32_t i = g_cManyFiles; i < cBitmap; i++)
|
---|
1087 | ASMBitSet(pvBitmap, i);
|
---|
1088 |
|
---|
1089 | uint32_t cFiles = 0;
|
---|
1090 | RTTESTI_CHECK_RC_RETV(RTDirOpen(&hDir, InDir(RT_STR_TUPLE("manyfiles"))), VINF_SUCCESS);
|
---|
1091 | for (;;)
|
---|
1092 | {
|
---|
1093 | int rc = RTDirRead(hDir, &Entry, NULL);
|
---|
1094 | if (rc == VINF_SUCCESS)
|
---|
1095 | {
|
---|
1096 | if (Entry.szName[0] == '.')
|
---|
1097 | {
|
---|
1098 | if (Entry.szName[1] == '.')
|
---|
1099 | {
|
---|
1100 | RTTESTI_CHECK(!(fDots & 2));
|
---|
1101 | fDots |= 2;
|
---|
1102 | }
|
---|
1103 | else
|
---|
1104 | {
|
---|
1105 | RTTESTI_CHECK(Entry.szName[1] == '\0');
|
---|
1106 | RTTESTI_CHECK(!(fDots & 1));
|
---|
1107 | fDots |= 1;
|
---|
1108 | }
|
---|
1109 | }
|
---|
1110 | else
|
---|
1111 | {
|
---|
1112 | uint32_t iFile = UINT32_MAX;
|
---|
1113 | RTTESTI_CHECK_RC(RTStrToUInt32Full(Entry.szName, 10, &iFile), VINF_SUCCESS);
|
---|
1114 | if ( iFile < g_cManyFiles
|
---|
1115 | && !ASMBitTest(pvBitmap, iFile))
|
---|
1116 | {
|
---|
1117 | ASMBitSet(pvBitmap, iFile);
|
---|
1118 | cFiles++;
|
---|
1119 | }
|
---|
1120 | else
|
---|
1121 | RTTestFailed(g_hTest, "line %u: iFile=%u g_cManyFiles=%u\n", __LINE__, iFile, g_cManyFiles);
|
---|
1122 | }
|
---|
1123 | }
|
---|
1124 | else if (rc == VERR_NO_MORE_FILES)
|
---|
1125 | break;
|
---|
1126 | else
|
---|
1127 | {
|
---|
1128 | RTTestFailed(g_hTest, "RTDirRead failed enumerating manyfiles: %Rrc\n", rc);
|
---|
1129 | RTDirClose(hDir);
|
---|
1130 | return;
|
---|
1131 | }
|
---|
1132 | }
|
---|
1133 | RTTESTI_CHECK_RC(RTDirClose(hDir), VINF_SUCCESS);
|
---|
1134 | RTTESTI_CHECK(fDots == 3);
|
---|
1135 | RTTESTI_CHECK(cFiles == g_cManyFiles);
|
---|
1136 | RTTESTI_CHECK(ASMMemIsAllU8(pvBitmap, cBitmap / 8, 0xff));
|
---|
1137 | }
|
---|
1138 |
|
---|
1139 | /*
|
---|
1140 | * Profile.
|
---|
1141 | */
|
---|
1142 | PROFILE_FN(fsPerfEnumEmpty(),g_nsTestRun, "RTDirOpen/Read/Close empty");
|
---|
1143 | if (g_fManyFiles)
|
---|
1144 | PROFILE_FN(fsPerfEnumManyFiles(), g_nsTestRun, "RTDirOpen/Read/Close manyfiles");
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 |
|
---|
1148 | void fsPerfMkRmDir(void)
|
---|
1149 | {
|
---|
1150 | RTTestISub("mkdir/rmdir");
|
---|
1151 |
|
---|
1152 | /* Non-existing directories: */
|
---|
1153 | RTTESTI_CHECK_RC(RTDirRemove(InEmptyDir(RT_STR_TUPLE("no-such-dir"))), VERR_FILE_NOT_FOUND);
|
---|
1154 | RTTESTI_CHECK_RC(RTDirRemove(InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file"))), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
1155 | RTTESTI_CHECK_RC(RTDirRemove(InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file"))), VERR_PATH_NOT_FOUND);
|
---|
1156 | RTTESTI_CHECK_RC(RTDirCreate(InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file")), 0755, 0), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
1157 | RTTESTI_CHECK_RC(RTDirCreate(InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file")), 0755, 0), VERR_PATH_NOT_FOUND);
|
---|
1158 |
|
---|
1159 | /** @todo check what happens if non-final path component isn't a directory. unix
|
---|
1160 | * should return ENOTDIR and IPRT translates that to VERR_PATH_NOT_FOUND.
|
---|
1161 | * Curious what happens on windows. */
|
---|
1162 |
|
---|
1163 | /* Already existing directories and files: */
|
---|
1164 | RTTESTI_CHECK_RC(RTDirCreate(InEmptyDir(RT_STR_TUPLE(".")), 0755, 0), VERR_ALREADY_EXISTS);
|
---|
1165 | RTTESTI_CHECK_RC(RTDirCreate(InEmptyDir(RT_STR_TUPLE("..")), 0755, 0), VERR_ALREADY_EXISTS);
|
---|
1166 |
|
---|
1167 | /* Remove directory with subdirectories: */
|
---|
1168 | #if defined(RT_OS_WINDOWS)
|
---|
1169 | RTTESTI_CHECK_RC(RTDirRemove(InDir(RT_STR_TUPLE("."))), VERR_DIR_NOT_EMPTY);
|
---|
1170 | #else
|
---|
1171 | RTTESTI_CHECK_RC(RTDirRemove(InDir(RT_STR_TUPLE("."))), VERR_INVALID_PARAMETER); /* EINVAL for '.' */
|
---|
1172 | #endif
|
---|
1173 | #if defined(RT_OS_WINDOWS)
|
---|
1174 | RTTESTI_CHECK_RC(RTDirRemove(InDir(RT_STR_TUPLE(".."))), VERR_SHARING_VIOLATION); /* weird */
|
---|
1175 | #else
|
---|
1176 | RTTESTI_CHECK_RC(RTDirRemove(InDir(RT_STR_TUPLE(".."))), VERR_DIR_NOT_EMPTY);
|
---|
1177 | #endif
|
---|
1178 | RTTESTI_CHECK_RC(RTDirRemove(InDir(RT_STR_TUPLE(""))), VERR_DIR_NOT_EMPTY);
|
---|
1179 |
|
---|
1180 | /* Create a directory and remove it: */
|
---|
1181 | RTTESTI_CHECK_RC(RTDirCreate(InDir(RT_STR_TUPLE("subdir-1")), 0755, 0), VINF_SUCCESS);
|
---|
1182 | RTTESTI_CHECK_RC(RTDirRemove(g_szDir), VINF_SUCCESS);
|
---|
1183 |
|
---|
1184 | /* Create a file and try remove it or create a directory with the same name: */
|
---|
1185 | RTFILE hFile1;
|
---|
1186 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file18")),
|
---|
1187 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
1188 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
1189 | RTTESTI_CHECK_RC(RTDirRemove(g_szDir), VERR_NOT_A_DIRECTORY);
|
---|
1190 | RTTESTI_CHECK_RC(RTDirCreate(g_szDir, 0755, 0), VERR_ALREADY_EXISTS);
|
---|
1191 | RTTESTI_CHECK_RC(RTDirCreate(InDir(RT_STR_TUPLE("file18" RTPATH_SLASH_STR "subdir")), 0755, 0), VERR_PATH_NOT_FOUND);
|
---|
1192 |
|
---|
1193 | /*
|
---|
1194 | * Profile alternately creating and removing a bunch of directories.
|
---|
1195 | */
|
---|
1196 | RTTESTI_CHECK_RC_RETV(RTDirCreate(InDir(RT_STR_TUPLE("subdir-2")), 0755, 0), VINF_SUCCESS);
|
---|
1197 | size_t cchDir = strlen(g_szDir);
|
---|
1198 | g_szDir[cchDir++] = RTPATH_SLASH;
|
---|
1199 | g_szDir[cchDir++] = 's';
|
---|
1200 |
|
---|
1201 | uint32_t cCreated = 0;
|
---|
1202 | uint64_t nsCreate = 0;
|
---|
1203 | uint64_t nsRemove = 0;
|
---|
1204 | for (;;)
|
---|
1205 | {
|
---|
1206 | /* Create a bunch: */
|
---|
1207 | uint64_t nsStart = RTTimeNanoTS();
|
---|
1208 | for (uint32_t i = 0; i < 998; i++)
|
---|
1209 | {
|
---|
1210 | RTStrFormatU32(&g_szDir[cchDir], sizeof(g_szDir) - cchDir, i, 10, 3, 3, RTSTR_F_ZEROPAD);
|
---|
1211 | RTTESTI_CHECK_RC_RETV(RTDirCreate(g_szDir, 0755, 0), VINF_SUCCESS);
|
---|
1212 | }
|
---|
1213 | nsCreate += RTTimeNanoTS() - nsStart;
|
---|
1214 | cCreated += 998;
|
---|
1215 |
|
---|
1216 | /* Remove the bunch: */
|
---|
1217 | nsStart = RTTimeNanoTS();
|
---|
1218 | for (uint32_t i = 0; i < 998; i++)
|
---|
1219 | {
|
---|
1220 | RTStrFormatU32(&g_szDir[cchDir], sizeof(g_szDir) - cchDir, i, 10, 3, 3, RTSTR_F_ZEROPAD);
|
---|
1221 | RTTESTI_CHECK_RC_RETV(RTDirRemove(g_szDir), VINF_SUCCESS);
|
---|
1222 | }
|
---|
1223 | nsRemove = RTTimeNanoTS() - nsStart;
|
---|
1224 |
|
---|
1225 | /* Check if we got time for another round: */
|
---|
1226 | if ( ( nsRemove >= g_nsTestRun
|
---|
1227 | && nsCreate >= g_nsTestRun)
|
---|
1228 | || nsCreate + nsRemove >= g_nsTestRun * 3)
|
---|
1229 | break;
|
---|
1230 | }
|
---|
1231 | RTTestIValue("RTDirCreate", nsCreate / cCreated, RTTESTUNIT_NS_PER_OCCURRENCE);
|
---|
1232 | RTTestIValue("RTDirRemove", nsRemove / cCreated, RTTESTUNIT_NS_PER_OCCURRENCE);
|
---|
1233 | }
|
---|
1234 |
|
---|
1235 |
|
---|
1236 | void fsPerfStatVfs(void)
|
---|
1237 | {
|
---|
1238 | RTTestISub("statvfs");
|
---|
1239 |
|
---|
1240 | g_szEmptyDir[g_cchEmptyDir] = '\0';
|
---|
1241 | RTFOFF cbTotal;
|
---|
1242 | RTFOFF cbFree;
|
---|
1243 | uint32_t cbBlock;
|
---|
1244 | uint32_t cbSector;
|
---|
1245 | RTTESTI_CHECK_RC(RTFsQuerySizes(g_szEmptyDir, &cbTotal, &cbFree, &cbBlock, &cbSector), VINF_SUCCESS);
|
---|
1246 |
|
---|
1247 | uint32_t uSerial;
|
---|
1248 | RTTESTI_CHECK_RC(RTFsQuerySerial(g_szEmptyDir, &uSerial), VINF_SUCCESS);
|
---|
1249 |
|
---|
1250 | RTFSPROPERTIES Props;
|
---|
1251 | RTTESTI_CHECK_RC(RTFsQueryProperties(g_szEmptyDir, &Props), VINF_SUCCESS);
|
---|
1252 |
|
---|
1253 | RTFSTYPE enmType;
|
---|
1254 | RTTESTI_CHECK_RC(RTFsQueryType(g_szEmptyDir, &enmType), VINF_SUCCESS);
|
---|
1255 |
|
---|
1256 | g_szDeepDir[g_cchDeepDir] = '\0';
|
---|
1257 | PROFILE_FN(RTFsQuerySizes(g_szEmptyDir, &cbTotal, &cbFree, &cbBlock, &cbSector), g_nsTestRun, "RTFsQuerySize/empty");
|
---|
1258 | PROFILE_FN(RTFsQuerySizes(g_szDeepDir, &cbTotal, &cbFree, &cbBlock, &cbSector), g_nsTestRun, "RTFsQuerySize/deep");
|
---|
1259 | }
|
---|
1260 |
|
---|
1261 |
|
---|
1262 | void fsPerfRm(void)
|
---|
1263 | {
|
---|
1264 | RTTestISub("rm");
|
---|
1265 |
|
---|
1266 | /* Non-existing files. */
|
---|
1267 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE("no-such-file"))), VERR_FILE_NOT_FOUND);
|
---|
1268 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file"))), FSPERF_VERR_PATH_NOT_FOUND);
|
---|
1269 | RTTESTI_CHECK_RC(RTFileDelete(InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file"))), VERR_PATH_NOT_FOUND);
|
---|
1270 |
|
---|
1271 | /* Directories: */
|
---|
1272 | #if defined(RT_OS_WINDOWS)
|
---|
1273 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE("."))), VERR_ACCESS_DENIED);
|
---|
1274 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE(".."))), VERR_ACCESS_DENIED);
|
---|
1275 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE(""))), VERR_ACCESS_DENIED);
|
---|
1276 | #elif defined(RT_OS_DARWIN) /* unlink() on xnu 16.7.0 is behaviour totally werid: */
|
---|
1277 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE("."))), VERR_INVALID_PARAMETER);
|
---|
1278 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE(".."))), VINF_SUCCESS /*WTF?!?*/);
|
---|
1279 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE(""))), VERR_ACCESS_DENIED);
|
---|
1280 | #else
|
---|
1281 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE("."))), VERR_IS_A_DIRECTORY);
|
---|
1282 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE(".."))), VERR_IS_A_DIRECTORY);
|
---|
1283 | RTTESTI_CHECK_RC(RTFileDelete(InEmptyDir(RT_STR_TUPLE(""))), VERR_IS_A_DIRECTORY);
|
---|
1284 | #endif
|
---|
1285 |
|
---|
1286 | /* Shallow: */
|
---|
1287 | RTFILE hFile1;
|
---|
1288 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file19")),
|
---|
1289 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_WRITE), VINF_SUCCESS);
|
---|
1290 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
1291 | RTTESTI_CHECK_RC(RTFileDelete(g_szDir), VINF_SUCCESS);
|
---|
1292 | RTTESTI_CHECK_RC(RTFileDelete(g_szDir), VERR_FILE_NOT_FOUND);
|
---|
1293 |
|
---|
1294 | if (g_fManyFiles)
|
---|
1295 | {
|
---|
1296 | /*
|
---|
1297 | * Profile the deletion of the manyfiles content.
|
---|
1298 | */
|
---|
1299 | {
|
---|
1300 | InDir(RT_STR_TUPLE("manyfiles" RTPATH_SLASH_STR));
|
---|
1301 | size_t const offFilename = strlen(g_szDir);
|
---|
1302 | fsPerfYield();
|
---|
1303 | uint64_t const nsStart = RTTimeNanoTS();
|
---|
1304 | for (uint32_t i = 0; i < g_cManyFiles; i++)
|
---|
1305 | {
|
---|
1306 | RTStrFormatU32(&g_szDir[offFilename], sizeof(g_szDir) - offFilename, i, 10, 5, 5, RTSTR_F_ZEROPAD);
|
---|
1307 | RTTESTI_CHECK_RC_RETV(RTFileDelete(g_szDir), VINF_SUCCESS);
|
---|
1308 | }
|
---|
1309 | uint64_t const cNsElapsed = RTTimeNanoTS() - nsStart;
|
---|
1310 | RTTestIValueF(cNsElapsed, RTTESTUNIT_NS, "Deleted %u empty files from a single directory", g_cManyFiles);
|
---|
1311 | RTTestIValueF(cNsElapsed / g_cManyFiles, RTTESTUNIT_NS_PER_OCCURRENCE, "Delete file (single dir)");
|
---|
1312 | }
|
---|
1313 |
|
---|
1314 | /*
|
---|
1315 | * Ditto for the manytree.
|
---|
1316 | */
|
---|
1317 | {
|
---|
1318 | char szPath[RTPATH_MAX];
|
---|
1319 | uint64_t const nsStart = RTTimeNanoTS();
|
---|
1320 | DO_MANYTREE_FN(szPath, RTTESTI_CHECK_RC_RETV(RTFileDelete(szPath), VINF_SUCCESS));
|
---|
1321 | uint64_t const cNsElapsed = RTTimeNanoTS() - nsStart;
|
---|
1322 | RTTestIValueF(cNsElapsed, RTTESTUNIT_NS, "Deleted %u empty files in tree", g_cManyTreeFiles);
|
---|
1323 | RTTestIValueF(cNsElapsed / g_cManyTreeFiles, RTTESTUNIT_NS_PER_OCCURRENCE, "Delete file (tree)");
|
---|
1324 | }
|
---|
1325 | }
|
---|
1326 | }
|
---|
1327 |
|
---|
1328 |
|
---|
1329 | void fsPerfChSize(void)
|
---|
1330 | {
|
---|
1331 | RTTestISub("chsize");
|
---|
1332 |
|
---|
1333 | /*
|
---|
1334 | * We need some free space to perform this test.
|
---|
1335 | */
|
---|
1336 | g_szDir[g_cchDir] = '\0';
|
---|
1337 | RTFOFF cbFree = 0;
|
---|
1338 | RTTESTI_CHECK_RC_RETV(RTFsQuerySizes(g_szDir, NULL, &cbFree, NULL, NULL), VINF_SUCCESS);
|
---|
1339 | if (cbFree < _1M)
|
---|
1340 | {
|
---|
1341 | RTTestSkipped(g_hTest, "Insufficent free space: %'RU64 bytes, requires >= 1MB", cbFree);
|
---|
1342 | return;
|
---|
1343 | }
|
---|
1344 |
|
---|
1345 | /*
|
---|
1346 | * Create a file and play around with it's size.
|
---|
1347 | * We let the current file position follow the end position as we make changes.
|
---|
1348 | */
|
---|
1349 | RTFILE hFile1;
|
---|
1350 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file20")),
|
---|
1351 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_READWRITE), VINF_SUCCESS);
|
---|
1352 | uint64_t cbFile = UINT64_MAX;
|
---|
1353 | RTTESTI_CHECK_RC(RTFileGetSize(hFile1, &cbFile), VINF_SUCCESS);
|
---|
1354 | RTTESTI_CHECK(cbFile == 0);
|
---|
1355 |
|
---|
1356 | uint8_t abBuf[4096];
|
---|
1357 | static uint64_t const s_acbChanges[] =
|
---|
1358 | {
|
---|
1359 | 1023, 1024, 1024, 1025, 8192, 11111, _1M, _8M, _8M,
|
---|
1360 | _4M, _2M + 1, _1M - 1, 65537, 65536, 32768, 8000, 7999, 7998, 1024, 1, 0
|
---|
1361 | };
|
---|
1362 | uint64_t cbOld = 0;
|
---|
1363 | for (unsigned i = 0; i < RT_ELEMENTS(s_acbChanges); i++)
|
---|
1364 | {
|
---|
1365 | uint64_t cbNew = s_acbChanges[i];
|
---|
1366 | if (cbNew + _64K >= (uint64_t)cbFree)
|
---|
1367 | continue;
|
---|
1368 |
|
---|
1369 | RTTESTI_CHECK_RC(RTFileSetSize(hFile1, cbNew), VINF_SUCCESS);
|
---|
1370 | RTTESTI_CHECK_RC(RTFileGetSize(hFile1, &cbFile), VINF_SUCCESS);
|
---|
1371 | RTTESTI_CHECK_MSG(cbFile == cbNew, ("cbFile=%#RX64 cbNew=%#RX64\n", cbFile, cbNew));
|
---|
1372 |
|
---|
1373 | if (cbNew > cbOld)
|
---|
1374 | {
|
---|
1375 | /* Check that the extension is all zeroed: */
|
---|
1376 | uint64_t cbLeft = cbNew - cbOld;
|
---|
1377 | while (cbLeft > 0)
|
---|
1378 | {
|
---|
1379 | memset(abBuf, 0xff, sizeof(abBuf));
|
---|
1380 | size_t cbToRead = sizeof(abBuf);
|
---|
1381 | if (cbToRead > cbLeft)
|
---|
1382 | cbToRead = (size_t)cbLeft;
|
---|
1383 | RTTESTI_CHECK_RC(RTFileRead(hFile1, abBuf, cbToRead, NULL), VINF_SUCCESS);
|
---|
1384 | RTTESTI_CHECK(ASMMemIsZero(abBuf, cbToRead));
|
---|
1385 | cbLeft -= cbToRead;
|
---|
1386 | }
|
---|
1387 | }
|
---|
1388 | else
|
---|
1389 | {
|
---|
1390 | /* Check that reading fails with EOF because current position is now beyond the end: */
|
---|
1391 | RTTESTI_CHECK_RC(RTFileRead(hFile1, abBuf, 1, NULL), VERR_EOF);
|
---|
1392 |
|
---|
1393 | /* Keep current position at the end of the file: */
|
---|
1394 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, cbNew, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
1395 | }
|
---|
1396 | cbOld = cbNew;
|
---|
1397 | }
|
---|
1398 |
|
---|
1399 | /*
|
---|
1400 | * Profile just the file setting operation itself, keeping the changes within
|
---|
1401 | * an allocation unit to avoid needing to adjust the actual (host) FS allocation.
|
---|
1402 | * ASSUMES allocation unit >= 512 and power of two.
|
---|
1403 | */
|
---|
1404 | RTTESTI_CHECK_RC(RTFileSetSize(hFile1, _64K), VINF_SUCCESS);
|
---|
1405 | PROFILE_FN(RTFileSetSize(hFile1, _64K - (iIteration & 255) - 128), g_nsTestRun, "RTFileSetSize/noalloc");
|
---|
1406 |
|
---|
1407 | RTTESTI_CHECK_RC(RTFileSetSize(hFile1, 0), VINF_SUCCESS);
|
---|
1408 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
1409 | RTTESTI_CHECK_RC(RTFileDelete(g_szDir), VINF_SUCCESS);
|
---|
1410 | }
|
---|
1411 |
|
---|
1412 |
|
---|
1413 | int fsPerfIoPrepFile(RTFILE hFile1, uint64_t cbFile, uint8_t **ppbFree)
|
---|
1414 | {
|
---|
1415 | /*
|
---|
1416 | * Seek to the end - 4K and write the last 4K.
|
---|
1417 | * This should have the effect of filling the whole file with zeros.
|
---|
1418 | */
|
---|
1419 | RTTESTI_CHECK_RC_RET(RTFileSeek(hFile1, cbFile - _4K, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS, rcCheck);
|
---|
1420 | RTTESTI_CHECK_RC_RET(RTFileWrite(hFile1, g_abRTZero4K, _4K, NULL), VINF_SUCCESS, rcCheck);
|
---|
1421 |
|
---|
1422 | /*
|
---|
1423 | * Check that the space we searched across actually is zero filled.
|
---|
1424 | */
|
---|
1425 | RTTESTI_CHECK_RC_RET(RTFileSeek(hFile1, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS, rcCheck);
|
---|
1426 | size_t cbBuf = _1M;
|
---|
1427 | uint8_t *pbBuf = *ppbFree = (uint8_t *)RTMemAlloc(cbBuf);
|
---|
1428 | RTTESTI_CHECK_RET(pbBuf != NULL, VERR_NO_MEMORY);
|
---|
1429 | uint64_t cbLeft = cbFile;
|
---|
1430 | while (cbLeft > 0)
|
---|
1431 | {
|
---|
1432 | size_t cbToRead = cbBuf;
|
---|
1433 | if (cbToRead > cbLeft)
|
---|
1434 | cbToRead = (size_t)cbLeft;
|
---|
1435 | pbBuf[cbToRead] = 0xff;
|
---|
1436 |
|
---|
1437 | RTTESTI_CHECK_RC_RET(RTFileRead(hFile1, pbBuf, cbToRead, NULL), VINF_SUCCESS, rcCheck);
|
---|
1438 | RTTESTI_CHECK_RET(ASMMemIsZero(pbBuf, cbToRead), VERR_MISMATCH);
|
---|
1439 |
|
---|
1440 | cbLeft -= cbToRead;
|
---|
1441 | }
|
---|
1442 |
|
---|
1443 | /*
|
---|
1444 | * Fill the file with 0xf6 and insert offset markers with 1KB intervals.
|
---|
1445 | */
|
---|
1446 | RTTESTI_CHECK_RC_RET(RTFileSeek(hFile1, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS, rcCheck);
|
---|
1447 | memset(pbBuf, 0xf6, cbBuf);
|
---|
1448 | cbLeft = cbFile;
|
---|
1449 | uint64_t off = 0;
|
---|
1450 | while (cbLeft > 0)
|
---|
1451 | {
|
---|
1452 | Assert(!(off & (_1K - 1)));
|
---|
1453 | Assert(!(cbBuf & (_1K - 1)));
|
---|
1454 | for (size_t offBuf = 0; offBuf < cbBuf; offBuf += _1K, off += _1K)
|
---|
1455 | *(uint64_t *)&pbBuf[offBuf] = off;
|
---|
1456 |
|
---|
1457 | size_t cbToWrite = cbBuf;
|
---|
1458 | if (cbToWrite > cbLeft)
|
---|
1459 | cbToWrite = (size_t)cbLeft;
|
---|
1460 |
|
---|
1461 | RTTESTI_CHECK_RC_RET(RTFileWrite(hFile1, pbBuf, cbToWrite, NULL), VINF_SUCCESS, rcCheck);
|
---|
1462 |
|
---|
1463 | cbLeft -= cbToWrite;
|
---|
1464 | }
|
---|
1465 |
|
---|
1466 | return VINF_SUCCESS;
|
---|
1467 | }
|
---|
1468 |
|
---|
1469 |
|
---|
1470 | /**
|
---|
1471 | * Checks the content read from the file fsPerfIoPrepFile() prepared.
|
---|
1472 | */
|
---|
1473 | bool fsPerfCheckReadBuf(unsigned uLineNo, uint64_t off, uint8_t const *pbBuf, size_t cbBuf, uint8_t bFiller = 0xf6)
|
---|
1474 | {
|
---|
1475 | uint32_t cMismatches = 0;
|
---|
1476 | size_t offBuf = 0;
|
---|
1477 | uint32_t offBlock = (uint32_t)(off & (_1K - 1));
|
---|
1478 | while (offBuf < cbBuf)
|
---|
1479 | {
|
---|
1480 | /*
|
---|
1481 | * Check the offset marker:
|
---|
1482 | */
|
---|
1483 | if (offBlock < sizeof(uint64_t))
|
---|
1484 | {
|
---|
1485 | RTUINT64U uMarker;
|
---|
1486 | uMarker.u = off + offBuf - offBlock;
|
---|
1487 | unsigned offMarker = offBlock & (sizeof(uint64_t) - 1);
|
---|
1488 | while (offMarker < sizeof(uint64_t) && offBuf < cbBuf)
|
---|
1489 | {
|
---|
1490 | if (uMarker.au8[offMarker] != pbBuf[offBuf])
|
---|
1491 | {
|
---|
1492 | RTTestIFailed("%u: Mismatch at buffer/file offset %#zx/%#RX64: %#x, expected %#x",
|
---|
1493 | uLineNo, offBuf, off + offBuf, pbBuf[offBuf], uMarker.au8[offMarker]);
|
---|
1494 | if (cMismatches++ > 32)
|
---|
1495 | return false;
|
---|
1496 | }
|
---|
1497 | offMarker++;
|
---|
1498 | offBuf++;
|
---|
1499 | }
|
---|
1500 | offBlock = sizeof(uint64_t);
|
---|
1501 | }
|
---|
1502 |
|
---|
1503 | /*
|
---|
1504 | * Check the filling:
|
---|
1505 | */
|
---|
1506 | size_t cbFilling = RT_MIN(_1K - offBlock, cbBuf - offBuf);
|
---|
1507 | if ( cbFilling == 0
|
---|
1508 | || ASMMemIsAllU8(&pbBuf[offBuf], cbFilling, bFiller))
|
---|
1509 | offBuf += cbFilling;
|
---|
1510 | else
|
---|
1511 | {
|
---|
1512 | /* Some mismatch, locate it/them: */
|
---|
1513 | while (cbFilling > 0 && offBuf < cbBuf)
|
---|
1514 | {
|
---|
1515 | if (pbBuf[offBuf] != bFiller)
|
---|
1516 | {
|
---|
1517 | RTTestIFailed("%u: Mismatch at buffer/file offset %#zx/%#RX64: %#x, expected %#04x",
|
---|
1518 | uLineNo, offBuf, off + offBuf, pbBuf[offBuf], bFiller);
|
---|
1519 | if (cMismatches++ > 32)
|
---|
1520 | return false;
|
---|
1521 | }
|
---|
1522 | offBuf++;
|
---|
1523 | cbFilling--;
|
---|
1524 | }
|
---|
1525 | }
|
---|
1526 | offBlock = 0;
|
---|
1527 | }
|
---|
1528 | return cMismatches == 0;
|
---|
1529 | }
|
---|
1530 |
|
---|
1531 |
|
---|
1532 | /**
|
---|
1533 | * Sets up write buffer with offset markers and fillers.
|
---|
1534 | */
|
---|
1535 | void fsPerfFillWriteBuf(uint64_t off, uint8_t *pbBuf, size_t cbBuf, uint8_t bFiller = 0xf6)
|
---|
1536 | {
|
---|
1537 | uint32_t offBlock = (uint32_t)(off & (_1K - 1));
|
---|
1538 | while (cbBuf > 0)
|
---|
1539 | {
|
---|
1540 | /* The marker. */
|
---|
1541 | if (offBlock < sizeof(uint64_t))
|
---|
1542 | {
|
---|
1543 | RTUINT64U uMarker;
|
---|
1544 | uMarker.u = off + offBlock;
|
---|
1545 | if (cbBuf > sizeof(uMarker) - offBlock)
|
---|
1546 | {
|
---|
1547 | memcpy(pbBuf, &uMarker.au8[offBlock], sizeof(uMarker) - offBlock);
|
---|
1548 | pbBuf += sizeof(uMarker) - offBlock;
|
---|
1549 | cbBuf -= sizeof(uMarker) - offBlock;
|
---|
1550 | off += sizeof(uMarker) - offBlock;
|
---|
1551 | }
|
---|
1552 | else
|
---|
1553 | {
|
---|
1554 | memcpy(pbBuf, &uMarker.au8[offBlock], cbBuf);
|
---|
1555 | return;
|
---|
1556 | }
|
---|
1557 | offBlock = sizeof(uint64_t);
|
---|
1558 | }
|
---|
1559 |
|
---|
1560 | /* Do the filling. */
|
---|
1561 | size_t cbFilling = RT_MIN(_1K - offBlock, cbBuf);
|
---|
1562 | memset(pbBuf, bFiller, cbFilling);
|
---|
1563 | pbBuf += cbFilling;
|
---|
1564 | cbBuf -= cbFilling;
|
---|
1565 | off += cbFilling;
|
---|
1566 |
|
---|
1567 | offBlock = 0;
|
---|
1568 | }
|
---|
1569 | }
|
---|
1570 |
|
---|
1571 |
|
---|
1572 |
|
---|
1573 | void fsPerfIoSeek(RTFILE hFile1, uint64_t cbFile)
|
---|
1574 | {
|
---|
1575 | /*
|
---|
1576 | * Do a bunch of search tests, most which are random.
|
---|
1577 | */
|
---|
1578 | struct
|
---|
1579 | {
|
---|
1580 | int rc;
|
---|
1581 | uint32_t uMethod;
|
---|
1582 | int64_t offSeek;
|
---|
1583 | uint64_t offActual;
|
---|
1584 |
|
---|
1585 | } aSeeks[9 + 64] =
|
---|
1586 | {
|
---|
1587 | { VINF_SUCCESS, RTFILE_SEEK_BEGIN, 0, 0 },
|
---|
1588 | { VINF_SUCCESS, RTFILE_SEEK_CURRENT, 0, 0 },
|
---|
1589 | { VINF_SUCCESS, RTFILE_SEEK_END, 0, cbFile },
|
---|
1590 | { VINF_SUCCESS, RTFILE_SEEK_CURRENT, -4096, cbFile - 4096 },
|
---|
1591 | { VINF_SUCCESS, RTFILE_SEEK_CURRENT, 4096 - (int64_t)cbFile, 0 },
|
---|
1592 | { VINF_SUCCESS, RTFILE_SEEK_END, -(int64_t)cbFile/2, cbFile / 2 + (cbFile & 1) },
|
---|
1593 | { VINF_SUCCESS, RTFILE_SEEK_CURRENT, -(int64_t)cbFile/2, 0 },
|
---|
1594 | #if defined(RT_OS_WINDOWS)
|
---|
1595 | { VERR_NEGATIVE_SEEK, RTFILE_SEEK_CURRENT, -1, 0 },
|
---|
1596 | #else
|
---|
1597 | { VERR_INVALID_PARAMETER, RTFILE_SEEK_CURRENT, -1, 0 },
|
---|
1598 | #endif
|
---|
1599 | { VINF_SUCCESS, RTFILE_SEEK_CURRENT, 0, 0 },
|
---|
1600 | };
|
---|
1601 |
|
---|
1602 | uint64_t offActual = 0;
|
---|
1603 | for (unsigned i = 9; i < RT_ELEMENTS(aSeeks); i++)
|
---|
1604 | {
|
---|
1605 | switch (RTRandU32Ex(RTFILE_SEEK_BEGIN, RTFILE_SEEK_END))
|
---|
1606 | {
|
---|
1607 | default: AssertFailedBreak();
|
---|
1608 | case RTFILE_SEEK_BEGIN:
|
---|
1609 | aSeeks[i].uMethod = RTFILE_SEEK_BEGIN;
|
---|
1610 | aSeeks[i].rc = VINF_SUCCESS;
|
---|
1611 | aSeeks[i].offSeek = RTRandU64Ex(0, cbFile + cbFile / 8);
|
---|
1612 | aSeeks[i].offActual = offActual = aSeeks[i].offSeek;
|
---|
1613 | break;
|
---|
1614 |
|
---|
1615 | case RTFILE_SEEK_CURRENT:
|
---|
1616 | aSeeks[i].uMethod = RTFILE_SEEK_CURRENT;
|
---|
1617 | aSeeks[i].rc = VINF_SUCCESS;
|
---|
1618 | aSeeks[i].offSeek = (int64_t)RTRandU64Ex(0, cbFile + cbFile / 8) - (int64_t)offActual;
|
---|
1619 | aSeeks[i].offActual = offActual += aSeeks[i].offSeek;
|
---|
1620 | break;
|
---|
1621 |
|
---|
1622 | case RTFILE_SEEK_END:
|
---|
1623 | aSeeks[i].uMethod = RTFILE_SEEK_END;
|
---|
1624 | aSeeks[i].rc = VINF_SUCCESS;
|
---|
1625 | aSeeks[i].offSeek = -(int64_t)RTRandU64Ex(0, cbFile);
|
---|
1626 | aSeeks[i].offActual = offActual = cbFile + aSeeks[i].offSeek;
|
---|
1627 | break;
|
---|
1628 | }
|
---|
1629 | }
|
---|
1630 |
|
---|
1631 | for (unsigned iDoReadCheck = 0; iDoReadCheck < 2; iDoReadCheck++)
|
---|
1632 | {
|
---|
1633 | for (uint32_t i = 0; i < RT_ELEMENTS(aSeeks); i++)
|
---|
1634 | {
|
---|
1635 | offActual = UINT64_MAX;
|
---|
1636 | int rc = RTFileSeek(hFile1, aSeeks[i].offSeek, aSeeks[i].uMethod, &offActual);
|
---|
1637 | if (rc != aSeeks[i].rc)
|
---|
1638 | RTTestIFailed("Seek #%u: Expected %Rrc, got %Rrc", i, aSeeks[i].rc, rc);
|
---|
1639 | if (RT_SUCCESS(rc) && offActual != aSeeks[i].offActual)
|
---|
1640 | RTTestIFailed("Seek #%u: offActual %#RX64, expected %#RX64", i, offActual, aSeeks[i].offActual);
|
---|
1641 | if (RT_SUCCESS(rc))
|
---|
1642 | {
|
---|
1643 | uint64_t offTell = RTFileTell(hFile1);
|
---|
1644 | if (offTell != offActual)
|
---|
1645 | RTTestIFailed("Seek #%u: offActual %#RX64, RTFileTell %#RX64", i, offActual, offTell);
|
---|
1646 | }
|
---|
1647 |
|
---|
1648 | if (RT_SUCCESS(rc) && offActual + _2K <= cbFile && iDoReadCheck)
|
---|
1649 | {
|
---|
1650 | uint8_t abBuf[_2K];
|
---|
1651 | RTTESTI_CHECK_RC(rc = RTFileRead(hFile1, abBuf, sizeof(abBuf), NULL), VINF_SUCCESS);
|
---|
1652 | if (RT_SUCCESS(rc))
|
---|
1653 | {
|
---|
1654 | size_t offMarker = (size_t)(RT_ALIGN_64(offActual, _1K) - offActual);
|
---|
1655 | uint64_t uMarker = *(uint64_t *)&abBuf[offMarker]; /** @todo potentially unaligned access */
|
---|
1656 | if (uMarker != offActual + offMarker)
|
---|
1657 | RTTestIFailed("Seek #%u: Invalid marker value (@ %#RX64): %#RX64, expected %#RX64",
|
---|
1658 | i, offActual, uMarker, offActual + offMarker);
|
---|
1659 |
|
---|
1660 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, -(int64_t)sizeof(abBuf), RTFILE_SEEK_CURRENT, NULL), VINF_SUCCESS);
|
---|
1661 | }
|
---|
1662 | }
|
---|
1663 | }
|
---|
1664 | }
|
---|
1665 |
|
---|
1666 |
|
---|
1667 | /*
|
---|
1668 | * Profile seeking relative to the beginning of the file and relative
|
---|
1669 | * to the end. The latter might be more expensive in a SF context.
|
---|
1670 | */
|
---|
1671 | PROFILE_FN(RTFileSeek(hFile1, iIteration < cbFile ? iIteration : iIteration % cbFile, RTFILE_SEEK_BEGIN, NULL),
|
---|
1672 | g_nsTestRun, "RTFileSeek/BEGIN");
|
---|
1673 | PROFILE_FN(RTFileSeek(hFile1, iIteration < cbFile ? -(int64_t)iIteration : -(int64_t)(iIteration % cbFile), RTFILE_SEEK_END, NULL),
|
---|
1674 | g_nsTestRun, "RTFileSeek/END");
|
---|
1675 |
|
---|
1676 | }
|
---|
1677 |
|
---|
1678 |
|
---|
1679 | /** For fsPerfIoRead and fsPerfIoWrite. */
|
---|
1680 | #define PROFILE_IO_FN(a_szOperation, a_fnCall) \
|
---|
1681 | do \
|
---|
1682 | { \
|
---|
1683 | RTTESTI_CHECK_RC_RETV(RTFileSeek(hFile1, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS); \
|
---|
1684 | uint64_t offActual = 0; \
|
---|
1685 | uint32_t cSeeks = 0; \
|
---|
1686 | \
|
---|
1687 | /* Estimate how many iterations we need to fill up the given timeslot: */ \
|
---|
1688 | fsPerfYield(); \
|
---|
1689 | uint64_t nsStart = RTTimeNanoTS(); \
|
---|
1690 | uint64_t ns; \
|
---|
1691 | do \
|
---|
1692 | ns = RTTimeNanoTS(); \
|
---|
1693 | while (ns == nsStart); \
|
---|
1694 | nsStart = ns; \
|
---|
1695 | \
|
---|
1696 | uint64_t iIteration = 0; \
|
---|
1697 | do \
|
---|
1698 | { \
|
---|
1699 | RTTESTI_CHECK_RC(a_fnCall, VINF_SUCCESS); \
|
---|
1700 | iIteration++; \
|
---|
1701 | ns = RTTimeNanoTS() - nsStart; \
|
---|
1702 | } while (ns < RT_NS_10MS); \
|
---|
1703 | ns /= iIteration; \
|
---|
1704 | if (ns > g_nsPerNanoTSCall + 32) \
|
---|
1705 | ns -= g_nsPerNanoTSCall; \
|
---|
1706 | uint64_t cIterations = g_nsTestRun / ns; \
|
---|
1707 | if (cIterations < 2) \
|
---|
1708 | cIterations = 2; \
|
---|
1709 | else if (cIterations & 1) \
|
---|
1710 | cIterations++; \
|
---|
1711 | \
|
---|
1712 | /* Do the actual profiling: */ \
|
---|
1713 | cSeeks = 0; \
|
---|
1714 | iIteration = 0; \
|
---|
1715 | fsPerfYield(); \
|
---|
1716 | nsStart = RTTimeNanoTS(); \
|
---|
1717 | for (uint32_t iAdjust = 0; iAdjust < 4; iAdjust++) \
|
---|
1718 | { \
|
---|
1719 | for (; iIteration < cIterations; iIteration++)\
|
---|
1720 | RTTESTI_CHECK_RC(a_fnCall, VINF_SUCCESS); \
|
---|
1721 | ns = RTTimeNanoTS() - nsStart;\
|
---|
1722 | if (ns >= g_nsTestRun - (g_nsTestRun / 10)) \
|
---|
1723 | break; \
|
---|
1724 | cIterations += cIterations / 4; \
|
---|
1725 | if (cIterations & 1) \
|
---|
1726 | cIterations++; \
|
---|
1727 | nsStart += g_nsPerNanoTSCall; \
|
---|
1728 | } \
|
---|
1729 | RTTestIValueF(ns / iIteration, \
|
---|
1730 | RTTESTUNIT_NS_PER_OCCURRENCE, a_szOperation "/seq/%RU32 latency", cbBlock); \
|
---|
1731 | RTTestIValueF((uint64_t)((uint64_t)iIteration * cbBlock / ((double)ns / RT_NS_1SEC)), \
|
---|
1732 | RTTESTUNIT_BYTES_PER_SEC, a_szOperation "/seq/%RU32 throughput", cbBlock); \
|
---|
1733 | RTTestIValueF(iIteration, \
|
---|
1734 | RTTESTUNIT_CALLS, a_szOperation "/seq/%RU32 calls", cbBlock); \
|
---|
1735 | RTTestIValueF((uint64_t)iIteration * cbBlock, \
|
---|
1736 | RTTESTUNIT_BYTES, a_szOperation "/seq/%RU32 bytes", cbBlock); \
|
---|
1737 | RTTestIValueF(cSeeks, \
|
---|
1738 | RTTESTUNIT_OCCURRENCES, a_szOperation "/seq/%RU32 seeks", cbBlock); \
|
---|
1739 | if (g_fShowDuration) \
|
---|
1740 | RTTestIValueF(ns, RTTESTUNIT_NS, a_szOperation "/seq/%RU32 duration", cbBlock); \
|
---|
1741 | } while (0)
|
---|
1742 |
|
---|
1743 |
|
---|
1744 | /**
|
---|
1745 | * One RTFileRead profiling iteration.
|
---|
1746 | */
|
---|
1747 | DECL_FORCE_INLINE(int) fsPerfIoReadWorker(RTFILE hFile1, uint64_t cbFile, uint32_t cbBlock, uint8_t *pbBlock,
|
---|
1748 | uint64_t *poffActual, uint32_t *pcSeeks)
|
---|
1749 | {
|
---|
1750 | /* Do we need to seek back to the start? */
|
---|
1751 | if (*poffActual + cbBlock <= cbFile)
|
---|
1752 | { /* likely */ }
|
---|
1753 | else
|
---|
1754 | {
|
---|
1755 | RTTESTI_CHECK_RC_RET(RTFileSeek(hFile1, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS, rcCheck);
|
---|
1756 | *pcSeeks += 1;
|
---|
1757 | *poffActual = 0;
|
---|
1758 | }
|
---|
1759 |
|
---|
1760 | size_t cbActuallyRead = 0;
|
---|
1761 | RTTESTI_CHECK_RC_RET(RTFileRead(hFile1, pbBlock, cbBlock, &cbActuallyRead), VINF_SUCCESS, rcCheck);
|
---|
1762 | if (cbActuallyRead == cbBlock)
|
---|
1763 | {
|
---|
1764 | *poffActual += cbActuallyRead;
|
---|
1765 | return VINF_SUCCESS;
|
---|
1766 | }
|
---|
1767 | RTTestIFailed("RTFileRead at %#RX64 returned just %#x bytes, expected %#x", *poffActual, cbActuallyRead, cbBlock);
|
---|
1768 | *poffActual += cbActuallyRead;
|
---|
1769 | return VERR_READ_ERROR;
|
---|
1770 | }
|
---|
1771 |
|
---|
1772 |
|
---|
1773 | void fsPerfIoReadBlockSize(RTFILE hFile1, uint64_t cbFile, uint32_t cbBlock)
|
---|
1774 | {
|
---|
1775 | RTTestISubF("IO - Sequential read %RU32", cbBlock);
|
---|
1776 |
|
---|
1777 | uint8_t *pbBuf = (uint8_t *)RTMemPageAlloc(cbBlock);
|
---|
1778 | if (pbBuf)
|
---|
1779 | {
|
---|
1780 | memset(pbBuf, 0xf7, cbBlock);
|
---|
1781 | PROFILE_IO_FN("RTFileRead", fsPerfIoReadWorker(hFile1, cbFile, cbBlock, pbBuf, &offActual, &cSeeks));
|
---|
1782 | RTMemPageFree(pbBuf, cbBlock);
|
---|
1783 | }
|
---|
1784 | else
|
---|
1785 | RTTestSkipped(g_hTest, "insufficient (virtual) memory available");
|
---|
1786 | }
|
---|
1787 |
|
---|
1788 |
|
---|
1789 | void fsPerfRead(RTFILE hFile1, RTFILE hFileNoCache, uint64_t cbFile)
|
---|
1790 | {
|
---|
1791 | RTTestISubF("IO - RTFileRead");
|
---|
1792 |
|
---|
1793 | /*
|
---|
1794 | * Allocate a big buffer we can play around with. Min size is 1MB.
|
---|
1795 | */
|
---|
1796 | size_t cbBuf = cbFile < _64M ? (size_t)cbFile : _64M;
|
---|
1797 | uint8_t *pbBuf = (uint8_t *)RTMemPageAlloc(cbBuf);
|
---|
1798 | while (!pbBuf)
|
---|
1799 | {
|
---|
1800 | cbBuf /= 2;
|
---|
1801 | RTTESTI_CHECK_RETV(cbBuf >= _1M);
|
---|
1802 | pbBuf = (uint8_t *)RTMemPageAlloc(_32M);
|
---|
1803 | }
|
---|
1804 |
|
---|
1805 | #if 1
|
---|
1806 | /*
|
---|
1807 | * Start at the beginning and read the full buffer in random small chunks, thereby
|
---|
1808 | * checking that unaligned buffer addresses, size and file offsets work fine.
|
---|
1809 | */
|
---|
1810 | struct
|
---|
1811 | {
|
---|
1812 | uint64_t offFile;
|
---|
1813 | uint32_t cbMax;
|
---|
1814 | } aRuns[] = { { 0, 127 }, { cbFile - cbBuf, UINT32_MAX }, { 0, UINT32_MAX -1 }};
|
---|
1815 | for (uint32_t i = 0; i < RT_ELEMENTS(aRuns); i++)
|
---|
1816 | {
|
---|
1817 | memset(pbBuf, 0x55, cbBuf);
|
---|
1818 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, aRuns[i].offFile, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
1819 | for (size_t offBuf = 0; offBuf < cbBuf; )
|
---|
1820 | {
|
---|
1821 | uint32_t const cbLeft = (uint32_t)(cbBuf - offBuf);
|
---|
1822 | uint32_t const cbToRead = aRuns[i].cbMax < UINT32_MAX / 2 ? RTRandU32Ex(1, RT_MIN(aRuns[i].cbMax, cbLeft))
|
---|
1823 | : aRuns[i].cbMax == UINT32_MAX ? RTRandU32Ex(RT_MAX(cbLeft / 4, 1), cbLeft)
|
---|
1824 | : RTRandU32Ex(cbLeft >= _8K ? _8K : 1, RT_MIN(_1M, cbLeft));
|
---|
1825 | size_t cbActual = 0;
|
---|
1826 | RTTESTI_CHECK_RC(RTFileRead(hFile1, &pbBuf[offBuf], cbToRead, &cbActual), VINF_SUCCESS);
|
---|
1827 | if (cbActual == cbToRead)
|
---|
1828 | offBuf += cbActual;
|
---|
1829 | else
|
---|
1830 | {
|
---|
1831 | RTTestIFailed("Attempting to read %#x bytes at %#zx, only got %#x bytes back! (cbLeft=%#x cbBuf=%#zx)\n",
|
---|
1832 | cbToRead, offBuf, cbActual, cbLeft, cbBuf);
|
---|
1833 | if (cbActual)
|
---|
1834 | offBuf += cbActual;
|
---|
1835 | else
|
---|
1836 | pbBuf[offBuf++] = 0x11;
|
---|
1837 | }
|
---|
1838 | }
|
---|
1839 | fsPerfCheckReadBuf(__LINE__, aRuns[i].offFile, pbBuf, cbBuf);
|
---|
1840 | }
|
---|
1841 | #endif
|
---|
1842 |
|
---|
1843 | /*
|
---|
1844 | * Test reading beyond the end of the file.
|
---|
1845 | */
|
---|
1846 | size_t const acbMax[] = { cbBuf, _64K, _16K, _4K, 256 };
|
---|
1847 | uint32_t const aoffFromEos[] =
|
---|
1848 | { 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,
|
---|
1849 | 4092, 4093, 4094, 4095, 4096, 4097, 4098, 4099, 4100, 8192, 16384, 32767, 32768, 32769, 65535, 65536, _1M - 1
|
---|
1850 | };
|
---|
1851 | for (unsigned iMax = 0; iMax < RT_ELEMENTS(acbMax); iMax++)
|
---|
1852 | {
|
---|
1853 | size_t const cbMaxRead = acbMax[iMax];
|
---|
1854 | for (uint32_t iOffFromEos = 0; iOffFromEos < RT_ELEMENTS(aoffFromEos); iOffFromEos++)
|
---|
1855 | {
|
---|
1856 | uint32_t off = aoffFromEos[iOffFromEos];
|
---|
1857 | if (off >= cbMaxRead)
|
---|
1858 | continue;
|
---|
1859 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, cbFile - off, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
1860 | size_t cbActual = ~(size_t)0;
|
---|
1861 | RTTESTI_CHECK_RC(RTFileRead(hFile1, pbBuf, cbMaxRead, &cbActual), VINF_SUCCESS);
|
---|
1862 | RTTESTI_CHECK(cbActual == off);
|
---|
1863 |
|
---|
1864 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, cbFile - off, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
1865 | cbActual = ~(size_t)0;
|
---|
1866 | RTTESTI_CHECK_RC(RTFileRead(hFile1, pbBuf, off, &cbActual), VINF_SUCCESS);
|
---|
1867 | RTTESTI_CHECK_MSG(cbActual == off, ("%#zx vs %#zx", cbActual, off));
|
---|
1868 |
|
---|
1869 | cbActual = ~(size_t)0;
|
---|
1870 | RTTESTI_CHECK_RC(RTFileRead(hFile1, pbBuf, 1, &cbActual), VINF_SUCCESS);
|
---|
1871 | RTTESTI_CHECK(cbActual == 0);
|
---|
1872 |
|
---|
1873 | RTTESTI_CHECK_RC(RTFileRead(hFile1, pbBuf, cbMaxRead, NULL), VERR_EOF);
|
---|
1874 | }
|
---|
1875 | }
|
---|
1876 |
|
---|
1877 | /*
|
---|
1878 | * Test reading beyond end of the file.
|
---|
1879 | */
|
---|
1880 | for (unsigned iMax = 0; iMax < RT_ELEMENTS(acbMax); iMax++)
|
---|
1881 | {
|
---|
1882 | size_t const cbMaxRead = acbMax[iMax];
|
---|
1883 | for (uint32_t off = 0; off < 256; off++)
|
---|
1884 | {
|
---|
1885 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, cbFile + off, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
1886 | size_t cbActual = ~(size_t)0;
|
---|
1887 | RTTESTI_CHECK_RC(RTFileRead(hFile1, pbBuf, cbMaxRead, &cbActual), VINF_SUCCESS);
|
---|
1888 | RTTESTI_CHECK(cbActual == 0);
|
---|
1889 |
|
---|
1890 | RTTESTI_CHECK_RC(RTFileRead(hFile1, pbBuf, cbMaxRead, NULL), VERR_EOF);
|
---|
1891 | }
|
---|
1892 | }
|
---|
1893 |
|
---|
1894 | /*
|
---|
1895 | * Do uncached access, must be page aligned.
|
---|
1896 | */
|
---|
1897 | uint32_t cbPage = PAGE_SIZE;
|
---|
1898 | memset(pbBuf, 0x66, cbBuf);
|
---|
1899 | if (!g_fIgnoreNoCache || hFileNoCache != NIL_RTFILE)
|
---|
1900 | {
|
---|
1901 | RTTESTI_CHECK_RC(RTFileSeek(hFileNoCache, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
1902 | for (size_t offBuf = 0; offBuf < cbBuf; )
|
---|
1903 | {
|
---|
1904 | uint32_t const cPagesLeft = (uint32_t)((cbBuf - offBuf) / cbPage);
|
---|
1905 | uint32_t const cPagesToRead = RTRandU32Ex(1, cPagesLeft);
|
---|
1906 | size_t const cbToRead = cPagesToRead * (size_t)cbPage;
|
---|
1907 | size_t cbActual = 0;
|
---|
1908 | RTTESTI_CHECK_RC(RTFileRead(hFileNoCache, &pbBuf[offBuf], cbToRead, &cbActual), VINF_SUCCESS);
|
---|
1909 | if (cbActual == cbToRead)
|
---|
1910 | offBuf += cbActual;
|
---|
1911 | else
|
---|
1912 | {
|
---|
1913 | RTTestIFailed("Attempting to read %#zx bytes at %#zx, only got %#x bytes back!\n", cbToRead, offBuf, cbActual);
|
---|
1914 | if (cbActual)
|
---|
1915 | offBuf += cbActual;
|
---|
1916 | else
|
---|
1917 | {
|
---|
1918 | memset(&pbBuf[offBuf], 0x11, cbPage);
|
---|
1919 | offBuf += cbPage;
|
---|
1920 | }
|
---|
1921 | }
|
---|
1922 | }
|
---|
1923 | fsPerfCheckReadBuf(__LINE__, 0, pbBuf, cbBuf);
|
---|
1924 | }
|
---|
1925 |
|
---|
1926 | /*
|
---|
1927 | * Check reading zero bytes at the end of the file.
|
---|
1928 | * Requires native call because RTFileWrite doesn't call kernel on zero byte reads.
|
---|
1929 | */
|
---|
1930 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, 0, RTFILE_SEEK_END, NULL), VINF_SUCCESS);
|
---|
1931 | #ifdef RT_OS_WINDOWS
|
---|
1932 | IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
|
---|
1933 | NTSTATUS rcNt = NtReadFile((HANDLE)RTFileToNative(hFile1), NULL, NULL, NULL, &Ios, pbBuf, 0, NULL, NULL);
|
---|
1934 | RTTESTI_CHECK_MSG(rcNt == STATUS_SUCCESS, ("rcNt=%#x", rcNt));
|
---|
1935 | RTTESTI_CHECK(Ios.Status == STATUS_SUCCESS);
|
---|
1936 | RTTESTI_CHECK(Ios.Information == 0);
|
---|
1937 |
|
---|
1938 | RTNT_IO_STATUS_BLOCK_REINIT(&Ios);
|
---|
1939 | rcNt = NtReadFile((HANDLE)RTFileToNative(hFile1), NULL, NULL, NULL, &Ios, pbBuf, 1, NULL, NULL);
|
---|
1940 | RTTESTI_CHECK_MSG(rcNt == STATUS_END_OF_FILE, ("rcNt=%#x", rcNt));
|
---|
1941 | RTTESTI_CHECK(Ios.Status == STATUS_END_OF_FILE);
|
---|
1942 | RTTESTI_CHECK(Ios.Information == 0);
|
---|
1943 | #else
|
---|
1944 | ssize_t cbRead = read((int)RTFileToNative(hFile1), pbBuf, 0);
|
---|
1945 | RTTESTI_CHECK(cbRead == 0);
|
---|
1946 | #endif
|
---|
1947 |
|
---|
1948 | /*
|
---|
1949 | * Other OS specific stuff.
|
---|
1950 | */
|
---|
1951 | #ifdef RT_OS_WINDOWS
|
---|
1952 | /* Check that reading at an offset modifies the position: */
|
---|
1953 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, 0, RTFILE_SEEK_END, NULL), VINF_SUCCESS);
|
---|
1954 | RTTESTI_CHECK(RTFileTell(hFile1) == cbFile);
|
---|
1955 |
|
---|
1956 | RTNT_IO_STATUS_BLOCK_REINIT(&Ios);
|
---|
1957 | LARGE_INTEGER offNt;
|
---|
1958 | offNt.QuadPart = cbFile / 2;
|
---|
1959 | rcNt = NtReadFile((HANDLE)RTFileToNative(hFile1), NULL, NULL, NULL, &Ios, pbBuf, _4K, &offNt, NULL);
|
---|
1960 | RTTESTI_CHECK_MSG(rcNt == STATUS_SUCCESS, ("rcNt=%#x", rcNt));
|
---|
1961 | RTTESTI_CHECK(Ios.Status == STATUS_SUCCESS);
|
---|
1962 | RTTESTI_CHECK(Ios.Information == _4K);
|
---|
1963 | RTTESTI_CHECK(RTFileTell(hFile1) == cbFile / 2 + _4K);
|
---|
1964 | fsPerfCheckReadBuf(__LINE__, cbFile / 2, pbBuf, _4K);
|
---|
1965 | #endif
|
---|
1966 |
|
---|
1967 | RTMemPageFree(pbBuf, cbBuf);
|
---|
1968 | }
|
---|
1969 |
|
---|
1970 |
|
---|
1971 | /**
|
---|
1972 | * One RTFileWrite profiling iteration.
|
---|
1973 | */
|
---|
1974 | DECL_FORCE_INLINE(int) fsPerfIoWriteWorker(RTFILE hFile1, uint64_t cbFile, uint32_t cbBlock, uint8_t *pbBlock,
|
---|
1975 | uint64_t *poffActual, uint32_t *pcSeeks)
|
---|
1976 | {
|
---|
1977 | /* Do we need to seek back to the start? */
|
---|
1978 | if (*poffActual + cbBlock <= cbFile)
|
---|
1979 | { /* likely */ }
|
---|
1980 | else
|
---|
1981 | {
|
---|
1982 | RTTESTI_CHECK_RC_RET(RTFileSeek(hFile1, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS, rcCheck);
|
---|
1983 | *pcSeeks += 1;
|
---|
1984 | *poffActual = 0;
|
---|
1985 | }
|
---|
1986 |
|
---|
1987 | size_t cbActuallyWritten = 0;
|
---|
1988 | RTTESTI_CHECK_RC_RET(RTFileWrite(hFile1, pbBlock, cbBlock, &cbActuallyWritten), VINF_SUCCESS, rcCheck);
|
---|
1989 | if (cbActuallyWritten == cbBlock)
|
---|
1990 | {
|
---|
1991 | *poffActual += cbActuallyWritten;
|
---|
1992 | return VINF_SUCCESS;
|
---|
1993 | }
|
---|
1994 | RTTestIFailed("RTFileWrite at %#RX64 returned just %#x bytes, expected %#x", *poffActual, cbActuallyWritten, cbBlock);
|
---|
1995 | *poffActual += cbActuallyWritten;
|
---|
1996 | return VERR_WRITE_ERROR;
|
---|
1997 | }
|
---|
1998 |
|
---|
1999 |
|
---|
2000 | void fsPerfIoWriteBlockSize(RTFILE hFile1, uint64_t cbFile, uint32_t cbBlock)
|
---|
2001 | {
|
---|
2002 | RTTestISubF("IO - Sequential write %RU32", cbBlock);
|
---|
2003 |
|
---|
2004 | uint8_t *pbBuf = (uint8_t *)RTMemPageAlloc(cbBlock);
|
---|
2005 | if (pbBuf)
|
---|
2006 | {
|
---|
2007 | memset(pbBuf, 0xf7, cbBlock);
|
---|
2008 | PROFILE_IO_FN("RTFileWrite", fsPerfIoWriteWorker(hFile1, cbFile, cbBlock, pbBuf, &offActual, &cSeeks));
|
---|
2009 | RTMemPageFree(pbBuf, cbBlock);
|
---|
2010 | }
|
---|
2011 | else
|
---|
2012 | RTTestSkipped(g_hTest, "insufficient (virtual) memory available");
|
---|
2013 | }
|
---|
2014 |
|
---|
2015 |
|
---|
2016 | void fsPerfWrite(RTFILE hFile1, RTFILE hFileNoCache, RTFILE hFileWriteThru, uint64_t cbFile)
|
---|
2017 | {
|
---|
2018 | RTTestISubF("IO - RTFileWrite");
|
---|
2019 |
|
---|
2020 | /*
|
---|
2021 | * Allocate a big buffer we can play around with. Min size is 1MB.
|
---|
2022 | */
|
---|
2023 | size_t cbBuf = cbFile < _64M ? (size_t)cbFile : _64M;
|
---|
2024 | uint8_t *pbBuf = (uint8_t *)RTMemPageAlloc(cbBuf);
|
---|
2025 | while (!pbBuf)
|
---|
2026 | {
|
---|
2027 | cbBuf /= 2;
|
---|
2028 | RTTESTI_CHECK_RETV(cbBuf >= _1M);
|
---|
2029 | pbBuf = (uint8_t *)RTMemPageAlloc(_32M);
|
---|
2030 | }
|
---|
2031 |
|
---|
2032 | /*
|
---|
2033 | * Start at the beginning and write out the full buffer in random small chunks, thereby
|
---|
2034 | * checking that unaligned buffer addresses, size and file offsets work fine.
|
---|
2035 | */
|
---|
2036 | struct
|
---|
2037 | {
|
---|
2038 | uint64_t offFile;
|
---|
2039 | uint32_t cbMax;
|
---|
2040 | } aRuns[] = { { 0, 127 }, { cbFile - cbBuf, UINT32_MAX }, { 0, UINT32_MAX -1 }};
|
---|
2041 | uint8_t bFiller = 0x88;
|
---|
2042 | for (uint32_t i = 0; i < RT_ELEMENTS(aRuns); i++, bFiller)
|
---|
2043 | {
|
---|
2044 | fsPerfFillWriteBuf(aRuns[i].offFile, pbBuf, cbBuf, bFiller);
|
---|
2045 | fsPerfCheckReadBuf(__LINE__, aRuns[i].offFile, pbBuf, cbBuf, bFiller);
|
---|
2046 |
|
---|
2047 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, aRuns[i].offFile, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2048 | for (size_t offBuf = 0; offBuf < cbBuf; )
|
---|
2049 | {
|
---|
2050 | uint32_t const cbLeft = (uint32_t)(cbBuf - offBuf);
|
---|
2051 | uint32_t const cbToWrite = aRuns[i].cbMax < UINT32_MAX / 2 ? RTRandU32Ex(1, RT_MIN(aRuns[i].cbMax, cbLeft))
|
---|
2052 | : aRuns[i].cbMax == UINT32_MAX ? RTRandU32Ex(RT_MAX(cbLeft / 4, 1), cbLeft)
|
---|
2053 | : RTRandU32Ex(cbLeft >= _8K ? _8K : 1, RT_MIN(_1M, cbLeft));
|
---|
2054 | size_t cbActual = 0;
|
---|
2055 | RTTESTI_CHECK_RC(RTFileWrite(hFile1, &pbBuf[offBuf], cbToWrite, &cbActual), VINF_SUCCESS);
|
---|
2056 | if (cbActual == cbToWrite)
|
---|
2057 | offBuf += cbActual;
|
---|
2058 | else
|
---|
2059 | {
|
---|
2060 | RTTestIFailed("Attempting to write %#x bytes at %#zx (%#x left), only got %#x written!\n",
|
---|
2061 | cbToWrite, offBuf, cbLeft, cbActual);
|
---|
2062 | if (cbActual)
|
---|
2063 | offBuf += cbActual;
|
---|
2064 | else
|
---|
2065 | pbBuf[offBuf++] = 0x11;
|
---|
2066 | }
|
---|
2067 | }
|
---|
2068 |
|
---|
2069 | RTTESTI_CHECK_RC(RTFileReadAt(hFile1, aRuns[i].offFile, pbBuf, cbBuf, NULL), VINF_SUCCESS);
|
---|
2070 | fsPerfCheckReadBuf(__LINE__, aRuns[i].offFile, pbBuf, cbBuf, bFiller);
|
---|
2071 | }
|
---|
2072 |
|
---|
2073 |
|
---|
2074 | /*
|
---|
2075 | * Do uncached and write-thru accesses, must be page aligned.
|
---|
2076 | */
|
---|
2077 | RTFILE ahFiles[2] = { hFileWriteThru, hFileNoCache };
|
---|
2078 | for (unsigned iFile = 0; iFile < RT_ELEMENTS(ahFiles); iFile++, bFiller++)
|
---|
2079 | {
|
---|
2080 | if (g_fIgnoreNoCache && ahFiles[iFile] == NIL_RTFILE)
|
---|
2081 | continue;
|
---|
2082 |
|
---|
2083 | fsPerfFillWriteBuf(0, pbBuf, cbBuf, bFiller);
|
---|
2084 | fsPerfCheckReadBuf(__LINE__, 0, pbBuf, cbBuf, bFiller);
|
---|
2085 | RTTESTI_CHECK_RC(RTFileSeek(ahFiles[iFile], 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2086 |
|
---|
2087 | uint32_t cbPage = PAGE_SIZE;
|
---|
2088 | for (size_t offBuf = 0; offBuf < cbBuf; )
|
---|
2089 | {
|
---|
2090 | uint32_t const cPagesLeft = (uint32_t)((cbBuf - offBuf) / cbPage);
|
---|
2091 | uint32_t const cPagesToWrite = RTRandU32Ex(1, cPagesLeft);
|
---|
2092 | size_t const cbToWrite = cPagesToWrite * (size_t)cbPage;
|
---|
2093 | size_t cbActual = 0;
|
---|
2094 | RTTESTI_CHECK_RC(RTFileWrite(ahFiles[iFile], &pbBuf[offBuf], cbToWrite, &cbActual), VINF_SUCCESS);
|
---|
2095 | if (cbActual == cbToWrite)
|
---|
2096 | {
|
---|
2097 | RTTESTI_CHECK_RC(RTFileReadAt(hFile1, offBuf, pbBuf, cbToWrite, NULL), VINF_SUCCESS);
|
---|
2098 | fsPerfCheckReadBuf(__LINE__, offBuf, pbBuf, cbToWrite, bFiller);
|
---|
2099 | offBuf += cbActual;
|
---|
2100 | }
|
---|
2101 | else
|
---|
2102 | {
|
---|
2103 | RTTestIFailed("Attempting to read %#zx bytes at %#zx, only got %#x written!\n", cbToWrite, offBuf, cbActual);
|
---|
2104 | if (cbActual)
|
---|
2105 | offBuf += cbActual;
|
---|
2106 | else
|
---|
2107 | {
|
---|
2108 | memset(&pbBuf[offBuf], 0x11, cbPage);
|
---|
2109 | offBuf += cbPage;
|
---|
2110 | }
|
---|
2111 | }
|
---|
2112 | }
|
---|
2113 |
|
---|
2114 | RTTESTI_CHECK_RC(RTFileReadAt(ahFiles[iFile], 0, pbBuf, cbBuf, NULL), VINF_SUCCESS);
|
---|
2115 | fsPerfCheckReadBuf(__LINE__, 0, pbBuf, cbBuf, bFiller);
|
---|
2116 | }
|
---|
2117 |
|
---|
2118 | /*
|
---|
2119 | * Check the behavior of writing zero bytes to the file _4K from the end
|
---|
2120 | * using native API. In the olden days zero sized write have been known
|
---|
2121 | * to be used to truncate a file.
|
---|
2122 | */
|
---|
2123 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, -_4K, RTFILE_SEEK_END, NULL), VINF_SUCCESS);
|
---|
2124 | #ifdef RT_OS_WINDOWS
|
---|
2125 | IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
|
---|
2126 | NTSTATUS rcNt = NtWriteFile((HANDLE)RTFileToNative(hFile1), NULL, NULL, NULL, &Ios, pbBuf, 0, NULL, NULL);
|
---|
2127 | RTTESTI_CHECK_MSG(rcNt == STATUS_SUCCESS, ("rcNt=%#x", rcNt));
|
---|
2128 | RTTESTI_CHECK(Ios.Status == STATUS_SUCCESS);
|
---|
2129 | RTTESTI_CHECK(Ios.Information == 0);
|
---|
2130 | #else
|
---|
2131 | ssize_t cbWritten = write((int)RTFileToNative(hFile1), pbBuf, 0);
|
---|
2132 | RTTESTI_CHECK(cbWritten == 0);
|
---|
2133 | #endif
|
---|
2134 | RTTESTI_CHECK_RC(RTFileRead(hFile1, pbBuf, _4K, NULL), VINF_SUCCESS);
|
---|
2135 | fsPerfCheckReadBuf(__LINE__, cbFile - _4K, pbBuf, _4K, pbBuf[0x8]);
|
---|
2136 |
|
---|
2137 | /*
|
---|
2138 | * Other OS specific stuff.
|
---|
2139 | */
|
---|
2140 | #ifdef RT_OS_WINDOWS
|
---|
2141 | /* Check that reading at an offset modifies the position: */
|
---|
2142 | RTTESTI_CHECK_RC(RTFileReadAt(hFile1, cbFile / 2, pbBuf, _4K, NULL), VINF_SUCCESS);
|
---|
2143 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, 0, RTFILE_SEEK_END, NULL), VINF_SUCCESS);
|
---|
2144 | RTTESTI_CHECK(RTFileTell(hFile1) == cbFile);
|
---|
2145 |
|
---|
2146 | RTNT_IO_STATUS_BLOCK_REINIT(&Ios);
|
---|
2147 | LARGE_INTEGER offNt;
|
---|
2148 | offNt.QuadPart = cbFile / 2;
|
---|
2149 | rcNt = NtWriteFile((HANDLE)RTFileToNative(hFile1), NULL, NULL, NULL, &Ios, pbBuf, _4K, &offNt, NULL);
|
---|
2150 | RTTESTI_CHECK_MSG(rcNt == STATUS_SUCCESS, ("rcNt=%#x", rcNt));
|
---|
2151 | RTTESTI_CHECK(Ios.Status == STATUS_SUCCESS);
|
---|
2152 | RTTESTI_CHECK(Ios.Information == _4K);
|
---|
2153 | RTTESTI_CHECK(RTFileTell(hFile1) == cbFile / 2 + _4K);
|
---|
2154 | #endif
|
---|
2155 |
|
---|
2156 | RTMemPageFree(pbBuf, cbBuf);
|
---|
2157 | }
|
---|
2158 |
|
---|
2159 |
|
---|
2160 | /**
|
---|
2161 | * Worker for testing RTFileFlush.
|
---|
2162 | */
|
---|
2163 | DECL_FORCE_INLINE(int) fsPerfFSyncWorker(RTFILE hFile1, uint64_t cbFile, uint8_t *pbBuf, size_t cbBuf, uint64_t *poffFile)
|
---|
2164 | {
|
---|
2165 | if (*poffFile + cbBuf <= cbFile)
|
---|
2166 | { /* likely */ }
|
---|
2167 | else
|
---|
2168 | {
|
---|
2169 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2170 | *poffFile = 0;
|
---|
2171 | }
|
---|
2172 |
|
---|
2173 | RTTESTI_CHECK_RC_RET(RTFileWrite(hFile1, pbBuf, cbBuf, NULL), VINF_SUCCESS, rcCheck);
|
---|
2174 | RTTESTI_CHECK_RC_RET(RTFileFlush(hFile1), VINF_SUCCESS, rcCheck);
|
---|
2175 |
|
---|
2176 | *poffFile += cbBuf;
|
---|
2177 | return VINF_SUCCESS;
|
---|
2178 | }
|
---|
2179 |
|
---|
2180 |
|
---|
2181 | void fsPerfFSync(RTFILE hFile1, uint64_t cbFile)
|
---|
2182 | {
|
---|
2183 | RTTestISub("fsync");
|
---|
2184 |
|
---|
2185 | RTTESTI_CHECK_RC(RTFileFlush(hFile1), VINF_SUCCESS);
|
---|
2186 |
|
---|
2187 | PROFILE_FN(RTFileFlush(hFile1), g_nsTestRun, "RTFileFlush");
|
---|
2188 |
|
---|
2189 | size_t cbBuf = PAGE_SIZE;
|
---|
2190 | uint8_t *pbBuf = (uint8_t *)RTMemPageAlloc(cbBuf);
|
---|
2191 | RTTESTI_CHECK_RETV(pbBuf != NULL);
|
---|
2192 | memset(pbBuf, 0xf4, cbBuf);
|
---|
2193 |
|
---|
2194 | RTTESTI_CHECK_RC(RTFileSeek(hFile1, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2195 | uint64_t offFile = 0;
|
---|
2196 | PROFILE_FN(fsPerfFSyncWorker(hFile1, cbFile, pbBuf, cbBuf, &offFile), g_nsTestRun, "RTFileWrite[Page]/RTFileFlush");
|
---|
2197 |
|
---|
2198 | RTMemPageFree(pbBuf, cbBuf);
|
---|
2199 | }
|
---|
2200 |
|
---|
2201 |
|
---|
2202 | #ifndef RT_OS_OS2
|
---|
2203 | /**
|
---|
2204 | * Worker for profiling msync.
|
---|
2205 | */
|
---|
2206 | DECL_FORCE_INLINE(int) fsPerfMSyncWorker(uint8_t *pbMapping, size_t offMapping, size_t cbFlush, size_t *pcbFlushed)
|
---|
2207 | {
|
---|
2208 | uint8_t *pbCur = &pbMapping[offMapping];
|
---|
2209 | for (size_t offFlush = 0; offFlush < cbFlush; offFlush += PAGE_SIZE)
|
---|
2210 | *(size_t volatile *)&pbCur[offFlush + 8] = cbFlush;
|
---|
2211 | # ifdef RT_OS_WINDOWS
|
---|
2212 | RTTESTI_CHECK(FlushViewOfFile(pbCur, cbFlush));
|
---|
2213 | # else
|
---|
2214 | RTTESTI_CHECK(msync(pbCur, cbFlush, MS_SYNC) == 0);
|
---|
2215 | # endif
|
---|
2216 | if (*pcbFlushed < offMapping + cbFlush)
|
---|
2217 | *pcbFlushed = offMapping + cbFlush;
|
---|
2218 | return VINF_SUCCESS;
|
---|
2219 | }
|
---|
2220 | #endif /* !RT_OS_OS2 */
|
---|
2221 |
|
---|
2222 |
|
---|
2223 | void fsPerfMMap(RTFILE hFile1, RTFILE hFileNoCache, uint64_t cbFile)
|
---|
2224 | {
|
---|
2225 | RTTestISub("mmap");
|
---|
2226 | #if !defined(RT_OS_OS2)
|
---|
2227 | static const char * const s_apszStates[] = { "readonly", "writecopy", "readwrite" };
|
---|
2228 | enum { kMMap_ReadOnly = 0, kMMap_WriteCopy, kMMap_ReadWrite, kMMap_End };
|
---|
2229 | for (int enmState = kMMap_ReadOnly; enmState < kMMap_End; enmState++)
|
---|
2230 | {
|
---|
2231 | /*
|
---|
2232 | * Do the mapping.
|
---|
2233 | */
|
---|
2234 | size_t cbMapping = (size_t)cbFile;
|
---|
2235 | if (cbMapping != cbFile)
|
---|
2236 | cbMapping = _256M;
|
---|
2237 | uint8_t *pbMapping;
|
---|
2238 |
|
---|
2239 | # ifdef RT_OS_WINDOWS
|
---|
2240 | HANDLE hSection;
|
---|
2241 | pbMapping = NULL;
|
---|
2242 | for (;; cbMapping /= 2)
|
---|
2243 | {
|
---|
2244 | hSection = CreateFileMapping((HANDLE)RTFileToNative(hFile1), NULL,
|
---|
2245 | enmState == kMMap_ReadOnly ? PAGE_READONLY
|
---|
2246 | : enmState == kMMap_WriteCopy ? PAGE_WRITECOPY : PAGE_READWRITE,
|
---|
2247 | (uint32_t)((uint64_t)cbMapping >> 32), (uint32_t)cbMapping, NULL);
|
---|
2248 | DWORD dwErr1 = GetLastError();
|
---|
2249 | DWORD dwErr2 = 0;
|
---|
2250 | if (hSection != NULL)
|
---|
2251 | {
|
---|
2252 | pbMapping = (uint8_t *)MapViewOfFile(hSection,
|
---|
2253 | enmState == kMMap_ReadOnly ? FILE_MAP_READ
|
---|
2254 | : enmState == kMMap_WriteCopy ? FILE_MAP_COPY
|
---|
2255 | : FILE_MAP_WRITE,
|
---|
2256 | 0, 0, cbMapping);
|
---|
2257 | if (pbMapping)
|
---|
2258 | break;
|
---|
2259 | dwErr2 = GetLastError();
|
---|
2260 | CloseHandle(hSection);
|
---|
2261 | }
|
---|
2262 | if (cbMapping <= _2M)
|
---|
2263 | {
|
---|
2264 | RTTestIFailed("%u/%s: CreateFileMapping or MapViewOfFile failed: %u, %u",
|
---|
2265 | enmState, s_apszStates[enmState], dwErr1, dwErr2);
|
---|
2266 | break;
|
---|
2267 | }
|
---|
2268 | }
|
---|
2269 | # else
|
---|
2270 | for (;; cbMapping /= 2)
|
---|
2271 | {
|
---|
2272 | pbMapping = (uint8_t *)mmap(NULL, cbMapping,
|
---|
2273 | enmState == kMMap_ReadOnly ? PROT_READ : PROT_READ | PROT_WRITE,
|
---|
2274 | enmState == kMMap_WriteCopy ? MAP_PRIVATE : MAP_SHARED,
|
---|
2275 | (int)RTFileToNative(hFile1), 0);
|
---|
2276 | if ((void *)pbMapping != MAP_FAILED)
|
---|
2277 | break;
|
---|
2278 | if (cbMapping <= _2M)
|
---|
2279 | {
|
---|
2280 | RTTestIFailed("%u/%s: mmap failed: %s (%u)", enmState, s_apszStates[enmState], strerror(errno), errno);
|
---|
2281 | break;
|
---|
2282 | }
|
---|
2283 | }
|
---|
2284 | # endif
|
---|
2285 | if (cbMapping <= _2M)
|
---|
2286 | continue;
|
---|
2287 |
|
---|
2288 | /*
|
---|
2289 | * Time page-ins just for fun.
|
---|
2290 | */
|
---|
2291 | size_t const cPages = cbMapping >> PAGE_SHIFT;
|
---|
2292 | size_t uDummy = 0;
|
---|
2293 | uint64_t ns = RTTimeNanoTS();
|
---|
2294 | for (size_t iPage = 0; iPage < cPages; iPage++)
|
---|
2295 | uDummy += ASMAtomicReadU8(&pbMapping[iPage << PAGE_SHIFT]);
|
---|
2296 | ns = RTTimeNanoTS() - ns;
|
---|
2297 | RTTestIValueF(ns / cPages, RTTESTUNIT_NS_PER_OCCURRENCE, "page-in %s", s_apszStates[enmState]);
|
---|
2298 |
|
---|
2299 | /* Check the content. */
|
---|
2300 | fsPerfCheckReadBuf(__LINE__, 0, pbMapping, cbMapping);
|
---|
2301 |
|
---|
2302 | if (enmState != kMMap_ReadOnly)
|
---|
2303 | {
|
---|
2304 | /* Write stuff to the first two megabytes. In the COW case, we'll detect
|
---|
2305 | corruption of shared data during content checking of the RW iterations. */
|
---|
2306 | fsPerfFillWriteBuf(0, pbMapping, _2M, 0xf7);
|
---|
2307 | if (enmState == kMMap_ReadWrite)
|
---|
2308 | {
|
---|
2309 | /* For RW we can try read back from the file handle and check if we get
|
---|
2310 | a match there first. */
|
---|
2311 | uint8_t abBuf[_4K];
|
---|
2312 | for (uint32_t off = 0; off < _2M; off += sizeof(abBuf))
|
---|
2313 | {
|
---|
2314 | RTTESTI_CHECK_RC(RTFileReadAt(hFile1, off, abBuf, sizeof(abBuf), NULL), VINF_SUCCESS);
|
---|
2315 | fsPerfCheckReadBuf(__LINE__, off, abBuf, sizeof(abBuf), 0xf7);
|
---|
2316 | }
|
---|
2317 | # ifdef RT_OS_WINDOWS
|
---|
2318 | RTTESTI_CHECK(FlushViewOfFile(pbMapping, _2M));
|
---|
2319 | # else
|
---|
2320 | RTTESTI_CHECK(msync(pbMapping, _2M, MS_SYNC) == 0);
|
---|
2321 | # endif
|
---|
2322 |
|
---|
2323 | /*
|
---|
2324 | * Time modifying and flushing a few different number of pages.
|
---|
2325 | */
|
---|
2326 | static size_t const s_acbFlush[] = { PAGE_SIZE, PAGE_SIZE * 2, PAGE_SIZE * 3, PAGE_SIZE * 8, PAGE_SIZE * 16, _2M };
|
---|
2327 | for (unsigned iFlushSize = 0 ; iFlushSize < RT_ELEMENTS(s_acbFlush); iFlushSize++)
|
---|
2328 | {
|
---|
2329 | size_t const cbFlush = s_acbFlush[iFlushSize];
|
---|
2330 | if (cbFlush > cbMapping)
|
---|
2331 | continue;
|
---|
2332 |
|
---|
2333 | char szDesc[80];
|
---|
2334 | RTStrPrintf(szDesc, sizeof(szDesc), "touch/flush/%zu", cbFlush);
|
---|
2335 | size_t const cFlushes = cbMapping / cbFlush;
|
---|
2336 | size_t const cbMappingUsed = cFlushes * cbFlush;
|
---|
2337 | size_t cbFlushed = 0;
|
---|
2338 | PROFILE_FN(fsPerfMSyncWorker(pbMapping, (iIteration * cbFlush) % cbMappingUsed, cbFlush, &cbFlushed),
|
---|
2339 | g_nsTestRun, szDesc);
|
---|
2340 |
|
---|
2341 | /*
|
---|
2342 | * Check that all the changes made it thru to the file:
|
---|
2343 | */
|
---|
2344 | if (!g_fIgnoreNoCache || hFileNoCache != NIL_RTFILE)
|
---|
2345 | {
|
---|
2346 | size_t cbBuf = _2M;
|
---|
2347 | uint8_t *pbBuf = (uint8_t *)RTMemPageAlloc(_2M);
|
---|
2348 | if (!pbBuf)
|
---|
2349 | {
|
---|
2350 | cbBuf = _4K;
|
---|
2351 | pbBuf = (uint8_t *)RTMemPageAlloc(_2M);
|
---|
2352 | }
|
---|
2353 | if (pbBuf)
|
---|
2354 | {
|
---|
2355 | RTTESTI_CHECK_RC(RTFileSeek(hFileNoCache, 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
|
---|
2356 | size_t const cbToCheck = RT_MIN(cFlushes * cbFlush, cbFlushed);
|
---|
2357 | unsigned cErrors = 0;
|
---|
2358 | for (size_t offBuf = 0; cErrors < 32 && offBuf < cbToCheck; offBuf += cbBuf)
|
---|
2359 | {
|
---|
2360 | size_t cbToRead = RT_MIN(cbBuf, cbToCheck - offBuf);
|
---|
2361 | RTTESTI_CHECK_RC(RTFileRead(hFileNoCache, pbBuf, cbToRead, NULL), VINF_SUCCESS);
|
---|
2362 |
|
---|
2363 | for (size_t offFlush = 0; offFlush < cbToRead; offFlush += PAGE_SIZE)
|
---|
2364 | if (*(size_t volatile *)&pbBuf[offFlush + 8] != cbFlush)
|
---|
2365 | {
|
---|
2366 | RTTestIFailed("Flush issue at offset #%zx: %#zx, expected %#zx (cbFlush=%#zx)",
|
---|
2367 | offBuf, *(size_t volatile *)&pbBuf[offFlush + 8], cbFlush, cbFlush);
|
---|
2368 | if (++cErrors > 32)
|
---|
2369 | break;
|
---|
2370 | }
|
---|
2371 | }
|
---|
2372 | RTMemPageFree(pbBuf, cbBuf);
|
---|
2373 | }
|
---|
2374 | }
|
---|
2375 | }
|
---|
2376 | }
|
---|
2377 | }
|
---|
2378 |
|
---|
2379 | /*
|
---|
2380 | * Unmap it.
|
---|
2381 | */
|
---|
2382 | # ifdef RT_OS_WINDOWS
|
---|
2383 | RTTESTI_CHECK(UnmapViewOfFile(pbMapping));
|
---|
2384 | RTTESTI_CHECK(CloseHandle(hSection));
|
---|
2385 | # else
|
---|
2386 | RTTESTI_CHECK(munmap(pbMapping, cbMapping) == 0);
|
---|
2387 | # endif
|
---|
2388 | }
|
---|
2389 |
|
---|
2390 | RT_NOREF(hFileNoCache);
|
---|
2391 | #else
|
---|
2392 | RTTestSkipped(g_hTest, "not supported/implemented");
|
---|
2393 | RT_NOREF(hFile1, hFileNoCache, cbFile);
|
---|
2394 | #endif
|
---|
2395 | }
|
---|
2396 |
|
---|
2397 |
|
---|
2398 | /**
|
---|
2399 | * This does the read, write and seek tests.
|
---|
2400 | */
|
---|
2401 | void fsPerfIo(void)
|
---|
2402 | {
|
---|
2403 | RTTestISub("I/O");
|
---|
2404 |
|
---|
2405 | /*
|
---|
2406 | * Determin the size of the test file.
|
---|
2407 | */
|
---|
2408 | g_szDir[g_cchDir] = '\0';
|
---|
2409 | RTFOFF cbFree = 0;
|
---|
2410 | RTTESTI_CHECK_RC_RETV(RTFsQuerySizes(g_szDir, NULL, &cbFree, NULL, NULL), VINF_SUCCESS);
|
---|
2411 | uint64_t cbFile = g_cbIoFile;
|
---|
2412 | if (cbFile + _16M < (uint64_t)cbFree)
|
---|
2413 | cbFile = RT_ALIGN_64(cbFile, _64K);
|
---|
2414 | else
|
---|
2415 | {
|
---|
2416 | if (cbFree < _32M)
|
---|
2417 | {
|
---|
2418 | RTTestSkipped(g_hTest, "Insufficent free space: %'RU64 bytes, requires >= 32MB", cbFree);
|
---|
2419 | return;
|
---|
2420 | }
|
---|
2421 | cbFile = cbFree - (cbFree > _128M ? _64M : _16M);
|
---|
2422 | cbFile = RT_ALIGN_64(cbFile, _64K);
|
---|
2423 | RTTestIPrintf(RTTESTLVL_ALWAYS, "Adjusted file size to %'RU64 bytes, due to %'RU64 bytes free.\n", cbFile, cbFree);
|
---|
2424 | }
|
---|
2425 | if (cbFile < _64K)
|
---|
2426 | {
|
---|
2427 | RTTestSkipped(g_hTest, "Specified test file size too small: %'RU64 bytes, requires >= 64KB", cbFile);
|
---|
2428 | return;
|
---|
2429 | }
|
---|
2430 |
|
---|
2431 | /*
|
---|
2432 | * Create a cbFile sized test file.
|
---|
2433 | */
|
---|
2434 | RTFILE hFile1;
|
---|
2435 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile1, InDir(RT_STR_TUPLE("file21")),
|
---|
2436 | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_READWRITE), VINF_SUCCESS);
|
---|
2437 | RTFILE hFileNoCache;
|
---|
2438 | if (!g_fIgnoreNoCache)
|
---|
2439 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFileNoCache, g_szDir,
|
---|
2440 | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READWRITE | RTFILE_O_NO_CACHE),
|
---|
2441 | VINF_SUCCESS);
|
---|
2442 | else
|
---|
2443 | {
|
---|
2444 | int rc = RTFileOpen(&hFileNoCache, g_szDir, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READWRITE | RTFILE_O_NO_CACHE);
|
---|
2445 | if (RT_FAILURE(rc))
|
---|
2446 | {
|
---|
2447 | RTTestIPrintf(RTTESTLVL_ALWAYS, "Unable to open I/O file with non-cache flag (%Rrc), skipping related tests.\n", rc);
|
---|
2448 | hFileNoCache = NIL_RTFILE;
|
---|
2449 | }
|
---|
2450 | }
|
---|
2451 | RTFILE hFileWriteThru;
|
---|
2452 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFileWriteThru, g_szDir,
|
---|
2453 | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READWRITE | RTFILE_O_WRITE_THROUGH),
|
---|
2454 | VINF_SUCCESS);
|
---|
2455 |
|
---|
2456 | uint8_t *pbFree = NULL;
|
---|
2457 | int rc = fsPerfIoPrepFile(hFile1, cbFile, &pbFree);
|
---|
2458 | RTMemFree(pbFree);
|
---|
2459 | if (RT_SUCCESS(rc))
|
---|
2460 | {
|
---|
2461 | /*
|
---|
2462 | * Do the testing & profiling.
|
---|
2463 | */
|
---|
2464 | if (g_fSeek)
|
---|
2465 | fsPerfIoSeek(hFile1, cbFile);
|
---|
2466 |
|
---|
2467 | if (g_fReadTests)
|
---|
2468 | fsPerfRead(hFile1, hFileNoCache, cbFile);
|
---|
2469 | if (g_fReadPerf)
|
---|
2470 | for (unsigned i = 0; i < g_cIoBlocks; i++)
|
---|
2471 | fsPerfIoReadBlockSize(hFile1, cbFile, g_acbIoBlocks[i]);
|
---|
2472 |
|
---|
2473 | if (g_fMMap)
|
---|
2474 | fsPerfMMap(hFile1, hFileNoCache, cbFile);
|
---|
2475 |
|
---|
2476 | /* This is destructive to the file content. */
|
---|
2477 | if (g_fWriteTests)
|
---|
2478 | fsPerfWrite(hFile1, hFileNoCache, hFileWriteThru, cbFile);
|
---|
2479 | if (g_fWritePerf)
|
---|
2480 | for (unsigned i = 0; i < g_cIoBlocks; i++)
|
---|
2481 | fsPerfIoWriteBlockSize(hFile1, cbFile, g_acbIoBlocks[i]);
|
---|
2482 |
|
---|
2483 | if (g_fFSync)
|
---|
2484 | fsPerfFSync(hFile1, cbFile);
|
---|
2485 | }
|
---|
2486 |
|
---|
2487 | RTTESTI_CHECK_RC(RTFileSetSize(hFile1, 0), VINF_SUCCESS);
|
---|
2488 | RTTESTI_CHECK_RC(RTFileClose(hFile1), VINF_SUCCESS);
|
---|
2489 | if (hFileNoCache != NIL_RTFILE || !g_fIgnoreNoCache)
|
---|
2490 | RTTESTI_CHECK_RC(RTFileClose(hFileNoCache), VINF_SUCCESS);
|
---|
2491 | RTTESTI_CHECK_RC(RTFileClose(hFileWriteThru), VINF_SUCCESS);
|
---|
2492 | RTTESTI_CHECK_RC(RTFileDelete(g_szDir), VINF_SUCCESS);
|
---|
2493 | }
|
---|
2494 |
|
---|
2495 |
|
---|
2496 | /**
|
---|
2497 | * Display the usage to @a pStrm.
|
---|
2498 | */
|
---|
2499 | static void Usage(PRTSTREAM pStrm)
|
---|
2500 | {
|
---|
2501 | char szExec[RTPATH_MAX];
|
---|
2502 | RTStrmPrintf(pStrm, "usage: %s <-d <testdir>> [options]\n",
|
---|
2503 | RTPathFilename(RTProcGetExecutablePath(szExec, sizeof(szExec))));
|
---|
2504 | RTStrmPrintf(pStrm, "\n");
|
---|
2505 | RTStrmPrintf(pStrm, "options: \n");
|
---|
2506 |
|
---|
2507 | for (unsigned i = 0; i < RT_ELEMENTS(g_aCmdOptions); i++)
|
---|
2508 | {
|
---|
2509 | char szHelp[80];
|
---|
2510 | const char *pszHelp;
|
---|
2511 | switch (g_aCmdOptions[i].iShort)
|
---|
2512 | {
|
---|
2513 | case 'd': pszHelp = "The directory to use for testing. default: CWD/fstestdir"; break;
|
---|
2514 | case 'e': pszHelp = "Enables all tests. default: -e"; break;
|
---|
2515 | case 'z': pszHelp = "Disables all tests. default: -e"; break;
|
---|
2516 | case 's': pszHelp = "Set benchmark duration in seconds. default: 10 sec"; break;
|
---|
2517 | case 'm': pszHelp = "Set benchmark duration in milliseconds. default: 10000 ms"; break;
|
---|
2518 | case 'v': pszHelp = "More verbose execution."; break;
|
---|
2519 | case 'q': pszHelp = "Quiet execution."; break;
|
---|
2520 | case 'h': pszHelp = "Displays this help and exit"; break;
|
---|
2521 | case 'V': pszHelp = "Displays the program revision"; break;
|
---|
2522 | case kCmdOpt_ShowDuration: pszHelp = "Show duration of profile runs. default: --no-show-duration"; break;
|
---|
2523 | case kCmdOpt_NoShowDuration: pszHelp = "Hide duration of profile runs. default: --no-show-duration"; break;
|
---|
2524 | case kCmdOpt_ShowIterations: pszHelp = "Show iteration count for profile runs. default: --no-show-iterations"; break;
|
---|
2525 | case kCmdOpt_NoShowIterations: pszHelp = "Hide iteration count for profile runs. default: --no-show-iterations"; break;
|
---|
2526 | case kCmdOpt_ManyFiles: pszHelp = "Count of files in big test dir. default: --many-files 10000"; break;
|
---|
2527 | case kCmdOpt_NoManyFiles: pszHelp = "Skip big test dir with many files. default: --many-files 10000"; break;
|
---|
2528 | case kCmdOpt_ManyTreeFilesPerDir: pszHelp = "Count of files per directory in test tree. default: 640"; break;
|
---|
2529 | case kCmdOpt_ManyTreeSubdirsPerDir: pszHelp = "Count of subdirs per directory in test tree. default: 16"; break;
|
---|
2530 | case kCmdOpt_ManyTreeDepth: pszHelp = "Depth of test tree (not counting root). default: 1"; break;
|
---|
2531 | case kCmdOpt_IgnoreNoCache: pszHelp = "Ignore error wrt no-cache handle. default: --no-ignore-no-cache"; break;
|
---|
2532 | case kCmdOpt_NoIgnoreNoCache: pszHelp = "Do not ignore error wrt no-cache handle. default: --no-ignore-no-cache"; break;
|
---|
2533 | case kCmdOpt_IoFileSize: pszHelp = "Size of file used for I/O tests. default: 512 MB"; break;
|
---|
2534 | case kCmdOpt_SetBlockSize: pszHelp = "Sets single I/O block size (in bytes)."; break;
|
---|
2535 | case kCmdOpt_AddBlockSize: pszHelp = "Adds an I/O block size (in bytes)."; break;
|
---|
2536 | default:
|
---|
2537 | if (g_aCmdOptions[i].iShort >= kCmdOpt_First)
|
---|
2538 | {
|
---|
2539 | if (RTStrStartsWith(g_aCmdOptions[i].pszLong, "--no-"))
|
---|
2540 | RTStrPrintf(szHelp, sizeof(szHelp), "Disables the '%s' test.", g_aCmdOptions[i].pszLong + 5);
|
---|
2541 | else
|
---|
2542 | RTStrPrintf(szHelp, sizeof(szHelp), "Enables the '%s' test.", g_aCmdOptions[i].pszLong + 2);
|
---|
2543 | pszHelp = szHelp;
|
---|
2544 | }
|
---|
2545 | else
|
---|
2546 | pszHelp = "Option undocumented";
|
---|
2547 | break;
|
---|
2548 | }
|
---|
2549 | if ((unsigned)g_aCmdOptions[i].iShort < 127U)
|
---|
2550 | {
|
---|
2551 | char szOpt[64];
|
---|
2552 | RTStrPrintf(szOpt, sizeof(szOpt), "%s, -%c", g_aCmdOptions[i].pszLong, g_aCmdOptions[i].iShort);
|
---|
2553 | RTStrmPrintf(pStrm, " %-19s %s\n", szOpt, pszHelp);
|
---|
2554 | }
|
---|
2555 | else
|
---|
2556 | RTStrmPrintf(pStrm, " %-19s %s\n", g_aCmdOptions[i].pszLong, pszHelp);
|
---|
2557 | }
|
---|
2558 | }
|
---|
2559 |
|
---|
2560 |
|
---|
2561 | static uint32_t fsPerfCalcManyTreeFiles(void)
|
---|
2562 | {
|
---|
2563 | uint32_t cDirs = 1;
|
---|
2564 | for (uint32_t i = 0, cDirsAtLevel = 1; i < g_cManyTreeDepth; i++)
|
---|
2565 | {
|
---|
2566 | cDirs += cDirsAtLevel * g_cManyTreeSubdirsPerDir;
|
---|
2567 | cDirsAtLevel *= g_cManyTreeSubdirsPerDir;
|
---|
2568 | }
|
---|
2569 | return g_cManyTreeFilesPerDir * cDirs;
|
---|
2570 | }
|
---|
2571 |
|
---|
2572 |
|
---|
2573 | int main(int argc, char *argv[])
|
---|
2574 | {
|
---|
2575 | /*
|
---|
2576 | * Init IPRT and globals.
|
---|
2577 | */
|
---|
2578 | int rc = RTTestInitAndCreate("FsPerf", &g_hTest);
|
---|
2579 | if (rc)
|
---|
2580 | return rc;
|
---|
2581 | RTListInit(&g_ManyTreeHead);
|
---|
2582 |
|
---|
2583 | /*
|
---|
2584 | * Default values.
|
---|
2585 | */
|
---|
2586 | rc = RTPathGetCurrent(g_szDir, sizeof(g_szDir) / 2);
|
---|
2587 | if (RT_SUCCESS(rc))
|
---|
2588 | rc = RTPathAppend(g_szDir, sizeof(g_szDir) / 2, "fstestdir-");
|
---|
2589 | if (RT_SUCCESS(rc))
|
---|
2590 | {
|
---|
2591 | g_cchDir = strlen(g_szDir);
|
---|
2592 | g_cchDir += RTStrPrintf(&g_szDir[g_cchDir], sizeof(g_szDir) - g_cchDir, "%u" RTPATH_SLASH_STR, RTProcSelf());
|
---|
2593 | }
|
---|
2594 | else
|
---|
2595 | {
|
---|
2596 | RTTestFailed(g_hTest, "RTPathGetCurrent (or RTPathAppend) failed: %Rrc\n", rc);
|
---|
2597 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
2598 | }
|
---|
2599 |
|
---|
2600 | RTGETOPTUNION ValueUnion;
|
---|
2601 | RTGETOPTSTATE GetState;
|
---|
2602 | RTGetOptInit(&GetState, argc, argv, g_aCmdOptions, RT_ELEMENTS(g_aCmdOptions), 1, 0 /* fFlags */);
|
---|
2603 | while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
|
---|
2604 | {
|
---|
2605 | switch (rc)
|
---|
2606 | {
|
---|
2607 | case 'd':
|
---|
2608 | rc = RTPathAbs(ValueUnion.psz, g_szDir, sizeof(g_szDir) / 2);
|
---|
2609 | if (RT_SUCCESS(rc))
|
---|
2610 | {
|
---|
2611 | RTPathEnsureTrailingSeparator(g_szDir, sizeof(g_szDir));
|
---|
2612 | g_cchDir = strlen(g_szDir);
|
---|
2613 | break;
|
---|
2614 | }
|
---|
2615 | RTTestFailed(g_hTest, "RTPathAbs(%s) failed: %Rrc\n", ValueUnion.psz, rc);
|
---|
2616 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
2617 |
|
---|
2618 | case 's':
|
---|
2619 | if (ValueUnion.u32 == 0)
|
---|
2620 | g_nsTestRun = RT_NS_1SEC_64 * 10;
|
---|
2621 | else
|
---|
2622 | g_nsTestRun = ValueUnion.u32 * RT_NS_1SEC_64;
|
---|
2623 | break;
|
---|
2624 |
|
---|
2625 | case 'm':
|
---|
2626 | if (ValueUnion.u64 == 0)
|
---|
2627 | g_nsTestRun = RT_NS_1SEC_64 * 10;
|
---|
2628 | else
|
---|
2629 | g_nsTestRun = ValueUnion.u64 * RT_NS_1MS;
|
---|
2630 | break;
|
---|
2631 |
|
---|
2632 | case 'e':
|
---|
2633 | g_fManyFiles = true;
|
---|
2634 | g_fOpen = true;
|
---|
2635 | g_fFStat = true;
|
---|
2636 | g_fFChMod = true;
|
---|
2637 | g_fFUtimes = true;
|
---|
2638 | g_fStat = true;
|
---|
2639 | g_fChMod = true;
|
---|
2640 | g_fUtimes = true;
|
---|
2641 | g_fRename = true;
|
---|
2642 | g_fDirEnum = true;
|
---|
2643 | g_fMkRmDir = true;
|
---|
2644 | g_fStatVfs = true;
|
---|
2645 | g_fRm = true;
|
---|
2646 | g_fChSize = true;
|
---|
2647 | g_fReadTests = true;
|
---|
2648 | g_fReadPerf = true;
|
---|
2649 | g_fWriteTests= true;
|
---|
2650 | g_fWritePerf = true;
|
---|
2651 | g_fSeek = true;
|
---|
2652 | g_fFSync = true;
|
---|
2653 | g_fMMap = true;
|
---|
2654 | break;
|
---|
2655 |
|
---|
2656 | case 'z':
|
---|
2657 | g_fManyFiles = false;
|
---|
2658 | g_fOpen = false;
|
---|
2659 | g_fFStat = false;
|
---|
2660 | g_fFChMod = false;
|
---|
2661 | g_fFUtimes = false;
|
---|
2662 | g_fStat = false;
|
---|
2663 | g_fChMod = false;
|
---|
2664 | g_fUtimes = false;
|
---|
2665 | g_fRename = false;
|
---|
2666 | g_fDirEnum = false;
|
---|
2667 | g_fMkRmDir = false;
|
---|
2668 | g_fStatVfs = false;
|
---|
2669 | g_fRm = false;
|
---|
2670 | g_fChSize = false;
|
---|
2671 | g_fReadTests = false;
|
---|
2672 | g_fReadPerf = false;
|
---|
2673 | g_fWriteTests= false;
|
---|
2674 | g_fWritePerf = false;
|
---|
2675 | g_fSeek = false;
|
---|
2676 | g_fFSync = false;
|
---|
2677 | g_fMMap = false;
|
---|
2678 | break;
|
---|
2679 |
|
---|
2680 | #define CASE_OPT(a_Stem) \
|
---|
2681 | case RT_CONCAT(kCmdOpt_,a_Stem): RT_CONCAT(g_f,a_Stem) = true; break; \
|
---|
2682 | case RT_CONCAT(kCmdOpt_No,a_Stem): RT_CONCAT(g_f,a_Stem) = false; break
|
---|
2683 | CASE_OPT(Open);
|
---|
2684 | CASE_OPT(FStat);
|
---|
2685 | CASE_OPT(FChMod);
|
---|
2686 | CASE_OPT(FUtimes);
|
---|
2687 | CASE_OPT(Stat);
|
---|
2688 | CASE_OPT(ChMod);
|
---|
2689 | CASE_OPT(Utimes);
|
---|
2690 | CASE_OPT(Rename);
|
---|
2691 | CASE_OPT(DirEnum);
|
---|
2692 | CASE_OPT(MkRmDir);
|
---|
2693 | CASE_OPT(StatVfs);
|
---|
2694 | CASE_OPT(Rm);
|
---|
2695 | CASE_OPT(ChSize);
|
---|
2696 | CASE_OPT(ReadTests);
|
---|
2697 | CASE_OPT(ReadPerf);
|
---|
2698 | CASE_OPT(WriteTests);
|
---|
2699 | CASE_OPT(WritePerf);
|
---|
2700 | CASE_OPT(Seek);
|
---|
2701 | CASE_OPT(FSync);
|
---|
2702 | CASE_OPT(MMap);
|
---|
2703 | CASE_OPT(IgnoreNoCache);
|
---|
2704 |
|
---|
2705 | CASE_OPT(ShowDuration);
|
---|
2706 | CASE_OPT(ShowIterations);
|
---|
2707 | #undef CASE_OPT
|
---|
2708 |
|
---|
2709 | case kCmdOpt_ManyFiles:
|
---|
2710 | g_fManyFiles = ValueUnion.u32 > 0;
|
---|
2711 | g_cManyFiles = ValueUnion.u32;
|
---|
2712 | break;
|
---|
2713 |
|
---|
2714 | case kCmdOpt_NoManyFiles:
|
---|
2715 | g_fManyFiles = false;
|
---|
2716 | break;
|
---|
2717 |
|
---|
2718 | case kCmdOpt_ManyTreeFilesPerDir:
|
---|
2719 | if (ValueUnion.u32 > 0 && ValueUnion.u32 <= _64M)
|
---|
2720 | {
|
---|
2721 | g_cManyTreeFilesPerDir = ValueUnion.u32;
|
---|
2722 | g_cManyTreeFiles = fsPerfCalcManyTreeFiles();
|
---|
2723 | break;
|
---|
2724 | }
|
---|
2725 | RTTestFailed(g_hTest, "Out of range --files-per-dir value: %u (%#x)\n", ValueUnion.u32, ValueUnion.u32);
|
---|
2726 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
2727 |
|
---|
2728 | case kCmdOpt_ManyTreeSubdirsPerDir:
|
---|
2729 | if (ValueUnion.u32 > 0 && ValueUnion.u32 <= 1024)
|
---|
2730 | {
|
---|
2731 | g_cManyTreeSubdirsPerDir = ValueUnion.u32;
|
---|
2732 | g_cManyTreeFiles = fsPerfCalcManyTreeFiles();
|
---|
2733 | break;
|
---|
2734 | }
|
---|
2735 | RTTestFailed(g_hTest, "Out of range --subdirs-per-dir value: %u (%#x)\n", ValueUnion.u32, ValueUnion.u32);
|
---|
2736 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
2737 |
|
---|
2738 | case kCmdOpt_ManyTreeDepth:
|
---|
2739 | if (ValueUnion.u32 <= 8)
|
---|
2740 | {
|
---|
2741 | g_cManyTreeDepth = ValueUnion.u32;
|
---|
2742 | g_cManyTreeFiles = fsPerfCalcManyTreeFiles();
|
---|
2743 | break;
|
---|
2744 | }
|
---|
2745 | RTTestFailed(g_hTest, "Out of range --tree-depth value: %u (%#x)\n", ValueUnion.u32, ValueUnion.u32);
|
---|
2746 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
2747 |
|
---|
2748 | case kCmdOpt_IoFileSize:
|
---|
2749 | if (ValueUnion.u64 == 0)
|
---|
2750 | g_cbIoFile = _512M;
|
---|
2751 | else
|
---|
2752 | g_cbIoFile = ValueUnion.u64;
|
---|
2753 | break;
|
---|
2754 |
|
---|
2755 | case kCmdOpt_SetBlockSize:
|
---|
2756 | if (ValueUnion.u32 > 0)
|
---|
2757 | {
|
---|
2758 | g_cIoBlocks = 1;
|
---|
2759 | g_acbIoBlocks[0] = ValueUnion.u32;
|
---|
2760 | }
|
---|
2761 | else
|
---|
2762 | {
|
---|
2763 | RTTestFailed(g_hTest, "Invalid I/O block size: %u (%#x)\n", ValueUnion.u32, ValueUnion.u32);
|
---|
2764 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
2765 | }
|
---|
2766 | break;
|
---|
2767 |
|
---|
2768 | case kCmdOpt_AddBlockSize:
|
---|
2769 | if (g_cIoBlocks >= RT_ELEMENTS(g_acbIoBlocks))
|
---|
2770 | RTTestFailed(g_hTest, "Too many I/O block sizes: max %u\n", RT_ELEMENTS(g_acbIoBlocks));
|
---|
2771 | else if (ValueUnion.u32 == 0)
|
---|
2772 | RTTestFailed(g_hTest, "Invalid I/O block size: %u (%#x)\n", ValueUnion.u32, ValueUnion.u32);
|
---|
2773 | else
|
---|
2774 | {
|
---|
2775 | g_acbIoBlocks[g_cIoBlocks++] = ValueUnion.u32;
|
---|
2776 | break;
|
---|
2777 | }
|
---|
2778 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
2779 |
|
---|
2780 | case 'q':
|
---|
2781 | g_uVerbosity = 0;
|
---|
2782 | break;
|
---|
2783 |
|
---|
2784 | case 'v':
|
---|
2785 | g_uVerbosity++;
|
---|
2786 | break;
|
---|
2787 |
|
---|
2788 | case 'h':
|
---|
2789 | Usage(g_pStdOut);
|
---|
2790 | return RTEXITCODE_SUCCESS;
|
---|
2791 |
|
---|
2792 | case 'V':
|
---|
2793 | {
|
---|
2794 | char szRev[] = "$Revision: 77052 $";
|
---|
2795 | szRev[RT_ELEMENTS(szRev) - 2] = '\0';
|
---|
2796 | RTPrintf(RTStrStrip(strchr(szRev, ':') + 1));
|
---|
2797 | return RTEXITCODE_SUCCESS;
|
---|
2798 | }
|
---|
2799 |
|
---|
2800 | default:
|
---|
2801 | return RTGetOptPrintError(rc, &ValueUnion);
|
---|
2802 | }
|
---|
2803 | }
|
---|
2804 |
|
---|
2805 | /*
|
---|
2806 | * Create the test directory with an 'empty' subdirectory under it,
|
---|
2807 | * execute the tests, and remove directory when done.
|
---|
2808 | */
|
---|
2809 | RTTestBanner(g_hTest);
|
---|
2810 | if (!RTPathExists(g_szDir))
|
---|
2811 | {
|
---|
2812 | /* The base dir: */
|
---|
2813 | rc = RTDirCreate(g_szDir, 0755,
|
---|
2814 | RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_DONT_SET | RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_NOT_CRITICAL);
|
---|
2815 | if (RT_SUCCESS(rc))
|
---|
2816 | {
|
---|
2817 | RTTestIPrintf(RTTESTLVL_ALWAYS, "Test dir: %s\n", g_szDir);
|
---|
2818 | rc = fsPrepTestArea();
|
---|
2819 | if (RT_SUCCESS(rc))
|
---|
2820 | {
|
---|
2821 | /* Profile RTTimeNanoTS(). */
|
---|
2822 | fsPerfNanoTS();
|
---|
2823 |
|
---|
2824 | /* Do tests: */
|
---|
2825 | if (g_fManyFiles)
|
---|
2826 | fsPerfManyFiles();
|
---|
2827 | if (g_fOpen)
|
---|
2828 | fsPerfOpen();
|
---|
2829 | if (g_fFStat)
|
---|
2830 | fsPerfFStat();
|
---|
2831 | if (g_fFChMod)
|
---|
2832 | fsPerfFChMod();
|
---|
2833 | if (g_fFUtimes)
|
---|
2834 | fsPerfFUtimes();
|
---|
2835 | if (g_fStat)
|
---|
2836 | fsPerfStat();
|
---|
2837 | if (g_fChMod)
|
---|
2838 | fsPerfChmod();
|
---|
2839 | if (g_fUtimes)
|
---|
2840 | fsPerfUtimes();
|
---|
2841 | if (g_fRename)
|
---|
2842 | fsPerfRename();
|
---|
2843 | if (g_fDirEnum)
|
---|
2844 | vsPerfDirEnum();
|
---|
2845 | if (g_fMkRmDir)
|
---|
2846 | fsPerfMkRmDir();
|
---|
2847 | if (g_fStatVfs)
|
---|
2848 | fsPerfStatVfs();
|
---|
2849 | if (g_fRm || g_fManyFiles)
|
---|
2850 | fsPerfRm(); /* deletes manyfiles and manytree */
|
---|
2851 | if (g_fChSize)
|
---|
2852 | fsPerfChSize();
|
---|
2853 | if (g_fReadPerf || g_fReadTests || g_fWritePerf || g_fWriteTests || g_fSeek || g_fFSync || g_fMMap)
|
---|
2854 | fsPerfIo();
|
---|
2855 | }
|
---|
2856 |
|
---|
2857 | /* Cleanup: */
|
---|
2858 | g_szDir[g_cchDir] = '\0';
|
---|
2859 | rc = RTDirRemoveRecursive(g_szDir, RTDIRRMREC_F_CONTENT_AND_DIR);
|
---|
2860 | if (RT_FAILURE(rc))
|
---|
2861 | RTTestFailed(g_hTest, "RTDirRemoveRecursive(%s,) -> %Rrc\n", g_szDir, rc);
|
---|
2862 | }
|
---|
2863 | else
|
---|
2864 | RTTestFailed(g_hTest, "RTDirCreate(%s) -> %Rrc\n", g_szDir, rc);
|
---|
2865 | }
|
---|
2866 | else
|
---|
2867 | RTTestFailed(g_hTest, "Test directory already exists: %s\n", g_szDir);
|
---|
2868 |
|
---|
2869 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
2870 | }
|
---|