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