示例#1
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;
}
示例#2
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;
}
示例#3
0
int main(int argc, char *argv[]) {
    enum                    { MAX_RETRIES = 100 };
    enum                    { SLEEP_US    = 1000 };
    bool                      attach = false;
    _xcc_status               cc;
    bool                      client = false;
    int                       count;
    int                       count_read;
    int                       count_written;
    bool                      dif = false;
    double                    dloop;
    double                    dms;
    double                    dsec;
    int                       err;
    bool                      exec = false;
    int                       ferr;
    bool                      fin = false;
    MS_Mon_Process_Info_Type  info;
    MS_Mon_Process_Info_Type *infop;
    int                       inx;
    int                       inx2;
    int                       inx3;
    short                     len;
    short                     lerr;
    short                     lerr2;
    int                       loop = 10;
    int                       max;
    int                       nid;
    pid_t                     pid;
    int                       sargc;
    ssize_t                   size;
    int                       snid;
    int                       spid;
    bool                      startup = false;
    xzsys_ddl_smsg_def       *sys_msgp = (xzsys_ddl_smsg_def *) recv_buffer;
    int                       sys_msg;
    int                       sys_msg_count;
    bool                      verbose = false;
    TAD                       zargs[] = {
      { "-attach",    TA_Bool, TA_NOMAX,    &attach    },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-dif",       TA_Bool, TA_NOMAX,    &dif       },
      { "-exec",      TA_Bool, TA_NOMAX,    &exec      },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxsp",     TA_Int,  TA_NOMAX,    &maxsp     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-startup",   TA_Bool, TA_NOMAX,    &startup   },
      { "-trace",     TA_Bool, TA_NOMAX,    &trace     },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "-verbose",   TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    arg_proc_args(zargs, false, argc, argv);
    sprintf(fifo1, "%s-%s", FIFO1, getenv("USER"));
    sprintf(fifo2, "%s-%s", FIFO2, getenv("USER"));
    if (trace)
        msg_init_trace();
    if (exec)
        return 0;
    if (startup) {
        err = fifo_open(fifo1, O_WRONLY);
        assert(err != -1);
        ffds[1] = err;
        err = fifo_open(fifo2, O_RDONLY);
        assert(err != -1);
        ffds[0] = err;
        if (trace)
            trace_printf("cli: writing fifo\n");
        size = write(ffds[1], recv_buffer, 1);
        if (trace)
            trace_printf("cli: fifo write, size=%d\n", (int) size);
        assert(size == 1);
        if (trace)
            trace_printf("cli: fifo written\n");
        close(ffds[1]);
        return 0;
    }
    if (attach)
        ferr = file_init_attach(&argc, &argv, false, NULL);
    else
        ferr = file_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    util_test_start(client);
    ferr = msg_mon_process_startup(true); // system messages
    util_check("msg_mon_process_startup", ferr);
    ferr = msg_mon_get_my_process_name(procname, BUFSIZ);
    util_check("msg_mon_get_my_process_name", ferr);
    ferr = msg_mon_get_process_info(procname, &nid, &pid);
    TEST_CHK_FEOK(ferr);

    if (trace)
        trace_printf("proc=%s, nid=%d, pid=%d\n", procname, nid, pid);
    dloop = (double) loop;
    for (inx = 0; inx < T_MAX; inx++)
        t_elapsed[inx] = 0.0;
    if (client) {
        printf("loop=%d, maxsp=%d\n", loop, maxsp);
        sargc = argc;
        assert(sargc < MAX_ARGS);
        for (inx2 = 0; inx2 < argc; inx2++) {
            if (strcmp(argv[inx2], "-client") == 0)
                sargv[inx2] = (char *) "-server";
            else
                sargv[inx2] = argv[inx2];
            if (strcmp(argv[inx2], "-attach") == 0)
                sargv[inx2] = (char *) "-server";
        }
        sargv[argc] = NULL;
        sprintf(sprog, "%s/%s", getenv("PWD"), argv[0]);
        time_start(T_TOTAL);
        for (inx = 0; inx < loop; inx += maxsp) {
            if (dif)
                snid = -1;
            else
                snid = nid;
            max = loop - inx;
            if (max > maxsp)
                max = maxsp;
            for (inx2 = 0; inx2 < max; inx2++)
                sname[inx2][0] = 0; // mon picks name
            if (trace)
                trace_printf("cli: newproc, inx=%d\n", inx);
            time_start(T_NEWPROC);
            for (inx2 = 0; inx2 < max; inx2++) {
                ferr = msg_mon_start_process(sprog,                  // prog
                                             sname[inx2],            // name
                                             sname[inx2],            // ret_name
                                             sargc,                  // argc
                                             sargv,                  // argv
                                             TPT_REF2(sphandle,inx2),// phandle
                                             false,                  // open
                                             &soid[inx2],            // oid
                                             MS_ProcessType_Generic, // type
                                             0,                      // priority
                                             false,                  // debug
                                             false,                  // backup
                                             &snid,                  // nid
                                             &spid,                  // pid
                                             NULL,                   // infile
                                             NULL);                  // outfile
                TEST_CHK_FEOK(ferr);
            }
            time_stop(T_NEWPROC);
            time_elapsed(T_NEWPROC);

            // wait here until processes are 'up'
            // so that open timing is correct
            inx3 = 0;
            for (inx2 = 0; inx2 < max; inx2++) {
                ferr = msg_mon_get_process_info_detail(sname[inx2], &info);
                TEST_CHK_FEOK(ferr);
                if (info.state != MS_Mon_State_Up) {
                    inx3++;
                    if (inx3 > MAX_RETRIES) {
                        printf("process %s did not enter 'UP' state\n", sname[inx2]);
                        assert(inx3 < MAX_RETRIES);
                    }
                    usleep(SLEEP_US);
                    inx2--;
                    continue;
                } else
                    inx3 = 0;
            }

            if (trace)
                trace_printf("cli: open, inx=%d\n", inx);
            time_start(T_OPEN);
            for (inx2 = 0; inx2 < max; inx2++) {
                if (trace)
                    trace_printf("cli: opening inx=%d, name=%s\n", inx, sname[inx2]);
                len = (short) strlen(sname[inx2]);
                ferr = BFILE_OPEN_(sname[inx2], len, &sfilenum[inx2],
                                   0, 0, 0,
                                   0, 0, 0, 0);
                if (trace)
                    trace_printf("cli: open, inx=%d, name=%s, ferr=%d\n",
                           inx, sname[inx2], ferr);
                TEST_CHK_FEOK(ferr);
            }
            time_stop(T_OPEN);
            time_elapsed(T_OPEN);

            if (trace)
                trace_printf("cli: procinfo, inx=%d\n", inx);
            time_start(T_PROCINFO);
            for (inx2 = 0; inx2 < max; inx2++) {
                ferr = msg_mon_get_process_info_detail(sname[inx2], &info);
                TEST_CHK_FEOK(ferr);
            }
            time_stop(T_PROCINFO);
            time_elapsed(T_PROCINFO);

            if (trace)
                trace_printf("cli: procinfo-type, inx=%d\n", inx);
            time_start(T_PROCINFO_TYPE);
            ferr = msg_mon_get_process_info_type(MS_ProcessType_Generic,
                                                 &count,
                                                 MAX_SRV,
                                                 infotype);
            TEST_CHK_FEOK(ferr);
            time_stop(T_PROCINFO_TYPE);
            time_elapsed(T_PROCINFO_TYPE);
            if (verbose) {
                for (inx2 = 0; inx2 < count; inx2++) {
                    infop = &infotype[inx2];
                    char s_em = infop->event_messages ? 'E' : '-';
                    char s_sm = infop->system_messages ? 'S' : '-';
                    char s_pr = infop->pending_replication ? 'R' : '-';
                    char s_pd = infop->pending_delete ? 'D' : '-';
                    char s_s  = infop->state == MS_Mon_State_Up ? 'A' : 'U';
                    char s_o  = infop->opened ? 'O' : '-';
                    char s_p  = infop->paired ? 'P' : infop->backup ? 'B' : '-';
                    printf("%3.3d,%8.8d %3.3d %d %c%c%c%c%c%c%c %-11s %-11s %-15s\n",
                           infop->nid,
                           infop->pid,
                           infop->priority,
                           infop->state,
                           s_em, s_sm, s_pr, s_pd, s_s, s_o, s_p,
                           infop->process_name,
                           infop->parent_name,
                           infop->program);
                }
            }

            if (trace)
                trace_printf("cli: close, inx=%d\n", inx);
            time_start(T_CLOSE);
            for (inx2 = 0; inx2 < max; inx2++) {
                ferr = BFILE_CLOSE_(sfilenum[inx2]);
                TEST_CHK_FEOK(ferr);
            }
            time_stop(T_CLOSE);
            time_elapsed(T_CLOSE);

            // re-open/close
            for (inx2 = 0; inx2 < max; inx2++) {
                if (trace)
                    trace_printf("cli: re-opening inx=%d, name=%s\n",
                           inx, sname[inx2]);
                len = (short) strlen(sname[inx2]);
                ferr = BFILE_OPEN_(sname[inx2], len, &sfilenum[inx2],
                                   0, 0, 0,
                                   0, 0, 0, 0);
                TEST_CHK_FEOK(ferr);
            }
            if (trace)
                trace_printf("cli: re-close, inx=%d\n", inx);
            for (inx2 = 0; inx2 < max; inx2++) {
                ferr = BFILE_CLOSE_(sfilenum[inx2]);
                TEST_CHK_FEOK(ferr);
            }

            if (trace)
                trace_printf("cli: newproc-forkexec, inx=%d\n", inx);
            sargc = 2;
            sargv[0] = argv[0];
            sargv[1] = (char *) "-exec";
            if (trace)
                sargv[sargc++] = (char *) "-trace";
            sargv[sargc] = NULL;
            time_start(T_FORKEXEC);
            for (inx2 = 0; inx2 < max; inx2++) {
                pid = fork();
                assert(pid >= 0);
                if (pid == 0) {
                    // child
                    err = execv(sprog, sargv);
                    assert(err == 0);
                }
            }
            time_stop(T_FORKEXEC);
            time_elapsed(T_FORKEXEC);

            if (trace)
                trace_printf("cli: newproc-forkexec-su, inx=%d\n", inx);
            sargc = 2;
            sargv[0] = argv[0];
            sargv[1] = (char *) "-startup";
            if (trace)
                sargv[sargc++] = (char *) "-trace";
            sargv[sargc] = NULL;
            time_start(T_FORKEXEC_SU);
            for (inx2 = 0; inx2 < max; inx2++) {
                fifo_create(fifo1, fifo2);
                pid = fork();
                assert(pid >= 0);
                if (pid > 0) {
                    // parent
                    err = fifo_open(fifo1, O_RDONLY);
                    assert(err != -1);
                    ffds[0] = err;
                    err = fifo_open(fifo2, O_WRONLY);
                    assert(err != -1);
                    ffds[1] = err;
                    if (trace)
                        trace_printf("cli: reading fifo, inx=%d\n", inx2);
                    size = ::read(ffds[0], recv_buffer, 1);
                    if (trace)
                        trace_printf("cli: fifo read, size=%d\n", (int) size);
                    assert(size == 1);
                    if (trace)
                        trace_printf("cli: fifo read, inx=%d\n", inx2);
                    ::read(ffds[0], recv_buffer, 1);
                    err = fifo_close(ffds[0]);
                    assert(err == 0);
                    err = fifo_close(ffds[1]);
                    assert(err == 0);
                    fifo_destroy(fifo1, fifo1);
                } else {
                    // child
                    err = execv(sprog, sargv);
                    assert(err == 0);
                }
            }
            fifo_destroy(fifo2, fifo2);
            time_stop(T_FORKEXEC_SU);
            time_elapsed(T_FORKEXEC_SU);
        }
    } else {
        sys_msg_count = 0;
        time_start(T_TOTAL);
        ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr,
                           0, 0, 0,
                           1, 0); // sys msgs
        TEST_CHK_FEOK(ferr);
        for (inx = 0; !fin; inx++) {
            if (trace)
                trace_printf("srv: readupdate, inx=%d\n", inx);
            cc = BREADUPDATEX(filenumr,
                              recv_buffer,
                              4,
                              &count_read,
                              0);
            sys_msg = _xstatus_ne(cc);
            if (trace && sys_msg)
                trace_printf("srv: rcvd sys msg=%d\n",
                             sys_msgp->u_z_msg.z_msgnumber[0]);
            if (sys_msg) {
                sys_msg_count++;
                inx--;
            }
            lerr2 = BFILE_GETINFO_(filenumr, &lerr);
            TEST_CHK_FEIGNORE(lerr2);
            if (trace)
                trace_printf("srv: reply, inx=%d\n", inx);
            cc = BREPLYX(recv_buffer,
                         (unsigned short) 0,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
            if (sys_msg_count >= 4)
                fin = true;
        }
    }
    time_stop(T_TOTAL);
    time_elapsed(T_TOTAL);

    if (client) {
        dsec = time_sec(T_TOTAL);
        dms = dsec * 1000.0;
        printf("elapsed=%f\n", dms);
        printf("open/close/newprocess/processinfo/forkexec=%d\n", loop);
        dsec = time_sec(T_OPEN);
        dms = dsec * 1000.0;
        printf("open            : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_CLOSE);
        dms = dsec * 1000.0;
        printf("close           : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_PROCINFO);
        dms = dsec * 1000.0;
        printf("procinfo        : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_PROCINFO_TYPE);
        dms = dsec * 1000.0;
        printf("procinfo-type   : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_NEWPROC);
        dms = dsec * 1000.0;
        printf("newproc         : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_FORKEXEC);
        dms = dsec * 1000.0;
        printf("forkexec        : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_FORKEXEC_SU);
        dms = dsec * 1000.0;
        printf("forkexec-startup: total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
示例#4
0
int main(int argc, char *argv[]) {
    bool       client = false;
    int        client_mon;
    int        cnid = -1;
    bool       commit_rcvd = false;
    int        cpid = -1;
    int        disable;
    bool       done = false;
    int        event_len;
    int        ferr;
    int        first;
    int        handle;
    int        inx;
    int        len;
    int        lerr;
    int        loop = 10;
    int        msgid;
    int        nid;
    bool       open_rcvd = false;
    int        orig_tag;
    TPT_DECL2 (phandle,MAX_SERVERS);
    int        pid;
    int        pinx;
    RT         results;
    int        send_len;
    MS_SRE     sre;
    int        status;
    bool       sync = false;
    bool       threaded = false;
    bool       verbose = false;
    TAD        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-quiet",     TA_Bool, TA_NOMAX,    &quiet     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-sync",      TA_Bool, TA_NOMAX,    &sync      },
      { "-threaded",  TA_Bool, TA_NOMAX,    &threaded  },
      { "-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);
    sleep(1); // wait for client to get into msg_mon_process_info
    ferr = msg_mon_get_my_process_name(pname, sizeof(pname));
    TEST_CHK_FEOK(ferr);
    if (strcasecmp(pname, "$tm0") == 0)
         tag = TAG0;
    else if (strcasecmp(pname, "$tm1") == 0)
         tag = TAG1;
    else
         tag = TAG2;
    ferr = msg_mon_get_process_info(NULL, &snid, &spid);
    TEST_CHK_FEOK(ferr);
    if (client) {
        char serv[BUFSIZ];
        for (pinx = 0; pinx < MAX_SERVERS; pinx++) {
            sprintf(serv, "$tm%d", pinx);
            ferr = msg_mon_open_process(serv,         // name
                                        TPT_REF2(phandle,pinx),
                                        &oid[pinx]);
            TEST_CHK_FEOK(ferr);
        }
    } else {
        first = (strcasecmp(pname, "$tm0") == 0);
        disable = msg_test_assert_disable();
        ferr = msg_mon_tm_leader_set(&nid, &pid, lname);
        msg_test_assert_enable(disable);
        if (first) {
            TEST_CHK_FEOK(ferr);
        } else
            assert(ferr != XZFIL_ERR_OK);
        printf("leader is p-id=%d/%d, name=%s\n",
               nid, pid, lname);
    }

    util_gethostname(my_name, sizeof(my_name));
    msg_mon_enable_mon_messages(true);
    if (!client) {
        ferr = msg_mon_event_wait(1, &event_len, event_data);
        util_check("msg_mon_event_wait", ferr);
        ferr = msg_mon_tmsync_register(tmsync_cb);
        util_check("msg_mon_tmsync_register", ferr);
        if (sync) {
            char serv[BUFSIZ];
            for (pinx = 0; pinx < MAX_SERVERS; pinx++) {
                sprintf(serv, "$tm%d", pinx);
                if (strcasecmp(serv, pname) != 0) {
                    ferr = msg_mon_open_process(serv,         // name
                                                TPT_REF2(phandle,pinx),
                                                &oid[pinx]);
                    TEST_CHK_FEOK(ferr);
                }
            }
            // at this point, we know everyone is registered
            // if everyone isn't registered, there will be an abort
            do_sync();
            if (threaded)
                do_sync_threaded();
        }
    }

    if (client) {
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            send_len = (int) strlen(send_buffer) + 1;
            for (pinx = 0; pinx < MAX_SERVERS; pinx++) {
                if (verbose)
                    printf("%s: sending message, pinx=%d, inx=%d\n",
                           pname, pinx, inx);
                ferr = XMSG_LINK_(TPT_REF2(phandle,pinx),      // 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_REF2(phandle,pinx));
                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
                if (!quiet)
                    printf("%s\n", recv_buffer);
            }
        }
        for (pinx = 0; pinx < MAX_SERVERS; pinx++) {
            ferr = msg_mon_close_process(TPT_REF2(phandle,pinx));
            TEST_CHK_FEOK(ferr);
        }
    } else {
        inx = 0;
        while (!done) {
            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_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) {
                    MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
                    if (cnid < 0) {
                        ferr = msg_mon_get_process_info((char *) "$cli", &cnid, &cpid);
                        if (ferr != XZFIL_ERR_OK) {
                            cnid = -1;
                            cpid = -1;
                        }
                    }
                    client_mon = true;
                    Item *item_hdl;
                    Item *item_tag;
                    const char *type;
                    switch (msg->type) {
                    case MS_MsgType_Close:
                        type = "close";
                        if ((cnid == msg->u.close.nid) &&
                            (cpid == msg->u.close.pid)) {
                        } else
                            client_mon = false;
                        break;
                    case MS_MsgType_NodeDown:
                        type = "node-down";
                        break;
                    case MS_MsgType_Open:
                        type = "open";
                        if ((cnid == msg->u.open.nid) &&
                            (cpid == msg->u.open.pid))
                            open_rcvd = true;
                        else
                            client_mon = false;
                        break;
                    case MS_MsgType_ProcessDeath:
                        type = "process-death";
                        break;
                    case MS_MsgType_Shutdown:
                        type = "shutdown";
                        done = true;
                        break;
                    case MS_MsgType_TmSyncAbort:
                    case MS_MsgType_TmSyncCommit:
                        if (msg->type == MS_MsgType_TmSyncAbort)
                            type = "tmsync-abort";
                        else
                            type = "tmsync-commit";
                        nid = msg->u.tmsync.nid[0];
                        handle = msg->u.tmsync.handle[0];
                        if (msg->u.tmsync.orig_count == 0) {
                            msg->u.tmsync.orig_tag[0] = -1;
                            msg->u.tmsync.orig_handle[0] = -1;
                        }
                        orig_tag = msg->u.tmsync.orig_tag[0];
                        if (!quiet) {
                            printf("server (%s) received (%s) mon message, type=%s(%d), nid=%d\n",
                               pname,
                               client_mon ? "cli" : "dtm",
                               type,
                               msg->type,
                               nid);
                            printf("  orig_count=%d, orig_tag=%d, orig_handle=%d, count=%d, handle[0]=%d\n",
                               msg->u.tmsync.orig_count,
                               orig_tag,
                               msg->u.tmsync.orig_handle[0],
                               msg->u.tmsync.count,
                               handle);
                        }
                        if (nid == snid) {
                            if (!quiet)
                                printf("server (%s) commit handle=%d, orig-count=%d\n",
                                       pname, handle, msg->u.tmsync.orig_count);
                            for (int inx2 = 0;
                                 inx2 < msg->u.tmsync.count;
                                 inx2++) {
                                int ltag = msg->u.tmsync.orig_tag[inx2];
                                int lhandle = msg->u.tmsync.orig_handle[inx2];
                                if (!quiet)
                                    printf("server (%s) commit orig-tag/handle=%d/%d\n",
                                           pname, ltag, lhandle);
                                item_tag = (Item *) tag_issue_map.remove(ltag);
                                assert(item_tag != NULL);
                                delete item_tag;
                                item_hdl = (Item *) handle_issue_map.remove(lhandle);
                                assert(item_hdl != NULL);
                                delete item_hdl;
                            }
                        } else {
                            assert(msg->u.tmsync.orig_count == 0);
                        }
                        commit_rcvd = true;
                        break;
                    default:
                        type = "<unknown>";
                    }
                    if (!quiet)
                        printf("server (%s) received (%s) mon message, type=%s(%d)\n",
                               pname, client_mon ? "cli" : "dtm", type, msg->type);
                    len = 0;
                } else {
                    inx++;
                    if (verbose)
                        printf("%s: received non-mon message, inx=%d\n",
                               pname, inx);
                    if (!sync)
                        assert(sync_rcvd);
                    assert(commit_rcvd);
                    assert(open_rcvd);
                    strcat(recv_buffer, "- reply from ");
                    strcat(recv_buffer, my_name);
                    strcat(recv_buffer, " - ");
                    strcat(recv_buffer, pname);
                    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
            }
        }
        assert(inx == loop);
        assert(tag_issue_map.empty());
        assert(handle_issue_map.empty());
        // need to wait for shutdown to be started
        ferr = msg_mon_event_wait(2, &event_len, event_data);
        util_check("msg_mon_event_wait", ferr);
        if (sync && threaded) {
            sync_thr_shutdown = true;
            for (int thr = 0; thr < MAX_THR; thr++) {
                void *larg;
                status = sync_thr[thr]->join(&larg);
                TEST_CHK_STATUSOK(status);
            }
        }
    }

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
示例#5
0
int main(int argc, char *argv[]) {
    bool            client = false;
    int             ferr;
    int             inx;
    int             len;
    int             lerr;
    int             loop = 10;
    int             msgid;
    TPT_DECL2      (phandle,MAX_SERVERS);
    bool            rand = false;
    RT              results;
    int             send_len;
    MS_SRE          sre;
    MS_SRE_LDONE    sre_ldone;
    int             srv;
    int             srv2;
    TAD             zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-rand",      TA_Bool, TA_NOMAX,    &rand      },
      { "-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) {
        for (srv = 0; srv < MAX_SERVERS; srv++) {
            sprintf(name, "$srv%d", srv);
            ferr = msg_mon_open_process(name,
                                        TPT_REF2(phandle,srv),
                                        &oid[srv]);
            TEST_CHK_FEOK(ferr);
        }
    }
    util_gethostname(my_name, sizeof(my_name));

    if (client) {
        for (inx = 0; inx < loop; inx++) {
            for (srv = 0; srv < MAX_SERVERS; srv++) {
                sprintf(send_buffer[srv], "hello, greetings from %s, inx=%d, srv=%d",
                        my_name, inx, srv);
                send_len = (int) strlen(send_buffer[srv]) + 1;
                ferr = XMSG_LINK_(TPT_REF2(phandle,srv),          // phandle
                                  &msgid,                         // msgid
                                  send_buffer2,                   // reqctrl
                                  (ushort) (inx & 1),             // reqctrlsize
                                  recv_buffer3[srv],              // replyctrl
                                  1,                              // replyctrlmax
                                  send_buffer[srv],               // reqdata
                                  (ushort) send_len,              // reqdatasize
                                  recv_buffer[srv],               // replydata
                                  BUFSIZ,                         // replydatamax
                                  (SB_Tag_Type) send_buffer[srv], // linkertag
                                  0,                              // pri
                                  0,                              // xmitclass
                                  XMSG_LINK_LDONEQ);              // linkopts
                util_check("XMSG_LINK_", ferr);
            }
            for (srv = 0; srv < MAX_SERVERS;) {
                if (rand)
                    util_time_sleep_ms(rnd());
                lerr = XWAIT(LDONE, -1);
                TEST_CHK_WAITIGNORE(lerr);
                for (;;) {
                    lerr = XMSG_LISTEN_((short *) &sre_ldone, // sre
                                        0,                    // listenopts
                                        0);                   // listenertag
                    if (lerr == XSRETYPE_NOWORK)
                        break;
                    srv++;
                    assert(lerr == XSRETYPE_LDONE);
                    for (srv2 = 0; srv2 < MAX_SERVERS; srv2++) {
                        if (sre_ldone.sre_linkTag ==
                            (SB_Tag_Type) send_buffer[srv2])
                            break;
                    }
                    assert(srv2 < MAX_SERVERS);
                    ferr = XMSG_BREAK_(sre_ldone.sre_msgId,
                                       results.u.s,
                                       TPT_REF2(phandle,srv2));
                    util_check("XMSG_BREAK_", ferr);
                    assert(results.u.t.ctrl_size == (uint) (inx & 1));
                    assert(results.u.t.data_size > (strlen(send_buffer[srv2]) + 14));
                    assert(results.u.t.errm == RT_DATA_RCVD); // data
                    printf("%s\n", recv_buffer[srv2]);
                }
            }
        }
    } else {
        for (inx = 0; inx < loop;) {
            lerr = XWAIT(LREQ, -1);
            lerr = XMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
            if (lerr == XSRETYPE_NOWORK)
                continue;
            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_buffer4,   // reqdata
                                  BUFSIZ);        // bytecount
            util_check("XMSG_READDATA_", ferr);
            strcat(recv_buffer4, "- reply from ");
            strcat(recv_buffer4, my_name);
            len = (int) strlen(recv_buffer4) + 1;
            if (rand)
                util_time_sleep_ms(rnd());
            XMSG_REPLY_(sre.sre_msgId,       // msgid
                        recv_buffer2,        // replyctrl
                        sre.sre_reqCtrlSize, // replyctrlsize
                        recv_buffer4,        // replydata
                        (ushort) len,        // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
        }
    }

    if (client) {
        for (srv = 0; srv < MAX_SERVERS; srv++) {
            ferr = msg_mon_close_process(TPT_REF2(phandle,srv));
            TEST_CHK_FEOK(ferr);
        }
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
示例#6
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;
}