VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/utils/fs/FsPerf.cpp@ 78284

Last change on this file since 78284 was 78284, checked in by vboxsync, 6 years ago

FsPerf: Some more corner cases. bugref:9172

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette