FS-11453 [core] remove dependency to libtap for unit tests
move all core unit tests to tests/unit
This commit is contained in:
parent
e604dd15a3
commit
0c8f5ed60d
|
@ -1998,7 +1998,6 @@ AC_CONFIG_FILES([Makefile
|
||||||
libs/xmlrpc-c/config.mk
|
libs/xmlrpc-c/config.mk
|
||||||
libs/xmlrpc-c/srcdir.mk
|
libs/xmlrpc-c/srcdir.mk
|
||||||
libs/xmlrpc-c/stamp-h
|
libs/xmlrpc-c/stamp-h
|
||||||
tests/fst/Makefile
|
|
||||||
scripts/gentls_cert])
|
scripts/gentls_cert])
|
||||||
|
|
||||||
AM_CONDITIONAL(ISLINUX, [test `uname -s` = Linux])
|
AM_CONDITIONAL(ISLINUX, [test `uname -s` = Linux])
|
||||||
|
|
|
@ -66,7 +66,7 @@ static char *fst_getenv_default(const char *env, char *default_value, switch_boo
|
||||||
/**
|
/**
|
||||||
* initialize FS core from optional configuration dir
|
* initialize FS core from optional configuration dir
|
||||||
*/
|
*/
|
||||||
static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
static void fst_init_core_and_modload(const char *confdir, const char *basedir, int minimal)
|
||||||
{
|
{
|
||||||
const char *err;
|
const char *err;
|
||||||
// Let FreeSWITCH core pick these
|
// Let FreeSWITCH core pick these
|
||||||
|
@ -101,9 +101,13 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
SWITCH_GLOBAL_dirs.data_dir = switch_mprintf("%s%s", basedir, SWITCH_PATH_SEPARATOR);
|
SWITCH_GLOBAL_dirs.data_dir = switch_mprintf("%s%s", basedir, SWITCH_PATH_SEPARATOR);
|
||||||
SWITCH_GLOBAL_dirs.localstate_dir = switch_mprintf("%s%s", basedir, SWITCH_PATH_SEPARATOR);
|
SWITCH_GLOBAL_dirs.localstate_dir = switch_mprintf("%s%s", basedir, SWITCH_PATH_SEPARATOR);
|
||||||
|
|
||||||
|
if (!minimal) {
|
||||||
switch_core_init_and_modload(0, SWITCH_TRUE, &err);
|
switch_core_init_and_modload(0, SWITCH_TRUE, &err);
|
||||||
switch_sleep(1 * 1000000);
|
switch_sleep(1 * 1000000);
|
||||||
switch_core_set_variable("sound_prefix", "." SWITCH_PATH_SEPARATOR);
|
switch_core_set_variable("sound_prefix", "." SWITCH_PATH_SEPARATOR);
|
||||||
|
} else {
|
||||||
|
switch_core_init(SCF_MINIMAL, SWITCH_TRUE, &err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -150,6 +154,18 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
#define fst_time_mark() \
|
#define fst_time_mark() \
|
||||||
fst_time_start = switch_time_now();
|
fst_time_start = switch_time_now();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check a test /w error message
|
||||||
|
*/
|
||||||
|
#define fst_xcheck(expr, error_msg) \
|
||||||
|
fct_xchk(expr, error_msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fail a test
|
||||||
|
*/
|
||||||
|
#define fst_fail(error_msg) \
|
||||||
|
fct_xchk(0, error_msg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check duration relative to test start, last marked time, or last check.
|
* Check duration relative to test start, last marked time, or last check.
|
||||||
*/
|
*/
|
||||||
|
@ -201,7 +217,7 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
switch_memory_pool_t *fst_pool = NULL; \
|
switch_memory_pool_t *fst_pool = NULL; \
|
||||||
fst_getenv_default("FST_SUPPRESS_UNUSED_STATIC_WARNING", NULL, SWITCH_FALSE); \
|
fst_getenv_default("FST_SUPPRESS_UNUSED_STATIC_WARNING", NULL, SWITCH_FALSE); \
|
||||||
if (fst_core) { \
|
if (fst_core) { \
|
||||||
fst_init_core_and_modload(NULL, NULL); /* shuts up compiler */ \
|
fst_init_core_and_modload(NULL, NULL, 0); /* shuts up compiler */ \
|
||||||
} \
|
} \
|
||||||
{ \
|
{ \
|
||||||
|
|
||||||
|
@ -222,14 +238,15 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
#define FST_CORE_BEGIN(confdir) \
|
#define FST_CORE_BEGIN(confdir) \
|
||||||
FCT_BGN() \
|
FCT_BGN() \
|
||||||
{ \
|
{ \
|
||||||
int fst_core = 1; \
|
int fst_core = 2; \
|
||||||
switch_time_t fst_time_start = 0; \
|
switch_time_t fst_time_start = 0; \
|
||||||
switch_timer_t fst_timer = { 0 }; \
|
switch_timer_t fst_timer = { 0 }; \
|
||||||
switch_memory_pool_t *fst_pool = NULL; \
|
switch_memory_pool_t *fst_pool = NULL; \
|
||||||
fst_getenv_default("FST_SUPPRESS_UNUSED_STATIC_WARNING", NULL, SWITCH_FALSE); \
|
fst_getenv_default("FST_SUPPRESS_UNUSED_STATIC_WARNING", NULL, SWITCH_FALSE); \
|
||||||
fst_init_core_and_modload(confdir, NULL); \
|
fst_init_core_and_modload(confdir, NULL, 0); \
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the end of a freeswitch core test driver.
|
* Define the end of a freeswitch core test driver.
|
||||||
*/
|
*/
|
||||||
|
@ -243,6 +260,21 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
} \
|
} \
|
||||||
FCT_END()
|
FCT_END()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimal FS core load
|
||||||
|
*/
|
||||||
|
#define FST_MINCORE_BEGIN() \
|
||||||
|
FCT_BGN() \
|
||||||
|
{ \
|
||||||
|
int fst_core = 1; \
|
||||||
|
switch_time_t fst_time_start = 0; \
|
||||||
|
switch_timer_t fst_timer = { 0 }; \
|
||||||
|
switch_memory_pool_t *fst_pool = NULL; \
|
||||||
|
fst_getenv_default("FST_SUPPRESS_UNUSED_STATIC_WARNING", NULL, SWITCH_FALSE); \
|
||||||
|
fst_init_core_and_modload(".", NULL, 1); /* minimal load */ \
|
||||||
|
{
|
||||||
|
|
||||||
|
#define FST_MINCORE_END FST_CORE_END
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the beginning of a FreeSWITCH module test suite. Loads the module for test.
|
* Define the beginning of a FreeSWITCH module test suite. Loads the module for test.
|
||||||
|
@ -252,8 +284,7 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
#define FST_MODULE_BEGIN(modname,suite) \
|
#define FST_MODULE_BEGIN(modname,suite) \
|
||||||
{ \
|
{ \
|
||||||
const char *fst_test_module = #modname; \
|
const char *fst_test_module = #modname; \
|
||||||
fst_requires(fst_core); \
|
if (fst_core && !zstr(fst_test_module)) { \
|
||||||
if (!zstr(fst_test_module)) { \
|
|
||||||
const char *err; \
|
const char *err; \
|
||||||
switch_loadable_module_load_module((char *)"../.libs", (char *)fst_test_module, SWITCH_FALSE, &err); \
|
switch_loadable_module_load_module((char *)"../.libs", (char *)fst_test_module, SWITCH_FALSE, &err); \
|
||||||
} \
|
} \
|
||||||
|
@ -293,7 +324,9 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
if (fst_core) { \
|
if (fst_core) { \
|
||||||
switch_core_new_memory_pool(&fst_pool); \
|
switch_core_new_memory_pool(&fst_pool); \
|
||||||
fst_requires(fst_pool != NULL); \
|
fst_requires(fst_pool != NULL); \
|
||||||
|
if (fst_core > 1) { \
|
||||||
fst_requires(switch_core_timer_init(&fst_timer, "soft", 20, 160, fst_pool) == SWITCH_STATUS_SUCCESS); \
|
fst_requires(switch_core_timer_init(&fst_timer, "soft", 20, 160, fst_pool) == SWITCH_STATUS_SUCCESS); \
|
||||||
|
} \
|
||||||
fst_time_mark(); \
|
fst_time_mark(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,7 +343,9 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
FCT_TEARDOWN_BGN() \
|
FCT_TEARDOWN_BGN() \
|
||||||
if (fst_core) { \
|
if (fst_core) { \
|
||||||
switch_core_destroy_memory_pool(&fst_pool); \
|
switch_core_destroy_memory_pool(&fst_pool); \
|
||||||
|
if (fst_core > 1) { \
|
||||||
switch_core_timer_destroy(&fst_timer); \
|
switch_core_timer_destroy(&fst_timer); \
|
||||||
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -423,7 +458,7 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
char *fst_asr_result = NULL; \
|
char *fst_asr_result = NULL; \
|
||||||
switch_asr_handle_t ah = { 0 }; \
|
switch_asr_handle_t ah = { 0 }; \
|
||||||
switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE; \
|
switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE; \
|
||||||
fst_requires(fst_core); \
|
fst_requires(fst_core > 1); \
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Open recognizer: %s\n", recognizer); \
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Open recognizer: %s\n", recognizer); \
|
||||||
/* open ASR interface and feed recorded audio into it and collect result */ \
|
/* open ASR interface and feed recorded audio into it and collect result */ \
|
||||||
fst_requires(switch_core_asr_open(&ah, recognizer, "L16", 8000, "", &flags, fst_pool) == SWITCH_STATUS_SUCCESS); \
|
fst_requires(switch_core_asr_open(&ah, recognizer, "L16", 8000, "", &flags, fst_pool) == SWITCH_STATUS_SUCCESS); \
|
||||||
|
@ -456,7 +491,7 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
fst_asr_result = NULL; \
|
fst_asr_result = NULL; \
|
||||||
file_handle.channels = 1; \
|
file_handle.channels = 1; \
|
||||||
file_handle.native_rate = 8000; \
|
file_handle.native_rate = 8000; \
|
||||||
fst_requires(fst_core); \
|
fst_requires(fst_core > 1); \
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Test recognizer: input = %s\n", input_filename); \
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Test recognizer: input = %s\n", input_filename); \
|
||||||
fst_requires(switch_core_asr_load_grammar(&ah, grammar, "") == SWITCH_STATUS_SUCCESS); \
|
fst_requires(switch_core_asr_load_grammar(&ah, grammar, "") == SWITCH_STATUS_SUCCESS); \
|
||||||
fst_requires(switch_core_file_open(&file_handle, input_filename, file_handle.channels, 8000, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) == SWITCH_STATUS_SUCCESS); \
|
fst_requires(switch_core_file_open(&file_handle, input_filename, file_handle.channels, 8000, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) == SWITCH_STATUS_SUCCESS); \
|
||||||
|
@ -499,7 +534,7 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
* switch_core_asr_pause(&ah) == SWITCH_STATUS_SUCCESS
|
* switch_core_asr_pause(&ah) == SWITCH_STATUS_SUCCESS
|
||||||
*/
|
*/
|
||||||
#define fst_test_core_asr_pause() \
|
#define fst_test_core_asr_pause() \
|
||||||
fst_requires(fst_core); \
|
fst_requires(fst_core > 1); \
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Pause recognizer\n"); \
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Pause recognizer\n"); \
|
||||||
flags = SWITCH_ASR_FLAG_NONE; \
|
flags = SWITCH_ASR_FLAG_NONE; \
|
||||||
fst_requires(switch_core_asr_pause(&ah) == SWITCH_STATUS_SUCCESS);
|
fst_requires(switch_core_asr_pause(&ah) == SWITCH_STATUS_SUCCESS);
|
||||||
|
@ -511,7 +546,7 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
* switch_core_asr_resume(&ah) == SWITCH_STATUS_SUCCESS
|
* switch_core_asr_resume(&ah) == SWITCH_STATUS_SUCCESS
|
||||||
*/
|
*/
|
||||||
#define fst_test_core_asr_resume() \
|
#define fst_test_core_asr_resume() \
|
||||||
fst_requires(fst_core); \
|
fst_requires(fst_core > 1); \
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Resume recognizer\n"); \
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Resume recognizer\n"); \
|
||||||
flags = SWITCH_ASR_FLAG_NONE; \
|
flags = SWITCH_ASR_FLAG_NONE; \
|
||||||
fst_requires(switch_core_asr_resume(&ah) == SWITCH_STATUS_SUCCESS);
|
fst_requires(switch_core_asr_resume(&ah) == SWITCH_STATUS_SUCCESS);
|
||||||
|
@ -523,7 +558,7 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
* switch_core_asr_close(&ah, flags) == SWITCH_STATUS_SUCCESS
|
* switch_core_asr_close(&ah, flags) == SWITCH_STATUS_SUCCESS
|
||||||
*/
|
*/
|
||||||
#define fst_test_core_asr_close() \
|
#define fst_test_core_asr_close() \
|
||||||
fst_requires(fst_core); \
|
fst_requires(fst_core > 1); \
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Close recognizer\n"); \
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Close recognizer\n"); \
|
||||||
flags = SWITCH_ASR_FLAG_NONE; \
|
flags = SWITCH_ASR_FLAG_NONE; \
|
||||||
fst_requires(switch_core_asr_close(&ah, &flags) == SWITCH_STATUS_SUCCESS); \
|
fst_requires(switch_core_asr_close(&ah, &flags) == SWITCH_STATUS_SUCCESS); \
|
||||||
|
@ -542,7 +577,7 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
#define fst_play_and_detect_speech_test_begin() \
|
#define fst_play_and_detect_speech_test_begin() \
|
||||||
{ \
|
{ \
|
||||||
const char *fst_asr_result = NULL; \
|
const char *fst_asr_result = NULL; \
|
||||||
fst_requires(fst_core);
|
fst_requires(fst_core > 1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use play_and_detect_speech APP to test recognizer
|
* Use play_and_detect_speech APP to test recognizer
|
||||||
|
@ -566,7 +601,7 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
#define fst_play_and_detect_speech_app_test(recognizer, grammar, prompt_filename, input_filename) \
|
#define fst_play_and_detect_speech_app_test(recognizer, grammar, prompt_filename, input_filename) \
|
||||||
{ \
|
{ \
|
||||||
char *args = NULL; \
|
char *args = NULL; \
|
||||||
fst_requires(fst_core); \
|
fst_requires(fst_core > 1); \
|
||||||
fst_requires_module("mod_dptools"); \
|
fst_requires_module("mod_dptools"); \
|
||||||
switch_channel_set_variable(fst_channel, "detect_speech_result", ""); \
|
switch_channel_set_variable(fst_channel, "detect_speech_result", ""); \
|
||||||
fst_requires(switch_ivr_displace_session(fst_session, input_filename, 0, "mr") == SWITCH_STATUS_SUCCESS); \
|
fst_requires(switch_ivr_displace_session(fst_session, input_filename, 0, "mr") == SWITCH_STATUS_SUCCESS); \
|
||||||
|
@ -598,7 +633,7 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
{ \
|
{ \
|
||||||
char *args = NULL; \
|
char *args = NULL; \
|
||||||
fst_asr_result = NULL; \
|
fst_asr_result = NULL; \
|
||||||
fst_requires(fst_core); \
|
fst_requires(fst_core > 1); \
|
||||||
fst_requires(switch_ivr_displace_session(fst_session, input_filename, 0, "mr") == SWITCH_STATUS_SUCCESS); \
|
fst_requires(switch_ivr_displace_session(fst_session, input_filename, 0, "mr") == SWITCH_STATUS_SUCCESS); \
|
||||||
switch_status_t status = switch_ivr_play_and_detect_speech(fst_session, prompt_filename, recognizer, grammar, (char **)&fst_asr_result, 0, input_args); \
|
switch_status_t status = switch_ivr_play_and_detect_speech(fst_session, prompt_filename, recognizer, grammar, (char **)&fst_asr_result, 0, input_args); \
|
||||||
fst_check(fst_asr_result != NULL); \
|
fst_check(fst_asr_result != NULL); \
|
||||||
|
@ -624,7 +659,7 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir)
|
||||||
{ \
|
{ \
|
||||||
switch_stream_handle_t stream = { 0 }; \
|
switch_stream_handle_t stream = { 0 }; \
|
||||||
SWITCH_STANDARD_STREAM(stream); \
|
SWITCH_STANDARD_STREAM(stream); \
|
||||||
fst_requires(fst_core); \
|
fst_requires(fst_core > 1); \
|
||||||
fst_requires_module("mod_commands"); \
|
fst_requires_module("mod_commands"); \
|
||||||
switch_status_t api_result = switch_api_execute("sched_api", switch_core_session_sprintf(fst_session, "%s none uuid_recv_dtmf %s %s", when, switch_core_session_get_uuid(fst_session), digits), NULL, &stream); \
|
switch_status_t api_result = switch_api_execute("sched_api", switch_core_session_sprintf(fst_session, "%s none uuid_recv_dtmf %s %s", when, switch_core_session_get_uuid(fst_session), digits), NULL, &stream); \
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fst_session), SWITCH_LOG_INFO, "Injecting DTMF %s at %s\n", digits, when); \
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fst_session), SWITCH_LOG_INFO, "Injecting DTMF %s at %s\n", digits, when); \
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
Makefile
|
|
||||||
Makefile.in
|
|
||||||
freeswitch.xml.fsxml
|
|
||||||
originate_test
|
|
|
@ -1,8 +0,0 @@
|
||||||
include $(top_srcdir)/build/modmake.rulesam
|
|
||||||
|
|
||||||
bin_PROGRAMS = originate_test
|
|
||||||
AM_LDFLAGS = -avoid-version -no-undefined $(SWITCH_AM_LDFLAGS) $(openssl_LIBS) $(FREESWITCH_LIBS) $(switch_builddir)/libfreeswitch.la $(CORE_LIBS) $(APR_LIBS)
|
|
||||||
AM_CFLAGS = $(SWITCH_AM_CPPFLAGS)
|
|
||||||
AM_CPPFLAGS = $(SWITCH_AM_CPPFLAGS)
|
|
||||||
|
|
||||||
TESTS = $(bin_PROGRAMS)
|
|
|
@ -3,29 +3,6 @@ benchmarks testing functionality exposed through libfreeswitch.
|
||||||
|
|
||||||
Requirements for a new unit tests:
|
Requirements for a new unit tests:
|
||||||
|
|
||||||
1. Tests must use TAP(Test Anything Protocol) output format, and must
|
1. Tests must use switch_test.h framework
|
||||||
print to stderr the summary statistics of the test before exiting.
|
|
||||||
|
|
||||||
2. Each test must return 0 on successful completion, or a non-zero
|
|
||||||
result in case of a failure.
|
|
||||||
|
|
||||||
3. Benchmarking stats should be output as a TAP note at the end of the
|
|
||||||
test in a human and machine(regex) parsable format
|
|
||||||
|
|
||||||
Use libtap from https://github.com/zorgnax/libtap
|
|
||||||
cd /usr/local/src/
|
|
||||||
git clone https://github.com/zorgnax/libtap.git
|
|
||||||
make PREFIX=/usr install
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
To run a benchmark version of a unit test, update the loops count, and
|
|
||||||
make sure to uncomment the 'BENCHMARK' define line. Then you can run
|
|
||||||
the benchmark with:
|
|
||||||
|
|
||||||
perf record ./.libs/switch_hash
|
|
||||||
|
|
||||||
Once that is completed you can view the results with:
|
|
||||||
|
|
||||||
perf report
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,25 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include <tap.h>
|
#include <test/switch_test.h>
|
||||||
|
|
||||||
// #define BENCHMARK 1
|
// #define BENCHMARK 1
|
||||||
|
|
||||||
int main () {
|
FST_MINCORE_BEGIN()
|
||||||
|
|
||||||
|
FST_SUITE_BEGIN(switch_event)
|
||||||
|
|
||||||
|
FST_SETUP_BEGIN()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
FST_SETUP_END()
|
||||||
|
|
||||||
|
FST_TEARDOWN_BEGIN()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
FST_TEARDOWN_END()
|
||||||
|
|
||||||
|
FST_TEST_BEGIN(benchmark)
|
||||||
|
{
|
||||||
switch_event_t *event = NULL;
|
switch_event_t *event = NULL;
|
||||||
switch_bool_t verbose = SWITCH_TRUE;
|
switch_bool_t verbose = SWITCH_TRUE;
|
||||||
const char *err = NULL;
|
const char *err = NULL;
|
||||||
|
@ -18,18 +33,8 @@ int main () {
|
||||||
|
|
||||||
#ifdef BENCHMARK
|
#ifdef BENCHMARK
|
||||||
switch_time_t small_start_ts, small_end_ts;
|
switch_time_t small_start_ts, small_end_ts;
|
||||||
|
|
||||||
plan(2);
|
|
||||||
#else
|
|
||||||
plan(2 + ( 2 * loops));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
status = switch_core_init(SCF_MINIMAL, verbose, &err);
|
|
||||||
|
|
||||||
if ( !ok( status == SWITCH_STATUS_SUCCESS, "Initialize FreeSWITCH core\n")) {
|
|
||||||
bail_out(0, "Bail due to failure to initialize FreeSWITCH[%s]", err);
|
|
||||||
}
|
|
||||||
|
|
||||||
index = calloc(loops, sizeof(char *));
|
index = calloc(loops, sizeof(char *));
|
||||||
for ( x = 0; x < loops; x++) {
|
for ( x = 0; x < loops; x++) {
|
||||||
index[x] = switch_mprintf("%d", x);
|
index[x] = switch_mprintf("%d", x);
|
||||||
|
@ -39,18 +44,18 @@ int main () {
|
||||||
start_ts = switch_time_now();
|
start_ts = switch_time_now();
|
||||||
|
|
||||||
status = switch_event_create(&event, SWITCH_EVENT_MESSAGE);
|
status = switch_event_create(&event, SWITCH_EVENT_MESSAGE);
|
||||||
ok( status == SWITCH_STATUS_SUCCESS,"Create Event");
|
fst_xcheck(status == SWITCH_STATUS_SUCCESS, "Failed to create event");
|
||||||
|
|
||||||
#ifndef BENCHMARK
|
#ifndef BENCHMARK
|
||||||
for ( x = 0; x < loops; x++) {
|
for ( x = 0; x < loops; x++) {
|
||||||
status = switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, index[x], index[x]);
|
status = switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, index[x], index[x]);
|
||||||
ok( status == SWITCH_STATUS_SUCCESS,"Add header to event");
|
fst_xcheck(status == SWITCH_STATUS_SUCCESS, "Failed to add header to event");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
small_start_ts = switch_time_now();
|
small_start_ts = switch_time_now();
|
||||||
for ( x = 0; x < loops; x++) {
|
for ( x = 0; x < loops; x++) {
|
||||||
if ( switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, index[x], index[x]) != SWITCH_STATUS_SUCCESS) {
|
if ( switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, index[x], index[x]) != SWITCH_STATUS_SUCCESS) {
|
||||||
fail("Failed to add header to event");
|
fst_fail("Failed to add header to event");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
small_end_ts = switch_time_now();
|
small_end_ts = switch_time_now();
|
||||||
|
@ -58,20 +63,20 @@ int main () {
|
||||||
micro_total = small_end_ts - small_start_ts;
|
micro_total = small_end_ts - small_start_ts;
|
||||||
micro_per = micro_total / (double) loops;
|
micro_per = micro_total / (double) loops;
|
||||||
rate_per_sec = 1000000 / micro_per;
|
rate_per_sec = 1000000 / micro_per;
|
||||||
note("switch_event add_header: Total %ldus / %ld loops, %.2f us per loop, %.0f loops per second\n",
|
printf("switch_event add_header: Total %ldus / %ld loops, %.2f us per loop, %.0f loops per second\n",
|
||||||
micro_total, loops, micro_per, rate_per_sec);
|
micro_total, loops, micro_per, rate_per_sec);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef BENCHMARK
|
#ifndef BENCHMARK
|
||||||
for ( x = 0; x < loops; x++) {
|
for ( x = 0; x < loops; x++) {
|
||||||
is(switch_event_get_header(event, index[x]), index[x], "correct header value returned");
|
fst_check_string_equals(switch_event_get_header(event, index[x]), index[x]);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
small_start_ts = switch_time_now();
|
small_start_ts = switch_time_now();
|
||||||
for ( x = 0; x < loops; x++) {
|
for ( x = 0; x < loops; x++) {
|
||||||
if ( !switch_event_get_header(event, index[x])) {
|
if ( !switch_event_get_header(event, index[x])) {
|
||||||
fail("Failed to lookup event header value");
|
fst_fail("Failed to lookup event header value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
small_end_ts = switch_time_now();
|
small_end_ts = switch_time_now();
|
||||||
|
@ -79,11 +84,10 @@ int main () {
|
||||||
micro_total = small_end_ts - small_start_ts;
|
micro_total = small_end_ts - small_start_ts;
|
||||||
micro_per = micro_total / (double) loops;
|
micro_per = micro_total / (double) loops;
|
||||||
rate_per_sec = 1000000 / micro_per;
|
rate_per_sec = 1000000 / micro_per;
|
||||||
note("switch_event get_header: Total %ldus / %ld loops, %.2f us per loop, %.0f loops per second\n",
|
printf("switch_event get_header: Total %ldus / %ld loops, %.2f us per loop, %.0f loops per second\n",
|
||||||
micro_total, loops, micro_per, rate_per_sec);
|
micro_total, loops, micro_per, rate_per_sec);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
switch_event_destroy(&event);
|
switch_event_destroy(&event);
|
||||||
/* END LOOPS */
|
/* END LOOPS */
|
||||||
|
|
||||||
|
@ -97,10 +101,15 @@ int main () {
|
||||||
micro_total = end_ts - start_ts;
|
micro_total = end_ts - start_ts;
|
||||||
micro_per = micro_total / (double) loops;
|
micro_per = micro_total / (double) loops;
|
||||||
rate_per_sec = 1000000 / micro_per;
|
rate_per_sec = 1000000 / micro_per;
|
||||||
diag("switch_event Total %ldus / %d loops, %.2f us per loop, %.0f loops per second\n",
|
printf("switch_event Total %ldus / %d loops, %.2f us per loop, %.0f loops per second\n",
|
||||||
micro_total, loops, micro_per, rate_per_sec);
|
micro_total, loops, micro_per, rate_per_sec);
|
||||||
|
|
||||||
switch_core_destroy();
|
|
||||||
|
|
||||||
done_testing();
|
|
||||||
}
|
}
|
||||||
|
FST_TEST_END()
|
||||||
|
|
||||||
|
FST_SUITE_END()
|
||||||
|
|
||||||
|
FST_MINCORE_END()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,25 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include <tap.h>
|
#include <test/switch_test.h>
|
||||||
|
|
||||||
// #define BENCHMARK 1
|
// #define BENCHMARK 1
|
||||||
|
|
||||||
int main () {
|
FST_MINCORE_BEGIN()
|
||||||
|
|
||||||
|
FST_SUITE_BEGIN(switch_hash)
|
||||||
|
|
||||||
|
FST_SETUP_BEGIN()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
FST_SETUP_END()
|
||||||
|
|
||||||
|
FST_TEARDOWN_BEGIN()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
FST_TEARDOWN_END()
|
||||||
|
|
||||||
|
FST_TEST_BEGIN(benchmark)
|
||||||
|
{
|
||||||
switch_event_t *event = NULL;
|
switch_event_t *event = NULL;
|
||||||
switch_bool_t verbose = SWITCH_TRUE;
|
switch_bool_t verbose = SWITCH_TRUE;
|
||||||
const char *err = NULL;
|
const char *err = NULL;
|
||||||
|
@ -24,23 +38,7 @@ int main () {
|
||||||
char **index = NULL;
|
char **index = NULL;
|
||||||
switch_hash_t *hash = NULL;
|
switch_hash_t *hash = NULL;
|
||||||
|
|
||||||
#ifndef BENCHMARK
|
fst_requires(switch_core_hash_init(&hash) == SWITCH_STATUS_SUCCESS);
|
||||||
plan(2 + ( 5 * loops));
|
|
||||||
#else
|
|
||||||
plan(2);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
status = switch_core_init(SCF_MINIMAL, verbose, &err);
|
|
||||||
|
|
||||||
if ( !ok( status == SWITCH_STATUS_SUCCESS, "Initialize FreeSWITCH core\n")) {
|
|
||||||
bail_out(0, "Bail due to failure to initialize FreeSWITCH[%s]", err);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = switch_core_hash_init(&hash);
|
|
||||||
|
|
||||||
if ( !ok(status == SWITCH_STATUS_SUCCESS, "Create a new hash")) {
|
|
||||||
bail_out(0, "Bail due to failure to create hash");
|
|
||||||
}
|
|
||||||
|
|
||||||
index = calloc(loops, sizeof(char *));
|
index = calloc(loops, sizeof(char *));
|
||||||
for ( x = 0; x < loops; x++) {
|
for ( x = 0; x < loops; x++) {
|
||||||
|
@ -54,7 +52,7 @@ int main () {
|
||||||
#ifndef BENCHMARK
|
#ifndef BENCHMARK
|
||||||
for ( x = 0; x < loops; x++) {
|
for ( x = 0; x < loops; x++) {
|
||||||
status = switch_core_hash_insert(hash, index[x], (void *) index[x]);
|
status = switch_core_hash_insert(hash, index[x], (void *) index[x]);
|
||||||
ok(status == SWITCH_STATUS_SUCCESS, "Insert into the hash");
|
fst_xcheck(status == SWITCH_STATUS_SUCCESS, "Failed to insert into the hash");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
small_start_ts = switch_time_now();
|
small_start_ts = switch_time_now();
|
||||||
|
@ -66,7 +64,7 @@ int main () {
|
||||||
micro_total = small_end_ts - small_start_ts;
|
micro_total = small_end_ts - small_start_ts;
|
||||||
micro_per = micro_total / (double) loops;
|
micro_per = micro_total / (double) loops;
|
||||||
rate_per_sec = 1000000 / micro_per;
|
rate_per_sec = 1000000 / micro_per;
|
||||||
note("switch_hash insert: Total %ldus / %ld loops, %.2f us per loop, %.0f loops per second\n",
|
printf("switch_hash insert: Total %ldus / %ld loops, %.2f us per loop, %.0f loops per second\n",
|
||||||
micro_total, loops, micro_per, rate_per_sec);
|
micro_total, loops, micro_per, rate_per_sec);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -76,14 +74,14 @@ int main () {
|
||||||
for ( x = 0; x < loops; x++) {
|
for ( x = 0; x < loops; x++) {
|
||||||
char *data = NULL;
|
char *data = NULL;
|
||||||
data = switch_core_hash_find(hash, index[x]);
|
data = switch_core_hash_find(hash, index[x]);
|
||||||
ok(data != NULL, "Successful lookup");
|
fst_xcheck(data != NULL, "Lookup failed");
|
||||||
is( index[x], data, "Returned correct data");
|
fst_check_string_equals( index[x], data);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
small_start_ts = switch_time_now();
|
small_start_ts = switch_time_now();
|
||||||
for ( x = 0; x < loops; x++) {
|
for ( x = 0; x < loops; x++) {
|
||||||
if ( ! switch_core_hash_find(hash, index[x])) {
|
if ( ! switch_core_hash_find(hash, index[x])) {
|
||||||
fail("Failed to properly locate one of the values");
|
fst_fail("Failed to properly locate one of the values");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
small_end_ts = switch_time_now();
|
small_end_ts = switch_time_now();
|
||||||
|
@ -91,7 +89,7 @@ int main () {
|
||||||
micro_total = small_end_ts - small_start_ts;
|
micro_total = small_end_ts - small_start_ts;
|
||||||
micro_per = micro_total / (double) loops;
|
micro_per = micro_total / (double) loops;
|
||||||
rate_per_sec = 1000000 / micro_per;
|
rate_per_sec = 1000000 / micro_per;
|
||||||
note("switch_hash find: Total %ldus / %ld loops, %.2f us per loop, %.0f loops per second\n",
|
printf("switch_hash find: Total %ldus / %ld loops, %.2f us per loop, %.0f loops per second\n",
|
||||||
micro_total, loops, micro_per, rate_per_sec);
|
micro_total, loops, micro_per, rate_per_sec);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -101,14 +99,14 @@ int main () {
|
||||||
for ( x = 0; x < loops; x++) {
|
for ( x = 0; x < loops; x++) {
|
||||||
char *data = NULL;
|
char *data = NULL;
|
||||||
data = switch_core_hash_delete(hash, index[x]);
|
data = switch_core_hash_delete(hash, index[x]);
|
||||||
ok(data != NULL, "Create a new hash");
|
fst_xcheck(data != NULL, "Delete from the hash");
|
||||||
is( index[x], data, "Returned correct data");
|
fst_check_string_equals( index[x], data );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
small_start_ts = switch_time_now();
|
small_start_ts = switch_time_now();
|
||||||
for ( x = 0; x < loops; x++) {
|
for ( x = 0; x < loops; x++) {
|
||||||
if ( !switch_core_hash_delete(hash, index[x])) {
|
if ( !switch_core_hash_delete(hash, index[x])) {
|
||||||
fail("Failed to delete and return the value");
|
fst_fail("Failed to delete and return the value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
small_end_ts = switch_time_now();
|
small_end_ts = switch_time_now();
|
||||||
|
@ -116,7 +114,7 @@ int main () {
|
||||||
micro_total = small_end_ts - small_start_ts;
|
micro_total = small_end_ts - small_start_ts;
|
||||||
micro_per = micro_total / (double) loops;
|
micro_per = micro_total / (double) loops;
|
||||||
rate_per_sec = 1000000 / micro_per;
|
rate_per_sec = 1000000 / micro_per;
|
||||||
note("switch_hash delete: Total %ldus / %d loops, %.2f us per loop, %.0f loops per second\n",
|
printf("switch_hash delete: Total %ldus / %d loops, %.2f us per loop, %.0f loops per second\n",
|
||||||
micro_total, loops, micro_per, rate_per_sec);
|
micro_total, loops, micro_per, rate_per_sec);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -133,10 +131,12 @@ int main () {
|
||||||
micro_total = end_ts - start_ts;
|
micro_total = end_ts - start_ts;
|
||||||
micro_per = micro_total / (double) loops;
|
micro_per = micro_total / (double) loops;
|
||||||
rate_per_sec = 1000000 / micro_per;
|
rate_per_sec = 1000000 / micro_per;
|
||||||
diag("switch_hash Total %ldus / %d loops, %.2f us per loop, %.0f loops per second\n",
|
printf("switch_hash Total %ldus / %d loops, %.2f us per loop, %.0f loops per second\n",
|
||||||
micro_total, loops, micro_per, rate_per_sec);
|
micro_total, loops, micro_per, rate_per_sec);
|
||||||
|
|
||||||
switch_core_destroy();
|
|
||||||
|
|
||||||
done_testing();
|
|
||||||
}
|
}
|
||||||
|
FST_TEST_END()
|
||||||
|
|
||||||
|
FST_SUITE_END()
|
||||||
|
|
||||||
|
FST_MINCORE_END()
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* Seven Du <dujinfang@gmail.com>
|
* Seven Du <dujinfang@gmail.com>
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* originate_test.c -- tests originate
|
* switch_ivr_originate.c -- tests originate
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
@ -69,7 +69,7 @@ static switch_state_handler_table_t state_handlers = {
|
||||||
|
|
||||||
FST_CORE_BEGIN("./conf")
|
FST_CORE_BEGIN("./conf")
|
||||||
{
|
{
|
||||||
FST_SUITE_BEGIN(originate)
|
FST_SUITE_BEGIN(switch_ivr_originate)
|
||||||
{
|
{
|
||||||
FST_SETUP_BEGIN()
|
FST_SETUP_BEGIN()
|
||||||
{
|
{
|
|
@ -6,12 +6,19 @@ check_PROGRAMS += tests/unit/switch_event
|
||||||
tests_unit_switch_event_SOURCES = tests/unit/switch_event.c
|
tests_unit_switch_event_SOURCES = tests/unit/switch_event.c
|
||||||
tests_unit_switch_event_CFLAGS = $(SWITCH_AM_CFLAGS)
|
tests_unit_switch_event_CFLAGS = $(SWITCH_AM_CFLAGS)
|
||||||
tests_unit_switch_event_LDADD = $(FSLD)
|
tests_unit_switch_event_LDADD = $(FSLD)
|
||||||
tests_unit_switch_event_LDFLAGS = $(SWITCH_AM_LDFLAGS) -ltap
|
tests_unit_switch_event_LDFLAGS = $(SWITCH_AM_LDFLAGS)
|
||||||
|
|
||||||
check_PROGRAMS += tests/unit/switch_hash
|
check_PROGRAMS += tests/unit/switch_hash
|
||||||
|
|
||||||
tests_unit_switch_hash_SOURCES = tests/unit/switch_hash.c
|
tests_unit_switch_hash_SOURCES = tests/unit/switch_hash.c
|
||||||
tests_unit_switch_hash_CFLAGS = $(SWITCH_AM_CFLAGS)
|
tests_unit_switch_hash_CFLAGS = $(SWITCH_AM_CFLAGS)
|
||||||
tests_unit_switch_hash_LDADD = $(FSLD)
|
tests_unit_switch_hash_LDADD = $(FSLD)
|
||||||
tests_unit_switch_hash_LDFLAGS = $(SWITCH_AM_LDFLAGS) -ltap
|
tests_unit_switch_hash_LDFLAGS = $(SWITCH_AM_LDFLAGS)
|
||||||
|
|
||||||
|
check_PROGRAMS += tests/unit/switch_ivr_originate
|
||||||
|
|
||||||
|
tests_unit_switch_ivr_originate_SOURCES = tests/unit/switch_ivr_originate.c
|
||||||
|
tests_unit_switch_ivr_originate_CFLAGS = $(SWITCH_AM_CFLAGS)
|
||||||
|
tests_unit_switch_ivr_originate_LDADD = $(FSLD)
|
||||||
|
tests_unit_switch_ivr_originate_LDFLAGS = $(SWITCH_AM_LDFLAGS)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue