diff --git a/Makefile.am b/Makefile.am index 282f63642b..f00bd48a4b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ EXTRA_DIST = -SUBDIRS = . src build tests/unit +SUBDIRS = . src build AUTOMAKE_OPTIONS = foreign subdir-objects NAME = freeswitch @@ -775,3 +775,15 @@ support: @cp support-d/.screenrc ~ @cp support-d/.bashrc ~ @test -f ~/.cc-mode-installed || sh support-d/install-cc-mode.sh && touch ~/.cc-mode-installed + +# Using a non-recursive Makefile structure for the automated tests so that the tests have visibility into +# targets in the rest of the FreeSWITCH tree. This greatly simplifies dependency tracking at the expense +# of longer test target names. Since the tests are expected to be run easily and rapidly after minor source +# changes this is the most effective structure. + +TESTS = +check_PROGRAMS = + +include tests/unit/unit.mk + + diff --git a/configure.ac b/configure.ac index fba37d7651..10d13898b0 100644 --- a/configure.ac +++ b/configure.ac @@ -1671,7 +1671,6 @@ ac_cv_file_dbd_apr_dbd_mysql_c=no AC_CONFIG_FILES([Makefile build/Makefile src/Makefile - tests/unit/Makefile src/mod/Makefile src/mod/applications/mod_abstraction/Makefile src/mod/applications/mod_avmd/Makefile diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am deleted file mode 100644 index d290dd506d..0000000000 --- a/tests/unit/Makefile.am +++ /dev/null @@ -1,30 +0,0 @@ -AUTOMAKE_OPTIONS = foreign -FSLD = $(top_builddir)/libfreeswitch.la $(top_builddir)/libs/apr/libapr-1.la $(top_builddir)/libs/apr-util/libaprutil-1.la - -TESTS = -check_PROGRAMS = - - -if HAVE_TAP -TESTS += switch_event -check_PROGRAMS += switch_event - -switch_event_SOURCES = switch_event.c -switch_event_CFLAGS = $(SWITCH_AM_CFLAGS) -switch_event_LDADD = $(FSLD) -switch_event_LDFLAGS = $(SWITCH_AM_LDFLAGS) -ltap - -TESTS += switch_hash -check_PROGRAMS += switch_hash - -switch_hash_SOURCES = switch_hash.c -switch_hash_CFLAGS = $(SWITCH_AM_CFLAGS) -switch_hash_LDADD = $(FSLD) -switch_hash_LDFLAGS = $(SWITCH_AM_LDFLAGS) -ltap - -else -check: error -error: - $(error You must install libtap-dev to build these unit tests) -endif - diff --git a/tests/unit/switch_event.c b/tests/unit/switch_event.c index 8ed612798a..a893d493fb 100644 --- a/tests/unit/switch_event.c +++ b/tests/unit/switch_event.c @@ -9,7 +9,7 @@ int main () { switch_bool_t verbose = SWITCH_TRUE; const char *err = NULL; switch_time_t start_ts, end_ts; - int rc = 0, loops = 10; + int rc = 0, loops = 10, x = 0; switch_status_t status = SWITCH_STATUS_SUCCESS; char **index = NULL; unsigned long long micro_total = 0; @@ -31,7 +31,7 @@ int main () { } index = calloc(loops, sizeof(char *)); - for ( int x = 0; x < loops; x++) { + for ( x = 0; x < loops; x++) { index[x] = switch_mprintf("%d", x); } @@ -42,13 +42,13 @@ int main () { ok( status == SWITCH_STATUS_SUCCESS,"Create Event"); #ifndef BENCHMARK - for ( int 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]); ok( status == SWITCH_STATUS_SUCCESS,"Add header to event"); } #else small_start_ts = switch_time_now(); - for ( int 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) { fail("Failed to add header to event"); } @@ -64,12 +64,12 @@ int main () { #ifndef BENCHMARK - for ( int 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"); } #else small_start_ts = switch_time_now(); - for ( int x = 0; x < loops; x++) { + for ( x = 0; x < loops; x++) { if ( !switch_event_get_header(event, index[x])) { fail("Failed to lookup event header value"); } @@ -89,7 +89,7 @@ int main () { end_ts = switch_time_now(); - for ( int x = 0; x < loops; x++) { + for ( x = 0; x < loops; x++) { free(index[x]); } free(index); diff --git a/tests/unit/switch_hash.c b/tests/unit/switch_hash.c index ec620d0327..522ca6ea1c 100644 --- a/tests/unit/switch_hash.c +++ b/tests/unit/switch_hash.c @@ -13,7 +13,8 @@ int main () { unsigned long long micro_total = 0; double micro_per = 0; double rate_per_sec = 0; - + int x = 0; + #ifdef BENCHMARK switch_time_t small_start_ts, small_end_ts; #endif @@ -42,7 +43,7 @@ int main () { } index = calloc(loops, sizeof(char *)); - for ( int x = 0; x < loops; x++) { + for ( x = 0; x < loops; x++) { index[x] = switch_mprintf("%d", x); } @@ -51,13 +52,13 @@ int main () { /* Insertion */ #ifndef BENCHMARK - for ( int x = 0; x < loops; x++) { + 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"); } #else small_start_ts = switch_time_now(); - for ( int x = 0; x < loops; x++) { + for ( x = 0; x < loops; x++) { switch_core_hash_insert(hash, index[x], (void *) index[x]); } small_end_ts = switch_time_now(); @@ -72,7 +73,7 @@ int main () { /* Lookup */ #ifndef BENCHMARK - for ( int x = 0; x < loops; x++) { + for ( x = 0; x < loops; x++) { char *data = NULL; data = switch_core_hash_find(hash, index[x]); ok(data != NULL, "Successful lookup"); @@ -80,7 +81,7 @@ int main () { } #else small_start_ts = switch_time_now(); - for ( int x = 0; x < loops; x++) { + for ( x = 0; x < loops; x++) { if ( ! switch_core_hash_find(hash, index[x])) { fail("Failed to properly locate one of the values"); } @@ -97,7 +98,7 @@ int main () { /* Delete */ #ifndef BENCHMARK - for ( int x = 0; x < loops; x++) { + for ( x = 0; x < loops; x++) { char *data = NULL; data = switch_core_hash_delete(hash, index[x]); ok(data != NULL, "Create a new hash"); @@ -105,7 +106,7 @@ int main () { } #else small_start_ts = switch_time_now(); - for ( int x = 0; x < loops; x++) { + for ( x = 0; x < loops; x++) { if ( !switch_core_hash_delete(hash, index[x])) { fail("Failed to delete and return the value"); } @@ -124,7 +125,7 @@ int main () { /* END LOOPS */ switch_core_hash_destroy(&hash); - for ( int x = 0; x < loops; x++) { + for ( x = 0; x < loops; x++) { free(index[x]); } free(index); diff --git a/tests/unit/unit.mk b/tests/unit/unit.mk new file mode 100644 index 0000000000..713fbb7d3e --- /dev/null +++ b/tests/unit/unit.mk @@ -0,0 +1,19 @@ +AUTOMAKE_OPTIONS = foreign +FSLD = $(top_builddir)/libfreeswitch.la $(top_builddir)/libs/apr/libapr-1.la $(top_builddir)/libs/apr-util/libaprutil-1.la + +TESTS += tests/unit/switch_event +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 += tests/unit/switch_hash +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 +