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 disable; int ferr; int oid; TPT_DECL (phandle); 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(true); // system messages? TEST_CHK_FEOK(ferr); if (client) { disable = msg_test_assert_disable(); ferr = msg_mon_open_process((char *) "$srv", // name TPT_REF(phandle), &oid); TEST_CHK_FEIGNORE(ferr); msg_test_assert_enable(disable); } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { enum { MAX_RETRIES = 100 }; enum { SLEEP_US = 1000 }; bool attach = false; _xcc_status cc; bool client = false; int count; int count_read; int count_written; bool dif = false; double dloop; double dms; double dsec; int err; bool exec = false; int ferr; bool fin = false; MS_Mon_Process_Info_Type info; MS_Mon_Process_Info_Type *infop; int inx; int inx2; int inx3; short len; short lerr; short lerr2; int loop = 10; int max; int nid; pid_t pid; int sargc; ssize_t size; int snid; int spid; bool startup = false; xzsys_ddl_smsg_def *sys_msgp = (xzsys_ddl_smsg_def *) recv_buffer; int sys_msg; int sys_msg_count; bool verbose = false; TAD zargs[] = { { "-attach", TA_Bool, TA_NOMAX, &attach }, { "-client", TA_Bool, TA_NOMAX, &client }, { "-dif", TA_Bool, TA_NOMAX, &dif }, { "-exec", TA_Bool, TA_NOMAX, &exec }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-maxsp", TA_Int, TA_NOMAX, &maxsp }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "-startup", TA_Bool, TA_NOMAX, &startup }, { "-trace", TA_Bool, TA_NOMAX, &trace }, { "-v", TA_Bool, TA_NOMAX, &verbose }, { "-verbose", TA_Ign, TA_NOMAX, NULL }, { "", TA_End, TA_NOMAX, NULL } }; arg_proc_args(zargs, false, argc, argv); sprintf(fifo1, "%s-%s", FIFO1, getenv("USER")); sprintf(fifo2, "%s-%s", FIFO2, getenv("USER")); if (trace) msg_init_trace(); if (exec) return 0; if (startup) { err = fifo_open(fifo1, O_WRONLY); assert(err != -1); ffds[1] = err; err = fifo_open(fifo2, O_RDONLY); assert(err != -1); ffds[0] = err; if (trace) trace_printf("cli: writing fifo\n"); size = write(ffds[1], recv_buffer, 1); if (trace) trace_printf("cli: fifo write, size=%d\n", (int) size); assert(size == 1); if (trace) trace_printf("cli: fifo written\n"); close(ffds[1]); return 0; } if (attach) ferr = file_init_attach(&argc, &argv, false, NULL); else ferr = file_init(&argc, &argv); TEST_CHK_FEOK(ferr); util_test_start(client); ferr = msg_mon_process_startup(true); // system messages util_check("msg_mon_process_startup", ferr); ferr = msg_mon_get_my_process_name(procname, BUFSIZ); util_check("msg_mon_get_my_process_name", ferr); ferr = msg_mon_get_process_info(procname, &nid, &pid); TEST_CHK_FEOK(ferr); if (trace) trace_printf("proc=%s, nid=%d, pid=%d\n", procname, nid, pid); dloop = (double) loop; for (inx = 0; inx < T_MAX; inx++) t_elapsed[inx] = 0.0; if (client) { printf("loop=%d, maxsp=%d\n", loop, maxsp); sargc = argc; assert(sargc < MAX_ARGS); for (inx2 = 0; inx2 < argc; inx2++) { if (strcmp(argv[inx2], "-client") == 0) sargv[inx2] = (char *) "-server"; else sargv[inx2] = argv[inx2]; if (strcmp(argv[inx2], "-attach") == 0) sargv[inx2] = (char *) "-server"; } sargv[argc] = NULL; sprintf(sprog, "%s/%s", getenv("PWD"), argv[0]); time_start(T_TOTAL); for (inx = 0; inx < loop; inx += maxsp) { if (dif) snid = -1; else snid = nid; max = loop - inx; if (max > maxsp) max = maxsp; for (inx2 = 0; inx2 < max; inx2++) sname[inx2][0] = 0; // mon picks name if (trace) trace_printf("cli: newproc, inx=%d\n", inx); time_start(T_NEWPROC); for (inx2 = 0; inx2 < max; inx2++) { ferr = msg_mon_start_process(sprog, // prog sname[inx2], // name sname[inx2], // ret_name sargc, // argc sargv, // argv TPT_REF2(sphandle,inx2),// phandle false, // open &soid[inx2], // oid MS_ProcessType_Generic, // type 0, // priority false, // debug false, // backup &snid, // nid &spid, // pid NULL, // infile NULL); // outfile TEST_CHK_FEOK(ferr); } time_stop(T_NEWPROC); time_elapsed(T_NEWPROC); // wait here until processes are 'up' // so that open timing is correct inx3 = 0; for (inx2 = 0; inx2 < max; inx2++) { ferr = msg_mon_get_process_info_detail(sname[inx2], &info); TEST_CHK_FEOK(ferr); if (info.state != MS_Mon_State_Up) { inx3++; if (inx3 > MAX_RETRIES) { printf("process %s did not enter 'UP' state\n", sname[inx2]); assert(inx3 < MAX_RETRIES); } usleep(SLEEP_US); inx2--; continue; } else inx3 = 0; } if (trace) trace_printf("cli: open, inx=%d\n", inx); time_start(T_OPEN); for (inx2 = 0; inx2 < max; inx2++) { if (trace) trace_printf("cli: opening inx=%d, name=%s\n", inx, sname[inx2]); len = (short) strlen(sname[inx2]); ferr = BFILE_OPEN_(sname[inx2], len, &sfilenum[inx2], 0, 0, 0, 0, 0, 0, 0); if (trace) trace_printf("cli: open, inx=%d, name=%s, ferr=%d\n", inx, sname[inx2], ferr); TEST_CHK_FEOK(ferr); } time_stop(T_OPEN); time_elapsed(T_OPEN); if (trace) trace_printf("cli: procinfo, inx=%d\n", inx); time_start(T_PROCINFO); for (inx2 = 0; inx2 < max; inx2++) { ferr = msg_mon_get_process_info_detail(sname[inx2], &info); TEST_CHK_FEOK(ferr); } time_stop(T_PROCINFO); time_elapsed(T_PROCINFO); if (trace) trace_printf("cli: procinfo-type, inx=%d\n", inx); time_start(T_PROCINFO_TYPE); ferr = msg_mon_get_process_info_type(MS_ProcessType_Generic, &count, MAX_SRV, infotype); TEST_CHK_FEOK(ferr); time_stop(T_PROCINFO_TYPE); time_elapsed(T_PROCINFO_TYPE); if (verbose) { for (inx2 = 0; inx2 < count; inx2++) { infop = &infotype[inx2]; char s_em = infop->event_messages ? 'E' : '-'; char s_sm = infop->system_messages ? 'S' : '-'; char s_pr = infop->pending_replication ? 'R' : '-'; char s_pd = infop->pending_delete ? 'D' : '-'; char s_s = infop->state == MS_Mon_State_Up ? 'A' : 'U'; char s_o = infop->opened ? 'O' : '-'; char s_p = infop->paired ? 'P' : infop->backup ? 'B' : '-'; printf("%3.3d,%8.8d %3.3d %d %c%c%c%c%c%c%c %-11s %-11s %-15s\n", infop->nid, infop->pid, infop->priority, infop->state, s_em, s_sm, s_pr, s_pd, s_s, s_o, s_p, infop->process_name, infop->parent_name, infop->program); } } if (trace) trace_printf("cli: close, inx=%d\n", inx); time_start(T_CLOSE); for (inx2 = 0; inx2 < max; inx2++) { ferr = BFILE_CLOSE_(sfilenum[inx2]); TEST_CHK_FEOK(ferr); } time_stop(T_CLOSE); time_elapsed(T_CLOSE); // re-open/close for (inx2 = 0; inx2 < max; inx2++) { if (trace) trace_printf("cli: re-opening inx=%d, name=%s\n", inx, sname[inx2]); len = (short) strlen(sname[inx2]); ferr = BFILE_OPEN_(sname[inx2], len, &sfilenum[inx2], 0, 0, 0, 0, 0, 0, 0); TEST_CHK_FEOK(ferr); } if (trace) trace_printf("cli: re-close, inx=%d\n", inx); for (inx2 = 0; inx2 < max; inx2++) { ferr = BFILE_CLOSE_(sfilenum[inx2]); TEST_CHK_FEOK(ferr); } if (trace) trace_printf("cli: newproc-forkexec, inx=%d\n", inx); sargc = 2; sargv[0] = argv[0]; sargv[1] = (char *) "-exec"; if (trace) sargv[sargc++] = (char *) "-trace"; sargv[sargc] = NULL; time_start(T_FORKEXEC); for (inx2 = 0; inx2 < max; inx2++) { pid = fork(); assert(pid >= 0); if (pid == 0) { // child err = execv(sprog, sargv); assert(err == 0); } } time_stop(T_FORKEXEC); time_elapsed(T_FORKEXEC); if (trace) trace_printf("cli: newproc-forkexec-su, inx=%d\n", inx); sargc = 2; sargv[0] = argv[0]; sargv[1] = (char *) "-startup"; if (trace) sargv[sargc++] = (char *) "-trace"; sargv[sargc] = NULL; time_start(T_FORKEXEC_SU); for (inx2 = 0; inx2 < max; inx2++) { fifo_create(fifo1, fifo2); pid = fork(); assert(pid >= 0); if (pid > 0) { // parent err = fifo_open(fifo1, O_RDONLY); assert(err != -1); ffds[0] = err; err = fifo_open(fifo2, O_WRONLY); assert(err != -1); ffds[1] = err; if (trace) trace_printf("cli: reading fifo, inx=%d\n", inx2); size = ::read(ffds[0], recv_buffer, 1); if (trace) trace_printf("cli: fifo read, size=%d\n", (int) size); assert(size == 1); if (trace) trace_printf("cli: fifo read, inx=%d\n", inx2); ::read(ffds[0], recv_buffer, 1); err = fifo_close(ffds[0]); assert(err == 0); err = fifo_close(ffds[1]); assert(err == 0); fifo_destroy(fifo1, fifo1); } else { // child err = execv(sprog, sargv); assert(err == 0); } } fifo_destroy(fifo2, fifo2); time_stop(T_FORKEXEC_SU); time_elapsed(T_FORKEXEC_SU); } } else { sys_msg_count = 0; time_start(T_TOTAL); ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr, 0, 0, 0, 1, 0); // sys msgs TEST_CHK_FEOK(ferr); for (inx = 0; !fin; inx++) { if (trace) trace_printf("srv: readupdate, inx=%d\n", inx); cc = BREADUPDATEX(filenumr, recv_buffer, 4, &count_read, 0); sys_msg = _xstatus_ne(cc); if (trace && sys_msg) trace_printf("srv: rcvd sys msg=%d\n", sys_msgp->u_z_msg.z_msgnumber[0]); if (sys_msg) { sys_msg_count++; inx--; } lerr2 = BFILE_GETINFO_(filenumr, &lerr); TEST_CHK_FEIGNORE(lerr2); if (trace) trace_printf("srv: reply, inx=%d\n", inx); cc = BREPLYX(recv_buffer, (unsigned short) 0, &count_written, 0, XZFIL_ERR_OK); TEST_CHK_CCEQ(cc); if (sys_msg_count >= 4) fin = true; } } time_stop(T_TOTAL); time_elapsed(T_TOTAL); if (client) { dsec = time_sec(T_TOTAL); dms = dsec * 1000.0; printf("elapsed=%f\n", dms); printf("open/close/newprocess/processinfo/forkexec=%d\n", loop); dsec = time_sec(T_OPEN); dms = dsec * 1000.0; printf("open : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n", dms, dms / dloop, dloop / dsec); dsec = time_sec(T_CLOSE); dms = dsec * 1000.0; printf("close : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n", dms, dms / dloop, dloop / dsec); dsec = time_sec(T_PROCINFO); dms = dsec * 1000.0; printf("procinfo : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n", dms, dms / dloop, dloop / dsec); dsec = time_sec(T_PROCINFO_TYPE); dms = dsec * 1000.0; printf("procinfo-type : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n", dms, dms / dloop, dloop / dsec); dsec = time_sec(T_NEWPROC); dms = dsec * 1000.0; printf("newproc : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n", dms, dms / dloop, dloop / dsec); dsec = time_sec(T_FORKEXEC); dms = dsec * 1000.0; printf("forkexec : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n", dms, dms / dloop, dloop / dsec); dsec = time_sec(T_FORKEXEC_SU); dms = dsec * 1000.0; printf("forkexec-startup: total-time=%f ms, time/loop=%f ms, ops/sec=%f\n", dms, dms / dloop, dloop / dsec); } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { _bcc_status bcc; bool client = false; int count_read; int count_written; int disable; int err; short error_reply; int ferr; short filenum; int inx; short lasterr; int loop = 10; int msgnum; bool open = false; short sender_len; xzsys_ddl_smsg_def *sys_msg = (xzsys_ddl_smsg_def *) recv_buffer; RI_Type ri; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "", TA_End, TA_NOMAX, NULL } }; ferr = file_init(&argc, &argv); TEST_CHK_FEOK(ferr); msfs_util_init_fs(&argc, &argv, file_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(true); ferr = msg_mon_process_startup(!client); // system messages TEST_CHK_FEOK(ferr); ferr = msg_mon_get_my_process_name(my_name, BUFSIZ); TEST_CHK_FEOK(ferr); ferr = msg_mon_get_process_info(NULL, &my_nid, &my_pid); TEST_CHK_FEOK(ferr); if (client) { printf("client name=%s, nid=%d, pid=%d\n", my_name, my_nid, my_pid); start_server(argc, argv); server_name_len = (short) strlen(server_name); ferr = BFILE_OPEN_((char *) server_name, server_name_len, &filenum, 0, 0, 0, 0, 0, 0, 0, NULL); TEST_CHK_FEOK(ferr); for (inx = 0; inx < loop; inx++) { sprintf(send_buffer, "hello, greetings from %s, inx=%d", my_name, inx); disable = msg_test_assert_disable(); bcc = BWRITEREADX(filenum, send_buffer, (int) (strlen(send_buffer) + 1), // cast BUFSIZ, &count_read, 0); msg_test_assert_enable(disable); if (_bstatus_eq(bcc)) printf("%s\n", send_buffer); else { ferr = XFILE_GETINFO_(-1, &lasterr, NULL, 0, NULL, NULL, NULL); printf("WRITEREAD error=%d\n", lasterr); } kill(server_pid, SIGKILL); for (;;) { err = kill(server_pid, 0); if ((err == -1) && (errno == ESRCH)) break; usleep(10000); } start_server(argc, argv); } kill(server_pid, SIGKILL); for (;;) { err = kill(server_pid, 0); if ((err == -1) && (errno == ESRCH)) break; usleep(10000); } ferr = BFILE_CLOSE_(filenum, 0); TEST_CHK_FEOK(ferr); } else { printf("server name=%s, nid=%d, pid=%d\n", my_name, my_nid, my_pid); ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenum, 0, 0, 0, 1, 0, // sys msg 0, 0, NULL); TEST_CHK_FEOK(ferr); for (inx = 0; inx < loop; inx++) { bcc = BREADUPDATEX(filenum, recv_buffer, BUFSIZ, &count_read, 0); getri(&ri); printri(&ri); sender_len = 0; sender_nid = -1; sender_pid = -1; disable = msg_test_assert_disable(); // errors are ok ferr = XPROCESSHANDLE_DECOMPOSE_(TPT_REF(ri.sender), &sender_nid, // cpu &sender_pid, // pin NULL, // nodenumber NULL, // nodename 0, // nodename NULL, // nodename_length sender, sizeof(sender), &sender_len, NULL); // sequence_number TEST_CHK_FEIGNORE(ferr); msg_test_assert_enable(disable); sender[sender_len] = 0; printf("sender=%s, nid=%d, pid=%d\n", sender, sender_nid, sender_pid); error_reply = XZFIL_ERR_OK; if (_bstatus_eq(bcc)) { if (open) { assert(sender_nid == open_sender_nid); assert(sender_pid == open_sender_pid); assert(strcmp(sender, open_sender) == 0); assert(ri.file_number == open_sender_file_number); strcat(recv_buffer, "- reply from "); strcat(recv_buffer, my_name); count_read = (int) (strlen(recv_buffer) + 1); // cast } else { printf("server not opened by client - returning WRONGID\n"); error_reply = XZFIL_ERR_WRONGID; } } else { msgnum = sys_msg->u_z_msg.z_msgnumber[0]; switch (msgnum) { case XZSYS_VAL_SMSG_OPEN: printf("msgnum=%d (open)\n", msgnum); assert(!open); TPT_COPY_INT(TPT_REF(open_sender_phandle), ri.sender); strcpy(open_sender, sender); open_sender_nid = sender_nid; open_sender_pid = sender_pid; open_sender_file_number = ri.file_number; open = true; break; case XZSYS_VAL_SMSG_CLOSE: printf("msgnum=%d (close)\n", msgnum); assert(open); open = false; break; case XZSYS_VAL_SMSG_SHUTDOWN: printf("msgnum=%d (shutdown)\n", msgnum); inx = loop; // exit break; default: printf("unexpected msgnum=%d\n", msgnum); abort(); } count_read = 0; inx--; } bcc = BREPLYX(recv_buffer, count_read, &count_written, 0, error_reply); TEST_CHK_BCCEQ(bcc); } ferr = XFILE_CLOSE_(filenum, 0); TEST_CHK_FEOK(ferr); } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(true); printf("if there were no asserts, all is well\n"); return 0; }
int main(int argc, char *argv[]) { void *buf; _xcc_status cc; bool client = false; unsigned short count_read; unsigned short count_written; unsigned short count_xferred; int disable; int ferr; short filenum; int linx; int loop = 1; int maxopen1; int maxopen2; char my_name[BUFSIZ]; int ninx; int oinx; int rd; int recvdepth = 1; int rinx; SB_Tag_Type tag; short tfilenum; int timeout = -1; bool verbose = false; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-recvdepth", TA_Int, MAXRCVDEPTH, &recvdepth }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "-v", TA_Bool, TA_NOMAX, &verbose }, { "", TA_End, TA_NOMAX, NULL } }; ferr = file_init(&argc, &argv); TEST_CHK_FEOK(ferr); msfs_util_init_fs(&argc, &argv, file_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = file_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); util_gethostname(my_name, (int) sizeof(my_name)); if (client) { maxopen1 = (recvdepth + MAXNOWAIT - 1 ) / MAXNOWAIT; maxopen2 = RDOVER / MAXNOWAIT; if (verbose) printf("client maxopen=%d, recvdepth=%d\n", maxopen1, recvdepth); for (oinx = 0; oinx < maxopen1; oinx++) { ferr = XFILE_OPEN_((char *) "$SRV", 8, &filenumc1[oinx], 0, 0, MAXNOWAIT, // nowait 0, 0, 0, 0, NULL); TEST_CHK_FEOK(ferr); } for (oinx = 0; oinx < maxopen2; oinx++) { ferr = XFILE_OPEN_((char *) "$SRV", 8, &filenumc2[oinx], 0, 0, MAXNOWAIT, // nowait 0, 0, 0, 0, NULL); TEST_CHK_FEOK(ferr); } for (linx = 0; linx < loop; linx++) { rd = 0; for (oinx = 0; oinx < maxopen1; oinx++) { for (ninx = 0; ninx < MAXNOWAIT; ninx++) { if (verbose) printf("client wr1, fnum=%d, linx=%d, oinx=%d, ninx=%d, rd=%d\n", filenumc1[oinx], linx, oinx, ninx, rd); sprintf(send_buffer1[oinx][ninx], "hello1, greetings from %s, oinx=%d, ninx=%d, rd=%d", my_name, oinx, ninx, rd); cc = XWRITEREADX(filenumc1[oinx], send_buffer1[oinx][ninx], (short) (strlen(send_buffer1[oinx][ninx]) + 1), BUFSIZ, &count_read, rd); TEST_CHK_CCEQ(cc); rd++; if (rd >= recvdepth) break; } } for (oinx = 0; oinx < maxopen2; oinx++) { for (ninx = 0; ninx < MAXNOWAIT; ninx++) { if (verbose) printf("client wr2, fnum=%d, linx=%d, oinx=%d, ninx=%d, rd=%d\n", filenumc2[oinx], linx, oinx, ninx, rd); sprintf(send_buffer2[oinx][ninx], "hello2, greetings from %s, oinx=%d, ninx=%d, rd=%d", my_name, oinx, ninx, rd); cc = XWRITEREADX(filenumc2[oinx], send_buffer2[oinx][ninx], (short) (strlen(send_buffer2[oinx][ninx]) + 1), BUFSIZ, &count_read, rd); TEST_CHK_CCEQ(cc); rd++; if (rd >= (recvdepth + RDOVER)) break; } } rd = 0; for (oinx = 0; oinx < maxopen1; oinx++) { for (ninx = 0; ninx < MAXNOWAIT; ninx++) { tfilenum = filenumc1[oinx]; if (verbose) printf("client awaitio1, fnum=%d, linx=%d, oinx=%d, ninx=%d, rd=%d\n", tfilenum, linx, oinx, ninx, rd); cc = XAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); TEST_CHK_CCEQ(cc); send_buffer1[oinx][ninx][count_xferred] = 0; printf("%s\n", send_buffer1[oinx][ninx]); rd++; if (rd >= recvdepth) break; } } rinx = 0; for (oinx = 0; oinx < maxopen2; oinx++) { for (ninx = 0; ninx < MAXNOWAIT; ninx++) { tfilenum = filenumc2[oinx]; if (verbose) printf("client awaitio2, fnum=%d, linx=%d, oinx=%d, ninx=%d, rd=%d\n", tfilenum, linx, oinx, ninx, rd); disable = msg_test_assert_disable(); cc = XAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); msg_test_assert_enable(disable); msg_ok[rinx] = _xstatus_eq(cc); if (msg_ok[rinx]) { send_buffer2[oinx][ninx][count_xferred] = 0; printf("%s\n", send_buffer2[oinx][ninx]); } else if (verbose) printf("client awaitio2-err\n"); rinx++; rd++; if (rd >= (recvdepth + RDOVER)) break; } } // // re-link any failures // rd = recvdepth; rinx = 0; for (oinx = 0; oinx < maxopen2; oinx++) { for (ninx = 0; ninx < MAXNOWAIT; ninx++) { if (msg_ok[rinx++]) continue; tfilenum = filenumc2[oinx]; if (verbose) printf("client wr3, fnum=%d, linx=%d, oinx=%d, ninx=%d, rd=%d\n", filenumc2[oinx], linx, oinx, ninx, rd); sprintf(send_buffer2[oinx][ninx], "hello3, greetings from %s, oinx=%d, ninx=%d, rd=%d", my_name, oinx, ninx, rd); cc = XWRITEREADX(tfilenum, send_buffer2[oinx][ninx], (short) (strlen(send_buffer2[oinx][ninx]) + 1), BUFSIZ, &count_read, rd); TEST_CHK_CCEQ(cc); if (verbose) printf("client awaitio3, fnum=%d, linx=%d, oinx=%d, ninx=%d, rd=%d\n", tfilenum, linx, oinx, ninx, rd); cc = XAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); TEST_CHK_CCEQ(cc); send_buffer2[oinx][ninx][count_xferred] = 0; printf("%s\n", send_buffer2[oinx][ninx]); rd++; if (rd >= (recvdepth + RDOVER)) break; } } } } else { ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum, 0, 0, 0, (short) recvdepth, 1, // no sys msg 0, 0, NULL); TEST_CHK_FEOK(ferr); for (linx = 0; linx < loop; linx++) { for (rinx = 0; rinx < recvdepth; rinx++) { if (verbose) printf("server ru rinx=%d, rd=%d\n", rinx, rinx); cc = XREADUPDATEX(filenum, recv_buffer[rinx], BUFSIZ, &count_read, 0); TEST_CHK_CCEQ(cc); } sleep(1); // force NOLCB for (rinx = 0; rinx < recvdepth; rinx++) { if (verbose) printf("server reply rinx=%d, rd=%d\n", rinx, rinx); strcat(recv_buffer[rinx], "- reply from "); strcat(recv_buffer[rinx], my_name); count_read = (unsigned short) (strlen(recv_buffer[rinx]) + 1); // cast cc = XREPLYX(recv_buffer[rinx], count_read, &count_written, (short) rinx, XZFIL_ERR_OK); TEST_CHK_CCEQ(cc); } sleep(1); // delay rd = recvdepth; for (rinx = 0; rinx < RDOVER; rinx++) { if (verbose) printf("server ru (over) rinx=%d, rd=%d\n", rinx, rd); cc = XREADUPDATEX(filenum, recv_buffer[rinx], BUFSIZ, &count_read, 0); TEST_CHK_CCEQ(cc); if (verbose) printf("server reply (over) rinx=%d, rd=%d\n", rinx, rd); strcat(recv_buffer[rinx], "- reply from "); strcat(recv_buffer[rinx], my_name); count_read = (unsigned short) (strlen(recv_buffer[rinx]) + 1); // cast cc = XREPLYX(recv_buffer[rinx], count_read, &count_written, (short) 0, XZFIL_ERR_OK); TEST_CHK_CCEQ(cc); rd++; } } ferr = XFILE_CLOSE_(filenum, 0); TEST_CHK_FEOK(ferr); } ferr = file_mon_process_shutdown(); TEST_CHK_FEIGNORE(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { void *buf; _xcc_status cc; bool client = false; unsigned short count_written; unsigned short count_xferred; int disable; bool done; int ferr; short filenum1; short filenum2; int inx; int loop = 10; char my_name[BUFSIZ]; char my_pname[BUFSIZ]; int out; MS_Mon_Process_Info_Type proc_info; char recv_buffer[BUFSIZ]; char send_buffer[BUFSIZ]; int send_len; SB_Tag_Type tag; int timeout = -1; short tfilenum; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "-v", TA_Bool, TA_NOMAX, &verbose }, { "", TA_End, TA_NOMAX, NULL } }; ferr = file_init(&argc, &argv); TEST_CHK_FEOK(ferr); msfs_util_init_fs(&argc, &argv, file_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = file_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); util_gethostname(my_name, (int) sizeof(my_name)); ferr = msg_mon_get_my_process_name(my_pname, sizeof(my_pname)); if (client) { ferr = XFILE_OPEN_(srv1, (short) strlen(srv1), &filenum1, 0, 0, MAX_OUT, 0, 0, 0, 0, NULL); TEST_CHK_FEOK(ferr); ferr = msg_mon_get_process_info_detail(srv1, &proc_info); TEST_CHK_FEOK(ferr); ferr = XFILE_OPEN_(srv2, (short) strlen(srv2), &filenum2, 0, 0, MAX_OUT, 0, 0, 0, 0, NULL); TEST_CHK_FEOK(ferr); for (inx = 0; inx < loop; inx++) { sprintf(send_buffer, "hello, greetings from %s, inx=%d", my_name, inx); send_len = (int) strlen(send_buffer) + 1; // cast if (verbose) printf("client doing writereadx's to fn1\n"); for (out = 0; out < MAX_OUT; out++) { cc = XWRITEREADX(filenum1, send_buffer, (ushort) send_len, BUFSIZ, &count_written, 0); TEST_CHK_CCEQ(cc); } if (verbose) printf("client doing writereadx's to fn2\n"); for (out = 0; out < MAX_OUT; out++) { cc = XWRITEREADX(filenum2, send_buffer, (ushort) send_len, BUFSIZ, &count_written, 0); TEST_CHK_CCEQ(cc); } if (verbose) printf("client killing srv1 (pid=%d), closing fn1\n", proc_info.os_pid); kill(proc_info.os_pid, SIGTERM); disable = msg_test_assert_disable(); ferr = XFILE_CLOSE_(filenum1); TEST_CHK_FEIGNORE(ferr); msg_test_assert_enable(disable); if (verbose) printf("client doing awaitios on fn1\n"); for (out = 0; out < MAX_OUT; out++) { tfilenum = -2; disable = msg_test_assert_disable(); cc = XAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); msg_test_assert_enable(disable); // can't check cc because of -2 if (_xstatus_eq(cc)) printf("%s\n", send_buffer); } if (verbose) printf("client restarting srv1, reopening fn1\n"); restart_server(argc, argv); ferr = XFILE_OPEN_(srv1, (short) strlen(srv1), &filenum1, 0, 0, MAX_OUT, 0, 0, 0, 0, NULL); TEST_CHK_FEOK(ferr); ferr = msg_mon_get_process_info_detail(srv1, &proc_info); } if (verbose) printf("client sending stop to srv1\n"); strcpy(send_buffer, "stop"); send_len = (int) strlen(send_buffer) + 1; // cast cc = XWRITEREADX(filenum1, send_buffer, (ushort) send_len, BUFSIZ, &count_written, 0); TEST_CHK_CCEQ(cc); tfilenum = filenum1; cc = XAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); TEST_CHK_CCEQ(cc); strcpy(send_buffer, "stop"); if (verbose) printf("client sending stop to srv2\n"); cc = XWRITEREADX(filenum2, send_buffer, (ushort) send_len, BUFSIZ, &count_written, 0); TEST_CHK_CCEQ(cc); tfilenum = filenum2; cc = XAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); TEST_CHK_CCEQ(cc); if (verbose) printf("client finishing\n"); } else { ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenum1, 0, 0, 0, 1, 1, // no sys msg 0, 0, NULL); TEST_CHK_FEOK(ferr); do { if (verbose) printf("server-%s: doing readupdate\n", my_pname); cc = XREADUPDATEX(filenum1, recv_buffer, BUFSIZ, NULL, 0); if (verbose) printf("server-%s: readupdate done cc=%d\n", my_pname, cc); TEST_CHK_CCEQ(cc); util_time_sleep_ms(10); done = (strcmp(recv_buffer, "stop") == 0); strcat(recv_buffer, "- reply from "); strcat(recv_buffer, my_name); if (verbose) printf("server-%s: doing reply, done=%d\n", my_pname, done); cc = XREPLYX(NULL, 0, &count_written, 0, XZFIL_ERR_OK); TEST_CHK_CCEQ(cc); assert(count_written == 0); } while (!done); ferr = XFILE_CLOSE_(filenum1, 0); TEST_CHK_FEOK(ferr); } ferr = file_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }