Merge branches 'hammer2' and 'master' of ssh://crater.dragonflybsd.org/repository...
[dragonfly.git] / test / sysmsg / sysmsg2.c
CommitLineData
6b055cd4
MD
1/*
2 * sysmsg2.c
3 *
a4523e75 4 * $DragonFly: src/test/sysmsg/sysmsg2.c,v 1.3 2004/09/02 11:21:12 eirikn Exp $
6b055cd4
MD
5 */
6
6b055cd4 7#include <time.h>
a4523e75
EN
8
9#include "syscall.h"
10
11__attribute__((weak))
6b055cd4
MD
12
13int
a4523e75 14write_test(int fd, void * buf, size_t nbyte)
6b055cd4 15{
a4523e75
EN
16 struct write_args writemsg;
17 int error;
6b055cd4 18
a4523e75
EN
19 INITMSGSYSCALL(write, MSGF_ASYNC);
20 writemsg.fd = fd;
21 writemsg.buf = buf;
22 writemsg.nbyte = nbyte;
23 DOMSGSYSCALL(write);
24 printf("write: error: %d\n", error);
25 printf("write: ms_error: %d\n", writemsg.usrmsg.umsg.ms_error);
26 printf("write: ms_result: %d\n", writemsg.usrmsg.umsg.u.ms_result);
27 FINISHMSGSYSCALL(write, error);
28}
6b055cd4 29
a4523e75
EN
30int
31nanosleep_test(const struct timespec * rqtp, struct timespec * rmtp)
32{
33 struct nanosleep_args nanosleepmsg;
34 int error;
6b055cd4 35
a4523e75
EN
36 INITMSGSYSCALL(nanosleep, MSGF_ASYNC);
37 nanosleepmsg.rqtp = rqtp;
38 nanosleepmsg.rmtp = rmtp;
39 DOMSGSYSCALL(nanosleep);
40 printf("nanosleep: error: %d\n", error);
41 printf("nanosleep: ms_error: %d\n", nanosleepmsg.usrmsg.umsg.ms_error);
42 printf("nanosleep: ms_result: %d\n", nanosleepmsg.usrmsg.umsg.u.ms_result);
43 FINISHMSGSYSCALL(nanosleep, error);
6b055cd4
MD
44}
45
a4523e75
EN
46int
47main(void)
48{
49 struct timespec ts, ts2;
50 int error;
51
52 printf("test synchronous syscall msg write 'hello!', with async hint\n");
53 printf("test ASynchronous syscall msg nanosleep for 1.5 seconds\n");
54 printf("WARNING! super-user only, do not ^C the test program!\n");
55 error = write_test(1, "hello!\n", 7);
56 if (error == -1)
57 err(1, "write");
58 ts.tv_sec = 1;
59 ts.tv_nsec = 500 * 1000000;
60 error = nanosleep_test(&ts, &ts2);
61 if (error == -1)
62 err(1, "nanosleep");
63}