Commit 67a74feb authored by Philippe Gerum's avatar Philippe Gerum

testsuite/smokey: add POSIX select testing code

parent 64ee0926
......@@ -931,6 +931,7 @@ AC_CONFIG_FILES([ \
testsuite/smokey/posix-mutex/Makefile \
testsuite/smokey/posix-clock/Makefile \
testsuite/smokey/posix-fork/Makefile \
testsuite/smokey/posix-select/Makefile \
testsuite/smokey/xddp/Makefile \
testsuite/smokey/iddp/Makefile \
testsuite/smokey/bufp/Makefile \
......
......@@ -108,6 +108,17 @@ struct smokey_test {
__ret; \
})
#define smokey_check_status(__expr) \
({ \
int __ret = (__expr); \
if (__ret) { \
smokey_warning(__FILE__, __LINE__, "%s: %s", \
#__expr, strerror(__ret)); \
__ret = -__ret; \
} \
__ret; \
})
#define smokey_assert(__expr) \
({ \
int __ret = (__expr); \
......
......@@ -6,7 +6,6 @@ noinst_HEADERS = check.h
test_PROGRAMS = \
leaks \
mq_select \
timerfd
CPPFLAGS = $(XENO_USER_CFLAGS) \
......
......@@ -15,6 +15,7 @@ SUBDIRS = \
posix-cond \
posix-fork \
posix-mutex \
posix-select \
rtdm \
sched-quota \
sched-tp \
......@@ -55,6 +56,7 @@ DIST_SUBDIRS = \
posix-cond \
posix-fork \
posix-mutex \
posix-select \
rtdm \
sched-quota \
sched-tp \
......
noinst_LIBRARIES = libposix-select.a
libposix_select_a_SOURCES = posix-select.c
CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
libposix_select_a_CPPFLAGS = \
@XENO_USER_CFLAGS@ \
-I$(top_srcdir)/include
......@@ -20,21 +20,21 @@
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <mqueue.h>
#include <pthread.h>
#include <sys/select.h>
#include <sys/mman.h>
#include <smokey/smokey.h>
#include "check.h"
smokey_test_plugin(posix_select,
SMOKEY_NOARGS,
"Check POSIX select service"
);
static const char *tunes[] = {
"Surfing With The Alien",
......@@ -55,64 +55,87 @@ static const char *tunes[] = {
"Engines Of Creation"
};
static void *task(void *cookie)
static int test_status;
static void *mq_thread(void *cookie)
{
mqd_t mqd = (mqd_t)(long)cookie;
fd_set inset;
unsigned i;
unsigned int i = 0, prio;
fd_set inset, tmp_inset;
char buf[128];
int ret;
FD_ZERO(&inset);
FD_SET(mqd, &inset);
for(i = 0; i < sizeof(tunes)/sizeof(tunes[0]); i++) {
fd_set tmp_inset = inset;
unsigned prio;
char buf[128];
for (;;) {
tmp_inset = inset;
check_unix(select(mqd + 1, &tmp_inset, NULL, NULL, NULL));
ret = smokey_check_errno(select(mqd + 1, &tmp_inset, NULL, NULL, NULL));
if (ret < 0) {
test_status = ret;
break;
}
check_unix(mq_receive(mqd, buf, sizeof(buf), &prio));
ret = smokey_check_errno(mq_receive(mqd, buf, sizeof(buf), &prio));
if (ret < 0) {
test_status = ret;
break;
}
if (strcmp(buf, tunes[i])) {
fprintf(stderr, "Received %s instead of %s\n",
buf, tunes[i]);
exit(EXIT_FAILURE);
if (strcmp(buf, "/done") == 0)
break;
if (!smokey_assert(strcmp(buf, tunes[i]) == 0)) {
test_status = -EINVAL;
break;
}
fprintf(stderr, "Received %s\n", buf);
smokey_note("received %s", buf);
i = (i + 1) % (sizeof(tunes) / sizeof(tunes[0]));
}
return NULL;
}
int main(void)
static int run_posix_select(struct smokey_test *t, int argc, char *const argv[])
{
struct mq_attr qa;
pthread_t tcb;
int i, j, ret;
mqd_t mq;
int i;
fprintf(stderr, "Checking select service with posix message queues\n");
mq_unlink("/select_test_mq");
qa.mq_maxmsg = 128;
qa.mq_msgsize = 128;
mq = mq_open("/select_test_mq", O_RDWR | O_CREAT | O_NONBLOCK, 0, &qa);
check_unix(mq == -1 ? -1 : 0);
check_pthread(pthread_create(&tcb, NULL, task, (void *)(long)mq));
alarm(30);
for(i = 0; i < sizeof(tunes) / sizeof(tunes[0]); i++) {
check_unix(mq_send(mq, tunes[i], strlen(tunes[i]) + 1, 0));
sleep(1);
mq = smokey_check_errno(mq_open("/select_test_mq", O_RDWR | O_CREAT | O_NONBLOCK, 0, &qa));
if (mq < 0)
return mq;
ret = smokey_check_status(pthread_create(&tcb, NULL, mq_thread, (void *)(long)mq));
if (ret)
return ret;
for (j = 0; j < 3; j++) {
for (i = 0; i < sizeof(tunes) / sizeof(tunes[0]); i++) {
ret = smokey_check_errno(mq_send(mq, tunes[i], strlen(tunes[i]) + 1, 0));
if (ret < 0) {
smokey_check_status(pthread_cancel(tcb));
goto out;
}
usleep(100000);
}
}
check_pthread(pthread_join(tcb, NULL));
fprintf(stderr, "select service with posix message queues: success\n");
return EXIT_SUCCESS;
ret = smokey_check_errno(mq_send(mq, "/done", sizeof "/done", 0));
if (ret < 0) {
smokey_check_status(pthread_cancel(tcb));
goto out;
}
usleep(300000);
smp_rmb();
ret = test_status;
out:
pthread_join(tcb, NULL);
return ret;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment