]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7820
authorWilliam King <william.king@quentustech.com>
Fri, 10 Jul 2015 14:07:36 +0000 (07:07 -0700)
committerWilliam King <william.king@quentustech.com>
Fri, 10 Jul 2015 19:04:04 +0000 (12:04 -0700)
C level unit testing and micro benchmarking framework, including one
example unit test.

Makefile.am
configure.ac
tests/unit/Makefile.am [new file with mode: 0644]
tests/unit/README [new file with mode: 0644]
tests/unit/event_create.c [new file with mode: 0644]

index c9b797b9c446079c6f75977964bceca36671a577..63f0896fac26044ff5798f66044e2e140a4d3aac 100644 (file)
@@ -1,5 +1,5 @@
 EXTRA_DIST =
-SUBDIRS = . src build
+SUBDIRS = . src build tests/unit
 AUTOMAKE_OPTIONS = foreign subdir-objects
 NAME = freeswitch
 
index 1fb30e18c6ada093f922ba7b11d2cb6ad84a358d..9bb07fccfe742cc2a020917468ec8818c2317991 100644 (file)
@@ -205,7 +205,6 @@ AC_DEFINE_UNQUOTED([SWITCH_DATA_DIR],"${datadir}",[directory for data files])
 
 AC_SUBST(localstatedir)
 AC_DEFINE_UNQUOTED([SWITCH_LOCALSTATE_DIR],"${localstatedir}",[directory for local state files])
-
 AC_SUBST(bindir)
 AC_SUBST(includedir)
 
@@ -1383,6 +1382,10 @@ PKG_CHECK_MODULES([AMQP], [librabbitmq >= 0.5.2],[
   AM_CONDITIONAL([HAVE_AMQP],[true])],[
   AC_MSG_RESULT([no]); AM_CONDITIONAL([HAVE_AMQP],[false])])
 
+PKG_CHECK_MODULES([TAP], [tap >= 0.1.0],[
+  AM_CONDITIONAL([HAVE_TAP],[true])],[
+  AC_MSG_RESULT([no]); AM_CONDITIONAL([HAVE_TAP],[false])])
+
 PKG_CHECK_MODULES([SMPP34], [libsmpp34 >= 1.10],[
   AM_CONDITIONAL([HAVE_SMPP34],[true])],[
   AC_MSG_RESULT([no]); AM_CONDITIONAL([HAVE_SMPP34],[false])])
@@ -1659,6 +1662,7 @@ 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
new file mode 100644 (file)
index 0000000..d88fe76
--- /dev/null
@@ -0,0 +1,22 @@
+FSLD = $(top_builddir)/libfreeswitch.la $(top_builddir)/libs/apr/libapr-1.la $(top_builddir)/libs/apr-util/libaprutil-1.la
+
+TESTS = event_create
+
+if HAVE_TAP
+
+check_PROGRAMS = event_create
+
+
+event_create_SOURCES = event_create.c
+event_create_CFLAGS = $(SWITCH_AM_CFLAGS)
+event_create_LDADD = $(FSLD)
+event_create_LDFLAGS = $(SWITCH_AM_LDFLAGS) -ltap
+
+
+else
+install: error
+all: error
+error:
+       $(error You must install libtap-dev to build these unit tests)
+endif
+
diff --git a/tests/unit/README b/tests/unit/README
new file mode 100644 (file)
index 0000000..79d3b9f
--- /dev/null
@@ -0,0 +1,18 @@
+FreeSWITCH unit tests should be kept as shallow unit tests and micro
+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
\ No newline at end of file
diff --git a/tests/unit/event_create.c b/tests/unit/event_create.c
new file mode 100644 (file)
index 0000000..bfef0cb
--- /dev/null
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <switch.h>
+#include <tap.h>
+
+int main () {
+
+  switch_event_t *event = NULL;
+  switch_bool_t verbose = SWITCH_TRUE;
+  const char *err = NULL;
+  switch_time_t start_ts, end_ts;
+  int rc = 0, loops = 1000;
+  switch_status_t status = SWITCH_STATUS_SUCCESS;
+
+  plan(1 + ( 3 * loops));
+
+  
+  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);
+  }
+
+  /* START LOOPS */
+  start_ts = switch_time_now();
+  
+  for ( int x = 0; x < loops; x++) {
+    status = switch_event_create(&event, SWITCH_EVENT_MESSAGE);
+    ok( status == SWITCH_STATUS_SUCCESS,"Create Event");
+    
+    status = switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "testing", "event_create");
+    ok( status == SWITCH_STATUS_SUCCESS,"Add header to event");
+    
+    is(switch_event_get_header(event, "testing"), "event_create", "correct header value returned");
+    
+    switch_event_destroy(&event);
+  } /* END LOOPS */
+  
+  end_ts = switch_time_now();
+
+  note("Total %ldus, %ldus per loop, %ld loops per second\n", end_ts - start_ts,(end_ts - start_ts) / loops, 1000000/ ((end_ts - start_ts) / loops));
+
+  switch_core_destroy();
+
+  done_testing();
+}