Example #1
0
int main(int argc, char *argv[]) {
    int              arg;
    bool             attach = false;
    _xcc_status      cc;
    bool             chook = false;
    bool             client = false;
    unsigned short   count_read;
    unsigned short   count_written;
    int              ferr;
    short            filenum;
    int              inx;
    int              loop = 10;
    char             my_name[BUFSIZ];
    char             prog[MS_MON_MAX_PROCESS_PATH];
    char             recv_buffer[BUFSIZ];
    char             ret_name[MS_MON_MAX_PROCESS_NAME];
    char             send_buffer[BUFSIZ];
    const char      *server_name = "$SRV";
    int              server_nid = -1;
    TPT_DECL        (server_phandle);
    int              server_pid;
    bool             shook = false;
    TAD              zargs[] = {
      { "-attach",    TA_Bool, TA_NOMAX,    &attach    },
      { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-shook",     TA_Bool, TA_NOMAX,    &shook     },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

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

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

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

        ferr = XFILE_OPEN_((char *) server_name, (short) strlen(server_name), &filenum,
                           0, 0, 0, 0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            cc = XWRITEREADX(filenum,
                             send_buffer,
                             (short) (strlen(send_buffer) + 1),
                             BUFSIZ,
                             &count_read,
                             0);
            TEST_CHK_CCEQ(cc);
            printf("%s\n", send_buffer);
        }
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, 0,
                           1, 1, // no sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            cc = XREADUPDATEX(filenum,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            TEST_CHK_CCEQ(cc);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            count_read = (short) (strlen(recv_buffer) + 1);
            cc = XREPLYX(recv_buffer,
                         count_read,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Example #2
0
int main(int argc, char *argv[]) {
    void                *buf;
    _xcc_status          cc;
    unsigned short       count_read;
    unsigned short       count_written;
    unsigned short       count_xferred;
    int                  ferr;
    short                filenum;
    short                lasterr;
    int                  inx;
    int                  loop = 10;
    char                 my_name[BUFSIZ];
    bool                 nowait = false;
    int                  nid;
    char                *p;
    int                  pid;
    char                 recv_buffer[BUFSIZ];
    char                 send_buffer[BUFSIZ];
    SB_Tag_Type          tag;
    short                tfilenum;
    int                  tm_seq;
    int                  timeout = -1;
    MS_Mon_Transid_Type  transid;
    TAD                  zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-nowait",    TA_Bool, TA_NOMAX,    &nowait    },
      { "-print",     TA_Bool, TA_NOMAX,    &print     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

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

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

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

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

    if (client) {
        ferr = XFILE_OPEN_((char *) "$srv", 4, &filenum,
                           0, 0, 0, 0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        short filenumx;
        ferr = XFILE_OPEN_((char *) "$srv", 4, &filenumx,
                           0, 0, 0, 0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            cc = XWRITEREADX(filenum,
                             send_buffer,
                             (short) (strlen(send_buffer) + 1),
                             BUFSIZ,
                             &count_read,
                             0);
            TEST_CHK_CCEQ(cc);
            printf("%s\n", send_buffer);
        }
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, 0,
                           1, 0, // sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        // pick up opens
        for (inx = 0; inx < 2; inx++) {
            cc = XREADUPDATEX(filenum,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            TEST_CHK_CCNE(cc);
            getri(&ri);
            assert(recv_buffer[0] == XZSYS_VAL_SMSG_OPEN);
            assert(ri.io_type == 0);
            filenuma[inx] = ri.file_number;
            cc = XREPLYX(recv_buffer,
                         0,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
        for (inx = 0; inx < loop; inx++) {
            cc = XREADUPDATEX(filenum,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            TEST_CHK_CCEQ(cc);
            getri(&ri);
            assert(ri.io_type == XZSYS_VAL_RCV_IOTYPE_WRITEREAD);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            count_read = (short) (strlen(recv_buffer) + 1);
            cc = XREPLYX(recv_buffer,
                         count_read,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
        // pick up close
        for (inx = 0; inx < 2; inx++) {
            cc = XREADUPDATEX(filenum,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            TEST_CHK_CCNE(cc);
            getri(&ri);
            assert(recv_buffer[0] == XZSYS_VAL_SMSG_CLOSE);
            assert(ri.io_type == 0);
            if (ri.file_number == filenuma[0])
                filenuma[0] = -1;
            else if (ri.file_number == filenuma[1])
                filenuma[1] = -1;
            else
                assert(false); // needs to be matching
            cc = XREPLYX(recv_buffer,
                         0,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Example #5
0
int main(int argc, char *argv[]) {
    void           *buf;
    _xcc_status     cc;
    bool            client = false;
    unsigned short  count_read;
    unsigned short  count_written;
    unsigned short  count_xferred;
    int             ferr;
    short           filenum;
    int             inx;
    short           lasterr;
    int             loop = 10;
    char            my_name[BUFSIZ];
    bool            nowait = true;
    char            recv_buffer[BUFSIZ];
    char            send_buffer[BUFSIZ];
    SB_Tag_Type     tag;
    short           tfilenum;
    int             timeout;
    int             timeout_count;
    TAD             zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    if (client) {
        timeout_count = 0;
        ferr = XFILE_OPEN_((char *) "$srv", 4, &filenum,
                           0, 0, nowait ? (short) 1 : (short) 0,
                           0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            cc = XWRITEREADX(filenum,
                             send_buffer,
                             (short) (strlen(send_buffer) + 1),
                             BUFSIZ,
                             &count_read,
                             0);
            if (nowait) {
                TEST_CHK_CCEQ(cc);
                tfilenum = filenum;
                timeout = 1;
                cc = XAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag,
                               timeout,
                               NULL);
                if (_xstatus_ne(cc)) {
                    timeout_count++;
                    TEST_CHK_CCNE(cc);
                    ferr = XFILE_GETINFO_(filenum,
                                          &lasterr,
                                          NULL,
                                          0,
                                          NULL,
                                          NULL,
                                          NULL);
                    assert(lasterr == XZFIL_ERR_TIMEDOUT);
                    tfilenum = filenum;
                    timeout = 200;
                    cc = XAWAITIOX(&tfilenum,
                                   &buf,
                                   &count_xferred,
                                   &tag,
                                   timeout,
                                   NULL);
                    TEST_CHK_CCEQ(cc);
                }
            } else {
                TEST_CHK_CCNE(cc);
                ferr = XFILE_GETINFO_(-1, &lasterr, NULL, 0, NULL, NULL, NULL);
                TEST_CHK_FEOK(ferr);
                assert(lasterr == XZFIL_ERR_TIMEDOUT);
            }
            printf("%s\n", send_buffer);
        }
        assert(timeout_count);
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, 0,
                           1, 1, // no sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            cc = XREADUPDATEX(filenum,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            SB_Thread::Sthr::sleep(30); // cause timeout
            TEST_CHK_CCEQ(cc);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            count_read = (short) (strlen(recv_buffer) + 1);
            cc = XREPLYX(recv_buffer,
                         count_read,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
int main(int argc, char *argv[]) {
    _xcc_status     cc;
    bool            client = false;
    unsigned short  count_read;
    int             count_read_b;
    unsigned short  count_written;
    TCPU_DECL      (cpu);
    int             ferr;
    short           filenum;
    int             inx;
    int             loop = 10;
    TPT_DECL       (mphandle);
    char           *mphandlec = (char *) &mphandle;
    TPT_DECL_INT   (mphandlei);
    int             nid;
    char            nodename[20];
    short           nodename_length;
    int             nodenumber;
    int             pid;
    TPIN_DECL      (pin);
    char            procname[40];
    short           procname_length;
    SB_Int64_Type   sequence_number;
    const char     *sname = "$srv";
    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);
    ferr = msg_mon_get_process_info(my_name, &nid, &pid);
    TEST_CHK_FEOK(ferr);

    ferr = XPROCESSHANDLE_GETMINE_(TPT_REF(mphandle));
    util_check("XPROCESSHANDLE_GETMINE_", ferr);
    TPT_COPY_INT(mphandlei, mphandle);
    assert((mphandlei[0] & 0xf0) == 0x20); // named
    assert(strncmp(my_name, &mphandlec[4], 32) == 0);
    printf("phandle=%x.%x.%x.%x.%x, pname=%s\n",
           mphandlei[0], mphandlei[1], mphandlei[2], mphandlei[3], mphandlei[4],
           my_name);
    ferr = XPROCESSHANDLE_DECOMPOSE_(TPT_REF(mphandle),
                                     &cpu,
                                     &pin,
                                     &nodenumber,
                                     nodename,
                                     sizeof(nodename),
                                     &nodename_length,
                                     procname,
                                     sizeof(procname),
                                     &procname_length,
                                     &sequence_number);
    assert(cpu == nid);
    assert(pin == pid);
    assert(nodenumber == 0);
    assert(nodename_length == 4);
    nodename[nodename_length] = 0;
    assert(strcmp(nodename, "\\NSK") == 0);
    procname[procname_length] = 0;
    assert(strcmp(procname, my_name) == 0);
#ifdef SQ_PHANDLE_VERIFIER
    assert(sequence_number != 0);
#else
    assert(sequence_number == 0);
#endif

    if (client) {
        ferr = XFILE_OPEN_((char *) sname, 4, &filenum,
                           0, 0, 0, 0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            if ((inx & 1) == 0)
                cc = XWRITEREADX2(filenum,
                                  send_buffer,
                                  (unsigned short) (strlen(send_buffer) + 1), // cast
                                  recv_buffer,
                                  BUFSIZ,
                                  &count_read,
                                  0);
            else
                cc = BWRITEREADX2(filenum,
                                  send_buffer,
                                  (unsigned short) (strlen(send_buffer) + 1), // cast
                                  recv_buffer,
                                  BUFSIZ,
                                  &count_read_b,
                                  0);
            TEST_CHK_CCEQ(cc);
            printf("%s\n", recv_buffer);
        }
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, 0,
                           1, 1, // no sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            cc = XREADUPDATEX(filenum,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            TEST_CHK_CCEQ(cc);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            count_read = (unsigned short) (strlen(recv_buffer) + 1); // cast
            cc = XREPLYX(recv_buffer,
                         count_read,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Example #7
0
int main(int argc, char *argv[]) {
    _xcc_status         cc;
    bool                client = false;
    unsigned short      count_read;
    unsigned short      count_written;
    int                 ferr;
    short               filenumr;
    short               filenums[MAXSRV];
    int                 inxl;
    int                 inxs;
    int                 loop = 10;
    int                 maxsp = 2;
    bool                verbose = false;
    xzsys_ddl_smsg_def *sys_msg = (xzsys_ddl_smsg_def *) recv_buffer;
    struct timeval      t_elapsed_close;
    struct timeval      t_elapsed_closem1;
    struct timeval      t_elapsed_open;
    struct timeval      t_elapsed_openm1;
    struct timeval      t_start_close;
    struct timeval      t_start_closem1;
    struct timeval      t_start_open;
    struct timeval      t_start_openm1;
    struct timeval      t_stop_close;
    struct timeval      t_stop_closem1;
    struct timeval      t_stop_open;
    struct timeval      t_stop_openm1;
    TAD                 zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxsp",     TA_Int,  MAXSRV,      &maxsp     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    if (client) {
        util_time_timer_start(&t_start_open);
        for (inxs = 0; inxs < maxsp; inxs++) {
            ferr = XFILE_OPEN_((char *) "$srv", 4, &filenums[inxs],
                               0, 0, 0, 0, 0, 0, 0, NULL);
            TEST_CHK_FEOK(ferr);
            if (inxs == 0)
                util_time_timer_start(&t_start_openm1);
        }
        util_time_timer_stop(&t_stop_open);
        util_time_timer_stop(&t_stop_openm1);
        for (inxs = 0; inxs < maxsp; inxs++) {
            for (inxl = 0; inxl < loop; inxl++) {
                sprintf(send_buffer, "hello, greetings %d from %s, inx=%d",
                        inxs, my_name, inxl);
                cc = XWRITEREADX(filenums[inxs],
                                 send_buffer,
                                 (unsigned short) (strlen(send_buffer) + 1), // cast
                                 BUFSIZ,
                                 &count_read,
                                 0);
                TEST_CHK_CCEQ(cc);
                printf("%s\n", send_buffer);
            }
        }
        util_time_timer_start(&t_start_close);
        util_time_timer_start(&t_start_closem1);
        for (inxs = 0; inxs < maxsp; inxs++) {
            if (inxs == (maxsp - 1))
                util_time_timer_stop(&t_stop_closem1);
            ferr = XFILE_CLOSE_(filenums[inxs], 0);
            TEST_CHK_FEOK(ferr);
        }
        util_time_timer_stop(&t_stop_close);
        util_time_elapsed(&t_start_open, &t_stop_open, &t_elapsed_open);
        util_time_elapsed(&t_start_openm1, &t_stop_openm1, &t_elapsed_openm1);
        util_time_elapsed(&t_start_close, &t_stop_close, &t_elapsed_close);
        util_time_elapsed(&t_start_closem1, &t_stop_closem1, &t_elapsed_closem1);
        print_elapsed(" (open)", &t_elapsed_open);
        print_elapsed(" (open-1st)", &t_elapsed_openm1);
        print_elapsed(" (close)", &t_elapsed_close);
        print_elapsed(" (close-lst)", &t_elapsed_closem1);
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr,
                           0, 0, 0,
                           1, 0, // sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);

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

        // process closes
        for (inxs = 0; inxs < maxsp; inxs++) {
            cc = XREADUPDATEX(filenumr,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            TEST_CHK_CCNE(cc);
            if (verbose) {
                int mt = sys_msg->u_z_msg.z_msgnumber[0];
                printf("inx=%d, type=%d\n", inxs, mt);
            }
            cc = XREPLYX(recv_buffer,
                         0,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
        ferr = XFILE_CLOSE_(filenumr, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Example #8
0
int main(int argc, char *argv[]) {
    int             arg;
    _xcc_status     cc;
    bool            client = false;
    unsigned short  count_read;
    unsigned short  count_written;
    bool            death = false;
#ifdef SQ_PHANDLE_VERIFIER
    int             disable;
#endif
    int             ferr;
    short           filenumr;
    short           filenums;
#ifdef SQ_PHANDLE_VERIFIER
    short           filenums2;
#endif
    int             inxl;
    short           len;
#ifdef SQ_PHANDLE_VERIFIER
    short           len2;
#endif
    int             loop = 10;
    int             nid;
    int             pid;
    char            prog[MS_MON_MAX_PROCESS_PATH];
    char            retname[BUFSIZ];
    char            sname[10];
    char            sname_seq1[40];
#ifdef SQ_PHANDLE_VERIFIER
    char            sname_seq2[40];
#endif
    int             status;
    bool            verbose = false;
    TAD             zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-death",     TA_Bool, TA_NOMAX,    &death     },
      { "-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);
    for (arg = 1; arg < argc; arg++) {
        if (strcmp(argv[arg], "-client") == 0) // start_process
            argv[arg] = (char *) "-server";
    }
    util_test_start(client);
    if (death)
        ferr = file_mon_process_startup(true);     // system messages?
    else
        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) {
        if (death) {
            ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr,
                               0, 0, 0,
                               1, 0, // sys msg
                               0, 0, NULL);
            TEST_CHK_FEOK(ferr);
        }
        strcpy(sname, "$srv");
        if (verbose)
            printf("client starting server %s\n", sname);
        sprintf(prog, "%s/%s", getenv("PWD"), argv[0]);
        nid = -1;
        ferr =
          msg_mon_start_process_nowait_cb(cb,                    // callback
                                          prog,                  // prog
                                          sname,                 // name
                                          retname,               // ret-name
                                          argc,                  // argc
                                          argv,                  // argv
                                          MS_ProcessType_Generic,// ptype
                                          0,                     // priority
                                          false,                 // debug
                                          false,                 // backup
                                          0,                     // tag
                                          &nid,                  // nid
                                          &pid,                  // pid
                                          NULL,                  // infile
                                          NULL);                 // outfile
        TEST_CHK_FEOK(ferr);
        if (verbose)
            printf("client waiting for server=%s start\n", sname);
        status = cv.wait(true);
        assert(status == 0);

#ifdef SQ_PHANDLE_VERIFIER
        ferr = msg_mon_create_name_seq(sname,
                                       srv_verifier,
                                       sname_seq1,
                                       (int) sizeof(sname_seq1));
        TEST_CHK_FEOK(ferr);
        ferr = msg_mon_create_name_seq(sname,
                                       srv_verifier + 99,
                                       sname_seq2,
                                       (int) sizeof(sname_seq2));
        TEST_CHK_FEOK(ferr);
#else
        strcpy(sname_seq1, sname);
#endif

        len = (short) strlen(sname_seq1);
        if (verbose)
            printf("client opening server %s\n", sname);
        ferr = XFILE_OPEN_(sname_seq1, len, &filenums,
                           0, 0, 0, 0,
                           0,
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);

#ifdef SQ_PHANDLE_VERIFIER
        len2 = (short) strlen(sname_seq2);
        disable = msg_test_assert_disable();
        // make sure seq # is checked
        ferr = XFILE_OPEN_(sname_seq2, len2, &filenums2,
                           0, 0, 0, 0,
                           0,
                           0, 0, NULL);
        assert(ferr != XZFIL_ERR_OK);
        msg_test_assert_enable(disable);
#endif

        if (verbose)
            printf("open filenums=%d\n", filenums);
        for (inxl = 0; inxl < loop; inxl++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inxl);
            cc = XWRITEREADX(filenums,
                             send_buffer,
                             (unsigned short) (strlen(send_buffer) + 1), // cast
                             BUFSIZ,
                             &count_read,
                             0);
            TEST_CHK_CCEQ(cc);
            printf("%s\n", send_buffer);
        }
        disable = msg_test_assert_disable();
        ferr = XFILE_CLOSE_(filenums, 0);
        TEST_CHK_FEOK(ferr);
        msg_test_assert_enable(disable);
        if (death) {
            sleep(2);
        }

        if (verbose)
            printf("client calling shutdown\n");
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr,
                           0, 0, 0,
                           1, 0, // sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        cc = XREADUPDATEX(filenumr,
                          recv_buffer,
                          BUFSIZ,
                          &count_read,
                          0);
        TEST_CHK_CCNE(cc);
        count_read = 0;
        cc = XREPLYX(recv_buffer,
                     count_read,
                     &count_written,
                     0,
                     XZFIL_ERR_OK);
        TEST_CHK_CCEQ(cc);
        for (inxl = 0; inxl < loop; inxl++) {
            cc = XREADUPDATEX(filenumr,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            TEST_CHK_CCEQ(cc);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            count_read = (unsigned short) (strlen(recv_buffer) + 1); // cast
            cc = XREPLYX(recv_buffer,
                         count_read,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
        if (death) {
            sleep(1);
            util_abort_core_free();
        }
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Example #9
0
int main(int argc, char *argv[]) {
    void           *buf;
    _xcc_status     cc;
    bool            client = false;
    unsigned short  count_written;
    unsigned short  count_xferred;
    int             ferr;
    short           filenum;
    int             inx;
    int             loop = 10;
    char            my_name[BUFSIZ];
    bool            nowait = false;
    char            recv_buffer[BUFSIZ];
    RI_Type         ri;
    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      },
      { "-nowait",    TA_Bool, TA_NOMAX,    &nowait    },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    if (client) {
        ferr = XFILE_OPEN_((char *) "$srv", 4, &filenum,
                           0, 0, nowait ? (short) 1 : (short) 0,
                           0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            send_len = (int) strlen(send_buffer) + 1; // cast
            cc = XWRITEX(filenum,
                         send_buffer,
                         (ushort) send_len,
                         &count_written,
                         0);
            if (nowait) {
                TEST_CHK_CCEQ(cc);
                tfilenum = filenum;
                cc = XAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag,
                               timeout,
                               NULL);
                TEST_CHK_CCEQ(cc);
                assert(count_xferred == send_len);
            } else {
                TEST_CHK_CCEQ(cc);
                assert(count_written == send_len);
            }
            printf("%s\n", send_buffer);
        }
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, 0,
                           1, 1, // no sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            cc = XREADUPDATEX(filenum,
                              recv_buffer,
                              BUFSIZ,
                              NULL,
                              0);
            TEST_CHK_CCEQ(cc);
            getri(&ri);
            assert(ri.io_type == XZSYS_VAL_RCV_IOTYPE_WRITE);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            cc = XREPLYX(NULL,
                         0,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
            assert(count_written == 0);
        }
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Example #10
0
int main(int argc, char *argv[]) {
    _xcc_status     cc;
    bool            client = false;
    unsigned short  count_read;
    unsigned short  count_written;
    int             ferr;
    short           filenum;
    bool            forkexec = false;
    int             inx;
    int             loop = 10;
    char            my_name[BUFSIZ];
    const char     *name;
    char            recv_buffer[BUFSIZ];
    char            send_buffer[BUFSIZ];
    TAD             zargs[] = {
        { "-client",    TA_Bool, TA_NOMAX,    &client    },
        { "-forkexec",  TA_Bool, TA_NOMAX,    &forkexec  },
        { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
        { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    arg_proc_args(zargs, false, argc, argv);
    if (client)
        name = "$cli";
    else
        name = "$srv";
    ferr = file_init_attach(&argc, &argv, forkexec, (char *) name);
    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);
    util_gethostname(my_name, (int) sizeof(my_name));

    if (client) {
        ferr = XFILE_OPEN_((char *) "$srv", 4, &filenum,
                           0, 0, 0, 0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            cc = XWRITEREADX(filenum,
                             send_buffer,
                             (short) (strlen(send_buffer) + 1),
                             BUFSIZ,
                             &count_read,
                             0);
            TEST_CHK_CCEQ(cc);
            printf("%s\n", send_buffer);
        }
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, 0,
                           1, 1, // no sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            cc = XREADUPDATEX(filenum,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            TEST_CHK_CCEQ(cc);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            count_read = (short) (strlen(recv_buffer) + 1);
            cc = XREPLYX(recv_buffer,
                         count_read,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Example #11
0
int main(int argc, char *argv[]) {
    void           *buf;
    _xcc_status     cc;
    bool            client = false;
    unsigned short  count_read;
    unsigned short  count_written;
    unsigned short  count_xferred;
    bool            dup = false;
    int             ferr;
    short           filenum[10];
    int             filenums = 1;
    int             finx;
    int             inx;
    int             loop = 10;
    bool            noclose = false;
    bool            nowait = false;
    int             num;
    char            recv_buffer1[BUFSIZ];
    char            recv_buffer2[BUFSIZ];
    char            send_buffer1[BUFSIZ];
    char            send_buffer2[BUFSIZ];
    SB_Tag_Type     tag1;
    SB_Tag_Type     tag2;
    short           tfilenum;
    int             timeout = -1;
    bool            verbose = false;
    bool            wait = false;
    int             xinx;
    SB_Tag_Type     xtag;
    TAD             zargs[] = {
        { "-client",    TA_Bool, TA_NOMAX,    &client    },
        { "-dup",       TA_Bool, TA_NOMAX,    &dup       },
        { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
        { "-noclose",   TA_Bool, TA_NOMAX,    &noclose   },
        { "-nowait",    TA_Bool, TA_NOMAX,    &nowait    },
        { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
        { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
        { "-wait",      TA_Bool, TA_NOMAX,    &wait      },
        { "",           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);
    if (dup)
        filenums = 5;
    util_test_start(client);
    ferr = file_mon_process_startup(!client); // system messages
    TEST_CHK_FEOK(ferr);

    if (client) {
        if (verbose)
            printf("client opening server\n");
        if (nowait) {
            for (finx = 0; finx < filenums; finx++) {
                ferr = XFILE_OPEN_((char *) "$srv", 4, &filenum[finx],
                                   0, 0, 2,
                                   0,
                                   0x4000, // nowait open
                                   0, 0, NULL);
                TEST_CHK_FEOK(ferr);
            }
            for (finx = 0; finx < filenums; finx++) {
                tfilenum = filenum[finx];
                cc = XAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag1,
                               timeout,
                               NULL);
                TEST_CHK_CCEQ(cc);
                assert(tag1 == -30);
            }
        } else {
            for (finx = 0; finx < filenums; finx++) {
                ferr = XFILE_OPEN_((char *) "$srv", 4, &filenum[finx],
                                   0, 0, 2,
                                   0, 0, 0, 0, NULL);
                TEST_CHK_FEOK(ferr);
            }
        }
        for (inx = 0; inx < loop; inx++) {
            for (finx = 0; finx < filenums; finx++) {
                if (verbose)
                    printf("client wr-1 inx=%d, finx=%d\n", inx, finx);
                sprintf(send_buffer1, "inx=%d, tag=1", inx);
                cc = XWRITEREADX(filenum[finx],
                                 send_buffer1,
                                 (short) (strlen(send_buffer1) + 1),
                                 BUFSIZ,
                                 &count_read,
                                 1);
                TEST_CHK_CCEQ(cc);
                sprintf(send_buffer2, "inx=%d, tag=2", inx);
                if (verbose)
                    printf("client wr-2 inx=%d, finx=%d\n", inx, finx);
                cc = XWRITEREADX(filenum[finx],
                                 send_buffer2,
                                 (short) (strlen(send_buffer2) + 1),
                                 BUFSIZ,
                                 &count_read,
                                 2);
                TEST_CHK_CCEQ(cc);
                tfilenum = filenum[finx];
                if (verbose)
                    printf("client awaitio-1 inx=%d, finx=%d\n", inx, finx);
                cc = XAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag1,
                               timeout,
                               NULL);
                TEST_CHK_CCEQ(cc);
                assert(tag1 == 2);
                num = sscanf((char *) buf, "inx=%d, tag=" PFTAG, &xinx, &xtag);
                assert(num == 2);
                assert(xinx == inx);
                assert(xtag == 2);
                tfilenum = filenum[finx];
                if (verbose)
                    printf("client awaitio-2 inx=%d, finx=%d\n", inx, finx);
                cc = XAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag2,
                               timeout,
                               NULL);
                TEST_CHK_CCEQ(cc);
                assert(tag2 == 1);
                num = sscanf((char *) buf, "inx=%d, tag=" PFTAG, &xinx, &xtag);
                assert(num == 2);
                assert(xinx == inx);
                assert(xtag == 1);
            }
        }
        if (!noclose) {
            for (finx = 0; finx < filenums; finx++) {
                if (verbose)
                    printf("client closing server finx=%d\n", finx);
                ferr = XFILE_CLOSE_(filenum[finx], 0);
                TEST_CHK_FEOK(ferr);
            }
        }
        if (wait)
            sleep(5);
        printf("if there were no asserts, all is well\n");
    } else {
        if (verbose)
            printf("server opening $receive\n");
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum[0],
                           0, 0, 1,
                           2, 0, // sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (finx = 0; finx < filenums; finx++) {
            if (verbose)
                printf("server ru-open finx=%d\n", finx);
            cc = XREADUPDATEX(filenum[0],
                              recv_buffer1,
                              BUFSIZ,
                              &count_read,
                              1);
            TEST_CHK_CCEQ(cc);
            tfilenum = filenum[0];
            cc = XAWAITIOX(&tfilenum,
                           &buf,
                           &count_xferred,
                           &tag1,
                           timeout,
                           NULL);
            TEST_CHK_CCNE(cc);
            assert(recv_buffer1[0] == XZSYS_VAL_SMSG_OPEN);
            if (verbose)
                printf("server reply-open finx=%d\n", finx);
            cc = XREPLYX(recv_buffer1,
                         0,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
        for (inx = 0; inx < loop; inx++) {
            for (finx = 0; finx < filenums; finx++) {
                if (verbose)
                    printf("server ru-1 inx=%d, finx=%d\n", inx, finx);
                cc = XREADUPDATEX(filenum[0],
                                  recv_buffer1,
                                  BUFSIZ,
                                  &count_read,
                                  1);
                TEST_CHK_CCEQ(cc);
                tfilenum = filenum[0];
                cc = XAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag1,
                               timeout,
                               NULL);
                TEST_CHK_CCEQ(cc);
                if (verbose)
                    printf("server ru-2 inx=%d, finx=%d\n", inx, finx);
                cc = XREADUPDATEX(filenum[0],
                                  recv_buffer2,
                                  BUFSIZ,
                                  &count_read,
                                  2);
                TEST_CHK_CCEQ(cc);
                tfilenum = filenum[0];
                cc = XAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag2,
                               timeout,
                               NULL);
                TEST_CHK_CCEQ(cc);
                // reply in reverse order
                count_read = (short) (strlen(recv_buffer2) + 1);
                if (verbose)
                    printf("server reply-2 inx=%d, finx=%d\n", inx, finx);
                cc = XREPLYX(recv_buffer2,
                             count_read,
                             &count_written,
                             1,
                             XZFIL_ERR_OK);
                TEST_CHK_CCEQ(cc);
                count_read = (short) (strlen(recv_buffer1) + 1);
                if (verbose)
                    printf("server reply-1 inx=%d, finx=%d\n", inx, finx);
                cc = XREPLYX(recv_buffer1,
                             count_read,
                             &count_written,
                             0,
                             XZFIL_ERR_OK);
                TEST_CHK_CCEQ(cc);
            }
        }
        if (!noclose) {
            for (finx = 0; finx < filenums; finx++) {
                if (verbose)
                    printf("server ru-close finx=%d\n", finx);
                cc = XREADUPDATEX(filenum[0],
                                  recv_buffer1,
                                  BUFSIZ,
                                  &count_read,
                                  1);
                TEST_CHK_CCEQ(cc);
                tfilenum = filenum[0];
                cc = XAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag1,
                               timeout,
                               NULL);
                TEST_CHK_CCNE(cc);
                assert(recv_buffer1[0] == XZSYS_VAL_SMSG_CLOSE);
                if (verbose)
                    printf("server reply-close finx=%d\n", finx);
                cc = XREPLYX(recv_buffer1,
                             0,
                             &count_written,
                             0,
                             XZFIL_ERR_OK);
                TEST_CHK_CCEQ(cc);
            }
        }
        if (verbose)
            printf("server closing $receive\n");
        ferr = XFILE_CLOSE_(filenum[0], 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Example #12
0
int main(int argc, char *argv[]) {
    void           *buf;
    _xcc_status     cc;
    bool            client = false;
    unsigned short  count_read;
    unsigned short  count_written;
    unsigned short  count_xferred;
    int             ferr;
    short           filenum_rcv;
    short           filenum_wr;
    int             inx;
    int             loop = 10;
    char            my_name[BUFSIZ];
    bool            nowait = false;
    char            recv_buffer[BUFSIZ];
    RI_Type         ri;
    char            send_buffer[BUFSIZ];
    SB_Tag_Type     tag;
    short           tfilenum;
    int             timeout = -1;
    TAD             zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-nowait",    TA_Bool, TA_NOMAX,    &nowait    },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    if (client) {
        ferr = XFILE_OPEN_((char *) "$srv", 4, &filenum_wr,
                           0, 0, 0,
                           0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            cc = XWRITEREADX(filenum_wr,
                             send_buffer,
                             (short) (strlen(send_buffer) + 1),
                             BUFSIZ,
                             &count_read,
                             0);
            TEST_CHK_CCEQ(cc);
            printf("%s\n", send_buffer);
        }
        ferr = XFILE_CLOSE_(filenum_wr, 0);
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum_rcv,
                           0, 0, nowait ? (short) 1 : (short) 0,
                           1, 0, // sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        // read open message
        cc = XREADUPDATEX(filenum_rcv,
                          recv_buffer,
                          BUFSIZ,
                          &count_read,
                          0);
        if (nowait) {
            TEST_CHK_CCEQ(cc);
            tfilenum = filenum_rcv;
            cc = XAWAITIOX(&tfilenum,
                           &buf,
                           &count_xferred,
                           &tag,
                           timeout,
                           NULL);
        }
        TEST_CHK_CCNE(cc);
        getri(&ri);
        cc = XREPLYX(recv_buffer,
                     0,
                     &count_written,
                     ri.message_tag,
                     XZFIL_ERR_OK);
        TEST_CHK_CCEQ(cc);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "i'm the server inx=%d", inx);
            cc = XREADUPDATEX(filenum_rcv,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            TEST_CHK_CCEQ(cc);
            if (nowait) {
                tfilenum = filenum_rcv;
                cc = XAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag,
                               timeout,
                               NULL);
                TEST_CHK_CCEQ(cc);
            }
            getri(&ri);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            count_read = (short) (strlen(recv_buffer) + 1);
            cc = XREPLYX(recv_buffer,
                         count_read,
                         &count_written,
                         ri.message_tag,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
        ferr = XFILE_CLOSE_(filenum_rcv, 0);
        TEST_CHK_FEOK(ferr);
        ferr = file_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Example #13
0
int main(int argc, char *argv[]) {
    void           *buf;
    _xcc_status     cc;
    bool            client = false;
    unsigned short  count_read;
    unsigned short  count_written;
    unsigned short  count_xferred;
    int             disable;
    int             ferr;
    short           filenum;
    int             linx;
    int             loop = 1;
    int             maxopen1;
    int             maxopen2;
    char            my_name[BUFSIZ];
    int             ninx;
    int             oinx;
    int             rd;
    int             recvdepth = 1;
    int             rinx;
    SB_Tag_Type     tag;
    short           tfilenum;
    int             timeout = -1;
    bool            verbose = false;
    TAD             zargs[] = {
        { "-client",    TA_Bool, TA_NOMAX,    &client    },
        { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
        { "-recvdepth", TA_Int,  MAXRCVDEPTH, &recvdepth },
        { "-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));

    if (client) {
        maxopen1 = (recvdepth + MAXNOWAIT - 1 ) / MAXNOWAIT;
        maxopen2 = RDOVER / MAXNOWAIT;
        if (verbose)
            printf("client maxopen=%d, recvdepth=%d\n", maxopen1, recvdepth);
        for (oinx = 0; oinx < maxopen1; oinx++) {
            ferr = XFILE_OPEN_((char *) "$SRV", 8, &filenumc1[oinx],
                               0, 0, MAXNOWAIT,  // nowait
                               0, 0, 0, 0, NULL);
            TEST_CHK_FEOK(ferr);
        }
        for (oinx = 0; oinx < maxopen2; oinx++) {
            ferr = XFILE_OPEN_((char *) "$SRV", 8, &filenumc2[oinx],
                               0, 0, MAXNOWAIT,  // nowait
                               0, 0, 0, 0, NULL);
            TEST_CHK_FEOK(ferr);
        }
        for (linx = 0; linx < loop; linx++) {
            rd = 0;
            for (oinx = 0; oinx < maxopen1; oinx++) {
                for (ninx = 0; ninx < MAXNOWAIT; ninx++) {
                    if (verbose)
                        printf("client wr1, fnum=%d, linx=%d, oinx=%d, ninx=%d, rd=%d\n",
                               filenumc1[oinx], linx, oinx, ninx, rd);
                    sprintf(send_buffer1[oinx][ninx], "hello1, greetings from %s, oinx=%d, ninx=%d, rd=%d",
                            my_name, oinx, ninx, rd);
                    cc = XWRITEREADX(filenumc1[oinx],
                                     send_buffer1[oinx][ninx],
                                     (short) (strlen(send_buffer1[oinx][ninx]) + 1),
                                     BUFSIZ,
                                     &count_read,
                                     rd);
                    TEST_CHK_CCEQ(cc);
                    rd++;
                    if (rd >= recvdepth)
                        break;
                }
            }
            for (oinx = 0; oinx < maxopen2; oinx++) {
                for (ninx = 0; ninx < MAXNOWAIT; ninx++) {
                    if (verbose)
                        printf("client wr2, fnum=%d, linx=%d, oinx=%d, ninx=%d, rd=%d\n",
                               filenumc2[oinx], linx, oinx, ninx, rd);
                    sprintf(send_buffer2[oinx][ninx], "hello2, greetings from %s, oinx=%d, ninx=%d, rd=%d",
                            my_name, oinx, ninx, rd);
                    cc = XWRITEREADX(filenumc2[oinx],
                                     send_buffer2[oinx][ninx],
                                     (short) (strlen(send_buffer2[oinx][ninx]) + 1),
                                     BUFSIZ,
                                     &count_read,
                                     rd);
                    TEST_CHK_CCEQ(cc);
                    rd++;
                    if (rd >= (recvdepth + RDOVER))
                        break;
                }
            }

            rd = 0;
            for (oinx = 0; oinx < maxopen1; oinx++) {
                for (ninx = 0; ninx < MAXNOWAIT; ninx++) {
                    tfilenum = filenumc1[oinx];
                    if (verbose)
                        printf("client awaitio1, fnum=%d, linx=%d, oinx=%d, ninx=%d, rd=%d\n",
                               tfilenum, linx, oinx, ninx, rd);
                    cc = XAWAITIOX(&tfilenum,
                                   &buf,
                                   &count_xferred,
                                   &tag,
                                   timeout,
                                   NULL);
                    TEST_CHK_CCEQ(cc);
                    send_buffer1[oinx][ninx][count_xferred] = 0;
                    printf("%s\n", send_buffer1[oinx][ninx]);
                    rd++;
                    if (rd >= recvdepth)
                        break;
                }
            }
            rinx = 0;
            for (oinx = 0; oinx < maxopen2; oinx++) {
                for (ninx = 0; ninx < MAXNOWAIT; ninx++) {
                    tfilenum = filenumc2[oinx];
                    if (verbose)
                        printf("client awaitio2, fnum=%d, linx=%d, oinx=%d, ninx=%d, rd=%d\n",
                               tfilenum, linx, oinx, ninx, rd);
                    disable = msg_test_assert_disable();
                    cc = XAWAITIOX(&tfilenum,
                                   &buf,
                                   &count_xferred,
                                   &tag,
                                   timeout,
                                   NULL);
                    msg_test_assert_enable(disable);
                    msg_ok[rinx] = _xstatus_eq(cc);
                    if (msg_ok[rinx]) {
                        send_buffer2[oinx][ninx][count_xferred] = 0;
                        printf("%s\n", send_buffer2[oinx][ninx]);
                    } else if (verbose)
                        printf("client awaitio2-err\n");
                    rinx++;
                    rd++;
                    if (rd >= (recvdepth + RDOVER))
                        break;
                }
            }

            //
            // re-link any failures
            //
            rd = recvdepth;
            rinx = 0;
            for (oinx = 0; oinx < maxopen2; oinx++) {
                for (ninx = 0; ninx < MAXNOWAIT; ninx++) {
                    if (msg_ok[rinx++])
                        continue;
                    tfilenum = filenumc2[oinx];
                    if (verbose)
                        printf("client wr3, fnum=%d, linx=%d, oinx=%d, ninx=%d, rd=%d\n",
                               filenumc2[oinx], linx, oinx, ninx, rd);
                    sprintf(send_buffer2[oinx][ninx], "hello3, greetings from %s, oinx=%d, ninx=%d, rd=%d",
                            my_name, oinx, ninx, rd);
                    cc = XWRITEREADX(tfilenum,
                                     send_buffer2[oinx][ninx],
                                     (short) (strlen(send_buffer2[oinx][ninx]) + 1),
                                     BUFSIZ,
                                     &count_read,
                                     rd);
                    TEST_CHK_CCEQ(cc);
                    if (verbose)
                        printf("client awaitio3, fnum=%d, linx=%d, oinx=%d, ninx=%d, rd=%d\n",
                               tfilenum, linx, oinx, ninx, rd);
                    cc = XAWAITIOX(&tfilenum,
                                   &buf,
                                   &count_xferred,
                                   &tag,
                                   timeout,
                                   NULL);
                    TEST_CHK_CCEQ(cc);
                    send_buffer2[oinx][ninx][count_xferred] = 0;
                    printf("%s\n", send_buffer2[oinx][ninx]);
                    rd++;
                    if (rd >= (recvdepth + RDOVER))
                        break;
                }
            }
        }

    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, 0,
                           (short) recvdepth, 1, // no sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (linx = 0; linx < loop; linx++) {
            for (rinx = 0; rinx < recvdepth; rinx++) {
                if (verbose)
                    printf("server ru rinx=%d, rd=%d\n", rinx, rinx);
                cc = XREADUPDATEX(filenum,
                                  recv_buffer[rinx],
                                  BUFSIZ,
                                  &count_read,
                                  0);
                TEST_CHK_CCEQ(cc);
            }
            sleep(1); // force NOLCB
            for (rinx = 0; rinx < recvdepth; rinx++) {
                if (verbose)
                    printf("server reply rinx=%d, rd=%d\n", rinx, rinx);
                strcat(recv_buffer[rinx], "- reply from ");
                strcat(recv_buffer[rinx], my_name);
                count_read = (unsigned short) (strlen(recv_buffer[rinx]) + 1); // cast
                cc = XREPLYX(recv_buffer[rinx],
                             count_read,
                             &count_written,
                             (short) rinx,
                             XZFIL_ERR_OK);
                TEST_CHK_CCEQ(cc);
            }
            sleep(1); // delay
            rd = recvdepth;
            for (rinx = 0; rinx < RDOVER; rinx++) {
                if (verbose)
                    printf("server ru (over) rinx=%d, rd=%d\n", rinx, rd);
                cc = XREADUPDATEX(filenum,
                                  recv_buffer[rinx],
                                  BUFSIZ,
                                  &count_read,
                                  0);
                TEST_CHK_CCEQ(cc);
                if (verbose)
                    printf("server reply (over) rinx=%d, rd=%d\n", rinx, rd);
                strcat(recv_buffer[rinx], "- reply from ");
                strcat(recv_buffer[rinx], my_name);
                count_read = (unsigned short) (strlen(recv_buffer[rinx]) + 1); // cast
                cc = XREPLYX(recv_buffer[rinx],
                             count_read,
                             &count_written,
                             (short) 0,
                             XZFIL_ERR_OK);
                TEST_CHK_CCEQ(cc);
                rd++;
            }
        }

        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEIGNORE(ferr);
    util_test_finish(client);
    return 0;
}
Example #14
0
int main(int argc, char *argv[]) {
    void           *buf;
    _xcc_status     cc;
    bool            client = false;
    unsigned short  count_read;
    unsigned short  count_written;
    unsigned short  count_xferred;
    int             ferr;
    short           filenum;
    int             inx;
    int             loop = 10;
    int             num;
    int             out;
    SB_Tag_Type     tag;
    short           tfilenum;
    int             timeout = -1;
    int             xinx;
    SB_Tag_Type     xtag;
    TAD             zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    if (client) {
        ferr = XFILE_OPEN_((char *) "$srv", 4, &filenum,
                           0, 0, MAX_OUT,
                           0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            for (out = 0; out < MAX_OUT; out++) {
                sprintf(send_buffer[out], "inx=%d, tag=%d", inx, out + 1);
                cc = XWRITEREADX(filenum,
                                 send_buffer[out],
                                 0,
                                 0,
                                 &count_read,
                                 out + 1);
                TEST_CHK_CCEQ(cc);
            }
            for (out = 0; out < MAX_OUT; out++) {
                tfilenum = filenum;
                cc = XAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &xtag,
                               timeout,
                               NULL);
                TEST_CHK_CCEQ(cc);
                assert(xtag == (MAX_OUT - out));
                num = sscanf((char *) buf, "inx=%d, tag=" PFTAG, &xinx, &xtag);
                assert(num == 2);
                assert(xinx == inx);
                assert(xtag == (MAX_OUT - out));
            }
        }
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
        printf("if there were no asserts, all is well\n");
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum,
                           0, 0, 1,
                           MAX_OUT, 1, // no sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            for (out = 0; out < MAX_OUT; out++) {
                cc = XREADUPDATEX(filenum,
                                  recv_buffer[out],
                                  BUFSIZ,
                                  &count_read,
                                  out + 1);
                TEST_CHK_CCEQ(cc);
                tfilenum = filenum;
                cc = XAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag,
                               timeout,
                               NULL);
                TEST_CHK_CCEQ(cc);
            }
            for (out = MAX_OUT - 1; out >= 0; out--) {
                // reply in reverse order
                count_read = (short) (strlen(recv_buffer[out]) + 1);
                cc = XREPLYX(recv_buffer[out],
                             count_read,
                             &count_written,
                             (short) out,
                             XZFIL_ERR_OK);
                TEST_CHK_CCEQ(cc);
            }
        }
        ferr = XFILE_CLOSE_(filenum, 0);
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Example #15
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;
}
Example #16
0
int main(int argc, char *argv[]) {
    void           *buf;
    _xcc_status     cc;
    bool            client = false;
    unsigned short  count_read;
    unsigned short  count_written;
    unsigned short  count_xferred;
    int             ferr;
    short           filenum_rcv;
    short           filenum_wr;
    int             inx;
    short           lasterr;
    int             loop = 10;
    char            my_name[BUFSIZ];
    char            recv_buffer[BUFSIZ];
    char            send_buffer[BUFSIZ];
    SB_Tag_Type     tag;
    short           tfilenum;
    int             timeout = -1;
    bool            verbose = false;
    TAD             zargs[] = {
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    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(true); // system messages
    TEST_CHK_FEOK(ferr);
    util_gethostname(my_name, sizeof(my_name));

    // process-wait for client/server/shell
    ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, 3, NULL, verbose);
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = XFILE_OPEN_((char *) "$srv", 4, &filenum_wr,
                           0, 0, 1,
                           0, 0, 0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum_rcv,
                           0, 0, 0,
                           1, 0, // sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        // read open message
        cc = XREADUPDATEX(filenum_rcv,
                          recv_buffer,
                          BUFSIZ,
                          &count_read,
                          0);
        TEST_CHK_CCNE(cc);
        if (_xstatus_ne(cc)) {
            ferr = XFILE_GETINFO_(-1, &lasterr, NULL, 0, NULL, NULL, NULL);
            TEST_CHK_FEOK(ferr);
            assert(lasterr == XZFIL_ERR_SYSMESS);
        }
        cc = XREPLYX(recv_buffer,
                     0,
                     &count_written,
                     0,
                     XZFIL_ERR_OK);
        TEST_CHK_CCEQ(cc);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "hello, greetings from %s, inx=%d",
                    my_name, inx);
            if (verbose)
                printf("client doing writeread inx=%d\n", inx);
            cc = XWRITEREADX(filenum_wr,
                             send_buffer,
                             (short) (strlen(send_buffer) + 1),
                             BUFSIZ,
                             &count_read,
                             0);
            TEST_CHK_CCEQ(cc);
            if (verbose)
                printf("client doing awaitiox inx=%d\n", inx);
            tfilenum = filenum_wr;
            cc = XAWAITIOX(&tfilenum,
                           &buf,
                           &count_xferred,
                           &tag,
                           timeout,
                           NULL);
            TEST_CHK_CCEQ(cc);
            if (verbose)
                printf("client writeread done inx=%d\n", inx);
            printf("%s\n", send_buffer);
        }
        ferr = XFILE_CLOSE_(filenum_wr, 0);
        TEST_CHK_FEOK(ferr);
        ferr = file_mon_process_close();
        TEST_CHK_FEOK(ferr);
    } else {
        ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum_rcv,
                           0, 0, 1,
                           1, 0, // sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        // read open message
        cc = XREADUPDATEX(filenum_rcv,
                          recv_buffer,
                          BUFSIZ,
                          &count_read,
                          0);
        TEST_CHK_CCEQ(cc);
        tfilenum = filenum_rcv;
        cc = XAWAITIOX(&tfilenum,
                       &buf,
                       &count_xferred,
                       &tag,
                       timeout,
                       NULL);
        if (_xstatus_ne(cc)) {
            ferr = XFILE_GETINFO_(-1, &lasterr, NULL, 0, NULL, NULL, NULL);
            TEST_CHK_FEOK(ferr);
            assert(lasterr == XZFIL_ERR_SYSMESS);
        }
        cc = XREPLYX(recv_buffer,
                     0,
                     &count_written,
                     0,
                     XZFIL_ERR_OK);
        TEST_CHK_CCEQ(cc);
        ferr = XFILE_OPEN_((char *) "$cli", 4, &filenum_wr,
                           0, 0, 1,
                           0, 0, 0, 0, NULL);
        for (inx = 0; inx < loop; inx++) {
            sprintf(send_buffer, "i'm the server inx=%d", inx);
            if (verbose)
                printf("server doing readupdate inx=%d\n", inx);
            cc = XREADUPDATEX(filenum_rcv,
                              recv_buffer,
                              BUFSIZ,
                              &count_read,
                              0);
            TEST_CHK_CCEQ(cc);
            if (verbose)
                printf("server doing awaitiox inx=%d\n", inx);
            tfilenum = filenum_rcv;
            cc = XAWAITIOX(&tfilenum,
                           &buf,
                           &count_xferred,
                           &tag,
                           timeout,
                           NULL);
            TEST_CHK_CCEQ(cc);
            if (verbose)
                printf("server awaitiox done inx=%d\n", inx);
            strcat(recv_buffer, "- reply from ");
            strcat(recv_buffer, my_name);
            count_read = (short) (strlen(recv_buffer) + 1);
            if (verbose)
                printf("server doing reply inx=%d\n", inx);
            cc = XREPLYX(recv_buffer,
                         count_read,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
            if (verbose)
                printf("server reply done inx=%d\n", inx);
        }
        ferr = XFILE_CLOSE_(filenum_rcv, 0);
        TEST_CHK_FEOK(ferr);
        ferr = file_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }
    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}