EXTRA_DIST =
-SUBDIRS = . src build tests/unit
+SUBDIRS = . src build
AUTOMAKE_OPTIONS = foreign subdir-objects
NAME = freeswitch
@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
+
+
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
+++ /dev/null
-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
-
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;
}
index = calloc(loops, sizeof(char *));
- for ( int x = 0; x < loops; x++) {
+ for ( x = 0; x < loops; x++) {
index[x] = switch_mprintf("%d", x);
}
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");
}
#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");
}
end_ts = switch_time_now();
- for ( int x = 0; x < loops; x++) {
+ for ( x = 0; x < loops; x++) {
free(index[x]);
}
free(index);
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
}
index = calloc(loops, sizeof(char *));
- for ( int x = 0; x < loops; x++) {
+ for ( x = 0; x < loops; x++) {
index[x] = switch_mprintf("%d", x);
}
/* 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();
/* 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");
}
#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");
}
/* 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");
}
#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");
}
/* 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);
--- /dev/null
+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
+