00001 #include <kernel.h>
00002 #include <proc.h>
00003 #include <stdio.h>
00004
00005 extern void testPass(const char *);
00006 extern void testFail(const char *);
00007
00008 static void bigargs(uchar a, uchar b, uchar c, uchar d, uchar e, uchar f,
00009 uchar *testArray)
00010 {
00011 testArray[0] = a;
00012 testArray[1] = b;
00013 testArray[2] = c;
00014 testArray[3] = d;
00015 testArray[4] = e;
00016 testArray[5] = f;
00017 testArray[6] = a + b + c + d + e + f;
00018 return;
00019 }
00020
00021 static void t4(int times, uchar *testArray, int *shared)
00022 {
00023 int i = 0;
00024
00025 for (i = 0; i < times; i++)
00026 {
00027 testArray[*shared] = currpid;
00028 *shared = *shared + 1;
00029 resched();
00030 }
00031 }
00032
00033
00034
00035
00036
00037 int test_bigargs(int argc, char **argv)
00038 {
00039 uchar testArray[20];
00040 printf("Test Suite: More than four arguments");
00041
00042 ready(create((void *)bigargs, INITSTK, 31, "BIGARGS",
00043 7, 10, 20, 30, 40, 50, 60, testArray), RESCHED_YES);
00044
00045 if ((10 == testArray[0])
00046 && (20 == testArray[1])
00047 && (30 == testArray[2])
00048 && (40 == testArray[3])
00049 && (50 == testArray[4])
00050 && (60 == testArray[5])
00051 && (210 == testArray[6]))
00052 { testPass(""); }
00053 else
00054 { testFail(""); }
00055
00056 return OK;
00057 }
00058
00059 #define TIMES 5
00060
00061 int test_schedule(int argc, char **argv)
00062 {
00063 uchar testArray[20];
00064 int shared = 0;
00065
00066 int apid, bpid, cpid, dpid, i;
00067 bool passed = TRUE;
00068
00069 printf("Test Suite: Priority Scheduling");
00070 ready(apid = create((void *)t4, INITSTK, 31, "PRIORITY-A",
00071 3, TIMES, testArray, &shared), 0);
00072 ready(bpid = create((void *)t4, INITSTK, 32, "PRIORITY-B",
00073 3, TIMES, testArray, &shared), 0);
00074 ready(cpid = create((void *)t4, INITSTK, 34, "PRIORITY-C",
00075 3, TIMES, testArray, &shared), 0);
00076 ready(dpid = create((void *)t4, INITSTK, 32, "PRIORITY-D",
00077 3, TIMES, testArray, &shared), 0);
00078 resched();
00079
00080 for (i = 0; i < TIMES; i++)
00081 {
00082 if (cpid != testArray[i])
00083 {
00084 passed = FALSE;
00085 printf(" Expected testArray[%d] == %d, not %d\n",
00086 i, cpid, testArray[i]);
00087 }
00088 }
00089
00090 for (i = TIMES; i < 3 * TIMES; i += 2)
00091 {
00092 if (bpid != testArray[i])
00093 {
00094 passed = FALSE;
00095 printf(" Expected testArray[%d] == %d, not %d\n",
00096 i, bpid, testArray[i]);
00097 }
00098 }
00099
00100 for (i = TIMES + 1; i < 3 * TIMES; i += 2)
00101 {
00102 if (dpid != testArray[i])
00103 {
00104 passed = FALSE;
00105 printf(" Expected testArray[%d] == %d, not %d\n",
00106 i, dpid, testArray[i]);
00107 }
00108 }
00109
00110 for (i = 3 * TIMES; i < 4 * TIMES; i++)
00111 {
00112 if (apid != testArray[i])
00113 {
00114 passed = FALSE;
00115 printf(" Expected testArray[%d] == %d, not %d\n",
00116 i, apid, testArray[i]);
00117 }
00118 }
00119
00120 if (TRUE == passed)
00121 { testPass(""); }
00122 else
00123 { testFail(""); }
00124
00125 return OK;
00126 }