sys/arch/x86/include updates
[minix.git] / test / safecopy / requestor.c
blob4c1ef9b682af92eb3ed694632c6a7b60716d45ea
1 #include "inc.h"
3 char buf_buf[BUF_SIZE + CLICK_SIZE];
5 endpoint_t ep_granter;
6 int gid;
7 char *buf;
9 /*===========================================================================*
10 * test *
11 *===========================================================================*/
12 int test(size_t size)
14 u32_t low1, high1;
15 u32_t low2, high2;
16 int r;
18 /* Timing. */
19 read_tsc(&high1, &low1);
20 r = sys_safecopyfrom(ep_granter, gid, 0, (long)buf, size);
21 read_tsc(&high2, &low2);
22 if(r != OK) {
23 printf("REQUESTOR: error in safecopy: %d\n", r);
24 return r;
26 printf("REQUESTOR: SAFECOPY 0x%-8x - %d\n", size, low2 - low1);
28 /* Test. */
29 if(buf[0] != BUF_START) {
30 printf("REQUESTOR: error in safecopy!\n");
31 printf(" size, value: %d, %d\n", size, buf[0]);
32 return r;
35 return OK;
38 /* SEF functions and variables. */
39 static void sef_local_startup(void);
41 /*===========================================================================*
42 * main *
43 *===========================================================================*/
44 int main(int argc, char **argv)
46 endpoint_t ep_self;
47 int fid_send, fid_get;
48 int i;
50 /* SEF local startup. */
51 env_setargs(argc, argv);
52 sef_local_startup();
54 /* Prepare work. */
55 buf = (char*) CLICK_CEIL(buf_buf);
56 fid_get = open(FIFO_GRANTOR, O_RDONLY);
57 fid_send = open(FIFO_REQUESTOR, O_WRONLY);
58 if(fid_get < 0 || fid_send < 0) {
59 printf("REQUESTOR: can't open fifo files.\n");
60 return 1;
63 /* Sending the endpoint to the granter, in order to let him
64 * create the grant.
66 ep_self = getprocnr();
67 write(fid_send, &ep_self, sizeof(ep_self));
68 dprint("REQUESTOR: sending my endpoint: %d\n", ep_self);
70 /* Getting the granter's endpoint and gid. */
71 read(fid_get, &ep_granter, sizeof(ep_granter));
72 read(fid_get, &gid, sizeof(gid));
73 dprint("REQUESTOR: getting granter's endpoint %d and gid %d\n",
74 ep_granter, gid);
76 /* Test SAFECOPY. */
77 for(i = 0; i <= TEST_PAGE_SHIFT; i++) {
78 if(test(1 << i) != OK)
79 break;
82 /* Notify grantor we are done. */
83 FIFO_NOTIFY(fid_send);
85 return 0;
88 /*===========================================================================*
89 * sef_local_startup *
90 *===========================================================================*/
91 static void sef_local_startup()
93 /* Let SEF perform startup. */
94 sef_startup();