Tester: terminate factorizing common code

parent 42dde0eb
......@@ -41,3 +41,5 @@ tester/belle_sip_tester
tester/belle_http_get
tester/belle_sip_resolve
tester/CUnitAutomated-Results.xml
tester/download.tar.gz
tester/tmp_resolv.conf
......@@ -153,6 +153,7 @@ static BELLESIP_INLINE void BELLE_SIP_CHECK_FORMAT_ARGS(1,2) belle_sip_fatal(con
BELLESIP_EXPORT void belle_sip_set_log_file(FILE *file);
BELLESIP_EXPORT void belle_sip_set_log_handler(belle_sip_log_function_t func);
BELLESIP_EXPORT belle_sip_log_function_t belle_sip_get_log_handler();
BELLESIP_EXPORT char * BELLE_SIP_CHECK_FORMAT_ARGS(1,2) belle_sip_strdup_printf(const char *fmt,...);
......
......@@ -56,6 +56,9 @@ void belle_sip_set_log_handler(belle_sip_log_function_t func){
belle_sip_logv_out=func;
}
belle_sip_log_function_t belle_sip_get_log_handler(){
return belle_sip_logv_out;
}
unsigned int __belle_sip_log_mask=BELLE_SIP_LOG_WARNING|BELLE_SIP_LOG_ERROR|BELLE_SIP_LOG_FATAL;
......
......@@ -19,7 +19,7 @@ belle_sip_tester_SOURCES= \
belle_sip_uri_tester.c \
cast_test.c \
register_tester.h \
tester_utils.c tester_utils.h
common/tester_utils.c common/tester_utils.h
belle_sip_tester_CFLAGS=$(CUNIT_CFLAGS) $(STRICT_OPTIONS) $(STRICT_OPTIONS_CC) $(TLS_CFLAGS)
......
......@@ -20,6 +20,8 @@
#endif
#include "belle_sip_tester.h"
#include <belle-sip/utils.h>
#include <stdio.h>
#include "CUnit/Basic.h"
#include "CUnit/MyMem.h"
......@@ -35,6 +37,8 @@ extern const char *test_domain;
extern const char *auth_domain;
static const char *belle_sip_tester_root_ca_path = NULL;
static FILE * log_file = NULL;
static belle_sip_log_function_t belle_sip_log_handler;
static belle_sip_object_pool_t *pool;
......@@ -62,7 +66,20 @@ int belle_sip_tester_ipv6_available(void){
return ipv6_available;
}
static void log_handler(belle_sip_log_level lev, const char *fmt, va_list args) {
belle_sip_set_log_file(stderr);
belle_sip_log_handler(lev, fmt, args);
if (log_file){
belle_sip_set_log_file(log_file);
belle_sip_log_handler(lev, fmt, args);
}
}
void belle_sip_tester_init() {
belle_sip_log_handler = belle_sip_get_log_handler();
belle_sip_set_log_handler(log_handler);
tester_init();
belle_sip_init_sockets();
belle_sip_object_enable_marshal_check(TRUE);
ipv6_available=_belle_sip_tester_ipv6_available();
......@@ -98,6 +115,7 @@ void belle_sip_tester_uninit(void) {
static const char* belle_sip_helper =
"\t\t\t--verbose\n"
"\t\t\t--silent\n"
"\t\t\t--log-file <output log file path>\n"
"\t\t\t--domain <test sip domain>\n"
"\t\t\t--auth-domain <test auth domain>\n"
"\t\t\t--root-ca <root ca file path>\n";
......@@ -111,14 +129,24 @@ int main (int argc, char *argv[]) {
belle_sip_tester_init();
if (env_domain)
if (env_domain) {
test_domain=env_domain;
}
for(i=1;i<argc;++i){
if (strcmp(argv[i],"--verbose")==0){
belle_sip_set_log_level(BELLE_SIP_LOG_DEBUG);
} else if (strcmp(argv[i],"--silent")==0){
belle_sip_set_log_level(BELLE_SIP_LOG_FATAL);
} else if (strcmp(argv[i],"--log-file")==0){
CHECK_ARG("--log-file", ++i, argc);
log_file=fopen(argv[i],"w");
if (!log_file) {
tester_fprintf(stderr, "Cannot open file [%s] for writing logs because [%s]",argv[i],strerror(errno));
return -2;
} else {
tester_fprintf(stdout,"Redirecting traces to file [%s]",argv[i]);
}
} else if (strcmp(argv[i],"--domain")==0){
CHECK_ARG("--domain", ++i, argc);
test_domain=argv[i];
......@@ -129,9 +157,13 @@ int main (int argc, char *argv[]) {
CHECK_ARG("--root-ca", ++i, argc);
root_ca_path = argv[i];
}else {
int ret = tester_parse_args(argc, argv, i, belle_sip_helper);
if (ret>0) i += ret;
else return ret;
int ret = tester_parse_args(argc, argv, i);
if (ret>0) {
i += ret;
} else {
tester_helper(argv[0], belle_sip_helper);
return ret;
}
}
}
belle_sip_tester_set_root_ca_path(root_ca_path);
......
......@@ -20,7 +20,7 @@
#define _BELLE_SIP_TESTER_H
#include "tester_utils.h"
#include "common/tester_utils.h"
#ifdef __cplusplus
......
# Copyright (C) 2012 Belledonne Comunications, Grenoble, France
#
# 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.
# Created by Gautier Pelloux-Prayer on 2014/10/24.
# This script adds auto-completion for liblinphone_tester binary for Bash and
# zsh. To use it, just type: `source liblinphone_completion`, then use
# `./liblinphone_tester [tab] to get auto-completions. To use it permanently,
# source this file in your .rc file
_liblinphone_complete() {
local completions command_requiring_argument prev_arg latest_arg available_tasks has_not_set_suite suite_name
if [ -n "$BASH_VERSION" ]; then
set -- "${COMP_WORDS[@]}" #convert them to arguments (eg $1,$#,$@,etc.)
elif [ -n "$ZSH_VERSION" ]; then
local args
read -cA args #read list of arguments user entered
set -- "${args[@]}" #convert them to arguments (eg $1,$#,$@,etc.)
fi
#skip program name
program=$1
shift
# if user required help, do not complete anything
if ! grep -q -- "--help" <<< "$@"; then
# retrieve the last argument
latest_arg=""
prev_arg=""
latest_is_empty=0
for arg in "$@"; do
if [ ! -z "$arg" ]; then
prev_arg="$latest_arg"
latest_arg="$arg"
else
latest_is_empty=1
fi
done
# get the tasks available, from --help
available_tasks="$($program 2>&1 --help | sed -nE "s/.*--([^ ]*).*/--\\1/p")"
# these commands expect an argument
command_requiring_argument="$($program 2>&1 --help | sed -nE "s/.*--(.*) <.*/--\\1/p")"
# remove all already provided tasks (it's useless to provide them twice)
if [[ ! -z "$@" ]]; then
current_tasks=$(echo $@ | grep -Eo -- "--([^ ])*" | tr '\n' '|' | sed 's/|/$|/g')--$
if [ ! -z "$current_tasks" ]; then
available_tasks=$(echo "$available_tasks" | grep -vE -- "(${current_tasks})")
fi
fi
# remove --test option if --suite is not provided yet!
has_not_set_suite=$(grep -q -- "--suite" <<< "$@"; echo $?)
if [ $has_not_set_suite = 1 ]; then
available_tasks=$(echo "$available_tasks" | grep -v -- --test)
fi
# if latest arg does not start with '--', it is a custom value
if [ $latest_is_empty = 0 ] && ! grep -q -- '^--' <<< "$latest_arg"; then
# echo "yes!$prev_arg $has_not_set_suite"
if [ "$prev_arg" = "--test" ] && [ $has_not_set_suite = 0 ]; then
suite_name=$(echo $@ | sed -nE 's/.*--suite (.*) (--.*)$/\1/p' |sed "s@\\\\@@g")
completions="$($program --list-tests $suite_name)"
elif [ "$prev_arg" = "--suite" ] || [ "$prev_arg" = "--list-tests" ]; then
completions="$($program --list-suites)"
fi
elif [ "$latest_arg" = "--test" ]; then
if [ $has_not_set_suite = 0 ]; then
suite_name=$(echo $@ | sed -nE 's/.*--suite (.*) (--.*)$/\1/p' |sed "s@\\\\@@g")
completions="$($program --list-tests $suite_name)"
fi
elif [ "$latest_arg" = "--suite" ] || [ "$latest_arg" = "--list-tests" ]; then
completions="$($program --list-suites)"
# we are waiting for a custom value, so do not hint anything
elif [[ ! -z "$latest_arg" ]] && grep -q -- "^$latest_arg$" <<< "$command_requiring_argument"; then
completions=""
else
completions="$available_tasks"
fi
fi
if [ ! -z "$completions" ]; then
if [ -n "$BASH_VERSION" ]; then
IFS=$'\n' #if that even necessary?
COMPREPLY=($(compgen -W "${completions}" -- ${COMP_WORDS[COMP_CWORD]}))
elif [ -n "$ZSH_VERSION" ]; then
reply=( "${(ps:\n:)completions}" )
fi
fi
}
for tester in liblinphone_tester mediastreamer2_tester belle_sip_tester; do
if [ -n "$BASH_VERSION" ]; then
complete -F _liblinphone_complete $tester
elif [ -n "$ZSH_VERSION" ]; then
compctl -K _liblinphone_complete $tester
else
echo "Your shell might be not supported! Only bash and zsh tested."
fi
done
/home/gpelloux/code/desktop/belle-sip/tester/../../linphone-debian/tester/tester_utils.c
\ No newline at end of file
/home/gpelloux/code/desktop/belle-sip/tester/../../linphone-debian/tester/tester_utils.h
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment