1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 19 #include "test_pv_frame_metadata_utility.h" 20 21 #include "test_pv_frame_metadata_utility_testset1.h" 22 #if RUN_JANUSCPM_TESTCASES 23 #include "test_pv_frame_metadata_utility_testset_januscpm.h" 24 #endif 25 26 #include "oscl_mem.h" 27 #include "oscl_mem_audit.h" 28 #include "oscl_error.h" 29 #include "oscl_scheduler.h" 30 #include "pvlogger.h" 31 #include "pvlogger_file_appender.h" 32 #include "pvlogger_mem_appender.h" 33 #include "unit_test_args.h" 34 #include "oscl_utf8conv.h" 35 #include "oscl_string_utils.h" 36 37 #include "OMX_Core.h" 38 #include "pv_omxcore.h" 39 40 #ifndef DEFAULTSOURCEFILENAME 41 #error // The default source file needs to be defined in config file 42 #endif 43 44 #ifndef DEFAULTSOURCEFORMATTYPE 45 #error // The format type for default source file needs to be defined in config file 46 #endif 47 48 FILE* file; 49 50 #define MAX_LEN 100 51 52 class PVLoggerConfigFile 53 { 54 /* To change the logging settings without the need to compile the test application 55 Let us read the logging settings from the file instead of hard coding them over here 56 The name of the config file is pvlogger.ini 57 The format of entries in it is like 58 First entry will decide if the file appender has to be used or error appender will be used. 59 0 -> ErrAppender will be used 60 1 -> File Appender will be used 61 2 -> Mem Appender will be used 62 Entries after this will decide the module whose logging has to be taken.For example, contents of one sample config file could be 63 1 64 1,PVPlayerEngine 65 8,PVSocketNode 66 (pls note that no space is allowed between loglevel and logger tag) 67 This means, we intend to have logging of level 1 for the module PVPlayerEngine 68 and of level 8 for the PVSocketNode on file. 69 */ 70 public: 71 72 PVLoggerConfigFile(): iLogFileRead(false) 73 { 74 iFileServer.Connect(); 75 // Full path of pvlogger.ini is: SOURCENAME_PREPEND_STRING + pvlogger.ini 76 oscl_strncpy(iLogFileName, SOURCENAME_PREPEND_STRING, 77 oscl_strlen(SOURCENAME_PREPEND_STRING) + 1); 78 oscl_strcat(iLogFileName, "pvlogger.ini"); 79 oscl_memset(ibuffer, 0, sizeof(ibuffer)); 80 iAppenderType = 0; 81 82 } 83 84 ~PVLoggerConfigFile() 85 { 86 iFileServer.Close(); 87 } 88 89 bool get_next_line(const char *start_ptr, const char * end_ptr, 90 const char *& line_start, 91 const char *& line_end) 92 { 93 // Finds the boundaries of the next non-empty line within start 94 // and end ptrs 95 96 // This initializes line_start to the first non-whitespace character 97 line_start = skip_whitespace_and_line_term(start_ptr, end_ptr); 98 99 line_end = skip_to_line_term(line_start, end_ptr); 100 101 return (line_start < end_ptr); 102 103 } 104 105 106 bool IsLoggerConfigFilePresent() 107 { 108 if (-1 != ReadAndParseLoggerConfigFile()) 109 return true; 110 return false; 111 } 112 113 //Read and parse the config file 114 //retval = -1 if the config file doesnt exist 115 int8 ReadAndParseLoggerConfigFile() 116 { 117 int8 retval = 1; 118 119 if (0 != iLogFile.Open(iLogFileName, Oscl_File::MODE_READ, iFileServer)) 120 { 121 retval = -1; 122 } 123 else 124 { 125 if (!iLogFileRead) 126 { 127 int32 nCharRead = iLogFile.Read(ibuffer, 1, sizeof(ibuffer)); 128 //Parse the buffer for \n chars 129 Oscl_Vector<char*, OsclMemAllocator> LogConfigStrings; 130 131 const char *end_ptr = ibuffer + oscl_strlen(ibuffer) ; // Point just beyond the end 132 const char *section_start_ptr; 133 const char *line_start_ptr, *line_end_ptr; 134 char* end_temp_ptr; 135 int16 offset = 0; 136 137 section_start_ptr = skip_whitespace_and_line_term(ibuffer, end_ptr); 138 139 while (section_start_ptr < end_ptr) 140 { 141 if (!get_next_line(section_start_ptr, end_ptr, 142 line_start_ptr, line_end_ptr)) 143 { 144 break; 145 } 146 147 148 section_start_ptr = line_end_ptr + 1; 149 150 end_temp_ptr = (char*)line_end_ptr; 151 *end_temp_ptr = '\0'; 152 153 LogConfigStrings.push_back((char*)line_start_ptr); 154 155 } 156 157 //Populate the LoggerConfigElements vector 158 { 159 if (!LogConfigStrings.empty()) 160 { 161 Oscl_Vector<char*, OsclMemAllocator>::iterator it; 162 it = LogConfigStrings.begin(); 163 uint32 appenderType; 164 PV_atoi(*it, 'd', oscl_strlen(*it), appenderType); 165 iAppenderType = appenderType; 166 if (LogConfigStrings.size() > 1) 167 { 168 for (it = LogConfigStrings.begin() + 1; it != LogConfigStrings.end(); it++) 169 { 170 char* CommaIndex = (char*)oscl_strstr(*it, ","); 171 if (CommaIndex != NULL) 172 { 173 *CommaIndex = '\0'; 174 LoggerConfigElement obj; 175 uint32 logLevel; 176 PV_atoi(*it, 'd', oscl_strlen(*it), logLevel); 177 obj.iLogLevel = logLevel; 178 obj.iLoggerString = CommaIndex + 1; 179 iLoggerConfigElements.push_back(obj); 180 } 181 } 182 } 183 else 184 { 185 //Add the config element for complete logging fo all the modules 186 LoggerConfigElement obj; 187 obj.iLoggerString = ""; 188 obj.iLogLevel = 8; 189 iLoggerConfigElements.push_back(obj); 190 } 191 } 192 } 193 iLogFile.Close(); 194 iLogFileRead = true; 195 } 196 } 197 return retval; 198 } 199 200 void SetLoggerSettings() 201 { 202 Oscl_Vector<LoggerConfigElement, OsclMemAllocator>::iterator it; 203 204 PVLoggerAppender *appender = NULL; 205 OsclRefCounter *refCounter = NULL; 206 if (iLoggerConfigElements.empty()) 207 { 208 return; 209 } 210 211 if (iAppenderType == 0) 212 { 213 appender = new StdErrAppender<TimeAndIdLayout, 1024>(); 214 OsclRefCounterSA<LogAppenderDestructDealloc<StdErrAppender<TimeAndIdLayout, 1024> > > *appenderRefCounter = 215 new OsclRefCounterSA<LogAppenderDestructDealloc<StdErrAppender<TimeAndIdLayout, 1024> > >(appender); 216 refCounter = appenderRefCounter; 217 } 218 else if (iAppenderType == 1) 219 { 220 OSCL_wHeapString<OsclMemAllocator> logfilename(OUTPUTNAME_PREPEND_WSTRING); 221 logfilename += _STRLIT_WCHAR("player.log"); 222 appender = (PVLoggerAppender*)TextFileAppender<TimeAndIdLayout, 1024>::CreateAppender(logfilename.get_str()); 223 OsclRefCounterSA<LogAppenderDestructDealloc<TextFileAppender<TimeAndIdLayout, 1024> > > *appenderRefCounter = 224 new OsclRefCounterSA<LogAppenderDestructDealloc<TextFileAppender<TimeAndIdLayout, 1024> > >(appender); 225 refCounter = appenderRefCounter; 226 } 227 else 228 { 229 OSCL_wHeapString<OsclMemAllocator> logfilename(OUTPUTNAME_PREPEND_WSTRING); 230 logfilename += _STRLIT_WCHAR("player.log"); 231 appender = (PVLoggerAppender*)MemAppender<TimeAndIdLayout, 1024>::CreateAppender(logfilename.get_str()); 232 OsclRefCounterSA<LogAppenderDestructDealloc<MemAppender<TimeAndIdLayout, 1024> > > *appenderRefCounter = 233 new OsclRefCounterSA<LogAppenderDestructDealloc<MemAppender<TimeAndIdLayout, 1024> > >(appender); 234 refCounter = appenderRefCounter; 235 } 236 237 OsclSharedPtr<PVLoggerAppender> appenderPtr(appender, refCounter); 238 239 for (it = iLoggerConfigElements.begin(); it != iLoggerConfigElements.end(); it++) 240 { 241 PVLogger *node = NULL; 242 node = PVLogger::GetLoggerObject(it->iLoggerString); 243 node->AddAppender(appenderPtr); 244 node->SetLogLevel(it->iLogLevel); 245 } 246 } 247 248 private: 249 class LoggerConfigElement 250 { 251 public: 252 LoggerConfigElement() 253 { 254 iLoggerString = NULL; 255 iLogLevel = 8; 256 } 257 char *iLoggerString; 258 int8 iLogLevel; 259 }; 260 int8 iAppenderType; //Type of appender to be used for the logging 0-> Err Appender, 1-> File Appender 261 bool iLogFileRead; 262 Oscl_File iLogFile; 263 Oscl_FileServer iFileServer; 264 char iLogFileName[255]; 265 char ibuffer[1024]; 266 Oscl_Vector<LoggerConfigElement, OsclMemAllocator> iLoggerConfigElements; 267 }; 268 269 270 // Pull out source file name from arguments 271 // -source sometestfile.mp4 272 // 273 // 274 void FindSourceFile(cmd_line* command_line, OSCL_HeapString<OsclMemAllocator>& aFileNameInfo, PVMFFormatType& aInputFileFormatType, FILE* aFile) 275 { 276 aFileNameInfo = SOURCENAME_PREPEND_STRING; 277 aFileNameInfo += DEFAULTSOURCEFILENAME; 278 aInputFileFormatType = DEFAULTSOURCEFORMATTYPE; 279 280 int iFileArgument = 0; 281 bool iFileFound = false; 282 bool cmdline_iswchar = command_line->is_wchar(); 283 284 int count = command_line->get_count(); 285 286 // Search for the "-source" argument 287 // Go through each argument 288 for (int iFileSearch = 0; iFileSearch < count; iFileSearch++) 289 { 290 char argstr[128]; 291 // Convert to UTF8 if necessary 292 if (cmdline_iswchar) 293 { 294 oscl_wchar* argwstr = NULL; 295 command_line->get_arg(iFileSearch, argwstr); 296 oscl_UnicodeToUTF8(argwstr, oscl_strlen(argwstr), argstr, 128); 297 argstr[127] = NULL; 298 } 299 else 300 { 301 char* tmpstr = NULL; 302 command_line->get_arg(iFileSearch, tmpstr); 303 int32 tmpstrlen = oscl_strlen(tmpstr) + 1; 304 if (tmpstrlen > 128) 305 { 306 tmpstrlen = 128; 307 } 308 oscl_strncpy(argstr, tmpstr, tmpstrlen); 309 argstr[tmpstrlen-1] = NULL; 310 } 311 312 // Do the string compare 313 if (oscl_strcmp(argstr, "-help") == NULL) 314 { 315 fprintf(aFile, "Source specification option. Default is 'test.mp4':\n"); 316 fprintf(aFile, " -source sourcename\n"); 317 fprintf(aFile, " Specify the source filename or URL to use for test cases which\n"); 318 fprintf(aFile, " allow user-specified source name. The unit test determines the\n"); 319 fprintf(aFile, " source format type using extension or URL header.\n\n"); 320 } 321 else if (oscl_strcmp(argstr, "-source") == NULL) 322 { 323 iFileFound = true; 324 iFileArgument = ++iFileSearch; 325 break; 326 } 327 } 328 329 if (iFileFound) 330 { 331 // Convert to UTF8 if necessary 332 if (cmdline_iswchar) 333 { 334 oscl_wchar* cmd; 335 command_line->get_arg(iFileArgument, cmd); 336 char tmpstr[256]; 337 oscl_UnicodeToUTF8(cmd, oscl_strlen(cmd), tmpstr, 256); 338 tmpstr[255] = NULL; 339 aFileNameInfo = tmpstr; 340 } 341 else 342 { 343 char* cmdlinefilename = NULL; 344 command_line->get_arg(iFileArgument, cmdlinefilename); 345 aFileNameInfo = cmdlinefilename; 346 } 347 348 // Check the file extension to determine format type 349 // AAC file 350 if (oscl_strstr(aFileNameInfo.get_cstr(), ".aac") != NULL || oscl_strstr(aFileNameInfo.get_cstr(), ".AAC") != NULL) 351 { 352 aInputFileFormatType = PVMF_MIME_AACFF; 353 } 354 // MP3 file 355 else if (oscl_strstr(aFileNameInfo.get_cstr(), ".mp3") != NULL || oscl_strstr(aFileNameInfo.get_cstr(), ".MP3") != NULL) 356 { 357 aInputFileFormatType = PVMF_MIME_MP3FF; 358 } 359 // AMR file (IETF and IF2) 360 else if (oscl_strstr(aFileNameInfo.get_cstr(), ".amr") != NULL || oscl_strstr(aFileNameInfo.get_cstr(), ".AMR") != NULL || 361 oscl_strstr(aFileNameInfo.get_cstr(), ".cod") != NULL || oscl_strstr(aFileNameInfo.get_cstr(), ".COD") != NULL) 362 { 363 aInputFileFormatType = PVMF_MIME_AMRFF; 364 } 365 // RTSP URL 366 else if ((!oscl_strncmp("rtsp", aFileNameInfo.get_cstr(), 4)) || 367 (!oscl_strncmp("RTSP", aFileNameInfo.get_cstr(), 4))) 368 { 369 aInputFileFormatType = PVMF_MIME_DATA_SOURCE_RTSP_URL; 370 } 371 // HTTP URL 372 else if (oscl_strstr(aFileNameInfo.get_cstr(), "http:") != NULL || oscl_strstr(aFileNameInfo.get_cstr(), "HTTP:") != NULL) 373 { 374 aInputFileFormatType = PVMF_MIME_DATA_SOURCE_HTTP_URL; 375 } 376 // MP4/3GP file 377 else if (oscl_strstr(aFileNameInfo.get_cstr(), ".mp4") != NULL || oscl_strstr(aFileNameInfo.get_cstr(), ".MP4") != NULL || 378 oscl_strstr(aFileNameInfo.get_cstr(), ".3gp") != NULL || oscl_strstr(aFileNameInfo.get_cstr(), ".3GP") != NULL) 379 { 380 aInputFileFormatType = PVMF_MIME_MPEG4FF; 381 } 382 // ASF file 383 else if (oscl_strstr(aFileNameInfo.get_cstr(), ".asf") != NULL || oscl_strstr(aFileNameInfo.get_cstr(), ".ASF") != NULL || 384 oscl_strstr(aFileNameInfo.get_cstr(), ".wma") != NULL || oscl_strstr(aFileNameInfo.get_cstr(), ".WMA") != NULL || 385 oscl_strstr(aFileNameInfo.get_cstr(), ".wmv") != NULL || oscl_strstr(aFileNameInfo.get_cstr(), ".WMV") != NULL) 386 { 387 aInputFileFormatType = PVMF_MIME_ASFFF; 388 } 389 // SDP file 390 else if (oscl_strstr(aFileNameInfo.get_cstr(), ".sdp") != NULL || oscl_strstr(aFileNameInfo.get_cstr(), ".SDP") != NULL) 391 { 392 aInputFileFormatType = PVMF_MIME_DATA_SOURCE_SDP_FILE; 393 } 394 // PVX file 395 else if (oscl_strstr(aFileNameInfo.get_cstr(), ".pvx") != NULL || oscl_strstr(aFileNameInfo.get_cstr(), ".PVX") != NULL) 396 { 397 aInputFileFormatType = PVMF_MIME_DATA_SOURCE_PVX_FILE; 398 } 399 // WAV file 400 else if (oscl_strstr(aFileNameInfo.get_cstr(), ".wav") != NULL || oscl_strstr(aFileNameInfo.get_cstr(), ".WAV") != NULL) 401 { 402 aInputFileFormatType = PVMF_MIME_WAVFF; 403 } 404 // Unknown so set to unknown and let the player engine determine the format type 405 else 406 { 407 fprintf(file, "Source type unknown so setting to unknown and have the utility recognize it\n"); 408 aInputFileFormatType = PVMF_MIME_FORMAT_UNKNOWN; 409 } 410 } 411 } 412 413 //Find test range args: 414 //To run a range of tests by enum ID: 415 // -test 17 29 416 void FindTestRange(cmd_line* command_line, int32& iFirstTest, int32 &iLastTest, FILE* aFile) 417 { 418 //default is to run all tests. 419 iFirstTest = 0; 420 iLastTest = 999; 421 422 int iTestArgument = 0; 423 char *iTestArgStr1 = NULL; 424 char *iTestArgStr2 = NULL; 425 bool iTestFound = false; 426 bool cmdline_iswchar = command_line->is_wchar(); 427 428 int count = command_line->get_count(); 429 430 // Search for the "-test" argument 431 char *iSourceFind = NULL; 432 if (cmdline_iswchar) 433 { 434 iSourceFind = new char[256]; 435 } 436 437 // Go through each argument 438 for (int iTestSearch = 0; iTestSearch < count; iTestSearch++) 439 { 440 // Convert to UTF8 if necessary 441 if (cmdline_iswchar) 442 { 443 OSCL_TCHAR* cmd = NULL; 444 command_line->get_arg(iTestSearch, cmd); 445 oscl_UnicodeToUTF8(cmd, oscl_strlen(cmd), iSourceFind, 256); 446 } 447 else 448 { 449 iSourceFind = NULL; 450 command_line->get_arg(iTestSearch, iSourceFind); 451 } 452 453 // Do the string compare 454 if (oscl_strcmp(iSourceFind, "-help") == NULL) 455 { 456 fprintf(aFile, "Test cases to run option. Default is ALL:\n"); 457 fprintf(aFile, " -test x y\n"); 458 fprintf(aFile, " Specify a range of test cases to run. To run one test case, use the\n"); 459 fprintf(aFile, " same index for x and y.\n\n"); 460 } 461 else if (oscl_strcmp(iSourceFind, "-test") == NULL) 462 { 463 iTestFound = true; 464 iTestArgument = ++iTestSearch; 465 break; 466 } 467 } 468 469 if (cmdline_iswchar) 470 { 471 delete[] iSourceFind; 472 iSourceFind = NULL; 473 } 474 475 if (iTestFound) 476 { 477 // Convert to UTF8 if necessary 478 if (cmdline_iswchar) 479 { 480 iTestArgStr1 = new char[256]; 481 OSCL_TCHAR* cmd; 482 command_line->get_arg(iTestArgument, cmd); 483 if (cmd) 484 { 485 oscl_UnicodeToUTF8(cmd, oscl_strlen(cmd), iTestArgStr1, 256); 486 } 487 488 iTestArgStr2 = new char[256]; 489 command_line->get_arg(iTestArgument + 1, cmd); 490 if (cmd) 491 { 492 oscl_UnicodeToUTF8(cmd, oscl_strlen(cmd), iTestArgStr2, 256); 493 } 494 } 495 else 496 { 497 command_line->get_arg(iTestArgument, iTestArgStr1); 498 command_line->get_arg(iTestArgument + 1, iTestArgStr2); 499 } 500 501 //Pull out 2 integers... 502 if (iTestArgStr1 503 && '0' <= iTestArgStr1[0] && iTestArgStr1[0] <= '9' 504 && iTestArgStr2 505 && '0' <= iTestArgStr2[0] && iTestArgStr2[0] <= '9') 506 { 507 int len = oscl_strlen(iTestArgStr1); 508 switch (len) 509 { 510 case 3: 511 iFirstTest = 0; 512 if ('0' <= iTestArgStr1[0] && iTestArgStr1[0] <= '9') 513 { 514 iFirstTest = iFirstTest + 100 * (iTestArgStr1[0] - '0'); 515 } 516 517 if ('0' <= iTestArgStr1[1] && iTestArgStr1[1] <= '9') 518 { 519 iFirstTest = iFirstTest + 10 * (iTestArgStr1[1] - '0'); 520 } 521 522 if ('0' <= iTestArgStr1[2] && iTestArgStr1[2] <= '9') 523 { 524 iFirstTest = iFirstTest + 1 * (iTestArgStr1[2] - '0'); 525 } 526 break; 527 528 case 2: 529 iFirstTest = 0; 530 if ('0' <= iTestArgStr1[0] && iTestArgStr1[0] <= '9') 531 { 532 iFirstTest = iFirstTest + 10 * (iTestArgStr1[0] - '0'); 533 } 534 535 if ('0' <= iTestArgStr1[1] && iTestArgStr1[1] <= '9') 536 { 537 iFirstTest = iFirstTest + 1 * (iTestArgStr1[1] - '0'); 538 } 539 break; 540 541 case 1: 542 iFirstTest = 0; 543 if ('0' <= iTestArgStr1[0] && iTestArgStr1[0] <= '9') 544 { 545 iFirstTest = iFirstTest + 1 * (iTestArgStr1[0] - '0'); 546 } 547 break; 548 549 default: 550 break; 551 } 552 553 len = oscl_strlen(iTestArgStr2); 554 switch (len) 555 { 556 case 3: 557 iLastTest = 0; 558 if ('0' <= iTestArgStr2[0] && iTestArgStr2[0] <= '9') 559 { 560 iLastTest = iLastTest + 100 * (iTestArgStr2[0] - '0'); 561 } 562 563 if ('0' <= iTestArgStr2[1] && iTestArgStr2[1] <= '9') 564 { 565 iLastTest = iLastTest + 10 * (iTestArgStr2[1] - '0'); 566 } 567 568 if ('0' <= iTestArgStr2[2] && iTestArgStr2[2] <= '9') 569 { 570 iLastTest = iLastTest + 1 * (iTestArgStr2[2] - '0'); 571 } 572 break; 573 574 case 2: 575 iLastTest = 0; 576 if ('0' <= iTestArgStr2[0] && iTestArgStr2[0] <= '9') 577 { 578 iLastTest = iLastTest + 10 * (iTestArgStr2[0] - '0'); 579 } 580 581 if ('0' <= iTestArgStr2[1] && iTestArgStr2[1] <= '9') 582 { 583 iLastTest = iLastTest + 1 * (iTestArgStr2[1] - '0'); 584 } 585 break; 586 587 case 1: 588 iLastTest = 0; 589 if ('0' <= iTestArgStr2[0] && iTestArgStr2[0] <= '9') 590 { 591 iLastTest = iLastTest + 1 * (iTestArgStr2[0] - '0'); 592 } 593 break; 594 595 default: 596 break; 597 } 598 } 599 } 600 601 if (cmdline_iswchar) 602 { 603 if (iTestArgStr1) 604 { 605 delete[] iTestArgStr1; 606 iTestArgStr1 = NULL; 607 } 608 609 if (iTestArgStr2) 610 { 611 delete[] iTestArgStr2; 612 iTestArgStr2 = NULL; 613 } 614 615 if (iSourceFind) 616 { 617 delete[] iSourceFind; 618 iSourceFind = NULL; 619 } 620 } 621 } 622 623 624 void FindMemMgmtRelatedCmdLineParams(cmd_line* command_line, bool& aPrintDetailedMemLeakInfo, FILE* aFile) 625 { 626 aPrintDetailedMemLeakInfo = false; 627 628 bool cmdline_iswchar = command_line->is_wchar(); 629 630 int count = command_line->get_count(); 631 632 // Search for the "-logerr"/"-logwarn" argument 633 char *iSourceFind = NULL; 634 if (cmdline_iswchar) 635 { 636 iSourceFind = new char[256]; 637 } 638 639 // Go through each argument 640 for (int iTestSearch = 0; iTestSearch < count; iTestSearch++) 641 { 642 // Convert to UTF8 if necessary 643 if (cmdline_iswchar) 644 { 645 OSCL_TCHAR* cmd = NULL; 646 command_line->get_arg(iTestSearch, cmd); 647 oscl_UnicodeToUTF8(cmd, oscl_strlen(cmd), iSourceFind, 256); 648 } 649 else 650 { 651 iSourceFind = NULL; 652 command_line->get_arg(iTestSearch, iSourceFind); 653 } 654 655 // Do the string compare 656 if (oscl_strcmp(iSourceFind, "-help") == NULL) 657 { 658 fprintf(aFile, "Printing leak info option. Default is OFF:\n"); 659 fprintf(aFile, " -leakinfo\n"); 660 fprintf(aFile, " If there is a memory leak, prints out the memory leak information\n"); 661 fprintf(aFile, " after all specified test cases have finished running.\n\n"); 662 } 663 else if (oscl_strcmp(iSourceFind, "-leakinfo") == NULL) 664 { 665 aPrintDetailedMemLeakInfo = true; 666 } 667 } 668 669 if (cmdline_iswchar) 670 { 671 delete[] iSourceFind; 672 iSourceFind = NULL; 673 } 674 } 675 676 677 void FindLogLevel(cmd_line* command_line, int32& loglevel, FILE* aFile) 678 { 679 //default is verbose 680 loglevel = PVLOGMSG_DEBUG; 681 682 bool cmdline_iswchar = command_line->is_wchar(); 683 684 int count = command_line->get_count(); 685 686 // Search for the "-logerr"/"-logwarn" argument 687 char *iSourceFind = NULL; 688 if (cmdline_iswchar) 689 { 690 iSourceFind = new char[256]; 691 } 692 693 // Go through each argument 694 for (int iTestSearch = 0; iTestSearch < count; iTestSearch++) 695 { 696 // Convert to UTF8 if necessary 697 if (cmdline_iswchar) 698 { 699 OSCL_TCHAR* cmd = NULL; 700 command_line->get_arg(iTestSearch, cmd); 701 oscl_UnicodeToUTF8(cmd, oscl_strlen(cmd), iSourceFind, 256); 702 } 703 else 704 { 705 iSourceFind = NULL; 706 command_line->get_arg(iTestSearch, iSourceFind); 707 } 708 709 // Do the string compare 710 if (oscl_strcmp(iSourceFind, "-help") == NULL) 711 { 712 fprintf(aFile, "Log level options. Default is debug level:\n"); 713 fprintf(aFile, " -logerr\n"); 714 fprintf(aFile, " Log at error level\n"); 715 fprintf(aFile, " -logwarn\n"); 716 fprintf(aFile, " Log at warning level\n\n"); 717 } 718 else if (oscl_strcmp(iSourceFind, "-logerr") == NULL) 719 { 720 loglevel = PVLOGMSG_ERR; 721 } 722 else if (oscl_strcmp(iSourceFind, "-logwarn") == NULL) 723 { 724 loglevel = PVLOGMSG_WARNING; 725 } 726 } 727 728 if (cmdline_iswchar) 729 { 730 delete[] iSourceFind; 731 iSourceFind = NULL; 732 } 733 } 734 735 int _local_main(FILE* filehandle, cmd_line* command_line); 736 737 // Entry point for the unit test program 738 int local_main(FILE* filehandle, cmd_line* command_line) 739 { 740 //Init Oscl 741 OsclBase::Init(); 742 OsclErrorTrap::Init(); 743 OsclMem::Init(); 744 OMX_MasterInit(); 745 746 const int numArgs = 10; //change as per the number of args below 747 char *argv[numArgs]; 748 char arr[numArgs][MAX_LEN]; 749 FILE *InputFile = NULL; 750 int argc = 0; 751 752 fprintf(filehandle, "Test Program for pvFrameMetadata utility class.\n"); 753 754 InputFile = fopen("input.txt", "r+"); 755 if (NULL != InputFile) 756 { 757 int ii = 0; 758 int len = 0; 759 fseek(InputFile , 0 , SEEK_SET); 760 while (!feof(InputFile)) 761 { 762 arr[ii][0] = '\0'; 763 fgets(arr[ii], 127, InputFile); 764 len = strlen(arr[ii]); 765 if (arr[ii][len-1] == '\n') 766 { 767 arr[ii][len-1] = '\0'; 768 } 769 else 770 { 771 arr[ii][len-1] = '\0'; 772 } 773 argv[ii] = arr[ii]; 774 775 ii++; 776 } 777 fclose(InputFile); 778 779 argc = ii - 1; 780 } 781 782 int n = 0; 783 784 command_line->setup(argc - n, &argv[n]); 785 786 bool oPrintDetailedMemLeakInfo = false; 787 FindMemMgmtRelatedCmdLineParams(command_line, oPrintDetailedMemLeakInfo, filehandle); 788 789 //Run the test under a trap 790 int result = 0; 791 int32 err = 0; 792 793 OSCL_TRY(err, result = _local_main(filehandle, command_line);); 794 795 //Show any exception. 796 if (err != 0) 797 { 798 fprintf(file, "Error! Leave %d\n", err); 799 } 800 801 //Cleanup 802 OMX_MasterDeinit(); 803 #if !(OSCL_BYPASS_MEMMGT) 804 //Check for memory leaks before cleaning up OsclMem. 805 OsclAuditCB auditCB; 806 OsclMemInit(auditCB); 807 if (auditCB.pAudit) 808 { 809 MM_Stats_t* stats = auditCB.pAudit->MM_GetStats(""); 810 if (stats) 811 { 812 fprintf(file, "\nMemory Stats:\n"); 813 fprintf(file, " peakNumAllocs %d\n", stats->peakNumAllocs); 814 fprintf(file, " peakNumBytes %d\n", stats->peakNumBytes); 815 fprintf(file, " totalNumAllocs %d\n", stats->totalNumAllocs); 816 fprintf(file, " totalNumBytes %d\n", stats->totalNumBytes); 817 fprintf(file, " numAllocFails %d\n", stats->numAllocFails); 818 if (stats->numAllocs) 819 { 820 fprintf(file, " ERROR: Memory Leaks! numAllocs %d, numBytes %d\n", stats->numAllocs, stats->numBytes); 821 } 822 } 823 uint32 leaks = auditCB.pAudit->MM_GetNumAllocNodes(); 824 if (leaks != 0) 825 { 826 if (oPrintDetailedMemLeakInfo) 827 { 828 fprintf(file, "ERROR: %d Memory leaks detected!\n", leaks); 829 MM_AllocQueryInfo*info = auditCB.pAudit->MM_CreateAllocNodeInfo(leaks); 830 uint32 leakinfo = auditCB.pAudit->MM_GetAllocNodeInfo(info, leaks, 0); 831 if (leakinfo != leaks) 832 { 833 fprintf(file, "ERROR: Leak info is incomplete.\n"); 834 } 835 for (uint32 i = 0; i < leakinfo; i++) 836 { 837 fprintf(file, "Leak Info:\n"); 838 fprintf(file, " allocNum %d\n", info[i].allocNum); 839 fprintf(file, " fileName %s\n", info[i].fileName); 840 fprintf(file, " lineNo %d\n", info[i].lineNo); 841 fprintf(file, " size %d\n", info[i].size); 842 fprintf(file, " pMemBlock 0x%x\n", info[i].pMemBlock); 843 fprintf(file, " tag %s\n", info[i].tag); 844 } 845 auditCB.pAudit->MM_ReleaseAllocNodeInfo(info); 846 } 847 } 848 } 849 #endif 850 851 OsclMem::Cleanup(); 852 OsclErrorTrap::Cleanup(); 853 OsclBase::Cleanup(); 854 return result; 855 } 856 857 int _local_main(FILE* filehandle, cmd_line* command_line) 858 { 859 file = filehandle; 860 861 // Print out the extension for help if no argument 862 if (command_line->get_count() == 0) 863 { 864 fprintf(file, " Specify '-help' first to get help information on options\n\n"); 865 } 866 867 OSCL_HeapString<OsclMemAllocator> filenameinfo; 868 PVMFFormatType inputformattype ; 869 FindSourceFile(command_line, filenameinfo, inputformattype, file); 870 871 int32 firsttest, lasttest; 872 FindTestRange(command_line, firsttest, lasttest, file); 873 874 int32 loglevel; 875 FindLogLevel(command_line, loglevel, file); 876 877 fprintf(file, " Input file name '%s'\n", filenameinfo.get_cstr()); 878 fprintf(file, " Test case range %d to %d\n", firsttest, lasttest); 879 fprintf(file, " Log level %d\n", loglevel); 880 881 pvframemetadata_utility_test_suite* util_tests = NULL; 882 util_tests = new pvframemetadata_utility_test_suite(filenameinfo.get_str(), inputformattype, firsttest, lasttest, loglevel); 883 if (util_tests) 884 { 885 // Run the utility test 886 util_tests->run_test(); 887 888 // Print out the results 889 text_test_interpreter interp; 890 _STRING rs = interp.interpretation(util_tests->last_result()); 891 fprintf(file, rs.c_str()); 892 893 const test_result the_result = util_tests->last_result(); 894 delete util_tests; 895 util_tests = NULL; 896 897 return (the_result.success_count() != the_result.total_test_count()); 898 } 899 else 900 { 901 fprintf(file, "ERROR! pvframemetadata_utility_test_suite could not be instantiated.\n"); 902 return 1; 903 } 904 } 905 906 907 pvframemetadata_utility_test_suite::pvframemetadata_utility_test_suite(char *aFileName, PVMFFormatType aFileType, int32 aFirstTest, int32 aLastTest, int32 aLogLevel) 908 : test_case() 909 { 910 adopt_test_case(new pvframemetadata_utility_test(aFileName, aFileType, aFirstTest, aLastTest, aLogLevel)); 911 } 912 913 914 915 pvframemetadata_utility_test::pvframemetadata_utility_test(char *aFileName, PVMFFormatType aFileType, int32 aFirstTest, int32 aLastTest, int32 aLogLevel) 916 { 917 iFileName = aFileName; 918 iFileType = aFileType; 919 iCurrentTestNumber = 0; 920 iCurrentTest = NULL; 921 iFirstTest = aFirstTest; 922 iLastTest = aLastTest; 923 iLogLevel = aLogLevel; 924 iTotalAlloc = 0; 925 iTotalBytes = 0; 926 iAllocFails = 0; 927 iNumAllocs = 0; 928 } 929 930 931 pvframemetadata_utility_test::~pvframemetadata_utility_test() 932 { 933 } 934 935 936 void pvframemetadata_utility_test::TestCompleted(test_case &tc) 937 { 938 // Print out the result for this test case 939 const test_result the_result = tc.last_result(); 940 fprintf(file, " Successes %d, Failures %d\n" 941 , the_result.success_count() - iTotalSuccess, the_result.failures().size() - iTotalFail); 942 iTotalSuccess = the_result.success_count(); 943 iTotalFail = the_result.failures().size(); 944 iTotalError = the_result.errors().size(); 945 946 // Go to next test 947 ++iCurrentTestNumber; 948 949 // Stop the scheduler 950 OsclExecScheduler *sched = OsclExecScheduler::Current(); 951 if (sched) 952 { 953 sched->StopScheduler(); 954 } 955 } 956 957 void pvframemetadata_utility_test::test() 958 { 959 // Specify the starting test case 960 iCurrentTestNumber = iFirstTest; 961 iTotalSuccess = iTotalFail = iTotalError = 0; 962 963 while (iCurrentTestNumber <= iLastTest || iCurrentTestNumber < BeyondLastTest) 964 { 965 if (iCurrentTest) 966 { 967 delete iCurrentTest; 968 iCurrentTest = NULL; 969 970 // Shutdown PVLogger and scheduler before checking mem stats 971 OsclScheduler::Cleanup(); 972 PVLogger::Cleanup(); 973 #if !(OSCL_BYPASS_MEMMGT) 974 // Print out the memory usage results for this test case 975 OsclAuditCB auditCB; 976 OsclMemInit(auditCB); 977 if (auditCB.pAudit) 978 { 979 MM_Stats_t* stats = auditCB.pAudit->MM_GetStats(""); 980 if (stats) 981 { 982 fprintf(file, " Mem stats: TotalAllocs(%d), TotalBytes(%d),\n AllocFailures(%d), AllocLeak(%d)\n", 983 stats->totalNumAllocs - iTotalAlloc, stats->totalNumBytes - iTotalBytes, stats->numAllocFails - iAllocFails, stats->numAllocs - iNumAllocs); 984 } 985 else 986 { 987 fprintf(file, "Retrieving memory statistics after running test case failed! Memory statistics result is not available.\n"); 988 } 989 } 990 else 991 { 992 fprintf(file, "Memory audit not available! Memory statistics result is not available.\n"); 993 } 994 #endif 995 } 996 997 #if !(OSCL_BYPASS_MEMMGT) 998 // Obtain the current mem stats before running the test case 999 OsclAuditCB auditCB; 1000 OsclMemInit(auditCB); 1001 if (auditCB.pAudit) 1002 { 1003 MM_Stats_t* stats = auditCB.pAudit->MM_GetStats(""); 1004 if (stats) 1005 { 1006 iTotalAlloc = stats->totalNumAllocs; 1007 iTotalBytes = stats->totalNumBytes; 1008 iAllocFails = stats->numAllocFails; 1009 iNumAllocs = stats->numAllocs; 1010 } 1011 else 1012 { 1013 fprintf(file, "Retrieving memory statistics before running test case failed! Memory statistics result would be invalid.\n"); 1014 } 1015 } 1016 else 1017 { 1018 fprintf(file, "Memory audit not available! Memory statistics result would be invalid.\n"); 1019 } 1020 #endif 1021 1022 // Stop at last test of selected range. 1023 if (iCurrentTestNumber > iLastTest || iCurrentTestNumber == LastTest) 1024 { 1025 iCurrentTestNumber = BeyondLastTest; 1026 } 1027 else 1028 { 1029 fprintf(file, "\nStarting Test %d: ", iCurrentTestNumber); 1030 SetupLoggerScheduler(); 1031 } 1032 1033 // Setup the standard test case parameters based on current unit test settings 1034 PVFrameMetadataAsyncTestParam testparam; 1035 testparam.iObserver = this; 1036 testparam.iTestCase = this; 1037 testparam.iTestMsgOutputFile = file; 1038 testparam.iFileName = iFileName; 1039 testparam.iFileType = iFileType; 1040 testparam.iOutputFrameType = PVMF_MIME_YUV420; 1041 1042 switch (iCurrentTestNumber) 1043 { 1044 case NewDeleteTest: 1045 iCurrentTest = new pvframemetadata_async_test_newdelete(testparam); 1046 break; 1047 1048 case GetSourceMetadataTest: 1049 iCurrentTest = new pvframemetadata_async_test_getmetadata(testparam, 1); 1050 break; 1051 1052 case GetSourceMetadataandFrameTest: 1053 iCurrentTest = new pvframemetadata_async_test_getmetadata(testparam, 2); 1054 break; 1055 1056 case GetSourceMetadataandBestFrameTest: 1057 iCurrentTest = new pvframemetadata_async_test_getmetadata(testparam, 2, true); 1058 break; 1059 1060 case GetAllMetadataTest: 1061 iCurrentTest = new pvframemetadata_async_test_getmetadata(testparam, 3); 1062 break; 1063 1064 case GetFirstFrameYUV420AndMetadataTest: 1065 #if RUN_YUV420_TESTCASES 1066 testparam.iOutputFrameType = PVMF_MIME_YUV420; 1067 iCurrentTest = new pvframemetadata_async_test_getfirstframemetadata(testparam); 1068 fprintf(file, "YUV 4:2:0 "); 1069 #else 1070 fprintf(file, "YUV420 test cases disabled\n"); 1071 #endif 1072 break; 1073 1074 case GetFirstFrameYUV420UtilityBufferTest: 1075 #if RUN_YUV420_TESTCASES 1076 testparam.iOutputFrameType = PVMF_MIME_YUV420; 1077 iCurrentTest = new pvframemetadata_async_test_getfirstframeutilitybuffer(testparam); 1078 fprintf(file, "YUV 4:2:0 "); 1079 #else 1080 fprintf(file, "YVU420 test cases disabled\n"); 1081 #endif 1082 break; 1083 1084 case GetFirstFrameRGB12AndMetadataTest: 1085 #if RUN_RGB12_TESTCASES 1086 testparam.iOutputFrameType = PVMF_RGB12; 1087 iCurrentTest = new pvframemetadata_async_test_getfirstframemetadata(testparam); 1088 fprintf(file, "RGB 12bpp "); 1089 #else 1090 fprintf(file, "RGB12 test cases disabled\n"); 1091 #endif 1092 break; 1093 1094 case GetFirstFrameRGB12UtilityBufferTest: 1095 #if RUN_RGB12_TESTCASES 1096 testparam.iOutputFrameType = PVMF_RGB12; 1097 iCurrentTest = new pvframemetadata_async_test_getfirstframeutilitybuffer(testparam); 1098 fprintf(file, "RGB 12bpp "); 1099 #else 1100 fprintf(file, "RGB12 test cases disabled\n"); 1101 #endif 1102 break; 1103 1104 case GetFirstFrameRGB16AndMetadataTest: 1105 #if RUN_RGB16_TESTCASES 1106 testparam.iOutputFrameType = PVMF_MIME_RGB16; 1107 iCurrentTest = new pvframemetadata_async_test_getfirstframemetadata(testparam); 1108 fprintf(file, "RGB 16bpp "); 1109 #else 1110 fprintf(file, "RGB16 test cases disabled\n"); 1111 #endif 1112 break; 1113 1114 case GetFirstFrameRGB16UtilityBufferTest: 1115 #if RUN_RGB16_TESTCASES 1116 testparam.iOutputFrameType = PVMF_MIME_RGB16; 1117 iCurrentTest = new pvframemetadata_async_test_getfirstframeutilitybuffer(testparam); 1118 fprintf(file, "RGB 16bpp "); 1119 #else 1120 fprintf(file, "RGB16 test cases disabled\n"); 1121 #endif 1122 break; 1123 1124 case GetFirstFrameRGB24AndMetadataTest: 1125 #if RUN_RGB24_TESTCASES 1126 testparam.iOutputFrameType = PVMF_RGB24; 1127 iCurrentTest = new pvframemetadata_async_test_getfirstframemetadata(testparam); 1128 fprintf(file, "RGB 24bpp "); 1129 #else 1130 fprintf(file, "RGB24 test cases disabled\n"); 1131 #endif 1132 break; 1133 1134 case GetFirstFrameRGB24UtilityBufferTest: 1135 #if RUN_RGB24_TESTCASES 1136 testparam.iOutputFrameType = PVMF_RGB24; 1137 iCurrentTest = new pvframemetadata_async_test_getfirstframeutilitybuffer(testparam); 1138 fprintf(file, "RGB 24bpp "); 1139 #else 1140 fprintf(file, "RGB24 test cases disabled\n"); 1141 #endif 1142 break; 1143 1144 case Get30thFrameTest: 1145 iCurrentTest = new pvframemetadata_async_test_get30thframe(testparam); 1146 break; 1147 1148 case Get10secFrameTest: 1149 iCurrentTest = new pvframemetadata_async_test_get10secframe(testparam); 1150 break; 1151 1152 case CancelCommandTest: 1153 iCurrentTest = new pvframemetadata_async_test_cancelcommand(testparam); 1154 break; 1155 1156 case MultipleGetFirstFrameAndMetadataTest: 1157 iCurrentTest = new pvframemetadata_async_test_multigetfirstframemetadata(testparam); 1158 break; 1159 1160 case MultipleGetFramesYUVTest: 1161 #if RUN_YUV420_TESTCASES 1162 testparam.iOutputFrameType = PVMF_MIME_YUV420; 1163 iCurrentTest = new pvframemetadata_async_test_multigetframe(testparam); 1164 fprintf(file, "YUV 4:2:0 "); 1165 #else 1166 fprintf(file, "YUV420 test cases disabled\n"); 1167 #endif 1168 break; 1169 1170 case MultipleGetFramesRGB24Test: 1171 #if RUN_RGB24_TESTCASES 1172 testparam.iOutputFrameType = PVMF_RGB24; 1173 iCurrentTest = new pvframemetadata_async_test_multigetframe(testparam); 1174 fprintf(file, "RGB 24bpp "); 1175 #else 1176 fprintf(file, "RGB24 test cases disabled\n"); 1177 #endif 1178 break; 1179 1180 case InvalidSourceFileTest: 1181 iCurrentTest = new pvframemetadata_async_test_invalidsourcefile(testparam); 1182 break; 1183 1184 case NoGetFrameTest: 1185 iCurrentTest = new pvframemetadata_async_test_nogetframe(testparam); 1186 break; 1187 1188 case NoVideoTrackTest: 1189 testparam.iFileName = NOVIDEOSOURCEFILENAME; 1190 testparam.iFileType = NOVIDEOSOURCEFORMATTYPE; 1191 iCurrentTest = new pvframemetadata_async_test_novideotrack(testparam); 1192 break; 1193 1194 case ProtectedMetadataTest: 1195 #if RUN_JANUSCPM_TESTCASES 1196 iCurrentTest = new pvframemetadata_async_test_protectedmetadata(testparam); 1197 #else 1198 fprintf(file, "Janus CPM test cases disabled\n"); 1199 #endif 1200 break; 1201 case SetTimeoutAndGetFrameTest: 1202 iCurrentTest = new pvframemetadata_async_test_settimeout_getframe(testparam, 2, false); 1203 break; 1204 1205 case SetPlayerKeyTest: 1206 iCurrentTest = new pvframemetadata_async_test_set_player_key(testparam); 1207 break; 1208 1209 case BeyondLastTest: 1210 default: 1211 iCurrentTestNumber = BeyondLastTest; 1212 break; 1213 } 1214 1215 if (iCurrentTest) 1216 { 1217 OsclExecScheduler *sched = OsclExecScheduler::Current(); 1218 if (sched) 1219 { 1220 // Print out the test name 1221 fprintf(file, "%s\n", iCurrentTest->iTestCaseName.get_cstr()); 1222 // Start the test 1223 iCurrentTest->StartTest(); 1224 // Start the scheduler so the test case would run 1225 #if USE_NATIVE_SCHEDULER 1226 // Have PV scheduler use the scheduler native to the system 1227 sched->StartNativeScheduler(); 1228 #else 1229 // Have PV scheduler use its own implementation of the scheduler 1230 sched->StartScheduler(); 1231 #endif 1232 } 1233 else 1234 { 1235 fprintf(file, "ERROR! Scheduler is not available. Test case could not run."); 1236 ++iCurrentTestNumber; 1237 } 1238 } 1239 else 1240 { 1241 ++iCurrentTestNumber; 1242 if (iCurrentTestNumber < BeyondLastTest) 1243 { 1244 // Shutdown PVLogger and scheduler before continuing on 1245 OsclScheduler::Cleanup(); 1246 PVLogger::Cleanup(); 1247 } 1248 } 1249 } 1250 } 1251 1252 void pvframemetadata_utility_test::SetupLoggerScheduler() 1253 { 1254 // Enable the following code for logging (on Symbian, RDebug) 1255 PVLogger::Init(); 1256 PVLoggerConfigFile obj; 1257 if (obj.IsLoggerConfigFilePresent()) 1258 { 1259 obj.SetLoggerSettings(); 1260 } 1261 // Construct and install the active scheduler 1262 OsclScheduler::Init("PVFrameMetadataUtilityTestScheduler"); 1263 } 1264 1265 1266 1267 1268