lapic timer: Reimplement set_apic_timer using lapic_timer_oneshot
[dragonfly.git] / test / caps / caps1.c
blobb1f00d5521bf776dbf8bca077d6ca0f8a47e2386
1 /*
2 * CAPS1.C
4 * Simple IPC test. /tmp/cs1 -s in one window, /tmp/cs1 -c in another.
6 * $DragonFly: src/test/caps/caps1.c,v 1.1 2003/11/24 21:15:59 dillon Exp $
7 */
8 #include <sys/types.h>
9 #include <libcaps/globaldata.h>
10 #include <sys/thread.h>
11 #include <sys/msgport.h>
12 #include <sys/msgport2.h>
13 #include <sys/thread2.h>
14 #include <sys/caps.h>
15 #include <stdio.h>
16 #include <signal.h>
18 int
19 main(int ac, char **av)
21 caps_port_t port;
22 lwkt_msg_t msg;
23 struct lwkt_port replyport;
24 struct lwkt_msg junkmsg;
25 int i;
26 int r;
27 int quietOpt = 0;
28 enum { UNKNOWN, CLIENT, SERVER } mode;
30 signal(SIGPIPE, SIG_IGN);
32 for (i = 1; i < ac; ++i) {
33 char *ptr = av[i];
34 if (*ptr != '-')
35 continue;
36 ptr += 2;
37 switch(ptr[-1]) {
38 case 's':
39 mode = SERVER;
40 break;
41 case 'c':
42 mode = CLIENT;
43 break;
44 case 'q':
45 quietOpt = (*ptr) ? strtol(ptr, NULL, 0) : 1;
46 break;
50 switch(mode) {
51 case SERVER:
52 port = caps_service("test", -1, 0666, 0);
53 if (quietOpt == 0)
54 printf("caps_service port %p\n", port);
55 while ((msg = lwkt_waitport(&port->lport, NULL)) != NULL) {
56 if (quietOpt == 0) {
57 printf("received msg %p %08x\n", msg, msg->ms_flags);
58 printf("replyport: %p %p\n",
59 msg->ms_reply_port, msg->ms_reply_port->mp_replyport);
61 msg->u.ms_result = ~msg->u.ms_result;
62 lwkt_replymsg(msg, 23);
64 break;
65 case CLIENT:
66 lwkt_initport(&replyport, curthread);
67 port = caps_client("test", -1, 0);
68 if (quietOpt == 0)
69 printf("caps_client port %p msg %p\n", port, &junkmsg);
70 if (port == NULL) {
71 printf("failed to connect\n");
72 exit(1);
74 for (i = 0; ; ++i) {
75 lwkt_initmsg(&junkmsg, &replyport, 0);
76 junkmsg.u.ms_result = i;
77 junkmsg.ms_msgsize = sizeof(junkmsg);
78 junkmsg.ms_maxsize = sizeof(junkmsg);
79 lwkt_beginmsg(&port->lport, &junkmsg);
80 if (caps_client_waitreply(port, &junkmsg) == NULL) {
81 printf("client failed\n");
82 break;
84 if (quietOpt == 0) {
85 printf("reply: error=%d/23 res=%d/%d\n",
86 junkmsg.ms_error, ~junkmsg.u.ms_result, i);
87 } else if (quietOpt == 1 && (i & 65535) == 0) {
88 printf("reply: error=%d/23 res=%d/%d\n",
89 junkmsg.ms_error, ~junkmsg.u.ms_result, i);
92 break;
94 printf("exit\n");
95 return(0);