Changeset 95000 in vbox
- Timestamp:
- May 13, 2022 9:39:42 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstFile.cpp
r93115 r95000 31 31 #include <iprt/test.h> 32 32 #include <iprt/file.h> 33 #include <iprt/errcore.h> 33 #include <iprt/err.h> 34 #include <iprt/path.h> 35 #include <iprt/rand.h> 34 36 #include <iprt/string.h> 35 37 #include <iprt/stream.h> … … 55 57 "habitasse platea dictumst.\n"; 56 58 59 /** 60 * Structure holding queried file system properties we're performing our tests on. 61 */ 62 typedef struct FsProps 63 { 64 RTFOFF cbTotal; 65 RTFOFF cbFree; 66 uint32_t cbBlock; 67 uint32_t cbSector; 68 } FsProps; 69 /** Queried file system properties we're performing our tests on. */ 70 static FsProps s_FsProps; 71 57 72 58 73 static void tstAppend(RTFILE hFile) … … 112 127 } 113 128 114 /* grow file beyond 2G */ 115 rc = RTFileSetSize(hFile, _2G + _1M); 129 uint64_t cbFileSize = _2G + RTRandU32Ex(_1K, _1M); /* Try growing file beyond 2G by default. */ 130 if ((uint64_t)s_FsProps.cbFree <= cbFileSize) 131 { 132 RTTestIPrintf(RTTESTLVL_ALWAYS, "Warning: Free disk space less than testcase file size (%RTfoff vs. %RU64), limiting\n", 133 s_FsProps.cbFree, cbFileSize); 134 cbFileSize = s_FsProps.cbFree - _1M; /* Leave a bit of space on the fs. */ 135 } 136 /** @todo Also check and clamp for fs max file size limits? */ 137 RTTESTI_CHECK_MSG_RETV(cbFileSize, ("No space left on file system (disk full)")); 138 139 rc = RTFileSetSize(hFile, cbFileSize); 116 140 if (RT_FAILURE(rc)) 117 RTTestIFailed("Failed to grow file #1 to 2.001GB. rc=%Rrc", rc);141 RTTestIFailed("Failed to grow file #1 to %RU64. rc=%Rrc", cbFileSize, rc); 118 142 else 119 143 { 120 144 uint64_t cb; 121 145 RTTESTI_CHECK_RC(RTFileQuerySize(hFile, &cb), VINF_SUCCESS); 122 RTTESTI_CHECK_MSG(cb == _2G + _1M, ("RTFileQuerySize return %RX64 bytes, expected %RX64.", cb, _2G + _1M));146 RTTESTI_CHECK_MSG(cb == cbFileSize, ("RTFileQuerySize return %RX64 bytes, expected %RX64.", cb, cbFileSize)); 123 147 124 148 /* … … 172 196 * Try some writes at the end of the file. 173 197 */ 174 rc = RTFileSeek(hFile, _2G + _1M, RTFILE_SEEK_BEGIN, NULL);175 if (RT_FAILURE(rc)) 176 RTTestIFailed("Failed to seek to _2G + _1M in file #1. rc=%Rrc\n", rc);198 rc = RTFileSeek(hFile, cbFileSize, RTFILE_SEEK_BEGIN, NULL); 199 if (RT_FAILURE(rc)) 200 RTTestIFailed("Failed to seek to %RU64 in file #1. rc=%Rrc\n", cbFileSize, rc); 177 201 else 178 202 { 179 203 offFile = RTFileTell(hFile); 180 if (offFile != _2G + _1M)181 RTTestIFailed("RTFileTell -> %#llx, expected %#llx (#2)\n", offFile, _2G + _1M);204 if (offFile != cbFileSize) 205 RTTestIFailed("RTFileTell -> %#llx, expected %#llx (#2)\n", offFile, cbFileSize); 182 206 else 183 207 { … … 192 216 } 193 217 if (RT_FAILURE(rc)) 194 RTTestIFailed("Failed to write to file #1 at offset 2G + 1M. rc=%Rrc\n", rc);218 RTTestIFailed("Failed to write to file #1 at offset %RU64. rc=%Rrc\n", cbFileSize, rc); 195 219 else 196 220 { … … 211 235 } 212 236 if (RT_FAILURE(rc)) 213 RTTestIFailed("Failed to read from file #1 at offset 2G + 1M. rc=%Rrc\n", rc);237 RTTestIFailed("Failed to read from file #1 at offset %RU64. rc=%Rrc\n", cbFileSize, rc); 214 238 else 215 239 { … … 217 241 RTPrintf("tstFile: tail write ok\n"); 218 242 else 219 RTTestIFailed("Data read from file #1 at offset 2G + 1M differs from what we wrote there.\n"); 243 RTTestIFailed("Data read from file #1 at offset %RU64 differs from what we wrote there.\n", 244 cbFileSize); 220 245 } 221 246 } … … 227 252 * Some general seeking around. 228 253 */ 229 rc = RTFileSeek(hFile, _2G + 1, RTFILE_SEEK_BEGIN, NULL); 230 if (RT_FAILURE(rc)) 231 RTTestIFailed("Failed to seek to _2G + 1 in file #1. rc=%Rrc\n", rc); 254 RTFOFF offSeek = RTRandS64Ex(0, cbFileSize); 255 rc = RTFileSeek(hFile, offSeek, RTFILE_SEEK_BEGIN, NULL); 256 if (RT_FAILURE(rc)) 257 RTTestIFailed("Failed to seek to %RTfoff in file #1. rc=%Rrc\n", offSeek, rc); 232 258 else 233 259 { 234 260 offFile = RTFileTell(hFile); 235 if (offFile != _2G + 1)236 RTTestIFailed("RTFileTell -> %# llx, expected %#llx (#3)\n", offFile, _2G + 1);261 if (offFile != (uint64_t)offSeek) 262 RTTestIFailed("RTFileTell -> %#RTfoff, expected %RTfoff (#3)\n", offFile, offSeek); 237 263 } 238 264 … … 244 270 { 245 271 offFile = RTFileTell(hFile); 246 if (offFile != _2G + _1M+ sizeof(g_szTestStr)) /* assuming tail write was ok. */247 RTTestIFailed("RTFileTell -> % #RX64, expected %#RX64 (#4)\n", offFile, _2G + _1M+ sizeof(g_szTestStr));272 if (offFile != cbFileSize + sizeof(g_szTestStr)) /* assuming tail write was ok. */ 273 RTTestIFailed("RTFileTell -> %RTfoff, expected %#RX64 (#4)\n", offFile, cbFileSize + sizeof(g_szTestStr)); 248 274 } 249 275 … … 256 282 offFile = RTFileTell(hFile); 257 283 if (offFile != 0) 258 RTTestIFailed("RTFileTell -> % #llx, expected 0 (#5)\n", offFile);284 RTTestIFailed("RTFileTell -> %RTfoff, expected 0 (#5)\n", offFile); 259 285 } 260 286 } … … 270 296 271 297 /* 298 * Query file system sizes first. 299 * This is needed beforehand, so that we don't perform tests which cannot succeed because of known limitations 300 * (too little space, file system maximum file size restrictions, ++). 301 */ 302 char szCWD[RTPATH_MAX]; 303 int rc = RTPathGetCurrent(szCWD, sizeof(szCWD)); 304 RTTESTI_CHECK_MSG(RT_SUCCESS(rc), ("Unable to query current directory, rc=%Rrc", rc)); 305 rc = RTFsQuerySizes(szCWD, &s_FsProps.cbTotal, &s_FsProps.cbFree, &s_FsProps.cbBlock, &s_FsProps.cbSector); 306 RTTESTI_CHECK_MSG(RT_SUCCESS(rc), ("Unable to query file system sizes of '%s', rc=%Rrc", szCWD, rc)); 307 308 /* 272 309 * Some basic tests. 273 310 */ 274 311 RTTestSub(hTest, "Basics"); 275 int rc = -1;276 312 RTFILE hFile = NIL_RTFILE; 277 313 RTTESTI_CHECK_RC(rc = RTFileOpen(&hFile, "tstFile#1.tst", RTFILE_O_READWRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE),
Note:
See TracChangeset
for help on using the changeset viewer.