Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
emulab
emulab-devel
Commits
bd3c351e
Commit
bd3c351e
authored
Nov 02, 2001
by
Ian Murdock
Browse files
Added test cases for event library.
parent
b30d583b
Changes
5
Hide whitespace changes
Inline
Side-by-side
event/test/Makefile
0 → 100644
View file @
bd3c351e
# Makefile for building event system tests
#
# $Id: Makefile,v 1.1 2001-11-02 04:47:14 imurdock Exp $
CC
=
gcc
CFLAGS
=
-g
-I
.
-I
../lib
-Wall
-DDEBUG
LDFLAGS
=
LIBS
=
-L
../lib
-levent
CFLAGS
+=
`
elvin-config
--cflags
`
LIBS
+=
`
elvin-config
--libs
`
MV
=
mv
-f
RM
=
rm
-f
tests
=
test-consume
\
test-produce
\
test-attr-consume
\
test-attr-produce
%
:
%.c
$(CC)
$(LDFLAGS)
-o
$@
$(CFLAGS)
$<
$(LIBS)
$(LIBS)
default
:
$(tests)
clean
:
$(RM)
$(tests)
$(
addsuffix
.o,
$(tests)
)
distclean
:
clean
$(tests)
:
../lib/libevent.a
event/test/test-attr-consume.c
0 → 100644
View file @
bd3c351e
/* test-consume.c: Test delivery of events, with attributes (consumer). */
static
char
rcsid
[]
=
"$Id: test-attr-consume.c,v 1.1 2001-11-02 04:47:14 imurdock Exp $"
;
#include
<event.h>
static
void
callback
(
event_handle_t
handle
,
event_notification_t
notification
,
void
*
data
);
int
main
(
int
argc
,
char
**
argv
)
{
event_handle_t
handle
;
/* Register with the event system: */
handle
=
event_register
();
if
(
handle
==
NULL
)
{
ERROR
(
"could not register with event system
\n
"
);
return
1
;
}
/* Subscribe to the test event: */
if
(
event_subscribe
(
handle
,
callback
,
EVENT_TEST
,
"event received"
)
==
NULL
)
{
ERROR
(
"could not subscribe to test event
\n
"
);
return
1
;
}
/* Begin the event loop, waiting to receive event notifications: */
event_main
(
handle
);
/* Unregister with the event system: */
if
(
event_unregister
(
handle
)
==
0
)
{
ERROR
(
"could not unregister with event system
\n
"
);
return
1
;
}
return
0
;
}
static
void
callback
(
event_handle_t
handle
,
event_notification_t
notification
,
void
*
data
)
{
char
*
message
=
(
char
*
)
data
;
char
*
host
;
event_type_t
type
;
double
attr_double
;
int32_t
attr_int32
;
int64_t
attr_int64
;
char
*
attr_string
;
TRACE
(
"the message is: %s
\n
"
,
message
);
if
(
event_notification_attr_get
(
handle
,
notification
,
EVENT_ATTR_STRING
,
"host"
,
(
event_attr_value_t
*
)
&
host
)
==
0
)
{
ERROR
(
"could not get host attribute
\n
"
);
return
;
}
TRACE
(
"host: %s
\n
"
,
host
);
if
(
event_notification_attr_get
(
handle
,
notification
,
EVENT_ATTR_STRING
,
"type"
,
(
event_attr_value_t
*
)
&
type
)
==
0
)
{
ERROR
(
"could not get type attribute
\n
"
);
return
;
}
TRACE
(
"type: %d
\n
"
,
type
);
if
(
event_notification_attr_get
(
handle
,
notification
,
EVENT_ATTR_DOUBLE
,
"double"
,
(
event_attr_value_t
*
)
&
attr_double
)
==
0
)
{
ERROR
(
"could not get double attribute
\n
"
);
return
;
}
TRACE
(
"double: %f
\n
"
,
attr_double
);
if
(
event_notification_attr_get
(
handle
,
notification
,
EVENT_ATTR_DOUBLE
,
"int32"
,
(
event_attr_value_t
*
)
&
attr_int32
)
==
0
)
{
ERROR
(
"could not get int32 attribute
\n
"
);
return
;
}
TRACE
(
"int32: %d
\n
"
,
attr_int32
);
if
(
event_notification_attr_get
(
handle
,
notification
,
EVENT_ATTR_DOUBLE
,
"int64"
,
(
event_attr_value_t
*
)
&
attr_int64
)
==
0
)
{
ERROR
(
"could not get int64 attribute
\n
"
);
return
;
}
TRACE
(
"int64: %lld
\n
"
,
attr_int64
);
if
(
event_notification_attr_get
(
handle
,
notification
,
EVENT_ATTR_DOUBLE
,
"string"
,
(
event_attr_value_t
*
)
&
attr_string
)
==
0
)
{
ERROR
(
"could not get string attribute
\n
"
);
return
;
}
TRACE
(
"string:
\"
%s
\"\n
"
,
attr_string
);
}
event/test/test-attr-produce.c
0 → 100644
View file @
bd3c351e
/* test-attr-produce.c: Test delivery of events, with attributes (producer). */
static
char
rcsid
[]
=
"$Id: test-attr-produce.c,v 1.1 2001-11-02 04:47:14 imurdock Exp $"
;
#include
<event.h>
int
main
(
int
argc
,
char
**
argv
)
{
event_handle_t
handle
;
event_notification_t
notification
;
/* Register with the event system: */
handle
=
event_register
();
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_attr_put
(
handle
,
notification
,
EVENT_ATTR_DOUBLE
,
"double"
,
(
event_attr_value_t
)
1
.
23
)
==
0
)
{
ERROR
(
"could not put double attribute
\n
"
);
return
1
;
}
if
(
event_notification_attr_put
(
handle
,
notification
,
EVENT_ATTR_INT32
,
"int32"
,
(
event_attr_value_t
)
123
)
==
0
)
{
ERROR
(
"could not put int32 attribute
\n
"
);
return
1
;
}
if
(
event_notification_attr_put
(
handle
,
notification
,
EVENT_ATTR_INT64
,
"int64"
,
(
event_attr_value_t
)
100000000000
)
==
0
)
{
ERROR
(
"could not put int64 attribute
\n
"
);
return
1
;
}
if
(
event_notification_attr_put
(
handle
,
notification
,
EVENT_ATTR_STRING
,
"string"
,
(
event_attr_value_t
)
"foo"
)
==
0
)
{
ERROR
(
"could not put string attribute
\n
"
);
return
1
;
}
if
(
event_notify
(
handle
,
notification
)
==
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
;
}
event/test/test-consume.c
0 → 100644
View file @
bd3c351e
/* test-consume.c: Test delivery of events (consumer). */
static
char
rcsid
[]
=
"$Id: test-consume.c,v 1.1 2001-11-02 04:47:14 imurdock Exp $"
;
#include
<event.h>
static
void
callback
(
event_handle_t
handle
,
event_notification_t
notification
,
void
*
data
);
int
main
(
int
argc
,
char
**
argv
)
{
event_handle_t
handle
;
/* Register with the event system: */
handle
=
event_register
();
if
(
handle
==
NULL
)
{
ERROR
(
"could not register with event system
\n
"
);
return
1
;
}
/* Subscribe to the test event: */
if
(
event_subscribe
(
handle
,
callback
,
EVENT_TEST
,
"event received"
)
==
NULL
)
{
ERROR
(
"could not subscribe to test event
\n
"
);
return
1
;
}
/* Begin the event loop, waiting to receive event notifications: */
event_main
(
handle
);
/* Unregister with the event system: */
if
(
event_unregister
(
handle
)
==
0
)
{
ERROR
(
"could not unregister with event system
\n
"
);
return
1
;
}
return
0
;
}
static
void
callback
(
event_handle_t
handle
,
event_notification_t
notification
,
void
*
data
)
{
char
*
message
=
(
char
*
)
data
;
char
*
host
;
event_type_t
type
;
TRACE
(
"the message is: %s
\n
"
,
message
);
if
(
event_notification_attr_get
(
handle
,
notification
,
EVENT_ATTR_STRING
,
"host"
,
(
event_attr_value_t
*
)
&
host
)
==
0
)
{
ERROR
(
"could not get host attribute
\n
"
);
return
;
}
TRACE
(
"host: %s
\n
"
,
host
);
if
(
event_notification_attr_get
(
handle
,
notification
,
EVENT_ATTR_STRING
,
"type"
,
(
event_attr_value_t
*
)
&
type
)
==
0
)
{
ERROR
(
"could not get type attribute
\n
"
);
return
;
}
TRACE
(
"type: %d
\n
"
,
type
);
}
event/test/test-produce.c
0 → 100644
View file @
bd3c351e
/* test-produce.c: Test delivery of events (producer). */
static
char
rcsid
[]
=
"$Id: test-produce.c,v 1.1 2001-11-02 04:47:14 imurdock Exp $"
;
#include
<event.h>
int
main
(
int
argc
,
char
**
argv
)
{
event_handle_t
handle
;
event_notification_t
notification
;
/* Register with the event system: */
handle
=
event_register
();
if
(
handle
==
NULL
)
{
ERROR
(
"could not register with event system
\n
"
);
return
1
;
}
/* Generate a test event: */
notification
=
event_notification_alloc
(
handle
,
EVENT_HOST_ANY
,
EVENT_TEST
);
if
(
notification
==
NULL
)
{
ERROR
(
"could not allocate notification
\n
"
);
return
1
;
}
if
(
event_notify
(
handle
,
notification
)
==
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
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment