Esempio n. 1
0
int main(int argc, char *argv[]) {
    bool            attach = false;
    bool            chook = false;
    bool            client = false;
    const char     *cname = "$cli";
    int             count;
    int             ferr;
    int             inx;
    int             len;
    int             lerr;
    int             loop = 10;
    int             msgid;
    int             oid;
    TPT_DECL       (phandle);
    char           *pname = NULL;
    RT              results;
    int             send_len;
    bool            shook = false;
    const char     *sname = "$srv";
    MS_SRE          sre;
    long            t_elapsed;
    struct timeval  t_start;
    struct timeval  t_stop;
    TAD             zargs[] = {
      { "-attach",    TA_Bool, TA_NOMAX,    &attach    },
      { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-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     },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    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);

    // 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 *) sname,       // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    }

    util_gethostname(my_name, sizeof(my_name));
    msg_mon_enable_mon_messages(true);
    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_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 {
                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);
    }
    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;
}
Esempio n. 2
0
int main(int argc, char *argv[]) {
    int                 abandon = 0;
    bool                client = false;
    int                 closes;
    int                 count;
    int                 count_abandon;
    int                 ferr;
    int                 inxl;
    int                 inxo;
    int                 inxs;
    int                 lerr;
    int                 loop = 10;
    int                 maxcp = 1;
    int                 maxout = 1;
    int                 maxsp = 1;
    int                 msgid[MAX_OUT];
    int                 msg_count;
    bool                mq = false;
    int                 oid;
    TPT_DECL2          (phandle, MAX_SRV);
    int                 recv_len;
    RT                  results;
    int                 send_len;
    char                serv[20];
    BMS_SRE             sre;
    bool                verbose = false;
    TAD                 zargs[] = {
      { "-abandon",   TA_Int,  TA_NOMAX,    &abandon   },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxcp",     TA_Int,  MAX_CLI,     &maxcp     },
      { "-maxout",    TA_Int,  MAX_OUT,     &maxout    },
      { "-maxsp",     TA_Int,  MAX_SRV,     &maxsp     },
      { "-mq",        TA_Bool, TA_NOMAX,    &mq        },
      { "-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);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_get_my_process_name(my_name, BUFSIZ);
    util_check("msg_mon_get_my_process_name", ferr);

    if (client) {
        ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETSENDLIMIT,
                                     XMAX_SETTABLE_SENDLIMIT);
        assert(ferr == XZFIL_ERR_OK);
        msg_count = 0;
        count_abandon = 0;
        for (inxl = 0; inxl < loop; inxl++) {
            for (inxs = 0; inxs < maxsp; inxs++) {
                sprintf(serv, "$srv%d", inxs);
                ferr = msg_mon_open_process((char *) serv,       // name
                                            TPT_REF2(phandle, inxs),
                                            &oid);
                TEST_CHK_FEOK(ferr);
            }
            count = 0;
            if (abandon)
                count_abandon = rnd(abandon);
            for (inxs = 0; inxs < maxsp; inxs++) {
                for (inxo = 0; inxo < maxout; inxo++) {
                    send_len = rnd(BUFSIZ);
                    ferr = BMSG_LINK_(TPT_REF2(phandle, inxs), // phandle
                                      &msgid[inxo],            // msgid
                                      NULL,                    // reqctrl
                                      0,                       // reqctrlsize
                                      NULL,                    // replyctrl
                                      0,                       // replyctrlmax
                                      send_buffer[inxo],       // reqdata
                                      send_len,                // reqdatasize
                                      recv_buffer[inxo],       // replydata
                                      BUFSIZ,                  // replydatamax
                                      0,                       // linkertag
                                      0,                       // pri
                                      0,                       // xmitclass
                                      0);                      // linkopts
                    util_check("XMSG_LINK_", ferr);
                }
            }
            for (inxs = 0; inxs < maxsp; inxs++) {
                for (inxo = 0; inxo < maxout; inxo++) {
                    msg_count++;
                    if (verbose)
                        printf("client(%s): msg-count=%d\n",
                               my_name, msg_count);
                    count++;
                    if (abandon && (count >= count_abandon)) {
                        if (verbose)
                            printf("client(%s): sending abandon, count=%d\n",
                                   my_name, count);
                        count_abandon = rnd(abandon);
                        count = 0;
                        ferr = XMSG_ABANDON_(msgid[inxo]);
                        util_check("XMSG_ABANDON_", ferr);
                    } else {
                        ferr = BMSG_BREAK_(msgid[inxo],
                                           results.u.s,
                                           TPT_REF2(phandle, inxs));
                        util_check("XMSG_BREAK_", ferr);
                    }
                }
            }
            if (mq) {
                if ((inxl % 100) == 0)
                    printf("client(%s): count=%d\n", my_name, inxl);
            }
        }
        for (inxs = 0; inxs < maxsp; inxs++) {
            ferr = msg_mon_close_process(TPT_REF2(phandle, inxs));
            TEST_CHK_FEOK(ferr);
        }
    } else {
        ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETRECVLIMIT,
                                     XMAX_SETTABLE_RECVLIMIT);
        assert(ferr == XZFIL_ERR_OK);
        closes = 0;
        msg_count = 0;
        msg_mon_enable_mon_messages(true);
        // process requests
        for (;;) {
            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) {
                ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                      recv_buffer[0], // reqdata
                                      BUFSIZ);        // bytecount
                util_check("XMSG_READDATA_", ferr);
                MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer[0];
                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 {
                msg_count++;
                if (verbose)
                    printf("server(%s): msg-count=%d\n",
                           my_name, msg_count);
            }
            recv_len = rnd(BUFSIZ);
            BMSG_REPLY_(sre.sre_msgId,       // msgid
                        NULL,                // replyctrl
                        0,                   // replyctrlsize
                        recv_buffer[0],      // replydata
                        recv_len,            // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
            if (closes >= maxcp)
                break;
        }
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Esempio n. 3
0
int main(int argc, char *argv[]) {
    bool      client = false;
    bool      client2 = false;
    int       close_count;
    int       cnid;
    int       cpid;
    int       ferr;
    bool      fin = false;
    int       inx;
    int       lerr;
    int       loop = 10;
    int       oid;
    char     *sname = (char *) "$srv";
    BMS_SRE   sre;
    bool      verbose = false;
    TAD       zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-client2",   TA_Bool, TA_NOMAX,    &client2   },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "-verbose",   TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    arg_proc_args(zargs, false, argc, argv);
    ferr = msg_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    util_test_start(client);
    ferr = msg_mon_process_startup(true); // system messages
    TEST_CHK_FEOK(ferr);
    if (client) {
        msg_debug_hook("c", "c");
        sprintf(cprog, "%s/%s", getenv("PWD"), argv[0]);
        for (inx = 0; inx < argc; inx++) {
            if (strcmp(argv[inx], "-client") == 0)
                argv[inx] = (char *) "-client2";
        }
        for (inx = 0; inx < loop; inx++) {
            if (verbose)
                printf("cli: newproc, inx=%d\n", inx);
            sprintf(cname, "$cli%d", inx);
            cnid = -1;
            ferr = msg_mon_start_process(cprog,                  // prog
                                         cname,                  // name
                                         NULL,                   // ret_name
                                         argc,                   // argc
                                         argv,                   // argv
                                         TPT_REF(cphandle),      // phandle
                                         false,                  // open
                                         NULL,                   // oid
                                         MS_ProcessType_Generic, // type
                                         0,                      // priority
                                         false,                  // debug
                                         false,                  // backup
                                         &cnid,                  // nid
                                         &cpid,                  // pid
                                         NULL,                   // infile
                                         NULL);                  // outfile
            TEST_CHK_FEOK(ferr);
        }
    } else if (client2) {
        if (verbose)
            printf("cli: open\n");
        ferr = msg_mon_open_process(sname,  // name
                                    TPT_REF(sphandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    } else {
        msg_mon_enable_mon_messages(true);
        close_count = 0;
        for (inx = 0; !fin; inx++) {
            do {
                lerr = XWAIT(LREQ, -1);
                lerr = BMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == BSRETYPE_NOWORK);
            if (sre.sre_flags & XSRE_MON) {
                ferr = BMSG_READDATA_(sre.sre_msgId,  // msgid
                                      recv_buffer,    // reqdata
                                      BUFSIZ);        // bytecount
                MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
                if (verbose)
                    printf("srv: rcvd mon msg=%d, inx=%d\n", msg->type, inx);
                if (msg->type == MS_MsgType_Close)
                    if (++close_count >= loop)
                        fin = true;
            }
            if (verbose)
                printf("srv: reply, inx=%d\n", inx);
            BMSG_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(client);
    return 0;
}
Esempio n. 4
0
int main(int argc, char *argv[]) {
    bool             chook = false;
    bool             client = false;
    FILE            *f;
    bool             fail = false;
    int              ferr;
    int              lerr;
    int              msgid;
    int              oid;
    TPT_DECL        (phandle);
    MS_Result_Type   results;
    MS_SRE           sre;
    TAD              zargs[] = {
      { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-cluster",   TA_Ign,  TA_NOMAX,    NULL       },
      { "-fail",      TA_Bool, TA_NOMAX,    &fail      },
      { "-verbose",   TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    arg_proc_args(zargs, false, argc, argv);
    if (chook)
        test_debug_hook("c", "c");
    util_test_start(true);
    if (client) {
        f = NULL;
        while (f == NULL) {
            f = fopen("z100", "r");
            if (f == NULL)
                sleep(1);
        }
        fclose(f);
    }
    if (client)
        ferr = msg_init_attach(&argc, &argv, true, (char *) "$CLI");
    else
        ferr = msg_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_process_startup(!client); // system messages
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_open_process((char *) "$SRV", TPT_REF(phandle), &oid);
        TEST_CHK_FEOK(ferr);
        if (fail)
            util_abort_core_free();
        ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                          &msgid,                      // msgid
                          NULL,                        // reqctrl
                          0,                           // reqctrlsize
                          recv_buffer3,                // replyctrl
                          0,                           // replyctrlmax
                          NULL,                        // reqdata
                          0,                           // reqdatasize
                          recv_buffer,                 // replydata
                          0,                           // replydatamax
                          0,                           // linkertag
                          0,                           // pri
                          0,                           // xmitclass
                          0);                          // linkopts
        TEST_CHK_FEOK(ferr);
        ferr = XMSG_BREAK_(msgid, (short *) &results, TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        f = fopen("z100", "w");
        assert(f != NULL);
        fclose(f);
        for (;;) {
            do {
                lerr = XWAIT(LREQ, 20);
                TEST_CHK_WAITIGNORE(lerr);
                if (!lerr)
                    continue;
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            if (sre.sre_flags & XSRE_MON)
                printf("server received mon message\n");
            else
                printf("server received regular message\n");
            XMSG_REPLY_(sre.sre_msgId,       // msgid
                        recv_buffer2,        // replyctrl
                        0,                   // replyctrlsize
                        recv_buffer,         // replydata
                        0,                   // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
            if ((sre.sre_flags & XSRE_MON) == 0)
                break;
        }
    }

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);

    util_test_finish(true);
    return 0;
}
Esempio n. 5
0
int main(int argc, char *argv[]) {
    bool               client = false;
    int                ferr;
    int                inx;
    int                len;
    int                lerr;
    int                oid;
    char               recv_buffer[BUFSIZ];
    short              recv_buffer2[BUFSIZ];
    MS_SRE             sre;
    int                status;
    SB_Thread::Thread *thr[MAX_THR];
    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);
    if (client)
        printf("threads=%d, msgs-per-thread=%d, msgs=%d\n",
               MAX_THR, MAX_MSGS_PER_THR, MAX_MSGS);
    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) {
        for (inx = 0; inx < MAX_THR; inx++) {
            char name[10];
            sprintf(name, "c%d", inx);
            thr[inx] = new SB_Thread::Thread(client_thr, name);
        }
        for (inx = 0; inx < MAX_THR; inx++)
            thr[inx]->start();
        for (inx = MAX_THR - 1; inx >= 0; inx--) {
            void *res;
            status = thr[inx]->join(&res);
            TEST_CHK_STATUSOK(status);
            printf("joined with client %d\n", inx);
        }
        for (inx = 0; inx < MAX_THR; inx++)
            delete thr[inx];
    } else {
        for (inx = 0; inx < MAX_MSGS;) {
            lerr = XWAIT(LREQ, -1);
            TEST_CHK_WAITIGNORE(lerr);
            do {
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
                if (lerr == XSRETYPE_IREQ) {
                    inx++;
                    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
                } else {
                    assert(lerr == XSRETYPE_NOWORK);
                }
            } while (lerr != XSRETYPE_NOWORK);
        }
    }

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    }
    printf("%s shutting down\n", client ? "client" : "server");
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Esempio n. 6
0
int main(int argc, char *argv[]) {
    int                arg;
    char               buf[BUFSIZ];
    bool               client = false;
    int                disable;
    int                ferr;
    int                inx;
    int                len;
    int                lerr;
    int                oid;
    void              *result;
    MS_SRE             sre;
    int                status;
    SB_Thread::Thread *thr_send[MAX_THREADS];
    TAD                zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-threads",   TA_Int,  MAX_THREADS, &threads   },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    gargc = &argc;
    gargv = argv;
    arg_proc_args(zargs, false, argc, argv);
    for (arg = 1; arg < argc; arg++) {
        if (strcmp(argv[arg], "-client") == 0) // start_process
            argv[arg] = (char *) "-server"; // set to server for start-process
    }
    if (threads < 1)
        threads = 1;
    if (client)
        strcpy(who, "client");
    else
        strcpy(who, "server");
    util_test_start(client);
    ferr = msg_mon_process_startup(true);  // system messages?
    TEST_CHK_FEOK(ferr);
    if (client) {
        if (verbose)
            printf("%s - opening server\n", who);
        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) {
        disable = msg_test_assert_disable();
        for (inx = 0; inx < threads; inx++) {
            sprintf(buf, "%d", inx);
            thr_send[inx] = new SB_Thread::Thread(thread_send_fun, buf);
            thr_send[inx]->start();
        }
        for (inx = 0; inx < threads; inx++) {
            status = thr_send[inx]->join(&result);
            TEST_CHK_STATUSOK(status);
            delete thr_send[inx];
        }
        thread_send_fun(NULL);
        msg_test_assert_enable(disable);
    } else {
        inx = 0;
        for (;;) {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            inx++;
            if (inx > 4)
                util_abort_core_free(); // don't reply
            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);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            len = (int) strlen(recv_buffer) + 1;
            len = len; // touch
            XMSG_REPLY_(sre.sre_msgId,             // msgid
                        NULL,                      // replyctrl
                        0,                         // replyctrlsize
                        recv_buffer,               // replydata
                        39000,                     // replydatasize
                        0,                         // errorclass
                        NULL);                     // newphandle
            if (sre.sre_reqDataSize == 0)
                break;
        }
    }
    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;
}
Esempio n. 7
0
int main(int argc, char *argv[]) {
    bool       client = false;
    int        ferr;
    int        inx;
    int        loop = 10;
    int        msgid;
    int        oid;
    TPT_DECL  (phandle);
    char       recv_buffer[40000];
    RT         results;
    char       send_buffer[40000];
    int        status;
    TAD        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-delay",     TA_Bool, TA_NOMAX,    &delay     },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxs",      TA_Int,  TA_NOMAX,    &maxs      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           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);
    util_gethostname(my_name, sizeof(my_name));

    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            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);
            ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
            assert(results.u.t.ctrl_size == 0);
            assert(results.u.t.errm == RT_DATA_RCVD); // data
            printf("%s\n", recv_buffer);
        }
        for (inx = 0; inx < maxs; inx++) {
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              NULL,                        // reqctrl
                              0,                           // reqctrlsize
                              NULL,                        // replyctrl
                              0,                           // replyctrlmax
                              send_buffer,                 // reqdata
                              0,                           // reqdatasize
                              recv_buffer,                 // replydata
                              0,                           // 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);
            printf("fin %d\n", inx);
        }
    } else {
        msg_mon_enable_mon_messages(true);
        for (inx = 0; inx < maxs; inx++) {
            char name[10];
            sprintf(name, "s%d", inx);
            thrs[inx] = new Server_Thread(server_thr, name, inx);
        }
        for (inx = 0; inx < maxs; inx++) {
            thrs[inx]->start();
            SB_Thread::Sthr::yield();
        }
        for (inx = 0; inx < maxs; inx++) {
            void *res;
            status = thrs[inx]->join(&res);
            TEST_CHK_STATUSOK(status);
            printf("joined with server %d\n", inx);
        }
    }
    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;
}
Esempio n. 8
0
int main(int argc, char *argv[]) {
    char           *cli;
    int             ferr;
    int             lerr;
    int             msgid;
    int             nid;
    int             oid;
    TPT_DECL       (phandle);
    int             pid;
    MS_Result_Type  results;
    int             send_len;
    const char     *sname = "$srv";
    MS_SRE          sre;

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

    sprintf(prog, "%s/%s", getenv("PWD"), argv[0]);
    cli = strstr(prog, "cli");
    strcpy(cli, "srv");
    nid = 0;
    ferr = msg_mon_start_process_nowait(prog,                     // prog
                                        (char *) sname,           // name
                                        retname,                  // ret-name
                                        argc,                     // argc
                                        argv,                     // argv
                                        TPT_REF(phandle),         // phandle
                                        MS_ProcessType_Generic,   // type
                                        0,                        // priority
                                        false,                    // debug
                                        false,                    // backup
                                        0x123456789abcdefLL,      // tag
                                        &nid,                     // nid
                                        &pid,                     // pid
                                        NULL,                     // infile
                                        NULL);                    // outfile
    TEST_CHK_FEOK(ferr);
    assert(strcasecmp(retname, sname) == 0);
    assert(nid == 0);
    lerr = XWAIT(LREQ, -1);
    TEST_CHK_WAITIGNORE(lerr);
    for (;;) {
        lerr = XMSG_LISTEN_((short *) &sre, // sre
                            0,              // listenopts
                            0);             // listenertag
        if (lerr == XSRETYPE_NOWORK)
            continue;
        ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                              recv_buffer,    // reqdata
                              BUFSIZ);        // bytecount
        TEST_CHK_FEOK(ferr);
        if (sre.sre_flags & XSRE_MON) {
            MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
            printf("client (%s) received mon message, type=%d\n",
                   pname, msg->type);
            assert(msg->type == MS_MsgType_ProcessCreated);
            printf("client (%s) received new process message, ferr=%d, nid=%d, pid=%d, tag=0x%llx, pname=%s\n",
                   pname,
                   msg->u.process_created.ferr,
                   msg->u.process_created.nid,
                   msg->u.process_created.pid,
                   msg->u.process_created.tag,
                   msg->u.process_created.process_name);
            assert(msg->u.process_created.ferr == XZFIL_ERR_OK);
            assert(msg->u.process_created.tag == 0x123456789abcdefLL);
            ferr = msg_mon_open_process((char *) sname,       // name
                                        TPT_REF(phandle),
                                        &oid);
            TEST_CHK_FEOK(ferr);
        }
        XMSG_REPLY_(sre.sre_msgId,       // msgid
                    NULL,                // replyctrl
                    0,                   // replyctrlsize
                    NULL,                // replydata
                    0,                   // replydatasize
                    0,                   // errorclass
                    NULL);               // newphandle
        if (sre.sre_flags & XSRE_MON)
            break;
    }

    strcpy(send_buffer, "hello, greetings from client");
    send_len = (int) strlen(send_buffer) + 1;
    ferr = BMSG_LINK_(TPT_REF(phandle),            // phandle
                      &msgid,                      // msgid
                      NULL,                        // reqctrl
                      0,                           // 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
    TEST_CHK_FEOK(ferr);
    ferr = BMSG_BREAK_(msgid, (short *) &results, TPT_REF(phandle));
    TEST_CHK_FEOK(ferr);
    printf("%s\n", recv_buffer);

    ferr = msg_mon_close_process(TPT_REF(phandle));
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    return 0;
}
Esempio n. 9
0
int main(int argc, char *argv[]) {
    bool       client = false;
    unsigned   expR3;
    int        ferr;
    int        inx;
    int        lc;
    int        lerr;
    int        msgid;
    int        oid;
    RT         results;
    TPT_DECL  (phandle);
    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));

    lc = (int) (sizeof(res)/sizeof(Test_Results));
    for (inx = 0; inx < lc; inx++) {
        if (client) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              ctrl_buffer,                 // reqctrl
                              res[inx].cQc,                // reqctrlsize
                              ctrl_buffer,                 // replyctrl
                              res[inx].cPcM,               // replyctrlmax
                              send_buffer,                 // reqdata
                              res[inx].cQd,                // reqdatasize
                              recv_buffer,                 // replydata
                              res[inx].cPdM,               // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
//          ferr = XMSG_ISDONE_(msgid);
//          checkdone("XMSG_ISDONE_", ferr);
            results.u.t.ctrl_size = (uint) -1;
            results.u.t.data_size = (uint) -1;
            results.u.t.errm = (uint) -1;
            ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
            if (results.u.t.ctrl_size != res[inx].cEpC) {
                printf("*** ERROR inx=%d, results.ctrl_size=%d, cEpC=%d\n",
                       inx, (int) results.u.t.ctrl_size, (int) res[inx].cEpC);
                assert(results.u.t.ctrl_size == res[inx].cEpC);
            }
            if (results.u.t.data_size != (uint) res[inx].cEpD) {
                printf("*** ERROR inx=%d, results.data_size=%d, cEpD=%d\n",
                       inx, (int) results.u.t.data_size, (int) res[inx].cEpD);
                assert(results.u.t.data_size == res[inx].cEpD);
            }
            expR3 = 0x0; // no-data
            if (res[inx].cEpD > 0)
                expR3 |= 0x2; // data
            if (results.u.t.errm != expR3) {
                printf("*** ERROR inx=%d, results.errm=%x, expR3=%x\n",
                       inx, results.u.t.errm, expR3);
                assert(results.u.t.errm == expR3);
            }
        } else {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            if (sre.sre_reqCtrlSize != res[inx].sEqC) {
                printf("*** ERROR inx=%d, sre.sre_reqCtrlSize=%d, sEqC=%d\n",
                       inx, sre.sre_reqCtrlSize, res[inx].sEqC);
                assert(sre.sre_reqCtrlSize == res[inx].sEqC);
            }
            if (sre.sre_reqDataSize != res[inx].sEqD) {
                printf("*** ERROR inx=%d, sre.sre_reqDataSize=%d, sEqD=%d\n",
                       inx, sre.sre_reqDataSize, res[inx].sEqD);
                assert(sre.sre_reqDataSize == res[inx].sEqD);
            }
            ferr = XMSG_READCTRL_(sre.sre_msgId,  // msgid
                                  ctrl_buffer,    // reqctrl
                                  res[inx].sQc);  // bytecount
            util_check("XMSG_READCTRL_", ferr);
            ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                  recv_buffer,    // reqdata
                                  res[inx].sQd);  // bytecount
            util_check("XMSG_READDATA_", ferr);
            XMSG_REPLY_(sre.sre_msgId,            // msgid
                        (short *) recv_buffer,    // replyctrl
                        res[inx].sPc,             // replyctrlsize
                        recv_buffer,              // replydata
                        res[inx].sPd,             // replydatasize
                        0,                        // errorclass
                        NULL);                    // newphandle
        }
    }
    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
        printf("if there were no asserts, all is well\n");
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Esempio n. 10
0
int main(int argc, char *argv[]) {
    bool       client = false;
    int        disable;
    int        ferr;
    int        inx;
    int        len;
    int        lerr;
    int        loop = 10;
    int        msgid;
    int        oid;
    TPT_DECL  (phandle);
    RT         results;
    MS_SRE     sre;
    TPT_DECL  (xphandle);
    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       }
    };

    setenv("MS_STREAMS_MAX", "10", 1);
    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 {
        disable = msg_test_assert_disable();
        for (inx = 0; inx < 20; inx++) {
            ferr = msg_mon_open_process((char *) "$crap", // name
                                        TPT_REF(xphandle),
                                        &oid);
            assert(ferr != XZFIL_ERR_OK);
        }
        msg_test_assert_enable(disable);
    }
    util_gethostname(my_name, sizeof(my_name));

    for (inx = 0; inx < loop; inx++) {
        if (client) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            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);
            ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
            assert(results.u.t.ctrl_size == 0);
            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
                                  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);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            len = (int) strlen(recv_buffer) + 1;
            len = len; // touch - not currently used
            XMSG_REPLY_(sre.sre_msgId,  // msgid
                        NULL,           // replyctrl
                        0,              // replyctrlsize
                        recv_buffer,    // replydata
                        39000,          // 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);
    util_test_finish(client);
    return 0;
}
Esempio n. 11
0
// -------------------------------------------------------------
// adp_module_init
// Purpose - initialize module for use
// -------------------------------------------------------------
void TM_Audit::adp_module_init()
{
    TMTrace(2, ("TM_Audit::adp_module_init: ENTER\n"));

    MS_Mon_Reg_Get_Type lv_info;
    char  lv_my_pname[8+1];
    char  lv_tlog_pname[8+1];
    int   lv_len = 8;
    int   lv_err = 0;
    int32 lv_oid = 0;
    TPT_DECL (lv_phandle);
    int   lv_TLOG_index = TLOG_AuditTrailIndex;

    if (iv_initialized)
        return;

    msg_mon_get_my_process_name(lv_my_pname,lv_len);

    lv_err = msg_mon_reg_get(MS_Mon_ConfigType_Process, false,
                             lv_my_pname, (char *)"TMASE", &lv_info);
    if ((lv_err == 0) && (lv_info.num_returned == 1))
    {
        strncpy (lv_tlog_pname, lv_info.list[0].value, 8);
        TMTrace(3, ("TM_Audit::adp_module_init: %s opening TLOG %s\n", lv_my_pname, lv_tlog_pname));

        lv_err = msg_mon_open_process(lv_tlog_pname, &lv_phandle, &lv_oid);

        if (!lv_err)
        {
            memcpy (&iv_adp_phandle, &lv_phandle, sizeof (SB_Phandle_Type));
            // If we using multiple TLOGs, we need to set the correct index (= nid)
            if (gv_tm_info.TLOGperTM())
               lv_TLOG_index = gv_tm_info.nid();
            iv_initialized = true;
        }
        else
        {
           TMTrace(1, ("TM_Audit::adp_module_init: error %d opening TLOG %s\n",
                    lv_err, lv_tlog_pname));
           tm_log_event(DTM_AUDIT_FAILED_ADPOPEN, SQ_LOG_CRIT, "DTM_AUDIT_FAILED_ADPOPEN",
                        lv_err, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
                        -1, -1, -1, -1, lv_my_pname);

           // Fast fail here if $TLOG is gone as we can't continue in M8.
           if (lv_err == FENOSUCHDEV)
           {
              gv_tm_info.error_shutdown_abrupt(lv_err);
              // Abort without core - don't need the core in this case.
              struct rlimit limit;
              limit.rlim_cur = 0;
              limit.rlim_max = 0;
              setrlimit(RLIMIT_CORE, &limit);
              abort();
           }
           iv_initialized = false;
        }
    } // lv_err = 0
    else
       iv_initialized = false;

    if (gv_tm_info.TLOGperTM())
    {
       TMTrace(2, ("TM_Audit::adp_module_init: EXIT, initialized = %d, name %s, TLOG%d.\n",
               iv_initialized, ia_vol_name2, lv_TLOG_index));
    }
    else
    {
       TMTrace(2, ("TM_Audit::adp_module_init: EXIT, initialized = %d, name %s, single TLOG.\n",
               iv_initialized, ia_vol_name2));
    }
}
Esempio n. 12
0
int main(int argc, char *argv[]) {
    bool      client = false;
    int       event_len;
    int       ferr;
    int       inx;
    int       len;
    int       lerr;
    int       linx;
    int       loop = 10;
    int       msgid;
    int       oid;
    TPT_DECL (phandle);
    RT        results;
    int       send_len;
    int       srv_nid = -1;
    int       srv_pid = -1;
    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);
    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
        ferr = msg_mon_get_process_info((char *) "$srv", &srv_nid, &srv_pid);
        TEST_CHK_FEOK(ferr);
    }

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

    for (inx = 0; inx < MS_MON_MAX_SYNC_DATA; inx++)
        event_data[inx] = (char) (inx + 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
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            lerr = XWAIT(LDONE, 10);
            TEST_CHK_WAITIGNORE(lerr);
            assert(!XMSG_ISDONE_(msgid));
            ferr =
              msg_mon_event_send(srv_nid,                    // nid
                                 srv_pid,                    // pid
                                 MS_ProcessType_Undefined,   // process-type
                                 inx,                        // event-id
                                 inx % MS_MON_MAX_SYNC_DATA, // event-len
                                 event_data);                // event-data
            TEST_CHK_FEOK(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);
                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 {
                memset(event_data, 0, sizeof(event_data));
                ferr = msg_mon_event_wait(inx, &event_len, event_data);
                TEST_CHK_FEOK(ferr);
                assert(event_len == (inx % MS_MON_MAX_SYNC_DATA));
                for (linx = 0; linx < event_len; linx++)
                    assert(event_data[linx] == (linx + 1));
                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;
}
Esempio n. 13
0
int main(int argc, char *argv[]) {
    bool       check = false;
    int        csize = -1;
    bool       client = false;
    int        dsize = MAX_BUF;
    int        ferr;
    int        inx;
    int        len;
    int        lerr;
    int        loop = 10;
    int        min_csize;
    int        min_dsize;
    int        max_csize = -1;
    int        max_dsize = -1;
    int        msgid;
    int        oid;
    TPT_DECL  (phandle);
    uint       result;
    RT         results;
    BMS_SRE    sre;
    bool       verbose = false;
    TAD        zargs[] = {
      { "-check",     TA_Bool, TA_NOMAX,    &check     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-csize",     TA_Int,  MAX_BUF,     &csize     },
      { "-dsize",     TA_Int,  MAX_BUF,     &dsize     },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxcsize",  TA_Int,  MAX_BUF,     &max_csize },
      { "-maxdsize",  TA_Int,  MAX_BUF,     &max_dsize },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           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));
    msg_mon_enable_mon_messages(true);

    if (check) {
        if (csize < 0)
            csize = 0;
        if (dsize == MAX_BUF)
            dsize = 0;
        min_csize = csize;
        min_dsize = dsize;
        min_csize = min_csize; // touch
        min_dsize = min_dsize; // touch
        if (client) {
            for (inx = 0; inx < MAX_BUF; inx++) {
                send_buffer[inx] = (char) inx; // cast
                send_buffer2[inx] = (short) inx; // cast
            }
        }
    } else
        min_csize = 0;
    for (inx = 0; inx < loop; inx++) {
        if (verbose)
            printf("client=%d, csize=%d, dsize=%d\n", client, csize, dsize);
        else if (check && (csize == min_csize))
            printf("client=%d, csize=%d, dsize=%d\n", client, csize, dsize);
        if (client) {
            if (check) {
                send_buffer[0] = (char) dsize; // cast
                send_buffer2[0] = (short) csize; // cast
                len = 0;
            } else {
                sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                        my_name, inx);
                len = (int) strlen(send_buffer) + 1; // cast
            }
            ferr = BMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              send_buffer2,                // reqctrl
                              csize < 0 ?                  // reqctrlsize
                                (inx & 1) : csize,
                              recv_buffer3,                // replyctrl
                              csize < 0 ? 1 : csize,       // replyctrlmax
                              send_buffer,                 // reqdata
                              check ? dsize : len,         // reqdatasize
                              recv_buffer,                 // replydata
                              MAX_BUF,                     // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("BMSG_LINK_", ferr);
            ferr = BMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            util_check("BMSG_BREAK_", ferr);
            if (check)
                assert(results.u.t.ctrl_size == (uint) csize);
            else
                assert(results.u.t.ctrl_size == (uint) (csize < 0 ? (inx & 1) : csize));
            if (check)
                assert(results.u.t.data_size == (uint) dsize);
            else
                assert(results.u.t.data_size > (strlen(send_buffer) + 14));
            if (check) {
                if (dsize)
                    result = RT_DATA_RCVD; // data
                else
                    result = 0x0; // no-data
                assert(results.u.t.errm == result);
                check_buf(send_buffer2, recv_buffer3, csize);
                check_buf(send_buffer, recv_buffer, dsize);
            } else {
                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 = BMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            ferr = BMSG_READCTRL_(sre.sre_msgId,          // msgid
                                  recv_buffer2,           // reqctrl
                                  sre.sre_reqCtrlSize);   // bytecount
            util_check("BMSG_READCTRL_", ferr);
            ferr = BMSG_READDATA_(sre.sre_msgId,        // msgid
                                  recv_buffer,          // reqdata
                                  sre.sre_reqDataSize); // bytecount
            util_check("BMSG_READDATA_", ferr);
            if (sre.sre_flags & XSRE_MON) {
                printf("server received mon message\n");
                inx--;
                len = 0;
            } else {
                if (!check) {
                    strcat(recv_buffer, "- reply from ");
                    strcat(recv_buffer, my_name);
                    len = (int) strlen(recv_buffer) + 1; // cast
                } else
                    len = 0;
            }
            BMSG_REPLY_(sre.sre_msgId,                     // msgid
                        recv_buffer2,                      // replyctrl
                        sre.sre_reqCtrlSize,               // replyctrlsize
                        recv_buffer,                       // replydata
                        check ? sre.sre_reqDataSize : len, // replydatasize
                        0,                                 // errorclass
                        NULL);                             // newphandle
            if (sre.sre_flags & XSRE_MON)
                continue;
        }
        if (check) {
            if (max_csize >= 0) {
                csize++;
                if (csize >= max_csize)
                    csize = min_csize;
            }
            if ((max_dsize >= 0) && (csize == min_csize))
                dsize++;
            if (dsize >= max_dsize) {
                printf("break client=%d, csize=%d, dsize=%d\n", client, csize, dsize);
                break;
            }
            if ((max_csize >= 0) || (max_dsize >= 0)) {
                inx--;
                continue;
            }
        }
    }

    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;
}
Esempio n. 14
0
int main(int argc, char *argv[]) {
    bool            client = false;
    int             exprinx;
    int             ferr;
    int             inx;
    int             len;
    int             lerr;
    int             loop = 100;
    int             msgid[MAX_MSGS];
    int             oid;
    char           *p;
    TPT_DECL       (phandle);
    int             pri;
    RT              results;
    int             rinx;
    BMS_SRE         sre;
    BMS_SRE_LDONE   sre_ldone;
    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_enable_priority_queue();
    util_gethostname(my_name, sizeof(my_name));

    if (client) {
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer[inx], "hello, greetings from %s, inx=%d",
                    my_name, inx);
            pri = 2 * inx + 5;
            ferr = BMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid[inx],                 // msgid
                              NULL,                        // reqctrl
                              0,                           // reqctrlsize
                              NULL,                        // replyctrl
                              0,                           // replyctrlmax
                              send_buffer[inx],            // reqdata
                              100,                         // reqdatasize
                              recv_buffer[inx],            // replydata
                              100,                         // replydatamax
                              inx,                         // linkertag
                              (short) pri,                 // pri
                              0,                           // xmitclass
                              BMSG_LINK_LDONEQ);           // linkopts
            util_check("BMSG_LINK_", ferr);
        }
        exprinx = loop - 1;
        for (inx = 0; inx < loop;) {
            lerr = XWAIT(LDONE, -1);
            TEST_CHK_WAITIGNORE(lerr);
            do {
                lerr = BMSG_LISTEN_((short *) &sre_ldone, // sre
                                    0,                    // listenopts
                                    0);                   // listenertag
                if (lerr == BSRETYPE_LDONE) {
                    ferr = BMSG_BREAK_(sre_ldone.sre_msgId, results.u.s, TPT_REF(phandle));
                    util_check("BMSG_BREAK_", ferr);
                    assert(results.u.t.ctrl_size == 0);
                    assert(results.u.t.errm == RT_DATA_RCVD); // data
                    printf("%s\n", recv_buffer[sre_ldone.sre_linkTag]);
                    p = strchr(recv_buffer[sre_ldone.sre_linkTag], '=');
                    assert(p != NULL);
                    rinx = atoi(&p[1]);
                    if (rinx != exprinx) {
                        printf("rinx=%d, exprinx=%d\n", rinx, exprinx);
                        assert(rinx == exprinx);
                    }
                    inx++;
                    exprinx--;
                }
            } while (lerr == BSRETYPE_LDONE);
        }
    } else {
        for (inx = 0; inx < loop; inx++) {
            do {
                lerr = XWAIT(LREQ, -1);
                if (inx == 0)
                    sleep(5);
                lerr = BMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == BSRETYPE_NOWORK);
            ferr = BMSG_READCTRL_(sre.sre_msgId,    // msgid
                                  NULL,             // reqctrl
                                  0);               // bytecount
            util_check("BMSG_READCTRL_", ferr);
            ferr = BMSG_READDATA_(sre.sre_msgId,    // msgid
                                  recv_buffer[inx], // reqdata
                                  100);             // bytecount
            util_check("BMSG_READDATA_", ferr);
            strcat(recv_buffer[inx], "- reply from ");
            strcat(recv_buffer[inx], my_name);
            len = (int) strlen(recv_buffer[inx]) + 1;
            len = len; // touch - not currently used
            BMSG_REPLY_(sre.sre_msgId,      // msgid
                        NULL,               // replyctrl
                        0,                  // replyctrlsize
                        recv_buffer[inx],   // replydata
                        100,                // 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);
    util_test_finish(client);
    return 0;
}
Esempio n. 15
0
int main(int argc, char *argv[]) {
    bool                client = false;
    int                 ferr;
    int                 inxl;
    int                 inxo;
    int                 inxs;
    int                 maxs = 2;
    int                 msgid[MAX_OUT];
    bool                mq = false;
    int                 oid;
    TPT_DECL           (phandle);
    void               *res;
    RT                  results;
    const char         *serv = "$srv";
    int                 status;
    TAD                 zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxout",    TA_Int,  MAX_OUT,     &maxout    },
      { "-maxs",      TA_Int,  MAX_THR_S,   &maxs      },
      { "-mq",        TA_Bool, TA_NOMAX,    &mq        },
      { "-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);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_get_my_process_name(my_name, BUFSIZ);
    util_check("msg_mon_get_my_process_name", ferr);

    if (client) {
        ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETSENDLIMIT,
                                     XMAX_SETTABLE_SENDLIMIT);
        assert(ferr == XZFIL_ERR_OK);
        atomic_set(&msg_count, 0);
        for (inxl = 0; inxl < loop; inxl++) {
            ferr = msg_mon_open_process((char *) serv,       // name
                                        TPT_REF(phandle),
                                        &oid);
            TEST_CHK_FEOK(ferr);
            count = 0;
            for (inxo = 0; inxo < 2; inxo++) {
                ferr = BMSG_LINK_(TPT_REF(phandle),        // phandle
                                  &msgid[inxo],            // msgid
                                  NULL,                    // reqctrl
                                  0,                       // reqctrlsize
                                  send_buffer2[inxo],      // replyctrl
                                  24,                      // replyctrlmax
                                  send_buffer[inxo],       // reqdata
                                  0,                       // reqdatasize
                                  recv_buffer[inxo],       // replydata
                                  BUFSIZ,                  // replydatamax
                                  0,                       // linkertag
                                  0,                       // pri
                                  0,                       // xmitclass
                                  0);                      // linkopts
                util_check("XMSG_LINK_", ferr);
                atomic_inc(&msg_count);
            }
            ferr = XMSG_ABANDON_(msgid[0]);
            util_check("XMSG_ABANDON_", ferr);
            ferr = BMSG_LINK_(TPT_REF(phandle),        // phandle
                              &msgid[inxo],            // msgid
                              NULL,                    // reqctrl
                              0,                       // reqctrlsize
                              send_buffer2[inxo],      // replyctrl
                              24,                      // replyctrlmax
                              send_buffer[inxo],       // reqdata
                              0,                       // reqdatasize
                              recv_buffer[inxo],       // replydata
                              BUFSIZ,                  // replydatamax
                              0,                       // linkertag
                              0,                       // pri
                              0,                       // xmitclass
                              0);                      // linkopts
            util_check("XMSG_LINK_", ferr);
            atomic_inc(&msg_count);
            ferr = BMSG_BREAK_(msgid[inxo],
                               results.u.s,
                               TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
            ferr = XMSG_ABANDON_(msgid[1]);
            util_check("XMSG_ABANDON_", ferr);
            if (maxout < 4)
                maxout = 4;
            for (inxo = 3; inxo < maxout; inxo++) {
                ferr = BMSG_LINK_(TPT_REF(phandle),        // phandle
                                  &msgid[inxo],            // msgid
                                  NULL,                    // reqctrl
                                  0,                       // reqctrlsize
                                  send_buffer2[inxo],      // replyctrl
                                  60,                      // replyctrlmax
                                  send_buffer[inxo],       // reqdata
                                  120,                     // reqdatasize
                                  recv_buffer[inxo],       // replydata
                                  BUFSIZ,                  // replydatamax
                                  0,                       // linkertag
                                  0,                       // pri
                                  0,                       // xmitclass
                                  0);                      // linkopts
                util_check("XMSG_LINK_", ferr);
                atomic_inc(&msg_count);
                if (verbose)
                    printf("client(%s): msg-count=%d\n",
                           my_name, atomic_read(&msg_count));
                count++;
                ferr = BMSG_BREAK_(msgid[inxo],
                                   results.u.s,
                                   TPT_REF(phandle));
                util_check("XMSG_BREAK_", ferr);
            }
            if (mq) {
                if ((inxl % 100) == 0)
                    printf("client(%s): count=%d\n", my_name, inxl);
            }
        }
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETRECVLIMIT,
                                     XMAX_SETTABLE_RECVLIMIT);
        assert(ferr == XZFIL_ERR_OK);
        closes = 0;
        maxmsg = loop * maxout;
        atomic_set(&msg_count, 0);
        msg_mon_enable_mon_messages(true);
        for (inxs = 0; inxs < maxs; inxs++) {
            char lname[10];
            sprintf(lname, "s%d", inxs);
            thrs[inxs] = new MyThread(server_thr, lname, inxs);
        }
        for (inxs = 0; inxs < maxs; inxs++)
            thrs[inxs]->start();
        for (inxs = 0; inxs < maxs; inxs++) {
            status = thrs[inxs]->join(&res);
            TEST_CHK_STATUSOK(status);
            printf("joined with server %d\n", inxs);
        }
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Esempio n. 16
0
int main(int argc, char *argv[]) {
    bool       client = false;
    int        disable;
    int        ferr;
    int        inx;
    int        lerr;
    int        loop = 10;
    int        msgid;
    int        oid;
    TPT_DECL  (phandle);
    RT         results;
    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);
    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) {
        for (inx = 0; inx < loop; inx++) {
            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
                              0,                           // reqdatasize
                              recv_buffer,                 // replydata
                              0,                           // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            assert(ferr);
            msg_test_assert_enable(disable);
        }
    } else {
        msg_mon_enable_mon_messages(true);
        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
                    recv_buffer,    // replydata
                    0,              // replydatasize
                    0,              // errorclass
                    NULL);          // newphandle
        util_abort_core_free();
    }
    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;
}
Esempio n. 17
0
int main(int argc, char *argv[]) {
    int                 exit;
    int                 ferr;
    bool                ldone;
    int                 lerr;
    int                 msgid;
    int                 nid;
    int                 oid;
    int                 pid;
    TPT_DECL           (phandle);
    char                recv_buffer[BUFSIZ];
    short               recv_buffer2[BUFSIZ];
    RT                  results;
    MS_SRE              sre;
    MS_Mon_Transid_Type transid;

    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);
    ferr = msg_mon_get_process_info((char *) "$srv", &nid, &pid);
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_open_process((char *) "$srv",      // name
                                TPT_REF(phandle),
                                &oid);
    TEST_CHK_FEOK(ferr);
    TRANSID_SET_NULL(transid);
    ferr = msg_mon_deregister_death_notification(nid, pid, transid);
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_register_death_notification(nid, pid);
    TEST_CHK_FEOK(ferr);
    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
                      XMSG_LINK_LDONEQ);           // linkopts
    util_check("XMSG_LINK_", ferr);
    exit = 0;
    ldone = false;
    while (!exit) {
        do {
            lerr = XWAIT(LREQ|LDONE, -1);
            TEST_CHK_WAITIGNORE(lerr);
            if (lerr == LDONE) {
                ldone = true;
                break;
            }
            lerr = XMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
        } while (lerr == XSRETYPE_NOWORK);
        if (ldone) {
            printf("LINK done\n");
            lerr = XMSG_LISTEN_((short *) &sre,       // sre
                                XLISTEN_ALLOW_LDONEM, // listenopts
                                0);                   // listenertag
            assert(lerr == XSRETYPE_LDONE);
            ferr = XMSG_BREAK_(sre.sre_msgId,
                               results.u.s,
                               TPT_REF(phandle));
            assert(ferr == XZFIL_ERR_OK);
            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_ProcessDeath) {
                assert(msg->u.death.nid == nid);
                assert(msg->u.death.pid == pid);
                exit = 1;
            } else if (msg->type == MS_MsgType_Shutdown) {
                printf("cli: received cluster shutdown, level=%d\n", msg->u.shutdown.level);
                assert(msg->u.shutdown.level==MS_Mon_ShutdownLevel_Immediate);
            }
        } 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;
}