Changeset 88985 in vbox
- Timestamp:
- May 11, 2021 4:31:00 PM (4 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/AudioTest.cpp
r88983 r88985 26 26 27 27 #include <iprt/dir.h> 28 #include <iprt/file.h> 29 #include <iprt/inifile.h> 30 #include <iprt/list.h> 28 31 #include <iprt/rand.h> 29 32 #include <iprt/uuid.h> 33 #include <iprt/vfs.h> 30 34 31 35 #define _USE_MATH_DEFINES … … 34 38 #include "AudioTest.h" 35 39 40 41 /********************************************************************************************************************************* 42 * Defines * 43 *********************************************************************************************************************************/ 44 /** The test manifest file. */ 45 #define AUDIOTEST_MANIFEST_FILE_STR "vkat_manifest.ini" 46 #define AUDIOTEST_MANIFEST_VER 1 47 48 #define AUDIOTEST_INI_SEC_HDR_STR "header" 36 49 37 50 /********************************************************************************************************************************* … … 245 258 } 246 259 260 static int audioTestManifestWriteLn(PAUDIOTESTSET pSet, const char *pszFormat, ...) 261 { 262 va_list va; 263 va_start(va, pszFormat); 264 265 char *psz = NULL; 266 RTStrAPrintfV(&psz, pszFormat, va); 267 AssertPtr(psz); 268 269 /** @todo Use RTIniFileWrite once its implemented. */ 270 int rc = RTFileWrite(pSet->f.hFile, psz, strlen(psz), NULL); 271 AssertRC(rc); 272 rc = RTFileWrite(pSet->f.hFile, "\n", strlen("\n"), NULL); 273 AssertRC(rc); 274 275 RTStrFree(psz); 276 va_end(va); 277 278 return rc; 279 } 280 281 static void audioTestSetInitInternal(PAUDIOTESTSET pSet) 282 { 283 pSet->f.hFile = NIL_RTFILE; 284 } 285 286 static bool audioTestManifestIsOpen(PAUDIOTESTSET pSet) 287 { 288 if ( pSet->enmMode == AUDIOTESTSETMODE_TEST 289 && pSet->f.hFile != NIL_RTFILE) 290 return true; 291 else if ( pSet->enmMode == AUDIOTESTSETMODE_VERIFY 292 && pSet->f.hIniFile != NIL_RTINIFILE) 293 return true; 294 295 return false; 296 } 297 298 static void audioTestErrorDescInit(PAUDIOTESTERRORDESC pErr) 299 { 300 RTListInit(&pErr->List); 301 pErr->cErrors = 0; 302 } 303 304 void AudioTestErrorDescDestroy(PAUDIOTESTERRORDESC pErr) 305 { 306 if (!pErr) 307 return; 308 309 PAUDIOTESTERRORENTRY pErrEntry, pErrEntryNext; 310 RTListForEachSafe(&pErr->List, pErrEntry, pErrEntryNext, AUDIOTESTERRORENTRY, Node) 311 { 312 RTListNodeRemove(&pErrEntry->Node); 313 314 RTMemFree(pErrEntry); 315 316 Assert(pErr->cErrors); 317 pErr->cErrors--; 318 } 319 320 Assert(pErr->cErrors == 0); 321 } 322 323 bool AudioTestErrorDescFailed(PAUDIOTESTERRORDESC pErr) 324 { 325 if (pErr->cErrors) 326 { 327 Assert(!RTListIsEmpty(&pErr->List)); 328 return true; 329 } 330 331 return false; 332 } 333 334 static int audioTestErrorDescAddV(PAUDIOTESTERRORDESC pErr, int rc, const char *pszFormat, va_list args) 335 { 336 PAUDIOTESTERRORENTRY pEntry = (PAUDIOTESTERRORENTRY)RTMemAlloc(sizeof(AUDIOTESTERRORENTRY)); 337 AssertReturn(pEntry, VERR_NO_MEMORY); 338 339 if (RTStrPrintf2V(pEntry->szDesc, sizeof(pEntry->szDesc), pszFormat, args) < 0) 340 AssertFailedReturn(VERR_BUFFER_OVERFLOW); 341 342 pEntry->rc = rc; 343 344 RTListAppend(&pErr->List, &pEntry->Node); 345 346 pErr->cErrors++; 347 348 return VINF_SUCCESS; 349 } 350 351 static int audioTestErrorDescAdd(PAUDIOTESTERRORDESC pErr, const char *pszFormat, ...) 352 { 353 va_list va; 354 va_start(va, pszFormat); 355 356 int rc = audioTestErrorDescAddV(pErr, VERR_GENERAL_FAILURE /** @todo Fudge! */, pszFormat, va); 357 358 va_end(va); 359 return rc; 360 } 361 362 #if 0 363 static int audioTestErrorDescAddRc(PAUDIOTESTERRORDESC pErr, int rc, const char *pszFormat, ...) 364 { 365 va_list va; 366 va_start(va, pszFormat); 367 368 int rc2 = audioTestErrorDescAddV(pErr, rc, pszFormat, va); 369 370 va_end(va); 371 return rc2; 372 } 373 #endif 374 247 375 int AudioTestPathCreateTemp(char *pszPath, size_t cbPath, const char *pszTag) 248 376 { … … 259 387 int rc; 260 388 389 audioTestSetInitInternal(pSet); 390 261 391 if (pszPath) 262 392 { 263 rc = RTStrCopy(pSet->szPath OutAbs, sizeof(pSet->szPathOutAbs), pszPath);264 AssertRCReturn(rc, rc); 265 266 rc = AudioTestPathCreate(pSet->szPath OutAbs, sizeof(pSet->szPathOutAbs), pszTag);393 rc = RTStrCopy(pSet->szPathAbs, sizeof(pSet->szPathAbs), pszPath); 394 AssertRCReturn(rc, rc); 395 396 rc = AudioTestPathCreate(pSet->szPathAbs, sizeof(pSet->szPathAbs), pszTag); 267 397 } 268 398 else 269 rc = AudioTestPathCreateTemp(pSet->szPathOutAbs, sizeof(pSet->szPathOutAbs), pszTag); 270 AssertRCReturn(rc, rc); 399 rc = AudioTestPathCreateTemp(pSet->szPathAbs, sizeof(pSet->szPathAbs), pszTag); 400 AssertRCReturn(rc, rc); 401 402 if (RT_SUCCESS(rc)) 403 { 404 char szManifest[RTPATH_MAX]; 405 rc = RTStrCopy(szManifest, sizeof(szManifest), pszPath); 406 AssertRCReturn(rc, rc); 407 408 rc = RTPathAppend(szManifest, sizeof(szManifest), AUDIOTEST_MANIFEST_FILE_STR); 409 AssertRCReturn(rc, rc); 410 411 rc = RTFileOpen(&pSet->f.hFile, szManifest, 412 RTFILE_O_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_WRITE); 413 AssertRCReturn(rc, rc); 414 415 rc = audioTestManifestWriteLn(pSet, "magic=vkat_ini"); /* VKAT Manifest, .INI-style. */ 416 AssertRCReturn(rc, rc); 417 rc = audioTestManifestWriteLn(pSet, "ver=%d", AUDIOTEST_MANIFEST_VER); 418 AssertRCReturn(rc, rc); 419 rc = audioTestManifestWriteLn(pSet, "tag=%s", pszTag); 420 AssertRCReturn(rc, rc); 421 422 char szTime[64]; 423 RTTIMESPEC time; 424 if (!RTTimeSpecToString(RTTimeNow(&time), szTime, sizeof(szTime))) 425 AssertFailedReturn(VERR_BUFFER_OVERFLOW); 426 427 rc = audioTestManifestWriteLn(pSet, "date_created=%s", szTime); 428 AssertRCReturn(rc, rc); 429 430 /** @todo Add more stuff here, like hostname, ++? */ 431 432 pSet->enmMode = AUDIOTESTSETMODE_TEST; 433 } 271 434 272 435 return rc; … … 275 438 void AudioTestSetDestroy(PAUDIOTESTSET pSet) 276 439 { 277 RT_NOREF(pSet); 440 if (!pSet) 441 return; 442 443 if (RTFileIsValid(pSet->f.hFile)) 444 { 445 RTFileClose(pSet->f.hFile); 446 pSet->f.hFile = NIL_RTFILE; 447 } 278 448 } 279 449 280 450 int AudioTestSetOpen(PAUDIOTESTSET pSet, const char *pszPath) 281 451 { 282 RT_NOREF(pSet, pszPath); 452 audioTestSetInitInternal(pSet); 453 454 char szManifest[RTPATH_MAX]; 455 int rc = RTStrCopy(szManifest, sizeof(szManifest), pszPath); 456 AssertRCReturn(rc, rc); 457 458 rc = RTPathAppend(szManifest, sizeof(szManifest), AUDIOTEST_MANIFEST_FILE_STR); 459 AssertRCReturn(rc, rc); 460 461 RTVFSFILE hVfsFile; 462 rc = RTVfsFileOpenNormal(szManifest, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE, &hVfsFile); 463 if (RT_FAILURE(rc)) 464 return rc; 465 466 rc = RTIniFileCreateFromVfsFile(&pSet->f.hIniFile, hVfsFile, RTINIFILE_F_READONLY); 467 RTVfsFileRelease(hVfsFile); 468 AssertRCReturn(rc, rc); 469 470 pSet->enmMode = AUDIOTESTSETMODE_VERIFY; 471 472 return rc; 473 } 474 475 void AudioTestSetClose(PAUDIOTESTSET pSet) 476 { 477 AudioTestSetDestroy(pSet); 478 } 479 480 int AudioTestSetPack(PAUDIOTESTSET pSet, const char *pszOutDir) 481 { 482 RT_NOREF(pSet, pszOutDir); 483 484 AssertReturn(audioTestManifestIsOpen(pSet), VERR_WRONG_ORDER); 485 // RTZipTarCmd() 283 486 284 487 return VERR_NOT_IMPLEMENTED; 285 488 } 286 489 287 void AudioTestSetClose(PAUDIOTESTSET pSet) 288 { 289 AudioTestSetDestroy(pSet); 290 } 291 292 int AudioTestSetPack(PAUDIOTESTSET pSet, const char *pszOutDir) 293 { 294 RT_NOREF(pSet, pszOutDir); 490 int AudioTestSetUnpack(const char *pszFile, const char *pszOutDir) 491 { 492 RT_NOREF(pszFile, pszOutDir); 493 295 494 // RTZipTarCmd() 296 495 … … 298 497 } 299 498 300 int AudioTestSet Unpack(const char *pszFile, const char *pszOutDir)301 { 302 RT_NOREF(pszFile, pszOutDir);303 // RTZipTarCmd() 304 305 return VERR_NOT_IMPLEMENTED;306 } 307 308 int AudioTestSetVerify(PAUDIOTESTSET pSet, const char *pszTag) 309 { 310 RT_NOREF(pSet, pszTag);311 //RTIniFileQueryPair()312 313 /** @todo Compare tag with test set. */ 314 315 return V ERR_NOT_IMPLEMENTED;316 } 317 499 int AudioTestSetVerify(PAUDIOTESTSET pSet, const char *pszTag, PAUDIOTESTERRORDESC pErrDesc) 500 { 501 AssertReturn(audioTestManifestIsOpen(pSet), VERR_WRONG_ORDER); 502 503 /* We ASSUME the caller has not init'd pErrDesc. */ 504 audioTestErrorDescInit(pErrDesc); 505 506 char szVal[_1K]; /** @todo Enough, too much? */ 507 508 int rc2 = RTIniFileQueryValue(pSet->f.hIniFile, AUDIOTEST_INI_SEC_HDR_STR, "tag", szVal, sizeof(szVal), NULL); 509 if ( RT_FAILURE(rc2) 510 || RTStrICmp(pszTag, szVal)) 511 audioTestErrorDescAdd(pErrDesc, "Tag '%s' does not match with manifest's tag '%s'", pszTag, szVal); 512 513 /* Only return critical stuff not related to actual testing here. */ 514 return VINF_SUCCESS; 515 } 516 -
trunk/src/VBox/Devices/Audio/AudioTest.h
r88983 r88985 63 63 typedef AUDIOTESTTONEPARMS *PAUDIOTESTTONEPARMS; 64 64 65 /** 66 * Enumeration for the test set mode. 67 */ 68 typedef enum AUDIOTESTSETMODE 69 { 70 /** Invalid test set mode. */ 71 AUDIOTESTSETMODE_INVALID = 0, 72 /** Test set is being created (testing in progress). */ 73 AUDIOTESTSETMODE_TEST, 74 /** Existing test set is being verified. */ 75 AUDIOTESTSETMODE_VERIFY, 76 /** The usual 32-bit hack. */ 77 AUDIOTESTSETMODE_32BIT_HACK = 0x7fffffff 78 } AUDIOTESTSETMODE; 79 80 /** 81 * Structure specifying an audio test set. 82 */ 65 83 typedef struct AUDIOTESTSET 66 84 { 67 /** Absolute path where to store the test audio data. 68 * If NULL, no test audio data will be written. */ 69 char szPathOutAbs[RTPATH_MAX]; 85 /** Absolute path where to store the test audio data. */ 86 char szPathAbs[RTPATH_MAX]; 87 /** Current mode the test set is in. */ 88 AUDIOTESTSETMODE enmMode; 89 union 90 { 91 RTFILE hFile; 92 RTINIFILE hIniFile; 93 } f; 94 } AUDIOTESTSET; 95 /** Pointer to an audio test set. */ 96 typedef AUDIOTESTSET *PAUDIOTESTSET; 70 97 71 } AUDIOTESTSET; 72 /** Pointer to audio test set parameters. */ 73 typedef AUDIOTESTSET *PAUDIOTESTSET; 98 /** 99 * Structure for holding a single audio test error entry. 100 */ 101 typedef struct AUDIOTESTERRORENTRY 102 { 103 /** The entrie's list node. */ 104 RTLISTNODE Node; 105 /** Additional rc. */ 106 int rc; 107 /** Actual error description. */ 108 char szDesc[128]; 109 } AUDIOTESTERRORENTRY; 110 /** Pointer to an audio test error description. */ 111 typedef AUDIOTESTERRORENTRY *PAUDIOTESTERRORENTRY; 112 113 /** 114 * Structure for holding an audio test error description. 115 * This can contain multiple errors (FIFO list). 116 */ 117 typedef struct AUDIOTESTERRORDESC 118 { 119 RTLISTANCHOR List; 120 uint32_t cErrors; 121 } AUDIOTESTERRORDESC; 122 /** Pointer to an audio test error description. */ 123 typedef AUDIOTESTERRORDESC *PAUDIOTESTERRORDESC; 74 124 75 125 … … 88 138 int AudioTestSetPack(PAUDIOTESTSET pSet, const char *pszOutDir); 89 139 int AudioTestSetUnpack(const char *pszFile, const char *pszOutDir); 90 int AudioTestSetVerify(PAUDIOTESTSET pSet, const char *pszTag); 140 int AudioTestSetVerify(PAUDIOTESTSET pSet, const char *pszTag, PAUDIOTESTERRORDESC pErrDesc); 141 142 bool AudioTestErrorDescFailed(PAUDIOTESTERRORDESC pErr); 143 void AudioTestErrorDescDestroy(PAUDIOTESTERRORDESC pErr); 91 144 92 145 #endif /* !VBOX_INCLUDED_SRC_Audio_AudioTest_h */ -
trunk/src/VBox/ValidationKit/utils/audio/vkat.cpp
r88984 r88985 835 835 if (RT_SUCCESS(rc)) 836 836 { 837 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Output directory is '%s'\n", TstEnv.Set.szPath OutAbs);837 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Output directory is '%s'\n", TstEnv.Set.szPathAbs); 838 838 839 839 PPDMAUDIOHOSTDEV pDev; … … 874 874 if (RT_SUCCESS(rc)) 875 875 { 876 rc = AudioTestSetVerify(&tstSet, pszTag); 876 AUDIOTESTERRORDESC errDesc; 877 rc = AudioTestSetVerify(&tstSet, pszTag, &errDesc); 877 878 if (RT_SUCCESS(rc)) 878 879 { 879 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Verification successful"); 880 if (AudioTestErrorDescFailed(&errDesc)) 881 { 882 /** @todo Use some AudioTestErrorXXX API for enumeration here later. */ 883 PAUDIOTESTERRORENTRY pErrEntry; 884 RTListForEach(&errDesc.List, pErrEntry, AUDIOTESTERRORENTRY, Node) 885 RTTestFailed(g_hTest, pErrEntry->szDesc); 886 } 887 else 888 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Verification successful"); 889 890 AudioTestErrorDescDestroy(&errDesc); 880 891 } 881 892 else
Note:
See TracChangeset
for help on using the changeset viewer.