00001 #include <kernel.h>
00002 #include <proc.h>
00003 #include <semaphore.h>
00004 #include <stdio.h>
00005
00006 extern void testPass(const char *);
00007 extern void testFail(const char *);
00008
00009 extern bool test_checkSemCount(semaphore s, short c);
00010 extern bool test_checkProcState(ushort pid, uchar state);
00011 extern bool test_checkResult(uchar testResult, uchar expected);
00012
00013 extern void test_semWaiter(semaphore s, int times, uchar *testResult);
00014
00015 int test_semaphore4(int argc, char **argv)
00016 {
00017 int apid;
00018 bool passed = TRUE;
00019 semaphore s;
00020 uchar testResult = 0;
00021 char msg[50];
00022
00023 printf("Test Suite: Semaphore Interruption\n");
00024
00025 printf(" Semaphore creation: ");
00026 s = newsem(0);
00027 if (isbadsem(s))
00028 {
00029 passed = FALSE;
00030 sprintf(msg, "%d", s);
00031 testFail(msg);
00032 }
00033 else if (test_checkSemCount(s, 0))
00034 { testPass(""); }
00035 else
00036 { passed = FALSE; }
00037
00038 ready(apid = create((void *)test_semWaiter, INITSTK, 31, "SEMAPHORE-A",
00039 3, s, 1, &testResult), RESCHED_YES);
00040
00041 printf(" Wait on semaphore: ");
00042 if ( test_checkProcState(apid, PRWAIT)
00043 && test_checkSemCount(s, -1)
00044 && test_checkResult(testResult, 0) )
00045 { testPass(""); }
00046 else
00047 { passed = FALSE; }
00048
00049 kill(apid);
00050
00051 printf(" Kill waiting process: ");
00052 if ( test_checkProcState(apid, PRFREE)
00053 && test_checkSemCount(s, 0)
00054 && test_checkResult(testResult, 0) )
00055 { testPass(""); }
00056 else
00057 { passed = FALSE; }
00058
00059 if (TRUE == passed)
00060 { testPass(""); }
00061 else
00062 { testFail(""); }
00063
00064 freesem(s);
00065
00066 return OK;
00067 }
00068