int pp_checkpoint(void *buf, int *size) { int ferr; if (gim_backup) { if (gverbosepp) pp_printf("waiting for checkpoint.\n"); ferr = pp_recv(buf, size); } else { int msgid; MS_Result_Type results; if (gverbosepp) pp_printf("sending checkpoint.\n"); ferr = XMSG_LINK_(TPT_REF(gpeer_phandle), // phandle &msgid, // msgid NULL, // reqctrl 0, // reqctrlsize NULL, // replyctrl 0, // replyctrlmax (char *) buf, // reqdata (ushort) *size, // reqdatasize NULL, // replydata 0, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts TEST_CHK_FEOK(ferr); // ignore checkpoint error ferr = XMSG_BREAK_(msgid, (short *) &results, TPT_REF(gpeer_phandle)); TEST_CHK_FEIGNORE(ferr); } return ferr; }
int main(int argc, char *argv[]) { bool client = false; int ferr; int inx; int loop = 10; int msgid; int oid; RT results; TPT_DECL (phandle); int send_len; TAD zargs[] = { { "-loop", TA_Int, TA_NOMAX, &loop }, { "", TA_End, TA_NOMAX, NULL } }; msfs_util_init_role(true, &argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); client = true; util_test_start(client); ferr = msg_mon_process_startup(!client); // system messages TEST_CHK_FEOK(ferr); ferr = msg_mon_open_process((char *) "$srv", // name TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); util_gethostname(my_name, sizeof(my_name)); 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; ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid send_buffer2, // reqctrl (ushort) ((inx & 1) + 1), // reqctrlsize recv_buffer3, // replyctrl 2, // replyctrlmax send_buffer, // reqdata (ushort) send_len, // reqdatasize recv_buffer, // replydata BUFSIZ, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); assert(results.u.t.ctrl_size == (uint) ((inx & 1) + 1)); assert(results.u.t.data_size > (strlen(send_buffer) + 14)); assert(results.u.t.errm == RT_DATA_RCVD); // data printf("%s\n", recv_buffer); } ferr = msg_mon_close_process(TPT_REF(phandle)); printf("close ferr=%d\n", ferr); printf("client shutting down\n"); ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
void client(int clinx, char *name, long id, int inx) { int ferr; int lerr; int msgid; Util_AA<char> recv_buffer(BUFSIZ); Util_AA<short> recv_buffer3(BUFSIZ); RT results; Util_AA<char> send_buffer(BUFSIZ); Util_AA<short> send_buffer2(BUFSIZ); int send_len; MS_SRE_LDONE sre_ldone; sprintf(&send_buffer, "hello, greetings from %s, name=%s, id=%ld, inx=%d", my_name, name, id, inx); while (clinx >= 0) { strcat(&send_buffer, "!"); clinx--; } send_len = (int) strlen(&send_buffer) + 1; ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid &send_buffer2, // reqctrl (ushort) (inx & 1), // reqctrlsize &recv_buffer3, // replyctrl 1, // replyctrlmax &send_buffer, // reqdata (ushort) send_len, // reqdatasize &recv_buffer, // replydata BUFSIZ, // replydatamax (SB_Tag_Type) &send_buffer, // linkertag 0, // pri 0, // xmitclass XMSG_LINK_LDONEQ); // linkopts util_check("XMSG_LINK_", ferr); do { lerr = XWAIT(LDONE, -1); TEST_CHK_WAITIGNORE(lerr); lerr = XMSG_LISTEN_((short *) &sre_ldone, // sre 0, // listenopts 0); // listenertag } while (lerr == XSRETYPE_NOWORK); assert(lerr == XSRETYPE_LDONE); assert(sre_ldone.sre_linkTag == (SB_Tag_Type) &send_buffer); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); assert(results.u.t.ctrl_size == (uint) (inx & 1)); assert(results.u.t.data_size > (strlen(&send_buffer) + 14)); assert(results.u.t.errm == RT_DATA_RCVD); // data printf("%s\n", &recv_buffer); }
void *thread_sendbrk(void *arg) { int ferr; int inx; int msgid; RT results; arg = arg; // touch for (inx = 0; inx < loop; inx++) { Item *item = (Item *) queue1.remove(); msgid = item->iv_link.iv_id.i; ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); assert(results.u.t.ctrl_size == 0); assert(results.u.t.errm == RT_DATA_RCVD); // data printf("%s\n", recv_buffer); queue2.add(&item->iv_link); } return NULL; }
void *client_thr(void *arg) { Util_AA<char> event_data(MS_MON_MAX_SYNC_DATA); int event_len; int ferr; int inx; int msgid; Util_AA<char> recv_buffer(BUFSIZ); Util_AA<short> recv_buffer3(BUFSIZ); RT results; Util_AA<char> send_buffer(BUFSIZ); Util_AA<short> send_buffer2(BUFSIZ); int send_len; long t_elapsed; struct timeval t_start; struct timeval t_stop; int whoami = inxc++; arg = arg; // touch if (event) { ferr = msg_mon_event_wait(1, &event_len, &event_data); TEST_CHK_FEOK(ferr); } util_time_timer_start(&t_start); for (inx = 0; inx < loop; inx++) { if (txrate) { if ((inx % 100) == 0) { util_time_timer_stop(&t_stop); t_elapsed = (t_stop.tv_sec * 1000000 + t_stop.tv_usec) - (t_start.tv_sec * 1000000 + t_start.tv_usec); t_elapsed = t_elapsed / 1000; if (inx == 0) printf("%s: c-%d\n", name, whoami); else printf("%s: c-%d, inx=%d, msg/ms=%ld\n", name, whoami, inx, t_elapsed / inx); } } else if (mq) { if ((inx % 100) == 0) printf("%s: c-%d, inx=%d\n", name, whoami, inx); } else if (!quiet) printf("c-%d, inx=%d\n", whoami, inx); fflush(stdout); sprintf(&send_buffer, "hello, greetings from %s-%d, inx=%d", my_name, whoami, inx); send_len = (int) strlen(&send_buffer) + 1; if (verbose) printf("c-%d: sending %s\n", whoami, &send_buffer); ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid &send_buffer2, // reqctrl (ushort) (inx & 1), // reqctrlsize &recv_buffer3, // replyctrl (ushort) 1, // replyctrlmax &send_buffer, // reqdata (ushort) send_len, // reqdatasize &recv_buffer, // replydata (ushort) BUFSIZ, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts if (!abortserver) util_check("XMSG_LINK_", ferr); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); if (!abortserver) util_check("XMSG_BREAK_", ferr); if (!abortserver) { if (verbose) printf("c-%d: received %s\n", whoami, &recv_buffer); assert(results.u.t.ctrl_size == (uint) (inx & 1)); assert(results.u.t.data_size == 100); assert(results.u.t.errm == RT_DATA_RCVD); // data if (inx == (loop - 1)) { if (maxcp > 1) printf("%s: %s\n", name, &recv_buffer); else printf("%s\n", &recv_buffer); } } } return NULL; }
int main(int argc, char *argv[]) { int exit; int ferr; bool ldone; int lerr; int msgid; int nid; int oid; int pid; TPT_DECL (phandle); char recv_buffer[BUFSIZ]; short recv_buffer2[BUFSIZ]; RT results; MS_SRE sre; MS_Mon_Transid_Type transid; ferr = msfs_util_init_role(true, &argc, &argv, msg_debug_hook); TEST_CHK_FEOK(ferr); util_test_start(true); ferr = msg_mon_process_startup(true); // system messages TEST_CHK_FEOK(ferr); msg_mon_enable_mon_messages(true); ferr = msg_mon_get_process_info((char *) "$srv", &nid, &pid); TEST_CHK_FEOK(ferr); ferr = msg_mon_open_process((char *) "$srv", // name TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); TRANSID_SET_NULL(transid); ferr = msg_mon_deregister_death_notification(nid, pid, transid); TEST_CHK_FEOK(ferr); ferr = msg_mon_register_death_notification(nid, pid); TEST_CHK_FEOK(ferr); ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid NULL, // reqctrl 0, // reqctrlsize recv_buffer2, // replyctrl 1, // replyctrlmax NULL, // reqdata 0, // reqdatasize recv_buffer, // replydata BUFSIZ, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass XMSG_LINK_LDONEQ); // linkopts util_check("XMSG_LINK_", ferr); exit = 0; ldone = false; while (!exit) { do { lerr = XWAIT(LREQ|LDONE, -1); TEST_CHK_WAITIGNORE(lerr); if (lerr == LDONE) { ldone = true; break; } lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag } while (lerr == XSRETYPE_NOWORK); if (ldone) { printf("LINK done\n"); lerr = XMSG_LISTEN_((short *) &sre, // sre XLISTEN_ALLOW_LDONEM, // listenopts 0); // listenertag assert(lerr == XSRETYPE_LDONE); ferr = XMSG_BREAK_(sre.sre_msgId, results.u.s, TPT_REF(phandle)); assert(ferr == XZFIL_ERR_OK); break; } ferr = XMSG_READDATA_(sre.sre_msgId, // msgid recv_buffer, // reqdata BUFSIZ); // bytecount util_check("XMSG_READDATA_", ferr); if (sre.sre_flags & XSRE_MON) { MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer; printf("cli: mon message, type=%d\n", msg->type); if (msg->type == MS_MsgType_ProcessDeath) { assert(msg->u.death.nid == nid); assert(msg->u.death.pid == pid); exit = 1; } else if (msg->type == MS_MsgType_Shutdown) { printf("cli: received cluster shutdown, level=%d\n", msg->u.shutdown.level); assert(msg->u.shutdown.level==MS_Mon_ShutdownLevel_Immediate); } } else printf("cli: NON-mon message\n"); XMSG_REPLY_(sre.sre_msgId, // msgid NULL, // replyctrl 0, // replyctrlsize NULL, // replydata 0, // replydatasize 0, // errorclass NULL); // newphandle } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(true); return 0; }
int main(int argc, char *argv[]) { bool client = false; int count; int ferr; int inx; int lerr; int loop = 10; int msgid; int oid; TPT_DECL (phandle); RT results; MS_SRE sre; BMS_SRE sre_tb; MS_SRE sre_tx; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "", TA_End, TA_NOMAX, NULL } }; msfs_util_init(&argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = msg_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); if (client) { ferr = msg_mon_open_process((char *) "$srv", // name TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); } else msg_mon_enable_mon_messages(true); // need this util_gethostname(my_name, sizeof(my_name)); for (inx = 0; inx < loop; inx++) { count = inx % 100; if (client) { ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid send_bufferc, // reqctrl (short) count, // reqctrlsize recv_bufferc, // replyctrl (short) (count+1), // replyctrlmax send_buffer, // reqdata (short) (count+2), // reqdatasize recv_buffer, // replydata (short) (count+3), // replydatamax 0, // linkertag (short) count, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); } else { do { lerr = XWAIT(LREQ, -1); TEST_CHK_WAITIGNORE(lerr); lerr = XMSG_LISTEN_((short *) &sre_tx, // sre XLISTEN_TEST_IREQM, // listenopts 0); // listenertag if (lerr == XSRETYPE_NOWORK) continue; if (sre_tx.sre_flags & XSRE_MON) { // toss out monitor messages lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag assert(lerr == XSRETYPE_IREQ); assert(sre_tx.sre_flags & XSRE_MON); lerr = XSRETYPE_NOWORK; XMSG_REPLY_(sre.sre_msgId, // msgid NULL, // replyctrl 0, // replyctrlsize NULL, // replydata 0, // replydatasize 0, // errorclass NULL); // newphandle continue; } lerr = BMSG_LISTEN_((short *) &sre_tb, // sre BLISTEN_TEST_IREQM, // listenopts 0); // listenertag assert(lerr == BSRETYPE_IREQ); lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag assert(lerr == XSRETYPE_IREQ); } while (lerr == XSRETYPE_NOWORK); assert(sre.sre_pri == count); assert(sre.sre_reqCtrlSize == count); assert(sre.sre_reqDataSize == (count + 2)); assert(sre.sre_replyCtrlMax == (count + 1)); assert(sre.sre_replyDataMax == (count + 3)); assert(sre.sre_msgId == sre_tx.sre_msgId); assert(sre.sre_flags == sre_tx.sre_flags); assert(sre.sre_pri == sre_tx.sre_pri); assert(sre.sre_reqCtrlSize == sre_tx.sre_reqCtrlSize); assert(sre.sre_reqDataSize == sre_tx.sre_reqDataSize); assert(sre.sre_replyCtrlMax == sre_tx.sre_replyCtrlMax); assert(sre.sre_replyDataMax == sre_tx.sre_replyDataMax); assert(sre.sre_msgId == sre_tb.sre_msgId); assert(sre.sre_flags == sre_tb.sre_flags); assert(sre.sre_pri == sre_tb.sre_pri); assert(sre.sre_reqCtrlSize == sre_tb.sre_reqCtrlSize); assert(sre.sre_reqDataSize == sre_tb.sre_reqDataSize); assert(sre.sre_replyCtrlMax == sre_tb.sre_replyCtrlMax); assert(sre.sre_replyDataMax == sre_tb.sre_replyDataMax); XMSG_REPLY_(sre.sre_msgId, // msgid NULL, // replyctrl 0, // replyctrlsize recv_buffer, // replydata 0, // replydatasize 0, // errorclass NULL); // newphandle } } if (client) { ferr = msg_mon_close_process(TPT_REF(phandle)); TEST_CHK_FEOK(ferr); } else { ferr = msg_mon_process_close(); TEST_CHK_FEOK(ferr); } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { bool client = false; int count; int disable; int ferr; MS_Mon_Open_Info_Type info; MS_Mon_Open_Info_Max_Type info_max[MAX_OPENS]; int inx; int len; int lerr; int loop = 10; int msgid; int oid; TPT_DECL (phandle); RT results; int send_len; MS_SRE sre; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "", TA_End, TA_NOMAX, NULL } }; msfs_util_init(&argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = msg_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); // process-wait for server/shell ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, 2, NULL, false); TEST_CHK_FEOK(ferr); // process-wait for client ferr = msfs_util_wait_process_count(MS_ProcessType_TSE, 1, NULL, false); TEST_CHK_FEOK(ferr); if (client) { ferr = msg_mon_open_process((char *) "$srv", // name TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); } else util_gethostname(my_name, sizeof(my_name)); msg_mon_enable_mon_messages(true); for (inx = 0; inx < loop; inx++) { if (client) { sprintf(send_buffer, "hello, greetings from %s, inx=%d", my_name, inx); send_len = (int) strlen(send_buffer) + 1; ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid send_buffer2, // reqctrl (ushort) (inx & 1), // reqctrlsize recv_buffer3, // replyctrl 1, // replyctrlmax send_buffer, // reqdata (ushort) send_len, // reqdatasize recv_buffer, // replydata BUFSIZ, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); assert(results.u.t.ctrl_size == (uint) (inx & 1)); assert(results.u.t.data_size > (strlen(send_buffer) + 14)); assert(results.u.t.errm == RT_DATA_RCVD); // data printf("%s\n", recv_buffer); } else { do { lerr = XWAIT(LREQ, -1); TEST_CHK_WAITIGNORE(lerr); lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag } while (lerr == XSRETYPE_NOWORK); ferr = XMSG_READCTRL_(sre.sre_msgId, // msgid recv_buffer2, // reqctrl 1); // bytecount util_check("XMSG_READCTRL_", ferr); ferr = XMSG_READDATA_(sre.sre_msgId, // msgid recv_buffer, // reqdata BUFSIZ); // bytecount util_check("XMSG_READDATA_", ferr); if (sre.sre_flags & XSRE_MON) { printf("server received mon message\n"); inx--; len = 0; } else { if (inx == 0) { sleep(3); // wait for monitor replicate disable = msg_test_assert_disable(); ferr = msg_mon_get_open_info(-1, -1, (char *) "$srv", 1, &info); assert(ferr == XZFIL_ERR_INVALOP); ferr = msg_mon_get_open_info_max(-1, -1, (char *) "$srv", false, &count, MAX_OPENS, info_max); assert(ferr == XZFIL_ERR_INVALOP); msg_test_assert_enable(disable); } strcat(recv_buffer, "- reply from "); strcat(recv_buffer, my_name); len = (int) strlen(recv_buffer) + 1; } XMSG_REPLY_(sre.sre_msgId, // msgid recv_buffer2, // replyctrl sre.sre_reqCtrlSize, // replyctrlsize recv_buffer, // replydata (ushort) len, // replydatasize 0, // errorclass NULL); // newphandle } } if (client) { ferr = msg_mon_close_process(TPT_REF(phandle)); TEST_CHK_FEOK(ferr); } else { ferr = msg_mon_process_close(); TEST_CHK_FEOK(ferr); } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { int csize = 0; int dinx; int dloop = MAX_OUT; int dsize = MAX_DBUF; int ferr; TPT_DECL2 (phandle,MAX_SERVERS); int inx; int lerr; int loop = 10; int max; int maxsp = 1; int msgids[MAX_SERVERS * MAX_OUT]; int oid; int pinx; short *reqctrl; char *reqdata; short *repctrl; char *repdata; RT results; MS_SRE sre; bool verbose = false; int xinx; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-csize", TA_Int, MAX_CBUF, &csize }, { "-dloop", TA_Int, MAX_OUT, &dloop }, { "-dsize", TA_Int, MAX_DBUF, &dsize }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-maxcp", TA_Int, MAX_CLIENTS, &maxcp }, { "-maxsp", TA_Int, MAX_SERVERS, &maxsp }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "-v", TA_Bool, TA_NOMAX, &verbose }, { "", TA_End, TA_NOMAX, NULL } }; ferr = msg_init(&argc, &argv); TEST_CHK_FEOK(ferr); msfs_util_init_fs(&argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); if (maxcp < 0) maxcp = 1; if (maxsp < 0) maxsp = 1; ferr = msg_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); if (!client) msg_mon_enable_mon_messages(true); ferr = msg_mon_get_my_process_name(my_name, BUFSIZ); TEST_CHK_FEOK(ferr); // process-wait for clients/servers/shell ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, maxcp + maxsp + 1, NULL, verbose); TEST_CHK_FEOK(ferr); sleep(3); // wait for all process_count's to complete if (client) { pinx = atoi(&my_name[4]); assert(pinx >= 0); printf("loop=%d\n", loop); for (inx = 0; inx < loop; inx++) { for (pinx = 0; pinx < maxsp; pinx++) { sprintf(serv, "$srv%d", pinx); ferr = msg_mon_open_process(serv, TPT_REF2(phandle,pinx), &oid); TEST_CHK_FEOK(ferr); } for (pinx = 0; pinx < maxsp; pinx++) { for (dinx = 0; dinx < dloop; dinx++) { xinx = pinx * maxsp + dinx; reqctrl = &send_buffer2[xinx * csize]; repctrl = &recv_buffer3[xinx * csize]; reqdata = &send_buffer[xinx * dsize]; repdata = &recv_buffer[xinx * dsize]; ferr = XMSG_LINK_(TPT_REF2(phandle,pinx), // phandle &msgids[xinx], // msgid reqctrl, // reqctrl (short) csize, // reqctrlsize repctrl, // replyctrl (short) csize, // replyctrlmax reqdata, // reqdata (short) dsize, // reqdatasize repdata, // replydata (short) dsize, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); } } for (pinx = 0; pinx < maxsp; pinx++) { for (dinx = 0; dinx < dloop; dinx++) { xinx = pinx * maxsp + dinx; ferr = XMSG_BREAK_(msgids[xinx], results.u.s, TPT_REF2(phandle,pinx)); util_check("XMSG_BREAK_", ferr); assert((int) results.u.t.ctrl_size == csize); assert((int) results.u.t.data_size == dsize); assert(results.u.t.errm == RT_DATA_RCVD); // data } if (verbose) printf("%s-open-count=%d\n", my_name, inx); } for (pinx = 0; pinx < maxsp; pinx++) { ferr = msg_mon_close_process(TPT_REF2(phandle,pinx)); TEST_CHK_FEOK(ferr); if (verbose) printf("%s-close-count=%d\n", my_name, inx); } } } else { max = 2 * maxcp * loop + maxcp * dloop * loop; for (inx = 0; inx < max; inx++) { do { lerr = XWAIT(LREQ, -1); TEST_CHK_WAITIGNORE(lerr); lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag } while (lerr == XSRETYPE_NOWORK); ferr = XMSG_READCTRL_(sre.sre_msgId, // msgid recv_buffer2, // reqctrl sre.sre_reqCtrlSize); // bytecount util_check("XMSG_READCTRL_", ferr); ferr = XMSG_READDATA_(sre.sre_msgId, // msgid recv_buffer, // reqdata sre.sre_reqDataSize); // bytecount util_check("XMSG_READDATA_", ferr); XMSG_REPLY_(sre.sre_msgId, // msgid recv_buffer2, // replyctrl sre.sre_reqCtrlSize, // replyctrlsize recv_buffer, // replydata sre.sre_reqDataSize, // replydatasize 0, // errorclass NULL); // newphandle if (verbose) printf("%s-count=%d\n", my_name, inx); } } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { bool attach = false; bool chook = false; bool client = false; const char *cname = "$cli"; int count; int ferr; int inx; int len; int lerr; int loop = 10; int msgid; int oid; TPT_DECL (phandle); char *pname = NULL; RT results; int send_len; bool shook = false; const char *sname = "$srv"; MS_SRE sre; long t_elapsed; struct timeval t_start; struct timeval t_stop; TAD zargs[] = { { "-attach", TA_Bool, TA_NOMAX, &attach }, { "-chook", TA_Bool, TA_NOMAX, &chook }, { "-client", TA_Bool, TA_NOMAX, &client }, { "-cname", TA_Str, TA_NOMAX, &cname }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-name", TA_Str, TA_NOMAX, &pname }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "-shook", TA_Bool, TA_NOMAX, &shook }, { "-sname", TA_Str, TA_NOMAX, &sname }, { "", TA_End, TA_NOMAX, NULL } }; arg_proc_args(zargs, false, argc, argv); if (client && chook) test_debug_hook("c", "c"); if (!client && shook) test_debug_hook("s", "s"); if (attach) msfs_util_init_attach(&argc, &argv, msg_debug_hook, false, pname); else msfs_util_init(&argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); util_time_timer_start(&t_start); util_test_start(client); ferr = msg_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); // process-wait for server/shell ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, 2, NULL, false); TEST_CHK_FEOK(ferr); // process-wait for client ferr = msfs_util_wait_process_count(MS_ProcessType_TSE, 1, NULL, false); TEST_CHK_FEOK(ferr); if (client) { ferr = msg_mon_open_process((char *) sname, // name TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); } util_gethostname(my_name, sizeof(my_name)); msg_mon_enable_mon_messages(true); if (client) { ferr = msg_mon_get_process_info_type(MS_ProcessType_TSE, &count, 0, NULL); TEST_CHK_FEOK(ferr); if (!attach) assert(count == 1); ferr = msg_mon_get_process_info_type(MS_ProcessType_TSE, &count, 1, info); TEST_CHK_FEOK(ferr); if (!attach) assert(count == 1); } for (inx = 0; inx < loop; inx++) { if (client) { sprintf(send_buffer, "hello, greetings from %s, inx=%d", my_name, inx); send_len = (int) strlen(send_buffer) + 1; ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid send_buffer2, // reqctrl (ushort) (inx & 1), // reqctrlsize recv_buffer3, // replyctrl 1, // replyctrlmax send_buffer, // reqdata (ushort) send_len, // reqdatasize recv_buffer, // replydata BUFSIZ, // replydatamax 0, // linkertag (short) (inx+1), // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); assert(results.u.t.ctrl_size == (uint) (inx & 1)); assert(results.u.t.data_size > (strlen(send_buffer) + 14)); assert(results.u.t.errm == RT_DATA_RCVD); // data printf("%s\n", recv_buffer); } else { do { lerr = XWAIT(LREQ, -1); TEST_CHK_WAITIGNORE(lerr); lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag } while (lerr == XSRETYPE_NOWORK); ferr = XMSG_READCTRL_(sre.sre_msgId, // msgid recv_buffer2, // reqctrl 1); // bytecount util_check("XMSG_READCTRL_", ferr); ferr = XMSG_READDATA_(sre.sre_msgId, // msgid recv_buffer, // reqdata BUFSIZ); // bytecount util_check("XMSG_READDATA_", ferr); if (sre.sre_flags & XSRE_MON) { printf("server received mon message\n"); inx--; len = 0; } else { strcat(recv_buffer, "- reply from "); strcat(recv_buffer, my_name); len = (int) strlen(recv_buffer) + 1; } XMSG_REPLY_(sre.sre_msgId, // msgid recv_buffer2, // replyctrl sre.sre_reqCtrlSize, // replyctrlsize recv_buffer, // replydata (ushort) len, // replydatasize 0, // errorclass NULL); // newphandle } } if (client) { ferr = msg_mon_close_process(TPT_REF(phandle)); TEST_CHK_FEOK(ferr); } else { ferr = msg_mon_process_close(); TEST_CHK_FEOK(ferr); } util_time_timer_stop(&t_stop); t_elapsed = (t_stop.tv_sec * 1000000 + t_stop.tv_usec) - (t_start.tv_sec * 1000000 + t_start.tv_usec); ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); if (client) printf("elapsed time (gettimeofday us)=%ld\n", t_elapsed); return 0; }
void client(int clinx, char *name, long id, int inx) { int ferr; int lerr; bool ok; int match; Util_AA<int> msgid(MAX_SENDS); Util_AA<char> recv_buffer(MAX_SENDS * BUFSIZ); Util_AA<short> recv_buffer3(MAX_SENDS * BUFSIZ); RT results; int send; Util_AA<char> send_buffer(MAX_SENDS * BUFSIZ); Util_AA<short> send_buffer2(MAX_SENDS * BUFSIZ); int send_len; MS_SRE_LDONE sre_ldone; for (send = 0; send < MAX_SENDS; send++) { sprintf(&send_buffer.ip_v[send * BUFSIZ], "hello, greetings from %s, name=%s, id=%ld, inx=%d, send=%d", my_name, name, id, inx, send); while (clinx >= 0) { strcat(&send_buffer.ip_v[send * BUFSIZ], "!"); clinx--; } send_len = (int) strlen(&send_buffer.ip_v[send * BUFSIZ]) + 1; ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid.ip_v[send], // msgid &send_buffer2.ip_v[send * BUFSIZ], // reqctrl (ushort) (inx & 1), // reqctrlsize &recv_buffer3.ip_v[send * BUFSIZ], // replyctrl 1, // replyctrlmax &send_buffer.ip_v[send * BUFSIZ], // reqdata (ushort) send_len, // reqdatasize &recv_buffer.ip_v[send * BUFSIZ], // replydata BUFSIZ, // replydatamax (SB_Tag_Type) // linkertag &send_buffer.ip_v[send * BUFSIZ], 0, // pri 0, // xmitclass XMSG_LINK_LDONEQ); // linkopts util_check("XMSG_LINK_", ferr); } for (send = 0; send < MAX_SENDS;) { lerr = XWAIT(LDONE, -1); TEST_CHK_WAITIGNORE(lerr); for (;;) { lerr = XMSG_LISTEN_((short *) &sre_ldone, // sre 0, // listenopts 0); // listenertag if (lerr == XSRETYPE_NOWORK) break; send++; assert(lerr == XSRETYPE_LDONE); ok = false; for (match = 0; match < MAX_SENDS; match++) { if (sre_ldone.sre_linkTag == (SB_Tag_Type) &send_buffer.ip_v[match * BUFSIZ]) { ok = true; break; } } assert(ok); ferr = XMSG_BREAK_(msgid.ip_v[match], results.u.s, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); assert(results.u.t.ctrl_size == (uint) (inx & 1)); assert(results.u.t.data_size > (strlen(&send_buffer.ip_v[match * BUFSIZ]) + 14)); assert(results.u.t.errm == RT_DATA_RCVD); // data printf("%s\n", &recv_buffer.ip_v[match * BUFSIZ]); } } }
int main(int argc, char *argv[]) { bool client = false; int ferr; int inx; int loop = 10; int msgid; int oid; TPT_DECL (phandle); char recv_buffer[40000]; RT results; char send_buffer[40000]; int status; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-delay", TA_Bool, TA_NOMAX, &delay }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-maxs", TA_Int, TA_NOMAX, &maxs }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "-v", TA_Bool, TA_NOMAX, &verbose }, { "", TA_End, TA_NOMAX, NULL } }; msfs_util_init(&argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = msg_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); util_gethostname(my_name, sizeof(my_name)); if (client) { ferr = msg_mon_open_process((char *) "$srv", // name TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); for (inx = 0; inx < loop; inx++) { sprintf(send_buffer, "hello, greetings from %s, inx=%d", my_name, inx); ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid NULL, // reqctrl 0, // reqctrlsize NULL, // replyctrl 0, // replyctrlmax send_buffer, // reqdata 39000, // reqdatasize recv_buffer, // replydata 40000, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); assert(results.u.t.ctrl_size == 0); assert(results.u.t.errm == RT_DATA_RCVD); // data printf("%s\n", recv_buffer); } for (inx = 0; inx < maxs; inx++) { ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid NULL, // reqctrl 0, // reqctrlsize NULL, // replyctrl 0, // replyctrlmax send_buffer, // reqdata 0, // reqdatasize recv_buffer, // replydata 0, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); printf("fin %d\n", inx); } } else { msg_mon_enable_mon_messages(true); for (inx = 0; inx < maxs; inx++) { char name[10]; sprintf(name, "s%d", inx); thrs[inx] = new Server_Thread(server_thr, name, inx); } for (inx = 0; inx < maxs; inx++) { thrs[inx]->start(); SB_Thread::Sthr::yield(); } for (inx = 0; inx < maxs; inx++) { void *res; status = thrs[inx]->join(&res); TEST_CHK_STATUSOK(status); printf("joined with server %d\n", inx); } } if (client) { ferr = msg_mon_close_process(TPT_REF(phandle)); TEST_CHK_FEOK(ferr); } else { ferr = msg_mon_process_close(); TEST_CHK_FEOK(ferr); } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { bool client = false; int disable; int ferr; int inx; int len; int lerr; int loop = 10; int msgid; int oid; TPT_DECL (phandle); RT results; MS_SRE sre; TPT_DECL (xphandle); 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 } }; setenv("MS_STREAMS_MAX", "10", 1); msfs_util_init(&argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = msg_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); if (client) { ferr = msg_mon_open_process((char *) "$srv", // name TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); } else { disable = msg_test_assert_disable(); for (inx = 0; inx < 20; inx++) { ferr = msg_mon_open_process((char *) "$crap", // name TPT_REF(xphandle), &oid); assert(ferr != XZFIL_ERR_OK); } msg_test_assert_enable(disable); } util_gethostname(my_name, sizeof(my_name)); for (inx = 0; inx < loop; inx++) { if (client) { sprintf(send_buffer, "hello, greetings from %s, inx=%d", my_name, inx); ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid NULL, // reqctrl 0, // reqctrlsize NULL, // replyctrl 0, // replyctrlmax send_buffer, // reqdata 39000, // reqdatasize recv_buffer, // replydata 40000, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); assert(results.u.t.ctrl_size == 0); assert(results.u.t.errm == RT_DATA_RCVD); // data printf("%s\n", recv_buffer); } else { do { lerr = XWAIT(LREQ, -1); TEST_CHK_WAITIGNORE(lerr); lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag } while (lerr == XSRETYPE_NOWORK); ferr = XMSG_READCTRL_(sre.sre_msgId, // msgid NULL, // reqctrl 0); // bytecount util_check("XMSG_READCTRL_", ferr); ferr = XMSG_READDATA_(sre.sre_msgId, // msgid recv_buffer, // reqdata 40000); // bytecount util_check("XMSG_READDATA_", ferr); strcat(recv_buffer, "- reply from "); strcat(recv_buffer, my_name); len = (int) strlen(recv_buffer) + 1; len = len; // touch - not currently used XMSG_REPLY_(sre.sre_msgId, // msgid NULL, // replyctrl 0, // replyctrlsize recv_buffer, // replydata 39000, // replydatasize 0, // errorclass NULL); // newphandle } } if (client) { ferr = msg_mon_close_process(TPT_REF(phandle)); TEST_CHK_FEOK(ferr); } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { bool client = false; unsigned expR3; int ferr; int inx; int lc; int lerr; int msgid; int oid; RT results; TPT_DECL (phandle); MS_SRE sre; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "", TA_End, TA_NOMAX, NULL } }; msfs_util_init(&argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = msg_mon_process_startup(!client); // system messages TEST_CHK_FEOK(ferr); if (client) { ferr = msg_mon_open_process((char *) "$srv", // name TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); } util_gethostname(my_name, sizeof(my_name)); lc = (int) (sizeof(res)/sizeof(Test_Results)); for (inx = 0; inx < lc; inx++) { if (client) { sprintf(send_buffer, "hello, greetings from %s, inx=%d", my_name, inx); ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid ctrl_buffer, // reqctrl res[inx].cQc, // reqctrlsize ctrl_buffer, // replyctrl res[inx].cPcM, // replyctrlmax send_buffer, // reqdata res[inx].cQd, // reqdatasize recv_buffer, // replydata res[inx].cPdM, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); // ferr = XMSG_ISDONE_(msgid); // checkdone("XMSG_ISDONE_", ferr); results.u.t.ctrl_size = (uint) -1; results.u.t.data_size = (uint) -1; results.u.t.errm = (uint) -1; ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); if (results.u.t.ctrl_size != res[inx].cEpC) { printf("*** ERROR inx=%d, results.ctrl_size=%d, cEpC=%d\n", inx, (int) results.u.t.ctrl_size, (int) res[inx].cEpC); assert(results.u.t.ctrl_size == res[inx].cEpC); } if (results.u.t.data_size != (uint) res[inx].cEpD) { printf("*** ERROR inx=%d, results.data_size=%d, cEpD=%d\n", inx, (int) results.u.t.data_size, (int) res[inx].cEpD); assert(results.u.t.data_size == res[inx].cEpD); } expR3 = 0x0; // no-data if (res[inx].cEpD > 0) expR3 |= 0x2; // data if (results.u.t.errm != expR3) { printf("*** ERROR inx=%d, results.errm=%x, expR3=%x\n", inx, results.u.t.errm, expR3); assert(results.u.t.errm == expR3); } } else { do { lerr = XWAIT(LREQ, -1); TEST_CHK_WAITIGNORE(lerr); lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag } while (lerr == XSRETYPE_NOWORK); if (sre.sre_reqCtrlSize != res[inx].sEqC) { printf("*** ERROR inx=%d, sre.sre_reqCtrlSize=%d, sEqC=%d\n", inx, sre.sre_reqCtrlSize, res[inx].sEqC); assert(sre.sre_reqCtrlSize == res[inx].sEqC); } if (sre.sre_reqDataSize != res[inx].sEqD) { printf("*** ERROR inx=%d, sre.sre_reqDataSize=%d, sEqD=%d\n", inx, sre.sre_reqDataSize, res[inx].sEqD); assert(sre.sre_reqDataSize == res[inx].sEqD); } ferr = XMSG_READCTRL_(sre.sre_msgId, // msgid ctrl_buffer, // reqctrl res[inx].sQc); // bytecount util_check("XMSG_READCTRL_", ferr); ferr = XMSG_READDATA_(sre.sre_msgId, // msgid recv_buffer, // reqdata res[inx].sQd); // bytecount util_check("XMSG_READDATA_", ferr); XMSG_REPLY_(sre.sre_msgId, // msgid (short *) recv_buffer, // replyctrl res[inx].sPc, // replyctrlsize recv_buffer, // replydata res[inx].sPd, // replydatasize 0, // errorclass NULL); // newphandle } } if (client) { ferr = msg_mon_close_process(TPT_REF(phandle)); TEST_CHK_FEOK(ferr); printf("if there were no asserts, all is well\n"); } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { bool client = false; int event_len; int ferr; int inx; int len; int lerr; int linx; int loop = 10; int msgid; int oid; TPT_DECL (phandle); RT results; int send_len; int srv_nid = -1; int srv_pid = -1; MS_SRE sre; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "", TA_End, TA_NOMAX, NULL } }; msfs_util_init(&argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = msg_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); if (client) { ferr = msg_mon_open_process((char *) "$srv", // name TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); ferr = msg_mon_get_process_info((char *) "$srv", &srv_nid, &srv_pid); TEST_CHK_FEOK(ferr); } util_gethostname(my_name, sizeof(my_name)); msg_mon_enable_mon_messages(true); for (inx = 0; inx < MS_MON_MAX_SYNC_DATA; inx++) event_data[inx] = (char) (inx + 1); for (inx = 0; inx < loop; inx++) { if (client) { sprintf(send_buffer, "hello, greetings from %s, inx=%d", my_name, inx); send_len = (int) strlen(send_buffer) + 1; ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid send_buffer2, // reqctrl (ushort) (inx & 1), // reqctrlsize recv_buffer3, // replyctrl 1, // replyctrlmax send_buffer, // reqdata (ushort) send_len, // reqdatasize recv_buffer, // replydata BUFSIZ, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); lerr = XWAIT(LDONE, 10); TEST_CHK_WAITIGNORE(lerr); assert(!XMSG_ISDONE_(msgid)); ferr = msg_mon_event_send(srv_nid, // nid srv_pid, // pid MS_ProcessType_Undefined, // process-type inx, // event-id inx % MS_MON_MAX_SYNC_DATA, // event-len event_data); // event-data TEST_CHK_FEOK(ferr); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); assert(results.u.t.ctrl_size == (uint) (inx & 1)); assert(results.u.t.data_size > (strlen(send_buffer) + 14)); assert(results.u.t.errm == RT_DATA_RCVD); // data printf("%s\n", recv_buffer); } else { do { lerr = XWAIT(LREQ, -1); lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag } while (lerr == XSRETYPE_NOWORK); ferr = XMSG_READCTRL_(sre.sre_msgId, // msgid recv_buffer2, // reqctrl 1); // bytecount util_check("XMSG_READCTRL_", ferr); ferr = XMSG_READDATA_(sre.sre_msgId, // msgid recv_buffer, // reqdata BUFSIZ); // bytecount util_check("XMSG_READDATA_", ferr); if (sre.sre_flags & XSRE_MON) { printf("server received mon message\n"); inx--; len = 0; } else { memset(event_data, 0, sizeof(event_data)); ferr = msg_mon_event_wait(inx, &event_len, event_data); TEST_CHK_FEOK(ferr); assert(event_len == (inx % MS_MON_MAX_SYNC_DATA)); for (linx = 0; linx < event_len; linx++) assert(event_data[linx] == (linx + 1)); strcat(recv_buffer, "- reply from "); strcat(recv_buffer, my_name); len = (int) strlen(recv_buffer) + 1; } XMSG_REPLY_(sre.sre_msgId, // msgid recv_buffer2, // replyctrl sre.sre_reqCtrlSize, // replyctrlsize recv_buffer, // replydata (ushort) len, // replydatasize 0, // errorclass NULL); // newphandle } } if (client) { ferr = msg_mon_close_process(TPT_REF(phandle)); TEST_CHK_FEOK(ferr); } else { ferr = msg_mon_process_close(); TEST_CHK_FEOK(ferr); } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { bool client = false; bool client1 = false; bool client2 = false; bool client3 = false; int ferr; int inx; int lerr; int loop = 10; int msgid; int oid; TPT_DECL (phandle); MS_Result_Type results; MS_SRE sre; MS_Mon_Transid_Type transid; TAD zargs[] = { { "-client1", TA_Bool, TA_NOMAX, &client1 }, { "-client2", TA_Bool, TA_NOMAX, &client2 }, { "-client3", TA_Bool, TA_NOMAX, &client3 }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "", TA_End, TA_NOMAX, NULL } }; msfs_util_init(&argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); if (client1) client = true; if (client2) client = true; if (client3) client = true; util_test_start(client); ferr = msg_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); if (client) { ferr = msg_mon_open_process((char *) "$srv", // name TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); } util_gethostname(my_name, sizeof(my_name)); if (client) { if (client1) sleep(5); else if (client2) { util_abort_core_free(); } else { ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid NULL, // reqctrl 0, // reqctrlsize NULL, // replyctrl 0, // replyctrlmax send_buffer, // reqdata 0, // reqdatasize recv_buffer, // replydata 0, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); ferr = XMSG_BREAK_(msgid, (short *) &results, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); } } else { msg_mon_enable_mon_messages(true); for (inx = 0; inx < 7; inx++) { do { lerr = XWAIT(LREQ, -1); TEST_CHK_WAITIGNORE(lerr); lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag } while (lerr == XSRETYPE_NOWORK); ferr = XMSG_READDATA_(sre.sre_msgId, // msgid recv_buffer, // reqdata 40000); // bytecount util_check("XMSG_READDATA_", ferr); if (sre.sre_flags & XSRE_MON) { MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer; if (msg->type == MS_MsgType_Open) { if (strcasecmp(msg->u.open.target_process_name, "$cli2") == 0) { transid.id[0] = -1; transid.id[1] = -1; transid.id[2] = -1; transid.id[3] = -1; ferr = msg_mon_deregister_death_notification(-1, // msg->u.open.nid, -1, // msg->u.open.pid, transid); TEST_CHK_FEOK(ferr); } } printf("server reply type=%d, inx=%d\n", msg->type, inx); } else printf("server reply inx=%d\n", inx); XMSG_REPLY_(sre.sre_msgId, // msgid NULL, // replyctrl 0, // replyctrlsize recv_buffer, // replydata 0, // replydatasize 0, // errorclass NULL); // newphandle } } if (client) { ferr = msg_mon_close_process(TPT_REF(phandle)); TEST_CHK_FEOK(ferr); } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { bool chook = false; bool client = false; FILE *f; bool fail = false; int ferr; int lerr; int msgid; int oid; TPT_DECL (phandle); MS_Result_Type results; MS_SRE sre; TAD zargs[] = { { "-chook", TA_Bool, TA_NOMAX, &chook }, { "-client", TA_Bool, TA_NOMAX, &client }, { "-cluster", TA_Ign, TA_NOMAX, NULL }, { "-fail", TA_Bool, TA_NOMAX, &fail }, { "-verbose", TA_Ign, TA_NOMAX, NULL }, { "", TA_End, TA_NOMAX, NULL } }; arg_proc_args(zargs, false, argc, argv); if (chook) test_debug_hook("c", "c"); util_test_start(true); if (client) { f = NULL; while (f == NULL) { f = fopen("z100", "r"); if (f == NULL) sleep(1); } fclose(f); } if (client) ferr = msg_init_attach(&argc, &argv, true, (char *) "$CLI"); else ferr = msg_init(&argc, &argv); TEST_CHK_FEOK(ferr); ferr = msg_mon_process_startup(!client); // system messages TEST_CHK_FEOK(ferr); if (client) { ferr = msg_mon_open_process((char *) "$SRV", TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); if (fail) util_abort_core_free(); ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid NULL, // reqctrl 0, // reqctrlsize recv_buffer3, // replyctrl 0, // replyctrlmax NULL, // reqdata 0, // reqdatasize recv_buffer, // replydata 0, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts TEST_CHK_FEOK(ferr); ferr = XMSG_BREAK_(msgid, (short *) &results, TPT_REF(phandle)); TEST_CHK_FEOK(ferr); } else { f = fopen("z100", "w"); assert(f != NULL); fclose(f); for (;;) { do { lerr = XWAIT(LREQ, 20); TEST_CHK_WAITIGNORE(lerr); if (!lerr) continue; lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag } while (lerr == XSRETYPE_NOWORK); if (sre.sre_flags & XSRE_MON) printf("server received mon message\n"); else printf("server received regular message\n"); XMSG_REPLY_(sre.sre_msgId, // msgid recv_buffer2, // replyctrl 0, // replyctrlsize recv_buffer, // replydata 0, // replydatasize 0, // errorclass NULL); // newphandle if ((sre.sre_flags & XSRE_MON) == 0) break; } } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(true); return 0; }
int main(int argc, char *argv[]) { bool client = false; int disable; int ferr; int inx; int lerr; int loop = 10; int msgid; int oid; TPT_DECL (phandle); RT results; MS_SRE sre; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "", TA_End, TA_NOMAX, NULL } }; msfs_util_init(&argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = msg_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); if (client) { ferr = msg_mon_open_process((char *) "$srv", // name TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); } util_gethostname(my_name, sizeof(my_name)); if (client) { for (inx = 0; inx < loop; inx++) { disable = msg_test_assert_disable(); ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid NULL, // reqctrl 0, // reqctrlsize NULL, // replyctrl 0, // replyctrlmax send_buffer, // reqdata 0, // reqdatasize recv_buffer, // replydata 0, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); assert(ferr); msg_test_assert_enable(disable); } } else { msg_mon_enable_mon_messages(true); do { lerr = XWAIT(LREQ, -1); TEST_CHK_WAITIGNORE(lerr); lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag } while (lerr == XSRETYPE_NOWORK); XMSG_REPLY_(sre.sre_msgId, // msgid NULL, // replyctrl 0, // replyctrlsize recv_buffer, // replydata 0, // replydatasize 0, // errorclass NULL); // newphandle util_abort_core_free(); } if (client) { ferr = msg_mon_close_process(TPT_REF(phandle)); TEST_CHK_FEOK(ferr); } else { ferr = msg_mon_process_close(); TEST_CHK_FEOK(ferr); } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { bool client = false; bool disable = false; int ferr; int lerr; int msgid; int oid; TPT_DECL (phandle); RT results; MS_SRE sre; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "", TA_End, TA_NOMAX, NULL } }; msfs_util_init(&argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = msg_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); if (client) { ferr = msg_mon_open_process((char *) "$srv", // name TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); } util_gethostname(my_name, sizeof(my_name)); if (client) { sprintf(send_buffer, "hello, greetings from %s", my_name); ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid NULL, // reqctrl 0, // reqctrlsize NULL, // replyctrl 0, // replyctrlmax send_buffer, // reqdata 39000, // reqdatasize recv_buffer, // replydata 40000, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); disable = msg_test_assert_disable(); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); msg_test_assert_enable(disable); assert(ferr == XZFIL_ERR_PATHDOWN); disable = msg_test_assert_disable(); ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid NULL, // reqctrl 0, // reqctrlsize NULL, // replyctrl 0, // replyctrlmax send_buffer, // reqdata 39000, // reqdatasize recv_buffer, // replydata 40000, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); msg_test_assert_enable(disable); ferr = XMSG_ABANDON_(msgid); util_check("XMSG_ABANDON_", ferr); } else { for (;;) { do { lerr = XWAIT(LREQ, -1); TEST_CHK_WAITIGNORE(lerr); lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag } while (lerr == XSRETYPE_NOWORK); util_abort_core_free(); } } if (client) { ferr = msg_mon_close_process(TPT_REF(phandle)); TEST_CHK_FEOK(ferr); } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { bool client = false; int ferr; int inx; int len; int lerr; int loop = 10; int msgid; TPT_DECL2 (phandle,MAX_SERVERS); bool rand = false; RT results; int send_len; MS_SRE sre; MS_SRE_LDONE sre_ldone; int srv; int srv2; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-rand", TA_Bool, TA_NOMAX, &rand }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "", TA_End, TA_NOMAX, NULL } }; msfs_util_init(&argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = msg_mon_process_startup(!client); // system messages TEST_CHK_FEOK(ferr); if (client) { for (srv = 0; srv < MAX_SERVERS; srv++) { sprintf(name, "$srv%d", srv); ferr = msg_mon_open_process(name, TPT_REF2(phandle,srv), &oid[srv]); TEST_CHK_FEOK(ferr); } } util_gethostname(my_name, sizeof(my_name)); if (client) { for (inx = 0; inx < loop; inx++) { for (srv = 0; srv < MAX_SERVERS; srv++) { sprintf(send_buffer[srv], "hello, greetings from %s, inx=%d, srv=%d", my_name, inx, srv); send_len = (int) strlen(send_buffer[srv]) + 1; ferr = XMSG_LINK_(TPT_REF2(phandle,srv), // phandle &msgid, // msgid send_buffer2, // reqctrl (ushort) (inx & 1), // reqctrlsize recv_buffer3[srv], // replyctrl 1, // replyctrlmax send_buffer[srv], // reqdata (ushort) send_len, // reqdatasize recv_buffer[srv], // replydata BUFSIZ, // replydatamax (SB_Tag_Type) send_buffer[srv], // linkertag 0, // pri 0, // xmitclass XMSG_LINK_LDONEQ); // linkopts util_check("XMSG_LINK_", ferr); } for (srv = 0; srv < MAX_SERVERS;) { if (rand) util_time_sleep_ms(rnd()); lerr = XWAIT(LDONE, -1); TEST_CHK_WAITIGNORE(lerr); for (;;) { lerr = XMSG_LISTEN_((short *) &sre_ldone, // sre 0, // listenopts 0); // listenertag if (lerr == XSRETYPE_NOWORK) break; srv++; assert(lerr == XSRETYPE_LDONE); for (srv2 = 0; srv2 < MAX_SERVERS; srv2++) { if (sre_ldone.sre_linkTag == (SB_Tag_Type) send_buffer[srv2]) break; } assert(srv2 < MAX_SERVERS); ferr = XMSG_BREAK_(sre_ldone.sre_msgId, results.u.s, TPT_REF2(phandle,srv2)); util_check("XMSG_BREAK_", ferr); assert(results.u.t.ctrl_size == (uint) (inx & 1)); assert(results.u.t.data_size > (strlen(send_buffer[srv2]) + 14)); assert(results.u.t.errm == RT_DATA_RCVD); // data printf("%s\n", recv_buffer[srv2]); } } } } else { for (inx = 0; inx < loop;) { lerr = XWAIT(LREQ, -1); lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag if (lerr == XSRETYPE_NOWORK) continue; inx++; ferr = XMSG_READCTRL_(sre.sre_msgId, // msgid recv_buffer2, // reqctrl 1); // bytecount util_check("XMSG_READCTRL_", ferr); ferr = XMSG_READDATA_(sre.sre_msgId, // msgid recv_buffer4, // reqdata BUFSIZ); // bytecount util_check("XMSG_READDATA_", ferr); strcat(recv_buffer4, "- reply from "); strcat(recv_buffer4, my_name); len = (int) strlen(recv_buffer4) + 1; if (rand) util_time_sleep_ms(rnd()); XMSG_REPLY_(sre.sre_msgId, // msgid recv_buffer2, // replyctrl sre.sre_reqCtrlSize, // replyctrlsize recv_buffer4, // replydata (ushort) len, // replydatasize 0, // errorclass NULL); // newphandle } } if (client) { for (srv = 0; srv < MAX_SERVERS; srv++) { ferr = msg_mon_close_process(TPT_REF2(phandle,srv)); TEST_CHK_FEOK(ferr); } } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { char *args[4]; bool attach = false; bool chook = false; bool client = false; bool clientd = false; int cli_nid = -1; int cli_pid = -1; const char *cname = "$cli"; int count; int ferr; int inx; int len; int lerr; int loop = 10; TPT_DECL (mphandle); char *mphandlec = (char *) &mphandle; TPT_DECL_INT (mphandlei); int msgid; int my_mon_nid; int my_mon_pid; int my_mon_ptype; int my_mon_zid; int my_os_pid; long my_os_tid; int my_compid; int my_pnid; int my_segid; int nid; int oid; TPT_DECL (phandle); int pid; char *pname = NULL; int ptype; RT results; int scollpid = -1; int scompid = -1; int send_len; bool shook = false; const char *sname = "$srv"; bool sonar = false; MS_SRE sre; int srv_nid = -1; int srv_pid = -1; MS_Mon_Monitor_Stats_Type stats; int status; long t_elapsed; struct timeval t_start; struct timeval t_stop; int tm_seq; bool val_bool; int val_int; const char *val_str; int winx; pid_t wpid; TAD zargs[] = { { "-attach", TA_Bool, TA_NOMAX, &attach }, { "-chook", TA_Bool, TA_NOMAX, &chook }, { "-client", TA_Bool, TA_NOMAX, &client }, { "-clientd", TA_Bool, TA_NOMAX, &clientd }, { "-cname", TA_Str, TA_NOMAX, &cname }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-name", TA_Str, TA_NOMAX, &pname }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "-shook", TA_Bool, TA_NOMAX, &shook }, { "-sname", TA_Str, TA_NOMAX, &sname }, { "-sonar", TA_Bool, TA_NOMAX, &sonar }, { "", 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 (client && chook) test_debug_hook("c", "c"); if (!client && shook) test_debug_hook("s", "s"); setenv("TESTKEYBOOL", "1", 1); setenv("TESTKEYINT", "44", 1); setenv("TESTKEYSTR", "TESTVALSTR", 1); // // test msg_getenv* before msg_init // val_bool = true; msg_getenv_bool("TESTKEYBOOL", &val_bool); assert(val_bool); val_bool = false; msg_getenv_bool("TESTKEYBOOL", &val_bool); assert(!val_bool); val_int = 0; msg_getenv_int("TESTKEYINT", &val_int); assert(val_int == 0); val_int = 1; msg_getenv_int("TESTKEYINT", &val_int); assert(val_int == 1); val_str = (const char *) 1; val_str = msg_getenv_str("TESTKEYSTR"); assert(val_str == NULL); if (attach) msfs_util_init_attach(&argc, &argv, msg_debug_hook, false, pname); else msfs_util_init(&argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); util_time_timer_start(&t_start); util_test_start(client); ferr = msg_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); // // test msg_getenv* after msg_init // msg_getenv_bool("TESTKEYBOOL", &val_bool); assert(val_bool); msg_getenv_int("TESTKEYINT", &val_int); assert(val_int == 44); val_str = msg_getenv_str("TESTKEYSTR"); assert(strcmp(val_str, "TESTVALSTR") == 0); // process-wait for server/shell ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, 2, NULL, false); TEST_CHK_FEOK(ferr); // process-wait for client ferr = msfs_util_wait_process_count(MS_ProcessType_TSE, 1, NULL, false); TEST_CHK_FEOK(ferr); if (client) { if (sonar) { scollpid = fork(); if (scollpid == 0) { // child args[0] = (char *) "sonarcollector"; args[1] = (char *) "-i"; // sampling interval // cast args[2] = (char *) "1"; // cast args[3] = NULL; lerr = execvp(args[0], args); assert(lerr == 0); } } ferr = msg_mon_open_process((char *) sname, // name TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); } // this phandle check assumed a particular data structure ferr = msg_mon_get_my_process_name(my_name, BUFSIZ); util_check("msg_mon_get_my_process_name", 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\n", mphandlei[0], mphandlei[1], mphandlei[2], mphandlei[3], mphandlei[4]); ferr = msg_mon_get_my_info(&my_mon_nid, &my_mon_pid, my_mon_name, BUFSIZ, &my_mon_ptype, &my_mon_zid, &my_os_pid, &my_os_tid); util_check("msg_mon_get_my_info", ferr); printf("nid=%d, pid=%d, name=%s, ptype=%d, zid=%d, os-pid=%d, os-tid=%ld\n", my_mon_nid, my_mon_pid, my_mon_name, my_mon_ptype, my_mon_zid, my_os_pid, my_os_tid); my_mon_nid = -1; my_mon_pid = -1; my_mon_ptype = -1; my_mon_zid = -1; my_os_pid = -1; my_os_tid = -1; my_compid = -1; my_pnid = -1; ferr = msg_mon_get_my_info3(&my_mon_nid, &my_mon_pid, my_mon_name3, BUFSIZ, &my_mon_ptype, &my_mon_zid, &my_os_pid, &my_os_tid, &my_compid, &my_pnid); util_check("msg_mon_get_my_info3", ferr); printf("nid=%d, pid=%d, name=%s, ptype=%d, zid=%d, os-pid=%d, os-tid=%ld, compid=%d, pnid=%d\n", my_mon_nid, my_mon_pid, my_mon_name3, my_mon_ptype, my_mon_zid, my_os_pid, my_os_tid, my_compid, my_pnid); ferr = msg_mon_get_my_segid(&my_segid); util_check("msg_mon_get_my_segid", ferr); printf("segid=%d\n", my_segid); ferr = msg_mon_get_monitor_stats(&stats); util_check("msg_mon_get_monitor_stats", ferr); printf("avail_min=%d, acquired_max=%d, buf_misses=%d\n", stats.avail_min, stats.acquired_max, stats.buf_misses); util_gethostname(my_name, sizeof(my_name)); msg_mon_enable_mon_messages(true); ferr = msg_mon_get_tm_seq(&tm_seq); util_check("msg_mon_get_tm_seq", ferr); printf("tm_seq=%d\n", tm_seq); if (client) { ferr = msg_mon_get_process_info_type(MS_ProcessType_TSE, &count, 0, NULL); TEST_CHK_FEOK(ferr); if (!attach) assert(count == 1); ferr = msg_mon_get_process_info_type(MS_ProcessType_TSE, &count, 1, info); TEST_CHK_FEOK(ferr); if (!attach) assert(count == 1); } for (inx = 0; inx < loop; inx++) { if (client) { sprintf(send_buffer, "hello, greetings from %s, inx=%d", my_name, inx); send_len = (int) strlen(send_buffer) + 1; ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid send_buffer2, // reqctrl (ushort) (inx & 1), // reqctrlsize recv_buffer3, // replyctrl 1, // replyctrlmax send_buffer, // reqdata (ushort) send_len, // reqdatasize recv_buffer, // replydata BUFSIZ, // replydatamax 0, // linkertag (short) (inx+1), // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); assert(results.u.t.ctrl_size == (uint) (inx & 1)); assert(results.u.t.data_size > (strlen(send_buffer) + 14)); assert(results.u.t.errm == RT_DATA_RCVD); // data printf("%s\n", recv_buffer); } else { do { lerr = XWAIT(LREQ, -1); TEST_CHK_WAITIGNORE(lerr); lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag } while (lerr == XSRETYPE_NOWORK); ferr = XMSG_GETREQINFO_(MSGINFO_NID, sre.sre_msgId, &nid); util_check("XMSG_GETREQINFO_", ferr); ferr = XMSG_GETREQINFO_(MSGINFO_PID, sre.sre_msgId, &pid); util_check("XMSG_GETREQINFO_", ferr); ferr = XMSG_GETREQINFO_(MSGINFO_PTYPE, sre.sre_msgId, &ptype); util_check("XMSG_GETREQINFO_", ferr); if (sre.sre_flags & XSRE_MON) { // mon messages have our nid/pid if (srv_nid < 0) { ferr = msg_mon_get_process_info((char *) "", &srv_nid, &srv_pid); TEST_CHK_FEOK(ferr); } if (!clientd) { assert(nid == srv_nid); assert(pid == srv_pid); } } else { assert(sre.sre_pri == ((inx+1) & 0xffff)); if (cli_nid < 0) { ferr = msg_mon_get_process_info((char *) cname, &cli_nid, &cli_pid); TEST_CHK_FEOK(ferr); } if (!attach) assert(ptype == MS_ProcessType_TSE); assert(nid == cli_nid); assert(pid == cli_pid); } ferr = XMSG_READCTRL_(sre.sre_msgId, // msgid recv_buffer2, // reqctrl 1); // bytecount util_check("XMSG_READCTRL_", ferr); ferr = XMSG_READDATA_(sre.sre_msgId, // msgid recv_buffer, // reqdata BUFSIZ); // bytecount util_check("XMSG_READDATA_", ferr); if (sre.sre_flags & XSRE_MON) { printf("server received mon message\n"); inx--; len = 0; if (clientd) { MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer; if (msg->type == MS_MsgType_Close) inx = loop; } } else { strcat(recv_buffer, "- reply from "); strcat(recv_buffer, my_name); len = (int) strlen(recv_buffer) + 1; } XMSG_REPLY_(sre.sre_msgId, // msgid recv_buffer2, // replyctrl sre.sre_reqCtrlSize, // replyctrlsize recv_buffer, // replydata (ushort) len, // replydatasize 0, // errorclass NULL); // newphandle } } if (sonar) { if (client) { // for some reason [monitor?], one 'sonarcom stop' doesn't stop coll for (winx = 0; winx < 20; winx++) { scompid = fork(); if (scompid == 0) { // child args[0] = (char *) "sonarcom"; args[1] = (char *) "stop"; args[2] = NULL; lerr = execvp(args[0], args); assert(lerr == 0); } wpid = waitpid(scompid, &status, 0); assert(wpid == scompid); wpid = waitpid(scollpid, &status, WNOHANG); if (wpid == scollpid) break; else sleep(1); } assert(wpid == scollpid); ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid NULL, // reqctrl 0, // reqctrlsize NULL, // replyctrl 0, // replyctrlmax NULL, // reqdata 0, // reqdatasize NULL, // replydata 0, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts TEST_CHK_FEOK(ferr); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); TEST_CHK_FEOK(ferr); } else { do { lerr = XWAIT(LREQ, -1); lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag } while (lerr == XSRETYPE_NOWORK); XMSG_REPLY_(sre.sre_msgId, // msgid NULL, // replyctrl 0, // replyctrlsize NULL, // replydata 0, // replydatasize 0, // errorclass NULL); // newphandle } } if (client) { ferr = msg_mon_close_process(TPT_REF(phandle)); TEST_CHK_FEOK(ferr); } else { if (!clientd) { ferr = msg_mon_process_close(); TEST_CHK_FEOK(ferr); } } util_time_timer_stop(&t_stop); t_elapsed = (t_stop.tv_sec * 1000000 + t_stop.tv_usec) - (t_start.tv_sec * 1000000 + t_start.tv_usec); ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); if (client) { printf("elapsed time (gettimeofday us)=%ld\n", t_elapsed); } return 0; }
int main(int argc, char *argv[]) { int cycle; int disable; int ferr; #ifndef USE_OPEN int lnid; int lpid; #endif int msgid; char process_name[MS_MON_MAX_PROCESS_NAME]; char recvbuf[100]; MS_Result_Type results; int retries; int sendbuf[3]; ferr = msfs_util_init_role(true, &argc, &argv, msg_debug_hook); TEST_CHK_FEOK(ferr); ferr = msg_mon_get_my_process_name(gdisplay_name, sizeof(gdisplay_name)); assert(ferr == XZFIL_ERR_OK); myprintf("processing startup.\n"); util_test_start(true); ferr = msg_mon_process_startup(true); // system messages TEST_CHK_FEOK(ferr); ferr = msg_mon_get_process_info(gdisplay_name, &gnid, &gpid); TEST_CHK_FEOK(ferr); strcpy(process_name, "$srv"); myprintf("opening server %s.\n", process_name); #ifdef USE_OPEN ferr = msg_mon_open_process(process_name, TPT_REF(gserver_phandle), &gserver_oid); TEST_CHK_FEOK(ferr); #else gserver_phandlep = msg_get_phandle(process_name); assert(gserver_phandlep != NULL); #endif // do the work myprintf("Starting work with server\n"); disable = msg_test_assert_disable(); for (cycle = 0; cycle < MAX_CYCLES + 1; cycle++) { sendbuf[0] = gpid; sendbuf[1] = cycle; switch (cycle) { case 5: sendbuf[2] = CMD_ABORT; break; case 6: sendbuf[2] = CMD_CP_AB; break; case MAX_CYCLES: sendbuf[2] = CMD_END; break; default: sendbuf[2] = CMD_CONT; } retries = 5; do { myprintf("sending %d.%d.%d to server\n", sendbuf[0], sendbuf[1], sendbuf[2]); #ifdef USE_OPEN ferr = XMSG_LINK_(TPT_REF(gserver_phandle), // phandle #else ferr = XPROCESSHANDLE_DECOMPOSE_(gserver_phandlep, &lnid, &lpid); assert(ferr == XZFIL_ERR_OK); printf("phandle nid=%d, pid=%d\n", lnid, lpid); ferr = XMSG_LINK_(gserver_phandlep, // phandle #endif &msgid, // msgid NULL, // reqctrl 0, // reqctrlsize NULL, // replyctrl 0, // replyctrlmax (char *) sendbuf, // reqdata sizeof(sendbuf), // reqdatasize recvbuf, // replydata sizeof(recvbuf), // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts TEST_CHK_FEOK(ferr); ferr = XMSG_BREAK_(msgid, (short *) &results, #ifdef USE_OPEN TPT_REF(gserver_phandle)); #else gserver_phandlep); #endif if (ferr == XZFIL_ERR_OK) myprintf("Cycle # %d - %s\n", cycle, recvbuf); else myprintf("XMSG_BREAK_ error ferr=%d\n", ferr); if (ferr != XZFIL_ERR_OK) { retries--; sleep(1); if (retries <= 0) { myprintf("retries exhausted\n"); assert(retries > 0); } myprintf("retrying\n"); } else retries = 0; } while (retries > 0); } msg_test_assert_enable(disable); // close the server processes myprintf("closing server %s.\n", process_name); #ifdef USE_OPEN ferr = msg_mon_close_process(TPT_REF(gserver_phandle)); #else ferr = msg_mon_close_process(gserver_phandlep); #endif TEST_CHK_FEOK(ferr); myprintf("sending exit process message.\n"); ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(true); return 0; }
int main(int argc, char *argv[]) { SB_Array<int> array(MAX_OUT); int client = false; int disable = 0; int ferr; int inx; int lerr; int linker = false; int listener = false; int oid; int req_ctrl_size; int req_data_size; int rep_ctrl_size; int rep_data_size; RT results; TPT_DECL (phandle); TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-linker", TA_Bool, TA_NOMAX, &linker }, { "-listener", TA_Bool, TA_NOMAX, &listener }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "", TA_End, TA_NOMAX, NULL } }; msfs_util_init(&argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = msg_mon_process_startup(!client); // system messages TEST_CHK_FEOK(ferr); if (client) { ferr = msg_mon_open_process((char *) "$srv", // name TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); for (inx = 0; inx < MAX_OUT; inx++) { req_ctrl_size = (inx + 1) % MAX_DATA; req_data_size = (inx + 2) % MAX_DATA; ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgids[inx], // msgid send_cli_c_buffer[inx], // reqctrl (ushort) req_ctrl_size, // reqctrlsize recv_cli_c_buffer[inx], // replyctrl (ushort) MAX_DATA, // replyctrlmax send_cli_d_buffer[inx], // reqdata (ushort) req_data_size, // reqdatasize recv_cli_d_buffer[inx], // replydata (ushort) MAX_DATA, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); } if (linker) { sleep(1); util_abort_core_free(); } for (inx = 0; inx < MAX_OUT; inx++) { array.add(); array.set_val(inx, inx); } for (inx = 0; inx < MAX_OUT; inx++) { int rnd = (int) (1.0 * array.get_size() * rand_r(&seed) / (RAND_MAX + 1.0)); int xinx = array.get_val(rnd); array.remove(rnd); rep_ctrl_size = (xinx + 3) % MAX_DATA; rep_data_size = (xinx + 4) % MAX_DATA; if (listener) disable = msg_test_assert_disable(); ferr = XMSG_BREAK_(msgids[xinx], results.u.s, TPT_REF(phandle)); if (listener) { assert(ferr == XZFIL_ERR_PATHDOWN); msg_test_assert_enable(disable); } else { util_check("XMSG_BREAK_", ferr); assert(results.u.t.ctrl_size == (unsigned short) rep_ctrl_size); assert(results.u.t.data_size == (unsigned short) rep_data_size); } } printf("if there were no asserts, all is well\n"); } else { for (inx = 0; inx < MAX_OUT; inx++) { lerr = XWAIT(LREQ, -1); TEST_CHK_WAITIGNORE(lerr); do { lerr = XMSG_LISTEN_((short *) &sres[inx], // sre 0, // listenopts 0); // listenertag if (lerr == XSRETYPE_NOWORK) util_time_sleep_ms(1); } while (lerr == XSRETYPE_NOWORK); } for (inx = 0; inx < MAX_OUT; inx++) { array.add(); array.set_val(inx, inx); } for (inx = 0; inx < MAX_OUT; inx++) { int rnd = (int) (1.0 * array.get_size() * rand_r(&seed) / (RAND_MAX + 1.0)); int xinx = array.get_val(rnd); array.remove(rnd); req_ctrl_size = (xinx + 1) % MAX_DATA; req_data_size = (xinx + 2) % MAX_DATA; assert(req_ctrl_size == sres[xinx].sre_reqCtrlSize); assert(req_data_size == sres[xinx].sre_reqDataSize); ferr = XMSG_READCTRL_(sres[xinx].sre_msgId, // msgid recv_srv_c_buffer[xinx], // reqctrl sres[xinx].sre_reqCtrlSize); // bytecount util_check("XMSG_READCTRL_", ferr); ferr = XMSG_READDATA_(sres[xinx].sre_msgId, // msgid recv_srv_d_buffer[xinx], // reqdata sres[xinx].sre_reqDataSize); // bytecount util_check("XMSG_READDATA_", ferr); } for (inx = 0; inx < MAX_OUT; inx++) { array.add(); array.set_val(inx, inx); } if (linker) sleep(1); if (listener) util_abort_core_free(); for (inx = 0; inx < MAX_OUT; inx++) { int rnd = (int) (1.0 * array.get_size() * rand_r(&seed) / (RAND_MAX + 1.0)); int xinx = array.get_val(rnd); array.remove(rnd); rep_ctrl_size = (xinx + 3) % MAX_DATA; rep_data_size = (xinx + 4) % MAX_DATA; XMSG_REPLY_(sres[xinx].sre_msgId, // msgid recv_srv_c_buffer[xinx], // replyctrl (ushort) rep_ctrl_size, // replyctrlsize recv_srv_d_buffer[xinx], // replydata (ushort) rep_data_size, // replydatasize 0, // errorclass NULL); // newphandle } } if (client) { ferr = msg_mon_close_process(TPT_REF(phandle)); TEST_CHK_FEOK(ferr); } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); if (linker) util_test_finish(!client); else util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { bool client = false; int client_mon; int cnid = -1; bool commit_rcvd = false; int cpid = -1; int disable; bool done = false; int event_len; int ferr; int first; int handle; int inx; int len; int lerr; int loop = 10; int msgid; int nid; bool open_rcvd = false; int orig_tag; TPT_DECL2 (phandle,MAX_SERVERS); int pid; int pinx; RT results; int send_len; MS_SRE sre; int status; bool sync = false; bool threaded = false; bool verbose = false; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-quiet", TA_Bool, TA_NOMAX, &quiet }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "-sync", TA_Bool, TA_NOMAX, &sync }, { "-threaded", TA_Bool, TA_NOMAX, &threaded }, { "-v", TA_Bool, TA_NOMAX, &verbose }, { "", TA_End, TA_NOMAX, NULL } }; msfs_util_init(&argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = msg_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); sleep(1); // wait for client to get into msg_mon_process_info ferr = msg_mon_get_my_process_name(pname, sizeof(pname)); TEST_CHK_FEOK(ferr); if (strcasecmp(pname, "$tm0") == 0) tag = TAG0; else if (strcasecmp(pname, "$tm1") == 0) tag = TAG1; else tag = TAG2; ferr = msg_mon_get_process_info(NULL, &snid, &spid); TEST_CHK_FEOK(ferr); if (client) { char serv[BUFSIZ]; for (pinx = 0; pinx < MAX_SERVERS; pinx++) { sprintf(serv, "$tm%d", pinx); ferr = msg_mon_open_process(serv, // name TPT_REF2(phandle,pinx), &oid[pinx]); TEST_CHK_FEOK(ferr); } } else { first = (strcasecmp(pname, "$tm0") == 0); disable = msg_test_assert_disable(); ferr = msg_mon_tm_leader_set(&nid, &pid, lname); msg_test_assert_enable(disable); if (first) { TEST_CHK_FEOK(ferr); } else assert(ferr != XZFIL_ERR_OK); printf("leader is p-id=%d/%d, name=%s\n", nid, pid, lname); } util_gethostname(my_name, sizeof(my_name)); msg_mon_enable_mon_messages(true); if (!client) { ferr = msg_mon_event_wait(1, &event_len, event_data); util_check("msg_mon_event_wait", ferr); ferr = msg_mon_tmsync_register(tmsync_cb); util_check("msg_mon_tmsync_register", ferr); if (sync) { char serv[BUFSIZ]; for (pinx = 0; pinx < MAX_SERVERS; pinx++) { sprintf(serv, "$tm%d", pinx); if (strcasecmp(serv, pname) != 0) { ferr = msg_mon_open_process(serv, // name TPT_REF2(phandle,pinx), &oid[pinx]); TEST_CHK_FEOK(ferr); } } // at this point, we know everyone is registered // if everyone isn't registered, there will be an abort do_sync(); if (threaded) do_sync_threaded(); } } if (client) { for (inx = 0; inx < loop; inx++) { sprintf(send_buffer, "hello, greetings from %s, inx=%d", my_name, inx); send_len = (int) strlen(send_buffer) + 1; for (pinx = 0; pinx < MAX_SERVERS; pinx++) { if (verbose) printf("%s: sending message, pinx=%d, inx=%d\n", pname, pinx, inx); ferr = XMSG_LINK_(TPT_REF2(phandle,pinx), // phandle &msgid, // msgid send_buffer2, // reqctrl (ushort) (inx & 1), // reqctrlsize recv_buffer3, // replyctrl 1, // replyctrlmax send_buffer, // reqdata (ushort) send_len, // reqdatasize recv_buffer, // replydata BUFSIZ, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF2(phandle,pinx)); util_check("XMSG_BREAK_", ferr); assert(results.u.t.ctrl_size == (uint) (inx & 1)); assert(results.u.t.data_size > (strlen(send_buffer) + 14)); assert(results.u.t.errm == RT_DATA_RCVD); // data if (!quiet) printf("%s\n", recv_buffer); } } for (pinx = 0; pinx < MAX_SERVERS; pinx++) { ferr = msg_mon_close_process(TPT_REF2(phandle,pinx)); TEST_CHK_FEOK(ferr); } } else { inx = 0; while (!done) { lerr = XWAIT(LREQ, -1); TEST_CHK_WAITIGNORE(lerr); for (;;) { lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag if (lerr == XSRETYPE_NOWORK) break; ferr = XMSG_READCTRL_(sre.sre_msgId, // msgid recv_buffer2, // reqctrl 1); // bytecount util_check("XMSG_READCTRL_", ferr); ferr = XMSG_READDATA_(sre.sre_msgId, // msgid recv_buffer, // reqdata BUFSIZ); // bytecount util_check("XMSG_READDATA_", ferr); if (sre.sre_flags & XSRE_MON) { MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer; if (cnid < 0) { ferr = msg_mon_get_process_info((char *) "$cli", &cnid, &cpid); if (ferr != XZFIL_ERR_OK) { cnid = -1; cpid = -1; } } client_mon = true; Item *item_hdl; Item *item_tag; const char *type; switch (msg->type) { case MS_MsgType_Close: type = "close"; if ((cnid == msg->u.close.nid) && (cpid == msg->u.close.pid)) { } else client_mon = false; break; case MS_MsgType_NodeDown: type = "node-down"; break; case MS_MsgType_Open: type = "open"; if ((cnid == msg->u.open.nid) && (cpid == msg->u.open.pid)) open_rcvd = true; else client_mon = false; break; case MS_MsgType_ProcessDeath: type = "process-death"; break; case MS_MsgType_Shutdown: type = "shutdown"; done = true; break; case MS_MsgType_TmSyncAbort: case MS_MsgType_TmSyncCommit: if (msg->type == MS_MsgType_TmSyncAbort) type = "tmsync-abort"; else type = "tmsync-commit"; nid = msg->u.tmsync.nid[0]; handle = msg->u.tmsync.handle[0]; if (msg->u.tmsync.orig_count == 0) { msg->u.tmsync.orig_tag[0] = -1; msg->u.tmsync.orig_handle[0] = -1; } orig_tag = msg->u.tmsync.orig_tag[0]; if (!quiet) { printf("server (%s) received (%s) mon message, type=%s(%d), nid=%d\n", pname, client_mon ? "cli" : "dtm", type, msg->type, nid); printf(" orig_count=%d, orig_tag=%d, orig_handle=%d, count=%d, handle[0]=%d\n", msg->u.tmsync.orig_count, orig_tag, msg->u.tmsync.orig_handle[0], msg->u.tmsync.count, handle); } if (nid == snid) { if (!quiet) printf("server (%s) commit handle=%d, orig-count=%d\n", pname, handle, msg->u.tmsync.orig_count); for (int inx2 = 0; inx2 < msg->u.tmsync.count; inx2++) { int ltag = msg->u.tmsync.orig_tag[inx2]; int lhandle = msg->u.tmsync.orig_handle[inx2]; if (!quiet) printf("server (%s) commit orig-tag/handle=%d/%d\n", pname, ltag, lhandle); item_tag = (Item *) tag_issue_map.remove(ltag); assert(item_tag != NULL); delete item_tag; item_hdl = (Item *) handle_issue_map.remove(lhandle); assert(item_hdl != NULL); delete item_hdl; } } else { assert(msg->u.tmsync.orig_count == 0); } commit_rcvd = true; break; default: type = "<unknown>"; } if (!quiet) printf("server (%s) received (%s) mon message, type=%s(%d)\n", pname, client_mon ? "cli" : "dtm", type, msg->type); len = 0; } else { inx++; if (verbose) printf("%s: received non-mon message, inx=%d\n", pname, inx); if (!sync) assert(sync_rcvd); assert(commit_rcvd); assert(open_rcvd); strcat(recv_buffer, "- reply from "); strcat(recv_buffer, my_name); strcat(recv_buffer, " - "); strcat(recv_buffer, pname); len = (int) strlen(recv_buffer) + 1; } XMSG_REPLY_(sre.sre_msgId, // msgid recv_buffer2, // replyctrl sre.sre_reqCtrlSize, // replyctrlsize recv_buffer, // replydata (ushort) len, // replydatasize 0, // errorclass NULL); // newphandle } } assert(inx == loop); assert(tag_issue_map.empty()); assert(handle_issue_map.empty()); // need to wait for shutdown to be started ferr = msg_mon_event_wait(2, &event_len, event_data); util_check("msg_mon_event_wait", ferr); if (sync && threaded) { sync_thr_shutdown = true; for (int thr = 0; thr < MAX_THR; thr++) { void *larg; status = sync_thr[thr]->join(&larg); TEST_CHK_STATUSOK(status); } } } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
void *client_thr(void *arg) { int dinx; int ferr; static int kinx = -1; int lerr; int req_ctrl_size; int req_data_size; RT results; MS_SRE_LDONE sre_ldone; MyThread *thr; int tinx; thr = (MyThread *) arg; tinx = thr->inx; if (kinx < 0) kinx = gdloop - 1; for (dinx = 0; dinx < gdloop; dinx++) { req_ctrl_size = 0; req_data_size = gdsize; if (gverbose) printf("client LINK tinx=%d, dinx=%d\n", tinx, dinx); ferr = XMSG_LINK_(TPT_REF(gphandle), // phandle &gmsgids[tinx][dinx], // msgid gsend_cli_c_buffer[tinx][dinx], // reqctrl (ushort) req_ctrl_size, // reqctrlsize grecv_cli_c_buffer[tinx][dinx], // replyctrl (ushort) req_ctrl_size, // replyctrlmax gsend_cli_d_buffer[tinx][dinx], // reqdata (ushort) req_data_size, // reqdatasize grecv_cli_d_buffer[tinx][dinx], // replydata (ushort) req_data_size, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass XMSG_LINK_LDONEQ); // linkopts util_check("XMSG_LINK_", ferr); if ((tinx == 0) && (dinx == kinx)) { usleep(10000); if (gnodecycle && gvirtual) node_cycle(); else kill_server(); kinx--; if (kinx < 0) kinx = gdloop - 1; } } for (dinx = 0; dinx < gdloop; ) { lerr = XWAIT(LDONE, -1); TEST_CHK_WAITIGNORE(lerr); do { lerr = XMSG_LISTEN_((short *) &sre_ldone, // sre XLISTEN_ALLOW_LDONEM, // listenopts 0); // listenertag if (lerr == XSRETYPE_LDONE) { if (gverbose) printf("client LISTEN tinx=%d, dinx=%d\n", tinx, dinx); dinx++; ferr = XMSG_BREAK_(sre_ldone.sre_msgId, results.u.s, TPT_REF(gphandle)); ferr = ferr; // ignore } } while (lerr); } return NULL; }
void *thread_send(void *arg) { bool end; int ferr; int inx; char lwho[BUFSIZ]; int msgid; char *name; RT results; Util_AA<char> send_buffer(40000); int status; int thrinx; end = (arg == NULL); if (end) thrinx = -1; else { name = SB_Thread::Sthr::self_name(); thrinx = atoi(name); } sprintf(lwho, "client-%d", thrinx); for (inx = 0; inx < loop; inx++) { sprintf(&send_buffer, "hello, greetings from %s-%d, inx=%d", my_name, thrinx, inx); ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid NULL, // reqctrl 0, // reqctrlsize NULL, // replyctrl 0, // replyctrlmax &send_buffer, // reqdata end ? // reqdatasize (ushort) 0 : (ushort) 39000, recv_buffer, // replydata 40000, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass XMSG_LINK_LDONEQ); // linkopts assert((ferr != XZFIL_ERR_NOBUFSPACE) && (ferr != XZFIL_ERR_PATHDOWN)); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); if (verbose) { printf("%s - BREAK returned err=%d\n", lwho, ferr); if (ferr == XZFIL_ERR_OK) printf("%s - rcvd=%s\n", lwho, recv_buffer); } if (ferr != XZFIL_ERR_OK) { static SB_Thread::Mutex mutex; if (mutex.trylock() == 0) { // got lock restart_server(); status = mutex.unlock(); TEST_CHK_STATUSOK(status); } else SB_Thread::Sthr::sleep(100); // 100 ms inx--; continue; } else if (end) break; } return NULL; }
int main(int argc, char *argv[]) { bool exit; int ferr; int lerr; int msgid; int nid; int oid; int pid; TPT_DECL (phandle); char recv_buffer[BUFSIZ]; short recv_buffer2[BUFSIZ]; MS_Result_Type results; MS_SRE sre; ferr = msfs_util_init_role(true, &argc, &argv, msg_debug_hook); TEST_CHK_FEOK(ferr); util_test_start(true); ferr = msg_mon_process_startup(true); // system messages TEST_CHK_FEOK(ferr); msg_mon_enable_mon_messages(true); printf("cli: opening server\n"); ferr = msg_mon_get_process_info((char *) "$srv", &nid, &pid); TEST_CHK_FEOK(ferr); printf("cli: server opened\n"); ferr = msg_mon_open_process((char *) "$srv", // name TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); exit = false; while (!exit) { lerr = XWAIT(LREQ, -1); TEST_CHK_WAITIGNORE(lerr); for (;;) { lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag if (lerr == XSRETYPE_NOWORK) break; ferr = XMSG_READDATA_(sre.sre_msgId, // msgid recv_buffer, // reqdata BUFSIZ); // bytecount util_check("XMSG_READDATA_", ferr); if (sre.sre_flags & XSRE_MON) { MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer; printf("cli: mon message, type=%d\n", msg->type); if (msg->type == MS_MsgType_Open) { ferr = msg_mon_get_process_info((char *) "$srv", &nid, &pid); TEST_CHK_FEOK(ferr); assert(msg->u.open.nid == nid); assert(msg->u.open.pid == pid); assert(strcasecmp(msg->u.open.target_process_name, "$srv") == 0); exit = true; } } else { printf("cli: NON-mon message\n"); } XMSG_REPLY_(sre.sre_msgId, // msgid NULL, // replyctrl 0, // replyctrlsize NULL, // replydata 0, // replydatasize 0, // errorclass NULL); // newphandle } } printf("cli: sending message to server\n"); ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid NULL, // reqctrl 0, // reqctrlsize recv_buffer2, // replyctrl 1, // replyctrlmax NULL, // reqdata 0, // reqdatasize recv_buffer, // replydata BUFSIZ, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); ferr = XMSG_BREAK_(msgid, (short *) &results, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); exit = false; while (!exit) { lerr = XWAIT(LREQ, -1); for (;;) { lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag if (lerr == XSRETYPE_NOWORK) break; ferr = XMSG_READDATA_(sre.sre_msgId, // msgid recv_buffer, // reqctrl BUFSIZ); // bytecount util_check("XMSG_READDATA_", ferr); if (sre.sre_flags & XSRE_MON) { MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer; printf("cli: mon message, type=%d\n", msg->type); if (msg->type == MS_MsgType_ProcessDeath) { assert(msg->u.death.nid == nid); assert(msg->u.death.pid == pid); exit = true; } } else printf("cli: NON-mon message\n"); XMSG_REPLY_(sre.sre_msgId, // msgid NULL, // replyctrl 0, // replyctrlsize NULL, // replydata 0, // replydatasize 0, // errorclass NULL); // newphandle } } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(true); return 0; }
int main(int argc, char *argv[]) { char cli[10]; bool closer; int disable; int event_len; int ferr; int inst = 0; int inx; int lerr; int loop = 10; int msgid; int nid; int oid; TPT_DECL (phandle); int pid; char recv_buffer[30000]; RT results; char send_buffer[10]; MS_SRE sre; TAD zargs[] = { { "-client", TA_Ign, TA_NOMAX, NULL }, { "-inst", TA_Int, TA_NOMAX, &inst }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-maxcp", TA_Int, TA_NOMAX, &maxcp }, { "-maxs", TA_Int, TA_NOMAX, &maxs }, { "-maxsp", TA_Next, TA_NOMAX, NULL }, { "-name", TA_Next, TA_NOMAX, NULL }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "-v", TA_Bool, TA_NOMAX, &verbose }, { "", TA_End, TA_NOMAX, NULL } }; msfs_util_init(&argc, &argv, msg_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(true); ferr = msg_mon_process_startup(true); // system messages? TEST_CHK_FEOK(ferr); ferr = msg_mon_get_my_process_name(my_name, sizeof(my_name)); TEST_CHK_FEOK(ferr); msg_mon_enable_mon_messages(true); // process-wait for clients/shell // (needed so msg_mon_register_death_notification below works correctly) ferr = msfs_util_wait_process_count(MS_ProcessType_TSE, maxcp, NULL, false); TEST_CHK_FEOK(ferr); sleep(1); if (verbose) printf("%s: inst=%d, maxcp=%d\n", my_name, inst, maxcp); closer = (inst == (maxcp -1)); if (closer && (maxcp > 1)) { if (verbose) printf("%s: register-death-notifications\n", my_name); for (inx = 0; inx < (maxcp - 1); inx++) { sprintf(cli, "$c%d", inx); ferr = msg_mon_get_process_info(cli, &nid, &pid); TEST_CHK_FEOK(ferr); ferr = msg_mon_register_death_notification(nid, pid); TEST_CHK_FEOK(ferr); } } // // wait here until all clients sync-up // (needed so msg_mon_register_death_notification above works correctly) // ferr = msg_mon_event_send(-1, // nid -1, // pid MS_ProcessType_TSE, // process-type 3, // event-id 0, // event-len NULL); // event-data TEST_CHK_FEOK(ferr); for (inx = 0; inx < maxcp; inx++) { ferr = msg_mon_event_wait(3, &event_len, event_data); TEST_CHK_FEOK(ferr); } disable = msg_test_assert_disable(); // check process-type range ferr = msg_mon_event_send(-1, // nid -1, // pid -1, // process-type 4, // event-id 0, // event-len NULL); // event-data assert(ferr == XZFIL_ERR_BOUNDSERR); ferr = msg_mon_event_send(-1, // nid -1, // pid MS_ProcessType_SMS + 1, // process-type 5, // event-id 0, // event-len NULL); // event-data assert(ferr == XZFIL_ERR_BOUNDSERR); msg_test_assert_enable(disable); ferr = msg_mon_open_process((char *) "$srv", // name TPT_REF(phandle), &oid); TEST_CHK_FEOK(ferr); for (inx = 0; inx < loop; inx++) { ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid NULL, // reqctrl 0, // reqctrlsize NULL, // replyctrl 0, // replyctrlmax send_buffer, // reqdata 1, // reqdatasize recv_buffer, // replydata 0, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); } if (closer) { inx = 0; while (inx < (maxcp - 1)) { do { lerr = XWAIT(LREQ, -1); TEST_CHK_WAITIGNORE(lerr); lerr = XMSG_LISTEN_((short *) &sre, // sre 0, // listenopts 0); // listenertag } while (lerr == XSRETYPE_NOWORK); if (sre.sre_flags & XSRE_MON) { ferr = BMSG_READDATA_(sre.sre_msgId, // msgid recv_buffer, // reqdata BUFSIZ); // bytecount TEST_CHK_FEOK(ferr); MS_Mon_Msg *msg = (MS_Mon_Msg *) recv_buffer; if (msg->type == MS_MsgType_ProcessDeath) { if (verbose) printf("%s: process death process=%s\n", my_name, msg->u.death.process_name); inx++; } } XMSG_REPLY_(sre.sre_msgId, // msgid NULL, // replyctrl 0, // replyctrlsize recv_buffer, // replydata 0, // replydatasize 0, // errorclass NULL); // newphandle } if (verbose) printf("%s: sending stop\n", my_name); for (inx = 0; inx < maxs; inx++) { ferr = XMSG_LINK_(TPT_REF(phandle), // phandle &msgid, // msgid NULL, // reqctrl 0, // reqctrlsize NULL, // replyctrl 0, // replyctrlmax send_buffer, // reqdata 0, // reqdatasize recv_buffer, // replydata 0, // replydatamax 0, // linkertag 0, // pri 0, // xmitclass 0); // linkopts util_check("XMSG_LINK_", ferr); ferr = XMSG_BREAK_(msgid, results.u.s, TPT_REF(phandle)); util_check("XMSG_BREAK_", ferr); } } ferr = msg_mon_close_process(TPT_REF(phandle)); TEST_CHK_FEOK(ferr); ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(true); return 0; }