static int test_rfork1(int idx, struct bproc_test_info_t *inf) { int err, i; #if 0 int cc, ncc, lw; /* ACTUAL values */ int c_cc, c_ncc, c_lw; /* CORRECT values */ #endif printf(" ppid=%d(%d)", getpid(), bproc_currnode()); fflush(stdout); for (i=1; i < inf->nprocs; i++) { inf->pid[i] = bproc_rfork(inf->node[i]); if (inf->pid[i] < 0) { fprintf(stderr, "bproc_rfork(%d): %s\n", inf->pid[i], bproc_strerror(errno)); exit(1); } if (inf->pid[i] == 0) { /* CHILD */ exit(0); } printf(" pid=%d", inf->pid[i]); fflush(stdout); } #if 0 /* This sanity check is broken */ /* Sanity check our process tree */ cc = child_count(); ncc = nlchild_count(); lw = local_wait(0); c_cc = 2; c_ncc = (inf->pid[0] == inf->pid[1] || inf->pid[0] == -1) ? 0 : 2; c_lw = (inf->pid[0] == inf->pid[1] || inf->pid[0] == -1) ? 1 : 0; if ((cc != c_cc) || (ncc != c_ncc) || (lw != c_lw)) { printf("\nProcess State:\n"); printf(" kern mine\n"); printf(" child_count = %-4d %d%s\n", cc, c_cc, cc != c_cc ? " ** MISMATCH **":""); printf(" nlchild_count = %-4d %d%s\n", ncc, c_ncc, ncc != c_ncc ? " ** MISMATCH **":""); printf(" local_wait = %-4d %d%s\n", lw, c_lw, lw != c_lw ? " ** MISMATCH **":""); for (i=1; i < inf->nprocs; i++) printf(" ch[%d]=%d(%s)", i, inf->pid[i], proc_str(proc_arr(inf->arr,i))); printf("\n"); } #endif err = 0; for (i=1; i < inf->nprocs; i++) { if (wait(0) < 0) { printf("wait: %s", strerror(errno)); err = 1; } } exit(err); }
/* these 2 functions will return the inner node IP, special for Linux Scyld. G. Zheng */ skt_ip_t skt_innode_my_ip(void) { #if CMK_BPROC /* on Scyld, the hostname is just the node number */ char hostname[200]; sprintf(hostname, "%d", bproc_currnode()); return skt_innode_lookup_ip(hostname); #else return skt_my_ip(); #endif }
int main(int argc, char *argv[]) { int nnodes, pid; int n1, n2; enum proc_loc p, c; setvbuf(stdout, 0, _IONBF, 0); setvbuf(stderr, 0, _IONBF, 0); nodes[0] = -99; nodes[1] = -99; fill_node_list(nodes, &nnodes, 2); if (nnodes < 2) { printf("Only got %d slaves - not doing all tests.\n", nnodes); } signal(SIGCHLD, child_handler); for (p = proc_fe; p < proc_inv; p++) { for (c = proc_fe; c <= proc_inv; c++) { printf("parent=%-10s child=%-10s : ",proc_names[p], proc_names[c]); /* Setup parent */ switch (p) { case proc_fe: n1 = BPROC_NODE_MASTER; break; case proc_sl: n1 = nodes[0]; break; default: printf("Huh?\n"); exit(1); } switch (c) { case proc_fe: n2 = BPROC_NODE_MASTER; break; case proc_sl: n2 = (n1 == BPROC_NODE_MASTER) ? nodes[0] : nodes[1]; break; case proc_inv: n2 = -100; break; default: printf("What?\n"); exit(1); } if (n1 == -99 || n2 == -99) { printf("not enough nodes"); goto next; } if (bproc_currnode() != n1 && bproc_move(n1) != 0) { printf("\nbproc_move(%d): %s\n", n1, strerror(errno)); exit(1); } sigchld_flag = 0; if (n2 != -100) { /* Expect a valid move */ pid = bproc_rfork(n2); if (pid < 0) { printf("rfork failed: %s", strerror(errno)); goto next; } if (pid == 0) exit(0); if (waitpid(pid, 0, 0) != pid) { printf("wait failed: %s", strerror(errno)); goto next; } if (sigchld_flag != 1) { printf("wrong number of SIGCHLDs - expecting %d; got %d", 1, sigchld_flag); goto next; } printf("Ok."); } else { /* Expect an error and no SIGCHLD */ pid = bproc_rfork(n2); if (pid == 0) { printf("bproc_rfork returned zero for an invalid" " node number.\n"); exit(1); } if (pid > 0) { printf("bproc_rfork returned > zero for an" "invalid node number.\n"); goto next; } usleep(SIGWAIT); if (sigchld_flag) { printf("Got an unexpected SIGCHLD on a failed " "bproc_rfork.\n"); goto next; } printf("Ok."); } next: printf("\n"); } } usleep(SIGWAIT); /* allow IO to flush. */ exit(0); }