int main(int argc, char *argv[]) { _xcc_status cc; bool client = false; int closes; int count_read; int count_written; int ferr; short filenumr; short filenums[MAX_SRV]; int inxl; int inxs; int loop = 10; int maxcp = 1; int maxsp = 1; bool mq = false; char serv[20]; xzsys_ddl_smsg_def *sys_msg = (xzsys_ddl_smsg_def *) recv_buffer; bool verbose = false; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-maxcp", TA_Int, MAX_CLI, &maxcp }, { "-maxsp", TA_Int, MAX_SRV, &maxsp }, { "-mq", TA_Bool, TA_NOMAX, &mq }, { "-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); ferr = msg_mon_get_my_process_name(my_name, BUFSIZ); util_check("msg_mon_get_my_process_name", ferr); if (client) { for (inxl = 0; inxl < loop; inxl++) { for (inxs = 0; inxs < maxsp; inxs++) { sprintf(serv, "$srv%d", inxs); ferr = BFILE_OPEN_(serv, (short) strlen(serv), &filenums[inxs], 0, 0, 0, 0, 0, 0, 0, NULL); TEST_CHK_FEOK(ferr); } for (inxs = 0; inxs < maxsp; inxs++) { sprintf(send_buffer, "hello, greetings %d from %s, inx=%d", inxs, my_name, inxl); cc = BWRITEREADX(filenums[inxs], send_buffer, (int) (strlen(send_buffer) + 1), // cast BUFSIZ, &count_read, 0); TEST_CHK_CCEQ(cc); if (mq) { if ((inxl % 100) == 0) printf("count=%d\n", inxl); } else printf("%s\n", send_buffer); } for (inxs = 0; inxs < maxsp; inxs++) { ferr = BFILE_CLOSE_(filenums[inxs], 0); TEST_CHK_FEOK(ferr); } } } else { closes = 0; ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr, 0, 0, 0, 1, 0, // sys msg 0, 0, NULL); TEST_CHK_FEOK(ferr); // process requests for (inxl = 0;; inxl++) { cc = BREADUPDATEX(filenumr, recv_buffer, BUFSIZ, &count_read, 0); if (_xstatus_ne(cc)) { int mt = sys_msg->u_z_msg.z_msgnumber[0]; if (verbose) { if (mt == XZSYS_VAL_SMSG_CLOSE) printf("inx=%d, type=%d, cc=%d\n", inxl, mt, closes); else printf("inx=%d, type=%d\n", inxl, mt); } if (mt == XZSYS_VAL_SMSG_CLOSE) closes++; count_read = 0; } else { strcat(recv_buffer, "- reply from "); strcat(recv_buffer, my_name); count_read = (int) (strlen(recv_buffer) + 1); // cast } cc = BREPLYX(recv_buffer, count_read, &count_written, 0, XZFIL_ERR_OK); TEST_CHK_CCEQ(cc); if (closes >= maxcp * loop) break; } ferr = BFILE_CLOSE_(filenumr, 0); TEST_CHK_FEOK(ferr); } ferr = file_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { _bcc_status bcc; void *buf; bool client = false; int count_read; int count_written; int count_xferred; bool e_ldone; bool e_pwu; int err; int ferr; short filenumr; short filenums; int inx; int loop = 10; char *p; char recv_buffer[BUFSIZ]; char send_buffer[BUFSIZ]; int socka; int sockc; int sockl; SB_Tag_Type tag; short tfilenum; int timeout = -1; short wakeup; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "-v", TA_Bool, TA_NOMAX, &verbose }, { "", TA_End, TA_NOMAX, NULL } }; ferr = file_init(&argc, &argv); TEST_CHK_FEOK(ferr); msfs_util_init_fs(&argc, &argv, file_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = file_mon_process_startup(!client); // system messages TEST_CHK_FEOK(ferr); if (client) { ferr = BFILE_OPEN_((char *) "$srv", (short) 4, &filenums, 0, 0, 1, 0, 0, 0, 0, NULL); TEST_CHK_FEOK(ferr); for (inx = 0; inx < loop; inx++) { sprintf(send_buffer, "inx=%d", inx); bcc = BWRITEREADX(filenums, send_buffer, (short) (strlen(send_buffer) + 1), BUFSIZ, &count_read, 1); TEST_CHK_BCCEQ(bcc); tfilenum = -1; bcc = BAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); TEST_CHK_BCCEQ(bcc); } p = strchr(send_buffer, ':'); *p = 0; p++; strcpy(host, send_buffer); port = (unsigned short) atoi(p); if (verbose) printf("server returned host=%s, port=%d\n", host, port); if (verbose) printf("client connecting up\n"); // connect up, and setup fds epoll_init(); sockc = do_sock_connect(); pin_main = 1; proc_register_group_pin(-1, pin_main); epoll_add(sockc); do_thread_create(); bcc = BWRITEREADX(filenums, NULL, 0, BUFSIZ, &count_read, 1); TEST_CHK_BCCEQ(bcc); usleep(10000); e_pwu = false; e_ldone = false; for (;;) { wakeup = XWAIT(LDONE | PWU, -1); if (wakeup & PWU) { e_pwu = true; do_io_comp(); } if (wakeup & LDONE) { e_ldone = true; timeout = -1; tfilenum = -1; bcc = BAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); TEST_CHK_BCCEQ(bcc); } if (e_ldone && e_pwu) break; } do_thread_join(); if (verbose) printf("client closing\n"); ferr = BFILE_CLOSE_(filenums, 0); TEST_CHK_FEOK(ferr); printf("if there were no asserts, all is well\n"); } else { sockl = do_sock_listen(); assert(sockl != -1); ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr, 0, 0, 1, 1, 1, // no sys msg 0, 0, NULL); TEST_CHK_FEOK(ferr); for (inx = 0; inx < loop; inx++) { bcc = BREADUPDATEX(filenumr, recv_buffer, BUFSIZ, &count_read, 1); TEST_CHK_BCCEQ(bcc); tfilenum = filenumr; bcc = BAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); TEST_CHK_BCCEQ(bcc); assert(tag == 1); sprintf(recv_buffer, "%s:%d\n", host, port); count_read = (short) (strlen(recv_buffer) + 1); bcc = BREPLYX(recv_buffer, count_read, &count_written, 0, XZFIL_ERR_OK); TEST_CHK_BCCEQ(bcc); } if (verbose) printf("server accepting\n"); socka = do_sock_accept(sockl); err = (int) write(socka, recv_buffer, 1); assert(err != -1); for (inx = 0; inx < 1; inx++) { bcc = BREADUPDATEX(filenumr, recv_buffer, BUFSIZ, &count_read, 1); TEST_CHK_BCCEQ(bcc); tfilenum = filenumr; bcc = BAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); TEST_CHK_BCCEQ(bcc); bcc = BREPLYX(recv_buffer, 0, &count_written, 0, XZFIL_ERR_OK); TEST_CHK_BCCEQ(bcc); } if (verbose) printf("server closing\n"); ferr = BFILE_CLOSE_(filenumr, 0); TEST_CHK_FEOK(ferr); } ferr = file_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { bool abort1 = false; bool abort2 = false; void *buf; _xcc_status cc; bool client = false; int count_read; int count_written; int count_xferred; int dsize = 1024; int ferr; short filenum; int inx; int loop = 10; short mt; char my_name[BUFSIZ]; bool verbose = false; SB_Tag_Type tag; short tfilenum; int timeout = -1; TAD zargs[] = { { "-abort1", TA_Bool, TA_NOMAX, &abort1 }, { "-abort2", TA_Bool, TA_NOMAX, &abort2 }, { "-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); ferr = msg_mon_get_my_process_name(my_name, BUFSIZ); util_check("msg_mon_get_my_process_name", ferr); if (client) { ferr = BFILE_OPEN_((char *) "$srv", 4, &filenum, 0, 0, (short) 1, // nowait 0, 0, 0, 0, NULL); if (verbose) printf("client open ferr=%d\n", ferr); TEST_CHK_FEOK(ferr); for (inx = 0; inx < loop; inx++) { sprintf(send_buffer, "hello, greetings from %s, inx=%d", my_name, inx); cc = BWRITEREADX(filenum, send_buffer, (unsigned short) (strlen(send_buffer) + 1), // cast 0, &count_read, 0); if (verbose) printf("client wr cc=%d\n", cc); TEST_CHK_CCEQ(cc); tfilenum = -2; cc = BAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); if (verbose) printf("client awaitiox cc=%d, fn=%d\n", cc, tfilenum); if (abort1) { if (_xstatus_ne(cc)) { sleep(1); inx--; continue; } } else { TEST_CHK_CCEQ(cc); } printf("%s\n", send_buffer); } } else { ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenum, 0, 0, (short) 0, 1, 0, // sys msg 0, 0, NULL); TEST_CHK_FEOK(ferr); if (abort1) { } else if (abort2) { loop -= 2; } else { loop += 2; } for (inx = 0; inx < loop; inx++) { if (abort1 && (inx == 3)) util_abort_core_free(); cc = BREADUPDATEX(filenum, recv_buffer, (int) dsize, // cast &count_read, 0); if (verbose) { memcpy(&mt, recv_buffer, sizeof(mt)); printf("server cc=%d, mt=%d\n", cc, mt); } cc = BREPLYX(recv_buffer, 0, &count_written, 0, XZFIL_ERR_OK); TEST_CHK_CCEQ(cc); } } if (client) { ferr = BFILE_CLOSE_(filenum, 0); TEST_CHK_FEOK(ferr); } else { ferr = BFILE_CLOSE_(filenum, 0); TEST_CHK_FEOK(ferr); } ferr = file_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { _bcc_status bcc; bool client = false; int count_read; int count_written; int ferr; short filenum; int inx; int loop = 10; 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(client); ferr = file_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); util_gethostname(my_name, (int) sizeof(my_name)); if (client) { ferr = BFILE_OPEN_((char *) "$srv", 4, &filenum, 0, 0, 0, 0, 0, 0, 0, NULL); TEST_CHK_FEOK(ferr); for (inx = 0; inx < loop; inx++) { sprintf(send_buffer, "hello, greetings from %s, inx=%d", my_name, inx); bcc = BWRITEREADX(filenum, send_buffer, MAX_BUF, MAX_BUF, &count_read, 0); TEST_CHK_BCCEQ(bcc); assert(count_read == MAX_BUF); printf("%s\n", send_buffer); } ferr = BFILE_CLOSE_(filenum, 0); TEST_CHK_FEOK(ferr); } else { ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenum, 0, 0, 0, 1, 1, // no sys msg 0, 0, NULL); TEST_CHK_FEOK(ferr); for (inx = 0; inx < loop; inx++) { bcc = BREADUPDATEX(filenum, recv_buffer, MAX_BUF, &count_read, 0); TEST_CHK_BCCEQ(bcc); getri(&ri); #ifdef USE_SB_NEW_RI assert(ri.max_reply_count == MAX_BUF); #endif getri(&ri); #ifdef USE_SB_NEW_RI assert(ri.max_reply_count == MAX_BUF); #endif strcat(recv_buffer, "- reply from "); strcat(recv_buffer, my_name); count_read = (int) strlen(recv_buffer) + 1; // cast bcc = BREPLYX(recv_buffer, MAX_BUF, &count_written, 0, XZFIL_ERR_OK); TEST_CHK_BCCEQ(bcc); assert(count_written == MAX_BUF); } ferr = BFILE_CLOSE_(filenum, 0); TEST_CHK_FEOK(ferr); } ferr = file_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { 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[]) { bool bidir = false; bool bm = false; void *buf; double busy; _xcc_status cc; int count_read; int count_written; int count_xferred; int dsize = 1024; int ferr; short filenum[MAX_SERVERS]; short filenumr; int inx; int loop = 10; int max; int maxsp = 1; bool mq = false; bool nocopy = false; bool nowaitc = false; bool nowaits = false; int pinx; struct rusage r_start; struct rusage r_stop; char *recv_buffer_ptr; RI_Type ri; short sender_len; int sys_msg; struct timeval t_elapsed_data; struct timeval t_elapsed_open; struct timeval t_elapsed_total; struct timeval t_start_data; struct timeval t_start_total; struct timeval t_stop; SB_Tag_Type tag; short tfilenum; int timeout = -1; bool verbose = false; TAD zargs[] = { { "-bidir", TA_Bool, TA_NOMAX, &bidir }, { "-bm", TA_Bool, TA_NOMAX, &bm }, { "-client", TA_Bool, TA_NOMAX, &client }, { "-dsize", TA_Int, MAX_DBUF, &dsize }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-maxcp", TA_Int, MAX_CLIENTS, &maxcp }, { "-maxsp", TA_Int, MAX_SERVERS, &maxsp }, { "-mq", TA_Bool, TA_NOMAX, &mq }, { "-nocopy", TA_Bool, TA_NOMAX, &nocopy }, { "-nowaitc", TA_Bool, TA_NOMAX, &nowaitc }, { "-nowaits", TA_Bool, TA_NOMAX, &nowaits }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "", TA_End, TA_NOMAX, NULL } }; for (inx = 0; inx < MAX_CLIENTS; inx++) account[inx] = 0; signal(SIGUSR2, printaccount); ferr = file_init(&argc, &argv); TEST_CHK_FEOK(ferr); msfs_util_init_fs(&argc, &argv, file_debug_hook); arg_proc_args(zargs, false, argc, argv); if (maxcp < 0) maxcp = 1; if (maxsp < 0) maxsp = 1; util_test_start(client); ferr = file_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); if (nocopy) { ferr = file_buf_register(buf_alloc, buf_free); TEST_CHK_FEOK(ferr); } 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); if (client) sleep(1); util_time_timer_start(&t_start_total); if (client) { inx = atoi(&my_name[4]); printf("dsize=%d, loop=%d\n", dsize, loop); for (pinx = 0; pinx < maxsp; pinx++) { sprintf(serv, "$srv%d", pinx); ferr = BFILE_OPEN_(serv, (short) strlen(serv), &filenum[pinx], 0, 0, nowaitc ? (short) 1 : (short) 0, 0, 0, 0, 0, NULL); TEST_CHK_FEOK(ferr); } util_time_timer_start(&t_start_data); util_cpu_timer_start(&r_start); util_time_elapsed(&t_start_total, &t_start_data, &t_elapsed_open); max = loop; for (inx = 0; inx < max; inx++) { for (pinx = 0; pinx < maxsp; pinx++) { if (pinx == 0) { if (verbose) printf("%s-count=%d\n", my_name, inx); else if (mq && ((inx % 1000) == 0)) printf("%s-count=%d\n", my_name, inx); } cc = BWRITEREADX(filenum[pinx], send_buffer, (int) dsize, // cast bidir ? dsize : 0, &count_read, 0); } for (pinx = 0; pinx < maxsp; pinx++) { if (nowaitc) { TEST_CHK_CCEQ(cc); tfilenum = filenum[pinx]; cc = BAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); TEST_CHK_CCEQ(cc); } } } } else { ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr, 0, 0, nowaits ? (short) 1 : (short) 0, // nowait 1, 0, // sys msg 0, 0, NULL); TEST_CHK_FEOK(ferr); util_time_timer_start(&t_start_data); util_cpu_timer_start(&r_start); max = maxcp * loop; for (inx = 0; inx < max; inx++) { if (nocopy) { cc = file_buf_readupdatex(filenumr, &recv_buffer_ptr, &count_read, 0); buf_free(recv_buffer_ptr); } else cc = BREADUPDATEX(filenumr, recv_buffer, (int) dsize, // cast &count_read, 0); if (nowaits) { tfilenum = -1; cc = BAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); // don't check cc - could be sys msg sys_msg = _xstatus_ne(cc); } else sys_msg = _xstatus_ne(cc); if (sys_msg) inx--; if (!sys_msg) { getri(&ri); ferr = XPROCESSHANDLE_DECOMPOSE_(TPT_REF(ri.sender), NULL, // cpu NULL, // pin NULL, // nodenumber NULL, // nodename 0, // nodename NULL, // nodename_length sender, sizeof(sender), &sender_len, NULL); // sequence_number TEST_CHK_FEOK(ferr); sender[sender_len] = 0; if (verbose) printf("sender=%s\n", sender); char *p = &sender[4]; // past $cli int sender_inx = atoi(p); account[sender_inx]++; } cc = BREPLYX(recv_buffer, bidir ? dsize : 0, &count_written, 0, XZFIL_ERR_OK); TEST_CHK_CCEQ(cc); } } util_cpu_timer_stop(&r_stop); util_time_timer_stop(&t_stop); util_time_elapsed(&t_start_total, &t_stop, &t_elapsed_total); util_time_elapsed(&t_start_data, &t_stop, &t_elapsed_data); util_cpu_timer_busy(&r_start, &r_stop, &t_elapsed_data, &busy); if (client) { if (!bm) { print_elapsed("", &t_elapsed_total); print_elapsed(" (data)", &t_elapsed_data); print_elapsed(" (open)", &t_elapsed_open); } print_rate(bm, "", bidir ? 2 * loop : loop, dsize, &t_elapsed_data, busy); } else print_server_busy(bm, "", busy); if (client) { for (pinx = 0; pinx < maxsp; pinx++) { ferr = BFILE_CLOSE_(filenum[pinx], 0); TEST_CHK_FEOK(ferr); } } else { ferr = BFILE_CLOSE_(filenumr, 0); TEST_CHK_FEOK(ferr); ferr = file_mon_process_close(); TEST_CHK_FEOK(ferr); } ferr = file_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); printaccount(0); return 0; }
GuaReceiveFastStart::GuaReceiveFastStart() { _bcc_status status; Lng32 bufferAddr; readUpdate_ = FALSE; awaitiox_ = FALSE; replyx_ = FALSE; awaitioxError_ = 0; fileGetReceiveInfo_ = FALSE; zsys_ddl_smsg_open_reply_def openReply; //openError_ -- not altered openError_ = BFILE_OPEN_((char *)"$RECEIVE", 8, &receiveFile_, 0, 0, 1, 4000, 0); //open_ -- not altered open_ = TRUE; if (openError_ == 0) { status = BSETMODE(receiveFile_, 74, -1); if (_status_ne(status)) { // this is bad ABORT("Internal error on setmode($receive)"); } // readUpdateStatus_ -- not altered readUpdateStatus_ = BREADUPDATEX(receiveFile_, (char *)&readBuffer_[0], 80); // readUpdate_ -- altered readUpdate_ = TRUE; // bufferData_ -- altered bufferData_ = NULL; if (_status_eq(readUpdateStatus_)) // Did not get an error on READUPDATEX { // awaitioxStatus_ -- not altered awaitioxStatus_ = BAWAITIOX(&receiveFile_, (void **)&bufferAddr, &awaitioxCountTransferred_, (SB_Tag_Type *)&ioTag_, 100 * 60 *10); // 10 minutes // fileGetInfoError_ -- not altered fileGetInfoError_ = BFILE_GETINFO_(receiveFile_, &awaitioxError_); // awaitiox_ -- altered awaitiox_ = TRUE; if (fileGetInfoError_ == 0 && awaitioxError_ == 6) { fileGetReceiveInfoError_ = BFILE_GETRECEIVEINFO_((FS_Receiveinfo_Type *)&receiveInfo_); // fileGetReceiveInfo_ -- altered fileGetReceiveInfo_ = TRUE; if (fileGetReceiveInfoError_ == 0) { openReply.z_msgnumber = ZSYS_VAL_SMSG_OPEN; openReply.z_openid = 0; // GuaReceiveControlConnection id_ must be zero // replyxstatus_ -- not altered replyxstatus_ = BREPLYX((IpcMessageBufferPtr)&openReply, 4, &replyxCountWritten_, receiveInfo_.replyTag_, GuaOK); // replyx_ == altered replyx_ = TRUE; } } } } }
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[]) { _bcc_status bcc; void *buf; int cancel = 0; bool client = false; int closes; int count; int count_cancel; int count_read; int count_written; int count_xferred; int ferr; int inxl; int inxo; int inxs; int inxx; int loop = 10; int maxcp = 1; int maxout = 1; int maxsp = 1; int msg_count; bool mq = false; short filenumr; short filenums[MAX_SRV]; int send_len; char serv[20]; xzsys_ddl_smsg_def *sys_msg = (xzsys_ddl_smsg_def *) recv_buffer; SB_Tag_Type tago; short tfilenum; int timeout = -1; bool verbose = false; TAD zargs[] = { { "-cancel", TA_Int, TA_NOMAX, &cancel }, { "-client", TA_Bool, TA_NOMAX, &client }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-maxcp", TA_Int, MAX_CLI, &maxcp }, { "-maxout", TA_Int, MAX_OUT, &maxout }, { "-maxsp", TA_Int, MAX_SRV, &maxsp }, { "-mq", TA_Bool, TA_NOMAX, &mq }, { "-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); ferr = msg_mon_get_my_process_name(my_name, BUFSIZ); util_check("file_mon_get_my_process_name", ferr); if (client) { ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETSENDLIMIT, XMAX_SETTABLE_SENDLIMIT); assert(ferr == XZFIL_ERR_OK); for (inxs = 0; inxs < maxsp; inxs++) { sprintf(serv, "$srv%d", inxs); ferr = BFILE_OPEN_(serv, (short) strlen(serv), &filenums[inxs], 0, 0, (short) maxout, 0, 0, 0, 0, NULL); TEST_CHK_FEOK(ferr); } msg_count = 0; count_cancel = 0; for (inxl = 0; inxl < loop; inxl++) { count = 0; if (cancel) count_cancel = rnd(cancel); for (inxs = 0; inxs < maxsp; inxs++) { for (inxo = 0; inxo < maxout; inxo++) { send_len = rnd(BUFSIZ); bcc = BWRITEREADX(filenums[inxs], send_buffer[inxo], send_len, BUFSIZ, &count_read, inxo + 1); out_list[inxs][inxo] = inxo + 1; util_check("BWRITEREADX", ferr); } } for (inxs = 0; inxs < maxsp; inxs++) { for (inxo = 0; inxo < maxout; inxo++) { msg_count++; if (verbose) printf("client(%s): msg-count=%d\n", my_name, msg_count); count++; if (cancel && (count >= count_cancel)) { if (verbose) printf("client(%s): cancel, count=%d\n", my_name, count); count_cancel = rnd(cancel); count = 0; tago = out_list[inxs][inxo]; if (tago == 0) { for (inxx = maxout - 1; inxx > 0; inxx--) { tago = out_list[inxs][inxx]; if (tago > 0) break; } } if (verbose) printf("client(%s): cancel, tag=" PFTAG "\n", my_name, tago); ferr = BCANCELREQ(filenums[inxs], tago); util_check("BCANCELREQ", ferr); } else { tfilenum = filenums[inxs]; bcc = BAWAITIOX(&tfilenum, &buf, &count_xferred, &tago, timeout, NULL); TEST_CHK_BCCEQ(bcc); assert(tago <= maxout); out_list[inxs][tago-1] = 0; } } } if (mq) { if ((inxl % 100) == 0) printf("client(%s): count=%d\n", my_name, inxl); } } for (inxs = 0; inxs < maxsp; inxs++) { ferr = BFILE_CLOSE_(filenums[inxs]); TEST_CHK_FEOK(ferr); } } else { ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETRECVLIMIT, XMAX_SETTABLE_RECVLIMIT); assert(ferr == XZFIL_ERR_OK); ferr = XFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr, 0, 0, 0, 1, 0, // sys msg 0, 0, NULL); TEST_CHK_FEOK(ferr); closes = 0; msg_count = 0; // process requests for (;;) { bcc = BREADUPDATEX(filenumr, recv_buffer, BUFSIZ, &count_read, 0); if (_xstatus_ne(bcc)) { int mt = sys_msg->u_z_msg.z_msgnumber[0]; if (mt == XZSYS_VAL_SMSG_CLOSE) { closes++; if (verbose) printf("server(%s): closes=%d\n", my_name, closes); } else { const char *mtstr = msfs_util_get_sysmsg_str(mt); if (verbose) printf("server(%s): type=%s(%d)\n", my_name, mtstr, mt); } } else { msg_count++; if (verbose) printf("server(%s): msg-count=%d\n", my_name, msg_count); } bcc = BREPLYX(recv_buffer, count_read, &count_written, 0, XZFIL_ERR_OK); TEST_CHK_BCCEQ(bcc); if (closes >= maxcp) break; } } ferr = file_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { _bcc_status cc; bool chook = false; bool client = false; int count_read; int count_written; int ferr; int inx; void *result; bool shook = false; int status; SB_Thread::Thread *thr_test; TAD zargs[] = { { "-any1", TA_Bool, TA_NOMAX, &any1 }, { "-any2", TA_Bool, TA_NOMAX, &any2 }, { "-chook", TA_Bool, TA_NOMAX, &chook }, { "-client", TA_Bool, TA_NOMAX, &client }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "-shook", TA_Bool, TA_NOMAX, &shook }, { "-thread", TA_Bool, TA_NOMAX, &thread }, { "", 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"); ferr = file_init(&argc, &argv); TEST_CHK_FEOK(ferr); msfs_util_init_fs(&argc, &argv, file_debug_hook); util_test_start(client); ferr = file_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); if (client) { if (thread) { thr_test = new SB_Thread::Thread(thread_test_fun, "thr-test"); thr_test->start(); status = thr_test->join(&result); TEST_CHK_STATUSOK(status); delete thr_test; } else { thread_test_fun(NULL); } } else { ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenum, 0, 0, 0, 1, 1, // no sys msg 0, 0, NULL); TEST_CHK_FEOK(ferr); for (inx = 0; inx < loop; inx++) { cc = BREADUPDATEX(filenum, recv_buffer, BUFSIZ, &count_read, 0); TEST_CHK_CCEQ(cc); strcat(recv_buffer, "- reply from "); strcat(recv_buffer, my_name); count_read = (unsigned short) (strlen(recv_buffer) + 1); // cast cc = BREPLYX(recv_buffer, count_read, &count_written, 0, XZFIL_ERR_OK); TEST_CHK_CCEQ(cc); } ferr = BFILE_CLOSE_(filenum, 0); TEST_CHK_FEOK(ferr); } ferr = file_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { _xcc_status cc; bool client = false; int count_read; int count_written; int ferr; short filenum; int inx; void *result; int status; SB_Thread::Thread *thr_cli; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "-sname", TA_Str, TA_NOMAX, &sname }, { "", TA_End, TA_NOMAX, NULL } }; ferr = file_init(&argc, &argv); TEST_CHK_FEOK(ferr); msfs_util_init_fs(&argc, &argv, file_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = file_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); ferr = msg_mon_get_my_process_name(my_name, BUFSIZ); util_check("msg_mon_get_my_process_name", ferr); if (client) { thr_cli = new SB_Thread::Thread(thread_cli_fun, "cli"); thr_cli->start(); status = thr_cli->join(&result); TEST_CHK_STATUSOK(status); delete thr_cli; } else { 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 + 4); inx++) { cc = BREADUPDATEX(filenum, recv_buffer, BUFSIZ, &count_read, 0); if (_xstatus_ne(cc)) { count_read = 0; } else { strcat(recv_buffer, "- reply from "); strcat(recv_buffer, my_name); count_read = (int) (strlen(recv_buffer) + 1); // cast } cc = BREPLYX(recv_buffer, count_read, &count_written, 0, XZFIL_ERR_OK); TEST_CHK_CCEQ(cc); } ferr = BFILE_CLOSE_(filenum, 0); TEST_CHK_FEOK(ferr); } ferr = file_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { bool bidir = false; char *buf; _xcc_status cc; bool check = false; bool client = false; bool copy = false; int count_read; int count_written; int count_xferred; int dsize = 1024; int ferr; short filenum; int inx; int inx2; #ifdef MEM_LEAK int leak_loop; #endif int loop = 10; bool nowait = false; long t_elapsed; long t_elapsed_sec; struct timeval t_start; struct timeval t_stop; SB_Tag_Type tag; short tfilenum; int timeout = -1; int rc; bool reverse = false; bool verbose = false; int wc; TAD zargs[] = { { "-bidir", TA_Bool, TA_NOMAX, &bidir }, { "-check", TA_Bool, TA_NOMAX, &check }, { "-client", TA_Bool, TA_NOMAX, &client }, { "-copy", TA_Bool, TA_NOMAX, © }, { "-dsize", TA_Int, MAX_DBUF, &dsize }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-nowait", TA_Bool, TA_NOMAX, &nowait }, { "-reverse", TA_Bool, TA_NOMAX, &reverse }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "-v", TA_Bool, TA_NOMAX, &verbose }, { "", TA_End, TA_NOMAX, NULL } }; ferr = file_init(&argc, &argv); TEST_CHK_FEOK(ferr); msfs_util_init_fs(&argc, &argv, file_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = file_mon_process_startup(!client); // system messages? TEST_CHK_FEOK(ferr); if (bidir) reverse = false; for (inx2 = 0; inx2 < dsize; inx2++) send_buffer[inx2] = CHK_CHAR; if (client) { printf("bidir=%d, check=%d, copy=%d, dsize=%d, loop=%d, nowait=%d, reverse=%d\n", bidir, check, copy, dsize, loop, nowait, reverse); ferr = BFILE_OPEN_((char *) "$srv", 4, &filenum, 0, 0, nowait ? (short) 1 : (short) 0, 0, 0, 0, 0, NULL); TEST_CHK_FEOK(ferr); util_time_timer_start(&t_start); #ifdef MEM_LEAK for (leak_loop = 0; ; leak_loop++) { if ((leak_loop % 100) == 0) printf("leak_loop=%d\n", leak_loop); #endif for (inx = 0; inx < loop; inx++) { if (verbose) printf("count=%d\n", inx); wc = dsize; rc = dsize; if (reverse) wc = 0; else if (!bidir) rc = 0; // !bidir && !reverse cc = BWRITEREADX(filenum, send_buffer, wc, rc, &count_read, 0); TEST_CHK_CCEQ(cc); if (nowait) { tfilenum = filenum; cc = BAWAITIOX(&tfilenum, (void **) &buf, &count_xferred, &tag, timeout, NULL); TEST_CHK_CCEQ(cc); if (check) { assert(buf == send_buffer); assert(count_xferred == 0); if (rc) { for (inx2 = 0; inx2 < dsize; inx2++) { if (buf[inx2] != CHK_CHAR) { printf("buf[%d]=%d\n", inx2, buf[inx2]); assert(buf[inx2] == CHK_CHAR); } } } } } } #ifdef MEM_LEAK } #endif 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_sec = t_elapsed / 1000000; t_elapsed -= t_elapsed_sec * 1000000; printf("elapsed=%ld.%ld\n", t_elapsed_sec, t_elapsed); ferr = BFILE_CLOSE_(filenum, 0); TEST_CHK_FEOK(ferr); } else { ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenum, 0, 0, nowait ? (short) 1 : (short) 0, 1, 1, // no sys msg 0, 0, NULL); TEST_CHK_FEOK(ferr); #ifdef MEM_LEAK for (leak_loop = 0; ; leak_loop++) { #endif for (inx = 0; inx < loop; inx++) { if (copy) cc = BREADUPDATEX(filenum, recv_buffer, dsize, &count_read, inx); else cc = file_buf_readupdatex(filenum, &buf, &count_read, inx); TEST_CHK_CCEQ(cc); if (nowait) { tfilenum = filenum; cc = BAWAITIOX(&tfilenum, (void **) &buf, &count_xferred, &tag, timeout, NULL); TEST_CHK_CCEQ(cc); if (check) { if (reverse) assert(count_xferred == 0); else assert(count_xferred == dsize); assert(tag == inx); if (copy) assert(buf == recv_buffer); } } else { if (reverse) assert(count_read == 0); else assert(count_read == dsize); if (copy) buf = recv_buffer; else if (reverse) { buf = send_buffer; } } if (check && !reverse) { for (inx2 = 0; inx2 < dsize; inx2++) { if (buf[inx2] != CHK_CHAR) { printf("buf[%d]=%d\n", inx2, buf[inx2]); assert(buf[inx2] == CHK_CHAR); } } } if (bidir || reverse) cc = BREPLYX(buf, dsize, // wc &count_written, 0, XZFIL_ERR_OK); else cc = BREPLYX(buf, 0, // wc &count_written, 0, XZFIL_ERR_OK); TEST_CHK_CCEQ(cc); if (!copy && !reverse) free(buf); } #ifdef MEM_LEAK } #endif ferr = BFILE_CLOSE_(filenum, 0); TEST_CHK_FEOK(ferr); } ferr = file_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
int main(int argc, char *argv[]) { _bcc_status bcc; void *buf; bool client = false; int count_read; int count_written; int count_xferred; #ifdef USE_SB_FC int err; #endif // USE_SB_FC int ferr; short filenumr; short filenums[MAX_SRV]; #ifdef USE_SB_FC short info_count; #endif // USE_SB_FC int inx; int len; #ifdef USE_SB_FC short list_inx; #endif // USE_SB_FC int loop = 10; char *p; char recv_buffer[BUFSIZ]; char send_buffer[MAX_SRV][BUFSIZ]; #ifdef USE_SB_FC int socka1; int socka2; int sockc1[MAX_SRV]; int sockc2[MAX_SRV]; int sockl; #endif // USE_SB_FC int srv; SB_Tag_Type tag; short tfilenum; int timeout = -1; TAD zargs[] = { { "-client", TA_Bool, TA_NOMAX, &client }, { "-loop", TA_Int, TA_NOMAX, &loop }, { "-maxcp", TA_Next, TA_NOMAX, NULL }, { "-maxsp", TA_Next, TA_NOMAX, NULL }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "-v", TA_Bool, TA_NOMAX, &verbose }, { "", TA_End, TA_NOMAX, NULL } }; ferr = file_init(&argc, &argv); TEST_CHK_FEOK(ferr); msfs_util_init_fs(&argc, &argv, file_debug_hook); arg_proc_args(zargs, false, argc, argv); util_test_start(client); ferr = file_mon_process_startup(!client); // system messages TEST_CHK_FEOK(ferr); if (client) { #ifdef USE_SB_FC // check empty list ferr = BFILE_COMPLETE_GETINFO_((short *) info_list, MAX_INFO_LIST, &info_count); TEST_CHK_FEOK(ferr); assert(info_count == 0); // add bogus add_list[0].z_fnum_fd = 99; add_list[0].u_z_options.z_options.z_set_file = 0; // set add_list[0].u_z_options.z_options.z_filetype = 0; // guardian ferr = BFILE_COMPLETE_SET_((short *) add_list, 1, &list_inx); assert(ferr == XZFIL_ERR_NOTFOUND); assert(list_inx == 0); #endif // USE_SB_FC for (srv = 0; srv < MAX_SRV; srv++) { sprintf(send_buffer[srv], "$srv%d", srv); len = (int) strlen(send_buffer[srv]); ferr = BFILE_OPEN_((char *) send_buffer[srv], (short) len, &filenums[srv], 0, 0, 1, 0, 0, 0, 0, NULL); TEST_CHK_FEOK(ferr); } #ifdef USE_SB_FC do_set_guardian(filenums[0], 0, 1); // add do_set_guardian(filenums[0], 1, 0); // remove (specific) do_set_guardian(filenums[0], 0, 1); // add do_set_guardian(-1, 1, 0); // remove (all) do_set_guardian(-1, 0, 1); // add (all) #endif // USE_SB_FC for (srv = 0; srv < MAX_SRV; srv++) { for (inx = 0; inx < loop; inx++) { sprintf(send_buffer[srv], "inx=%d", inx); bcc = BWRITEREADX(filenums[srv], send_buffer[srv], (short) (strlen(send_buffer[srv]) + 1), BUFSIZ, &count_read, 1); TEST_CHK_BCCEQ(bcc); #ifdef USE_SB_FC ferr = BFILE_COMPLETE_((short *) &info, timeout, NULL, 0, NULL); TEST_CHK_FEOK(ferr); assert(info.z_tag == 1); #else tfilenum = -1; bcc = BAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); TEST_CHK_BCCEQ(bcc); #endif } } for (srv = 0; srv < MAX_SRV; srv++) { p = strchr(send_buffer[srv], ':'); *p = 0; p++; strcpy(host[srv], send_buffer[srv]); port[srv] = (unsigned short) atoi(p); if (verbose) printf("server[%d] returned host=%s, port=%d\n", srv, host[srv], port[srv]); } #ifdef USE_SB_FC if (verbose) printf("client connecting up\n"); // connect up, and setup fds for (srv = 0; srv < MAX_SRV; srv++) { sockc1[srv] = do_connect(srv); sockc2[srv] = do_connect(srv); } do_set_guardian(-1, 1, 0); // remove (all) do_set_linux(sockc1[0], 0, 0, 0, 0, 1); // add-no rr/wr/exc // nothing should be ready timeout = 0; ferr = BFILE_COMPLETE_((short *) &info, timeout, NULL, 0, NULL); assert(ferr == XZFIL_ERR_TIMEDOUT); // server has sent something, so rr should be on sleep(1); do_set_linux(sockc1[0], 0, 1, 0, 0, 1); // rr timeout = -1; ferr = BFILE_COMPLETE_((short *) &info, timeout, NULL, 0, NULL); TEST_CHK_FEOK(ferr); assert(info.z_filetype); // linux assert(info.z_error == XZFIL_ERR_OK); assert(info.z_fnum_fd == sockc1[0]); assert(info.u_z_return_value.z_return_value.z_read_ready); assert(!info.u_z_return_value.z_return_value.z_write_ready); assert(!info.u_z_return_value.z_return_value.z_exception); // wr should be on do_set_linux(sockc1[0], 0, 0, 1, 0, 1); // wr timeout = -1; ferr = BFILE_COMPLETE_((short *) &info, timeout, NULL, 0, NULL); TEST_CHK_FEOK(ferr); assert(info.z_filetype); // linux assert(info.z_error == XZFIL_ERR_OK); assert(info.z_fnum_fd == sockc1[0]); assert(!info.u_z_return_value.z_return_value.z_read_ready); assert(info.u_z_return_value.z_return_value.z_write_ready); assert(!info.u_z_return_value.z_return_value.z_exception); do_set_linux(sockc1[0], 0, 0, 0, 0, 1); // clear ready do_set_linux(sockc2[0], 0, 0, 0, 0, 2); // add-no rr/wr/exc // nothing should be ready timeout = 0; ferr = BFILE_COMPLETE_((short *) &info, timeout, NULL, 0, NULL); assert(ferr == XZFIL_ERR_TIMEDOUT); // rr should NOT be ready do_set_linux(sockc2[0], 0, 1, 0, 0, 2); // rr timeout = 100; ferr = BFILE_COMPLETE_((short *) &info, timeout, NULL, 0, NULL); assert(ferr == XZFIL_ERR_TIMEDOUT); // test fairness (check trace) do_set_linux(-1, 1, 0, 0, 0, 0); // clear linux for (srv = 0; srv < MAX_SRV; srv++) do_set_guardian(filenums[srv], 0, srv + 1); // add for (srv = 0; srv < MAX_SRV; srv++) { bcc = BWRITEREADX(filenums[srv], NULL, 0, BUFSIZ, &count_read, 1); TEST_CHK_BCCEQ(bcc); } usleep(10000); for (srv = 0; srv < MAX_SRV; srv++) { timeout = -1; ferr = BFILE_COMPLETE_((short *) &info, timeout, NULL, 0, NULL); TEST_CHK_FEOK(ferr); assert(!info.z_filetype); // guardian assert(info.z_error == XZFIL_ERR_OK); assert(info.z_fnum_fd == filenums[srv]); } #endif // USE_SB_FC if (verbose) printf("client closing\n"); for (srv = 0; srv < MAX_SRV; srv++) { ferr = BFILE_CLOSE_(filenums[srv], 0); TEST_CHK_FEOK(ferr); } printf("if there were no asserts, all is well\n"); } else { #ifdef USE_SB_FC sockl = do_listen(); assert(sockl != -1); #endif // USE_SB_FC ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr, 0, 0, 1, 1, 1, // no sys msg 0, 0, NULL); TEST_CHK_FEOK(ferr); for (inx = 0; inx < loop; inx++) { bcc = BREADUPDATEX(filenumr, recv_buffer, BUFSIZ, &count_read, 1); TEST_CHK_BCCEQ(bcc); tfilenum = filenumr; bcc = BAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); TEST_CHK_BCCEQ(bcc); assert(tag == 1); sprintf(recv_buffer, "%s:%d\n", host[0], port[0]); count_read = (short) (strlen(recv_buffer) + 1); bcc = BREPLYX(recv_buffer, count_read, &count_written, 0, XZFIL_ERR_OK); TEST_CHK_BCCEQ(bcc); } #ifdef USE_SB_FC if (verbose) printf("server accepting\n"); socka1 = do_accept(sockl); socka2 = do_accept(sockl); err = write(socka1, recv_buffer, 1); assert(err == 1); for (inx = 0; inx < 1; inx++) { bcc = BREADUPDATEX(filenumr, recv_buffer, BUFSIZ, &count_read, 1); TEST_CHK_BCCEQ(bcc); tfilenum = filenumr; bcc = BAWAITIOX(&tfilenum, &buf, &count_xferred, &tag, timeout, NULL); TEST_CHK_BCCEQ(bcc); bcc = BREPLYX(recv_buffer, 0, &count_written, 0, XZFIL_ERR_OK); TEST_CHK_BCCEQ(bcc); } #endif // USE_SB_FC if (verbose) printf("server closing\n"); ferr = BFILE_CLOSE_(filenumr, 0); TEST_CHK_FEOK(ferr); } ferr = file_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }