]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-8233 convert unit tests frameworks to non-recursive makefiles
authorWilliam King <william.king@quentustech.com>
Mon, 28 Sep 2015 20:06:15 +0000 (13:06 -0700)
committerWilliam King <william.king@quentustech.com>
Thu, 8 Oct 2015 20:01:04 +0000 (13:01 -0700)
Makefile.am
configure.ac
tests/unit/Makefile.am [deleted file]
tests/unit/switch_event.c
tests/unit/switch_hash.c
tests/unit/unit.mk [new file with mode: 0644]

index 282f63642b05d2f858c02eadee8a38220bbff52a..f00bd48a4baa7db8eb5d4c07dddcc24598e145b0 100644 (file)
@@ -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
+
+
index fba37d76516507e74bf1f4847859b424a76bfe7e..10d13898b002bf883ee90341023e4e327274324f 100644 (file)
@@ -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 (file)
index d290dd5..0000000
+++ /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
-
index 8ed612798a85f656fbcf8a2a1e10070f11d04208..a893d493fbb451d716027fdfec812586a015a8ab 100644 (file)
@@ -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);
index ec620d032792cf4aa9bd741abb2d1e09a8fff7d5..522ca6ea1c439f997bc8fd2182181b7fd0cdfbc2 100644 (file)
@@ -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 (file)
index 0000000..713fbb7
--- /dev/null
@@ -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
+