int main(int argc, char *argv[]) {
    bool      client = false;
    int       ferr;
    int       inx;
    int       loop = 10;
    int       msgid;
    int       oid;
    RT        results;
    TPT_DECL (phandle);
    int       send_len;
    TAD       zargs[] = {
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    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;
        ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                          &msgid,                      // msgid
                          send_buffer2,                // reqctrl
                          (ushort) ((inx & 1) + 1),    // reqctrlsize
                          recv_buffer3,                // replyctrl
                          2,                           // replyctrlmax
                          send_buffer,                 // reqdata
                          (ushort) send_len,           // reqdatasize
                          recv_buffer,                 // replydata
                          BUFSIZ,                      // replydatamax
                          0,                           // linkertag
                          0,                           // pri
                          0,                           // xmitclass
                          0);                          // linkopts
         util_check("XMSG_LINK_", ferr);
        ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
        util_check("XMSG_BREAK_", ferr);
        assert(results.u.t.ctrl_size == (uint) ((inx & 1) + 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);
    }
    ferr = msg_mon_close_process(TPT_REF(phandle));
    printf("close ferr=%d\n", ferr);
    printf("client shutting down\n");
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Beispiel #2
0
int main(int argc, char *argv[]) {
    int        err;
    void      *result;
    pthread_t  thr_cli;
    pthread_t  thr_srv;
    TAD        zargs[] = {
      { "-bidir",     TA_Bool, TA_NOMAX,    &bidir     },
      { "-bm",        TA_Bool, TA_NOMAX,    &bm        },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-cluster",   TA_Ign,  TA_NOMAX,    NULL       },
      { "-csize",     TA_Int,  MAX_CBUF,    &csize     },
      { "-dsize",     TA_Int,  MAX_DBUF,    &dsize     },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-nocopy",    TA_Bool, TA_NOMAX,    &nocopy    },
      { "-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);
    util_test_start(client);
    init();
    err = pthread_create(&thr_srv, NULL, thread_srv_fun, NULL);
    assert(err == 0);
    err = pthread_create(&thr_cli, NULL, thread_cli_fun, NULL);
    assert(err == 0);
    err = pthread_join(thr_cli, &result);
    assert(err == 0);
    err = pthread_join(thr_srv, &result);
    assert(err == 0);

    util_test_finish(client);
    return 0;
}
int main(int argc, char *argv[]) {
    bool       client = false;
    int        disable;
    int        ferr;
    int        oid;
    TPT_DECL  (phandle);
    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(true);  // system messages?
    TEST_CHK_FEOK(ferr);
    if (client) {
        disable = msg_test_assert_disable();
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEIGNORE(ferr);
        msg_test_assert_enable(disable);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Beispiel #4
0
int main(int argc, char *argv[]) {
    bool attach = false;
    int  ferr;
    int  level = MS_Mon_ShutdownLevel_Normal;
    TAD  zargs[] = {
      { "-attach",    TA_Bool, TA_NOMAX,    &attach    },
      { "-level",     TA_Int,  TA_NOMAX,    &level     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    arg_proc_args(zargs, false, argc, argv);
    if (attach)
        msfs_util_init_attach(&argc,
                              &argv,
                              msg_debug_hook,
                              false,
                              (char *) "$cli"); // cast
    else
        msfs_util_init(&argc, &argv, msg_debug_hook);
    util_test_start(true);
    ferr = msg_mon_process_startup(false);             // system messages
    TEST_CHK_FEOK(ferr);
    printf("using shutdown level=%d\n", level);
    ferr = msg_mon_shutdown(level);
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(true);
    return 0;
}
int main(int argc, char *argv[]) {
    bool      client = false;
    int       ferr;
    char      my_name[BUFSIZ];
    int       oid;
    TPT_DECL (phandle);
    TAD       zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msg_mon_enable_mon_messages(true);
    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(true);           // system messages
    TEST_CHK_FEOK(ferr);
    // process-wait for client/server/shell
    ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, 3, NULL, false);
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
        do_readmsg(); // open message
    } else {
        do_readmsg(); // open message
        ferr = msg_mon_open_process((char *) "$cli",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    }
    util_gethostname(my_name, sizeof(my_name));

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
        printf("if there were no asserts, all is well\n");
    } else {
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
        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;
}
Beispiel #6
0
int main(int argc, char *argv[]) {
    int     ferr;
    int     inx;
    int     len;
    int     lerr;
    int     loop = 10;
    char    my_name[BUFSIZ];
    char    recv_buffer[BUFSIZ];
    short   recv_buffer2[BUFSIZ];
    MS_SRE  sre;
    TAD     zargs[] = {
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    for (inx = 0; inx < loop/2; inx++) {
        do {
            lerr = XWAIT(LREQ, -1);
            TEST_CHK_WAITIGNORE(lerr);
            lerr = XMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
        } while (lerr == XSRETYPE_NOWORK);
        ferr = XMSG_READCTRL_(sre.sre_msgId,  // msgid
                              recv_buffer2,   // reqctrl
                              1);             // bytecount
        util_check("XMSG_READCTRL_", ferr);
        ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                              recv_buffer,    // reqdata
                              BUFSIZ);        // bytecount
        util_check("XMSG_READDATA_", ferr);
        strcat(recv_buffer, "- reply from ");
        strcat(recv_buffer, my_name);
        len = (int) strlen(recv_buffer) + 1;
        XMSG_REPLY_(sre.sre_msgId,       // msgid
                    recv_buffer2,        // replyctrl
                    sre.sre_reqCtrlSize, // replyctrlsize
                    recv_buffer,         // replydata
                    (ushort) len,        // replydatasize
                    0,                   // errorclass
                    NULL);               // newphandle
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    return 0;
}
Beispiel #7
0
int main(int argc, char *argv[]) {
    bool  chook = false;
    int   ferr;
    int   loop = 10;
    TAD   zargs[] = {
      { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
      { "-client",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxth",     TA_Int,  MAX_THR,     &maxth     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-tol",       TA_Int,  TA_NOMAX,    &to_tol    },
      { "-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);
    if (chook)
        msg_debug_hook("c", "c");
    util_test_start(true);
    ferr = msg_mon_process_startup(true);  // system messages?
    TEST_CHK_FEOK(ferr);
    util_gethostname(my_name, sizeof(my_name));

#if 0 // reproduce bug 1570
    // - add sleep(1) in sb_timer_setitimer when pv_to != 0
#endif
    test_cancel();
    test_timers();
    test_timers_alloc();
    test_thread1();
    test_cancel_cb();
    test_timers_cb();
    test_thread3();
#if 0 // reproduce bug 728
// - must add sleep(1) after call-to-sb_timer_comp_q_remove() in MSG_LISTEN_
    test_thread2();
#endif

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(true);
    return 0;
}
int main(int argc, char *argv[]) {
    bool          chook = false;
    int           client = false;
    int           dinx;
    int           disable;
    int           ferr;
    int           inx;
    char          lname[10];
    bool          mq = false;
    int           oid;
    void         *res;
    bool          rnd = false;
    int           sleept;
    int           snid;
    int           spid;
    int           status;
    TAD           zargs[] =  {
        { "-chook",     TA_Bool, TA_NOMAX,    &chook      },
        { "-client",    TA_Bool, TA_NOMAX,    &client     },
        { "-dloop",     TA_Int,  MAX_OUT,     &gdloop     },
        { "-dsize",     TA_Int,  TA_NOMAX,    &gdsize     },
        { "-ksleep",    TA_Int,  TA_NOMAX,    &gksleep    },
        { "-loop",      TA_Int,  TA_NOMAX,    &gloop      },
        { "-maxc",      TA_Int,  MAX_THR,     &gmaxc      },
        { "-maxs",      TA_Int,  MAX_THR,     &gmaxs      },
        { "-mq",        TA_Bool, TA_NOMAX,    &mq         },
        { "-nodecycle", TA_Bool, TA_NOMAX,    &gnodecycle },
        { "-rnd",       TA_Bool, TA_NOMAX,    &rnd        },
        { "-server",    TA_Ign,  TA_NOMAX,    NULL        },
        { "-v",         TA_Bool, TA_NOMAX,    &gverbose   },
        { "-vpp",       TA_Bool, TA_NOMAX,    &gverbosepp },
        { "",           TA_End,  TA_NOMAX,    NULL        }
    };

    arg_proc_args(zargs, false, argc, argv);
    if (client && chook)
        test_debug_hook("c", "c");
    msfs_util_init(&argc, &argv, msg_debug_hook);
    util_test_start(client);
    if (!client)
        setup_sig();
    ferr = msg_mon_process_startup(true);             // system messages
    TEST_CHK_FEOK(ferr);
    gargc = argc; // after msg_init - it removes args
    gargp = argv;
    sprintf(gprog, "%s/%s", getenv("PWD"), argv[0]);
    gvirtual = (getenv("SQ_VIRTUAL_NODES") != NULL);
    ferr = msg_mon_get_my_process_name(gname, sizeof(gname));
    assert(ferr == XZFIL_ERR_OK);
    if (client) {
        msg_mon_enable_mon_messages(true); // get mon messages
        ferr = msg_mon_get_process_info(NULL, &gcnid, NULL);
        assert(ferr == XZFIL_ERR_OK);
        ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETSENDLIMIT,
                                     (short) (gmaxc * gdloop));
        assert(ferr == XZFIL_ERR_OK);
        srand(1);
        sleept = 1000;
        start_server(argc, argv);
        sleep(1);
        ferr = msg_mon_open_process((char *) "$srv",              // name
                                    TPT_REF(gphandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
        ferr = XPROCESSHANDLE_DECOMPOSE_(TPT_REF(gphandle), &snid, &spid);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < gloop; inx++) {
            if (mq)
                printf("client: inx=%d\n", inx);
            for (dinx = 0; dinx < gmaxc; dinx++) {
                sprintf(lname, "c%d", dinx);
                gthrc[dinx] = new MyThread(client_thr, lname, dinx);
            }
            disable = msg_test_assert_disable();
            for (dinx = 0; dinx < gmaxc; dinx++)
                gthrc[dinx]->start();
            if (rnd)
                sleept = (int) ((float) gksleep * (rand_r(&gseed) / (RAND_MAX + 1.0)));
            usleep(sleept);
            for (dinx = 0; dinx < gmaxc; dinx++) {
                status = gthrc[dinx]->join(&res);
                TEST_CHK_STATUSOK(status);
                if (gverbose)
                    printf("joined with client %d\n", dinx);
            }
            for (dinx = 0; dinx < gmaxc; dinx++)
                delete gthrc[dinx];
            msg_test_assert_enable(disable);
        }
    } else {
        msg_mon_enable_mon_messages(true); // get mon messages
        ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETRECVLIMIT,
                                     XMAX_SETTABLE_RECVLIMIT);
        assert(ferr == XZFIL_ERR_OK);
        pp_init();
        if (!gshutdown) {
            for (dinx = 0; dinx < gmaxs; dinx++) {
                char lname[10];
                sprintf(lname, "s%d", dinx);
                gthrs[dinx] = new SB_Thread::Thread(server_thr, lname);
            }
            for (dinx = 0; dinx < gmaxs; dinx++)
                gthrs[dinx]->start();
            for (dinx = 0; dinx < gmaxs; dinx++) {
                status = gthrs[dinx]->join(&res);
                TEST_CHK_STATUSOK(status);
                if (gverbose)
                    printf("joined with server %d\n", dinx);
            }
        }
        if (gverbosepp)
            pp_printf("exit pid=%d\n", getpid());
    }

    if (client) {
        sleep(1);
        ferr = msg_mon_close_process(TPT_REF(gphandle));
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
int main(int argc, char *argv[]) {
    _xcc_status         cc;
    bool                client = false;
    int                 closes;
    int                 count_read;
    int                 count_written;
    int                 ferr;
    short               filenumr;
    short               filenums[MAX_SRV];
    int                 inxl;
    int                 inxs;
    int                 loop = 10;
    int                 maxcp = 1;
    int                 maxsp = 1;
    bool                mq = false;
    char                serv[20];
    xzsys_ddl_smsg_def *sys_msg = (xzsys_ddl_smsg_def *) recv_buffer;
    bool                verbose = false;
    TAD                 zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxcp",     TA_Int,  MAX_CLI,     &maxcp     },
      { "-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 = file_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    msfs_util_init_fs(&argc, &argv, file_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = file_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_get_my_process_name(my_name, BUFSIZ);
    util_check("msg_mon_get_my_process_name", ferr);

    if (client) {
        for (inxl = 0; inxl < loop; inxl++) {
            for (inxs = 0; inxs < maxsp; inxs++) {
                sprintf(serv, "$srv%d", inxs);
                ferr = BFILE_OPEN_(serv, (short) strlen(serv), &filenums[inxs],
                                   0, 0, 0, 0, 0, 0, 0, NULL);
                TEST_CHK_FEOK(ferr);
            }
            for (inxs = 0; inxs < maxsp; inxs++) {
                sprintf(send_buffer, "hello, greetings %d from %s, inx=%d",
                        inxs, my_name, inxl);
                cc = BWRITEREADX(filenums[inxs],
                                 send_buffer,
                                 (int) (strlen(send_buffer) + 1), // cast
                                 BUFSIZ,
                                 &count_read,
                                 0);
                TEST_CHK_CCEQ(cc);
                if (mq) {
                    if ((inxl % 100) == 0)
                        printf("count=%d\n", inxl);
                } else
                    printf("%s\n", send_buffer);
            }
            for (inxs = 0; inxs < maxsp; inxs++) {
                ferr = BFILE_CLOSE_(filenums[inxs], 0);
                TEST_CHK_FEOK(ferr);
            }
        }
    } else {
        closes = 0;
        ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr,
                           0, 0, 0,
                           1, 0, // sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);

        // process requests
        for (inxl = 0;; inxl++) {
            cc = BREADUPDATEX(filenumr,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            if (_xstatus_ne(cc)) {
                int mt = sys_msg->u_z_msg.z_msgnumber[0];
                if (verbose) {
                    if (mt == XZSYS_VAL_SMSG_CLOSE)
                        printf("inx=%d, type=%d, cc=%d\n", inxl, mt, closes);
                    else
                        printf("inx=%d, type=%d\n", inxl, mt);
                }
                if (mt == XZSYS_VAL_SMSG_CLOSE)
                    closes++;
                count_read = 0;
            } else {
                strcat(recv_buffer, "- reply from ");
                strcat(recv_buffer, my_name);
                count_read = (int) (strlen(recv_buffer) + 1); // cast
            }
            cc = BREPLYX(recv_buffer,
                         count_read,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
            if (closes >= maxcp * loop)
                break;
        }
        ferr = BFILE_CLOSE_(filenumr, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
int main(int argc, char *argv[]) {
    int              arg;
    bool             attach = false;
    _xcc_status      cc;
    bool             chook = false;
    bool             client = false;
    unsigned short   count_read;
    unsigned short   count_written;
    int              ferr;
    short            filenum;
    int              inx;
    int              loop = 10;
    char             my_name[BUFSIZ];
    char             prog[MS_MON_MAX_PROCESS_PATH];
    char             recv_buffer[BUFSIZ];
    char             ret_name[MS_MON_MAX_PROCESS_NAME];
    char             send_buffer[BUFSIZ];
    const char      *server_name = "$SRV";
    int              server_nid = -1;
    TPT_DECL        (server_phandle);
    int              server_pid;
    bool             shook = false;
    TAD              zargs[] = {
      { "-attach",    TA_Bool, TA_NOMAX,    &attach    },
      { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-shook",     TA_Bool, TA_NOMAX,    &shook     },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    arg_proc_args(zargs, false, argc, argv);
    if (chook && client)
        test_debug_hook("c", "c");
    if (shook && !client)
        test_debug_hook("s", "s");
    if (client && attach)
        ferr = file_init_attach(&argc, &argv, true, (char *) "$CLI");
    else
        ferr = file_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    util_test_start(client);
    ferr = file_mon_process_startup(!client); // system messages
    TEST_CHK_FEOK(ferr);
    util_gethostname(my_name, sizeof(my_name));

    if (client) {
        sprintf(prog, "%s/%s", getenv("PWD"), argv[0]);
        for (arg = 0; arg < argc; arg++)
            if (strcmp(argv[arg], "-client") == 0) // start_process
                argv[arg] = (char *) "-server";
        ferr = msg_mon_start_process(prog,                   // prog
                                     (char *) server_name,   // name
                                     ret_name,               // ret name
                                     argc,
                                     argv,
                                     TPT_REF(server_phandle),
                                     0,                      // open
                                     NULL,                   // oid
                                     MS_ProcessType_Generic, // type
                                     0,                      // priority
                                     0,                      // debug
                                     0,                      // backup
                                     &server_nid,            // nid
                                     &server_pid,            // pid
                                     NULL,                   // infile
                                     NULL);                  // outfile
        TEST_CHK_FEOK(ferr);

        assert(strcmp(ret_name, server_name) == 0);

        ferr = XFILE_OPEN_((char *) server_name, (short) strlen(server_name), &filenum,
                           0, 0, 0, 0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            cc = XWRITEREADX(filenum,
                             send_buffer,
                             (short) (strlen(send_buffer) + 1),
                             BUFSIZ,
                             &count_read,
                             0);
            TEST_CHK_CCEQ(cc);
            printf("%s\n", send_buffer);
        }
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, 0,
                           1, 1, // no sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            cc = XREADUPDATEX(filenum,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            TEST_CHK_CCEQ(cc);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            count_read = (short) (strlen(recv_buffer) + 1);
            cc = XREPLYX(recv_buffer,
                         count_read,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Beispiel #11
0
int main(int argc, char *argv[]) {
    SB_Array<int>  array(MAX_OUT);
    int            client = false;
    int            disable = 0;
    int            ferr;
    int            inx;
    int            lerr;
    int            linker = false;
    int            listener = false;
    int            oid;
    int            req_ctrl_size;
    int            req_data_size;
    int            rep_ctrl_size;
    int            rep_data_size;
    RT             results;
    TPT_DECL      (phandle);
    TAD            zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-linker",    TA_Bool, TA_NOMAX,    &linker    },
      { "-listener",  TA_Bool, TA_NOMAX,    &listener  },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

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

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    if (linker)
        util_test_finish(!client);
    else
        util_test_finish(client);
    return 0;
}
Beispiel #12
0
int main(int argc, char *argv[]) {
    int         arg;
    bool        chook = false;
    bool        client = false;
    int         ferr;
    int         inx;
    int         loop = 10;
    char        my_name[BUFSIZ];
    bool        nowait = false;
    int         nid;
    int         pid;
    char        prog[MS_MON_MAX_PROCESS_PATH];
    char        retname[BUFSIZ];
    char        server_name[30];
    int         server_nid;
    TPT_DECL   (server_phandle);
    int         server_pid;
    bool        shook = false;
    int         status;
    TAD         zargs[] = {
      { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-nowait",    TA_Bool, TA_NOMAX,    &nowait    },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-shook",     TA_Bool, TA_NOMAX,    &shook     },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    arg_proc_args(zargs, false, argc, argv);
    if (chook && client)
        test_debug_hook("c", "c");
    if (shook && !client)
        test_debug_hook("s", "s");
    ferr = msg_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    if (client)
        msg_mon_enable_mon_messages(true);
    util_test_start(client);
    msg_mon_enable_mon_messages(true);
    ferr = msg_mon_process_startup(client); // system messages
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_get_process_info(NULL, &nid, &pid);
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_get_my_process_name(my_name, sizeof(my_name));
    TEST_CHK_FEOK(ferr);

    if (client) {
        sprintf(prog, "%s/%s", getenv("PWD"), argv[0]);
        for (arg = 0; arg < argc; arg++)
            if (strcmp(argv[arg], "-client") == 0) // start_process
                argv[arg] = (char *) "-server";
        for (inx = 0; inx < loop; inx++) {
            sprintf(server_name, "$SRV%d", inx);
            server_nid = -1;
            if (nowait)
                ferr = msg_mon_start_process_nowait_cb(cb,                       // callback
                                                       prog,                     // prog
                                                       server_name,              // name
                                                       retname,                  // ret-name
                                                       argc,                     // argc
                                                       argv,                     // argv
                                                       MS_ProcessType_Generic,   // type
                                                       0,                        // priority
                                                       false,                    // debug
                                                       false,                    // backup
                                                       inx,                      // tag
                                                       &server_nid,              // nid
                                                       &server_pid,              // pid
                                                       NULL,                     // infile
                                                       NULL);                    // outfile
            else
                ferr = msg_mon_start_process(prog,                   // prog
                                             server_name,            // name
                                             NULL,                   // ret name
                                             argc,
                                             argv,
                                             TPT_REF(server_phandle),
                                             0,                      // open
                                             NULL,                   // oid
                                             MS_ProcessType_Generic, // type
                                             0,                      // priority
                                             0,                      // debug
                                             0,                      // backup
                                             &server_nid,            // nid
                                             &server_pid,            // pid
                                             NULL,                   // infile
                                             NULL);                  // outfile
            printf("process started, err=%d\n", ferr);
            TEST_CHK_FEOK(ferr);
            if (nowait) {
                status = cv.wait(true);
                TEST_CHK_STATUSOK(status);
            }
            wait_death();
        }
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Beispiel #13
0
int main(int argc, char *argv[]) {
    bool            bidir = false;
    bool            bm = false;
    void           *buf;
    double          busy;
    _xcc_status     cc;
    int             count_read;
    int             count_written;
    int             count_xferred;
    int             dsize = 1024;
    int             ferr;
    short           filenum[MAX_SERVERS];
    short           filenumr;
    int             inx;
    int             loop = 10;
    int             max;
    int             maxsp = 1;
    bool            mq = false;
    bool            nocopy = false;
    bool            nowaitc = false;
    bool            nowaits = false;
    int             pinx;
    struct rusage   r_start;
    struct rusage   r_stop;
    char           *recv_buffer_ptr;
    RI_Type         ri;
    short           sender_len;
    int             sys_msg;
    struct timeval  t_elapsed_data;
    struct timeval  t_elapsed_open;
    struct timeval  t_elapsed_total;
    struct timeval  t_start_data;
    struct timeval  t_start_total;
    struct timeval  t_stop;
    SB_Tag_Type     tag;
    short           tfilenum;
    int             timeout = -1;
    bool            verbose = false;
    TAD             zargs[] = {
      { "-bidir",     TA_Bool, TA_NOMAX,    &bidir        },
      { "-bm",        TA_Bool, TA_NOMAX,    &bm           },
      { "-client",    TA_Bool, TA_NOMAX,    &client       },
      { "-dsize",     TA_Int,  MAX_DBUF,    &dsize        },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop         },
      { "-maxcp",     TA_Int,  MAX_CLIENTS, &maxcp        },
      { "-maxsp",     TA_Int,  MAX_SERVERS, &maxsp        },
      { "-mq",        TA_Bool, TA_NOMAX,    &mq           },
      { "-nocopy",    TA_Bool, TA_NOMAX,    &nocopy       },
      { "-nowaitc",   TA_Bool, TA_NOMAX,    &nowaitc      },
      { "-nowaits",   TA_Bool, TA_NOMAX,    &nowaits      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL          },
      { "",           TA_End,  TA_NOMAX,    NULL          }
    };

    for (inx = 0; inx < MAX_CLIENTS; inx++)
        account[inx] = 0;
    signal(SIGUSR2, printaccount);
    ferr = file_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    msfs_util_init_fs(&argc, &argv, file_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    if (maxcp < 0)
        maxcp = 1;
    if (maxsp < 0)
        maxsp = 1;
    util_test_start(client);
    ferr = file_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    if (nocopy) {
        ferr = file_buf_register(buf_alloc, buf_free);
        TEST_CHK_FEOK(ferr);
    }
    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);
    if (client)
        sleep(1);
    util_time_timer_start(&t_start_total);
    if (client) {
        inx = atoi(&my_name[4]);
        printf("dsize=%d, loop=%d\n", dsize, loop);
        for (pinx = 0; pinx < maxsp; pinx++) {
            sprintf(serv, "$srv%d", pinx);
            ferr = BFILE_OPEN_(serv, (short) strlen(serv), &filenum[pinx],
                               0, 0, nowaitc ? (short) 1 : (short) 0,
                               0, 0, 0, 0, NULL);
            TEST_CHK_FEOK(ferr);
        }
        util_time_timer_start(&t_start_data);
        util_cpu_timer_start(&r_start);
        util_time_elapsed(&t_start_total, &t_start_data, &t_elapsed_open);
        max = loop;
        for (inx = 0; inx < max; inx++) {
            for (pinx = 0; pinx < maxsp; pinx++) {
                if (pinx == 0) {
                    if (verbose)
                        printf("%s-count=%d\n", my_name, inx);
                    else if (mq && ((inx % 1000) == 0))
                        printf("%s-count=%d\n", my_name, inx);
                }
                cc = BWRITEREADX(filenum[pinx],
                                 send_buffer,
                                 (int) dsize, // cast
                                 bidir ? dsize : 0,
                                 &count_read,
                                 0);
            }
            for (pinx = 0; pinx < maxsp; pinx++) {
                if (nowaitc) {
                    TEST_CHK_CCEQ(cc);
                    tfilenum = filenum[pinx];
                    cc = BAWAITIOX(&tfilenum,
                                   &buf,
                                   &count_xferred,
                                   &tag,
                                   timeout,
                                   NULL);
                    TEST_CHK_CCEQ(cc);
                }
            }
        }
    } else {
        ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr,
                           0, 0, nowaits ? (short) 1 : (short) 0, // nowait
                           1, 0, // sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        util_time_timer_start(&t_start_data);
        util_cpu_timer_start(&r_start);
        max = maxcp * loop;
        for (inx = 0; inx < max; inx++) {
            if (nocopy) {
                cc = file_buf_readupdatex(filenumr,
                                          &recv_buffer_ptr,
                                          &count_read,
                                          0);
                buf_free(recv_buffer_ptr);
            } else
                cc = BREADUPDATEX(filenumr,
                                  recv_buffer,
                                  (int) dsize, // cast
                                  &count_read,
                                  0);
            if (nowaits) {
                tfilenum = -1;
                cc = BAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag,
                               timeout,
                               NULL);
                // don't check cc - could be sys msg
                sys_msg = _xstatus_ne(cc);
            } else
                sys_msg = _xstatus_ne(cc);
            if (sys_msg)
                inx--;
            if (!sys_msg) {
                getri(&ri);
                ferr = XPROCESSHANDLE_DECOMPOSE_(TPT_REF(ri.sender),
                                                 NULL, // cpu
                                                 NULL, // pin
                                                 NULL, // nodenumber
                                                 NULL, // nodename
                                                 0,    // nodename
                                                 NULL, // nodename_length
                                                 sender,
                                                 sizeof(sender),
                                                 &sender_len,
                                                 NULL); // sequence_number
                TEST_CHK_FEOK(ferr);
                sender[sender_len] = 0;
                if (verbose)
                    printf("sender=%s\n", sender);
                char *p = &sender[4]; // past $cli
                int sender_inx = atoi(p);
                account[sender_inx]++;
            }
            cc = BREPLYX(recv_buffer,
                         bidir ? dsize : 0,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
    }

    util_cpu_timer_stop(&r_stop);
    util_time_timer_stop(&t_stop);
    util_time_elapsed(&t_start_total, &t_stop, &t_elapsed_total);
    util_time_elapsed(&t_start_data, &t_stop, &t_elapsed_data);
    util_cpu_timer_busy(&r_start, &r_stop, &t_elapsed_data, &busy);

    if (client) {
        if (!bm) {
            print_elapsed("", &t_elapsed_total);
            print_elapsed(" (data)", &t_elapsed_data);
            print_elapsed(" (open)", &t_elapsed_open);
        }
        print_rate(bm, "", bidir ? 2 * loop : loop, dsize, &t_elapsed_data, busy);
    } else
        print_server_busy(bm, "", busy);

    if (client) {
        for (pinx = 0; pinx < maxsp; pinx++) {
            ferr = BFILE_CLOSE_(filenum[pinx], 0);
            TEST_CHK_FEOK(ferr);
        }
    } else {
        ferr = BFILE_CLOSE_(filenumr, 0);
        TEST_CHK_FEOK(ferr);
        ferr = file_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }

    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    printaccount(0);
    return 0;
}
Beispiel #14
0
int main(int argc, char *argv[]) {
    bool            client = false;
    int             ferr;
    int             inx;
    int             inx2;
    int             lerr;
    int             loop = 10;
    int             oid;
    TPT_DECL       (phandle);
    MS_SRE          sre;
    long            t_elapsed;
    struct timeval  t_start;
    struct timeval  t_stop;
    bool            verbose = false;
    TAD             zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    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_time_timer_start(&t_start);
    if (client) {
        for (inx = 0; inx < loop; inx++) {
            if (verbose)
                printf("opening inx=%d\n", inx);
            ferr = msg_mon_open_process((char *) "$srv",      // name
                                        TPT_REF(phandle),
                                        &oid);
            TEST_CHK_FEOK(ferr);
            ferr = msg_mon_close_process(TPT_REF(phandle));
            TEST_CHK_FEOK(ferr);
        }
    } else {
        msg_mon_enable_mon_messages(true);
        for (inx = 0; inx < loop; inx++) {
            for (inx2 = 0; inx2 < 2; inx2++) {
                do {
                    lerr = XWAIT(LREQ, -1);
                    TEST_CHK_WAITIGNORE(lerr);
                    lerr = XMSG_LISTEN_((short *) &sre, // sre
                                        0,              // listenopts
                                        0);             // listenertag
                } while (lerr == XSRETYPE_NOWORK);
                if (verbose)
                    printf("replying inx=%d\n", inx);
                XMSG_REPLY_(sre.sre_msgId,  // msgid
                            NULL,           // replyctrl
                            0,              // replyctrlsize
                            NULL,           // replydata
                            0,              // replydatasize
                            0,              // errorclass
                            NULL);          // newphandle
            }
        }
    }
    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;
}
Beispiel #15
0
int main(int argc, char *argv[]) {
    void           *buf;
    _xcc_status     cc;
    bool            client = false;
    unsigned short  count_read;
    unsigned short  count_written;
    unsigned short  count_xferred;
    int             ferr;
    short           filenum;
    int             inx;
    short           lasterr;
    int             loop = 10;
    char            my_name[BUFSIZ];
    bool            nowait = true;
    char            recv_buffer[BUFSIZ];
    char            send_buffer[BUFSIZ];
    SB_Tag_Type     tag;
    short           tfilenum;
    int             timeout;
    int             timeout_count;
    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       }
    };

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

    if (client) {
        timeout_count = 0;
        ferr = XFILE_OPEN_((char *) "$srv", 4, &filenum,
                           0, 0, nowait ? (short) 1 : (short) 0,
                           0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            cc = XWRITEREADX(filenum,
                             send_buffer,
                             (short) (strlen(send_buffer) + 1),
                             BUFSIZ,
                             &count_read,
                             0);
            if (nowait) {
                TEST_CHK_CCEQ(cc);
                tfilenum = filenum;
                timeout = 1;
                cc = XAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag,
                               timeout,
                               NULL);
                if (_xstatus_ne(cc)) {
                    timeout_count++;
                    TEST_CHK_CCNE(cc);
                    ferr = XFILE_GETINFO_(filenum,
                                          &lasterr,
                                          NULL,
                                          0,
                                          NULL,
                                          NULL,
                                          NULL);
                    assert(lasterr == XZFIL_ERR_TIMEDOUT);
                    tfilenum = filenum;
                    timeout = 200;
                    cc = XAWAITIOX(&tfilenum,
                                   &buf,
                                   &count_xferred,
                                   &tag,
                                   timeout,
                                   NULL);
                    TEST_CHK_CCEQ(cc);
                }
            } else {
                TEST_CHK_CCNE(cc);
                ferr = XFILE_GETINFO_(-1, &lasterr, NULL, 0, NULL, NULL, NULL);
                TEST_CHK_FEOK(ferr);
                assert(lasterr == XZFIL_ERR_TIMEDOUT);
            }
            printf("%s\n", send_buffer);
        }
        assert(timeout_count);
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, 0,
                           1, 1, // no sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            cc = XREADUPDATEX(filenum,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            SB_Thread::Sthr::sleep(30); // cause timeout
            TEST_CHK_CCEQ(cc);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            count_read = (short) (strlen(recv_buffer) + 1);
            cc = XREPLYX(recv_buffer,
                         count_read,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Beispiel #16
0
int main(int argc, char *argv[]) {
    char                      *args[4];
    bool                       attach = false;
    bool                       chook = false;
    bool                       client = false;
    bool                       clientd = false;
    int                        cli_nid = -1;
    int                        cli_pid = -1;
    const char                *cname = "$cli";
    int                        count;
    int                        ferr;
    int                        inx;
    int                        len;
    int                        lerr;
    int                        loop = 10;
    TPT_DECL                  (mphandle);
    char                      *mphandlec = (char *) &mphandle;
    TPT_DECL_INT              (mphandlei);
    int                        msgid;
    int                        my_mon_nid;
    int                        my_mon_pid;
    int                        my_mon_ptype;
    int                        my_mon_zid;
    int                        my_os_pid;
    long                       my_os_tid;
    int                        my_compid;
    int                        my_pnid;
    int                        my_segid;
    int                        nid;
    int                        oid;
    TPT_DECL                  (phandle);
    int                        pid;
    char                      *pname = NULL;
    int                        ptype;
    RT                         results;
    int                        scollpid = -1;
    int                        scompid = -1;
    int                        send_len;
    bool                       shook = false;
    const char                *sname = "$srv";
    bool                       sonar = false;
    MS_SRE                     sre;
    int                        srv_nid = -1;
    int                        srv_pid = -1;
    MS_Mon_Monitor_Stats_Type  stats;
    int                        status;
    long                       t_elapsed;
    struct timeval             t_start;
    struct timeval             t_stop;
    int                        tm_seq;
    bool                       val_bool;
    int                        val_int;
    const char                *val_str;
    int                        winx;
    pid_t                      wpid;
    TAD                        zargs[] = {
        { "-attach",    TA_Bool, TA_NOMAX,    &attach    },
        { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
        { "-client",    TA_Bool, TA_NOMAX,    &client    },
        { "-clientd",   TA_Bool, TA_NOMAX,    &clientd   },
        { "-cname",     TA_Str,  TA_NOMAX,    &cname     },
        { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
        { "-name",      TA_Str,  TA_NOMAX,    &pname     },
        { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
        { "-shook",     TA_Bool, TA_NOMAX,    &shook     },
        { "-sname",     TA_Str,  TA_NOMAX,    &sname     },
        { "-sonar",     TA_Bool, TA_NOMAX,    &sonar     },
        { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

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

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

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

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

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

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

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

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

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

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        if (!clientd) {
            ferr = msg_mon_process_close();
            TEST_CHK_FEOK(ferr);
        }
    }
    util_time_timer_stop(&t_stop);
    t_elapsed = (t_stop.tv_sec * 1000000 + t_stop.tv_usec) -
                (t_start.tv_sec * 1000000 + t_start.tv_usec);
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    if (client) {
        printf("elapsed time (gettimeofday us)=%ld\n", t_elapsed);
    }
    return 0;
}
int main(int argc, char *argv[]) {
    int             arg;
    bool            bm = false;
    char           *buf;
    double          busy;
    bool            chook = false;
    bool            client = false;
    char            errnobuf[100];
    char            error_txt[200];
    int             event_len;
    char            event_data[MS_MON_MAX_SYNC_DATA];
    int             ferr;
    int             inx;
    int             key;
    int             lerr;
    int             loop = 10;
    int             msid;
    int             pid;
    char            prog[MS_MON_MAX_PROCESS_PATH];
    struct rusage   r_start;
    struct rusage   r_stop;
    const char     *server_name = "$SRV";
    int             server_nid;
    TPT_DECL       (server_phandle);
    int             server_pid;
    bool            shook = false;
    struct timeval  t_elapsed;
    struct timeval  t_start;
    struct timeval  t_stop;
    TAD             zargs[] = {
      { "-bm",        TA_Bool, TA_NOMAX,    &bm        },
      { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-shook",     TA_Bool, TA_NOMAX,    &shook     },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

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

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

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Beispiel #18
0
int main(int argc, char *argv[]) {
    bool           abort1 = false;
    bool           abort2 = false;
    void          *buf;
    _xcc_status    cc;
    bool           client = false;
    int            count_read;
    int            count_written;
    int            count_xferred;
    int            dsize = 1024;
    int            ferr;
    short          filenum;
    int            inx;
    int            loop = 10;
    short          mt;
    char           my_name[BUFSIZ];
    bool           verbose = false;
    SB_Tag_Type    tag;
    short          tfilenum;
    int            timeout = -1;
    TAD            zargs[] = {
        { "-abort1",    TA_Bool, TA_NOMAX,    &abort1    },
        { "-abort2",    TA_Bool, TA_NOMAX,    &abort2    },
        { "-client",    TA_Bool, TA_NOMAX,    &client    },
        { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
        { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
        { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
        { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    ferr = file_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    msfs_util_init_fs(&argc, &argv, file_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = file_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_get_my_process_name(my_name, BUFSIZ);
    util_check("msg_mon_get_my_process_name", ferr);

    if (client) {
        ferr = BFILE_OPEN_((char *) "$srv", 4, &filenum,
                           0, 0, (short) 1, // nowait
                           0, 0, 0, 0, NULL);
        if (verbose)
            printf("client open ferr=%d\n", ferr);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            cc = BWRITEREADX(filenum,
                             send_buffer,
                             (unsigned short) (strlen(send_buffer) + 1), // cast
                             0,
                             &count_read,
                             0);
            if (verbose)
                printf("client wr cc=%d\n", cc);
            TEST_CHK_CCEQ(cc);
            tfilenum = -2;
            cc = BAWAITIOX(&tfilenum,
                           &buf,
                           &count_xferred,
                           &tag,
                           timeout,
                           NULL);
            if (verbose)
                printf("client awaitiox cc=%d, fn=%d\n", cc, tfilenum);
            if (abort1) {
                if (_xstatus_ne(cc)) {
                    sleep(1);
                    inx--;
                    continue;
                }
            } else {
                TEST_CHK_CCEQ(cc);
            }
            printf("%s\n", send_buffer);
        }
    } else {
        ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, (short) 0,
                           1, 0, // sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        if (abort1) {
        } else if (abort2) {
            loop -= 2;
        } else {
            loop += 2;
        }
        for (inx = 0; inx < loop; inx++) {
            if (abort1 && (inx == 3))
                util_abort_core_free();
            cc = BREADUPDATEX(filenum,
                              recv_buffer,
                              (int) dsize, // cast
                              &count_read,
                              0);
            if (verbose) {
                memcpy(&mt, recv_buffer, sizeof(mt));
                printf("server cc=%d, mt=%d\n", cc, mt);
            }
            cc = BREPLYX(recv_buffer,
                         0,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
    }

    if (client) {
        ferr = BFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = BFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    }

    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
int main(int argc, char *argv[]) {
    bool                       client = false;
    int                        count;
    int                        disable;
    int                        ferr;
    MS_Mon_Open_Info_Type      info;
    MS_Mon_Open_Info_Max_Type  info_max[MAX_OPENS];
    int                        inx;
    int                        len;
    int                        lerr;
    int                        loop = 10;
    int                        msgid;
    int                        oid;
    TPT_DECL                  (phandle);
    RT                         results;
    int                        send_len;
    MS_SRE                     sre;
    TAD                        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

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

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

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
int main(int argc, char *argv[]) {
    bool               client = false;
    int                ferr;
    int                inx;
    int                len;
    int                lerr;
    int                oid;
    void              *result;
    MS_SRE             sre;
    int                status;
    SB_Thread::Thread *thr_wait;
    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);
    ferr = proc_set_process_completion();
    TEST_CHK_FEOK(ferr);
    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) {
        thr_wait = new SB_Thread::Thread(thread_wait_fun, "wait");
        thr_wait->start();
        thr_send = new SB_Thread::Thread(thread_send_fun, "send");
        thr_send->start();
        thr_send_brk = new SB_Thread::Thread(thread_sendbrk_fun, "sendbrk");
        thr_send_brk->start();
        status = thr_send->join(&result);
        TEST_CHK_STATUSOK(status);
        status = thr_send_brk->join(&result);
        TEST_CHK_STATUSOK(status);
        delete thr_send;
        delete thr_send_brk;
        thr_send = NULL;
        thr_send_brk = NULL;
        status = thr_wait->join(&result);
        TEST_CHK_STATUSOK(status);
        delete thr_wait;
    } else {
        for (inx = 0; inx < loop; 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
                                  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 (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;
}
int main(int argc, char *argv[]) {
    void           *buf;
    _xcc_status     cc;
    bool            client = false;
    unsigned short  count_read;
    unsigned short  count_written;
    unsigned short  count_xferred;
    int             ferr;
    short           filenum;
    int             inx;
    int             loop = 10;
    char            recv_buffer[BUFSIZ];
    char            send_buffer[BUFSIZ];
    SB_Tag_Type     tag;
    short           tfilenum;
    int             timeout = -1;
    bool            verbose = false;
    int             xinx;
    TAD                 zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    if (client) {
        ferr = XFILE_OPEN_((char *) "$srv", 4, &filenum,
                           0, 0, 1,
                           0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "inx=%d, tag=%d", inx, inx);
            cc = XWRITEREADX(filenum,
                             send_buffer,
                             (short) (strlen(send_buffer) + 1),
                             BUFSIZ,
                             &count_read,
                             inx);
            TEST_CHK_CCEQ(cc);
            if (inx < (loop - 1)) {
                cc = XCANCELREQ(filenum, inx);
                TEST_CHK_CCEQ(cc);
                if (verbose)
                    printf("client cancelled inx=%d\n", inx);
            } else {
                printf("client waiting response inx=%d\n", inx);
                tfilenum = filenum;
                cc = XAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag,
                               timeout,
                               NULL);
                TEST_CHK_CCEQ(cc);
                assert(tag == inx);
                printf("%s\n", send_buffer);
            }
        }
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
        printf("if there were no asserts, all is well\n");
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, 1,
                           1, 1, // no sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            cc = XREADUPDATEX(filenum,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              1);
            TEST_CHK_CCEQ(cc);
            tfilenum = filenum;
            cc = XAWAITIOX(&tfilenum,
                           &buf,
                           &count_xferred,
                           &tag,
                           timeout,
                           NULL);
            TEST_CHK_CCEQ(cc);
            count_read = (short) (strlen(recv_buffer) + 1);
            sscanf(recv_buffer, "inx=%d", &xinx);
            if (verbose)
                printf("server replying, server inx=%d, client inx=%d, %s\n",
                       inx, xinx, recv_buffer);
            inx = xinx;
            cc = XREPLYX(recv_buffer,
                         count_read,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
        if (verbose)
            printf("server closing file inx=%d\n", inx);
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
int main(int argc, char *argv[]) {
    int     exit = false;
    int     err;
    int     ferr;
    int     len;
    char    my_name[100];
    char    recv_buffer[BUFSIZ];
    BMS_SRE sre;
    bool    verbose = false;
    TAD     zargs[] = {
      { "-v",         TA_Bool, TA_NOMAX,    &verbose     },
      { "",           TA_End,  TA_NOMAX,    NULL         }
    };

    ferr = msg_init(&argc, &argv);
    arg_proc_args(zargs, false, 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(my_name, (int) sizeof(my_name));
    TEST_CHK_FEOK(ferr);
    msg_mon_enable_mon_messages(true);

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

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    return 0;
}
Beispiel #23
0
int main(int argc, char *argv[]) {
    _bcc_status  bcc;
    bool         client = false;
    int          count_read;
    int          count_written;
    int          ferr;
    short        filenum;
    int          inx;
    int          loop = 10;
    RI_Type      ri;
    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       }
    };

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

    if (client) {
        ferr = BFILE_OPEN_((char *) "$srv", 4, &filenum,
                           0, 0, 0, 0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            bcc = BWRITEREADX(filenum,
                              send_buffer,
                              MAX_BUF,
                              MAX_BUF,
                              &count_read,
                              0);
            TEST_CHK_BCCEQ(bcc);
            assert(count_read == MAX_BUF);
            printf("%s\n", send_buffer);
        }
        ferr = BFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, 0,
                           1, 1, // no sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            bcc = BREADUPDATEX(filenum,
                               recv_buffer,
                               MAX_BUF,
                               &count_read,
                               0);
            TEST_CHK_BCCEQ(bcc);
            getri(&ri);
#ifdef USE_SB_NEW_RI
            assert(ri.max_reply_count == MAX_BUF);
#endif
            getri(&ri);
#ifdef USE_SB_NEW_RI
            assert(ri.max_reply_count == MAX_BUF);
#endif
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            count_read = (int) strlen(recv_buffer) + 1; // cast
            bcc = BREPLYX(recv_buffer,
                          MAX_BUF,
                          &count_written,
                          0,
                          XZFIL_ERR_OK);
            TEST_CHK_BCCEQ(bcc);
            assert(count_written == MAX_BUF);
        }
        ferr = BFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Beispiel #24
0
int main(int argc, char *argv[]) {
    bool       client = false;
    bool       disable = false;
    int        ferr;
    int        lerr;
    int        msgid;
    int        oid;
    TPT_DECL  (phandle);
    RT         results;
    MS_SRE     sre;
    TAD        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    if (client) {
        sprintf(send_buffer, "hello, greetings from %s", my_name);
        ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                          &msgid,                      // msgid
                          NULL,                        // reqctrl
                          0,                           // reqctrlsize
                          NULL,                        // replyctrl
                          0,                           // replyctrlmax
                          send_buffer,                 // reqdata
                          39000,                       // reqdatasize
                          recv_buffer,                 // replydata
                          40000,                       // replydatamax
                          0,                           // linkertag
                          0,                           // pri
                          0,                           // xmitclass
                          0);                          // linkopts
        util_check("XMSG_LINK_", ferr);
        disable = msg_test_assert_disable();
        ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
        msg_test_assert_enable(disable);
        assert(ferr == XZFIL_ERR_PATHDOWN);
        disable = msg_test_assert_disable();
        ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                          &msgid,                      // msgid
                          NULL,                        // reqctrl
                          0,                           // reqctrlsize
                          NULL,                        // replyctrl
                          0,                           // replyctrlmax
                          send_buffer,                 // reqdata
                          39000,                       // reqdatasize
                          recv_buffer,                 // replydata
                          40000,                       // replydatamax
                          0,                           // linkertag
                          0,                           // pri
                          0,                           // xmitclass
                          0);                          // linkopts
        util_check("XMSG_LINK_", ferr);
        msg_test_assert_enable(disable);
        ferr = XMSG_ABANDON_(msgid);
        util_check("XMSG_ABANDON_", ferr);
    } else {
        for (;;) {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            util_abort_core_free();
        }
    }
    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Beispiel #25
0
int main(int argc, char *argv[]) {
    bool      client = false;
    int       count;
    int       ferr;
    int       inx;
    int       lerr;
    int       loop = 10;
    int       msgid;
    int       oid;
    TPT_DECL (phandle);
    RT        results;
    MS_SRE    sre;
    BMS_SRE   sre_tb;
    MS_SRE    sre_tx;
    TAD       zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

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

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

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

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

            XMSG_REPLY_(sre.sre_msgId,  // msgid
                        NULL,           // replyctrl
                        0,              // replyctrlsize
                        recv_buffer,    // replydata
                        0,              // replydatasize
                        0,              // errorclass
                        NULL);          // newphandle
        }
    }
    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
int main(int argc, char *argv[]) {
    int              arg;
    char            *argvn[100];
    char             argvna[100][200];
    bool             chook = false;
    bool             client = false;
    int              ferr;
    int              linx;
    int              loop = 1;
    char             name[20];
    int              pid;
    bool             server0 = false;
    bool             server1 = false;
    bool             server2 = false;
    char            *server_name = (char *) "$SRV";
    bool             shook = false;
    int              status;
    bool             strace = false;
    struct timeval   t_elapsed;
    struct timeval   t_start;
    struct timeval   t_stop;
    bool             test[] = { true, true, true };
    bool             test0 = false;
    bool             test1 = false;
    bool             test2 = false;
    int              tinx;
    int              uerr;
    bool             verbose = false;
    const char      *who;
    TAD              zargs[] = {
      { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-server0",   TA_Bool, TA_NOMAX,    &server0   },
      { "-server1",   TA_Bool, TA_NOMAX,    &server1   },
      { "-server2",   TA_Bool, TA_NOMAX,    &server2   },
      { "-shook",     TA_Bool, TA_NOMAX,    &shook     },
      { "-strace",    TA_Bool, TA_NOMAX,    &strace    },
      { "-test0",     TA_Bool, TA_NOMAX,    &test0     },
      { "-test1",     TA_Bool, TA_NOMAX,    &test1     },
      { "-test2",     TA_Bool, TA_NOMAX,    &test2     },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    arg_proc_args(zargs, false, argc, argv);
    if (test0) {
        test[0] = true;
        test[1] = false;
        test[2] = false;
    } else if (test1) {
        test[0] = false;
        test[1] = true;
        test[2] = false;
    } else if (test2) {
        test[0] = false;
        test[1] = false;
        test[2] = true;
    }
    if (client)
        who = "cli";
    else if (server0)
        who = "srv0";
    else if (server1)
        who = "srv1";
    else
        who = "srv2";
    if (verbose)
        for (arg = 0; arg < argc; arg++)
            printf("%s: argv[%d]=%s\n", who, arg, argv[arg]);
    if (chook && client)
        test_debug_hook("c", "c");
    if (shook && !client)
        test_debug_hook("s", "s");
    if (client) {
        if (verbose)
            printf("%s: about to msg_init\n", who);
        ferr = msg_init(&argc, &argv);
        TEST_CHK_FEOK(ferr);
    } else if (server0) {
        if (verbose)
            printf("%s: about to msg_init_attach\n", who);
        ferr = msg_init_attach(&argc, &argv, false, server_name);
    TEST_CHK_FEOK(ferr);
    } else if (server1) {
        if (verbose)
            printf("%s: about to msg_init_attach\n", who);
        ferr = msg_test_enable_client_only();
        TEST_CHK_FEOK(ferr);
        ferr = msg_init_attach(&argc, &argv, false, server_name);
        TEST_CHK_FEOK(ferr);
    }
    if (client)
        util_test_start(client);
    if (verbose)
        printf("%s: about to msg_mon_process_startup\n", who);
    if (client || server0 || server1) {
        ferr = msg_mon_process_startup(!client); // system messages
        TEST_CHK_FEOK(ferr);
    }

    if (client) {
        for (linx = 0; linx < loop; linx++) {
            for (tinx = 0; tinx < 3; tinx++) {
                if (!test[tinx])
                    continue;
                for (arg = 0; arg < argc; arg++) {
                    if (strcmp(argv[arg], "-client") == 0) { // start_process
                        sprintf(argvna[arg], "-server%d", tinx);
                        argvn[arg] = argvna[arg];
                    } else
                        argvn[arg] = argv[arg];
                }
                argvn[arg] = NULL;
                if (strace) {
                    sprintf(argvna[0], "xt172ms%d", tinx);
                    argvn[0] = argvna[0];
                }
                if (verbose)
                    printf("%s: about to fork-exec\n", who);
                util_time_timer_start(&t_start);
                pid = fork();
                switch (pid) {
                case 0:
                    // child
                    uerr = execvp(argvn[0], argvn);
                    if (uerr == -1)
                        perror("execvp");
                    exit(0);
                case -1:
                    // parent
                    perror("fork");
                    exit(1);
                default:
                    // parent
                    while (wait(&status) != pid)
                        ;
                    util_time_timer_stop(&t_stop);
                    util_time_elapsed(&t_start, &t_stop, &t_elapsed);
                    sprintf(name, " server%d", tinx);
                    print_elapsed(name, &t_elapsed);
                }
                TEST_CHK_FEOK(ferr);
            }
        }
    }
    if (client || server0 || server1) {
        if (verbose)
            printf("%s: about to msg_mon_process_shutdown\n", who);
        ferr = msg_mon_process_shutdown();
        TEST_CHK_FEOK(ferr);
    }
    if (client) {
        util_test_finish(client);
        util_time_timer_stop(&t_stop);
        util_time_elapsed(&t_start, &t_stop, &t_elapsed);
        print_elapsed(" client", &t_elapsed);
    }
    if (verbose)
        printf("%s: about to exit main\n", who);
    return 0;
}
Beispiel #27
0
int main(int argc, char *argv[]) {
    _bcc_status     bcc;
    void           *buf;
    bool            client = false;
    int             count_read;
    int             count_written;
    int             count_xferred;
    bool            e_ldone;
    bool            e_pwu;
    int             err;
    int             ferr;
    short           filenumr;
    short           filenums;
    int             inx;
    int             loop = 10;
    char           *p;
    char            recv_buffer[BUFSIZ];
    char            send_buffer[BUFSIZ];
    int             socka;
    int             sockc;
    int             sockl;
    SB_Tag_Type     tag;
    short           tfilenum;
    int             timeout = -1;
    short           wakeup;
    TAD             zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

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

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

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

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

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

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

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

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

        if (verbose)
            printf("server closing\n");
        ferr = BFILE_CLOSE_(filenumr, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
int main(int argc, char *argv[]) {
    void                *buf;
    _xcc_status          cc;
    unsigned short       count_read;
    unsigned short       count_written;
    unsigned short       count_xferred;
    int                  ferr;
    short                filenum;
    short                lasterr;
    int                  inx;
    int                  loop = 10;
    char                 my_name[BUFSIZ];
    bool                 nowait = false;
    int                  nid;
    char                *p;
    int                  pid;
    char                 recv_buffer[BUFSIZ];
    char                 send_buffer[BUFSIZ];
    SB_Tag_Type          tag;
    short                tfilenum;
    int                  tm_seq;
    int                  timeout = -1;
    MS_Mon_Transid_Type  transid;
    TAD                  zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-nowait",    TA_Bool, TA_NOMAX,    &nowait    },
      { "-print",     TA_Bool, TA_NOMAX,    &print     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    TRANSID_SET_NULL(curr_transid);
    TRANSID_SET_NULL(exp_trans);
    ferr = file_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    msfs_util_init_fs(&argc, &argv, file_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = file_mon_process_startup(!client); // system messages
    TEST_CHK_FEOK(ferr);
    util_gethostname(my_name, sizeof(my_name));

    ferr = msg_mon_trans_register_tmlib(tmlib);
    TEST_CHK_FEOK(ferr);
    ferr = msg_mon_get_process_info(NULL, &nid, &pid);
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = XFILE_OPEN_((char *) "$srv", 4, &filenum,
                           0, 0, nowait ? (short) 1 : (short) 0,
                           0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            ferr = msg_mon_get_tm_seq(&tm_seq);
            TEST_CHK_FEOK(ferr);
            if (inx & 1)
                cc = XSETMODE(filenum, 117, 1, 0, NULL); // suppress
            else
                cc = XSETMODE(filenum, 117, 0, 0, NULL); // normal
            TEST_CHK_CCEQ(cc);
            ferr = XFILE_GETINFO_(-1, &lasterr, NULL, 0, NULL, NULL, NULL);
            assert(lasterr == XZFIL_ERR_OK);
            sprintf(send_buffer, "hello, greetings from %s, inx=%d, trans=%d",
                    my_name, inx, tm_seq);
            if (print)
                printf("client enlist, transid=%d\n", tm_seq);
            TRANSID_SET_SEQ(transid, tm_seq);
            trans_set_curr(transid);
            if ((inx & 1) == 0) {
                ferr = msg_mon_trans_enlist(nid, pid, transid);
                TEST_CHK_FEOK(ferr);
            }
            if ((inx & 1) == 0)
                fun_set(TMLIB_FUN_GET_TX, TMLIB_FUN_REINSTATE_TX);
            else
                fun_set(-1, -1);
            trans_set(transid);
            cc = XWRITEREADX(filenum,
                             send_buffer,
                             (short) (strlen(send_buffer) + 1),
                             BUFSIZ,
                             &count_read,
                             0);
            if (nowait) {
                TEST_CHK_CCEQ(cc);
                tfilenum = filenum;
                cc = XAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag,
                               timeout,
                               NULL);
            }
            TEST_CHK_CCEQ(cc);
            fun_check(-1);
            if (print)
                printf("client end, transid=%d\n", tm_seq);
            if ((inx & 1) == 0) {
                ferr = msg_mon_trans_end(nid, pid, transid);
                TEST_CHK_FEOK(ferr);
                TRANSID_SET_NULL(transid);
                trans_set_curr(transid); // no more trans
            }
            printf("%s\n", send_buffer);
        }
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, nowait ? (short) 1 : (short) 0,
                           1, 1, // no sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            if ((inx & 1) == 0)
                fun_set(TMLIB_FUN_REG_TX, -1);
            else
                fun_set(-1, -1);
            cc = XREADUPDATEX(filenum,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            TEST_CHK_CCEQ(cc);
            if (nowait) {
                tfilenum = filenum;
                cc = XAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag,
                               timeout,
                               NULL);
                TEST_CHK_CCEQ(cc);
            }
            if (inx & 1) {
                TRANSID_SET_NULL(transid);
            } else {
                p = &recv_buffer[strlen(recv_buffer)];
                while ((p > recv_buffer) && (*p != '='))
                    p--;
                if (*p == '=') {
                    p++;
                    sscanf(p, "%d", &tm_seq);
                    TRANSID_SET_SEQ(transid, tm_seq);
                } else
                    TRANSID_SET_NULL(transid);
            }
            if (inx & 1) {
                MS_Mon_Transid_Type ltransid;
                TRANSID_SET_NULL(ltransid);
                trans_set_curr(ltransid);
            }
            trans_set(transid);
            trans_check(curr_transid);
            fun_check(-1);
            if ((inx & 1) == 0)
                fun_set(TMLIB_FUN_CLEAR_TX, -1);
            else
                fun_set(-1, -1);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            count_read = (short) (strlen(recv_buffer) + 1);
            cc = XREPLYX(recv_buffer,
                         count_read,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_FEOK(ferr);
            fun_check(-1);
        }
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Beispiel #29
0
int main(int argc, char *argv[]) {
    int        ferr;
    TPT_DECL2 (phandle,MAX_SERVERS);
    int        inx;
    int        lerr;
    int        loop = 10;
    int        max;
    int        maxsp = 1;
    int        oid;
    int        pinx;
    MS_SRE     sre;
    bool       verbose = false;
    TAD        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxcp",     TA_Int,  MAX_CLIENTS, &maxcp     },
      { "-maxsp",     TA_Int,  MAX_SERVERS, &maxsp     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

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

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
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;
}