Example #1
0
void wait_death() {
    int         ferr;
    int         lerr;
    MS_Mon_Msg *msg;
    char        recv_buffer[BUFSIZ];
    BMS_SRE     sre;

    do {
        lerr = XWAIT(LREQ, -1);
        TEST_CHK_WAITIGNORE(lerr);
        lerr = BMSG_LISTEN_((short *) &sre, // sre
                            0,              // listenopts
                            0);             // listenertag
    } while (lerr == BSRETYPE_NOWORK);
    assert(sre.sre_flags & XSRE_MON);
    ferr = BMSG_READDATA_(sre.sre_msgId,  // msgid
                          recv_buffer,    // reqdata
                          BUFSIZ);        // bytecount
    util_check("XMSG_READDATA_", ferr);
    msg = (MS_Mon_Msg *) recv_buffer;
    assert(msg->type == MS_MsgType_ProcessDeath);
    printf("received death message for %s\n", msg->u.death.process_name);
    XMSG_REPLY_(sre.sre_msgId,  // msgid
                NULL,           // replyctrl
                0,              // replyctrlsize
                NULL,           // replydata
                0,              // replydatasize
                0,              // errorclass
                NULL);          // newphandle
}
Example #2
0
void *thread_wait(void *arg) {
    int  inx;
    int  lerr;
    bool senders_done;

    arg = arg; // touch
    senders_done = false;
#ifdef USE_EVENT_REG
    proc_event_register(LREQ);
    proc_event_register(LDONE);
#endif
    for (inx = 0; inx < loop / 5; inx++) {
        do {
            lerr = XWAIT(LREQ | LDONE, 10);
            TEST_CHK_WAITIGNORE(lerr);
            if (lerr == 0) {
                if ((thr_send == NULL) && (thr_send_brk == NULL)) {
                    senders_done = true;
                    break;
                }
            }
        } while (lerr == 0);
        if (senders_done)
            break;
        printf("wait-thread woke up\n");
    }
    if (senders_done)
        printf("wait-thread senders done, inx=%d\n", inx);
    return NULL;
}
void wait_node_notice() {
    int    ferr;
    int    lerr;
    bool   node_change;
    MS_SRE sre;

    node_change = false;
    while (!node_change) {
        lerr = XWAIT(LREQ, -1);
        TEST_CHK_WAITIGNORE(lerr);
        do {
            lerr = XMSG_LISTEN_((short *) &sre,       // sre
                                XLISTEN_ALLOW_IREQM,  // listenopts
                                0);                   // listenertag
            if (lerr == XSRETYPE_IREQ) {
                bool mon_msg = (sre.sre_flags & XSRE_MON);
                if (gverbose)
                    printf("client LISTEN mon-msg=%d\n", mon_msg);
                assert(mon_msg);
                int msg_size = sre.sre_reqDataSize;
                char *msg = new char[msg_size];
                ferr = XMSG_READDATA_(sre.sre_msgId,      // msgid
                                      msg,                // reqdata
                                      (ushort) msg_size); // bytecount
                assert(ferr == XZFIL_ERR_OK);
                MS_Mon_Msg *msgp = (MS_Mon_Msg *) msg;

                switch (msgp->type) {
                case MS_MsgType_NodeDown:
                    if (gverbose)
                        printf("client mon-msg-type=node-down(%d)\n", msgp->type);
                    node_change = true;
                    break;
                case MS_MsgType_NodeUp:
                    if (gverbose)
                        printf("client mon-msg-type=node-up(%d)\n", msgp->type);
                    node_change = true;
                    break;
                case MS_MsgType_ProcessDeath:
                    if (gverbose)
                        printf("client mon-msg-type=proc-death(%d)\n", msgp->type);
                    break;
                default:
                    if (gverbose)
                        printf("client mon-msg-type=%d\n", msgp->type);
                    break;
                }
                XMSG_REPLY_(sre.sre_msgId,       // msgid
                            NULL,                // replyctrl
                            0,                   // replyctrlsize
                            NULL,                // replydata
                            0,                   // replydatasize
                            0,                   // errorclass
                            NULL);               // newphandle
                delete [] msg;
            }
        } while (lerr);
    }
}
int recv(void *buf, int *size) {
    int  *lbuf;
    int   ferr;
    int   lerr;
    bool  mon_msg;
    int   nid;
    int   pid;

    do {
        do {
            lerr = XWAIT(LREQ, -1);
            TEST_CHK_WAITIGNORE(lerr);
            lerr = XMSG_LISTEN_((short *) &gsre,   // sre
                               0,                 // listenopts
                               0);                // listenertag
        } while (lerr == XSRETYPE_NOWORK);
        mon_msg = (gsre.sre_flags & XSRE_MON);
        if (mon_msg) {
            int msg_size = gsre.sre_reqDataSize;
            char *msg = new char[msg_size];
            ferr = XMSG_READDATA_(gsre.sre_msgId,     // msgid
                                  msg,                // reqdata
                                  (ushort) msg_size); // bytecount
            assert(ferr == XZFIL_ERR_OK);
            check_mon_msg(msg);
            XMSG_REPLY_(gsre.sre_msgId,      // msgid
                        NULL,                // replyctrl
                        0,                   // replyctrlsize
                        NULL,                // replydata
                        0,                   // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
            delete [] msg;
            if (gtakeover)
                return 1;
        } else {
            ferr = XMSG_READDATA_(gsre.sre_msgId,   // msgid
                                  (char *) buf,     // reqctrl
                                  (ushort) *size);  // bytecount
            assert(ferr == XZFIL_ERR_OK);
            *size = gsre.sre_reqDataSize;
            ferr = XMSG_GETREQINFO_(MSGINFO_NID,
                                    gsre.sre_msgId,
                                    &nid);
            assert(ferr == XZFIL_ERR_OK);
            ferr = XMSG_GETREQINFO_(MSGINFO_PID,
                                    gsre.sre_msgId,
                                    &pid);
            assert(ferr == XZFIL_ERR_OK);
            lbuf = (int *) buf;
            myprintf("received from p-id=%d/%d: %d.%d.%d\n",
                     nid, pid, lbuf[0], lbuf[1], lbuf[2]);
        }
    } while (mon_msg);
    return 0;
}
Example #5
0
void *server_thr(void *arg) {
    int                 ferr;
    int                 lerr;
    int                 recv_len;
    BMS_SRE             sre;
    MyThread           *thr;
    int                 thrinx;

    thr = (MyThread *) arg;
    thrinx = thr->inx;
    // process requests
    for (;;) {
        do {
            lerr = XWAIT(LREQ, 100);
            lerr = BMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
            if ((lerr == XSRETYPE_NOWORK) &&
                (atomic_read(&msg_count) >= maxmsg))
                return NULL;
        } while (lerr == XSRETYPE_NOWORK);
        if (lerr == XSRETYPE_ABANDON)
            continue;
        if (sre.sre_flags & XSRE_MON) {
            ferr = XMSG_READDATA_(sre.sre_msgId,       // msgid
                                  recv_buffer[thrinx], // reqdata
                                  BUFSIZ);             // bytecount
            util_check("XMSG_READDATA_", ferr);
            MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer[thrinx];
            if (verbose)
                printf("server(%s): mon-msg type=%d\n", my_name, msg->type);
            if (msg->type == MS_MsgType_Close) {
                closes++;
                if (verbose)
                    printf("server(%s): closes=%d\n", my_name, closes);
            }
        } else {
            atomic_inc(&msg_count);
            if (verbose)
                printf("server(%s): msg-count=%d\n",
                       my_name, atomic_read(&msg_count));
        }
        recv_len = rnd(BUFSIZ);
        BMSG_REPLY_(sre.sre_msgId,       // msgid
                    NULL,                // replyctrl
                    0,                   // replyctrlsize
                    recv_buffer[thrinx], // replydata
                    recv_len,            // replydatasize
                    0,                   // errorclass
                    NULL);               // newphandle
        if (closes)
            break;
    }
    return NULL;
}
void *server_thr(void *arg) {
    int       ferr;
    int       lerr;
    int       max_msgs = gmaxc * gloop;
    bool      mon_msg;
    Test_SRE  sre;
    int       status;
    int       whoami = ginxs++;

    arg = arg; // touch
    for (;;) {
        if (gsre_count >= max_msgs)
            break;
        if (gshutdown)
            break;
        do {
            lerr = XWAIT(LREQ, 100);
            lerr = XMSG_LISTEN_((short *) &sre.sre,  // sre
                                0,                   // listenopts
                                0);                  // listenertag
        } while (lerr == XSRETYPE_NOWORK);
        mon_msg = (sre.sre.sre_flags & XSRE_MON);
        if (mon_msg) {
            int msg_size = sre.sre.sre_reqDataSize;
            char *msg = new char[msg_size];
            ferr = XMSG_READDATA_(sre.sre.sre_msgId,     // msgid
                                  msg,                   // reqdata
                                  (ushort) msg_size);    // bytecount
            assert(ferr == XZFIL_ERR_OK);
            pp_check_mon_msg(msg);
            pp_check_mon_msg_shutdown(msg);
            XMSG_REPLY_(sre.sre.sre_msgId,   // msgid
                        NULL,                // replyctrl
                        0,                   // replyctrlsize
                        NULL,                // replydata
                        0,                   // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
            delete [] msg;
            if (gshutdown)
                break;
        } else {
            status = gmutex.lock();
            TEST_CHK_STATUSOK(status);
            gsre_count++;
            status = gmutex.unlock();
            TEST_CHK_STATUSOK(status);
            if (gverbose)
                printf("s-%d: have work, sre-count=%d\n",
                       whoami, gsre_count);
            server(whoami, &sre);
        }
    }
    return NULL;
}
Example #7
0
int main(int argc, char *argv[]) {
    int     ferr;
    int     inx;
    int     len;
    int     lerr;
    int     loop = 10;
    char    my_name[BUFSIZ];
    char    recv_buffer[BUFSIZ];
    short   recv_buffer2[BUFSIZ];
    MS_SRE  sre;
    TAD     zargs[] = {
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init_role(false, &argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    ferr = msg_mon_process_startup(true); // system messages
    TEST_CHK_FEOK(ferr);
    util_gethostname(my_name, sizeof(my_name));

    for (inx = 0; inx < loop/2; inx++) {
        do {
            lerr = XWAIT(LREQ, -1);
            TEST_CHK_WAITIGNORE(lerr);
            lerr = XMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
        } while (lerr == XSRETYPE_NOWORK);
        ferr = XMSG_READCTRL_(sre.sre_msgId,  // msgid
                              recv_buffer2,   // reqctrl
                              1);             // bytecount
        util_check("XMSG_READCTRL_", ferr);
        ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                              recv_buffer,    // reqdata
                              BUFSIZ);        // bytecount
        util_check("XMSG_READDATA_", ferr);
        strcat(recv_buffer, "- reply from ");
        strcat(recv_buffer, my_name);
        len = (int) strlen(recv_buffer) + 1;
        XMSG_REPLY_(sre.sre_msgId,       // msgid
                    recv_buffer2,        // replyctrl
                    sre.sre_reqCtrlSize, // replyctrlsize
                    recv_buffer,         // replydata
                    (ushort) len,        // replydatasize
                    0,                   // errorclass
                    NULL);               // newphandle
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    return 0;
}
Example #8
0
void client(int clinx, char *name, long id, int inx) {
    int              ferr;
    int              lerr;
    int              msgid;
    Util_AA<char>    recv_buffer(BUFSIZ);
    Util_AA<short>   recv_buffer3(BUFSIZ);
    RT               results;
    Util_AA<char>    send_buffer(BUFSIZ);
    Util_AA<short>   send_buffer2(BUFSIZ);
    int              send_len;
    MS_SRE_LDONE     sre_ldone;

    sprintf(&send_buffer, "hello, greetings from %s, name=%s, id=%ld, inx=%d",
            my_name, name, id, inx);
    while (clinx >= 0) {
        strcat(&send_buffer, "!");
        clinx--;
    }
    send_len = (int) strlen(&send_buffer) + 1;
    ferr = XMSG_LINK_(TPT_REF(phandle),                     // phandle
                      &msgid,                      // msgid
                      &send_buffer2,               // reqctrl
                      (ushort) (inx & 1),          // reqctrlsize
                      &recv_buffer3,               // replyctrl
                      1,                           // replyctrlmax
                      &send_buffer,                // reqdata
                      (ushort) send_len,           // reqdatasize
                      &recv_buffer,                // replydata
                      BUFSIZ,                      // replydatamax
                      (SB_Tag_Type) &send_buffer,  // linkertag
                      0,                           // pri
                      0,                           // xmitclass
                      XMSG_LINK_LDONEQ);           // linkopts
    util_check("XMSG_LINK_", ferr);
    do {
        lerr = XWAIT(LDONE, -1);
        TEST_CHK_WAITIGNORE(lerr);
        lerr = XMSG_LISTEN_((short *) &sre_ldone, // sre
                            0,                    // listenopts
                            0);                   // listenertag
    } while (lerr == XSRETYPE_NOWORK);
    assert(lerr == XSRETYPE_LDONE);
    assert(sre_ldone.sre_linkTag == (SB_Tag_Type) &send_buffer);
    ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
    util_check("XMSG_BREAK_", ferr);
    assert(results.u.t.ctrl_size == (uint) (inx & 1));
    assert(results.u.t.data_size > (strlen(&send_buffer) + 14));
    assert(results.u.t.errm == RT_DATA_RCVD); // data
    printf("%s\n", &recv_buffer);
}
Example #9
0
void Thread_Test2::work() {
    _xcc_status     cc;
    int             lerr;
    MS_SRE_TPOP     sre;

    if (whoami == 0) {
        while (tleid_test2 < 0)
            SB_Thread::Sthr::yield();
        usleep(100000);
        cc = XCANCELTIMEOUT(tleid_test2);
        TEST_CHK_CCNE(cc);
    } else {
        lerr = XWAIT(LREQ, -1);
        assert(lerr == LREQ);
        cc = XSIGNALTIMEOUT(1, 1, 1, &tleid_test2);
        TEST_CHK_CCEQ(cc);
        lerr = XWAIT(LREQ, -1);
        assert(lerr == LREQ);
        lerr = XMSG_LISTEN_((short *) &sre, // sre
                            0,              // listenopts
                            0);             // listenertag
    }
}
Example #10
0
void Server_Thread::work() {
    bool   done;
    int    ferr;
    int    lerr;
    char   recv_buffer[40000];
    MS_SRE sre;

    if (verbose)
        printf("server-%d thread starting\n", whoami);
    done = false;
    while (!done) {
        do {
            lerr = XWAIT(LREQ, -1);
            TEST_CHK_WAITIGNORE(lerr);
            lerr = XMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
        } while (lerr == XSRETYPE_NOWORK);
        if (verbose)
            printf("server-%d thread processing msgid=%d\n",
                   whoami, sre.sre_msgId);
        ferr = XMSG_READCTRL_(sre.sre_msgId,  // msgid
                              NULL,           // reqctrl
                              0);             // bytecount
        util_check("XMSG_READCTRL_", ferr);
        ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                              recv_buffer,    // reqdata
                              40000);         // bytecount
        util_check("XMSG_READDATA_", ferr);
        if (sre.sre_flags & XSRE_MON) {
        } else if (sre.sre_reqDataSize > 0) {
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
        } else
            done = true;
        XMSG_REPLY_(sre.sre_msgId,  // msgid
                    NULL,           // replyctrl
                    0,              // replyctrlsize
                    recv_buffer,    // replydata
                    39000,          // replydatasize
                    0,              // errorclass
                    NULL);          // newphandle
        if (delay)
            sleep(1);
    }
    if (verbose)
        printf("server-%d thread stopping\n", whoami);
}
Example #11
0
int main(int argc, char *argv[]) {
    int     exit;
    int     ferr;
    int     lerr;
    char    name[BUFSIZ];
    char    recv_buffer[BUFSIZ];
    MS_SRE  sre;

    msfs_util_init_role(false, &argc, &argv, msg_debug_hook);
    ferr = msg_mon_process_startup(true); // system messages
    TEST_CHK_FEOK(ferr);
    msg_mon_enable_mon_messages(true);
    ferr = msg_mon_get_my_process_name(name, sizeof(name));
    TEST_CHK_FEOK(ferr);
    exit = 0;
    while (!exit) {
        do {
            lerr = XWAIT(LREQ, -1);
            TEST_CHK_WAITIGNORE(lerr);
            lerr = XMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
        } while (lerr == XSRETYPE_NOWORK);
        ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                              recv_buffer,    // reqdata
                              BUFSIZ);        // bytecount
        util_check("XMSG_READDATA_", ferr);
        if (sre.sre_flags & XSRE_MON) {
            MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
            printf("srv %s: mon message, type=%d\n", name, msg->type);
            if (msg->type == MS_MsgType_Close)
                exit = 1;
        } else {
            printf("srv %s: NON-mon message\n", name);
        }
        XMSG_REPLY_(sre.sre_msgId,       // msgid
                    NULL,                // replyctrl
                    0,                   // replyctrlsize
                    NULL,                // replydata
                    0,                   // replydatasize
                    0,                   // errorclass
                    NULL);               // newphandle
    }
    printf("server %s shutting down\n", name);
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    return 0;
}
int main(int argc, char *argv[]) {
    int     exit = false;
    int     err;
    int     ferr;
    int     len;
    char    recv_buffer[BUFSIZ];
    BMS_SRE sre;

    ferr = msg_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_process_startup(true);  // system messages?
    TEST_CHK_FEOK(ferr);
    msg_mon_enable_mon_messages(true);

    for (;;) {
        do {
            err = XWAIT(LREQ, -1);
            TEST_CHK_WAITIGNORE(err);
            err = BMSG_LISTEN_((short *) &sre, // sre
                               0,              // listenopts
                               0);             // listenertag
        } while (err == BSRETYPE_NOWORK);
        ferr = BMSG_READDATA_(sre.sre_msgId,  // msgid
                              recv_buffer,    // reqdata
                              BUFSIZ);        // bytecount
        TEST_CHK_FEOK(ferr);
        if ((sre.sre_flags & BSRE_MON)) {
            MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
            if (msg->type == MS_MsgType_Close)
                exit = true;
        }
        strcat(recv_buffer, "- reply from server");
        len = (int) strlen(recv_buffer) + 1;
        BMSG_REPLY_(sre.sre_msgId,       // msgid
                    NULL,                // replyctrl
                    0,                   // replyctrlsize
                    recv_buffer,         // replydata
                    len,                 // replydatasize
                    0,                   // errorclass
                    NULL);               // newphandle
        if (exit)
            break;
    }

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    return 0;
}
Example #13
0
void do_readmsg() {
    int     lerr;
    MS_SRE  sre;

    do {
        lerr = XWAIT(LREQ, -1);
        TEST_CHK_WAITIGNORE(lerr);
        lerr = XMSG_LISTEN_((short *) &sre, // sre
                            0,              // listenopts
                            0);             // listenertag
    } while (lerr == XSRETYPE_NOWORK);
    XMSG_REPLY_(sre.sre_msgId,       // msgid
                NULL,                // replyctrl
                0,                   // replyctrlsize
                NULL,                // replydata
                0,                   // replydatasize
                0,                   // errorclass
                NULL);               // newphandle
}
Example #14
0
//
// server main
//
int main(int pv_argc, char *pa_argv[]) {
    bool     lv_done;
    int      lv_ferr;
    int      lv_lerr;
    BMS_SRE  lv_sre;

    CALL_COMP_DOVERS(idtmsrv, pv_argc, pa_argv);

    do_init(pv_argc, pa_argv);

    lv_ferr = msg_mon_process_startup(true); // system messages
    assert(lv_ferr == XZFIL_ERR_OK);
    msg_mon_enable_mon_messages(true);
    lv_ferr = msg_mon_get_my_process_name(ga_name, sizeof(ga_name));
    assert(lv_ferr == XZFIL_ERR_OK);

    do_shm();
    lv_ferr = timer_start_cb(gv_time_refresh_delay, 0, 0, &gv_tleid, &timer_callback);
    assert(lv_ferr == XZFIL_ERR_OK);

    lv_done = false;
    while (!lv_done) {
        do {
            lv_lerr = XWAIT(LREQ, -1);
            lv_lerr = BMSG_LISTEN_((short *) &lv_sre, // sre
                                   0,                 // listenopts
                                   0);                // listenertag
        } while (lv_lerr == XSRETYPE_NOWORK);
        if (lv_sre.sre_flags & XSRE_MON) {
            do_mon_msg(&lv_sre, &lv_done);
        } else {
            do_req(&lv_sre);
        }
    }

    if (gv_verbose)
        printf("server %s shutting down\n", ga_name);
    lv_ferr = msg_mon_process_shutdown();
    assert(lv_ferr == XZFIL_ERR_OK);

    return 0;
}
Example #15
0
void Thread_Test3::work() {
    _xcc_status  cc;
    int          inx;
    int          lerr;
    MS_SRE_TPOP  sre;
    short        tleid;

    for (inx = 0; inx < 1000; inx++) {
        cc = XSIGNALTIMEOUT(1, 1, 1, &tleid);
        TEST_CHK_CCEQ(cc);
        do {
            lerr = XWAIT(LREQ, -1);
            assert(lerr == LREQ);
            lerr = XMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
        } while (lerr == XSRETYPE_NOWORK);
        assert(lerr == XSRETYPE_TPOP);
    }
}
Example #16
0
void *server_thr(void *arg) {
    int       lerr;
    int       max_msgs = maxcp * maxc * loop;
    Test_SRE  sre;
    Test_SRE *srep;
    int       status;
    int       whoami = inxs++;

    arg = arg; // touch
    for (;;) {
        if (thrlisten) {
            sre.fin = false;
            if (sre_count >= max_msgs)
                break;
            do {
                lerr = XWAIT(LREQ, -1);
                lerr = XMSG_LISTEN_((short *) &sre.sre,  // sre
                                    0,                   // listenopts
                                    0);                  // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            status = mutex.lock();
            TEST_CHK_STATUSOK(status);
            sre_count++;
            status = mutex.unlock();
            TEST_CHK_STATUSOK(status);
            srep = &sre;
        } else
            srep = (Test_SRE *) work_q.remove();
        if (verbose)
            printf("s-%d: have work, fin=%d\n", whoami, srep->fin);
        if (srep->fin)
            break;
        server(whoami, srep);
        if (!thrlisten)
            free_q.add(&srep->link);
    }
    return NULL;
}
Example #17
0
//
// server main
//
int main(int argc, char *argv[]) {
    bool     done;
    int      ferr;
    int      lerr;
    BMS_SRE  sre;

    do_init(argc, argv);

    ferr = msg_mon_process_startup(true); // system messages
    assert(ferr == XZFIL_ERR_OK);
    msg_mon_enable_mon_messages(true);
    ferr = msg_mon_get_my_process_name(name, sizeof(name));
    assert(ferr == XZFIL_ERR_OK);

    do_shm();

    done = false;
    while (!done) {
        do {
            lerr = XWAIT(LREQ, -1);
            lerr = BMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
        } while (lerr == XSRETYPE_NOWORK);
        if (sre.sre_flags & XSRE_MON) {
            do_mon_msg(&sre, &done);
        } else {
            do_req(&sre);
        }
    }

    if (verbose)
        printf("server %s shutting down\n", name);
    ferr = msg_mon_process_shutdown();
    assert(ferr == XZFIL_ERR_OK);
    return 0;
}
Example #18
0
int main(int argc, char *argv[]) {
    bool                       client = false;
    int                        count;
    int                        disable;
    int                        ferr;
    MS_Mon_Open_Info_Type      info;
    MS_Mon_Open_Info_Max_Type  info_max[MAX_OPENS];
    int                        inx;
    int                        len;
    int                        lerr;
    int                        loop = 10;
    int                        msgid;
    int                        oid;
    TPT_DECL                  (phandle);
    RT                         results;
    int                        send_len;
    MS_SRE                     sre;
    TAD                        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    // process-wait for server/shell
    ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, 2, NULL, false);
    TEST_CHK_FEOK(ferr);
    // process-wait for client
    ferr = msfs_util_wait_process_count(MS_ProcessType_TSE, 1, NULL, false);
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    } else

    util_gethostname(my_name, sizeof(my_name));
    msg_mon_enable_mon_messages(true);

    for (inx = 0; inx < loop; inx++) {
        if (client) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            send_len = (int) strlen(send_buffer) + 1;
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              send_buffer2,                // reqctrl
                              (ushort) (inx & 1),          // reqctrlsize
                              recv_buffer3,                // replyctrl
                              1,                           // replyctrlmax
                              send_buffer,                 // reqdata
                              (ushort) send_len,           // reqdatasize
                              recv_buffer,                 // replydata
                              BUFSIZ,                      // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
            assert(results.u.t.ctrl_size == (uint) (inx & 1));
            assert(results.u.t.data_size > (strlen(send_buffer) + 14));
            assert(results.u.t.errm == RT_DATA_RCVD); // data
            printf("%s\n", recv_buffer);
        } else {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            ferr = XMSG_READCTRL_(sre.sre_msgId,  // msgid
                                  recv_buffer2,   // reqctrl
                                  1);             // bytecount
            util_check("XMSG_READCTRL_", ferr);
            ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                  recv_buffer,    // reqdata
                                  BUFSIZ);        // bytecount
            util_check("XMSG_READDATA_", ferr);
            if (sre.sre_flags & XSRE_MON) {
                printf("server received mon message\n");
                inx--;
                len = 0;
            } else {
                if (inx == 0) {
                    sleep(3); // wait for monitor replicate
                    disable = msg_test_assert_disable();
                    ferr = msg_mon_get_open_info(-1,
                                                 -1,
                                                 (char *) "$srv",
                                                 1,
                                                 &info);
                    assert(ferr == XZFIL_ERR_INVALOP);
                    ferr = msg_mon_get_open_info_max(-1,
                                                     -1,
                                                     (char *) "$srv",
                                                     false,
                                                     &count,
                                                     MAX_OPENS,
                                                     info_max);
                    assert(ferr == XZFIL_ERR_INVALOP);
                    msg_test_assert_enable(disable);
                }
                strcat(recv_buffer, "- reply from ");
                strcat(recv_buffer, my_name);
                len = (int) strlen(recv_buffer) + 1;
            }
            XMSG_REPLY_(sre.sre_msgId,       // msgid
                        recv_buffer2,        // replyctrl
                        sre.sre_reqCtrlSize, // replyctrlsize
                        recv_buffer,         // replydata
                        (ushort) len,        // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
        }
    }

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Example #19
0
int main(int argc, char *argv[]) {
    bool       client = false;
    bool       disable = false;
    int        ferr;
    int        lerr;
    int        msgid;
    int        oid;
    TPT_DECL  (phandle);
    RT         results;
    MS_SRE     sre;
    TAD        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    }
    util_gethostname(my_name, sizeof(my_name));

    if (client) {
        sprintf(send_buffer, "hello, greetings from %s", my_name);
        ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                          &msgid,                      // msgid
                          NULL,                        // reqctrl
                          0,                           // reqctrlsize
                          NULL,                        // replyctrl
                          0,                           // replyctrlmax
                          send_buffer,                 // reqdata
                          39000,                       // reqdatasize
                          recv_buffer,                 // replydata
                          40000,                       // replydatamax
                          0,                           // linkertag
                          0,                           // pri
                          0,                           // xmitclass
                          0);                          // linkopts
        util_check("XMSG_LINK_", ferr);
        disable = msg_test_assert_disable();
        ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
        msg_test_assert_enable(disable);
        assert(ferr == XZFIL_ERR_PATHDOWN);
        disable = msg_test_assert_disable();
        ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                          &msgid,                      // msgid
                          NULL,                        // reqctrl
                          0,                           // reqctrlsize
                          NULL,                        // replyctrl
                          0,                           // replyctrlmax
                          send_buffer,                 // reqdata
                          39000,                       // reqdatasize
                          recv_buffer,                 // replydata
                          40000,                       // replydatamax
                          0,                           // linkertag
                          0,                           // pri
                          0,                           // xmitclass
                          0);                          // linkopts
        util_check("XMSG_LINK_", ferr);
        msg_test_assert_enable(disable);
        ferr = XMSG_ABANDON_(msgid);
        util_check("XMSG_ABANDON_", ferr);
    } else {
        for (;;) {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            util_abort_core_free();
        }
    }
    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Example #20
0
void *client_thr(void *arg) {
    int           dinx;
    int           ferr;
    static int    kinx = -1;
    int           lerr;
    int           req_ctrl_size;
    int           req_data_size;
    RT            results;
    MS_SRE_LDONE  sre_ldone;
    MyThread     *thr;
    int           tinx;

    thr = (MyThread *) arg;
    tinx = thr->inx;

    if (kinx < 0)
        kinx = gdloop - 1;
    for (dinx = 0; dinx < gdloop; dinx++) {
        req_ctrl_size = 0;
        req_data_size = gdsize;
        if (gverbose)
            printf("client LINK tinx=%d, dinx=%d\n", tinx, dinx);
        ferr = XMSG_LINK_(TPT_REF(gphandle),              // phandle
                          &gmsgids[tinx][dinx],           // msgid
                          gsend_cli_c_buffer[tinx][dinx], // reqctrl
                          (ushort) req_ctrl_size,         // reqctrlsize
                          grecv_cli_c_buffer[tinx][dinx], // replyctrl
                          (ushort) req_ctrl_size,         // replyctrlmax
                          gsend_cli_d_buffer[tinx][dinx], // reqdata
                          (ushort) req_data_size,         // reqdatasize
                          grecv_cli_d_buffer[tinx][dinx], // replydata
                          (ushort) req_data_size,         // replydatamax
                          0,                              // linkertag
                          0,                              // pri
                          0,                              // xmitclass
                          XMSG_LINK_LDONEQ);              // linkopts
        util_check("XMSG_LINK_", ferr);
        if ((tinx == 0) && (dinx == kinx)) {
            usleep(10000);
            if (gnodecycle && gvirtual)
                node_cycle();
            else
                kill_server();
            kinx--;
            if (kinx < 0)
                kinx = gdloop - 1;
        }
    }
    for (dinx = 0; dinx < gdloop; ) {
        lerr = XWAIT(LDONE, -1);
        TEST_CHK_WAITIGNORE(lerr);
        do {
            lerr = XMSG_LISTEN_((short *) &sre_ldone, // sre
                                XLISTEN_ALLOW_LDONEM, // listenopts
                                0);                   // listenertag
            if (lerr == XSRETYPE_LDONE) {
                if (gverbose)
                    printf("client LISTEN tinx=%d, dinx=%d\n", tinx, dinx);
                dinx++;
                ferr = XMSG_BREAK_(sre_ldone.sre_msgId,
                                   results.u.s,
                                   TPT_REF(gphandle));
                ferr = ferr; // ignore
            }
        } while (lerr);
    }
    return NULL;
}
Example #21
0
int main(int argc, char *argv[]) {
    _bcc_status     bcc;
    void           *buf;
    bool            client = false;
    int             count_read;
    int             count_written;
    int             count_xferred;
    bool            e_ldone;
    bool            e_pwu;
    int             err;
    int             ferr;
    short           filenumr;
    short           filenums;
    int             inx;
    int             loop = 10;
    char           *p;
    char            recv_buffer[BUFSIZ];
    char            send_buffer[BUFSIZ];
    int             socka;
    int             sockc;
    int             sockl;
    SB_Tag_Type     tag;
    short           tfilenum;
    int             timeout = -1;
    short           wakeup;
    TAD             zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    ferr = file_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    msfs_util_init_fs(&argc, &argv, file_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = file_mon_process_startup(!client); // system messages
    TEST_CHK_FEOK(ferr);

    if (client) {
        ferr = BFILE_OPEN_((char *) "$srv", (short) 4, &filenums,
                           0, 0, 1,
                           0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);

        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "inx=%d", inx);
            bcc = BWRITEREADX(filenums,
                              send_buffer,
                              (short) (strlen(send_buffer) + 1),
                              BUFSIZ,
                              &count_read,
                              1);
            TEST_CHK_BCCEQ(bcc);
            tfilenum = -1;
            bcc = BAWAITIOX(&tfilenum,
                            &buf,
                            &count_xferred,
                            &tag,
                            timeout,
                            NULL);
            TEST_CHK_BCCEQ(bcc);
        }
        p = strchr(send_buffer, ':');
        *p = 0;
        p++;
        strcpy(host, send_buffer);
        port = (unsigned short) atoi(p);
        if (verbose)
            printf("server returned host=%s, port=%d\n",
                   host, port);

        if (verbose)
            printf("client connecting up\n");
        // connect up, and setup fds
        epoll_init();
        sockc = do_sock_connect();
        pin_main = 1;
        proc_register_group_pin(-1, pin_main);
        epoll_add(sockc);
        do_thread_create();

        bcc = BWRITEREADX(filenums,
                          NULL,
                          0,
                          BUFSIZ,
                          &count_read,
                          1);
        TEST_CHK_BCCEQ(bcc);
        usleep(10000);
        e_pwu = false;
        e_ldone = false;
        for (;;) {
            wakeup = XWAIT(LDONE | PWU, -1);
            if (wakeup & PWU) {
                e_pwu = true;
                do_io_comp();
            }
            if (wakeup & LDONE) {
                e_ldone = true;
                timeout = -1;
                tfilenum = -1;
                bcc = BAWAITIOX(&tfilenum,
                                &buf,
                                &count_xferred,
                                &tag,
                                timeout,
                                NULL);
                TEST_CHK_BCCEQ(bcc);
            }
            if (e_ldone && e_pwu)
                break;
        }

        do_thread_join();
        if (verbose)
            printf("client closing\n");
        ferr = BFILE_CLOSE_(filenums, 0);
        TEST_CHK_FEOK(ferr);
        printf("if there were no asserts, all is well\n");
    } else {
        sockl = do_sock_listen();
        assert(sockl != -1);

        ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr,
                           0, 0, 1,
                           1, 1, // no sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            bcc = BREADUPDATEX(filenumr,
                               recv_buffer,
                               BUFSIZ,
                               &count_read,
                               1);
            TEST_CHK_BCCEQ(bcc);
            tfilenum = filenumr;
            bcc = BAWAITIOX(&tfilenum,
                            &buf,
                            &count_xferred,
                            &tag,
                            timeout,
                            NULL);
            TEST_CHK_BCCEQ(bcc);
            assert(tag == 1);
            sprintf(recv_buffer, "%s:%d\n", host, port);
            count_read = (short) (strlen(recv_buffer) + 1);
            bcc = BREPLYX(recv_buffer,
                          count_read,
                          &count_written,
                          0,
                          XZFIL_ERR_OK);
            TEST_CHK_BCCEQ(bcc);
        }

        if (verbose)
            printf("server accepting\n");
        socka = do_sock_accept(sockl);
        err = (int) write(socka, recv_buffer, 1);
        assert(err != -1);

        for (inx = 0; inx < 1; inx++) {
            bcc = BREADUPDATEX(filenumr,
                               recv_buffer,
                               BUFSIZ,
                               &count_read,
                               1);
            TEST_CHK_BCCEQ(bcc);
            tfilenum = filenumr;
            bcc = BAWAITIOX(&tfilenum,
                            &buf,
                            &count_xferred,
                            &tag,
                            timeout,
                            NULL);
            TEST_CHK_BCCEQ(bcc);
            bcc = BREPLYX(recv_buffer,
                          0,
                          &count_written,
                          0,
                          XZFIL_ERR_OK);
            TEST_CHK_BCCEQ(bcc);
        }

        if (verbose)
            printf("server closing\n");
        ferr = BFILE_CLOSE_(filenumr, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Example #22
0
int main(int argc, char *argv[]) {
    bool      client = false;
    int       count;
    int       ferr;
    int       inx;
    int       lerr;
    int       loop = 10;
    int       msgid;
    int       oid;
    TPT_DECL (phandle);
    RT        results;
    MS_SRE    sre;
    BMS_SRE   sre_tb;
    MS_SRE    sre_tx;
    TAD       zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    } else
        msg_mon_enable_mon_messages(true); // need this
    util_gethostname(my_name, sizeof(my_name));

    for (inx = 0; inx < loop; inx++) {
        count = inx % 100;
        if (client) {
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              send_bufferc,                // reqctrl
                              (short) count,               // reqctrlsize
                              recv_bufferc,                // replyctrl
                              (short) (count+1),           // replyctrlmax
                              send_buffer,                 // reqdata
                              (short) (count+2),           // reqdatasize
                              recv_buffer,                 // replydata
                              (short) (count+3),           // replydatamax
                              0,                           // linkertag
                              (short) count,               // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
        } else {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre_tx,     // sre
                                    XLISTEN_TEST_IREQM,    // listenopts
                                    0);                    // listenertag
                if (lerr == XSRETYPE_NOWORK)
                    continue;
                if (sre_tx.sre_flags & XSRE_MON) {
                    // toss out monitor messages
                    lerr = XMSG_LISTEN_((short *) &sre, // sre
                                        0,              // listenopts
                                        0);             // listenertag
                    assert(lerr == XSRETYPE_IREQ);
                    assert(sre_tx.sre_flags & XSRE_MON);
                    lerr = XSRETYPE_NOWORK;
                    XMSG_REPLY_(sre.sre_msgId,  // msgid
                                NULL,           // replyctrl
                                0,              // replyctrlsize
                                NULL,           // replydata
                                0,              // replydatasize
                                0,              // errorclass
                                NULL);          // newphandle
                    continue;
                }
                lerr = BMSG_LISTEN_((short *) &sre_tb,     // sre
                                    BLISTEN_TEST_IREQM,    // listenopts
                                    0);                    // listenertag
                assert(lerr == BSRETYPE_IREQ);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
                assert(lerr == XSRETYPE_IREQ);
            } while (lerr == XSRETYPE_NOWORK);

            assert(sre.sre_pri == count);
            assert(sre.sre_reqCtrlSize == count);
            assert(sre.sre_reqDataSize == (count + 2));
            assert(sre.sre_replyCtrlMax == (count + 1));
            assert(sre.sre_replyDataMax == (count + 3));

            assert(sre.sre_msgId == sre_tx.sre_msgId);
            assert(sre.sre_flags == sre_tx.sre_flags);
            assert(sre.sre_pri == sre_tx.sre_pri);
            assert(sre.sre_reqCtrlSize == sre_tx.sre_reqCtrlSize);
            assert(sre.sre_reqDataSize == sre_tx.sre_reqDataSize);
            assert(sre.sre_replyCtrlMax == sre_tx.sre_replyCtrlMax);
            assert(sre.sre_replyDataMax == sre_tx.sre_replyDataMax);

            assert(sre.sre_msgId == sre_tb.sre_msgId);
            assert(sre.sre_flags == sre_tb.sre_flags);
            assert(sre.sre_pri == sre_tb.sre_pri);
            assert(sre.sre_reqCtrlSize == sre_tb.sre_reqCtrlSize);
            assert(sre.sre_reqDataSize == sre_tb.sre_reqDataSize);
            assert(sre.sre_replyCtrlMax == sre_tb.sre_replyCtrlMax);
            assert(sre.sre_replyDataMax == sre_tb.sre_replyDataMax);

            XMSG_REPLY_(sre.sre_msgId,  // msgid
                        NULL,           // replyctrl
                        0,              // replyctrlsize
                        recv_buffer,    // replydata
                        0,              // replydatasize
                        0,              // errorclass
                        NULL);          // newphandle
        }
    }
    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Example #23
0
void test_timers() {
    _xcc_status     cc;
    int             lerr;
    MS_SRE_TPOP     sre;
    struct timeval  t_elapsed;
    struct timeval  t_start1;
    struct timeval  t_start2;
    struct timeval  t_stop;
    short           tleid1;
    short           tleid2;
    long            to_act;
    long            to_exp;

    if (verbose)
        printf("timer-test\n");

    // drain pending LREQ
    lerr = XWAIT(LREQ, -1);
    assert(lerr == LREQ);

    // check timers
    util_time_timer_start(&t_start1);
    cc = XSIGNALTIMEOUT(40, 2, 2, &tleid1);
    TEST_CHK_CCEQ(cc);
    usleep(30000);
    util_time_timer_start(&t_start2);
    cc = XSIGNALTIMEOUT(40, 4, 4, &tleid2);
    TEST_CHK_CCEQ(cc);

    lerr = XWAIT(LREQ, -1);
    assert(lerr == LREQ);
    lerr = XMSG_LISTEN_((short *) &sre, // sre
                        0,              // listenopts
                        0);             // listenertag
    assert(lerr == XSRETYPE_TPOP);
    util_time_timer_stop(&t_stop);
    util_time_elapsed(&t_start1, &t_stop, &t_elapsed);
    to_act = t_elapsed.tv_sec * 1000000 + t_elapsed.tv_usec;
    to_exp = sre.sre_tleTOVal * 10000;
    if (verbose || (to_act < to_exp))
        printf("tleid=%d, exp-to=%ld, act-to=%ld\n",
               sre.sre_tleId, to_exp, to_act);
    assert(to_act >= to_exp);
    if (to_tol > 0)
        assert(to_act <= (to_exp + to_tol));

    lerr = XWAIT(LREQ, -1);
    assert(lerr == LREQ);
    lerr = XMSG_LISTEN_((short *) &sre, // sre
                        0,              // listenopts
                        0);             // listenertag
    assert(lerr == XSRETYPE_TPOP);
    util_time_timer_stop(&t_stop);
    util_time_elapsed(&t_start2, &t_stop, &t_elapsed);
    to_act = t_elapsed.tv_sec * 1000000 + t_elapsed.tv_usec;
    to_exp = sre.sre_tleTOVal * 10000;
    if (verbose || (to_act < to_exp))
        printf("tleid=%d, exp-to=%ld, act-to=%ld\n",
               sre.sre_tleId, to_exp, to_act);
    assert(to_act >= to_exp);
    if (to_tol > 0)
        assert(to_act <= (to_exp + to_tol));
}
Example #24
0
int main(int argc, char *argv[]) {
    int        csize = 0;
    int        dinx;
    int        dloop = MAX_OUT;
    int        dsize = MAX_DBUF;
    int        ferr;
    TPT_DECL2 (phandle,MAX_SERVERS);
    int        inx;
    int        lerr;
    int        loop = 10;
    int        max;
    int        maxsp = 1;
    int        msgids[MAX_SERVERS * MAX_OUT];
    int        oid;
    int        pinx;
    short     *reqctrl;
    char      *reqdata;
    short     *repctrl;
    char      *repdata;
    RT         results;
    MS_SRE     sre;
    bool       verbose = false;
    int        xinx;
    TAD        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-csize",     TA_Int,  MAX_CBUF,    &csize     },
      { "-dloop",     TA_Int,  MAX_OUT,     &dloop     },
      { "-dsize",     TA_Int,  MAX_DBUF,    &dsize     },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxcp",     TA_Int,  MAX_CLIENTS, &maxcp     },
      { "-maxsp",     TA_Int,  MAX_SERVERS, &maxsp     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    ferr = msg_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    msfs_util_init_fs(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    if (maxcp < 0)
        maxcp = 1;
    if (maxsp < 0)
        maxsp = 1;
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    if (!client)
        msg_mon_enable_mon_messages(true);
    ferr = msg_mon_get_my_process_name(my_name, BUFSIZ);
    TEST_CHK_FEOK(ferr);

    // process-wait for clients/servers/shell
    ferr = msfs_util_wait_process_count(MS_ProcessType_Generic,
                                        maxcp + maxsp + 1,
                                        NULL,
                                        verbose);
    TEST_CHK_FEOK(ferr);
    sleep(3); // wait for all process_count's to complete
    if (client) {
        pinx = atoi(&my_name[4]);
        assert(pinx >= 0);
        printf("loop=%d\n", loop);
        for (inx = 0; inx < loop; inx++) {
            for (pinx = 0; pinx < maxsp; pinx++) {
                sprintf(serv, "$srv%d", pinx);
                ferr = msg_mon_open_process(serv,
                                            TPT_REF2(phandle,pinx),
                                            &oid);
                TEST_CHK_FEOK(ferr);
            }
            for (pinx = 0; pinx < maxsp; pinx++) {
                for (dinx = 0; dinx < dloop; dinx++) {
                    xinx = pinx * maxsp + dinx;
                    reqctrl = &send_buffer2[xinx * csize];
                    repctrl = &recv_buffer3[xinx * csize];
                    reqdata = &send_buffer[xinx * dsize];
                    repdata = &recv_buffer[xinx * dsize];
                    ferr = XMSG_LINK_(TPT_REF2(phandle,pinx), // phandle
                                      &msgids[xinx],          // msgid
                                      reqctrl,                // reqctrl
                                      (short) csize,          // reqctrlsize
                                      repctrl,                // replyctrl
                                      (short) csize,          // replyctrlmax
                                      reqdata,                // reqdata
                                      (short) dsize,          // reqdatasize
                                      repdata,                // replydata
                                      (short) dsize,          // replydatamax
                                      0,                      // linkertag
                                      0,                      // pri
                                      0,                      // xmitclass
                                      0);                     // linkopts
                    util_check("XMSG_LINK_", ferr);
                }
            }
            for (pinx = 0; pinx < maxsp; pinx++) {
                for (dinx = 0; dinx < dloop; dinx++) {
                    xinx = pinx * maxsp + dinx;
                    ferr = XMSG_BREAK_(msgids[xinx],
                                       results.u.s,
                                       TPT_REF2(phandle,pinx));
                    util_check("XMSG_BREAK_", ferr);
                    assert((int) results.u.t.ctrl_size == csize);
                    assert((int) results.u.t.data_size == dsize);
                    assert(results.u.t.errm == RT_DATA_RCVD); // data
                }
                if (verbose)
                    printf("%s-open-count=%d\n", my_name, inx);
            }
            for (pinx = 0; pinx < maxsp; pinx++) {
                ferr = msg_mon_close_process(TPT_REF2(phandle,pinx));
                TEST_CHK_FEOK(ferr);
                if (verbose)
                    printf("%s-close-count=%d\n", my_name, inx);
            }
        }
    } else {
        max = 2 * maxcp * loop + maxcp * dloop * loop;
        for (inx = 0; inx < max; inx++) {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            ferr = XMSG_READCTRL_(sre.sre_msgId,        // msgid
                                  recv_buffer2,         // reqctrl
                                  sre.sre_reqCtrlSize); // bytecount
            util_check("XMSG_READCTRL_", ferr);
            ferr = XMSG_READDATA_(sre.sre_msgId,        // msgid
                                  recv_buffer,          // reqdata
                                  sre.sre_reqDataSize); // bytecount
            util_check("XMSG_READDATA_", ferr);
            XMSG_REPLY_(sre.sre_msgId,         // msgid
                        recv_buffer2,          // replyctrl
                        sre.sre_reqCtrlSize,   // replyctrlsize
                        recv_buffer,           // replydata
                        sre.sre_reqDataSize,   // replydatasize
                        0,                     // errorclass
                        NULL);                 // newphandle
            if (verbose)
                printf("%s-count=%d\n", my_name, inx);
        }
    }

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Example #25
0
int main(int argc, char *argv[]) {
    char                      *args[4];
    bool                       attach = false;
    bool                       chook = false;
    bool                       client = false;
    bool                       clientd = false;
    int                        cli_nid = -1;
    int                        cli_pid = -1;
    const char                *cname = "$cli";
    int                        count;
    int                        ferr;
    int                        inx;
    int                        len;
    int                        lerr;
    int                        loop = 10;
    TPT_DECL                  (mphandle);
    char                      *mphandlec = (char *) &mphandle;
    TPT_DECL_INT              (mphandlei);
    int                        msgid;
    int                        my_mon_nid;
    int                        my_mon_pid;
    int                        my_mon_ptype;
    int                        my_mon_zid;
    int                        my_os_pid;
    long                       my_os_tid;
    int                        my_compid;
    int                        my_pnid;
    int                        my_segid;
    int                        nid;
    int                        oid;
    TPT_DECL                  (phandle);
    int                        pid;
    char                      *pname = NULL;
    int                        ptype;
    RT                         results;
    int                        scollpid = -1;
    int                        scompid = -1;
    int                        send_len;
    bool                       shook = false;
    const char                *sname = "$srv";
    bool                       sonar = false;
    MS_SRE                     sre;
    int                        srv_nid = -1;
    int                        srv_pid = -1;
    MS_Mon_Monitor_Stats_Type  stats;
    int                        status;
    long                       t_elapsed;
    struct timeval             t_start;
    struct timeval             t_stop;
    int                        tm_seq;
    bool                       val_bool;
    int                        val_int;
    const char                *val_str;
    int                        winx;
    pid_t                      wpid;
    TAD                        zargs[] = {
        { "-attach",    TA_Bool, TA_NOMAX,    &attach    },
        { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
        { "-client",    TA_Bool, TA_NOMAX,    &client    },
        { "-clientd",   TA_Bool, TA_NOMAX,    &clientd   },
        { "-cname",     TA_Str,  TA_NOMAX,    &cname     },
        { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
        { "-name",      TA_Str,  TA_NOMAX,    &pname     },
        { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
        { "-shook",     TA_Bool, TA_NOMAX,    &shook     },
        { "-sname",     TA_Str,  TA_NOMAX,    &sname     },
        { "-sonar",     TA_Bool, TA_NOMAX,    &sonar     },
        { "",           TA_End,  TA_NOMAX,    NULL       }
    };

#ifdef DEBUG_ENV
    env = environ;
    while (*env != NULL) {
        printf("env=%s\n", *env);
        env++;
    }
#endif

    arg_proc_args(zargs, false, argc, argv);
    if (client && chook)
        test_debug_hook("c", "c");
    if (!client && shook)
        test_debug_hook("s", "s");

    setenv("TESTKEYBOOL", "1", 1);
    setenv("TESTKEYINT", "44", 1);
    setenv("TESTKEYSTR", "TESTVALSTR", 1);
    //
    // test msg_getenv* before msg_init
    //
    val_bool = true;
    msg_getenv_bool("TESTKEYBOOL", &val_bool);
    assert(val_bool);
    val_bool = false;
    msg_getenv_bool("TESTKEYBOOL", &val_bool);
    assert(!val_bool);
    val_int = 0;
    msg_getenv_int("TESTKEYINT", &val_int);
    assert(val_int == 0);
    val_int = 1;
    msg_getenv_int("TESTKEYINT", &val_int);
    assert(val_int == 1);
    val_str = (const char *) 1;
    val_str = msg_getenv_str("TESTKEYSTR");
    assert(val_str == NULL);

    if (attach)
        msfs_util_init_attach(&argc, &argv, msg_debug_hook, false, pname);
    else
        msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_time_timer_start(&t_start);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);

    //
    // test msg_getenv* after msg_init
    //
    msg_getenv_bool("TESTKEYBOOL", &val_bool);
    assert(val_bool);
    msg_getenv_int("TESTKEYINT", &val_int);
    assert(val_int == 44);
    val_str = msg_getenv_str("TESTKEYSTR");
    assert(strcmp(val_str, "TESTVALSTR") == 0);

    // process-wait for server/shell
    ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, 2, NULL, false);
    TEST_CHK_FEOK(ferr);
    // process-wait for client
    ferr = msfs_util_wait_process_count(MS_ProcessType_TSE, 1, NULL, false);
    TEST_CHK_FEOK(ferr);
    if (client) {
        if (sonar) {
            scollpid = fork();
            if (scollpid == 0) {
                // child
                args[0] = (char *) "sonarcollector";
                args[1] = (char *) "-i"; // sampling interval // cast
                args[2] = (char *) "1"; // cast
                args[3] = NULL;
                lerr = execvp(args[0], args);
                assert(lerr == 0);
            }
        }
        ferr = msg_mon_open_process((char *) sname,       // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    }

    // this phandle check assumed a particular data structure
    ferr = msg_mon_get_my_process_name(my_name, BUFSIZ);
    util_check("msg_mon_get_my_process_name", ferr);
    ferr = XPROCESSHANDLE_GETMINE_(TPT_REF(mphandle));
    util_check("XPROCESSHANDLE_GETMINE_", ferr);
    TPT_COPY_INT(mphandlei, mphandle);
    assert((mphandlei[0] & 0xf0) == 0x20); // named
    assert(strncmp(my_name, &mphandlec[4], 32) == 0);
    printf("phandle=%x.%x.%x.%x.%x\n",
           mphandlei[0],
           mphandlei[1],
           mphandlei[2],
           mphandlei[3],
           mphandlei[4]);
    ferr = msg_mon_get_my_info(&my_mon_nid,
                               &my_mon_pid,
                               my_mon_name,
                               BUFSIZ,
                               &my_mon_ptype,
                               &my_mon_zid,
                               &my_os_pid,
                               &my_os_tid);
    util_check("msg_mon_get_my_info", ferr);
    printf("nid=%d, pid=%d, name=%s, ptype=%d, zid=%d, os-pid=%d, os-tid=%ld\n",
           my_mon_nid,
           my_mon_pid,
           my_mon_name,
           my_mon_ptype,
           my_mon_zid,
           my_os_pid,
           my_os_tid);
    my_mon_nid   = -1;
    my_mon_pid   = -1;
    my_mon_ptype = -1;
    my_mon_zid   = -1;
    my_os_pid    = -1;
    my_os_tid    = -1;
    my_compid    = -1;
    my_pnid      = -1;
    ferr = msg_mon_get_my_info3(&my_mon_nid,
                                &my_mon_pid,
                                my_mon_name3,
                                BUFSIZ,
                                &my_mon_ptype,
                                &my_mon_zid,
                                &my_os_pid,
                                &my_os_tid,
                                &my_compid,
                                &my_pnid);
    util_check("msg_mon_get_my_info3", ferr);
    printf("nid=%d, pid=%d, name=%s, ptype=%d, zid=%d, os-pid=%d, os-tid=%ld, compid=%d, pnid=%d\n",
           my_mon_nid,
           my_mon_pid,
           my_mon_name3,
           my_mon_ptype,
           my_mon_zid,
           my_os_pid,
           my_os_tid,
           my_compid,
           my_pnid);
    ferr = msg_mon_get_my_segid(&my_segid);
    util_check("msg_mon_get_my_segid", ferr);
    printf("segid=%d\n", my_segid);

    ferr = msg_mon_get_monitor_stats(&stats);
    util_check("msg_mon_get_monitor_stats", ferr);
    printf("avail_min=%d, acquired_max=%d, buf_misses=%d\n",
           stats.avail_min, stats.acquired_max, stats.buf_misses);

    util_gethostname(my_name, sizeof(my_name));
    msg_mon_enable_mon_messages(true);
    ferr = msg_mon_get_tm_seq(&tm_seq);
    util_check("msg_mon_get_tm_seq", ferr);
    printf("tm_seq=%d\n", tm_seq);
    if (client) {
        ferr = msg_mon_get_process_info_type(MS_ProcessType_TSE,
                                             &count,
                                             0,
                                             NULL);
        TEST_CHK_FEOK(ferr);
        if (!attach)
            assert(count == 1);
        ferr = msg_mon_get_process_info_type(MS_ProcessType_TSE,
                                             &count,
                                             1,
                                             info);
        TEST_CHK_FEOK(ferr);
        if (!attach)
            assert(count == 1);
    }

    for (inx = 0; inx < loop; inx++) {
        if (client) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            send_len = (int) strlen(send_buffer) + 1;
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              send_buffer2,                // reqctrl
                              (ushort) (inx & 1),          // reqctrlsize
                              recv_buffer3,                // replyctrl
                              1,                           // replyctrlmax
                              send_buffer,                 // reqdata
                              (ushort) send_len,           // reqdatasize
                              recv_buffer,                 // replydata
                              BUFSIZ,                      // replydatamax
                              0,                           // linkertag
                              (short) (inx+1),             // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            ferr = XMSG_BREAK_(msgid,
                               results.u.s,
                               TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
            assert(results.u.t.ctrl_size == (uint) (inx & 1));
            assert(results.u.t.data_size > (strlen(send_buffer) + 14));
            assert(results.u.t.errm == RT_DATA_RCVD); // data
            printf("%s\n", recv_buffer);
        } else {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            ferr = XMSG_GETREQINFO_(MSGINFO_NID,
                                    sre.sre_msgId,
                                    &nid);
            util_check("XMSG_GETREQINFO_", ferr);
            ferr = XMSG_GETREQINFO_(MSGINFO_PID,
                                    sre.sre_msgId,
                                    &pid);
            util_check("XMSG_GETREQINFO_", ferr);
            ferr = XMSG_GETREQINFO_(MSGINFO_PTYPE,
                                    sre.sre_msgId,
                                    &ptype);
            util_check("XMSG_GETREQINFO_", ferr);
            if (sre.sre_flags & XSRE_MON) {
                // mon messages have our nid/pid
                if (srv_nid < 0) {
                    ferr = msg_mon_get_process_info((char *) "",
                                                    &srv_nid,
                                                    &srv_pid);
                    TEST_CHK_FEOK(ferr);
                }
                if (!clientd) {
                    assert(nid == srv_nid);
                    assert(pid == srv_pid);
                }
            } else {
                assert(sre.sre_pri == ((inx+1) & 0xffff));
                if (cli_nid < 0) {
                    ferr = msg_mon_get_process_info((char *) cname,
                                                    &cli_nid,
                                                    &cli_pid);
                    TEST_CHK_FEOK(ferr);
                }
                if (!attach)
                    assert(ptype == MS_ProcessType_TSE);
                assert(nid == cli_nid);
                assert(pid == cli_pid);
            }
            ferr = XMSG_READCTRL_(sre.sre_msgId,  // msgid
                                  recv_buffer2,   // reqctrl
                                  1);             // bytecount
            util_check("XMSG_READCTRL_", ferr);
            ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                  recv_buffer,    // reqdata
                                  BUFSIZ);        // bytecount
            util_check("XMSG_READDATA_", ferr);
            if (sre.sre_flags & XSRE_MON) {
                printf("server received mon message\n");
                inx--;
                len = 0;
                if (clientd) {
                    MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
                    if (msg->type == MS_MsgType_Close)
                        inx = loop;
                }
            } else {
                strcat(recv_buffer, "- reply from ");
                strcat(recv_buffer, my_name);
                len = (int) strlen(recv_buffer) + 1;
            }
            XMSG_REPLY_(sre.sre_msgId,       // msgid
                        recv_buffer2,        // replyctrl
                        sre.sre_reqCtrlSize, // replyctrlsize
                        recv_buffer,         // replydata
                        (ushort) len,        // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
        }
    }
    if (sonar) {
        if (client) {
            // for some reason [monitor?], one 'sonarcom stop' doesn't stop coll
            for (winx = 0; winx < 20; winx++) {
                scompid = fork();
                if (scompid == 0) {
                    // child
                    args[0] = (char *) "sonarcom";
                    args[1] = (char *) "stop";
                    args[2] = NULL;
                    lerr = execvp(args[0], args);
                    assert(lerr == 0);
                }
                wpid = waitpid(scompid, &status, 0);
                assert(wpid == scompid);
                wpid = waitpid(scollpid, &status, WNOHANG);
                if (wpid == scollpid)
                    break;
                else
                    sleep(1);
            }
            assert(wpid == scollpid);
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              NULL,                        // reqctrl
                              0,                           // reqctrlsize
                              NULL,                        // replyctrl
                              0,                           // replyctrlmax
                              NULL,                        // reqdata
                              0,                           // reqdatasize
                              NULL,                        // replydata
                              0,                           // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            TEST_CHK_FEOK(ferr);
            ferr = XMSG_BREAK_(msgid,
                               results.u.s,
                               TPT_REF(phandle));
            TEST_CHK_FEOK(ferr);
        } else {
            do {
                lerr = XWAIT(LREQ, -1);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            XMSG_REPLY_(sre.sre_msgId,       // msgid
                        NULL,                // replyctrl
                        0,                   // replyctrlsize
                        NULL,                // replydata
                        0,                   // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
        }
    }

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        if (!clientd) {
            ferr = msg_mon_process_close();
            TEST_CHK_FEOK(ferr);
        }
    }
    util_time_timer_stop(&t_stop);
    t_elapsed = (t_stop.tv_sec * 1000000 + t_stop.tv_usec) -
                (t_start.tv_sec * 1000000 + t_start.tv_usec);
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    if (client) {
        printf("elapsed time (gettimeofday us)=%ld\n", t_elapsed);
    }
    return 0;
}
Example #26
0
void Thread_Test::work() {
    _xcc_status     cc;
    int             lerr;
    MS_SRE_TPOP     sre;
    int             status;
    struct timeval  t_elapsed;
    struct timeval  t_start;
    struct timeval  t_stop;
    int             tid;
    short           tleid1;
    short           tleid2;
    short           tleid3;
    short           tleid4;
    long            to_act;
    long            to_exp;

    tid = gettid();
    // drain events
    lerr = XWAIT(-1, -2);
    TEST_CHK_WAITIGNORE(lerr);
    lerr = XWAIT(-1, -2);
    TEST_CHK_WAITIGNORE(lerr);
    util_time_timer_start(&t_start);
    cc = XSIGNALTIMEOUT(40, 4, tid, &tleid1);
    TEST_CHK_CCEQ(cc);
    cc = XSIGNALTIMEOUT(80, 8, tid, &tleid2);
    TEST_CHK_CCEQ(cc);
    cc = XSIGNALTIMEOUT(20, 2, tid, &tleid3);
    TEST_CHK_CCEQ(cc);
    cc = XSIGNALTIMEOUT(160, 16, tid, &tleid4);
    TEST_CHK_CCEQ(cc);
    if (verbose)
        printf("w=%d\n", whoami);
    while (tles < 4 * maxth) {
        lerr = XWAIT(-1, 10);
        do {
            lerr = XMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
            switch (lerr) {
            case XSRETYPE_TPOP:
                util_time_timer_stop(&t_stop);
                util_time_elapsed(&t_start, &t_stop, &t_elapsed);
                to_act = t_elapsed.tv_sec * 1000000 + t_elapsed.tv_usec;
                to_exp = sre.sre_tleTOVal * 10000;
                if (verbose || (to_act < to_exp))
                    printf("w=%d, tid=%d, tleid=%d, exp-to=%ld, act-to=%ld\n",
                           whoami, tid, sre.sre_tleId, to_exp, to_act);
                assert(to_act >= to_exp);
                if (to_tol > 0)
                    assert(to_act <= (to_exp + to_tol));
                status = tles_sl.lock();
                TEST_CHK_STATUSOK(status);
                tles++;
                status = tles_sl.unlock();
                TEST_CHK_STATUSOK(status);
                if (verbose)
                    printf("w=%d, TLEs=%d\n", whoami, tles);
                break;
            case XSRETYPE_NOWORK:
                break;
            default:
                assert((lerr == XSRETYPE_TPOP) || (lerr == XSRETYPE_NOWORK));
            }
        } while (lerr != XSRETYPE_NOWORK);
    }
}
Example #27
0
int main(int argc, char *argv[]) {
    SB_Array<int>  array(MAX_OUT);
    int            client = false;
    int            disable = 0;
    int            ferr;
    int            inx;
    int            lerr;
    int            linker = false;
    int            listener = false;
    int            oid;
    int            req_ctrl_size;
    int            req_data_size;
    int            rep_ctrl_size;
    int            rep_data_size;
    RT             results;
    TPT_DECL      (phandle);
    TAD            zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-linker",    TA_Bool, TA_NOMAX,    &linker    },
      { "-listener",  TA_Bool, TA_NOMAX,    &listener  },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);             // system messages
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",              // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);

        for (inx = 0; inx < MAX_OUT; inx++) {
            req_ctrl_size = (inx + 1) % MAX_DATA;
            req_data_size = (inx + 2) % MAX_DATA;
            ferr = XMSG_LINK_(TPT_REF(phandle),         // phandle
                              &msgids[inx],             // msgid
                              send_cli_c_buffer[inx],   // reqctrl
                              (ushort) req_ctrl_size,   // reqctrlsize
                              recv_cli_c_buffer[inx],   // replyctrl
                              (ushort) MAX_DATA,        // replyctrlmax
                              send_cli_d_buffer[inx],   // reqdata
                              (ushort) req_data_size,   // reqdatasize
                              recv_cli_d_buffer[inx],   // replydata
                              (ushort) MAX_DATA,        // replydatamax
                              0,                        // linkertag
                              0,                        // pri
                              0,                        // xmitclass
                              0);                       // linkopts
            util_check("XMSG_LINK_", ferr);
        }
        if (linker) {
            sleep(1);
            util_abort_core_free();
        }
        for (inx = 0; inx < MAX_OUT; inx++) {
            array.add();
            array.set_val(inx, inx);
        }
        for (inx = 0; inx < MAX_OUT; inx++) {
            int rnd =
              (int) (1.0 * array.get_size() * rand_r(&seed) / (RAND_MAX + 1.0));
            int xinx = array.get_val(rnd);
            array.remove(rnd);
            rep_ctrl_size = (xinx + 3) % MAX_DATA;
            rep_data_size = (xinx + 4) % MAX_DATA;
            if (listener)
                disable = msg_test_assert_disable();
            ferr = XMSG_BREAK_(msgids[xinx], results.u.s, TPT_REF(phandle));
            if (listener) {
                assert(ferr == XZFIL_ERR_PATHDOWN);
                msg_test_assert_enable(disable);
            } else {
                util_check("XMSG_BREAK_", ferr);
                assert(results.u.t.ctrl_size == (unsigned short) rep_ctrl_size);
                assert(results.u.t.data_size == (unsigned short) rep_data_size);
            }
        }
        printf("if there were no asserts, all is well\n");
    } else {
        for (inx = 0; inx < MAX_OUT; inx++) {
            lerr = XWAIT(LREQ, -1);
            TEST_CHK_WAITIGNORE(lerr);
            do {
                lerr = XMSG_LISTEN_((short *) &sres[inx], // sre
                                    0,                    // listenopts
                                    0);                   // listenertag
                if (lerr == XSRETYPE_NOWORK)
                    util_time_sleep_ms(1);
            } while (lerr == XSRETYPE_NOWORK);
        }
        for (inx = 0; inx < MAX_OUT; inx++) {
            array.add();
            array.set_val(inx, inx);
        }
        for (inx = 0; inx < MAX_OUT; inx++) {
            int rnd =
              (int) (1.0 * array.get_size() * rand_r(&seed) / (RAND_MAX + 1.0));
            int xinx = array.get_val(rnd);
            array.remove(rnd);
            req_ctrl_size = (xinx + 1) % MAX_DATA;
            req_data_size = (xinx + 2) % MAX_DATA;
            assert(req_ctrl_size == sres[xinx].sre_reqCtrlSize);
            assert(req_data_size == sres[xinx].sre_reqDataSize);
            ferr = XMSG_READCTRL_(sres[xinx].sre_msgId,        // msgid
                                  recv_srv_c_buffer[xinx],     // reqctrl
                                  sres[xinx].sre_reqCtrlSize); // bytecount
            util_check("XMSG_READCTRL_", ferr);
            ferr = XMSG_READDATA_(sres[xinx].sre_msgId,        // msgid
                                  recv_srv_d_buffer[xinx],     // reqdata
                                  sres[xinx].sre_reqDataSize); // bytecount
            util_check("XMSG_READDATA_", ferr);
        }
        for (inx = 0; inx < MAX_OUT; inx++) {
            array.add();
            array.set_val(inx, inx);
        }
        if (linker)
            sleep(1);
        if (listener)
            util_abort_core_free();
        for (inx = 0; inx < MAX_OUT; inx++) {
            int rnd =
              (int) (1.0 * array.get_size() * rand_r(&seed) / (RAND_MAX + 1.0));
            int xinx = array.get_val(rnd);
            array.remove(rnd);
            rep_ctrl_size = (xinx + 3) % MAX_DATA;
            rep_data_size = (xinx + 4) % MAX_DATA;
            XMSG_REPLY_(sres[xinx].sre_msgId,    // msgid
                        recv_srv_c_buffer[xinx], // replyctrl
                        (ushort) rep_ctrl_size,  // replyctrlsize
                        recv_srv_d_buffer[xinx], // replydata
                        (ushort) rep_data_size,  // replydatasize
                        0,                       // errorclass
                        NULL);                   // newphandle
        }
    }

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    if (linker)
        util_test_finish(!client);
    else
        util_test_finish(client);
    return 0;
}
Example #28
0
int main(int argc, char *argv[]) {
    bool            exit;
    int             ferr;
    int             lerr;
    int             msgid;
    int             nid;
    int             oid;
    int             pid;
    TPT_DECL       (phandle);
    char            recv_buffer[BUFSIZ];
    short           recv_buffer2[BUFSIZ];
    MS_Result_Type  results;
    MS_SRE          sre;

    ferr = msfs_util_init_role(true, &argc, &argv, msg_debug_hook);
    TEST_CHK_FEOK(ferr);
    util_test_start(true);
    ferr = msg_mon_process_startup(true); // system messages
    TEST_CHK_FEOK(ferr);
    msg_mon_enable_mon_messages(true);
    printf("cli: opening server\n");
    ferr = msg_mon_get_process_info((char *) "$srv", &nid, &pid);
    TEST_CHK_FEOK(ferr);
    printf("cli: server opened\n");
    ferr = msg_mon_open_process((char *) "$srv",      // name
                                TPT_REF(phandle),
                                &oid);
    TEST_CHK_FEOK(ferr);
    exit = false;
    while (!exit) {
        lerr = XWAIT(LREQ, -1);
        TEST_CHK_WAITIGNORE(lerr);
        for (;;) {
            lerr = XMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
            if (lerr == XSRETYPE_NOWORK)
                break;
            ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                  recv_buffer,    // reqdata
                                  BUFSIZ);        // bytecount
            util_check("XMSG_READDATA_", ferr);
            if (sre.sre_flags & XSRE_MON) {
                MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
                printf("cli: mon message, type=%d\n", msg->type);
                if (msg->type == MS_MsgType_Open) {
                    ferr = msg_mon_get_process_info((char *) "$srv", &nid, &pid);
                    TEST_CHK_FEOK(ferr);
                    assert(msg->u.open.nid == nid);
                    assert(msg->u.open.pid == pid);
                    assert(strcasecmp(msg->u.open.target_process_name, "$srv") == 0);
                    exit = true;
                }
            } else {
                printf("cli: NON-mon message\n");
            }
            XMSG_REPLY_(sre.sre_msgId,       // msgid
                        NULL,                // replyctrl
                        0,                   // replyctrlsize
                        NULL,                // replydata
                        0,                   // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
        }
    }
    printf("cli: sending message to server\n");
    ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                      &msgid,                      // msgid
                      NULL,                        // reqctrl
                      0,                           // reqctrlsize
                      recv_buffer2,                // replyctrl
                      1,                           // replyctrlmax
                      NULL,                        // reqdata
                      0,                           // reqdatasize
                      recv_buffer,                 // replydata
                      BUFSIZ,                      // replydatamax
                      0,                           // linkertag
                      0,                           // pri
                      0,                           // xmitclass
                      0);                          // linkopts
    util_check("XMSG_LINK_", ferr);
    ferr = XMSG_BREAK_(msgid, (short *) &results, TPT_REF(phandle));
    util_check("XMSG_BREAK_", ferr);
    exit = false;
    while (!exit) {
        lerr = XWAIT(LREQ, -1);
        for (;;) {
            lerr = XMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
            if (lerr == XSRETYPE_NOWORK)
                break;
            ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                  recv_buffer,    // reqctrl
                                  BUFSIZ);        // bytecount
            util_check("XMSG_READDATA_", ferr);
            if (sre.sre_flags & XSRE_MON) {
                MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
                printf("cli: mon message, type=%d\n", msg->type);
                if (msg->type == MS_MsgType_ProcessDeath) {
                    assert(msg->u.death.nid == nid);
                    assert(msg->u.death.pid == pid);
                    exit = true;
                }
            } else
                printf("cli: NON-mon message\n");
            XMSG_REPLY_(sre.sre_msgId,       // msgid
                        NULL,                // replyctrl
                        0,                   // replyctrlsize
                        NULL,                // replydata
                        0,                   // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
        }
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(true);
    return 0;
}
Example #29
0
int main(int argc, char *argv[]) {
    int        ferr;
    TPT_DECL2 (phandle,MAX_SERVERS);
    int        inx;
    int        lerr;
    int        loop = 10;
    int        max;
    int        maxsp = 1;
    int        oid;
    int        pinx;
    MS_SRE     sre;
    bool       verbose = false;
    TAD        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxcp",     TA_Int,  MAX_CLIENTS, &maxcp     },
      { "-maxsp",     TA_Int,  MAX_SERVERS, &maxsp     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    ferr = msg_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    msfs_util_init_fs(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    if (maxcp < 0)
        maxcp = 1;
    if (maxsp < 0)
        maxsp = 1;
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    if (!client)
        msg_mon_enable_mon_messages(true);
    ferr = msg_mon_get_my_process_name(my_name, BUFSIZ);
    TEST_CHK_FEOK(ferr);

    // process-wait for clients/servers/shell
    ferr = msfs_util_wait_process_count(MS_ProcessType_Generic,
                                        maxcp + maxsp + 1,
                                        NULL,
                                        verbose);
    TEST_CHK_FEOK(ferr);
    sleep(3); // wait for all process_count's to complete
    if (client) {
        pinx = atoi(&my_name[4]);
        assert(pinx >= 0);
        printf("loop=%d\n", loop);
        for (inx = 0; inx < loop; inx++) {
            for (pinx = 0; pinx < maxsp; pinx++) {
                sprintf(serv, "$srv%d", pinx);
                ferr = msg_mon_open_process(serv,
                                            TPT_REF2(phandle,pinx),
                                            &oid);
                TEST_CHK_FEOK(ferr);
            }
            for (pinx = 0; pinx < maxsp; pinx++) {
                ferr = msg_mon_close_process(TPT_REF2(phandle,pinx));
                TEST_CHK_FEOK(ferr);
                if (verbose)
                    printf("%s-close-count=%d\n", my_name, inx);
            }
        }
    } else {
        max = 2 * maxcp * loop;
        for (inx = 0; inx < max; inx++) {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            ferr = XMSG_READCTRL_(sre.sre_msgId,        // msgid
                                  recv_buffer2,         // reqctrl
                                  sre.sre_reqCtrlSize); // bytecount
            util_check("XMSG_READCTRL_", ferr);
            ferr = XMSG_READDATA_(sre.sre_msgId,        // msgid
                                  recv_buffer,          // reqdata
                                  sre.sre_reqDataSize); // bytecount
            util_check("XMSG_READDATA_", ferr);
            XMSG_REPLY_(sre.sre_msgId,         // msgid
                        recv_buffer2,          // replyctrl
                        sre.sre_reqCtrlSize,   // replyctrlsize
                        recv_buffer,           // replydata
                        sre.sre_reqDataSize,   // replydatasize
                        1,                     // errorclass
                        NULL);                 // newphandle
            if (verbose)
                printf("%s-count=%d\n", my_name, inx);
        }
        sleep(5);
    }

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Example #30
0
int main(int argc, char *argv[]) {
    int             arg;
    bool            bm = false;
    char           *buf;
    double          busy;
    bool            chook = false;
    bool            client = false;
    char            errnobuf[100];
    char            error_txt[200];
    int             event_len;
    char            event_data[MS_MON_MAX_SYNC_DATA];
    int             ferr;
    int             inx;
    int             key;
    int             lerr;
    int             loop = 10;
    int             msid;
    int             pid;
    char            prog[MS_MON_MAX_PROCESS_PATH];
    struct rusage   r_start;
    struct rusage   r_stop;
    const char     *server_name = "$SRV";
    int             server_nid;
    TPT_DECL       (server_phandle);
    int             server_pid;
    bool            shook = false;
    struct timeval  t_elapsed;
    struct timeval  t_start;
    struct timeval  t_stop;
    TAD             zargs[] = {
      { "-bm",        TA_Bool, TA_NOMAX,    &bm        },
      { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-shook",     TA_Bool, TA_NOMAX,    &shook     },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    ferr = msg_init(&argc, &argv);
    arg_proc_args(zargs, false, argc, argv);
    if (chook && client)
        test_debug_hook("c", "c");
    if (shook && !client)
        test_debug_hook("s", "s");
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    proc_enable_external_wakeups();  // allow external wakeups
    if (client) {
        ferr = msg_mon_get_process_info(NULL, &server_nid, &server_pid);
        TEST_CHK_FEOK(ferr);
        sprintf(prog, "%s/%s", getenv("PWD"), argv[0]);
        for (arg = 0; arg < argc; arg++)
            if (strcmp(argv[arg], "-client") == 0) // start_process
                argv[arg] = (char *) "-server";
        ferr = msg_mon_start_process(prog,                   // prog
                                     (char *) server_name,   // name
                                     NULL,                   // ret name
                                     argc,
                                     argv,
                                     TPT_REF(server_phandle),
                                     0,                      // open
                                     NULL,                   // oid
                                     MS_ProcessType_Generic, // type
                                     0,                      // priority
                                     0,                      // debug
                                     0,                      // backup
                                     &server_nid,            // nid
                                     &server_pid,            // pid
                                     NULL,                   // infile
                                     NULL);                  // outfile
        printf("process started, err=%d\n", ferr);
        TEST_CHK_FEOK(ferr);
    }
    util_gethostname(my_name, sizeof(my_name));
    lerr = XWAIT(LREQ, -1); // remove first LREQ
    assert(lerr == LREQ);
    ferr = msg_mon_get_my_segid(&key);
    TEST_CHK_FEOK(ferr);
    // process-wait for client/server/shell
    ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, 3, NULL, false);
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_event_wait(1, &event_len, event_data);
        TEST_CHK_FEOK(ferr);
        msid = shmget(key, sizeof(recv_buffer), 0640);
        if (msid == -1) {
            perror("client shmget");
            sprintf(error_txt, "client shmget(%d)=%s\n",
                    key,
                    strerror_r(errno, errnobuf, sizeof(errnobuf)));
        }
        assert(msid != -1);
        buf = (char *) shmat(msid, NULL, 0);
        assert(buf != NULL);
    } else {
        msid = shmget(key, sizeof(recv_buffer), IPC_CREAT | 0640);
        if (msid == -1) {
            perror("server shmget");
            sprintf(error_txt, "server shmget(%d)=%s\n",
                    key,
                    strerror_r(errno, errnobuf, sizeof(errnobuf)));
        }
        assert(msid != -1);
        buf = (char *) shmat(msid, NULL, 0);
        assert(buf != NULL);
        ferr =
          msg_mon_event_send(-1,                         // nid
                             -1,                         // pid
                             MS_ProcessType_Undefined,   // process-type
                             1,                          // event-id
                             0,                          // event-len
                             NULL);                      // event-data
        TEST_CHK_FEOK(ferr);
        ferr = msg_mon_event_wait(1, &event_len, event_data);
        TEST_CHK_FEOK(ferr);
    }

    util_time_timer_start(&t_start);
    util_cpu_timer_start(&r_start);
    if (client) {
        pid = server_pid;
        for (inx = 0; inx < loop; inx++) {
            lerr = XPROCESS_AWAKE_(pid, LREQ);
            assert(lerr == XZFIL_ERR_OK);
            lerr = XWAIT(LDONE, -1);
            assert(lerr == LDONE);
        }
    } else {
        ferr = msg_mon_get_process_info((char *) "$CLI", &server_nid, &pid);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            lerr = XWAIT(LREQ, -1);
            assert(lerr == LREQ);
            lerr = XPROCESS_AWAKE_(pid, LDONE);
            assert(lerr == XZFIL_ERR_OK);
        }
    }
    util_cpu_timer_stop(&r_stop);
    util_time_timer_stop(&t_stop);
    util_time_elapsed(&t_start, &t_stop, &t_elapsed);
    util_cpu_timer_busy(&r_start, &r_stop, &t_elapsed, &busy);

    if (client) {
        if (!bm)
            print_elapsed("", &t_elapsed);
        print_rate(bm, "", loop, 1024, &t_elapsed, busy);
    } else
        print_server_busy(bm, "", busy);

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}