Beispiel #1
0
void test_timers_cb() {
    int             ferr;
    int             status;
    struct timeval  t_elapsed;
    struct timeval  t_start1;
    struct timeval  t_start2;
    struct timeval  t_stop;
    short           tleid1;
    short           tleid2;
    long            to_act;
    long            to_exp;

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

    // check timers
    util_time_timer_start(&t_start1);
    ferr = timer_start_cb(40, 2, 2, &tleid1, &cb1);
    assert(ferr == XZFIL_ERR_OK);
    usleep(30000);
    util_time_timer_start(&t_start2);
    ferr = timer_start_cb(40, 4, 4, &tleid2, &cb2);
    assert(ferr == XZFIL_ERR_OK);

    status = cv1.wait(true);
    TEST_CHK_STATUSOK(status);
    if (verbose)
        printf("cv1 wait done\n");
    util_time_timer_stop(&t_stop);
    util_time_elapsed(&t_start1, &t_stop, &t_elapsed);
    to_act = t_elapsed.tv_sec * 1000000 + t_elapsed.tv_usec;
    to_exp = t1.sre_tleTOVal * 10000;
    if (verbose || (to_act < to_exp))
        printf("tleid=%d, exp-to=%ld, act-to=%ld\n",
               t1.sre_tleId, to_exp, to_act);
    assert(to_act >= to_exp);
    if (to_tol > 0)
        assert(to_act <= (to_exp + to_tol));

    status = cv2.wait(true);
    TEST_CHK_STATUSOK(status);
    if (verbose)
        printf("cv2 wait done\n");
    util_time_timer_stop(&t_stop);
    util_time_elapsed(&t_start2, &t_stop, &t_elapsed);
    to_act = t_elapsed.tv_sec * 1000000 + t_elapsed.tv_usec;
    to_exp = t2.sre_tleTOVal * 10000;
    if (verbose || (to_act < to_exp))
        printf("tleid=%d, exp-to=%ld, act-to=%ld\n",
               t2.sre_tleId, to_exp, to_act);
    assert(to_act >= to_exp);
    if (to_tol > 0)
        assert(to_act <= (to_exp + to_tol));
}
Beispiel #2
0
void *thread_cli_fun(void *arg) {
    double          busy;
    int             inx;
    Msg            *msg;
    struct rusage   r_start;
    struct rusage   r_stop;
    struct timeval  t_elapsed_data;
    struct timeval  t_elapsed_total;
    struct timeval  t_start_data;
    struct timeval  t_start_total;
    struct timeval  t_stop;

    arg = arg; // touch
    util_time_timer_start(&t_start_total);
    util_time_timer_start(&t_start_data);
    util_cpu_timer_start(&r_start);
    for (inx = 0; inx < loop; inx++) {
        if (verbose)
            printf("count=%d\n", inx);
        msg = msg_queue_remove(&mutex_pool, &queue_pool);
        assert(msg != NULL);
        if (csize) {
            msg->cbuf = (char *) malloc(csize);
            memcpy(msg->cbuf, send_buffer2, csize);
        }
        if (dsize) {
            msg->dbuf = (char *) malloc(dsize);
            memcpy(msg->dbuf, send_buffer, dsize);
        }
        msg_queue_add(&mutex_srv, &queue_srv, msg);
        cv_signal(&cv_srv);
        cv_wait(&cv_cli);
        msg = msg_queue_remove(&mutex_cli, &queue_cli);
        assert(msg != NULL);
        msg_queue_add(&mutex_pool, &queue_pool, msg);
    }
    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 (!bm) {
        print_elapsed("", &t_elapsed_total);
        print_elapsed(" (data)", &t_elapsed_data);
    }
    print_rate(bm, "", bidir ? 2 * loop : loop, dsize, &t_elapsed_data, busy);
    return NULL;
}
Beispiel #3
0
void test_timers() {
    _xcc_status     cc;
    int             lerr;
    MS_SRE_TPOP     sre;
    struct timeval  t_elapsed;
    struct timeval  t_start1;
    struct timeval  t_start2;
    struct timeval  t_stop;
    short           tleid1;
    short           tleid2;
    long            to_act;
    long            to_exp;

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

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

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

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

    lerr = XWAIT(LREQ, -1);
    assert(lerr == LREQ);
    lerr = XMSG_LISTEN_((short *) &sre, // sre
                        0,              // listenopts
                        0);             // listenertag
    assert(lerr == XSRETYPE_TPOP);
    util_time_timer_stop(&t_stop);
    util_time_elapsed(&t_start2, &t_stop, &t_elapsed);
    to_act = t_elapsed.tv_sec * 1000000 + t_elapsed.tv_usec;
    to_exp = sre.sre_tleTOVal * 10000;
    if (verbose || (to_act < to_exp))
        printf("tleid=%d, exp-to=%ld, act-to=%ld\n",
               sre.sre_tleId, to_exp, to_act);
    assert(to_act >= to_exp);
    if (to_tol > 0)
        assert(to_act <= (to_exp + to_tol));
}
Beispiel #4
0
void Thread_Test::work() {
    _xcc_status     cc;
    int             lerr;
    MS_SRE_TPOP     sre;
    int             status;
    struct timeval  t_elapsed;
    struct timeval  t_start;
    struct timeval  t_stop;
    int             tid;
    short           tleid1;
    short           tleid2;
    short           tleid3;
    short           tleid4;
    long            to_act;
    long            to_exp;

    tid = gettid();
    // drain events
    lerr = XWAIT(-1, -2);
    TEST_CHK_WAITIGNORE(lerr);
    lerr = XWAIT(-1, -2);
    TEST_CHK_WAITIGNORE(lerr);
    util_time_timer_start(&t_start);
    cc = XSIGNALTIMEOUT(40, 4, tid, &tleid1);
    TEST_CHK_CCEQ(cc);
    cc = XSIGNALTIMEOUT(80, 8, tid, &tleid2);
    TEST_CHK_CCEQ(cc);
    cc = XSIGNALTIMEOUT(20, 2, tid, &tleid3);
    TEST_CHK_CCEQ(cc);
    cc = XSIGNALTIMEOUT(160, 16, tid, &tleid4);
    TEST_CHK_CCEQ(cc);
    if (verbose)
        printf("w=%d\n", whoami);
    while (tles < 4 * maxth) {
        lerr = XWAIT(-1, 10);
        do {
            lerr = XMSG_LISTEN_((short *) &sre, // sre
                                0,              // listenopts
                                0);             // listenertag
            switch (lerr) {
            case XSRETYPE_TPOP:
                util_time_timer_stop(&t_stop);
                util_time_elapsed(&t_start, &t_stop, &t_elapsed);
                to_act = t_elapsed.tv_sec * 1000000 + t_elapsed.tv_usec;
                to_exp = sre.sre_tleTOVal * 10000;
                if (verbose || (to_act < to_exp))
                    printf("w=%d, tid=%d, tleid=%d, exp-to=%ld, act-to=%ld\n",
                           whoami, tid, sre.sre_tleId, to_exp, to_act);
                assert(to_act >= to_exp);
                if (to_tol > 0)
                    assert(to_act <= (to_exp + to_tol));
                status = tles_sl.lock();
                TEST_CHK_STATUSOK(status);
                tles++;
                status = tles_sl.unlock();
                TEST_CHK_STATUSOK(status);
                if (verbose)
                    printf("w=%d, TLEs=%d\n", whoami, tles);
                break;
            case XSRETYPE_NOWORK:
                break;
            default:
                assert((lerr == XSRETYPE_TPOP) || (lerr == XSRETYPE_NOWORK));
            }
        } while (lerr != XSRETYPE_NOWORK);
    }
}
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 #6
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;
    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 #8
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 #9
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 #10
0
int main(int argc, char *argv[]) {
    _xcc_status         cc;
    bool                client = false;
    unsigned short      count_read;
    unsigned short      count_written;
    int                 ferr;
    short               filenumr;
    short               filenums[MAXSRV];
    int                 inxl;
    int                 inxs;
    int                 loop = 10;
    int                 maxsp = 2;
    bool                verbose = false;
    xzsys_ddl_smsg_def *sys_msg = (xzsys_ddl_smsg_def *) recv_buffer;
    struct timeval      t_elapsed_close;
    struct timeval      t_elapsed_closem1;
    struct timeval      t_elapsed_open;
    struct timeval      t_elapsed_openm1;
    struct timeval      t_start_close;
    struct timeval      t_start_closem1;
    struct timeval      t_start_open;
    struct timeval      t_start_openm1;
    struct timeval      t_stop_close;
    struct timeval      t_stop_closem1;
    struct timeval      t_stop_open;
    struct timeval      t_stop_openm1;
    TAD                 zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxsp",     TA_Int,  MAXSRV,      &maxsp     },
      { "-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) {
        util_time_timer_start(&t_start_open);
        for (inxs = 0; inxs < maxsp; inxs++) {
            ferr = XFILE_OPEN_((char *) "$srv", 4, &filenums[inxs],
                               0, 0, 0, 0, 0, 0, 0, NULL);
            TEST_CHK_FEOK(ferr);
            if (inxs == 0)
                util_time_timer_start(&t_start_openm1);
        }
        util_time_timer_stop(&t_stop_open);
        util_time_timer_stop(&t_stop_openm1);
        for (inxs = 0; inxs < maxsp; inxs++) {
            for (inxl = 0; inxl < loop; inxl++) {
                sprintf(send_buffer, "hello, greetings %d from %s, inx=%d",
                        inxs, my_name, inxl);
                cc = XWRITEREADX(filenums[inxs],
                                 send_buffer,
                                 (unsigned short) (strlen(send_buffer) + 1), // cast
                                 BUFSIZ,
                                 &count_read,
                                 0);
                TEST_CHK_CCEQ(cc);
                printf("%s\n", send_buffer);
            }
        }
        util_time_timer_start(&t_start_close);
        util_time_timer_start(&t_start_closem1);
        for (inxs = 0; inxs < maxsp; inxs++) {
            if (inxs == (maxsp - 1))
                util_time_timer_stop(&t_stop_closem1);
            ferr = XFILE_CLOSE_(filenums[inxs], 0);
            TEST_CHK_FEOK(ferr);
        }
        util_time_timer_stop(&t_stop_close);
        util_time_elapsed(&t_start_open, &t_stop_open, &t_elapsed_open);
        util_time_elapsed(&t_start_openm1, &t_stop_openm1, &t_elapsed_openm1);
        util_time_elapsed(&t_start_close, &t_stop_close, &t_elapsed_close);
        util_time_elapsed(&t_start_closem1, &t_stop_closem1, &t_elapsed_closem1);
        print_elapsed(" (open)", &t_elapsed_open);
        print_elapsed(" (open-1st)", &t_elapsed_openm1);
        print_elapsed(" (close)", &t_elapsed_close);
        print_elapsed(" (close-lst)", &t_elapsed_closem1);
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr,
                           0, 0, 0,
                           1, 0, // sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);

        // process opens
        for (inxs = 0; inxs < maxsp; inxs++) {
            cc = XREADUPDATEX(filenumr,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            TEST_CHK_CCNE(cc);
            if (verbose) {
                int mt = sys_msg->u_z_msg.z_msgnumber[0];
                printf("inx=%d, type=%d\n", inxs, mt);
            }
            cc = XREPLYX(recv_buffer,
                         0,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
        for (inxs = 0; inxs < maxsp; inxs++) {
            for (inxl = 0; inxl < loop; inxl++) {
                cc = XREADUPDATEX(filenumr,
                                  recv_buffer,
                                  BUFSIZ,
                                  &count_read,
                                  0);
                TEST_CHK_CCEQ(cc);
                strcat(recv_buffer, "- reply from ");
                strcat(recv_buffer, my_name);
                count_read = (unsigned short) (strlen(recv_buffer) + 1); // cast
                cc = XREPLYX(recv_buffer,
                             count_read,
                             &count_written,
                             0,
                             XZFIL_ERR_OK);
                TEST_CHK_CCEQ(cc);
            }
        }

        // process closes
        for (inxs = 0; inxs < maxsp; inxs++) {
            cc = XREADUPDATEX(filenumr,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            TEST_CHK_CCNE(cc);
            if (verbose) {
                int mt = sys_msg->u_z_msg.z_msgnumber[0];
                printf("inx=%d, type=%d\n", inxs, mt);
            }
            cc = XREPLYX(recv_buffer,
                         0,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
        ferr = XFILE_CLOSE_(filenumr, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Beispiel #11
0
void *client_thr(void *arg) {
    Util_AA<char>   event_data(MS_MON_MAX_SYNC_DATA);
    int             event_len;
    int             ferr;
    int             inx;
    int             msgid;
    Util_AA<char>   recv_buffer(BUFSIZ);
    Util_AA<short>  recv_buffer3(BUFSIZ);
    RT              results;
    Util_AA<char>   send_buffer(BUFSIZ);
    Util_AA<short>  send_buffer2(BUFSIZ);
    int             send_len;
    long            t_elapsed;
    struct timeval  t_start;
    struct timeval  t_stop;
    int             whoami = inxc++;

    arg = arg; // touch
    if (event) {
        ferr = msg_mon_event_wait(1, &event_len, &event_data);
        TEST_CHK_FEOK(ferr);
    }
    util_time_timer_start(&t_start);
    for (inx = 0; inx < loop; inx++) {
        if (txrate) {
            if ((inx % 100) == 0) {
                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);
                t_elapsed = t_elapsed / 1000;
                if (inx == 0)
                    printf("%s: c-%d\n", name, whoami);
                else
                    printf("%s: c-%d, inx=%d, msg/ms=%ld\n",
                           name, whoami, inx, t_elapsed / inx);
            }
        } else if (mq) {
            if ((inx % 100) == 0)
                printf("%s: c-%d, inx=%d\n", name, whoami, inx);
        } else if (!quiet)
            printf("c-%d, inx=%d\n", whoami, inx);
        fflush(stdout);
        sprintf(&send_buffer, "hello, greetings from %s-%d, inx=%d",
                my_name, whoami, inx);
        send_len = (int) strlen(&send_buffer) + 1;
        if (verbose)
            printf("c-%d: sending %s\n", whoami, &send_buffer);
        ferr = XMSG_LINK_(TPT_REF(phandle),                     // phandle
                          &msgid,                      // msgid
                          &send_buffer2,               // reqctrl
                          (ushort) (inx & 1),          // reqctrlsize
                          &recv_buffer3,               // replyctrl
                          (ushort) 1,                  // replyctrlmax
                          &send_buffer,                // reqdata
                          (ushort) send_len,           // reqdatasize
                          &recv_buffer,                // replydata
                          (ushort) BUFSIZ,             // replydatamax
                          0,                           // linkertag
                          0,                           // pri
                          0,                           // xmitclass
                          0);                          // linkopts
        if (!abortserver)
            util_check("XMSG_LINK_", ferr);
        ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
        if (!abortserver)
            util_check("XMSG_BREAK_", ferr);
        if (!abortserver) {
            if (verbose)
                printf("c-%d: received %s\n", whoami, &recv_buffer);
            assert(results.u.t.ctrl_size == (uint) (inx & 1));
            assert(results.u.t.data_size == 100);
            assert(results.u.t.errm == RT_DATA_RCVD); // data
            if (inx == (loop - 1)) {
                if (maxcp > 1)
                    printf("%s: %s\n", name, &recv_buffer);
                else
                    printf("%s\n", &recv_buffer);
            }
        }
    }
    return NULL;
}
Beispiel #12
0
int main(int argc, char *argv[]) {
    bool            attach = false;
    bool            chook = false;
    bool            client = false;
    const char     *cname = "$cli";
    int             count;
    int             ferr;
    int             inx;
    int             len;
    int             lerr;
    int             loop = 10;
    int             msgid;
    int             oid;
    TPT_DECL       (phandle);
    char           *pname = NULL;
    RT              results;
    int             send_len;
    bool            shook = false;
    const char     *sname = "$srv";
    MS_SRE          sre;
    long            t_elapsed;
    struct timeval  t_start;
    struct timeval  t_stop;
    TAD             zargs[] = {
      { "-attach",    TA_Bool, TA_NOMAX,    &attach    },
      { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-cname",     TA_Str,  TA_NOMAX,    &cname     },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-name",      TA_Str,  TA_NOMAX,    &pname     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-shook",     TA_Bool, TA_NOMAX,    &shook     },
      { "-sname",     TA_Str,  TA_NOMAX,    &sname     },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

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

    // process-wait for server/shell
    ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, 2, NULL, false);
    TEST_CHK_FEOK(ferr);
    // process-wait for client
    ferr = msfs_util_wait_process_count(MS_ProcessType_TSE, 1, NULL, false);
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_open_process((char *) sname,       // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    }

    util_gethostname(my_name, sizeof(my_name));
    msg_mon_enable_mon_messages(true);
    if (client) {
        ferr = msg_mon_get_process_info_type(MS_ProcessType_TSE,
                                             &count,
                                             0,
                                             NULL);
        TEST_CHK_FEOK(ferr);
        if (!attach)
            assert(count == 1);
        ferr = msg_mon_get_process_info_type(MS_ProcessType_TSE,
                                             &count,
                                             1,
                                             info);
        TEST_CHK_FEOK(ferr);
        if (!attach)
            assert(count == 1);
    }

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

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }
    util_time_timer_stop(&t_stop);
    t_elapsed = (t_stop.tv_sec * 1000000 + t_stop.tv_usec) -
                (t_start.tv_sec * 1000000 + t_start.tv_usec);
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    if (client)
        printf("elapsed time (gettimeofday us)=%ld\n", t_elapsed);
    return 0;
}
int main(int argc, char *argv[]) {
    bool            bidir = false;
    char           *buf;
    _xcc_status     cc;
    bool            check = false;
    bool            client = false;
    bool            copy = false;
    int             count_read;
    int             count_written;
    int             count_xferred;
    int             dsize = 1024;
    int             ferr;
    short           filenum;
    int             inx;
    int             inx2;
#ifdef MEM_LEAK
    int             leak_loop;
#endif
    int             loop = 10;
    bool            nowait = false;
    long            t_elapsed;
    long            t_elapsed_sec;
    struct timeval  t_start;
    struct timeval  t_stop;
    SB_Tag_Type     tag;
    short           tfilenum;
    int             timeout = -1;
    int             rc;
    bool            reverse = false;
    bool            verbose = false;
    int             wc;
    TAD             zargs[] = {
      { "-bidir",     TA_Bool, TA_NOMAX,    &bidir     },
      { "-check",     TA_Bool, TA_NOMAX,    &check     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-copy",      TA_Bool, TA_NOMAX,    &copy      },
      { "-dsize",     TA_Int,  MAX_DBUF,    &dsize     },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-nowait",    TA_Bool, TA_NOMAX,    &nowait    },
      { "-reverse",   TA_Bool, TA_NOMAX,    &reverse   },
      { "-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 (bidir)
        reverse = false;
    for (inx2 = 0; inx2 < dsize; inx2++)
        send_buffer[inx2] = CHK_CHAR;
    if (client) {
        printf("bidir=%d, check=%d, copy=%d, dsize=%d, loop=%d, nowait=%d, reverse=%d\n",
               bidir, check, copy, dsize, loop, nowait, reverse);
        ferr = BFILE_OPEN_((char *) "$srv", 4, &filenum,
                           0, 0, nowait ? (short) 1 : (short) 0,
                           0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        util_time_timer_start(&t_start);
#ifdef MEM_LEAK
        for (leak_loop = 0; ; leak_loop++) {
            if ((leak_loop % 100) == 0)
                printf("leak_loop=%d\n", leak_loop);
#endif
        for (inx = 0; inx < loop; inx++) {
            if (verbose)
                printf("count=%d\n", inx);
            wc = dsize;
            rc = dsize;
            if (reverse)
                wc = 0;
            else if (!bidir)
                rc = 0; // !bidir && !reverse
            cc = BWRITEREADX(filenum,
                             send_buffer,
                             wc,
                             rc,
                             &count_read,
                             0);
            TEST_CHK_CCEQ(cc);
            if (nowait) {
                tfilenum = filenum;
                cc = BAWAITIOX(&tfilenum,
                               (void **) &buf,
                               &count_xferred,
                               &tag,
                               timeout,
                               NULL);
                TEST_CHK_CCEQ(cc);
                if (check) {
                    assert(buf == send_buffer);
                    assert(count_xferred == 0);
                    if (rc) {
                        for (inx2 = 0; inx2 < dsize; inx2++) {
                            if (buf[inx2] != CHK_CHAR) {
                                printf("buf[%d]=%d\n", inx2, buf[inx2]);
                                assert(buf[inx2] == CHK_CHAR);
                            }
                        }
                    }
                }
            }
        }
#ifdef MEM_LEAK
        }
#endif
        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);
        t_elapsed_sec = t_elapsed / 1000000;
        t_elapsed -= t_elapsed_sec * 1000000;
        printf("elapsed=%ld.%ld\n", t_elapsed_sec, t_elapsed);

        ferr = BFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, nowait ? (short) 1 : (short) 0,
                           1, 1, // no sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
#ifdef MEM_LEAK
        for (leak_loop = 0; ; leak_loop++) {
#endif
        for (inx = 0; inx < loop; inx++) {
            if (copy)
                cc = BREADUPDATEX(filenum,
                                  recv_buffer,
                                  dsize,
                                  &count_read,
                                  inx);
            else
                cc = file_buf_readupdatex(filenum, &buf, &count_read, inx);
            TEST_CHK_CCEQ(cc);
            if (nowait) {
                tfilenum = filenum;
                cc = BAWAITIOX(&tfilenum,
                               (void **) &buf,
                               &count_xferred,
                               &tag,
                               timeout,
                               NULL);
                TEST_CHK_CCEQ(cc);
                if (check) {
                    if (reverse)
                        assert(count_xferred == 0);
                    else
                        assert(count_xferred == dsize);
                    assert(tag == inx);
                    if (copy)
                        assert(buf == recv_buffer);
                }
            } else {
                if (reverse)
                    assert(count_read == 0);
                else
                    assert(count_read == dsize);
                if (copy)
                    buf = recv_buffer;
                else if (reverse) {
                    buf = send_buffer;
                }
            }
            if (check && !reverse) {
                for (inx2 = 0; inx2 < dsize; inx2++) {
                    if (buf[inx2] != CHK_CHAR) {
                        printf("buf[%d]=%d\n", inx2, buf[inx2]);
                        assert(buf[inx2] == CHK_CHAR);
                    }
                }
            }
            if (bidir || reverse)
                cc = BREPLYX(buf,
                             dsize,  // wc
                             &count_written,
                             0,
                             XZFIL_ERR_OK);
            else
                cc = BREPLYX(buf,
                             0,      // wc
                             &count_written,
                             0,
                             XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
            if (!copy && !reverse)
                free(buf);
        }
#ifdef MEM_LEAK
        }
#endif
        ferr = BFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}