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 t5(int times, uchar *testArray, int *index)
00009 {
00010 if (times > 0)
00011 {
00012 testArray[*index] = currpid;
00013 *index = *index + 1;
00014 testArray[*index] = times;
00015 *index = *index + 1;
00016 resched();
00017 t5(times - 1, testArray, index);
00018 }
00019 }
00020
00021 #define TIMES 5
00022
00023
00024
00025
00026
00027 int test_recursion(int argc, char **argv)
00028 {
00029 int apid, bpid, cpid, dpid, i, j;
00030 bool passed = TRUE;
00031 uchar testArray[100];
00032 int index = 0;
00033
00034 printf("Test Suite: Recursion");
00035 ready(apid = create((void *)t5, INITSTK, 31, "RECURSION-A",
00036 3, TIMES, testArray, &index), 0);
00037 ready(bpid = create((void *)t5, INITSTK, 32, "RECURSION-B",
00038 3, TIMES, testArray, &index), 0);
00039 ready(cpid = create((void *)t5, INITSTK, 34, "RECURSION-C",
00040 3, TIMES, testArray, &index), 0);
00041 ready(dpid = create((void *)t5, INITSTK, 32, "RECURSION-D",
00042 3, TIMES, testArray, &index), 0);
00043 resched();
00044
00045
00046
00047
00048 for (i = 0, j = TIMES; i < TIMES; i += 2, j--)
00049 {
00050 if (cpid != testArray[i])
00051 {
00052 passed = FALSE;
00053 printf(" Expected testArray[%d] == %d, not %d\n",
00054 i, cpid, testArray[i]);
00055 }
00056 if (j != testArray[i+1])
00057 {
00058 passed = FALSE;
00059 printf(" Expected testArray[%d] == %d, not %d\n",
00060 i+1, j, testArray[i+1]);
00061 }
00062 }
00063
00064 for (i = TIMES * 2, j = TIMES; i < 6 * TIMES; i += 4, j--)
00065 {
00066 if (bpid != testArray[i])
00067 {
00068 passed = FALSE;
00069 printf(" Expected testArray[%d] == %d, not %d\n",
00070 i, bpid, testArray[i]);
00071 }
00072 if (j != testArray[i+1])
00073 {
00074 passed = FALSE;
00075 printf(" Expected testArray[%d] == %d, not %d\n",
00076 i+1, j, testArray[i+1]);
00077 }
00078 }
00079
00080 for (i = TIMES * 2 + 2, j = TIMES; i < 6 * TIMES; i += 4, j--)
00081 {
00082 if (dpid != testArray[i])
00083 {
00084 passed = FALSE;
00085 printf(" Expected testArray[%d] == %d, not %d\n",
00086 i, dpid, testArray[i]);
00087 }
00088 if (j != testArray[i+1])
00089 {
00090 passed = FALSE;
00091 printf(" Expected testArray[%d] == %d, not %d\n",
00092 i+1, j, testArray[i+1]);
00093 }
00094 }
00095
00096 for (i = 6 * TIMES, j = TIMES; i < 8 * TIMES; i += 2, j--)
00097 {
00098 if (apid != testArray[i])
00099 {
00100 passed = FALSE;
00101 printf(" Expected testArray[%d] == %d, not %d\n",
00102 i, apid, testArray[i]);
00103 }
00104 if (j != testArray[i+1])
00105 {
00106 passed = FALSE;
00107 printf(" Expected testArray[%d] == %d, not %d\n",
00108 i+1, j, testArray[i+1]);
00109 }
00110 }
00111
00112 if (TRUE == passed)
00113 { testPass(""); }
00114 else
00115 { testFail(""); }
00116
00117 return OK;
00118 }
00119