mediastreamer2_tester.c 4.15 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(ORTP_LOG_DOMAIN, lev, fmt, args);
44
	}
Ghislain MARY's avatar
Ghislain MARY committed
45 46
}

47
void mediastreamer2_tester_init(void(*ftester_printf)(int level, const char *fmt, va_list args)) {
Ghislain MARY's avatar
Ghislain MARY committed
48
	if (ftester_printf == NULL) ftester_printf = log_handler;
49
	bc_tester_init(ftester_printf, ORTP_MESSAGE, ORTP_ERROR, "sounds");
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
Sylvain Berfini's avatar
Sylvain Berfini committed
63
	bc_tester_add_suite(&text_stream_test_suite);
64 65 66
}

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

70 71 72 73 74 75 76 77 78 79 80 81 82 83
int mediastreamer2_tester_set_log_file(const char *filename) {
	if (log_file) {
		fclose(log_file);
	}
	log_file = fopen(filename, "w");
	if (!log_file) {
		ms_error("Cannot open file [%s] for writing logs because [%s]", filename, strerror(errno));
		return -1;
	}
	ms_message("Redirecting traces to file [%s]", filename);
	ortp_set_log_file(log_file);
	return 0;
}

84
static const char* mediastreamer2_helper =
85
		"\t\t\t--verbose\n"
86
		"\t\t\t--silent\n"
87
		"\t\t\t--log-file <output log file path>\n";
88

Ghislain MARY's avatar
Ghislain MARY committed
89

90
#if defined(_WIN32) && !defined(MS2_WINDOWS_DESKTOP)
91
#define BUILD_ENTRY_POINT 0
92 93
#else
#define BUILD_ENTRY_POINT 1
94 95 96
#endif

#if BUILD_ENTRY_POINT
97 98
#if TARGET_OS_MAC || TARGET_OS_IPHONE
int apple_main (int argc, char *argv[]) {
jehan's avatar
jehan committed
99
#else
Ghislain MARY's avatar
Ghislain MARY committed
100
int main (int argc, char *argv[]) {
jehan's avatar
jehan committed
101
#endif
Ghislain MARY's avatar
Ghislain MARY committed
102
	int i;
103
	int ret;
104

105
	mediastreamer2_tester_init(NULL);
106

107
	// this allows to launch tester from outside of tester directory
108
	if (strstr(argv[0], ".libs")) {
109 110 111
		int prefix_length = strstr(argv[0], ".libs") - argv[0] + 1;
		char *prefix = ms_strdup_printf("%s%.*s", argv[0][0] == '/' ? "" : "./", prefix_length, argv[0]);
		ms_warning("Resource prefix set to %s", prefix);
112 113 114
		bc_tester_set_resource_dir_prefix(prefix);
		bc_tester_set_writable_dir_prefix(prefix);
		ms_free(prefix);
115
	}
Ghislain MARY's avatar
Ghislain MARY committed
116
	for(i = 1; i < argc; ++i) {
117
		if (strcmp(argv[i], "--verbose") == 0) {
118
			ortp_set_log_level_mask(ORTP_LOG_DOMAIN, ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
119
		} else if (strcmp(argv[i], "--silent") == 0) {
120
			ortp_set_log_level_mask(ORTP_LOG_DOMAIN, ORTP_FATAL);
121 122
		} else if (strcmp(argv[i],"--log-file")==0){
			CHECK_ARG("--log-file", ++i, argc);
123
			if (mediastreamer2_tester_set_log_file(argv[i]) < 0) return -2;
124 125
		} else {
			int ret = bc_tester_parse_args(argc, argv, i);
126
			if (ret>0) {
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
127 128 129
				i += ret - 1;
				continue;
			} else if (ret<0) {
130
				bc_tester_helper(argv[0], mediastreamer2_helper);
131
			}
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
132
			return ret;
Ghislain MARY's avatar
Ghislain MARY committed
133
		}
134 135
	}

136
	ret = bc_tester_start(argv[0]);
137 138
	mediastreamer2_tester_uninit();
	return ret;
139

Ghislain MARY's avatar
Ghislain MARY committed
140 141
}
#endif