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;
}
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 #7
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 #8
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;
}