Ejemplo n.º 1
0
void *server_thr(void *arg) {
    int       ferr;
    int       lerr;
    int       max_msgs = gmaxc * gloop;
    bool      mon_msg;
    Test_SRE  sre;
    int       status;
    int       whoami = ginxs++;

    arg = arg; // touch
    for (;;) {
        if (gsre_count >= max_msgs)
            break;
        if (gshutdown)
            break;
        do {
            lerr = XWAIT(LREQ, 100);
            lerr = XMSG_LISTEN_((short *) &sre.sre,  // sre
                                0,                   // listenopts
                                0);                  // listenertag
        } while (lerr == XSRETYPE_NOWORK);
        mon_msg = (sre.sre.sre_flags & XSRE_MON);
        if (mon_msg) {
            int msg_size = sre.sre.sre_reqDataSize;
            char *msg = new char[msg_size];
            ferr = XMSG_READDATA_(sre.sre.sre_msgId,     // msgid
                                  msg,                   // reqdata
                                  (ushort) msg_size);    // bytecount
            assert(ferr == XZFIL_ERR_OK);
            pp_check_mon_msg(msg);
            pp_check_mon_msg_shutdown(msg);
            XMSG_REPLY_(sre.sre.sre_msgId,   // msgid
                        NULL,                // replyctrl
                        0,                   // replyctrlsize
                        NULL,                // replydata
                        0,                   // replydatasize
                        0,                   // errorclass
                        NULL);               // newphandle
            delete [] msg;
            if (gshutdown)
                break;
        } else {
            status = gmutex.lock();
            TEST_CHK_STATUSOK(status);
            gsre_count++;
            status = gmutex.unlock();
            TEST_CHK_STATUSOK(status);
            if (gverbose)
                printf("s-%d: have work, sre-count=%d\n",
                       whoami, gsre_count);
            server(whoami, &sre);
        }
    }
    return NULL;
}
Ejemplo n.º 2
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));
}
Ejemplo n.º 3
0
void *server_thr(void *arg) {
    int       lerr;
    int       max_msgs = maxcp * maxc * loop;
    Test_SRE  sre;
    Test_SRE *srep;
    int       status;
    int       whoami = inxs++;

    arg = arg; // touch
    for (;;) {
        if (thrlisten) {
            sre.fin = false;
            if (sre_count >= max_msgs)
                break;
            do {
                lerr = XWAIT(LREQ, -1);
                lerr = XMSG_LISTEN_((short *) &sre.sre,  // sre
                                    0,                   // listenopts
                                    0);                  // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            status = mutex.lock();
            TEST_CHK_STATUSOK(status);
            sre_count++;
            status = mutex.unlock();
            TEST_CHK_STATUSOK(status);
            srep = &sre;
        } else
            srep = (Test_SRE *) work_q.remove();
        if (verbose)
            printf("s-%d: have work, fin=%d\n", whoami, srep->fin);
        if (srep->fin)
            break;
        server(whoami, srep);
        if (!thrlisten)
            free_q.add(&srep->link);
    }
    return NULL;
}
Ejemplo n.º 4
0
void test_thread3() {
    int inx;
    int status;

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

    for (inx = 0; inx < maxth; inx++) {
        char name[10];
        sprintf(name, "s%d", inx);
        thr3[inx] = new Thread_Test3(thr_test3, name, inx);
    }
    for (inx = 0; inx < maxth; inx++) {
        thr3[inx]->start();
        SB_Thread::Sthr::yield();
    }
    for (inx = 0; inx < maxth; inx++) {
        void *res;
        status = thr3[inx]->join(&res);
        TEST_CHK_STATUSOK(status);
        printf("joined with thread %d\n", inx);
    }
}
Ejemplo n.º 5
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);
    }
}
Ejemplo n.º 6
0
int main(int argc, char *argv[]) {
    int         arg;
    bool        chook = false;
    bool        client = false;
    int         ferr;
    int         inx;
    int         loop = 10;
    char        my_name[BUFSIZ];
    bool        nowait = false;
    int         nid;
    int         pid;
    char        prog[MS_MON_MAX_PROCESS_PATH];
    char        retname[BUFSIZ];
    char        server_name[30];
    int         server_nid;
    TPT_DECL   (server_phandle);
    int         server_pid;
    bool        shook = false;
    int         status;
    TAD         zargs[] = {
      { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-nowait",    TA_Bool, TA_NOMAX,    &nowait    },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-shook",     TA_Bool, TA_NOMAX,    &shook     },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    if (client) {
        sprintf(prog, "%s/%s", getenv("PWD"), argv[0]);
        for (arg = 0; arg < argc; arg++)
            if (strcmp(argv[arg], "-client") == 0) // start_process
                argv[arg] = (char *) "-server";
        for (inx = 0; inx < loop; inx++) {
            sprintf(server_name, "$SRV%d", inx);
            server_nid = -1;
            if (nowait)
                ferr = msg_mon_start_process_nowait_cb(cb,                       // callback
                                                       prog,                     // prog
                                                       server_name,              // name
                                                       retname,                  // ret-name
                                                       argc,                     // argc
                                                       argv,                     // argv
                                                       MS_ProcessType_Generic,   // type
                                                       0,                        // priority
                                                       false,                    // debug
                                                       false,                    // backup
                                                       inx,                      // tag
                                                       &server_nid,              // nid
                                                       &server_pid,              // pid
                                                       NULL,                     // infile
                                                       NULL);                    // outfile
            else
                ferr = msg_mon_start_process(prog,                   // prog
                                             server_name,            // name
                                             NULL,                   // ret name
                                             argc,
                                             argv,
                                             TPT_REF(server_phandle),
                                             0,                      // open
                                             NULL,                   // oid
                                             MS_ProcessType_Generic, // type
                                             0,                      // priority
                                             0,                      // debug
                                             0,                      // backup
                                             &server_nid,            // nid
                                             &server_pid,            // pid
                                             NULL,                   // infile
                                             NULL);                  // outfile
            printf("process started, err=%d\n", ferr);
            TEST_CHK_FEOK(ferr);
            if (nowait) {
                status = cv.wait(true);
                TEST_CHK_STATUSOK(status);
            }
            wait_death();
        }
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Ejemplo n.º 7
0
int main(int argc, char *argv[]) {
    bool               client = false;
    int                ferr;
    int                inx;
    int                len;
    int                lerr;
    int                oid;
    void              *result;
    MS_SRE             sre;
    int                status;
    SB_Thread::Thread *thr_wait;
    TAD                zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    if (client) {
        thr_wait = new SB_Thread::Thread(thread_wait_fun, "wait");
        thr_wait->start();
        thr_send = new SB_Thread::Thread(thread_send_fun, "send");
        thr_send->start();
        thr_send_brk = new SB_Thread::Thread(thread_sendbrk_fun, "sendbrk");
        thr_send_brk->start();
        status = thr_send->join(&result);
        TEST_CHK_STATUSOK(status);
        status = thr_send_brk->join(&result);
        TEST_CHK_STATUSOK(status);
        delete thr_send;
        delete thr_send_brk;
        thr_send = NULL;
        thr_send_brk = NULL;
        status = thr_wait->join(&result);
        TEST_CHK_STATUSOK(status);
        delete thr_wait;
    } else {
        for (inx = 0; inx < loop; inx++) {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            ferr = XMSG_READCTRL_(sre.sre_msgId,  // msgid
                                  NULL,           // reqctrl
                                  0);             // bytecount
            util_check("XMSG_READCTRL_", ferr);
            ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                  recv_buffer,    // reqdata
                                  40000);         // bytecount
            util_check("XMSG_READDATA_", ferr);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            len = (int) strlen(recv_buffer) + 1;
            len = len; // touch
            XMSG_REPLY_(sre.sre_msgId,  // msgid
                        NULL,           // replyctrl
                        0,              // replyctrlsize
                        recv_buffer,    // replydata
                        39000,          // replydatasize
                        0,              // errorclass
                        NULL);          // newphandle
        }
    }
    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Ejemplo n.º 8
0
int main(int argc, char *argv[]) {
    bool  abortclose = false;
    bool  client = false;
    int   ferr;
    int   inx;
    int   lerr;
    int   oid;
    int   proc;
    void *res;
    int   status;
    int   thr;
    TAD   zargs[] = {
      { "-abortclose",  TA_Bool, TA_NOMAX,    &abortclose   },
      { "-abortserver", TA_Bool, TA_NOMAX,    &abortserver  },
      { "-client",      TA_Bool, TA_NOMAX,    &client       },
      { "-debug",       TA_Bool, TA_NOMAX,    &debug        },
      { "-event",       TA_Bool, TA_NOMAX,    &event        },
      { "-inst",        TA_Int,  TA_NOMAX,    &inst         },
      { "-loop",        TA_Int,  TA_NOMAX,    &loop         },
      { "-maxc",        TA_Int,  MAX_THR_C,   &maxc         },
      { "-maxcp",       TA_Int,  TA_NOMAX,    &maxcp        },
      { "-maxs",        TA_Int,  MAX_THR_S,   &maxs         },
      { "-maxsp",       TA_Int,  TA_NOMAX,    &maxsp        },
      { "-mq",          TA_Bool, TA_NOMAX,    &mq           },
      { "-name",        TA_Str,  TA_NOMAX,    &name         },
      { "-noshutdown",  TA_Bool, TA_NOMAX,    &shutdown     },
      { "-quiet",       TA_Bool, TA_NOMAX,    &quiet        },
      { "-server",      TA_Ign,  TA_NOMAX,    NULL          },
      { "-thrlisten",   TA_Bool, TA_NOMAX,    &thrlisten    },
      { "-txrate",      TA_Bool, TA_NOMAX,    &txrate       },
      { "-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);

    // setup threads
    if (client) {
        for (inx = 0; inx < maxc; inx++) {
            char lname[10];
            sprintf(lname, "c%d", inx);
            thrc[inx] = new SB_Thread::Thread(client_thr, lname);
        }
    } else {
        for (inx = 0; inx < maxs; inx++) {
            char lname[10];
            sprintf(lname, "s%d", inx);
            thrs[inx] = new SB_Thread::Thread(server_thr, lname);
        }
    }

    util_test_start(client);
    ferr = msg_mon_process_startup(!client); // system messages
    TEST_CHK_FEOK(ferr);
    if (client) {
        printf("inst=%d, loop=%d, maxc=%d, maxcp=%d, maxs=%d, maxsp=%d, shutdown=%d, thrlisten=%d, txrate=%d\n",
               inst, loop, maxc, maxcp, maxs, maxsp, shutdown, thrlisten, txrate);
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    }
    util_gethostname(my_name, sizeof(my_name));

    if (client) {
        for (inx = 0; inx < maxc; inx++)
            thrc[inx]->start();
        for (inx = 0; inx < maxc; inx++) {
            status = thrc[inx]->join(&res);
            TEST_CHK_STATUSOK(status);
            printf("joined with client %d\n", inx);
        }
    } else {
        for (inx = 0; inx < MAX_SRES; inx++)
            free_q.add(&sres[inx].link);
        for (inx = 0; inx < maxs; inx++)
            thrs[inx]->start();
        if (!thrlisten) {
            Test_SRE *sre = NULL;
            for (proc = 0; proc < maxcp; proc++) {
                for (thr = 0; thr < maxc; thr++) {
                    for (inx = 0; inx < loop;) {
                        lerr = XWAIT(LREQ, -1);
                        TEST_CHK_WAITIGNORE(lerr);
                        do {
                            if (sre == NULL) {
                                sre = (Test_SRE *) free_q.remove();
                                assert(sre != NULL);
                            }
                            sre->fin = false;
                            lerr = XMSG_LISTEN_((short *) &sre->sre, // sre
                                                0,                   // listenopts
                                                0);                  // listenertag
                            if (lerr == XSRETYPE_IREQ) {
                                assert(sre->sre.sre_msgId > 0);
                                if (verbose)
                                    printf("s-main: queue work inx=%d\n", inx);
                                work_q.add(&sre->link);
                                sre = NULL;
                                inx++;
                            }
                        } while (lerr == XSRETYPE_IREQ);
                    }
                }
            }

            for (inx = 0; inx < maxs; inx++) {
                Test_SRE *quit_sre = (Test_SRE *) free_q.remove();
                quit_sre->fin = true;
                if (verbose)
                    printf("s-main: fin inx=%d\n", inx);
                work_q.add(&quit_sre->link);
                util_time_sleep_ms(1);
            }
        }

        for (inx = 0; inx < maxs; inx++) {
            status = thrs[inx]->join(&res);
            TEST_CHK_STATUSOK(status);
            printf("joined with server %d\n", inx);
        }
    }

    if (abortclose)
        util_abort_core_free();
    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    }
    if (shutdown) {
        ferr = msg_mon_process_shutdown();
        TEST_CHK_FEOK(ferr);
    }
    util_test_finish(client);
    return 0;
}
Ejemplo n.º 9
0
int main(int argc, char *argv[]) {
    _bcc_status        cc;
    bool               chook = false;
    bool               client = false;
    int                count_read;
    int                count_written;
    int                ferr;
    int                inx;
    void              *result;
    bool               shook = false;
    int                status;
    SB_Thread::Thread *thr_test;
    TAD                zargs[] = {
      { "-any1",      TA_Bool, TA_NOMAX,    &any1      },
      { "-any2",      TA_Bool, TA_NOMAX,    &any2      },
      { "-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     },
      { "-thread",    TA_Bool, TA_NOMAX,    &thread    },
      { "",           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");
    ferr = file_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    msfs_util_init_fs(&argc, &argv, file_debug_hook);
    util_test_start(client);
    ferr = file_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);

    if (client) {
        if (thread) {
            thr_test = new SB_Thread::Thread(thread_test_fun, "thr-test");
            thr_test->start();
            status = thr_test->join(&result);
            TEST_CHK_STATUSOK(status);
            delete thr_test;
        } else {
            thread_test_fun(NULL);
        }
    } else {
        ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, 0,
                           1, 1, // no sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            cc = BREADUPDATEX(filenum,
                              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 = BREPLYX(recv_buffer,
                         count_read,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
        ferr = BFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Ejemplo n.º 10
0
void *thread_send(void *arg) {
    bool            end;
    int             ferr;
    int             inx;
    char            lwho[BUFSIZ];
    int             msgid;
    char           *name;
    RT              results;
    Util_AA<char>   send_buffer(40000);
    int             status;
    int             thrinx;

    end = (arg == NULL);
    if (end)
        thrinx = -1;
    else {
        name = SB_Thread::Sthr::self_name();
        thrinx = atoi(name);
    }
    sprintf(lwho, "client-%d", thrinx);
    for (inx = 0; inx < loop; inx++) {
        sprintf(&send_buffer, "hello, greetings from %s-%d, inx=%d",
                my_name, thrinx, inx);
        ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                          &msgid,                      // msgid
                          NULL,                        // reqctrl
                          0,                           // reqctrlsize
                          NULL,                        // replyctrl
                          0,                           // replyctrlmax
                          &send_buffer,                // reqdata
                          end ?                        // reqdatasize
                         (ushort) 0 : (ushort) 39000,
                          recv_buffer,                 // replydata
                          40000,                       // replydatamax
                          0,                           // linkertag
                          0,                           // pri
                          0,                           // xmitclass
                          XMSG_LINK_LDONEQ);           // linkopts
        assert((ferr != XZFIL_ERR_NOBUFSPACE) &&
               (ferr != XZFIL_ERR_PATHDOWN));
        ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
        if (verbose) {
            printf("%s - BREAK returned err=%d\n", lwho, ferr);
            if (ferr == XZFIL_ERR_OK)
                printf("%s - rcvd=%s\n", lwho, recv_buffer);
        }
        if (ferr != XZFIL_ERR_OK) {
            static SB_Thread::Mutex mutex;
            if (mutex.trylock() == 0) { // got lock
                restart_server();
                status = mutex.unlock();
                TEST_CHK_STATUSOK(status);
            } else
                SB_Thread::Sthr::sleep(100); // 100 ms
            inx--;
            continue;
        } else if (end)
            break;
    }
    return NULL;
}
Ejemplo n.º 11
0
int main(int argc, char *argv[]) {
    int                arg;
    char               buf[BUFSIZ];
    bool               client = false;
    int                disable;
    int                ferr;
    int                inx;
    int                len;
    int                lerr;
    int                oid;
    void              *result;
    MS_SRE             sre;
    int                status;
    SB_Thread::Thread *thr_send[MAX_THREADS];
    TAD                zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-threads",   TA_Int,  MAX_THREADS, &threads   },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    gargc = &argc;
    gargv = argv;
    arg_proc_args(zargs, false, argc, argv);
    for (arg = 1; arg < argc; arg++) {
        if (strcmp(argv[arg], "-client") == 0) // start_process
            argv[arg] = (char *) "-server"; // set to server for start-process
    }
    if (threads < 1)
        threads = 1;
    if (client)
        strcpy(who, "client");
    else
        strcpy(who, "server");
    util_test_start(client);
    ferr = msg_mon_process_startup(true);  // system messages?
    TEST_CHK_FEOK(ferr);
    if (client) {
        if (verbose)
            printf("%s - opening server\n", who);
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    }
    util_gethostname(my_name, sizeof(my_name));

    if (client) {
        disable = msg_test_assert_disable();
        for (inx = 0; inx < threads; inx++) {
            sprintf(buf, "%d", inx);
            thr_send[inx] = new SB_Thread::Thread(thread_send_fun, buf);
            thr_send[inx]->start();
        }
        for (inx = 0; inx < threads; inx++) {
            status = thr_send[inx]->join(&result);
            TEST_CHK_STATUSOK(status);
            delete thr_send[inx];
        }
        thread_send_fun(NULL);
        msg_test_assert_enable(disable);
    } else {
        inx = 0;
        for (;;) {
            do {
                lerr = XWAIT(LREQ, -1);
                TEST_CHK_WAITIGNORE(lerr);
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
            } while (lerr == XSRETYPE_NOWORK);
            inx++;
            if (inx > 4)
                util_abort_core_free(); // don't reply
            ferr = XMSG_READCTRL_(sre.sre_msgId,  // msgid
                                  NULL,           // reqctrl
                                  0);             // bytecount
            util_check("XMSG_READCTRL_", ferr);
            ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                  recv_buffer,    // reqdata
                                  40000);         // bytecount
            util_check("XMSG_READDATA_", ferr);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            len = (int) strlen(recv_buffer) + 1;
            len = len; // touch
            XMSG_REPLY_(sre.sre_msgId,             // msgid
                        NULL,                      // replyctrl
                        0,                         // replyctrlsize
                        recv_buffer,               // replydata
                        39000,                     // replydatasize
                        0,                         // errorclass
                        NULL);                     // newphandle
            if (sre.sre_reqDataSize == 0)
                break;
        }
    }
    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Ejemplo n.º 12
0
int main(int argc, char *argv[]) {
    bool       client = false;
    int        client_mon;
    int        cnid = -1;
    bool       commit_rcvd = false;
    int        cpid = -1;
    int        disable;
    bool       done = false;
    int        event_len;
    int        ferr;
    int        first;
    int        handle;
    int        inx;
    int        len;
    int        lerr;
    int        loop = 10;
    int        msgid;
    int        nid;
    bool       open_rcvd = false;
    int        orig_tag;
    TPT_DECL2 (phandle,MAX_SERVERS);
    int        pid;
    int        pinx;
    RT         results;
    int        send_len;
    MS_SRE     sre;
    int        status;
    bool       sync = false;
    bool       threaded = false;
    bool       verbose = false;
    TAD        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-quiet",     TA_Bool, TA_NOMAX,    &quiet     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-sync",      TA_Bool, TA_NOMAX,    &sync      },
      { "-threaded",  TA_Bool, TA_NOMAX,    &threaded  },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    sleep(1); // wait for client to get into msg_mon_process_info
    ferr = msg_mon_get_my_process_name(pname, sizeof(pname));
    TEST_CHK_FEOK(ferr);
    if (strcasecmp(pname, "$tm0") == 0)
         tag = TAG0;
    else if (strcasecmp(pname, "$tm1") == 0)
         tag = TAG1;
    else
         tag = TAG2;
    ferr = msg_mon_get_process_info(NULL, &snid, &spid);
    TEST_CHK_FEOK(ferr);
    if (client) {
        char serv[BUFSIZ];
        for (pinx = 0; pinx < MAX_SERVERS; pinx++) {
            sprintf(serv, "$tm%d", pinx);
            ferr = msg_mon_open_process(serv,         // name
                                        TPT_REF2(phandle,pinx),
                                        &oid[pinx]);
            TEST_CHK_FEOK(ferr);
        }
    } else {
        first = (strcasecmp(pname, "$tm0") == 0);
        disable = msg_test_assert_disable();
        ferr = msg_mon_tm_leader_set(&nid, &pid, lname);
        msg_test_assert_enable(disable);
        if (first) {
            TEST_CHK_FEOK(ferr);
        } else
            assert(ferr != XZFIL_ERR_OK);
        printf("leader is p-id=%d/%d, name=%s\n",
               nid, pid, lname);
    }

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

    if (client) {
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            send_len = (int) strlen(send_buffer) + 1;
            for (pinx = 0; pinx < MAX_SERVERS; pinx++) {
                if (verbose)
                    printf("%s: sending message, pinx=%d, inx=%d\n",
                           pname, pinx, inx);
                ferr = XMSG_LINK_(TPT_REF2(phandle,pinx),      // phandle
                                  &msgid,                      // msgid
                                  send_buffer2,                // reqctrl
                                  (ushort) (inx & 1),          // reqctrlsize
                                  recv_buffer3,                // replyctrl
                                  1,                           // replyctrlmax
                                  send_buffer,                 // reqdata
                                  (ushort) send_len,           // reqdatasize
                                  recv_buffer,                 // replydata
                                  BUFSIZ,                      // replydatamax
                                  0,                           // linkertag
                                  0,                           // pri
                                  0,                           // xmitclass
                                  0);                          // linkopts
                util_check("XMSG_LINK_", ferr);
                ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF2(phandle,pinx));
                util_check("XMSG_BREAK_", ferr);
                assert(results.u.t.ctrl_size == (uint) (inx & 1));
                assert(results.u.t.data_size > (strlen(send_buffer) + 14));
                assert(results.u.t.errm == RT_DATA_RCVD); // data
                if (!quiet)
                    printf("%s\n", recv_buffer);
            }
        }
        for (pinx = 0; pinx < MAX_SERVERS; pinx++) {
            ferr = msg_mon_close_process(TPT_REF2(phandle,pinx));
            TEST_CHK_FEOK(ferr);
        }
    } else {
        inx = 0;
        while (!done) {
            lerr = XWAIT(LREQ, -1);
            TEST_CHK_WAITIGNORE(lerr);
            for (;;) {
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
                if (lerr == XSRETYPE_NOWORK)
                    break;
                ferr = XMSG_READCTRL_(sre.sre_msgId,  // msgid
                                      recv_buffer2,   // reqctrl
                                      1);             // bytecount
                util_check("XMSG_READCTRL_", ferr);
                ferr = XMSG_READDATA_(sre.sre_msgId,  // msgid
                                      recv_buffer,    // reqdata
                                      BUFSIZ);        // bytecount
                util_check("XMSG_READDATA_", ferr);
                if (sre.sre_flags & XSRE_MON) {
                    MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer;
                    if (cnid < 0) {
                        ferr = msg_mon_get_process_info((char *) "$cli", &cnid, &cpid);
                        if (ferr != XZFIL_ERR_OK) {
                            cnid = -1;
                            cpid = -1;
                        }
                    }
                    client_mon = true;
                    Item *item_hdl;
                    Item *item_tag;
                    const char *type;
                    switch (msg->type) {
                    case MS_MsgType_Close:
                        type = "close";
                        if ((cnid == msg->u.close.nid) &&
                            (cpid == msg->u.close.pid)) {
                        } else
                            client_mon = false;
                        break;
                    case MS_MsgType_NodeDown:
                        type = "node-down";
                        break;
                    case MS_MsgType_Open:
                        type = "open";
                        if ((cnid == msg->u.open.nid) &&
                            (cpid == msg->u.open.pid))
                            open_rcvd = true;
                        else
                            client_mon = false;
                        break;
                    case MS_MsgType_ProcessDeath:
                        type = "process-death";
                        break;
                    case MS_MsgType_Shutdown:
                        type = "shutdown";
                        done = true;
                        break;
                    case MS_MsgType_TmSyncAbort:
                    case MS_MsgType_TmSyncCommit:
                        if (msg->type == MS_MsgType_TmSyncAbort)
                            type = "tmsync-abort";
                        else
                            type = "tmsync-commit";
                        nid = msg->u.tmsync.nid[0];
                        handle = msg->u.tmsync.handle[0];
                        if (msg->u.tmsync.orig_count == 0) {
                            msg->u.tmsync.orig_tag[0] = -1;
                            msg->u.tmsync.orig_handle[0] = -1;
                        }
                        orig_tag = msg->u.tmsync.orig_tag[0];
                        if (!quiet) {
                            printf("server (%s) received (%s) mon message, type=%s(%d), nid=%d\n",
                               pname,
                               client_mon ? "cli" : "dtm",
                               type,
                               msg->type,
                               nid);
                            printf("  orig_count=%d, orig_tag=%d, orig_handle=%d, count=%d, handle[0]=%d\n",
                               msg->u.tmsync.orig_count,
                               orig_tag,
                               msg->u.tmsync.orig_handle[0],
                               msg->u.tmsync.count,
                               handle);
                        }
                        if (nid == snid) {
                            if (!quiet)
                                printf("server (%s) commit handle=%d, orig-count=%d\n",
                                       pname, handle, msg->u.tmsync.orig_count);
                            for (int inx2 = 0;
                                 inx2 < msg->u.tmsync.count;
                                 inx2++) {
                                int ltag = msg->u.tmsync.orig_tag[inx2];
                                int lhandle = msg->u.tmsync.orig_handle[inx2];
                                if (!quiet)
                                    printf("server (%s) commit orig-tag/handle=%d/%d\n",
                                           pname, ltag, lhandle);
                                item_tag = (Item *) tag_issue_map.remove(ltag);
                                assert(item_tag != NULL);
                                delete item_tag;
                                item_hdl = (Item *) handle_issue_map.remove(lhandle);
                                assert(item_hdl != NULL);
                                delete item_hdl;
                            }
                        } else {
                            assert(msg->u.tmsync.orig_count == 0);
                        }
                        commit_rcvd = true;
                        break;
                    default:
                        type = "<unknown>";
                    }
                    if (!quiet)
                        printf("server (%s) received (%s) mon message, type=%s(%d)\n",
                               pname, client_mon ? "cli" : "dtm", type, msg->type);
                    len = 0;
                } else {
                    inx++;
                    if (verbose)
                        printf("%s: received non-mon message, inx=%d\n",
                               pname, inx);
                    if (!sync)
                        assert(sync_rcvd);
                    assert(commit_rcvd);
                    assert(open_rcvd);
                    strcat(recv_buffer, "- reply from ");
                    strcat(recv_buffer, my_name);
                    strcat(recv_buffer, " - ");
                    strcat(recv_buffer, pname);
                    len = (int) strlen(recv_buffer) + 1;
                }
                XMSG_REPLY_(sre.sre_msgId,       // msgid
                            recv_buffer2,        // replyctrl
                            sre.sre_reqCtrlSize, // replyctrlsize
                            recv_buffer,         // replydata
                            (ushort) len,        // replydatasize
                            0,                   // errorclass
                            NULL);               // newphandle
            }
        }
        assert(inx == loop);
        assert(tag_issue_map.empty());
        assert(handle_issue_map.empty());
        // need to wait for shutdown to be started
        ferr = msg_mon_event_wait(2, &event_len, event_data);
        util_check("msg_mon_event_wait", ferr);
        if (sync && threaded) {
            sync_thr_shutdown = true;
            for (int thr = 0; thr < MAX_THR; thr++) {
                void *larg;
                status = sync_thr[thr]->join(&larg);
                TEST_CHK_STATUSOK(status);
            }
        }
    }

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Ejemplo n.º 13
0
int main(int argc, char *argv[]) {
    bool               client = false;
    int                ferr;
    int                inx;
    int                len;
    int                lerr;
    int                oid;
    char               recv_buffer[BUFSIZ];
    short              recv_buffer2[BUFSIZ];
    MS_SRE             sre;
    int                status;
    SB_Thread::Thread *thr[MAX_THR];
    TAD                zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    if (client)
        printf("threads=%d, msgs-per-thread=%d, msgs=%d\n",
               MAX_THR, MAX_MSGS_PER_THR, MAX_MSGS);
    ferr = msg_mon_process_startup(!client); // system messages
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",      //  name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
    }
    util_gethostname(my_name, sizeof(my_name));

    if (client) {
        for (inx = 0; inx < MAX_THR; inx++) {
            char name[10];
            sprintf(name, "c%d", inx);
            thr[inx] = new SB_Thread::Thread(client_thr, name);
        }
        for (inx = 0; inx < MAX_THR; inx++)
            thr[inx]->start();
        for (inx = MAX_THR - 1; inx >= 0; inx--) {
            void *res;
            status = thr[inx]->join(&res);
            TEST_CHK_STATUSOK(status);
            printf("joined with client %d\n", inx);
        }
        for (inx = 0; inx < MAX_THR; inx++)
            delete thr[inx];
    } else {
        for (inx = 0; inx < MAX_MSGS;) {
            lerr = XWAIT(LREQ, -1);
            TEST_CHK_WAITIGNORE(lerr);
            do {
                lerr = XMSG_LISTEN_((short *) &sre, // sre
                                    0,              // listenopts
                                    0);             // listenertag
                if (lerr == XSRETYPE_IREQ) {
                    inx++;
                    ferr = XMSG_READCTRL_(sre.sre_msgId,    // msgid
                                          recv_buffer2,     // reqctrl
                                          1);               // bytecount
                    util_check("XMSG_READCTRL_", ferr);
                    ferr = XMSG_READDATA_(sre.sre_msgId,    // msgid
                                          recv_buffer,      // reqdata
                                          BUFSIZ);          // bytecount
                    util_check("XMSG_READDATA_", ferr);
                    strcat(recv_buffer, "- reply from ");
                    strcat(recv_buffer, my_name);
                    len = (int) strlen(recv_buffer) + 1;
                    XMSG_REPLY_(sre.sre_msgId,       // msgid
                                recv_buffer2,        // replyctrl
                                sre.sre_reqCtrlSize, // replyctrlsize
                                recv_buffer,         // replydata
                                (ushort) len,        // replydatasize
                                0,                   // errorclass
                                NULL);               // newphandle
                } else {
                    assert(lerr == XSRETYPE_NOWORK);
                }
            } while (lerr != XSRETYPE_NOWORK);
        }
    }

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    }
    printf("%s shutting down\n", client ? "client" : "server");
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Ejemplo n.º 14
0
int main(int argc, char *argv[]) {
    bool                client = false;
    int                 ferr;
    int                 inxl;
    int                 inxo;
    int                 inxs;
    int                 maxs = 2;
    int                 msgid[MAX_OUT];
    bool                mq = false;
    int                 oid;
    TPT_DECL           (phandle);
    void               *res;
    RT                  results;
    const char         *serv = "$srv";
    int                 status;
    TAD                 zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxout",    TA_Int,  MAX_OUT,     &maxout    },
      { "-maxs",      TA_Int,  MAX_THR_S,   &maxs      },
      { "-mq",        TA_Bool, TA_NOMAX,    &mq        },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    if (client) {
        ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETSENDLIMIT,
                                     XMAX_SETTABLE_SENDLIMIT);
        assert(ferr == XZFIL_ERR_OK);
        atomic_set(&msg_count, 0);
        for (inxl = 0; inxl < loop; inxl++) {
            ferr = msg_mon_open_process((char *) serv,       // name
                                        TPT_REF(phandle),
                                        &oid);
            TEST_CHK_FEOK(ferr);
            count = 0;
            for (inxo = 0; inxo < 2; inxo++) {
                ferr = BMSG_LINK_(TPT_REF(phandle),        // phandle
                                  &msgid[inxo],            // msgid
                                  NULL,                    // reqctrl
                                  0,                       // reqctrlsize
                                  send_buffer2[inxo],      // replyctrl
                                  24,                      // replyctrlmax
                                  send_buffer[inxo],       // reqdata
                                  0,                       // reqdatasize
                                  recv_buffer[inxo],       // replydata
                                  BUFSIZ,                  // replydatamax
                                  0,                       // linkertag
                                  0,                       // pri
                                  0,                       // xmitclass
                                  0);                      // linkopts
                util_check("XMSG_LINK_", ferr);
                atomic_inc(&msg_count);
            }
            ferr = XMSG_ABANDON_(msgid[0]);
            util_check("XMSG_ABANDON_", ferr);
            ferr = BMSG_LINK_(TPT_REF(phandle),        // phandle
                              &msgid[inxo],            // msgid
                              NULL,                    // reqctrl
                              0,                       // reqctrlsize
                              send_buffer2[inxo],      // replyctrl
                              24,                      // replyctrlmax
                              send_buffer[inxo],       // reqdata
                              0,                       // reqdatasize
                              recv_buffer[inxo],       // replydata
                              BUFSIZ,                  // replydatamax
                              0,                       // linkertag
                              0,                       // pri
                              0,                       // xmitclass
                              0);                      // linkopts
            util_check("XMSG_LINK_", ferr);
            atomic_inc(&msg_count);
            ferr = BMSG_BREAK_(msgid[inxo],
                               results.u.s,
                               TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
            ferr = XMSG_ABANDON_(msgid[1]);
            util_check("XMSG_ABANDON_", ferr);
            if (maxout < 4)
                maxout = 4;
            for (inxo = 3; inxo < maxout; inxo++) {
                ferr = BMSG_LINK_(TPT_REF(phandle),        // phandle
                                  &msgid[inxo],            // msgid
                                  NULL,                    // reqctrl
                                  0,                       // reqctrlsize
                                  send_buffer2[inxo],      // replyctrl
                                  60,                      // replyctrlmax
                                  send_buffer[inxo],       // reqdata
                                  120,                     // reqdatasize
                                  recv_buffer[inxo],       // replydata
                                  BUFSIZ,                  // replydatamax
                                  0,                       // linkertag
                                  0,                       // pri
                                  0,                       // xmitclass
                                  0);                      // linkopts
                util_check("XMSG_LINK_", ferr);
                atomic_inc(&msg_count);
                if (verbose)
                    printf("client(%s): msg-count=%d\n",
                           my_name, atomic_read(&msg_count));
                count++;
                ferr = BMSG_BREAK_(msgid[inxo],
                                   results.u.s,
                                   TPT_REF(phandle));
                util_check("XMSG_BREAK_", ferr);
            }
            if (mq) {
                if ((inxl % 100) == 0)
                    printf("client(%s): count=%d\n", my_name, inxl);
            }
        }
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETRECVLIMIT,
                                     XMAX_SETTABLE_RECVLIMIT);
        assert(ferr == XZFIL_ERR_OK);
        closes = 0;
        maxmsg = loop * maxout;
        atomic_set(&msg_count, 0);
        msg_mon_enable_mon_messages(true);
        for (inxs = 0; inxs < maxs; inxs++) {
            char lname[10];
            sprintf(lname, "s%d", inxs);
            thrs[inxs] = new MyThread(server_thr, lname, inxs);
        }
        for (inxs = 0; inxs < maxs; inxs++)
            thrs[inxs]->start();
        for (inxs = 0; inxs < maxs; inxs++) {
            status = thrs[inxs]->join(&res);
            TEST_CHK_STATUSOK(status);
            printf("joined with server %d\n", inxs);
        }
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Ejemplo n.º 15
0
int main(int argc, char *argv[]) {
    bool       client = false;
    int        ferr;
    int        inx;
    int        loop = 10;
    int        msgid;
    int        oid;
    TPT_DECL  (phandle);
    char       recv_buffer[40000];
    RT         results;
    char       send_buffer[40000];
    int        status;
    TAD        zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-delay",     TA_Bool, TA_NOMAX,    &delay     },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxs",      TA_Int,  TA_NOMAX,    &maxs      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    util_gethostname(my_name, sizeof(my_name));

    if (client) {
        ferr = msg_mon_open_process((char *) "$srv",      // name
                                    TPT_REF(phandle),
                                    &oid);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              NULL,                        // reqctrl
                              0,                           // reqctrlsize
                              NULL,                        // replyctrl
                              0,                           // replyctrlmax
                              send_buffer,                 // reqdata
                              39000,                       // reqdatasize
                              recv_buffer,                 // replydata
                              40000,                       // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
            assert(results.u.t.ctrl_size == 0);
            assert(results.u.t.errm == RT_DATA_RCVD); // data
            printf("%s\n", recv_buffer);
        }
        for (inx = 0; inx < maxs; inx++) {
            ferr = XMSG_LINK_(TPT_REF(phandle),            // phandle
                              &msgid,                      // msgid
                              NULL,                        // reqctrl
                              0,                           // reqctrlsize
                              NULL,                        // replyctrl
                              0,                           // replyctrlmax
                              send_buffer,                 // reqdata
                              0,                           // reqdatasize
                              recv_buffer,                 // replydata
                              0,                           // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              0);                          // linkopts
            util_check("XMSG_LINK_", ferr);
            ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle));
            util_check("XMSG_BREAK_", ferr);
            printf("fin %d\n", inx);
        }
    } else {
        msg_mon_enable_mon_messages(true);
        for (inx = 0; inx < maxs; inx++) {
            char name[10];
            sprintf(name, "s%d", inx);
            thrs[inx] = new Server_Thread(server_thr, name, inx);
        }
        for (inx = 0; inx < maxs; inx++) {
            thrs[inx]->start();
            SB_Thread::Sthr::yield();
        }
        for (inx = 0; inx < maxs; inx++) {
            void *res;
            status = thrs[inx]->join(&res);
            TEST_CHK_STATUSOK(status);
            printf("joined with server %d\n", inx);
        }
    }
    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = msg_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Ejemplo n.º 16
0
int main(int argc, char *argv[]) {
    bool          chook = false;
    int           client = false;
    int           dinx;
    int           disable;
    int           ferr;
    int           inx;
    char          lname[10];
    bool          mq = false;
    int           oid;
    void         *res;
    bool          rnd = false;
    int           sleept;
    int           snid;
    int           spid;
    int           status;
    TAD           zargs[] =  {
        { "-chook",     TA_Bool, TA_NOMAX,    &chook      },
        { "-client",    TA_Bool, TA_NOMAX,    &client     },
        { "-dloop",     TA_Int,  MAX_OUT,     &gdloop     },
        { "-dsize",     TA_Int,  TA_NOMAX,    &gdsize     },
        { "-ksleep",    TA_Int,  TA_NOMAX,    &gksleep    },
        { "-loop",      TA_Int,  TA_NOMAX,    &gloop      },
        { "-maxc",      TA_Int,  MAX_THR,     &gmaxc      },
        { "-maxs",      TA_Int,  MAX_THR,     &gmaxs      },
        { "-mq",        TA_Bool, TA_NOMAX,    &mq         },
        { "-nodecycle", TA_Bool, TA_NOMAX,    &gnodecycle },
        { "-rnd",       TA_Bool, TA_NOMAX,    &rnd        },
        { "-server",    TA_Ign,  TA_NOMAX,    NULL        },
        { "-v",         TA_Bool, TA_NOMAX,    &gverbose   },
        { "-vpp",       TA_Bool, TA_NOMAX,    &gverbosepp },
        { "",           TA_End,  TA_NOMAX,    NULL        }
    };

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

    if (client) {
        sleep(1);
        ferr = msg_mon_close_process(TPT_REF(gphandle));
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Ejemplo n.º 17
0
int main(int argc, char *argv[]) {
    _xcc_status         cc;
    bool                client = false;
    int                 count_read;
    int                 count_written;
    int                 ferr;
    short               filenum;
    int                 inx;
    void               *result;
    int                 status;
    SB_Thread::Thread  *thr_cli;
    TAD                 zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-sname",     TA_Str,  TA_NOMAX,    &sname     },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    if (client) {
        thr_cli = new SB_Thread::Thread(thread_cli_fun, "cli");
        thr_cli->start();
        status = thr_cli->join(&result);
        TEST_CHK_STATUSOK(status);
        delete thr_cli;
    } else {
        ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, 0,
                           1, 0, // sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < (loop + 4); inx++) {
            cc = BREADUPDATEX(filenum,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            if (_xstatus_ne(cc)) {
                count_read = 0;
            } else {
                strcat(recv_buffer, "- reply from ");
                strcat(recv_buffer, my_name);
                count_read = (int) (strlen(recv_buffer) + 1); // cast
            }
            cc = BREPLYX(recv_buffer,
                         count_read,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
        ferr = BFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}