Exemplo n.º 1
0
void test_timers_cb() {
    int             ferr;
    int             status;
    struct timeval  t_elapsed;
    struct timeval  t_start1;
    struct timeval  t_start2;
    struct timeval  t_stop;
    short           tleid1;
    short           tleid2;
    long            to_act;
    long            to_exp;

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

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

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

    status = cv2.wait(true);
    TEST_CHK_STATUSOK(status);
    if (verbose)
        printf("cv2 wait done\n");
    util_time_timer_stop(&t_stop);
    util_time_elapsed(&t_start2, &t_stop, &t_elapsed);
    to_act = t_elapsed.tv_sec * 1000000 + t_elapsed.tv_usec;
    to_exp = t2.sre_tleTOVal * 10000;
    if (verbose || (to_act < to_exp))
        printf("tleid=%d, exp-to=%ld, act-to=%ld\n",
               t2.sre_tleId, to_exp, to_act);
    assert(to_act >= to_exp);
    if (to_tol > 0)
        assert(to_act <= (to_exp + to_tol));
}
Exemplo n.º 2
0
void cb(SB_Phandle_Type *, struct MS_Mon_NewProcess_Notice_def *msg) {
    int status;

#ifdef SQ_PHANDLE_VERIFIER
    srv_verifier = msg->verifier;
#else
    msg = msg; // touch
#endif
    status = cv.signal();
    assert(status == 0);
}
Exemplo n.º 3
0
void cb(SB_Phandle_Type *, struct MS_Mon_NewProcess_Notice_def *msg) {
    printf("client received new process message, ferr=%d, nid=%d, pid=%d, tag=0x%llx, pname=%s\n",
           msg->ferr,
           msg->nid,
           msg->pid,
           msg->tag,
           msg->process_name);
    assert(msg->ferr == XZFIL_ERR_OK);
    assert(msg->tag == server_inx);
    cv.signal(true);
    server_inx++;
}
Exemplo n.º 4
0
//
// wait for TIMER_SIG and process timer-list
//
void SB_Timer_Thread::run() {
    const char          *WHERE = "SB_Timer_Thread::run";
    int                  lv_err;
    int                  lv_sig;
    sigset_t             lv_set;
    int                  lv_status;

    if (gv_ms_trace_timer)
        trace_where_printf(WHERE, "timer sig thread started\n");

    iv_running = true;
    iv_cv.signal(true); // need lock

    sigemptyset(&lv_set);
    sigaddset(&lv_set, TIMER_SIG);
    while (!iv_shutdown) {
        lv_err = sigwait(&lv_set, &lv_sig);
        SB_util_assert_ieq(lv_err, 0);
        if (gv_ms_trace_timer)
            trace_where_printf(WHERE, "sigwait returned sig=%d\n", lv_sig);

        if (iv_shutdown)
            break;
        if (lv_sig != TIMER_SIG)
            continue;

        lv_status = gv_timer_mutex.lock();
        SB_util_assert_ieq(lv_status, 0);

        sb_timer_timer_list_complete(WHERE);

        if (gp_timer_head != NULL) {
            if (gv_ms_trace_timer)
                sb_timer_timer_list_print();
            for (;;) {
                if (gp_timer_head == NULL)
                    break;
                // restart timer
                if (sb_timer_setitimer(WHERE, gp_timer_head->iv_to))
                    break;
                sb_timer_timer_list_complete(WHERE);
            }
        }
        lv_status = gv_timer_mutex.unlock();
        SB_util_assert_ieq(lv_status, 0);
    }
    if (gv_ms_trace_timer)
        trace_where_printf(WHERE, "EXITING timer sig thread\n");
    iv_running = false;
}
Exemplo n.º 5
0
int main(int argc, char *argv[]) {
    int         arg;
    bool        chook = false;
    bool        client = false;
    int         ferr;
    int         inx;
    int         loop = 10;
    char        my_name[BUFSIZ];
    bool        nowait = false;
    int         nid;
    int         pid;
    char        prog[MS_MON_MAX_PROCESS_PATH];
    char        retname[BUFSIZ];
    char        server_name[30];
    int         server_nid;
    TPT_DECL   (server_phandle);
    int         server_pid;
    bool        shook = false;
    int         status;
    TAD         zargs[] = {
      { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-nowait",    TA_Bool, TA_NOMAX,    &nowait    },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-shook",     TA_Bool, TA_NOMAX,    &shook     },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

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

    if (client) {
        sprintf(prog, "%s/%s", getenv("PWD"), argv[0]);
        for (arg = 0; arg < argc; arg++)
            if (strcmp(argv[arg], "-client") == 0) // start_process
                argv[arg] = (char *) "-server";
        for (inx = 0; inx < loop; inx++) {
            sprintf(server_name, "$SRV%d", inx);
            server_nid = -1;
            if (nowait)
                ferr = msg_mon_start_process_nowait_cb(cb,                       // callback
                                                       prog,                     // prog
                                                       server_name,              // name
                                                       retname,                  // ret-name
                                                       argc,                     // argc
                                                       argv,                     // argv
                                                       MS_ProcessType_Generic,   // type
                                                       0,                        // priority
                                                       false,                    // debug
                                                       false,                    // backup
                                                       inx,                      // tag
                                                       &server_nid,              // nid
                                                       &server_pid,              // pid
                                                       NULL,                     // infile
                                                       NULL);                    // outfile
            else
                ferr = msg_mon_start_process(prog,                   // prog
                                             server_name,            // name
                                             NULL,                   // ret name
                                             argc,
                                             argv,
                                             TPT_REF(server_phandle),
                                             0,                      // open
                                             NULL,                   // oid
                                             MS_ProcessType_Generic, // type
                                             0,                      // priority
                                             0,                      // debug
                                             0,                      // backup
                                             &server_nid,            // nid
                                             &server_pid,            // pid
                                             NULL,                   // infile
                                             NULL);                  // outfile
            printf("process started, err=%d\n", ferr);
            TEST_CHK_FEOK(ferr);
            if (nowait) {
                status = cv.wait(true);
                TEST_CHK_STATUSOK(status);
            }
            wait_death();
        }
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Exemplo n.º 6
0
void SB_Timer_Thread::wait() {
    int lv_status;

    lv_status = iv_cv.wait(true); // need lock
    SB_util_assert_ieq(lv_status, 0);
}
Exemplo n.º 7
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;
}