00001 #include <kernel.h>
00002 #include <proc.h>
00003 #include <queue.h>
00004 #include <semaphore.h>
00005 #include <stdio.h>
00006
00007 extern void testPass(const char *);
00008 extern void testFail(const char *);
00009
00010 int test_procQueue(int argc, char **argv)
00011 {
00012 semaphore s;
00013 queue q;
00014 bool passed = TRUE;
00015 int apid, bpid, cpid, dpid;
00016 char msg[50];
00017
00018 printf("Test Suite: Process Queues\n");
00019
00020
00021 s = newsem(0);
00022
00023 if (isbadsem(s))
00024 {
00025 passed = FALSE;
00026 sprintf(msg, "No semaphore, %d", s);
00027 testFail(msg);
00028 }
00029
00030 q = semtab[s].queue;
00031
00032
00033
00034 apid = create((void *)NULL, INITSTK, 0, "PQUEUE-A", 0);
00035 bpid = create((void *)NULL, INITSTK, 0, "PQUEUE-B", 0);
00036 cpid = create((void *)NULL, INITSTK, 0, "PQUEUE-C", 0);
00037 dpid = create((void *)NULL, INITSTK, 0, "PQUEUE-D", 0);
00038
00039 if ((SYSERR == apid) || (SYSERR == bpid)
00040 || (SYSERR == cpid) || (SYSERR == dpid))
00041 { passed = FALSE; }
00042
00043 printf(" Priority sorting");
00044 insert(cpid, q, 5);
00045 insert(bpid, q, 6);
00046 insert(dpid, q, 4);
00047 insert(apid, q, 7);
00048
00049 if ( (7 == firstkey(q)) && (apid = dequeue(q))
00050 && (6 == firstkey(q)) && (bpid = dequeue(q))
00051 && (5 == firstkey(q)) && (cpid = dequeue(q))
00052 && (4 == firstkey(q)) && (dpid = dequeue(q)) )
00053 { testPass(""); }
00054 else
00055 { passed = FALSE; testFail("insert out of order"); }
00056
00057 while (EMPTY != dequeue(q))
00058 ;
00059
00060 printf(" Same priority");
00061 insert(apid, q, 5);
00062 insert(bpid, q, 5);
00063 insert(cpid, q, 5);
00064 insert(dpid, q, 5);
00065
00066 if ( (5 == firstkey(q)) && (apid = dequeue(q))
00067 && (5 == firstkey(q)) && (bpid = dequeue(q))
00068 && (5 == firstkey(q)) && (cpid = dequeue(q))
00069 && (5 == firstkey(q)) && (dpid = dequeue(q)) )
00070 { testPass(""); }
00071 else
00072 { passed = FALSE; testFail("insert out of order"); }
00073
00074 while (EMPTY != dequeue(q))
00075 ;
00076
00077 kill(apid);
00078 kill(bpid);
00079 kill(cpid);
00080 kill(dpid);
00081
00082 freesem(s);
00083
00084 if (TRUE == passed)
00085 { testPass(""); }
00086 else
00087 { testFail(""); }
00088
00089 return OK;
00090 }