From 9f0009faeaa0960f57fcacea91b45997258016e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Tue, 1 Sep 2015 14:32:27 +0000 Subject: synch more with git svn path=/trunk/externals/iem/iemnet/; revision=17546 --- build/autotests/tests/Makefile.am | 30 ++++++++++++++ build/autotests/tests/common.h | 54 ++++++++++++++++++++++++ build/autotests/tests/fail.c | 5 +++ build/autotests/tests/pass.c | 7 ++++ build/autotests/tests/runtest.sh | 43 +++++++++++++++++++ build/autotests/tests/serialqueue.c | 58 ++++++++++++++++++++++++++ build/autotests/tests/skip.c | 5 +++ build/autotests/tests/threadedqueue.c | 77 +++++++++++++++++++++++++++++++++++ 8 files changed, 279 insertions(+) create mode 100644 build/autotests/tests/Makefile.am create mode 100644 build/autotests/tests/common.h create mode 100644 build/autotests/tests/fail.c create mode 100644 build/autotests/tests/pass.c create mode 100755 build/autotests/tests/runtest.sh create mode 100644 build/autotests/tests/serialqueue.c create mode 100644 build/autotests/tests/skip.c create mode 100644 build/autotests/tests/threadedqueue.c (limited to 'build/autotests/tests') 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 +static inline void pass(void) {exit(0); } +static inline void fail(void) {exit(1); } +static inline void skip(void) {exit(77); } + +#include +#include +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 + +#include + +#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; isize) { + 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 + +#include + +#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; isize) { + 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(); +} -- cgit v1.2.1