|
|
1.1 root 1: /* test.c - main */
2:
3: #include <conf.h>
4: #include <kernel.h>
5:
6: #define CIRCUIT 1000
7:
8: /*------------------------------------------------------------------------
9: * main -- current test routines
10: *------------------------------------------------------------------------
11: */
12: main()
13: {
14: int ctr, succpid;
15: int ringnode(), startnode();
16:
17: succpid = getpid();
18: for (ctr=0; ctr<NPROC-2; ctr++) {
19: succpid = create (ringnode, 500, 19, "ringnode", 1, succpid);
20: if (succpid != SYSERR)
21: resume (succpid);
22: else{
23: kprintf("error creating ring node\n");
24: break;
25: }
26: }
27: chprio (getpid(), 19);
28: startnode(succpid);
29: }
30:
31: ringnode(succpid)
32: int succpid;
33: {
34: int ctr, inval, predpid;
35:
36: /* send messages around ring CIRCUIT times */
37: for (ctr = 0; ctr < CIRCUIT; ctr++) {
38: inval = receive();
39: while (send(succpid, inval) == SYSERR) {
40: kprintf ("error sending\n");
41: sleep(1);
42: }
43: }
44: /* now each node tells its successor its pid */
45: while (send(succpid, getpid()) == SYSERR) {
46: kprintf("error sending\n");
47: sleep(1);
48: }
49: predpid = receive();
50: /* switch directions and send messages around ring CIRCUIT times */
51: for (ctr = 0; ctr < CIRCUIT; ctr++) {
52: inval = receive();
53: while (send(predpid, inval) == SYSERR) {
54: kprintf("error sending\n");
55: sleep(1);
56: }
57: }
58: }
59:
60: startnode(succpid)
61: int succpid;
62: {
63: int ctr, inval, predpid;
64:
65: /* send messages through ring CIRCUIT times */
66: kprintf("sending %d messages around ring\n", CIRCUIT);
67: for (ctr = 0; ctr < CIRCUIT; ctr++) {
68: while (send(succpid, ctr) == SYSERR) {
69: kprintf ("error sending\n");
70: sleep(1);
71: }
72: if ((inval = receive()) != ctr)
73: kprintf ("bad message\n");
74: }
75: kprintf("reversing ring direction\n");
76: /* now each node tells its successor its pid */
77: while (send(succpid, getpid()) == SYSERR) {
78: kprintf("error sending\n");
79: sleep(1);
80: }
81: predpid = receive(predpid);
82: /* switch directions and send messages around ring CIRCUIT times */
83: kprintf("sending %d messages around ring in reversed direction\n", CIRCUIT);
84: for (ctr = 0; ctr < CIRCUIT; ctr++) {
85: while (send(predpid, ctr) == SYSERR) {
86: kprintf("error sending\n");
87: sleep(1);
88: }
89: if ((inval = receive()) != ctr)
90: kprintf("bad message\n");
91: }
92: kprintf("done with message passing test\n");
93: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.