Commit f0fd5d86 authored by Ian Murdock's avatar Ian Murdock

Added test for event scheduler.

parent a3794773
# Makefile for building event system tests # Makefile for building event system tests
# #
# $Id: Makefile,v 1.3 2001-12-04 15:16:01 imurdock Exp $ # $Id: Makefile,v 1.4 2002-01-29 17:24:58 imurdock Exp $
CC = gcc CC = gcc
CFLAGS = -g -I. -I../lib -Wall -DDEBUG CFLAGS = -g -I. -I../lib -Wall -DDEBUG
LDFLAGS = LDFLAGS =
LIBS = -L../lib -levent LIBS = -lpthread -L../lib -levent
CFLAGS += `elvin-config --cflags` CFLAGS += `elvin-config --cflags`
LIBS += `elvin-config --libs` LIBS += `elvin-config --libs`
...@@ -18,7 +18,7 @@ tests = test-consume \ ...@@ -18,7 +18,7 @@ tests = test-consume \
test-attr-consume \ test-attr-consume \
test-attr-produce \ test-attr-produce \
test-queue \ test-queue \
test-sched test-sched-produce
%: %.c %: %.c
$(CC) $(LDFLAGS) -o $@ $(CFLAGS) $< $(LIBS) $(LIBS) $(CC) $(LDFLAGS) -o $@ $(CFLAGS) $< $(LIBS) $(LIBS)
...@@ -29,10 +29,6 @@ test-queue: ../sched/queue.c ...@@ -29,10 +29,6 @@ test-queue: ../sched/queue.c
$(CC) $(LDFLAGS) -o $@ $(CFLAGS) -DTEST_EVENT_QUEUES -I../sched \ $(CC) $(LDFLAGS) -o $@ $(CFLAGS) -DTEST_EVENT_QUEUES -I../sched \
$< $(LIBS) $(LIBS) $< $(LIBS) $(LIBS)
test-sched: ../sched/event-sched.c
$(CC) $(LDFLAGS) -o $@ $(CFLAGS) -DTEST_SCHED -I../sched \
$< ../sched/queue.o $(LIBS) $(LIBS)
$(tests): ../lib/libevent.a $(tests): ../lib/libevent.a
clean: clean:
......
/* test-sched-produce.c: Test event scheduler, with attributes (producer).
This test may be used with test-consume or test-attr-consume. */
static char rcsid[] = "$Id: test-sched-produce.c,v 1.1 2002-01-29 17:24:59 imurdock Exp $";
#include <event.h>
int
main(int argc, char **argv)
{
event_handle_t handle;
event_notification_t notification;
char *server = NULL;
int c;
struct timeval time;
/* Get current time: */
gettimeofday(&time, NULL);
TRACE("time.tv_sec = %ld, time.tv_usec = %ld\n",
time.tv_sec,
time.tv_usec);
while ((c = getopt(argc, argv, "s:")) != -1) {
switch (c) {
case 's':
server = optarg;
break;
default:
fprintf(stderr, "Usage: %s [-s SERVER]\n", argv[0]);
return 1;
}
}
/* Register with the event system: */
handle = event_register(server);
if (handle == NULL) {
ERROR("could not register with event system\n");
return 1;
}
/* Generate a test event, with some attributes: */
notification = event_notification_alloc(handle, EVENT_HOST_ANY,
EVENT_TEST);
if (notification == NULL) {
ERROR("could not allocate notification\n");
return 1;
}
if (event_notification_put_double(handle, notification, "double", 1.23)
== 0)
{
ERROR("could not put double attribute\n");
return 1;
}
if (event_notification_put_int32(handle, notification, "int32", 123)
== 0)
{
ERROR("could not put int32 attribute\n");
return 1;
}
if (event_notification_put_int64(handle, notification, "int64",
100000000000)
== 0)
{
ERROR("could not put int64 attribute\n");
return 1;
}
if (event_notification_put_opaque(handle, notification, "opaque", &time,
sizeof(time))
== 0)
{
ERROR("could not put opaque attribute\n");
return 1;
}
if (event_notification_put_string(handle, notification, "string", "foo")
== 0)
{
ERROR("could not put string attribute\n");
return 1;
}
/* Schedule the event to fire in 5 seconds: */
time.tv_sec += 5;
if (event_schedule(handle, notification, &time) == 0) {
ERROR("could not send test event notification\n");
return 1;
}
event_notification_free(handle, notification);
/* Unregister with the event system: */
if (event_unregister(handle) == 0) {
ERROR("could not unregister with event system\n");
return 1;
}
return 0;
}
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