void test_nodes() { const char * test_nodes[] = { "memyselfi:129", "zebra:321", "apple:123", "intheory:876"}; init_network_nodes(0, 4, test_nodes); assert(my_id() == 2); assert(get_port(0) == 123); assert(get_port(1) == 876); assert(get_port(2) == 129); assert(get_port(3) == 321); char *got = get_address(0); assert(strcmp(got, "apple") == 0); free(got); got = get_address(1); assert(strcmp(got, "intheory") == 0); free(got); got = get_address(2); assert(strcmp(got, "memyselfi") == 0); free(got); got = get_address(3); assert(strcmp(got, "zebra") == 0); free(got); destroy_network_nodes(); }
void notice(const char *msg, ...) { if (log_level < NOTICE) return; va_list args; fprintf(stdout, "NOTICE-%d:", my_id()); va_start( args, msg ); vfprintf(stdout, msg, args ); va_end( args ); fprintf(stdout, "\n" ); }
void info(const char *msg, ...) { if (log_level < INFO) return; va_list args; fprintf(stdout, "INFO-%d:", my_id()); va_start( args, msg ); vfprintf(stdout, msg, args ); va_end( args ); fprintf(stdout, "\n" ); }
void error(const char *msg, ...) { if (log_level < ERROR) return; va_list args; fprintf(stderr, "ERROR-%d: ", my_id()); va_start( args, msg ); vfprintf(stderr, msg, args ); va_end( args ); fprintf(stderr, "\n" ); }
int main(int argc, char *argv[]) { int id = my_id(); printf("Stackbomb started: %d\n", id); printf("Naive Fibonacci(%d): ", MAX_DEPTH); printf("%d\n", naive_fib(MAX_DEPTH)); printf("Stackbomb finished: %d\n", id); return 0; }
void log_state(state s, enum role_t r) { if (log_level < TRACE) return; int line_size = (num_nodes()) * 9 + 6; char line[line_size]; draw_base_graph(line, line_size); int meidx = graph_index(my_id(), r); line[meidx] = getStateName(s.state)[2]; printf("GRAPH: %s STATE %s %s %ld %ld %ld dead %ld\n", line, getRole(r), getStateName(s.state), s.ticket, s.slot, s.value, s.deadline); }
void __sys_entry(void * dummy) { #ifdef THREAD_SAFE __thread_state_init(&__ts); #endif main(); process_delete(my_id()); }
int main(int argc, char *argv[]) { int id = my_id(); char buf[8]; sprintf(buf, "+%d\n", id); kprint(buf); process_create(PROGRAM); process_create(PROGRAM); sprintf(buf, "-%d\n", id); kprint(buf); return 0; }
int main(int argc, char *argv[]) { char buf[64]; int *ptr; for (int i = 0;; i++) { sprintf(buf, ">>> hello from %d, iteration %d\n", my_id(), i); kprint(buf); ptr = (int*) malloc(SIZE); *ptr = i; assert(*ptr == i); usleep(SLEEP_MS * 1000); } return 0; }
void __sys_entry(void * bootinfo) { bi_header_t * bi_hdr; bi_hdr = bootinfo; __okl4_bootinfo = bootinfo; //__malloc_init((uintptr_t) bi_hdr->heap_base, (uintptr_t) bi_hdr->heap_end); #ifdef THREAD_SAFE __thread_state_init(&__ts); #endif main(); process_delete(my_id()); }
message * __recv_from(int r, int from_node, int slot, unsigned int mask) { int pos = role_read_ipos[r]; if (pos < 0) { pos = role_read_ipos[r] = 0; } int initial_pos = pos; message * msg = get_if_matches(pos, from_node, slot, mask); while(msg == 0) { pos = advance_role(r); if (pos == initial_pos) { return 0; } msg = get_if_matches(pos, from_node, slot, mask); } log_message("recv_from", msg); log_graph(msg->from, my_id(), msg->type, 1); return msg; }
void say_hello() { if (!set_it(SLOT, my_id(), 0)) { printf("ERROR: Can't get a word in!"); exit(1); } }
int __send_local(long ticket, unsigned short type, int slot, long value, unsigned short flags) { message *msg = create_message(my_id(), my_id(), ticket, type, slot, value, flags); log_message("send_local", msg); add_message(msg); return 1; }
int main(int argc, char **argv) { fildes_t fds[FILES]; char *filenames[FILES]; int pid = my_id(); for (int i = 0; i < FILES; i++) { filenames[i] = (char *) malloc(sizeof(char) * (sizeof(FILENAME) + 8)); snprintf(filenames[i], sizeof(FILENAME) + 8, "%s_%d_%d", FILENAME, pid, i); fds[i] = open(filenames[i], FM_READ | FM_WRITE); if (fds[i] < 0) { printf("stressvfs (%d) :%s cannot be opened: %s\n", pid, filenames[i], sos_error_msg(fds[i])); exit(EXIT_FAILURE); } } char *data = malloc(sizeof(char) * DATA_SIZE); char *data2 = malloc(sizeof(char) * DATA_SIZE); int nw = 0, nr = 0, rw = 0; for (int loopc = 0; loopc < LOOP_MAX; loopc++) { /* Write a lot */ for (int i = 0; i < FILES; i++) { nw = 0; while ((rw = write(fds[i], data, DATA_SIZE)) > 0) { nw += rw; if (nw >= WRITE_SIZE) { break; } } if (rw < 0) { printf("stressvfs (%d): Error on write (%s) (%d) (%d) (%s)\n", pid, filenames[i], fds[i], rw, sos_error_msg(rw)); exit(EXIT_FAILURE); } } /* Read it back */ for (int i = FILES - 1; i >= 0; i--) { nr = 0; while ((rw = read(fds[i], data2, DATA_SIZE)) > 0) { nr += rw; if (nr >= WRITE_SIZE) { break; } } if (rw < 0 && rw != SOS_VFS_EOF) { printf("stressvfs (%d): Error on read (%s) (%d) (%d) (%s)\n", pid, filenames[i], fds[i], rw, sos_error_msg(rw)); exit(EXIT_FAILURE); } /* Verify it */ int error = 0; for (int j = 0; j < DATA_SIZE; j++) { if (data[j] != data2[j]) { printf("stressvfs (%d): Data Corrupt! (%c != %c), (%d)\n", pid, data[j], data2[j], j); error = 1; } } if (error) { exit(EXIT_FAILURE); } } } }