extern "C" void badReceiver(void *arg) { epicsMessageQueue *q = (epicsMessageQueue *)arg; char cbuf[80]; int len; cbuf[0] = '\0'; len = q->receive(cbuf, 1); if (len < 0 && cbuf[0] == '\0') testPass("receive into undersized buffer returned error (%d)", len); else if (len == 1 && cbuf[0] == *msg1) testPass("receive into undersized buffer truncated message"); else testFail("receive into undersized buffer returned %d", len); epicsThreadSleep(3.0); cbuf[0] = '\0'; len = q->receive(cbuf, 1); if (len < 0 && cbuf[0] == '\0') testPass("receive into undersized buffer returned error (%d)", len); else if (len == 1 && cbuf[0] == *msg1) testPass("receive into undersized buffer truncated message"); else testFail("receive into undersized buffer returned %d", len); }
bool xpathplugin_xbn_and::testUnit() { return testPass("true() and true()" , 1, xbnode::xbn_temp, "true") & testPass("true() and false()" , 1, xbnode::xbn_temp, "false") & testPass("false() and true()" , 1, xbnode::xbn_temp, "false") & testPass("false() and false()" , 1, xbnode::xbn_temp, "false"); }
bool xpathplugin_xbn_or::testUnit() { return testPass("true() or true()" , 1, xbnode::xbn_temp, "true") | testPass("true() or false()" , 1, xbnode::xbn_temp, "true") | testPass("false() or true()" , 1, xbnode::xbn_temp, "true") | testPass("false() or false()" , 1, xbnode::xbn_temp, "false"); }
bool xpathplugin_round::testUnit() { return testPass( "round(1)", 1, xbnode::xbn_temp, "1" ) &testPass( "round(1.5)", 1, xbnode::xbn_temp, "2" ) &testPass( "round(1.4)", 1, xbnode::xbn_temp, "1" ) &testPass( "round(-1.5)", 1, xbnode::xbn_temp, "-2" ) &testPass( "round(-1.4)", 1, xbnode::xbn_temp, "-1" ); }
/* Action function for state "get" in state set "read_named" */ static void seqg_action_read_named_0_get(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { # line 37 "../pvGet.st" seq_efSet(seqg_env, ef_read_named); } return; case 1: { # line 40 "../pvGet.st" epicsMutexMustLock(mutex); # line 41 "../pvGet.st" seqg_var->seqg_vars_read_named.expected = shared; # line 42 "../pvGet.st" seq_pvGetTmo(seqg_env, 1/*named*/, ASYNC, DEFAULT_TIMEOUT); # line 43 "../pvGet.st" epicsMutexUnlock(mutex); # line 44 "../pvGet.st" if (seq_pvGetComplete(seqg_env, 1/*named*/)) { # line 46 "../pvGet.st" testOk(seqg_var->seqg_vars_read_named.expected == seqg_var->seqg_vars_read_named.named, "immediate completion: expected=%d==%d=named", seqg_var->seqg_vars_read_named.expected, seqg_var->seqg_vars_read_named.named); } else { # line 48 "../pvGet.st" testPass("no immediate completion"); } # line 50 "../pvGet.st" epicsThreadSleep(0.1); # line 51 "../pvGet.st" if (seq_pvGetComplete(seqg_env, 1/*named*/)) { # line 53 "../pvGet.st" testOk(seqg_var->seqg_vars_read_named.expected == seqg_var->seqg_vars_read_named.named, "completion after delay: expected=%d==%d=named", seqg_var->seqg_vars_read_named.expected, seqg_var->seqg_vars_read_named.named); } else { # line 55 "../pvGet.st" testPass("no completion after delay"); } } return; } }
/* Action function for state "get" in state set "read_anon" */ static void seqg_action_read_anon_1_get(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { # line 77 "../pvGet.st" seq_efSet(seqg_env, ef_read_anon); } return; case 1: { # line 80 "../pvGet.st" epicsMutexMustLock(mutex); # line 81 "../pvGet.st" seqg_var->seqg_vars_read_anon.expected = shared; # line 82 "../pvGet.st" seq_pvGetTmo(seqg_env, 0/*anon*/, ASYNC, DEFAULT_TIMEOUT); # line 83 "../pvGet.st" epicsMutexUnlock(mutex); # line 84 "../pvGet.st" if (seq_pvGetComplete(seqg_env, 0/*anon*/)) { # line 86 "../pvGet.st" testOk(seqg_var->seqg_vars_read_anon.expected == seqg_var->anon, "immediate completion: expected=%d==%d=anon", seqg_var->seqg_vars_read_anon.expected, seqg_var->anon); } else { # line 88 "../pvGet.st" testPass("no immediate completion"); } # line 90 "../pvGet.st" epicsThreadSleep(0.1); # line 91 "../pvGet.st" if (seq_pvGetComplete(seqg_env, 0/*anon*/)) { # line 93 "../pvGet.st" testOk(seqg_var->seqg_vars_read_anon.expected == seqg_var->anon, "completion after delay: expected=%d==%d=anon", seqg_var->seqg_vars_read_anon.expected, seqg_var->anon); } else { # line 95 "../pvGet.st" testPass("no completion after delay"); } } return; } }
/* Entry function for state "check_msg" in state set "check" */ static void seqg_entry_check_1_check_msg(SS_ID seqg_env) { # line 103 "../opttVar.st" seqg_var->seqg_vars_check.xp = seqg_var->seqg_vars_check.expected; # line 104 "../opttVar.st" testPass("start 1st round..."); }
/** * Test for ethernet loopback (ethloop) driver packet acceptance. */ thread test_ethloop(bool verbose) { #if NETHLOOP /* the failif macro depends on 'passed' and 'verbose' vars */ bool passed = TRUE; int i; for (i = 0; i < NETHLOOP; i++) { passed &= ethloopn_test(verbose, i + ELOOP); } /* always print out the overall tests status */ if (passed) { testPass(TRUE, ""); } else { testFail(TRUE, ""); } #else /* NETHLOOP */ testSkip(TRUE, ""); #endif /* !NETHLOOP */ return OK; }
/* Action function for state "check_msg" in state set "check" */ static void seqg_action_check_1_check_msg(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { # line 107 "../opttVar.st" seqg_var->seqg_vars_check.xp = seqg_var->seqg_vars_check.expected; # line 108 "../opttVar.st" testPass("one more time..."); # line 109 "../opttVar.st" seqg_var->seqg_vars_check.repeat = 0; } return; case 1: { } return; case 2: { # line 114 "../opttVar.st" testOk(strcmp(*seqg_var->seqg_vars_check.xp, seqg_var->msg) == 0, "msg=%s", seqg_var->msg); # line 115 "../opttVar.st" seqg_var->seqg_vars_check.xp++; } return; } }
void catchWrongTypeTestsInitialPass(ParamVal *param, const char* fcnName, ParamValWrongType *e ){ testPass("Should not be able to %s on %s\n %s", fcnName, param->getTypeName(), e->what()); testOk(!param->isDefined(), "%s value should be undefined after initial %s", param->getName(), fcnName); testOk(!param->hasValueChanged(), "%s value should report value " "not changed after initial %s", param->getName(), fcnName); }
void assertTest(void *given, void *expected, char info[]) { if (given == expected) { testPass(info); } else { testFail(info, given, expected); } }
/* Action function for state "done" in state set "reassign" */ static void A_reassign_0_done(SS_ID ssId, struct UserVar *pVar, int transNum, int *pNextState) { switch(transNum) { case 0: { # line 90 "../reassign.st" testPass("ok"); } return; } }
static void toolate(void *arg, epicsJobMode mode) { epicsJob *job=arg; if(mode==epicsJobModeCleanup){ epicsJobDestroy(job); return; } testPass("Job runs"); numtoolate++; epicsEventSignal(cancel[0]); epicsEventMustWait(cancel[1]); }
/* Action function for state "get_async" in state set "pvGetAsync" */ static void A_pvGetAsync_0_get_async(SS_ID ssId, struct UserVar *pVar, int transNum, int *pNextState) { switch(transNum) { case 0: { # line 30 "../pvGetAsync.st" testPass("pvGet completed %d times", 100000); } return; case 1: { } return; } }
/* Action function for state "check_not_set" in state set "myss" */ static void seqg_action_myss_0_check_not_set(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { # line 29 "../userfuncEf.st" testFail("argh, no timeout!"); } return; case 1: { # line 32 "../userfuncEf.st" testPass("cool, we came here"); } return; } }
/*------------------------------------------------------------------------ * main -- user main program *------------------------------------------------------------------------ */ int test_bigargs(int argc, char **argv) { uchar testArray[20]; printf("Test Suite: More than four arguments"); ready(create((void *)bigargs, INITSTK, 31, "BIGARGS", 7, 10, 20, 30, 40, 50, 60, testArray), RESCHED_YES); if ((10 == testArray[0]) && (20 == testArray[1]) && (30 == testArray[2]) && (40 == testArray[3]) && (50 == testArray[4]) && (60 == testArray[5]) && (210 == testArray[6])) { testPass(""); } else { testFail(""); } return OK; }
/* Action function for state "makeRequest" in state set "monitorEvflagTest" */ static void A_monitorEvflagTest_0_makeRequest(SS_ID ssId, struct UserVar *pVar, int transNum, int *pNextState) { switch(transNum) { case 0: { } return; case 1: { # line 38 "../monitorEvflag.st" testPass("no error in %d cycles", (20 * 500)); } return; case 2: { # line 41 "../monitorEvflag.st" pVar->requested = pVar->UserVar_monitorEvflagTest.cycleCount; # line 42 "../monitorEvflag.st" seq_pvPut(ssId, 0/*requested*/, 0); } return; } }
/* Action function for state "makeRequest" in state set "monitorEvflagTest" */ static void seqg_action_monitorEvflagTest_0_makeRequest(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { } return; case 1: { # line 38 "../monitorEvflag.st" testPass("no error in %d cycles", (20 * 500)); } return; case 2: { # line 41 "../monitorEvflag.st" seqg_var->requested = seqg_var->seqg_vars_monitorEvflagTest.cycleCount; # line 42 "../monitorEvflag.st" seq_pvPutTmo(seqg_env, 0/*requested*/, DEFAULT, DEFAULT_TIMEOUT); } return; } }
/** * Tests the stdlib.h header in the Xinu Standard Library. * @return OK when testing is complete */ thread test_libStdlib(bool verbose) { int i; char list[10] = "BCADFEHGI"; bool passed = TRUE; /* atoi */ testPrint(verbose, "ASCII to integer"); failif((-456 != atoi("-456")) || (123 != atoi("+123")) || (2147483647 != atoi("2147483647")) || (-1 != atoi("-1one")) || (2 != atoi("+2two")) || (3 != atoi("3three")) || (0 != atoi("-on1e")) || (0 != atoi("+tw2o")) || (0 != atoi("thre3e")), ""); /* atol */ testPrint(verbose, "ASCII to long"); failif((-456 != atol("-456")) || (123 != atol("+123")) || (2147483647 != atol("2147483647")) || (-1 != atol("-1one")) || (2 != atol("+2two")) || (3 != atol("3three")) || (0 != atol("-one")) || (0 != atol("+two")) || (0 != atol("three")), ""); /* qsort */ testPrint(verbose, "Quick sort"); qsort(list, sizeof(list) - 1, 1, (void *)qsort_callback); failif((0 != strncmp(list, "ABCDEFGHI", sizeof(list))), ""); /* bzero */ testPrint(verbose, "bzero"); bzero(list, sizeof(list)); for (i = 0; i < sizeof(list); i++) { if ('\0' != *(list + i)) { testFail(verbose, ""); passed = FALSE; break; } } if (i == sizeof(list)) { testPass(verbose, ""); } /* abs */ testPrint(verbose, "Absolute value"); failif((2147483647 != abs(-2147483647)) || (123 != abs(123)) || (0 != abs(0)), ""); /* labs */ testPrint(verbose, "Long absolute value"); failif((2147483647 != labs(-2147483647)) || (123 != labs(123)) || (0 != labs(0)), ""); /* rand */ testPrint(verbose, "Random number generation"); failif((rand() == rand()) && (rand() == rand()) && (rand() == rand()) && (rand() == rand()), "that was unlikely"); /* malloc (in test_umemory.c) */ if (passed) { testPass(TRUE, ""); } else { testFail(TRUE, ""); } return OK; }
/** * Tests UDP * @return OK when testing is complete */ thread test_udp(bool verbose) { #ifdef UDP1 struct udp *udpptr = NULL; ushort pta; ushort ptb; struct netaddr ipc; struct netaddr ipd; struct netaddr ipl; struct netaddr src; struct netaddr dst; struct netaddr mask; struct netaddr ipzero; struct packet *pkt[10]; struct udpPkt *udppkt; struct udpPseudoHdr *pseudo; uchar buffera[12]; uchar bufferb[12]; uchar bufferc[12]; uchar bufferd[12]; uchar bufferp[40]; bool passed = TRUE; /* struct pcap_pkthdr phdr; struct netif *netptr; int nproc; int i; int wait; struct packet *pktA; uchar buf[100]; uchar *data; uchar *buffer; */ pta = 20000; ptb = 30000; /* IP address "C" */ ipc.type = NETADDR_IPv4; ipc.len = IPv4_ADDR_LEN; ipc.addr[0] = 192; ipc.addr[1] = 168; ipc.addr[2] = 1; ipc.addr[3] = 5; /* IP address "D" */ ipd.type = NETADDR_IPv4; ipd.len = IPv4_ADDR_LEN; ipd.addr[0] = 192; ipd.addr[1] = 168; ipd.addr[2] = 1; ipd.addr[3] = 7; /* "Local" IP address */ ipl.type = NETADDR_IPv4; ipl.len = IPv4_ADDR_LEN; ipl.addr[0] = 192; ipl.addr[1] = 168; ipl.addr[2] = 1; ipl.addr[3] = 8; /* Source IP address */ src.type = NETADDR_IPv4; src.len = IPv4_ADDR_LEN; src.addr[0] = 192; src.addr[1] = 168; src.addr[2] = 1; src.addr[3] = 6; /* Destination IP address */ dst.type = NETADDR_IPv4; dst.len = IPv4_ADDR_LEN; dst.addr[0] = 192; dst.addr[1] = 168; dst.addr[2] = 1; dst.addr[3] = 1; /* Mask */ mask.type = NETADDR_IPv4; mask.len = IPv4_ADDR_LEN; mask.addr[0] = 255; mask.addr[1] = 255; mask.addr[2] = 255; mask.addr[3] = 0; /* Empty address */ ipzero.type = 0; ipzero.len = 0; ipzero.addr[0] = 0; ipzero.addr[1] = 0; ipzero.addr[2] = 0; ipzero.addr[3] = 0; ipzero.addr[4] = 0; ipzero.addr[5] = 0; /* Test udpPkt structure */ //testPrint(verbose, "Header structure"); /* TODO: Figure out how this should be done */ /* Test udpOpen */ testPrint(verbose, "Open UDP devices (NULL local port)"); if (SYSERR == open(UDP0, &ipl, &ipd, NULL, ptb)) { failif(TRUE, ""); } if (SYSERR == open(UDP1, &ipl, &ipc, NULL, pta)) { failif(TRUE, ""); } failif((udptab[0].localpt == udptab[1].localpt) || (udptab[0].localpt < UDP_PSTART) || (udptab[0].localpt > UDP_PMAX) || (udptab[1].localpt < UDP_PSTART) || (udptab[1].localpt > UDP_PMAX), ""); if (SYSERR == close(UDP0)) { failif(TRUE, ""); } if (SYSERR == close(UDP1)) { failif(TRUE, ""); } /* Test udpOpen */ testPrint(verbose, "Open UDP device (NULL remote port)"); if (SYSERR == open(UDP0, &ipl, &ipd, pta, NULL)) { failif(TRUE, ""); } failif(udptab[0].remotept != NULL, ""); if (SYSERR == close(UDP0)) { failif(TRUE, ""); } /* Test udpOpen */ testPrint(verbose, "Open UDP device (NULL remote ip)"); if (SYSERR == open(UDP0, &ipl, NULL, pta, ptb)) { failif(TRUE, ""); } failif(0 == netaddrequal(&udptab[0].remoteip, &ipzero), ""); if (SYSERR == close(UDP0)) { failif(TRUE, ""); } /* Test udpOpen */ testPrint(verbose, "Open UDP devices (same local port)"); if (SYSERR == open(UDP0, &ipl, &ipd, pta, ptb)) { failif(TRUE, ""); } if (SYSERR == open(UDP1, &ipl, &ipd, pta, pta)) { failif(TRUE, ""); } failif(udptab[0].localpt != udptab[1].localpt, ""); /* Only close the second UDP device this time, we want to test close * using UDP0 */ if (SYSERR == close(UDP1)) { failif(TRUE, ""); } /* Test udpClose */ testPrint(verbose, "Close UDP device"); if (SYSERR == close(UDP0)) { failif(TRUE, ""); } failif((udptab[0].dev != 0) || (udptab[0].icount != 0) || (udptab[0].istart != 0) || (udptab[0].isem != 0) || (udptab[0].localpt != 0) || (udptab[0].remotept != 0) || (FALSE == netaddrequal(&udptab[0].localip, &ipzero)) || (FALSE == netaddrequal(&udptab[0].remoteip, &ipzero)) || (udptab[0].state != 0) || (udptab[0].flags != 0), ""); /* Test udpControl */ testPrint(verbose, "UDP Control: Binding"); /* Open UDP device to resume testing of that device */ if (SYSERR == open(UDP0, &ipl, NULL, NULL, NULL)) { failif(TRUE, ""); } control(UDP0, UDP_CTRL_ACCEPT, pta, (long)&ipl); control(UDP0, UDP_CTRL_BIND, ptb, (long)&ipc); failif((udptab[0].localpt != pta) || (FALSE == netaddrequal(&udptab[0].localip, &ipl)) || (udptab[0].remotept != ptb) || (FALSE == netaddrequal(&udptab[0].remoteip, &ipc)), ""); /* Test udpControl */ testPrint(verbose, "UDP Control: Flags"); control(UDP0, UDP_CTRL_SETFLAG, UDP_FLAG_PASSIVE | UDP_FLAG_NOBLOCK | UDP_FLAG_BINDFIRST, NULL); control(UDP0, UDP_CTRL_CLRFLAG, UDP_FLAG_NOBLOCK, NULL); /* At this point NOBLOCK should be the only flag that is off */ failif((FALSE == (udptab[0].flags & UDP_FLAG_PASSIVE)) || (udptab[0].flags & UDP_FLAG_NOBLOCK) || (FALSE == (udptab[0].flags & UDP_FLAG_BINDFIRST)), ""); /* Test udpDemux */ testPrint(verbose, "UDP Demux (2 sockets)"); open(UDP1, &ipl, NULL, pta, NULL); udpptr = udpDemux(pta, ptb, &ipl, &ipc); failif((udpptr == &udptab[1]) || (NULL == udpptr), ""); /* Test udpRecv and udpRead */ testPrint(verbose, "Receive and read UDP packets"); control(UDP0, UDP_CTRL_CLRFLAG, UDP_FLAG_PASSIVE | UDP_FLAG_BINDFIRST, NULL); control(UDP0, UDP_CTRL_ACCEPT, pta, (long)&ipl); control(UDP0, UDP_CTRL_BIND, ptb, (long)&ipc); pkt[0] = makePkt(ptb, pta, &ipl, &ipc, 5, "ABCDE"); pkt[1] = makePkt(ptb, pta, &ipl, &ipc, 4, "FGHI"); pkt[2] = makePkt(ptb, pta, &ipl, &ipc, 3, "JKL"); pkt[3] = makePkt(ptb, pta, &ipl, &ipc, 2, "MN"); if (SYSERR == udpRecv(pkt[0], &ipc, &ipl)) { failif(TRUE, "recva"); } if (SYSERR == udpRecv(pkt[1], &ipc, &ipl)) { failif(TRUE, "recvb"); } if (SYSERR == udpRecv(pkt[2], &ipc, &ipl)) { failif(TRUE, "recvc"); } if (SYSERR == udpRecv(pkt[3], &ipc, &ipl)) { failif(TRUE, "recvd"); } if (SYSERR == read(UDP0, buffera, 5)) { failif(TRUE, "reada"); } if (SYSERR == read(UDP0, bufferb, 5)) { failif(TRUE, "readb"); } if (SYSERR == read(UDP0, bufferc, 5)) { failif(TRUE, "readc"); } if (SYSERR == read(UDP0, bufferd, 5)) { failif(TRUE, "readd"); } failif((0 != strncmp((char *)buffera, "ABCDE", 5)) || (0 != strncmp((char *)bufferb, "FGHI", 4)) || (0 != strncmp((char *)bufferc, "JKL", 3)) || (0 != strncmp((char *)bufferd, "MN", 2)), ""); /* Test udpRecv and udpRead */ testPrint(verbose, "Two UDP sockets"); pkt[0] = makePkt(pta, pta, &ipc, &ipl, 9, "ABCDEFGHI"); udpRecv(pkt[0], &ipc, &ipl); read(UDP1, bufferc, 9); failif(0 != strncmp((char *)bufferc, "ABCDEFGHI", 9), ""); /* Test udpRecv and udpRead */ testPrint(verbose, "Receive and read UDP packets (again)"); control(UDP0, UDP_CTRL_CLRFLAG, UDP_FLAG_PASSIVE | UDP_FLAG_BINDFIRST, NULL); control(UDP0, UDP_CTRL_ACCEPT, pta, (long)&ipl); control(UDP0, UDP_CTRL_BIND, ptb, (long)&ipc); pkt[0] = makePkt(ptb, pta, &ipl, &ipc, 5, "OPQRS"); pkt[1] = makePkt(ptb, pta, &ipl, &ipc, 3, "TUV"); pkt[2] = makePkt(ptb, pta, &ipl, &ipc, 2, "WX"); pkt[3] = makePkt(ptb, pta, &ipl, &ipc, 2, "YZ"); udpRecv(pkt[0], &ipc, &ipl); udpRecv(pkt[1], &ipc, &ipl); udpRecv(pkt[2], &ipc, &ipl); udpRecv(pkt[3], &ipc, &ipl); if (SYSERR == read(UDP0, buffera, 5)) { failif(TRUE, "reada"); } if (SYSERR == read(UDP0, bufferb, 3)) { failif(TRUE, "readb"); } if (SYSERR == read(UDP0, bufferc, 2)) { failif(TRUE, "readc"); } if (SYSERR == read(UDP0, bufferd, 2)) { failif(TRUE, "readd"); } failif(0 != strncmp((char *)buffera, "OPQRS", 5) || (0 != strncmp((char *)bufferb, "TUV", 3)) || (0 != strncmp((char *)bufferc, "WX", 2)) || (0 != strncmp((char *)bufferd, "YZ", 2)), ""); /* Test udpRecv and udpRead on multiple sockets */ testPrint(verbose, "Recv/read with varying sockets (1)"); /* Test 1 */ control(UDP0, UDP_CTRL_ACCEPT, pta, (long)&ipl); control(UDP0, UDP_CTRL_BIND, NULL, NULL); pkt[0] = makePkt(ptb, pta, &ipc, &ipl, 5, "test1"); udpRecv(pkt[0], &ipc, &ipl); read(UDP0, buffera, 5); failif(strncmp((char *)buffera, "test1", 5), ""); /* Test 2 */ testPrint(verbose, "Recv/read socket test 2"); control(UDP0, UDP_CTRL_ACCEPT, pta, (long)&ipl); control(UDP0, UDP_CTRL_BIND, ptb, NULL); control(UDP1, UDP_CTRL_ACCEPT, pta, (long)&ipl); control(UDP1, UDP_CTRL_BIND, 0, NULL); pkt[0] = makePkt(ptb, pta, &ipc, &ipl, 6, "test2a"); pkt[1] = makePkt(pta, pta, &ipc, &ipl, 6, "test2b"); udpRecv(pkt[0], &ipc, &ipl); udpRecv(pkt[1], &ipc, &ipl); read(UDP0, buffera, 6); read(UDP1, bufferb, 6); failif(0 != strncmp((char *)buffera, "test2a", 6) || (0 != strncmp((char *)bufferb, "test2b", 6)), ""); /* Test 3 */ testPrint(verbose, "Recv/read socket test 3"); control(UDP0, UDP_CTRL_BIND, ptb, (long)&ipc); control(UDP1, UDP_CTRL_BIND, ptb, NULL); pkt[0] = makePkt(ptb, pta, &ipc, &ipl, 6, "test3a"); pkt[1] = makePkt(ptb, pta, &ipd, &ipl, 6, "test3b"); udpRecv(pkt[0], &ipc, &ipl); udpRecv(pkt[1], &ipd, &ipl); read(UDP0, buffera, 6); read(UDP1, bufferb, 6); failif((0 != strncmp((char *)buffera, "test3a", 6)) || (0 != strncmp((char *)bufferb, "test3b", 6)), ""); /* Test 4 */ testPrint(verbose, "Recv/read socket test 4"); control(UDP0, UDP_CTRL_BIND, ptb, (long)&ipc); control(UDP1, UDP_CTRL_BIND, ptb, (long)&ipd); pkt[0] = makePkt(ptb, pta, &ipc, &ipl, 6, "test4a"); pkt[1] = makePkt(ptb, pta, &ipd, &ipl, 6, "test4b"); udpRecv(pkt[0], &ipc, &ipl); udpRecv(pkt[1], &ipd, &ipl); read(UDP0, buffera, 6); read(UDP1, bufferb, 6); failif((0 != strncmp((char *)buffera, "test4a", 6)) || (0 != strncmp((char *)bufferb, "test4b", 6)), ""); /* Test 5 */ testPrint(verbose, "Recv/read socket test 5"); control(UDP0, UDP_CTRL_BIND, 0, NULL); control(UDP1, UDP_CTRL_ACCEPT, ptb, (long)&ipl); control(UDP1, UDP_CTRL_BIND, 0, NULL); pkt[0] = makePkt(ptb, pta, &ipc, &ipl, 6, "test5a"); pkt[1] = makePkt(pta, ptb, &ipc, &ipl, 6, "test5b"); udpRecv(pkt[0], &ipc, &ipl); udpRecv(pkt[1], &ipc, &ipl); read(UDP0, buffera, 6); read(UDP1, bufferb, 6); failif((0 != strncmp((char *)buffera, "test5a", 6)) || (0 != strncmp((char *)bufferb, "test5b", 6)), ""); /* Read entire UDP packet */ testPrint(verbose, "Read entire UDP packet"); control(UDP0, UDP_CTRL_SETFLAG, UDP_FLAG_PASSIVE, NULL); pkt[0] = makePkt(ptb, pta, &ipc, &ipl, 7, "passive"); udpRecv(pkt[0], &ipc, &ipl); read(UDP0, bufferp, UDP_HDR_LEN + 7 + sizeof(struct udpPseudoHdr)); pseudo = (struct udpPseudoHdr *)bufferp; udppkt = (struct udpPkt *)(pseudo + 1); failif((0 != memcmp(pseudo->srcIp, ipc.addr, IPv4_ADDR_LEN)) || (0 != memcmp(pseudo->dstIp, ipl.addr, IPv4_ADDR_LEN)) || (udppkt->srcPort != ptb) || (udppkt->dstPort != pta) || (udppkt->len != UDP_HDR_LEN + 7) || (0 != strncmp((char *)udppkt->data, "passive", 7)), ""); /* Done testing, attempt to close all UDP devices (MAKE SURE BOTH * DEVICES ARE OPEN BEFORE YOU CLOSE THEM!!!) */ close(UDP0); close(UDP1); /* Print out the overall test's status (pass or fail) */ if (passed) { testPass(TRUE, ""); } else { testFail(TRUE, ""); } #else /* UDP1 */ testSkip(TRUE, ""); #endif /* !UDP1 */ return OK; }
thread test_semaphore3(bool verbose) { #if NSEM tid_typ atid, btid; bool passed = TRUE; semaphore s; uchar testResult = 0; char msg[50]; testPrint(verbose, "Semaphore creation: "); s = semcreate(1); if (isbadsem(s)) { passed = FALSE; sprintf(msg, "%d", s); testFail(verbose, msg); } else if (test_checkSemCount(s, 1)) { testPass(verbose, ""); } else { passed = FALSE; } /* We use a higher priority for thread A to ensure it is not rescheduled to * thread B before it is even able to wait on the semaphore. */ ready(atid = create((void *)test_semWaiter, INITSTK, 32, "SEMAPHORE-A", 3, s, 1, &testResult), RESCHED_NO); ready(btid = create((void *)test_semWaiter, INITSTK, 31, "SEMAPHORE-B", 3, s, 1, &testResult), RESCHED_YES); testPrint(verbose, "Wait on semaphore: "); /* Process A should be admitted, but B should wait. */ if (test_checkProcState(atid, THRFREE) && test_checkProcState(btid, THRWAIT) && test_checkSemCount(s, -1) && test_checkResult(testResult, 1)) { testPass(verbose, ""); } else { passed = FALSE; } signal(s); /* Process B waited, so signal should release it. */ testPrint(verbose, "Signal waiting semaphore: "); if (test_checkProcState(btid, THRFREE) && test_checkSemCount(s, 0) && test_checkResult(testResult, 2)) { testPass(verbose, ""); } else { passed = FALSE; } if (TRUE == passed) { testPass(TRUE, ""); } else { testFail(TRUE, ""); } /* Processes should be dead, but in case the test failed. */ kill(atid); kill(btid); semfree(s); #else /* NSEM */ testSkip(TRUE, ""); #endif /* NSEM == 0 */ return OK; }
int test_policychecker(int argc, char *argv[]) { PKIX_Boolean initialPolicyMappingInhibit = PKIX_FALSE; PKIX_Boolean initialAnyPolicyInhibit = PKIX_FALSE; PKIX_Boolean initialExplicitPolicy = PKIX_FALSE; PKIX_Boolean expectedResult = PKIX_FALSE; PKIX_UInt32 chainLength = 0; PKIX_UInt32 initArgs = 0; PKIX_UInt32 firstCert = 0; PKIX_UInt32 i = 0; PKIX_Int32 j = 0; PKIX_UInt32 actualMinorVersion; PKIX_ProcessingParams *procParams = NULL; char *firstTrustAnchor = "yassir2yassir"; char *secondTrustAnchor = "yassir2bcn"; char *dateAscii = "991201000000Z"; PKIX_ValidateParams *valParams = NULL; PKIX_ValidateResult *valResult = NULL; PKIX_List *userInitialPolicySet = NULL; /* List of PKIX_PL_OID */ char *certNames[PKIX_TEST_MAX_CERTS]; PKIX_PL_Cert *certs[PKIX_TEST_MAX_CERTS]; PKIX_List *chain = NULL; PKIX_Error *validationError = NULL; PKIX_VerifyNode *verifyTree = NULL; PKIX_PL_String *verifyString = NULL; char *dirName = NULL; char *dataCentralDir = NULL; char *anchorName = NULL; PKIX_TEST_STD_VARS(); PKIX_TEST_EXPECT_NO_ERROR( PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); /* * Perform hard-coded tests if no command line args. * If command line args are provided, they must be: * arg[1]: test name * arg[2]: "ENE" or "EE", for "expect no error" or "expect error" * arg[3]: directory for certificates * arg[4]: user-initial-policy-set, consisting of braces * containing zero or more OID sequences, separated by commas * arg[5]: (optional) "E", indicating initialExplicitPolicy * arg[firstCert]: the path and filename of the trust anchor certificate * arg[firstCert+1..(n-1)]: successive certificates in the chain * arg[n]: the end entity certificate * * Example: test_policychecker test1EE ENE * {2.5.29.32.0,2.5.29.32.3.6} Anchor CA EndEntity */ dirName = argv[3+j]; dataCentralDir = argv[4+j]; if (argc <= 5 || ((6 == argc) && (j))) { testPass (dataCentralDir, firstTrustAnchor, secondTrustAnchor, dateAscii); testNistTest1(dirName); testNistTest2(dirName); goto cleanup; } if (argc < (7 + j)) { printUsage(argv[0]); pkixTestErrorMsg = "Invalid command line arguments."; goto cleanup; } if (PORT_Strcmp(argv[2+j], "ENE") == 0) { expectedResult = PKIX_TRUE; } else if (PORT_Strcmp(argv[2+j], "EE") == 0) { expectedResult = PKIX_FALSE; } else { printUsage(argv[0]); pkixTestErrorMsg = "Invalid command line arguments."; goto cleanup; } userInitialPolicySet = policySetParse(argv[5+j]); if (!userInitialPolicySet) { printUsage(argv[0]); pkixTestErrorMsg = "Invalid command line arguments."; goto cleanup; } for (initArgs = 0; initArgs < 3; initArgs++) { if (PORT_Strcmp(argv[6+j+initArgs], "A") == 0) { initialAnyPolicyInhibit = PKIX_TRUE; } else if (PORT_Strcmp(argv[6+j+initArgs], "E") == 0) { initialExplicitPolicy = PKIX_TRUE; } else if (PORT_Strcmp(argv[6+j+initArgs], "P") == 0) { initialPolicyMappingInhibit = PKIX_TRUE; } else { break; } } firstCert = initArgs + j + 6; chainLength = argc - (firstCert + 1); if (chainLength > PKIX_TEST_MAX_CERTS) { printUsageMax(chainLength); pkixTestErrorMsg = "Invalid command line arguments."; goto cleanup; } /* * Create a chain, but don't include the first certName. * That's the anchor, and is supplied separately from * the chain. */ for (i = 0; i < chainLength; i++) { certNames[i] = argv[i + (firstCert + 1)]; certs[i] = NULL; } chain = createCertChainPlus (dirName, certNames, certs, chainLength, plContext); subTest(argv[1+j]); valParams = createValidateParams (dirName, argv[firstCert], NULL, NULL, userInitialPolicySet, initialPolicyMappingInhibit, initialAnyPolicyInhibit, initialExplicitPolicy, PKIX_FALSE, chain, plContext); if (expectedResult == PKIX_TRUE) { subTest(" (expecting successful validation)"); PKIX_TEST_EXPECT_NO_ERROR(PKIX_ValidateChain (valParams, &valResult, &verifyTree, plContext)); printValidPolicyTree(valResult); } else { subTest(" (expecting validation to fail)"); validationError = PKIX_ValidateChain (valParams, &valResult, &verifyTree, plContext); if (!validationError) { printValidPolicyTree(valResult); pkixTestErrorMsg = "Should have thrown an error here."; } PKIX_TEST_DECREF_BC(validationError); } PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString ((PKIX_PL_Object*)verifyTree, &verifyString, plContext)); (void) printf("verifyTree is\n%s\n", verifyString->escAsciiString); cleanup: PKIX_PL_Free(anchorName, plContext); PKIX_TEST_DECREF_AC(verifyString); PKIX_TEST_DECREF_AC(verifyTree); PKIX_TEST_DECREF_AC(userInitialPolicySet); PKIX_TEST_DECREF_AC(chain); PKIX_TEST_DECREF_AC(valParams); PKIX_TEST_DECREF_AC(valResult); PKIX_TEST_DECREF_AC(validationError); PKIX_Shutdown(plContext); PKIX_TEST_RETURN(); endTests("PolicyChecker"); return (0); }
thread test_ip(bool verbose) { #if NETHER struct netaddr dst; struct netaddr src; struct netaddr mask; struct netif *netptr; struct pcap_file_header pcap; struct pcap_pkthdr phdr; struct packet *pktA; struct packet *pktB; uchar *data; uchar buf[500]; int i; int nproc; int wait; bool passed = TRUE; src.type = NETADDR_IPv4; src.len = IPv4_ADDR_LEN; dst.type = NETADDR_IPv4; dst.len = IPv4_ADDR_LEN; mask.type = NETADDR_IPv4; mask.len = IPv4_ADDR_LEN; src.addr[0] = 192; src.addr[1] = 168; src.addr[2] = 1; src.addr[3] = 6; dst.addr[0] = 192; dst.addr[1] = 168; dst.addr[2] = 1; dst.addr[3] = 1; mask.addr[0] = 255; mask.addr[1] = 255; mask.addr[2] = 255; mask.addr[3] = 0; testPrint(verbose, "Initialization"); sleep(500); if (SYSERR == open(ELOOP)) { failif(TRUE, "Open returned SYSERR"); } else { if (SYSERR == netUp(ELOOP, &src, &mask, &dst)) { failif(TRUE, "netUp returned SYSERR"); } else { netptr = NULL; for (i = 0; i < NNETIF; i++) { if (ELOOP == netiftab[i].dev) { netptr = &netiftab[i]; break; } } pktA = netGetbuf(); pktB = netGetbuf(); failif(((NULL == netptr) || (SYSERR == (int)pktA) || (SYSERR == (int)pktB)), "Buffer allocation failed"); } } if (!passed) { testFail(TRUE, ""); return OK; } data = (uchar *)(&_binary_data_testip_pcap_start); memcpy(&pcap, data, sizeof(pcap)); data += sizeof(pcap); testPrint(verbose, "Ipv4Send"); /* Get 1st Packet */ memcpy(&phdr, data, sizeof(phdr)); data += sizeof(phdr); if (PCAP_MAGIC != pcap.magic) { phdr.caplen = endswap(phdr.caplen); } nproc = netptr->nproc; write(ELOOP, data, phdr.caplen); wait = 0; while ((wait < MAX_WAIT) && (netptr->nproc == nproc)) { wait++; sleep(10); } if (MAX_WAIT == wait) { failif(TRUE, "Wait time expired"); } else { /* Get 2nd Packet */ data += phdr.caplen; memcpy(&phdr, data, sizeof(phdr)); data += sizeof(phdr); if (PCAP_MAGIC != pcap.magic) { phdr.caplen = endswap(phdr.caplen); } memcpy(pktA->data, data, phdr.caplen); pktA->len = phdr.caplen; pktA->nif = netptr; pktA->linkhdr = pktA->data; pktA->nethdr = pktA->linkhdr + ETH_HDR_LEN; pktA->curr = pktA->nethdr + IPv4_HDR_LEN; pktB->curr -= UDP_HDR_LEN + 4; pktB->len += UDP_HDR_LEN + 4; memcpy(pktB->curr, pktA->curr, pktB->len); control(ELOOP, ELOOP_CTRL_SETFLAG, ELOOP_FLAG_HOLDNXT, NULL); if (OK != ipv4Send(pktB, &src, &dst, IPv4_PROTO_UDP)) { failif(TRUE, "ipv4Send didn't return okay"); } else { control(ELOOP, ELOOP_CTRL_GETHOLD, (long)buf, 500); failif(0 != memcmp(buf, pktA->linkhdr, pktA->len), ""); } } /* ipv4Recv Testing */ //TODO: Finish ipv4Recv /* testPrint(verbose, "ipv4Recv"); pktA->curr -= IPv4_HDR_LEN; if (SYSERR == rawOpen(RAW0, IPv4_PROTO_UDP, )) { failif(TRUE, "Open returned SYSERR"); } if (OK != ipv4Recv(pktA)) { failif(TRUE, "Didn't return okay"); } else { } */ netDown(ELOOP); close(ELOOP); /* always print out the overall tests status */ if (passed) { testPass(TRUE, ""); } else { testFail(TRUE, ""); } #else /* NETHER */ testSkip(TRUE, ""); #endif /* NETHER == 0 */ return OK; }
/** * Tests the string.h header in the Xinu Standard Library. * @return OK when testing is complete */ thread test_libString(bool verbose) { char *s1 = NULL; char *s2 = NULL; char str[LEN_STR] = "ZYXWYZ"; bool passed = TRUE; /* strncmp */ testPrint(verbose, "String n comparison"); failif(((0 > strncmp("ZYX", "WVU", 2)) || (0 < strncmp("wvu", "zyx", 2)) || (0 < strncmp("wvu", "zyx", 50)) || (0 > strncmp("zyx", "wvu", 50)) || (0 != strncmp("abc", "abc", 50)) || (0 != strncmp("987", "987", 2)) || (0 < strncmp("NOP", "NOQ", 3)) || (0 > strncmp("noq", "nop", 3)) || (0 != strncmp("450", "456", 2))), ""); /* strncpy */ testPrint(verbose, "String n copy"); char sB[6] = "abcde"; s1 = strncpy(sB, "fghij", 3); failif(((0 != strncmp(sB, "fghde", 5)) || (s1 != sB)), ""); /* strncat */ testPrint(verbose, "String n concantenate"); char sD[6] = "zyx"; s1 = strncat(sD, "wv", 1); failif(((0 != strncmp(sD, "zyxw", 4)) || (0 != strncmp(s1, "zyxw", 4))), ""); /* * * strchr * * */ /* fail to find char */ testPrint(verbose, "Fail to find; strchr()"); s1 = strchr(str, 'a'); failif(NULL != s1, ""); /* find a uniq char */ testPrint(verbose, "Find unique char; strchr()"); s1 = strchr(str, 'X'); failif('W' != *(s1 + 1), ""); /* find a non-uniq char */ testPrint(verbose, "Find non-unique char; strchr()"); s1 = strchr(str, 'Y'); failif('X' != *(s1 + 1), ""); /* find null char */ testPrint(verbose, "Find null char; strchr()"); s1 = strchr(str, '\0'); failif(str + (LEN_STR - 1) != s1 || '\0' != *s1, ""); /* * * strrchr * * */ /* fail to find char */ testPrint(verbose, "Fail to find; strrchr()"); s1 = strrchr(str, 'a'); failif(NULL != s1, ""); /* find a uniq char */ testPrint(verbose, "Find unique char; strrchr()"); s1 = strrchr(str, 'X'); failif('W' != *(s1 + 1), ""); /* find a non-uniq char */ testPrint(verbose, "Find non-unique char; strrchr()"); s1 = strrchr(str, 'Y'); failif('Z' != *(s1 + 1), ""); /* find null char */ testPrint(verbose, "Find null char; strrchr()"); s1 = strrchr(str, '\0'); failif(str + (LEN_STR - 1) != s1 || '\0' != *s1, ""); /* strstr */ testPrint(verbose, "String search"); char sG[9] = "ABBCDEBA"; s1 = strstr(sG, "BCD"); s1 += 3; failif(('E' != *s1), ""); /* strnlen */ testPrint(verbose, "String n length"); failif(((5 != strnlen("12345", 100)) || (0 != strnlen("", 5)) || (3 != strnlen("12345", 3)) || (0 != strnlen("12345", 0))), ""); /* memcmp */ testPrint(verbose, "Memory comparsion"); failif(((0 < memcmp("ABC", "DEF", 3)) || (0 > memcmp("def", "abc", 3)) || (0 != memcmp("123", "123", 3))), ""); /* memcpy */ testPrint(verbose, "Memory copy"); char sH[6] = "ABCDE"; s1 = memcpy(sH, "FGHIJ", 5); failif(((0 != memcmp(sH, "FGHIJ", 5)) || (0 != memcmp(s1, "FGHIJ", 5))), ""); /* memchr */ testPrint(verbose, "Memory character search"); char sI[7] = "abcdba"; s1 = memchr(sI, 'b', 6) + 1; s2 = memchr(sI, 'c', 6) + 1; failif((('c' != *s1) || ('d' != *s2)), ""); /* memset */ testPrint(verbose, "Memory set"); char sJ[6] = "ABCDE"; s1 = memset(sJ, 'F', 3); failif(((0 != memcmp(sJ, "FFFDE", 5)) || (s1 != sJ)), ""); if (passed) { testPass(TRUE, ""); } else { testFail(TRUE, ""); } return OK; }
thread test_netaddr(bool verbose) { #if NETHER bool passed = TRUE; struct netaddr a; struct netaddr b; /* Setup structures */ a.type = NETADDR_ETHERNET; a.len = ETH_ADDR_LEN; a.addr[0] = 0xAA; a.addr[1] = 0xBB; a.addr[2] = 0xCC; a.addr[3] = 0xDD; a.addr[4] = 0xEE; a.addr[5] = 0xFF; b.type = NETADDR_ETHERNET; b.len = ETH_ADDR_LEN; b.addr[0] = 0xAA; b.addr[1] = 0xBB; b.addr[2] = 0xCC; b.addr[3] = 0xDD; b.addr[4] = 0xEE; b.addr[5] = 0xFF; testPrint(verbose, "Comparison (diff lengths)"); b.len = ETH_ADDR_LEN - 1; failif((TRUE == netaddrequal(&a, &b)), ""); testPrint(verbose, "Comparison (diff types)"); b.len = ETH_ADDR_LEN; a.type = NETADDR_IPv4; failif((TRUE == netaddrequal(&a, &b)), ""); testPrint(verbose, "Comparison (equal MACs)"); a.type = NETADDR_ETHERNET; failif((FALSE == netaddrequal(&a, &b)), ""); testPrint(verbose, "Comparison (diff MACs)"); b.addr[5] = 0x00; failif((TRUE == netaddrequal(&a, &b)), ""); /* Setup structures */ a.type = NETADDR_IPv4; a.len = IPv4_ADDR_LEN; a.addr[0] = 192; a.addr[1] = 168; a.addr[2] = 1; a.addr[3] = 1; b.type = NETADDR_IPv4; b.len = IPv4_ADDR_LEN; b.addr[0] = 192; b.addr[1] = 168; b.addr[2] = 1; b.addr[3] = 1; testPrint(verbose, "Comparison (equal IPs)"); failif((FALSE == netaddrequal(&a, &b)), ""); testPrint(verbose, "Comparison (diff IPs)"); a.addr[3] = 2; failif((TRUE == netaddrequal(&a, &b)), ""); /* always print out the overall tests status */ if (passed) { testPass(TRUE, ""); } else { testFail(TRUE, ""); } #else /* NETHER */ testSkip(TRUE, ""); #endif /* NETHER == 0 */ return OK; }
void taskNotify(void *usr) { testPass("taskNotify"); }
void anyNotify(void *usr, epicsThreadId tid) { testPass("anyNotify(tid=%p)", (void *)tid); }
void monRemove(void *usr, epicsThreadId tid) { testPass("monRemove(tid=%p)", (void *)tid); }
void monNotify(void *usr, epicsThreadId tid, int suspended) { testPass("monNotify(tid=%p, suspended=%d)", (void *)tid, suspended); epicsThreadResume(tid); }
void monInsert(void *usr, epicsThreadId tid) { testPass("monInsert(tid=%p)", (void *)tid); }