Example #1
0
static void channelRegisterPost(dbChannel *chan, void *user,
    chPostEventFunc **cb_out, void **arg_out, db_field_log *probe)
{
    myStruct *my = (myStruct*)user;

    if (my == puser1) {
        testOk(e1 & e_reg_post, "register_post (1) called");
        testOk(!(c2 & e_reg_post),
            "register_post (2) was not called before register_post (1)");
        c1 |= e_reg_post;
    } else if (my == puser2) {
        testOk(e2 & e_reg_post, "register_post (2) called");
        testOk(!(e1 & e_reg_post) || c1 & e_reg_post,
            "register_post (1) was called before register_post (2)");
        c2 |= e_reg_post;
    } else {
        testFail("register_post: user pointer invalid");
        testSkip(1, "Can't check order of register_post(1)/register_post(2)");
    }
    testOk(!(e1 & e_reg_pre) || c1 & e_reg_pre,
        "register_pre (1) was called before register_post (%c)", inst(user));
    testOk(!(e2 & e_reg_pre) || c2 & e_reg_pre,
        "register_pre (2) was called before register_post (%c)", inst(user));

    my->offpost = offset++;
    probe->field_type++;
    *cb_out  = post;
    *arg_out = user;
}
LONGBOW_TEST_CASE(Local, rtaWebService_ProcessHelloRequest)
{
#ifndef __APPLE__
    testSkip("Test broken on non-darwin");
#endif

    blockSigChild();
    int fds[2];
    int failure = socketpair(AF_LOCAL, SOCK_STREAM, 0, fds);
    assertFalse(failure, "error on socketpair: (%d) %s", errno, strerror(errno));

    RtaFramework *framework = rtaFramework_Create(fds[0]);
    rtaFramework_Start(framework);
    rtaFramework_WaitForStatus(framework, FRAMEWORK_RUNNING);

    int fd = socket(AF_INET, SOCK_STREAM, 0);

    struct sockaddr_in sin;
    sin.sin_addr.s_addr = inet_addr("127.0.0.1");
    sin.sin_port = htons(9090);

    failure = connect(fd, (struct sockaddr *) &sin, sizeof(sin));
    assertFalse(failure, "error on connect: (%d) %s", errno, strerror(errno));

    char request[] = "GET /hello HTTP/1.1\r\n\r\n";
    ssize_t write_length = write(fd, request, sizeof(request));
    assertFalse(write_length < 0, "Error writing: (%d) %s", errno, strerror(errno));


    struct truth_s {
        char *line;
    } truth[] = {
        { .line = "HTTP/1.1 200 OK\r\n"                             },
        { .line = ""                                                }, // do not care line for Date
Example #3
0
/**
 * 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;
}
Example #4
0
void QDeclarativeTester::imagefailure()
{
    hasFailed = true;

    if (options & QDeclarativeViewer::ExitOnFailure){
        testSkip();
        exit(hasFailed?-1:0);
    }
}
Example #5
0
void QDeclarativeTester::imagefailure()
{
    hasFailed = true;

    if (options & QDeclarativeViewer::ExitOnFailure){
        testSkip();
        QCoreApplication::exit(hasFailed ? TestFailureExitCode : TestSuccessExitCode);
    }
}
Example #6
0
static void hookPass1(initHookState state)
{
    DBENTRY entry;
    DBADDR  addr;
    if(state!=initHookAfterInitDatabase)
        return;
    testDiag("initHookAfterInitDatabase");

    dbInitEntry(pdbbase, &entry);

    if(dbFindRecord(&entry, "rec0.VAL")==0) {
        aoRecord *prec = entry.precnode->precord;
        testOk(prec->val==3, "VAL %d==3 (init_record value)", (int)prec->val);
        testOk1(dbPutString(&entry, "4")==0);
        testOk(prec->val==4, "VAL %d==4", (int)prec->val);
    } else{
        testFail("Missing rec0");
        testSkip(1, "missing record");
    }

    /* Can't restore links in pass 1 */

    if(dbNameToAddr("rec1.VAL", &addr)) {
        testFail("missing rec1");
        testSkip(3, "missing record");
    } else {
        struct rset *prset = dbGetRset(&addr);
        dbfType ftype = addr.field_type;
        long count=-1, offset=-1, maxcount = addr.no_elements;
        testOk1(prset && prset->get_array_info && prset->put_array_info);
        testOk1((*prset->get_array_info)(&addr, &count, &offset)==0);
        /* count is ignored */
        testOk1((*dbPutConvertRoutine[DBF_DOUBLE][ftype])(&addr, values, NELEMENTS(values), maxcount,offset)==0);
        testOk1((*prset->put_array_info)(&addr, NELEMENTS(values))==0);
    }

    dbFinishEntry(&entry);
}
Example #7
0
static db_field_log * post(void *user, dbChannel *chan, db_field_log *pLog) {
    myStruct *my = (myStruct*)user;
    dbfl_freeFunc *dtor = NULL;

    if (my == puser1) {
        testOk(e1 & e_post, "post (1) called");
        testOk(!(c2 & e_post),
            "post (2) was not called before post (1)");
        c1 |= e_post;
        dtor = dbfl_free1;
    } else if (my == puser2) {
        testOk(e2 & e_post, "post (2) called");
        testOk(!(e1 & e_post) || c1 & e_post,
            "post (1) was called before post (2)");
        c2 |= e_post;
        dtor = dbfl_free2;
    } else {
        testFail("post: user pointer invalid");
        testSkip(1, "Can't check order of post(1)/post(2)");
    }
    testOk(!(e1 & e_pre) || c1 & e_pre,
        "pre (1) was called before post (%c)", inst(user));
    testOk(!(e2 & e_pre) || c2 & e_pre,
        "pre (2) was called before post (%c)", inst(user));

    if (!testOk(pLog->field_type == TYPE_START + my->offpost,
            "post (%c) got field log of expected type", inst(user)))
        testDiag("expected: %d, got %d",
            TYPE_START + my->offpost, pLog->field_type);
    pLog->field_type++;

    if (my->offpost == 0) { /* The first one registers a dtor and saves pfl */
        pLog->u.r.dtor = dtor;
        dtorpfl = pLog;
    }

    if (my->offpost == drop) {
        testDiag("post (%c) is dropping the field log", inst(user));
        return NULL;
    }
    return pLog;
}
Example #8
0
/* Action function for state "test" in state set "pvGetCancel" */
static void seqg_action_pvGetCancel_0_test(SS_ID seqg_env, int seqg_trn, int *seqg_pnst)
{
	switch(seqg_trn)
	{
	case 0:
		{
# line 48 "../pvGetCancel.st"
			testFail("pvGet completion timeout");
# line 49 "../pvGetCancel.st"
			testSkip(1, "further tests aborted");
		}
		return;
	case 1:
		{
# line 52 "../pvGetCancel.st"
			testOk1(seqg_vars_pvGetCancel.x[0] == seqg_vars_pvGetCancel.y[0]);
# line 53 "../pvGetCancel.st"
			testOk1(seqg_vars_pvGetCancel.x[1] == seqg_vars_pvGetCancel.y[1]);
		}
		return;
	}
}
Example #9
0
/* Start one thread per CPU which will all try lock
 * the same spinlock.  They break as soon as one
 * fails to take the lock.
 */
static void verifyTryLock()
{
    int N, i;
    struct verifyTryLock verify;

    N = epicsThreadGetCPUs();
    if(N==1) {
        testSkip(1, "verifyTryLock() only for SMP systems");
        return;
    }

    verify.flag = 0;
    verify.spin = epicsSpinMustCreate();

    testDiag("Starting %d spinners", N);

    verify.ents = calloc(N, sizeof(*verify.ents));
    for(i=0; i<N; i++) {
        verify.ents[i].main = &verify;
        verify.ents[i].done = epicsEventMustCreate(epicsEventEmpty);
        epicsThreadMustCreate("verifyTryLockThread", 40,
            epicsThreadGetStackSize(epicsThreadStackSmall),
                              verifyTryLockThread, &verify.ents[i]);
    }

    testDiag("All started");

    for(i=0; i<N; i++) {
        epicsEventMustWait(verify.ents[i].done);
        epicsEventDestroy(verify.ents[i].done);
    }

    testDiag("All done");

    testOk(verify.flag==1, "epicsTryLock returns %d (expect 1)", verify.flag);

    epicsSpinDestroy(verify.spin);
    free(verify.ents);
}
Example #10
0
void QDeclarativeTester::complete()
{
    if ((options & QDeclarativeViewer::TestErrorProperty) && !hasFailed) {
        QString e = m_view->rootObject()->property("error").toString();
        if (!e.isEmpty()) {
            qWarning() << "Test failed:" << e;
            hasFailed = true;
        }
    }


    testSkip();
    if (options & QDeclarativeViewer::ExitOnComplete)
        QApplication::exit(hasFailed?-1:0);

    if (hasCompleted)
        return;
    hasCompleted = true;

    if (options & QDeclarativeViewer::Play)
        qWarning("Script playback complete");
}
Example #11
0
/**
 * 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;
}
Example #12
0
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;
}
Example #13
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;
}
Example #14
0
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;
}
Example #15
0
void testStdoutRedir (const char *report)
{
    FILE *realStdout = stdout;
    FILE *stream = 0;
    char linebuf[80];
    size_t buflen = sizeof linebuf;
    
    testOk1(epicsGetStdout() == stdout);

    errno = 0;
    if (!testOk1((stream = fopen(report, "w")) != NULL)) {
        testDiag("'%s' could not be opened for writing: %s",
                 report, strerror(errno));
        testSkip(11, "Can't create stream file");
        return;
    }

    epicsSetThreadStdout(stream);
    testOk1(stdout == stream);

    printf(LINE_1);
    printf(LINE_2);

    epicsSetThreadStdout(0);
    testOk1(epicsGetStdout() == realStdout);
    testOk1(stdout == realStdout);

    errno = 0;
    if (!testOk1(!fclose(stream))) {
        testDiag("fclose error: %s", strerror(errno));
#ifdef vxWorks
        testDiag("The above test fails if you don't cd to a writable directory");
        testDiag("before running the test. The next test will also fail...");
#endif
    }

    if (!testOk1((stream = fopen(report, "r")) != NULL)) {
        testDiag("'%s' could not be opened for reading: %s",
                 report, strerror(errno));
        testSkip(6, "Can't reopen stream file.");
        return;
    }

    if (!testOk1(fgets(linebuf, buflen, stream) != NULL)) {
        testDiag("File read error: %s", strerror(errno));
        testSkip(5, "Read failed.");
        fclose(stream);
        return;
    }
    testOk(strcmp(linebuf, LINE_1) == 0, "First line correct");

    if (!testOk1(fgets(linebuf, buflen, stream) != NULL)) {
        testDiag("File read error: %s", strerror(errno));
        testSkip(1, "No line to compare.");
    } else
        testOk(strcmp(linebuf, LINE_2) == 0, "Second line");

    testOk(!fgets(linebuf, buflen, stream), "File ends");

    if (!testOk1(!fclose(stream)))
        testDiag("fclose error: %s\n", strerror(errno));
}
Example #16
0
static void hookPass0(initHookState state)
{
    DBENTRY entry;
    if(state!=initHookAfterInitDevSup)
        return;
    testDiag("initHookAfterInitDevSup");

    dbInitEntry(pdbbase, &entry);

    testDiag("restore integer pass0");
    /* rec0.VAL is initially 1, set it to 2 */
    if(dbFindRecord(&entry, "rec0.VAL")==0) {
        aoRecord *prec = entry.precnode->precord;
        testOk(prec->val==1, "VAL %d==1 (initial value from .db)", (int)prec->val);
        checkGetString(&entry, "1");
        testOk1(dbPutString(&entry, "2")==0);
        testOk(prec->val==2, "VAL %d==2", (int)prec->val);
        checkGetString(&entry, "2");
    } else {
        testFail("Missing rec0");
        testSkip(4, "missing record");
    }

    testDiag("restore string pass0");
    if(dbFindRecord(&entry, "rec0.DESC")==0) {
        aoRecord *prec = entry.precnode->precord;
        testOk1(strcmp(prec->desc, "foobar")==0);
        checkGetString(&entry, "foobar");
        testOk1(dbPutString(&entry, "hello")==0);
        testOk1(strcmp(prec->desc, "hello")==0);
        checkGetString(&entry, "hello");
    } else {
        testFail("Missing rec0");
        testSkip(4, "missing record");
    }

    if(dbFindRecord(&entry, "rec1.DESC")==0) {
        aoRecord *prec = entry.precnode->precord;
        testOk1(strcmp(prec->desc, "")==0);
        checkGetString(&entry, "");
        testOk1(dbPutString(&entry, "world")==0);
        testOk1(strcmp(prec->desc, "world")==0);
        checkGetString(&entry, "world");
    } else {
        testFail("Missing rec1");
        testSkip(4, "missing record");
    }

    testDiag("restore link pass0");
    /* rec0.OUT is initially "rec0.DISV", set it to "rec0.SEVR" */
    if(dbFindRecord(&entry, "rec0.OUT")==0) {
        aoRecord *prec = entry.precnode->precord;
        if(prec->out.type==CONSTANT)
            testOk(strcmp(prec->out.text,"rec0.DISV")==0,
                   "%s==rec0.DISV (initial value from .db)",
                   prec->out.text);
        else
            testFail("Wrong link type: %d", (int)prec->out.type);

        /* note that dbGetString() reads an empty string before links are initialized
         * should probably be considered a bug, but has been the case for so long
         * we call it a 'feature'.
         */
        checkGetString(&entry, "");

        testOk1(dbPutString(&entry, "rec0.SEVR")==0);
    } else{
        testFail("Missing rec0");
        testSkip(1, "missing record");
    }

    /* rec0.SDIS is initially NULL, set it to "rec0.STAT" */
    if(dbFindRecord(&entry, "rec0.SDIS")==0) {
        aoRecord *prec = entry.precnode->precord;
        if(prec->sdis.type==CONSTANT)
            testOk1(prec->sdis.value.constantStr==NULL);
        else
            testFail("Wrong link type: %d", (int)prec->sdis.type);

        testOk1(dbPutString(&entry, "rec0.STAT")==0);
    } else{
        testFail("Missing rec0");
        testSkip(1, "missing record");
    }

    /* can't restore array field in pass0 */

    dbFinishEntry(&entry);
}
Example #17
0
/**
 * Tests the stdio.h header in the Xinu Standard Library.
 * @return OK when testing is complete
 */
