Beispiel #1
0
int main(int argc, char *argv[]) {
    SB_Array<int>  array(MAX_OUT);
    int            client = false;
    int            disable = 0;
    int            ferr;
    int            inx;
    int            lerr;
    int            linker = false;
    int            listener = false;
    int            oid;
    int            req_ctrl_size;
    int            req_data_size;
    int            rep_ctrl_size;
    int            rep_data_size;
    RT             results;
    TPT_DECL      (phandle);
    TAD            zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-linker",    TA_Bool, TA_NOMAX,    &linker    },
      { "-listener",  TA_Bool, TA_NOMAX,    &listener  },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

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

    if (client) {
        ferr = msg_mon_close_process(TPT_REF(phandle));
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    if (linker)
        util_test_finish(!client);
    else
        util_test_finish(client);
    return 0;
}
int main(int argc, char *argv[]) {
    bool            client = false;
    int             ferr;
    int             inx;
    int             len;
    int             lerr;
    int             loop = 10;
    int             msgid;
    TPT_DECL2      (phandle,MAX_SERVERS);
    bool            rand = false;
    RT              results;
    int             send_len;
    MS_SRE          sre;
    MS_SRE_LDONE    sre_ldone;
    int             srv;
    int             srv2;
    TAD             zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-rand",      TA_Bool, TA_NOMAX,    &rand      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    msfs_util_init(&argc, &argv, msg_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    util_test_start(client);
    ferr = msg_mon_process_startup(!client); // system messages
    TEST_CHK_FEOK(ferr);
    if (client) {
        for (srv = 0; srv < MAX_SERVERS; srv++) {
            sprintf(name, "$srv%d", srv);
            ferr = msg_mon_open_process(name,
                                        TPT_REF2(phandle,srv),
                                        &oid[srv]);
            TEST_CHK_FEOK(ferr);
        }
    }
    util_gethostname(my_name, sizeof(my_name));

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

    if (client) {
        for (srv = 0; srv < MAX_SERVERS; srv++) {
            ferr = msg_mon_close_process(TPT_REF2(phandle,srv));
            TEST_CHK_FEOK(ferr);
        }
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Beispiel #3
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;
}
int main(int argc, char *argv[]) {
    void                     *buf;
    _xcc_status               cc;
    bool                      client = false;
    unsigned short            count_written;
    unsigned short            count_xferred;
    int                       disable;
    bool                      done;
    int                       ferr;
    short                     filenum1;
    short                     filenum2;
    int                       inx;
    int                       loop = 10;
    char                      my_name[BUFSIZ];
    char                      my_pname[BUFSIZ];
    int                       out;
    MS_Mon_Process_Info_Type  proc_info;
    char                      recv_buffer[BUFSIZ];
    char                      send_buffer[BUFSIZ];
    int                       send_len;
    SB_Tag_Type               tag;
    int                       timeout = -1;
    short                     tfilenum;
    TAD                       zargs[] = {
        { "-client",    TA_Bool, TA_NOMAX,    &client    },
        { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
        { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
        { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
        { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    if (client) {
        ferr = XFILE_OPEN_(srv1, (short) strlen(srv1), &filenum1,
                           0, 0, MAX_OUT, 0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        ferr = msg_mon_get_process_info_detail(srv1, &proc_info);
        TEST_CHK_FEOK(ferr);
        ferr = XFILE_OPEN_(srv2, (short) strlen(srv2), &filenum2,
                           0, 0, MAX_OUT, 0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            send_len = (int) strlen(send_buffer) + 1; // cast
            if (verbose)
                printf("client doing writereadx's to fn1\n");
            for (out = 0; out < MAX_OUT; out++) {
                cc = XWRITEREADX(filenum1,
                                 send_buffer,
                                 (ushort) send_len,
                                 BUFSIZ,
                                 &count_written,
                                 0);
                TEST_CHK_CCEQ(cc);
            }
            if (verbose)
                printf("client doing writereadx's to fn2\n");
            for (out = 0; out < MAX_OUT; out++) {
                cc = XWRITEREADX(filenum2,
                                 send_buffer,
                                 (ushort) send_len,
                                 BUFSIZ,
                                 &count_written,
                                 0);
                TEST_CHK_CCEQ(cc);
            }
            if (verbose)
                printf("client killing srv1 (pid=%d), closing fn1\n",
                       proc_info.os_pid);
            kill(proc_info.os_pid, SIGTERM);
            disable = msg_test_assert_disable();
            ferr = XFILE_CLOSE_(filenum1);
            TEST_CHK_FEIGNORE(ferr);
            msg_test_assert_enable(disable);
            if (verbose)
                printf("client doing awaitios on fn1\n");
            for (out = 0; out < MAX_OUT; out++) {
                tfilenum = -2;
                disable = msg_test_assert_disable();
                cc = XAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag,
                               timeout,
                               NULL);
                msg_test_assert_enable(disable);
                // can't check cc because of -2
                if (_xstatus_eq(cc))
                    printf("%s\n", send_buffer);
            }
            if (verbose)
                printf("client restarting srv1, reopening fn1\n");
            restart_server(argc, argv);
            ferr = XFILE_OPEN_(srv1, (short) strlen(srv1), &filenum1,
                               0, 0, MAX_OUT, 0, 0, 0, 0, NULL);
            TEST_CHK_FEOK(ferr);
            ferr = msg_mon_get_process_info_detail(srv1, &proc_info);
        }
        if (verbose)
            printf("client sending stop to srv1\n");
        strcpy(send_buffer, "stop");
        send_len = (int) strlen(send_buffer) + 1; // cast
        cc = XWRITEREADX(filenum1,
                         send_buffer,
                         (ushort) send_len,
                         BUFSIZ,
                         &count_written,
                         0);
        TEST_CHK_CCEQ(cc);
        tfilenum = filenum1;
        cc = XAWAITIOX(&tfilenum,
                       &buf,
                       &count_xferred,
                       &tag,
                       timeout,
                       NULL);
        TEST_CHK_CCEQ(cc);
        strcpy(send_buffer, "stop");
        if (verbose)
            printf("client sending stop to srv2\n");
        cc = XWRITEREADX(filenum2,
                         send_buffer,
                         (ushort) send_len,
                         BUFSIZ,
                         &count_written,
                         0);
        TEST_CHK_CCEQ(cc);
        tfilenum = filenum2;
        cc = XAWAITIOX(&tfilenum,
                       &buf,
                       &count_xferred,
                       &tag,
                       timeout,
                       NULL);
        TEST_CHK_CCEQ(cc);
        if (verbose)
            printf("client finishing\n");
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum1,
                           0, 0, 0,
                           1, 1, // no sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        do {
            if (verbose)
                printf("server-%s: doing readupdate\n", my_pname);
            cc = XREADUPDATEX(filenum1,
                              recv_buffer,
                              BUFSIZ,
                              NULL,
                              0);
            if (verbose)
                printf("server-%s: readupdate done cc=%d\n", my_pname, cc);
            TEST_CHK_CCEQ(cc);
            util_time_sleep_ms(10);
            done = (strcmp(recv_buffer, "stop") == 0);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            if (verbose)
                printf("server-%s: doing reply, done=%d\n", my_pname, done);
            cc = XREPLYX(NULL,
                         0,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
            assert(count_written == 0);
        } while (!done);
        ferr = XFILE_CLOSE_(filenum1, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}