aboutsummaryrefslogtreecommitdiff
path: root/build/autotests/tests
diff options
context:
space:
mode:
Diffstat (limited to 'build/autotests/tests')
-rw-r--r--build/autotests/tests/Makefile.am30
-rw-r--r--build/autotests/tests/common.h54
-rw-r--r--build/autotests/tests/fail.c5
-rw-r--r--build/autotests/tests/pass.c7
-rwxr-xr-xbuild/autotests/tests/runtest.sh43
-rw-r--r--build/autotests/tests/serialqueue.c58
-rw-r--r--build/autotests/tests/skip.c5
-rw-r--r--build/autotests/tests/threadedqueue.c77
8 files changed, 279 insertions, 0 deletions
diff --git a/build/autotests/tests/Makefile.am b/build/autotests/tests/Makefile.am
new file mode 100644
index 0000000..1a5f7f7
--- /dev/null
+++ b/build/autotests/tests/Makefile.am
@@ -0,0 +1,30 @@
+AUTOMAKE_OPTIONS = foreign
+AM_LDFLAGS= -module -avoid-version -shared -shrext .pd_linux
+
+TEST_EXTENSIONS = .la
+LA_LOG_COMPILER = $(srcdir)/runtest.sh
+
+AM_CPPFLAGS=-I$(top_srcdir)/../..
+AM_LDFLAGS+=$(top_builddir)/libiemnet.la -rpath /tmp
+
+SOURCES=common.h
+noinst_HEADERS=common.h
+EXTRA_DIST=runtest.sh
+
+TESTS = \
+ pass.la skip.la fail.la \
+ serialqueue.la threadedqueue.la
+
+XFAIL_TESTS = fail.la
+
+check_LTLIBRARIES= \
+ pass.la skip.la fail.la \
+ serialqueue.la threadedqueue.la
+
+pass_la_SOURCES=pass.c
+skip_la_SOURCES=skip.c
+fail_la_SOURCES=fail.c
+
+threadedqueue_la_SOURCES=threadedqueue.c
+serialqueue_la_SOURCES=serialqueue.c
+
diff --git a/build/autotests/tests/common.h b/build/autotests/tests/common.h
new file mode 100644
index 0000000..abef2c8
--- /dev/null
+++ b/build/autotests/tests/common.h
@@ -0,0 +1,54 @@
+#ifndef TESTS_COMMON_H
+#define TESTS_COMMON_H
+
+#include "iemnet.h"
+
+#include <stdlib.h>
+static inline void pass(void) {exit(0); }
+static inline void fail(void) {exit(1); }
+static inline void skip(void) {exit(77); }
+
+#include <stdio.h>
+#include <stdarg.h>
+static inline void pass_if (int test, int line, const char *format, ...)
+{
+ if (test) {
+ va_list argptr ;
+ printf("@%d: ", line);
+ va_start (argptr, format) ;
+ vprintf (format, argptr) ;
+ va_end (argptr) ;
+ printf("\n");
+ pass();
+ } ;
+} /* pass_if */
+static inline void skip_if (int test, int line, const char *format, ...)
+{
+ if (test) {
+ va_list argptr ;
+ printf("@%d: ", line);
+ va_start (argptr, format) ;
+ vprintf (format, argptr) ;
+ va_end (argptr) ;
+ printf("\n");
+ skip();
+ } ;
+} /* skip_if */
+static inline void fail_if (int test, int line, const char *format, ...)
+{
+ if (test) {
+ va_list argptr ;
+ printf("@%d: ", line);
+ va_start (argptr, format) ;
+ vprintf (format, argptr) ;
+ va_end (argptr) ;
+ printf("\n");
+ fail();
+ } ;
+} /* fail_if */
+
+#define STRINGIFY(x) #x
+#define STARTTEST(x) printf("============ %s[%04d]:\t%s '%s'\n", __FILE__, __LINE__, __FUNCTION__, x)
+
+#endif /* TESTS_COMMON_H */
+
diff --git a/build/autotests/tests/fail.c b/build/autotests/tests/fail.c
new file mode 100644
index 0000000..a2cb791
--- /dev/null
+++ b/build/autotests/tests/fail.c
@@ -0,0 +1,5 @@
+#include "common.h"
+
+void fail_setup() {
+ fail();
+}
diff --git a/build/autotests/tests/pass.c b/build/autotests/tests/pass.c
new file mode 100644
index 0000000..153e735
--- /dev/null
+++ b/build/autotests/tests/pass.c
@@ -0,0 +1,7 @@
+#include "common.h"
+
+
+void pass_setup(void) {
+ pass();
+}
+
diff --git a/build/autotests/tests/runtest.sh b/build/autotests/tests/runtest.sh
new file mode 100755
index 0000000..396d793
--- /dev/null
+++ b/build/autotests/tests/runtest.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+EXTERNAL=$1
+EXTERNAL=${EXTERNAL%.la}
+EXTERNAL=${EXTERNAL#./}
+
+TESTTYPE=$2
+
+
+##################################
+
+PD=pd
+PDARGS="-nrt -nogui -path .libs"
+PDARGS="-noprefs -nostdpath -nosound -nrt -nogui -path .libs"
+#PDARGS="-nostdpath -nosound -nrt -nogui -path .libs"
+#VALGRIND=valgrind
+VALGRIND="valgrind --error-exitcode=1"
+
+do_runtest() {
+case "$1" in
+ mem*|MEM*)
+ ${VALGRIND} ${PD} ${PDARGS} -lib ${EXTERNAL}
+ ;;
+ DRD|drd)
+ ${VALGRIND} --tool=drd ${PD} ${PDARGS} -lib ${EXTERNAL}
+ ;;
+ HEL*|hel*)
+ ${VALGRIND} --tool=helgrind ${PD} ${PDARGS} -lib ${EXTERNAL}
+ ;;
+ *)
+ ${PD} ${PDARGS} -lib ${EXTERNAL}
+ ;;
+esac
+}
+
+
+#do_runtest
+#do_runtest MEM
+#do_runtest DRD
+#do_runtest HEL
+#do_runtest && do_runtest MEM && do_runtest DRD
+
+do_runtest $TESTTYPE
diff --git a/build/autotests/tests/serialqueue.c b/build/autotests/tests/serialqueue.c
new file mode 100644
index 0000000..238be41
--- /dev/null
+++ b/build/autotests/tests/serialqueue.c
@@ -0,0 +1,58 @@
+#include <common.h>
+
+#include <pthread.h>
+
+#define NUMCHUNKS 1000
+
+
+typedef union {
+ unsigned char cp;
+ int count;
+} data_t;
+static int producer(t_iemnet_queue*q, unsigned int count, unsigned int msec) {
+ unsigned int i;
+ data_t data;
+ for(i=0; i<count; i++) {
+ t_iemnet_chunk*chunk=0;
+ data.count=i;
+ // post("producing %d", i);
+
+ chunk=iemnet__chunk_create_data(sizeof(data), &data.cp);
+ queue_push(q, chunk);
+ usleep(1000*msec);
+ }
+ return 0;
+}
+
+static int consumer(t_iemnet_queue*q) {
+ t_iemnet_chunk*chunk=NULL;
+ while(1) {
+ data_t*data=NULL;
+
+ /* in a non-threaded context, we must not use queue_pop_block()
+ * as we have no way to unblock the queue,
+ * resulting in a deadlock
+ */
+ chunk=queue_pop_noblock(q);
+ if(!chunk)
+ break;
+ if(sizeof(data_t)!=chunk->size) {
+ error("size mismatch %d!=%d", sizeof(data_t), chunk->size);
+ fail();
+ }
+ data=chunk->data;
+ // post("consumed %d", data->count);
+ iemnet__chunk_destroy(chunk);
+ }
+ printf("\n");
+ return 0;
+}
+
+void serialqueue_setup(void) {
+ t_iemnet_queue*q=queue_create();
+ producer(q, 1000, 1);
+ consumer(q);
+
+ queue_destroy(q);
+ pass();
+}
diff --git a/build/autotests/tests/skip.c b/build/autotests/tests/skip.c
new file mode 100644
index 0000000..63775ec
--- /dev/null
+++ b/build/autotests/tests/skip.c
@@ -0,0 +1,5 @@
+#include "common.h"
+
+void skip_setup(void) {
+ skip();
+}
diff --git a/build/autotests/tests/threadedqueue.c b/build/autotests/tests/threadedqueue.c
new file mode 100644
index 0000000..b68f11d
--- /dev/null
+++ b/build/autotests/tests/threadedqueue.c
@@ -0,0 +1,77 @@
+#include <common.h>
+
+#include <pthread.h>
+
+#define NUMCHUNKS 1000
+
+
+typedef union {
+ unsigned char cp;
+ int count;
+} data_t;
+static int producer(t_iemnet_queue*q, unsigned int count, unsigned int msec) {
+ unsigned int i;
+ data_t data;
+ for(i=0; i<count; i++) {
+ t_iemnet_chunk*chunk=0;
+ data.count=i;
+
+ chunk=iemnet__chunk_create_data(sizeof(data), &data.cp);
+ queue_push(q, chunk);
+ usleep(1000*msec);
+ }
+ return 0;
+}
+
+static int consumer(t_iemnet_queue*q) {
+ t_iemnet_chunk*chunk=NULL;
+ while(1) {
+ data_t*data=NULL;
+ chunk=queue_pop_block(q);
+ if(!chunk)
+ break;
+ if(sizeof(data_t)!=chunk->size) {
+ error("size mismatch %d!=%d", sizeof(data_t), chunk->size);
+ fail();
+ }
+ data=chunk->data;
+ //printf("%d ", data->count);
+ iemnet__chunk_destroy(chunk);
+ }
+ printf("\n");
+ return 0;
+}
+static void* consumer_thread(void*qq) {
+ t_iemnet_queue*q=(t_iemnet_queue*)qq;
+ consumer(q);
+ return NULL;
+}
+
+void threadedqueue_setup(void) {
+ pthread_t thread;
+ pthread_attr_t threadattr;
+
+ t_iemnet_queue*q=queue_create();
+
+ /* prepare child thread */
+ if(pthread_attr_init(&threadattr) < 0) {
+ error("warning: could not prepare child thread");
+ fail();
+ }
+ if(pthread_attr_setdetachstate(&threadattr, PTHREAD_CREATE_DETACHED) < 0) {
+ error("warning: could not prepare child thread...");
+ fail();
+ }
+
+ if(pthread_create(&thread, &threadattr, consumer_thread, q) < 0) {
+ error("warning: could not create child thread");
+ fail();
+ }
+
+
+ producer(q, 1000, 1);
+
+
+ queue_destroy(q);
+ pass();
+}