thread test_libStdio(bool verbose)
{
#if defined(LOOP0)
    char str[50];
    int stdsav;
    int d, o, x;
    char c;
    char s[50];
    bool passed = TRUE;
    int ret;
    char *pret;

    ret = open(LOOP0);
    failif(ret == SYSERR, "failed to open loopback device");

    ret = control(LOOP0, LOOP_CTRL_SET_FLAG, LOOP_NONBLOCK, 0);
    failif(ret == SYSERR, "failed to set loopback device to nonblocking");

    /* fputc, fgetc.  Note: return value of fgetc() must be stored in 'int', not
     * 'char', because it can be 257 possible values (all characters, plus EOF).
     * */
    testPrint(verbose, "fgetc, fputc: basic functionality");
    ret = fputc('a', LOOP0);
    failif(ret != 'a', "fputc failed to return put character");
    ret = fputc('\n', LOOP0);
    failif(ret != '\n', "fputc failed to return put character");
    ret = fputc(4, LOOP0);
    failif(ret != 4, "fputc failed to return put character");
    ret = fgetc(LOOP0);
    failif(ret != 'a', "fgetc failed to return character");
    ret = fgetc(LOOP0);
    failif(ret != '\n', "fgetc failed to return character");
    ret = fgetc(LOOP0);
    failif(ret != 4, "fgetc failed to return character");

    /* fgets */

    /* fgets - test basic functionality */
    testPrint(verbose, "fgets: basic functionality");
    ret = write(LOOP0, "Test sentence.\n", 15);
    failif(ret != 15, "failed to write data to loopback device");
    memset(str, 'X', 20);
    pret = fgets(str, 20, LOOP0);
    failif(pret != str, "fgets failed to return output buffer");
    failif((0 != memcmp(str, "Test sentence.\n\0XXXX", 20)),
           "fgets failed to correctly return written data");

    /* fgets - Test partial reads */
    testPrint(verbose, "fgets: partial reads");
    ret = write(LOOP0, "Test sentence.\n", 15);
    failif(ret != 15, "failed to write data to loopback device");
    memset(str, 'X', 20);
    pret = fgets(str, 8, LOOP0);
    failif(pret != str, "fgets failed to return output buffer");
    failif((0 != memcmp(str, "Test se\0XX", 10)),
           "fgets failed to correctly return written data");
    memset(str, 'X', 20);
    pret = fgets(str, 9, LOOP0);
    failif(pret != str, "fgets failed to return output buffer");
    failif((0 != memcmp(str, "ntence.\n\0X", 10)),
           "fgets failed to correctly return written data");

    /* fgets - check returns NULL at end-of-file */
    testPrint(verbose, "fgets: return NULL on end-of-file");
    pret = fgets(str, 9, LOOP0);
    failif(pret != NULL, "fgets failed to return NULL on end-of-file");

    /* fgets - Test reading stops at newline */
    testPrint(verbose, "fgets: only read until newline");
    ret = write(LOOP0, "line1\nline2\n", 12);
    failif(ret != 12, "failed to write data to loopback device");
    memset(str, 'X', 20);
    pret = fgets(str, 16, LOOP0);
    failif(pret != str, "fgets failed to return output buffer");
    failif(0 != memcmp(str, "line1\n\0XXX", 10),
           "fgets failed to read only partial line");

    memset(str, 'X', 20);
    pret = fgets(str, 16, LOOP0);
    failif(pret != str, "fgets failed to return output buffer");
    failif(0 != memcmp(str, "line2\n\0XXX", 10),
           "fgets failed to read only partial line");

    /* fputs */
    testPrint(verbose, "fputs: basic functionality");
    ret = fputs("Put test.", LOOP0);
    failif(ret < 0, "fputs failed to return nonnegative value on success");
    ret = read(LOOP0, str, 9);
    failif(ret != 9, "failed to read data put with fputs");
    failif((0 != strncmp(str, "Put test.", 9)),
           "data read back with fputs was not the same as written");

    /* putchar, getchar */
    testPrint(verbose, "putchar, getchar: basic functionality");
    stdsav = stdout;
    stdout = LOOP0;
    ret = putchar('a');
    stdout = stdsav;
    failif(ret != 'a', "putchar failed to return character written");
    stdsav = stdin;
    stdin = LOOP0;
    ret = getchar();
    stdin = stdsav;
    failif(ret != 'a', "getchar failed to return character previously written");

    testPrint(verbose, "getchar: return EOF on end-of-file");
    stdsav = stdin;
    stdin = LOOP0;
    ret = getchar();
    stdin = stdsav;
    failif(ret != EOF, "getchar failed to return EOF on end-of-file");

    /* fprintf */
    testPrint(verbose, "fprintf: basic functionality");
    ret = fprintf(LOOP0, "%d %o %x %c %s", 75, 75, 75, 75, "ABC");

    failif(ret != TEST_STR_LEN,
           "fprintf() did not correctly return number of characters written");

    ret = read(LOOP0, str, TEST_STR_LEN);
    failif(ret != TEST_STR_LEN,
           "failed to read data back from loop device");

    failif((0 != strncmp(str, TEST_STR, TEST_STR_LEN)),
           "fprintf() failed to print the data correctly");

    /* printf */
    testPrint(verbose, "printf: basic functionality");
    stdsav = stdout;
    stdout = LOOP0;
    ret = printf("%d %o %x %c %s", 75, 75, 75, 75, "ABC");
    stdout = stdsav;
    failif(ret != TEST_STR_LEN,
           "printf() did not correctly return number of characters written");
    ret = read(LOOP0, str, TEST_STR_LEN);
    failif(ret != TEST_STR_LEN,
           "failed to read data back from loop device");
    failif((0 != strncmp(str, TEST_STR, TEST_STR_LEN)),
           "printf() failed to print the data correctly");

    /* sprintf */
    testPrint(verbose, "sprintf: basic functionality");
    ret = sprintf(str, "%d %o %x %c %s", 75, 75, 75, 75, "ABC");
    failif(ret != TEST_STR_LEN,
           "sprintf() did not correctly return number of characters written");
    failif((0 != strncmp(str, TEST_STR, TEST_STR_LEN)),
           "sprintf() failed to print the data correctly");

    /* sscanf */
    testPrint(verbose, "sscanf: basic functionality");
    strncpy(str, TEST_STR, TEST_STR_LEN + 1);
    d = o = x = c = 0;
    ret = sscanf(str, "%d %o %x %c %s", &d, &o, &x, &c, s);
    failif(ret != 5,
           "sscanf did not correctly return number of matches");

    failif(75 != d || 75 != o || 75 != x || 75 != c ||
            0 != strncmp(s, "ABC", 3),
            "sscanf did not scan data correctly");

    /* fscanf */
    testPrint(verbose, "fscanf: basic functionality");
    d = o = x = c = 0;
    ret = write(LOOP0, TEST_STR, TEST_STR_LEN);
    failif(ret != TEST_STR_LEN,
           "failed to write data to loopback device");
    ret = fscanf(LOOP0, "%d %o %x %c %s", &d, &o, &x, &c, s);
    failif(ret != 5,
           "fscanf did not correctly return number of matches");
    failif(75 != d || 75 != o || 75 != x || 75 != c ||
            0 != strncmp(s, "ABC", 3),
            "fscanf did not scan data correctly");

    /* scanf */

    testPrint(verbose, "scanf: basic functionality");
    d = o = x = c = 0;
    ret = write(LOOP0, TEST_STR, TEST_STR_LEN);
    failif(ret != TEST_STR_LEN,
           "failed to write data to loopback device");
    stdsav = stdin;
    stdin = LOOP0;
    ret = scanf("%d %o %x %c %s", &d, &o, &x, &c, s);
    stdin = stdsav;
    failif(ret != 5, "scanf did not correctly return number of matches");
    failif(75 != d || 75 != o || 75 != x || 75 != c ||
            0 != strncmp(s, "ABC", 3), "");

    /* More detailed fprintf tests */
    passed = do_detailed_fprintf_tests(verbose, passed);

    /* More detailed fscanf tests */
    passed = do_detailed_fscanf_tests(verbose, passed);
    
    control(LOOP0, LOOP_CTRL_CLR_FLAG, LOOP_NONBLOCK, 0);

    if (passed)
    {
        testPass(TRUE, "");
    }
    else
    {
        testFail(TRUE, "");
    }

    close(LOOP0);
#else  /* defined(LOOP0) */
    testSkip(TRUE, "");
#endif  /* !defined(LOOP0) */
    return OK;
}