mediastreamer2_tester.c 3.78 KB
Newer Older
Ghislain MARY's avatar
Ghislain MARY committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2006-2013 Belledonne Communications, Grenoble

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include "mediastreamer2_tester.h"
21
#include "mediastreamer2_tester_private.h"
Ghislain MARY's avatar
Ghislain MARY committed
22

jehan's avatar
jehan committed
23 24 25
#ifdef __APPLE__
#include "TargetConditionals.h"
#endif
26

27

28
static FILE * log_file = NULL;
29

30
static void log_handler(int lev, const char *fmt, va_list args) {
31
#ifdef _WIN32
32
	vfprintf(lev == ORTP_ERROR ? stderr : stdout, fmt, args);
33 34 35 36 37 38 39 40 41
	fprintf(lev == ORTP_ERROR ? stderr : stdout, "\n");
#else
	va_list cap;
	va_copy(cap,args);
	/* Otherwise, we must use stdio to avoid log formatting (for autocompletion etc.) */
	vfprintf(lev == ORTP_ERROR ? stderr : stdout, fmt, cap);
	fprintf(lev == ORTP_ERROR ? stderr : stdout, "\n");
	va_end(cap);
#endif
42
	if (log_file){
43
		ortp_logv_out(lev, fmt, args);
44
	}
Ghislain MARY's avatar
Ghislain MARY committed
45 46
}

Ghislain MARY's avatar
Ghislain MARY committed
47 48 49
void mediastreamer2_tester_init(void(*ftester_printf)(int level, const char *fmt, va_list args)) {
	if (ftester_printf == NULL) ftester_printf = log_handler;
	bc_tester_init(ftester_printf, ORTP_MESSAGE, ORTP_ERROR);
50

51 52 53 54
	bc_tester_add_suite(&basic_audio_test_suite);
	bc_tester_add_suite(&sound_card_test_suite);
	bc_tester_add_suite(&adaptive_test_suite);
	bc_tester_add_suite(&audio_stream_test_suite);
55
#ifdef VIDEO_ENABLED
56
	bc_tester_add_suite(&video_stream_test_suite);
57
#endif
58 59
	bc_tester_add_suite(&framework_test_suite);
	bc_tester_add_suite(&player_test_suite);
60
#ifdef __ARM_NEON__
61
	bc_tester_add_suite(&neon_test_suite);
62
#endif
63 64 65
}

void mediastreamer2_tester_uninit(void) {
66
	bc_tester_uninit();
Ghislain MARY's avatar
Ghislain MARY committed
67 68
}

69
static const char* mediastreamer2_helper =
70
		"\t\t\t--verbose\n"
71
		"\t\t\t--silent\n"
72
		"\t\t\t--log-file <output log file path>\n";
73

Ghislain MARY's avatar
Ghislain MARY committed
74

75
#if defined(_WIN32) && !defined(MS2_WINDOWS_DESKTOP)
76
#define BUILD_ENTRY_POINT 0
77 78
#else
#define BUILD_ENTRY_POINT 1
79 80 81
#endif

#if BUILD_ENTRY_POINT
82 83
#if TARGET_OS_MAC || TARGET_OS_IPHONE
int apple_main (int argc, char *argv[]) {
jehan's avatar
jehan committed
84
#else
Ghislain MARY's avatar
Ghislain MARY committed
85
int main (int argc, char *argv[]) {
jehan's avatar
jehan committed
86
#endif
Ghislain MARY's avatar
Ghislain MARY committed
87
	int i;
88
	int ret;
89

Ghislain MARY's avatar
Ghislain MARY committed
90
	mediastreamer2_tester_init(NULL);
91

92
	// this allows to launch liblinphone_tester from outside of tester directory
93
	if (strstr(argv[0], ".libs")) {
94 95 96 97
		char* prefix = ms_strdup_printf("%s%s", argv[0][0]=='/'?"":"./", strstr(argv[0], ".libs"));
		bc_tester_set_resource_dir_prefix(prefix);
		bc_tester_set_writable_dir_prefix(prefix);
		ms_free(prefix);
98 99
	}

Ghislain MARY's avatar
Ghislain MARY committed
100
	for(i = 1; i < argc; ++i) {
101
		if (strcmp(argv[i], "--verbose") == 0) {
102
			ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
103
		} else if (strcmp(argv[i], "--silent") == 0) {
104 105 106 107 108 109 110 111 112
			ortp_set_log_level_mask(ORTP_FATAL);
		} else if (strcmp(argv[i],"--log-file")==0){
			CHECK_ARG("--log-file", ++i, argc);
			log_file=fopen(argv[i],"w");
			if (!log_file) {
				ms_error("Cannot open file [%s] for writing logs because [%s]",argv[i],strerror(errno));
				return -2;
			} else {
				ms_message("Redirecting traces to file [%s]",argv[i]);
113
				ortp_set_log_file(log_file);
114 115 116
			}
		} else {
			int ret = bc_tester_parse_args(argc, argv, i);
117
			if (ret>0) {
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
118 119 120
				i += ret - 1;
				continue;
			} else if (ret<0) {
121
				bc_tester_helper(argv[0], mediastreamer2_helper);
122
			}
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
123
			return ret;
Ghislain MARY's avatar
Ghislain MARY committed
124
		}
125 126
	}

127
	ret = bc_tester_start();
128 129
	mediastreamer2_tester_uninit();
	return ret;
130

Ghislain MARY's avatar
Ghislain MARY committed
131 132
}
#endif