mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-24 21:22:09 +00:00
FS-11453 [core] remove dependency to libtap for unit tests
move all core unit tests to tests/unit
This commit is contained in:
@@ -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)
|
||||
+1
-24
@@ -3,29 +3,6 @@ benchmarks testing functionality exposed through libfreeswitch.
|
||||
|
||||
Requirements for a new unit tests:
|
||||
|
||||
1. Tests must use TAP(Test Anything Protocol) output format, and must
|
||||
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
|
||||
1. Tests must use switch_test.h framework
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
+33
-24
@@ -1,10 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#include <switch.h>
|
||||
#include <tap.h>
|
||||
#include <test/switch_test.h>
|
||||
|
||||
// #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_bool_t verbose = SWITCH_TRUE;
|
||||
const char *err = NULL;
|
||||
@@ -18,18 +33,8 @@ int main () {
|
||||
|
||||
#ifdef BENCHMARK
|
||||
switch_time_t small_start_ts, small_end_ts;
|
||||
|
||||
plan(2);
|
||||
#else
|
||||
plan(2 + ( 2 * loops));
|
||||
#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 *));
|
||||
for ( x = 0; x < loops; x++) {
|
||||
index[x] = switch_mprintf("%d", x);
|
||||
@@ -39,18 +44,18 @@ int main () {
|
||||
start_ts = switch_time_now();
|
||||
|
||||
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
|
||||
for ( x = 0; x < loops; 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
|
||||
small_start_ts = switch_time_now();
|
||||
for ( x = 0; x < loops; x++) {
|
||||
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();
|
||||
@@ -58,20 +63,20 @@ int main () {
|
||||
micro_total = small_end_ts - small_start_ts;
|
||||
micro_per = micro_total / (double) loops;
|
||||
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);
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef BENCHMARK
|
||||
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
|
||||
small_start_ts = switch_time_now();
|
||||
for ( x = 0; x < loops; 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();
|
||||
@@ -79,11 +84,10 @@ int main () {
|
||||
micro_total = small_end_ts - small_start_ts;
|
||||
micro_per = micro_total / (double) loops;
|
||||
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);
|
||||
#endif
|
||||
|
||||
|
||||
switch_event_destroy(&event);
|
||||
/* END LOOPS */
|
||||
|
||||
@@ -97,10 +101,15 @@ int main () {
|
||||
micro_total = end_ts - start_ts;
|
||||
micro_per = micro_total / (double) loops;
|
||||
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);
|
||||
|
||||
switch_core_destroy();
|
||||
|
||||
done_testing();
|
||||
}
|
||||
FST_TEST_END()
|
||||
|
||||
FST_SUITE_END()
|
||||
|
||||
FST_MINCORE_END()
|
||||
|
||||
|
||||
|
||||
|
||||
+34
-34
@@ -1,11 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#include <switch.h>
|
||||
#include <tap.h>
|
||||
#include <test/switch_test.h>
|
||||
|
||||
// #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_bool_t verbose = SWITCH_TRUE;
|
||||
const char *err = NULL;
|
||||
@@ -24,23 +38,7 @@ int main () {
|
||||
char **index = NULL;
|
||||
switch_hash_t *hash = NULL;
|
||||
|
||||
#ifndef BENCHMARK
|
||||
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");
|
||||
}
|
||||
fst_requires(switch_core_hash_init(&hash) == SWITCH_STATUS_SUCCESS);
|
||||
|
||||
index = calloc(loops, sizeof(char *));
|
||||
for ( x = 0; x < loops; x++) {
|
||||
@@ -54,7 +52,7 @@ int main () {
|
||||
#ifndef BENCHMARK
|
||||
for ( x = 0; x < loops; 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
|
||||
small_start_ts = switch_time_now();
|
||||
@@ -66,7 +64,7 @@ int main () {
|
||||
micro_total = small_end_ts - small_start_ts;
|
||||
micro_per = micro_total / (double) loops;
|
||||
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);
|
||||
#endif
|
||||
|
||||
@@ -76,14 +74,14 @@ int main () {
|
||||
for ( x = 0; x < loops; x++) {
|
||||
char *data = NULL;
|
||||
data = switch_core_hash_find(hash, index[x]);
|
||||
ok(data != NULL, "Successful lookup");
|
||||
is( index[x], data, "Returned correct data");
|
||||
fst_xcheck(data != NULL, "Lookup failed");
|
||||
fst_check_string_equals( index[x], data);
|
||||
}
|
||||
#else
|
||||
small_start_ts = switch_time_now();
|
||||
for ( x = 0; x < loops; 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();
|
||||
@@ -91,7 +89,7 @@ int main () {
|
||||
micro_total = small_end_ts - small_start_ts;
|
||||
micro_per = micro_total / (double) loops;
|
||||
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);
|
||||
#endif
|
||||
|
||||
@@ -101,14 +99,14 @@ int main () {
|
||||
for ( x = 0; x < loops; x++) {
|
||||
char *data = NULL;
|
||||
data = switch_core_hash_delete(hash, index[x]);
|
||||
ok(data != NULL, "Create a new hash");
|
||||
is( index[x], data, "Returned correct data");
|
||||
fst_xcheck(data != NULL, "Delete from the hash");
|
||||
fst_check_string_equals( index[x], data );
|
||||
}
|
||||
#else
|
||||
small_start_ts = switch_time_now();
|
||||
for ( x = 0; x < loops; 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();
|
||||
@@ -116,7 +114,7 @@ int main () {
|
||||
micro_total = small_end_ts - small_start_ts;
|
||||
micro_per = micro_total / (double) loops;
|
||||
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);
|
||||
#endif
|
||||
|
||||
@@ -133,10 +131,12 @@ int main () {
|
||||
micro_total = end_ts - start_ts;
|
||||
micro_per = micro_total / (double) loops;
|
||||
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);
|
||||
|
||||
switch_core_destroy();
|
||||
|
||||
done_testing();
|
||||
}
|
||||
FST_TEST_END()
|
||||
|
||||
FST_SUITE_END()
|
||||
|
||||
FST_MINCORE_END()
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* Seven Du <dujinfang@gmail.com>
|
||||
*
|
||||
*
|
||||
* originate_test.c -- tests originate
|
||||
* switch_ivr_originate.c -- tests originate
|
||||
*
|
||||
*/
|
||||
#include <switch.h>
|
||||
@@ -69,7 +69,7 @@ static switch_state_handler_table_t state_handlers = {
|
||||
|
||||
FST_CORE_BEGIN("./conf")
|
||||
{
|
||||
FST_SUITE_BEGIN(originate)
|
||||
FST_SUITE_BEGIN(switch_ivr_originate)
|
||||
{
|
||||
FST_SETUP_BEGIN()
|
||||
{
|
||||
+9
-2
@@ -6,12 +6,19 @@ check_PROGRAMS += tests/unit/switch_event
|
||||
tests_unit_switch_event_SOURCES = tests/unit/switch_event.c
|
||||
tests_unit_switch_event_CFLAGS = $(SWITCH_AM_CFLAGS)
|
||||
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
|
||||
|
||||
tests_unit_switch_hash_SOURCES = tests/unit/switch_hash.c
|
||||
tests_unit_switch_hash_CFLAGS = $(SWITCH_AM_CFLAGS)
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user