void tst_run_tcases(int argc, char *argv[], struct tst_test *self) { unsigned int i = 0; unsigned long long stop_time = 0; int cont = 1; tst_test = self; TCID = tst_test->tid; do_setup(argc, argv); if (duration > 0) stop_time = get_time_ms() + (unsigned long long)(duration * 1000); for (;;) { cont = 0; if (i < (unsigned int)iterations) { i++; cont = 1; } if (stop_time && get_time_ms() < stop_time) cont = 1; if (!cont) break; run_tests(); } do_cleanup(); do_exit(); }
size_t fwrite(const void * ptr, size_t size, size_t nmemb, FILE * stream) { do_setup(); if(!isatty(fileno(stream))) { io_stats.fwrite_total += size * nmemb; io_stats.fwrite_calls++; } return _IO_fwrite(ptr, size, nmemb, stream); }
ssize_t pwrite(int fd, const void * buf, size_t count, off_t offset) { do_setup(); if(!isatty(fd)) { io_stats.pwrite_total += count; io_stats.pwrite_calls++; } return __libc_pwrite(fd, buf, count, offset); }
size_t fread(void * ptr, size_t size, size_t nmemb, FILE * stream) { do_setup(); if(!isatty(fileno(stream))) { io_stats.fread_total += size * nmemb; io_stats.fread_calls++; } return _IO_fread(ptr, size, nmemb, stream); }
ssize_t pread(int fd, void * buf, size_t count, off_t offset) { do_setup(); if(!isatty(fd)) { io_stats.pread_total += count; io_stats.pread_calls++; } return __libc_pread(fd, buf, count, offset); }
ssize_t write(int fd, const void * buf, size_t count) { do_setup(); if(!isatty(fd)) { io_stats.write_total += count; io_stats.write_calls++; } return __write(fd, buf, count); }
ssize_t read(int fd, void * buf, size_t count) { do_setup(); if(!isatty(fd)) { io_stats.read_total += count; io_stats.read_calls++; } return __read(fd, buf, count); }
void tst_run_tcases(int argc, char *argv[], struct tst_test *self) { int ret; lib_pid = getpid(); tst_test = self; do_setup(argc, argv); TCID = tid; SAFE_SIGNAL(SIGALRM, alarm_handler); SAFE_SIGNAL(SIGUSR1, heartbeat_handler); if (tst_test->all_filesystems) ret = run_tcases_per_fs(); else ret = fork_testrun(); do_exit(ret); }
int GDCT_Transfer::svc() { // 1 连接讯源服务器 // 2 向讯源服务器签到 // 3 退出时签退 do_setup(); is_connected_ = 0; // 进入主循环 while(KsgGetGateway()->is_running()) { if(is_connected_!=1) { if(do_connect_svr()!=0) { KSG_SLEEP(5000); continue; } if(do_login_svr()!=0) { // 登陆失败! do_disconnect(); KSG_SLEEP(5000); continue; } } ACE_Time_Value now_time = ACE_OS::gettimeofday(); if(now_time.sec()-this->last_success_time_.sec() > 180) { // 有 180s 没有通讯成功,进行一次心跳测试 do_send_heartbeat(); continue; } do_main_service(); } return 0; }
int main(int argc, char * const argv[]) { int option_index; char command[1024]; /* Initialize default strings */ strcpy(vmlinux, "--no-vmlinux"); strcpy(kernel_range, ""); while (1) { int c = getopt_long(argc, argv, "", long_options, &option_index); if (c == -1) { break; } switch (c) { case 0: break; /* --event */ case 'e': if (num_events == MAX_EVENTS) { fprintf(stderr, "More than %d events specified\n", MAX_EVENTS); exit(1); } if (process_event(optarg)) { exit(1); } break; /* --vmlinux */ case 'v': sprintf(vmlinux, "-k %s", optarg); break; /* --kernel-range */ case 'r': sprintf(kernel_range, "-r %s", optarg); break; /* --shutdown */ case 'h': { int pid = read_num(OP_DATA_DIR"/lock"); if (pid >= 0) { kill(pid, SIGKILL); } setup_session_dir(); break; } /* --status */ case 't': do_status(); break; default: usage(); exit(1); } } verbose("list_events = %d\n", list_events); verbose("setup = %d\n", setup); if (list_events) { do_list_events(); } if (quick) { process_event("CPU_CYCLES"); setup = 1; } if (reset) { do_reset(); } if (show_usage) { usage(); } if (setup) { if (do_setup()) { fprintf(stderr, "do_setup failed"); exit(1); } } if (num_events != 0) { int i; strcpy(command, "oprofiled --session-dir="OP_DATA_DIR); #if !defined(WITH_ARM_V7_A) /* Since counter #3 can only handle CPU_CYCLES, check and shuffle the * order a bit so that the maximal number of events can be profiled * simultaneously */ if (num_events == 3) { for (i = 0; i < num_events; i++) { int event_idx = selected_events[i]; if (event_info[event_idx].id == 0xff) { break; } } /* No CPU_CYCLES is found */ if (i == 3) { fprintf(stderr, "You can only specify three events if one of " "them is CPU_CYCLES\n"); exit(1); } /* Swap CPU_CYCLES to counter #2 (starting from #0)*/ else if (i != 2) { int temp; temp = selected_events[2]; selected_events[2] = selected_events[i]; selected_events[i] = temp; temp = selected_counts[2]; selected_counts[2] = selected_counts[i]; selected_counts[i] = temp; } } #endif /* Configure the counters and enable them */ for (i = 0; i < num_events; i++) { int event_idx = selected_events[i]; int setup_result = 0; if (i == 0) { snprintf(command+strlen(command), 1024 - strlen(command), " --events="); } else { snprintf(command+strlen(command), 1024 - strlen(command), ","); } /* Compose name:id:count:unit_mask:kernel:user, something like * --events=CYCLES_DATA_STALL:2:0:200000:0:1:1,.... */ snprintf(command+strlen(command), 1024 - strlen(command), "%s:%d:%d:%d:0:1:1", event_info[event_idx].name, event_info[event_idx].id, i, selected_counts[i]); setup_result |= echo_dev("1", 0, "user", i); setup_result |= echo_dev("1", 0, "kernel", i); setup_result |= echo_dev("0", 0, "unit_mask", i); setup_result |= echo_dev("1", 0, "enabled", i); setup_result |= echo_dev(NULL, selected_counts[i], "count", i); setup_result |= echo_dev(NULL, event_info[event_idx].id, "event", i); if (setup_result) { fprintf(stderr, "Counter configuration failed for %s\n", event_info[event_idx].name); fprintf(stderr, "Did you do \"opcontrol --setup\" first?\n"); exit(1); } } /* Disable the unused counters */ for (i = num_events; i < MAX_EVENTS; i++) { echo_dev("0", 0, "enabled", i); } snprintf(command+strlen(command), 1024 - strlen(command), " %s", vmlinux); if (kernel_range[0]) { snprintf(command+strlen(command), 1024 - strlen(command), " %s", kernel_range); } verbose("command: %s\n", command); system(command); } if (start) { echo_dev("1", 0, "enable", -1); } if (stop) { echo_dev("1", 0, "dump", -1); echo_dev("0", 0, "enable", -1); } }
int main() { struct Game *game = malloc(sizeof(struct Game)); char buf[BUFSIZ]; char *index; char *arg[4]; int arg_num; while (fgets(buf, sizeof(buf), stdin) != NULL) { index = buf; arg_num = 0; arg[arg_num] = index; for (;(*index != '\n'); index++) { if (*index == ' ') { *index = '\0'; arg[arg_num+1] = index+1; arg_num++; } } *index = '\0'; if (!strcmp(arg[0], "turn")) { game->turn = atoi(arg[1]); fprintf(stderr, "Got turn %d\n", game->turn); if (game->turn) { game->state = INGAME; do_preturn(game); } else { game->state = SETUP; } } else if (!strcmp(arg[0], "end")) { break; } if (game->state == SETUP) { if (!strcmp(arg[0], "loadtime")) { game->loadtime = atoi(arg[1]); } else if (!strcmp(arg[0], "turntime")) { game->turntime = atoi(arg[1]); } else if (!strcmp(arg[0], "rows")) { game->rows = atoi(arg[1]); } else if (!strcmp(arg[0], "cols")) { game->cols = atoi(arg[1]); } else if (!strcmp(arg[0], "turns")) { game->turns = atoi(arg[1]); } else if (!strcmp(arg[0], "viewradius2")) { game->viewradius2 = atoi(arg[1]); } else if (!strcmp(arg[0], "attackradius2")) { game->attackradius2 = atoi(arg[1]); } else if (!strcmp(arg[0], "spawnradius2")) { game->spawnradius2 = atoi(arg[1]); } else if (!strcmp(arg[0], "player_seed")) { game->player_seed = atoi(arg[1]); } else if (!strcmp(arg[0], "ready")) { do_setup(game); fprintf(stdout, "go\n"); fflush(NULL); } } else { int row,col,owner; switch (*arg[0]) { case 'w': row = atoi(arg[1]); col = atoi(arg[2]); game->watermap[loc(row,col)] = 1; break; case 'f': row = atoi(arg[1]); col = atoi(arg[2]); game->foodmap[loc(row,col)] = 1; break; case 'h': row = atoi(arg[1]); col = atoi(arg[2]); owner = atoi(arg[3]); game->hillmap[loc(row,col)] = owner+1; break; case 'a': row = atoi(arg[1]); col = atoi(arg[2]); owner = atoi(arg[3]); game->antmap[loc(row,col)] = owner+1; break; case 'd': // Dead ants, meh break; } if (!strcmp(arg[0], "go")) { do_turn(game); fprintf(stdout, "go\n"); fflush(NULL); } } } do_cleanup(game); return 0; }
/** maybe_setup Creates the ~/.freenote/probe.team file, based on user input. Assumes that we are /not/ daemonized yet. Returns 0 for success (i.e., successful setup -or- the probe has already been set up), -1 for failure (ex., couldn't write to the file). */ int maybe_setup() { fm_init_base(); if(read_str_opt("auto-setup")) { return set_teamstring(read_str_opt("auto-setup")); } if(read_int_opt("setup") || !(fm_exists(FM_TEAM_INFO) || read_int_opt("no-tokens"))) { try(do_setup()); p_exit(PEXIT_NORMAL); } return 0; } /* do_setup Does the setup. Returns 0 for success, -1 for failure. It doesn't use io_* because it's interactive. */ static int do_setup() { char team[TEAM_MAXLEN], pin[PIN_MAXLEN], *tmp = fm_abs(FM_TEAM_INFO); int r; // It's a little long. printf( "FreeNote Probe Setup:\n" "Please follow the on-screen instructions.\n" "\n" "If you do not have a team, you can visit http://freenote." "petta-tech.com\nto register.\n" "If you don't want to register, you can run the probe with" "the\n'--no-tokens'/'-n' option, " "or add 'no-tokens' to ~/.freenote/rc.\n" "Please enter your team name: "); fgets(team, TEAM_MAXLEN, stdin); chomp(team); printf("Please enter your team's pin code: "); fgets(pin, PIN_MAXLEN, stdin); chomp(pin); printf("Writing the information to %s...\n", tmp); r = set_team_info(team, pin); try(r); printf("Ready to roll! Run the probe again, without --setup.\n"); return r; } /** set_team_info Generates ~/.freenote/probe.team from the two arguments (the team name and the pin code). Returns 0 for success, -1 for failure. */ int set_team_info(const char *team_name, const char *pin_code) { // strlen("team_name:", ";\n", "pin_code:", ";\n\0") = 24 char buffer[TEAM_MAXLEN + PIN_MAXLEN + 24]; sprintf(buffer, "team_name:%s;\npin_code:%s;\n", team_name, pin_code); return fm_write(FM_TEAM_INFO, buffer, strlen(buffer)) - 1; }
void main(void) { // Have to init the clock first init_clock(); // These initialize variables // Mostly just zeroing them okay_to_transmit = FALSE; server_wants_header = FALSE; inside_non_blocking_interrupt = FALSE; last_connect_time = 0; check_in_period = 0; setup_button_pressed = FALSE; setup_button_time_trigger = 0; setup_button_time_duration = 0; main_mode = MAIN_MODE_INIT; init_internal_wattage_sensor(); init_temperature_sensor(); init_audio_sensor(); init_light_sensor(); uint8_t itor = 0; for (itor = 0; itor < NUMBER_OF_AUX_PORTS; itor++) { aux_sensor[itor] = 0; } // These initialize functions and interrupts init_timer(); init_time(); init_leds(); init_relay(); init_uart(); init_transmits(); init_buttons(); init_roving(&roving_call_back); setup_button_time_trigger = new_time(); setup_button_time_duration = new_time(); time_set_seconds(setup_button_time_duration, 2); _enable_interrupts(); // confirm roving works while (!enter_command_mode()) { reset_roving(); wait(500); } init_adc(); init_pll(); // This is for the check in // If we are disconnected, we wait 5 seconds before trying to reconnect last_connect_time = new_time(); check_in_period = new_time(); time_set_seconds(check_in_period, 5); // And go!!! set_led_anim(led_start); // MAIN LOOP while(1) { handle_roving_input(); // Check if it a long hold if(setup_button_pressed) { // If the button is pressed down if(time_cmp(global_time(), setup_button_time_trigger) >= 0) { // If enough time has passed if(in_setup_mode()) { leave_setup_mode(); } else { start_setup_mode(); } // Only want to check this once setup_button_pressed = FALSE; } } // MAIN BEHAVIOR // There is setup_mode and main_mode. // Setup mode is for configuring WiFi SSID and PASS // Main mode is for sampling if (in_setup_mode()) { if(main_mode != MAIN_MODE_SETUP) { stop_sampling(); set_led_anim(led_setup_start); main_mode = MAIN_MODE_SETUP; } do_setup(); } else if (in_main_mode()) { //regular mode if(main_mode != MAIN_MODE_SAMPLE) { set_led_anim(led_main_start); start_sampling(); main_mode = MAIN_MODE_SAMPLE; } if(!is_associated()) { associate(); } else if (!have_dhcp()) { get_dhcp(); } else { if(is_connected()) set_led_anim(led_main_connected); else set_led_anim(led_main_assoc); if(!is_connected() && (time_cmp(global_time(), last_connect_time) >= 0) ) { // If we are not connected, and enough time has passed, connect connect(); add_time_to_time(last_connect_time, check_in_period); } if(server_wants_header) { led_ping(); exit_command_mode(); transmit_header(); wait(100); } if(okay_to_transmit && have_data_to_transmit()) { led_ping(); exit_command_mode(); transmit_data(); } } } else { main_mode = MAIN_MODE_INIT; set_led_anim(led_error); stop_sampling(); } } }