void button_task(void) { task_open(); // init the Interrupt P3IES = 0xF8; P3OUT = 0xF8; P3REN = 0xF8; P3IFG = 0; P3IE = 0xF8; while(1) { event_wait(buttonEvent); // wait till button pressed buttonHoldDuration = 0; while(buttonMask != 0xF8) { // count the number of ticks that have elapsed. task_wait(10); buttonHoldDuration++; buttonMask = (P3IN & 0xF8); } //buttonMask = 0; } task_close(); }
void home_task(void) { task_open(); current_menu_item = 1; current_tid = 0; while(1) { if( current_tid == 0) { clearBuff(); setxy(2,4); xprint("%s\n0x%04X",mainMenu[current_menu_item].name,mainMenu[current_menu_item].task ); lcd_xmit(); } event_wait( buttonEvent ); char button_state = button_get_pressed(); if(current_tid == 0) { if(( button_state & BUTTON_DOWN )&&( current_menu_item > 0 )) { current_menu_item--; // antmation? } else if(( button_state & BUTTON_UP )&&( current_menu_item < N_MENU -1 )) { current_menu_item++; } else if(( button_state & BUTTON_SELECT )) // no task running { // call up a new task task_create( mainMenu[current_menu_item].task, 10, 0, 0, 0 ); // should be a lower priority than this task // store tid current_tid = 1;//task_id_get( mainMenu[current_menu_item].task ); } } else { if(( button_state & BUTTON_MENU )) { task_kill( mainMenu[current_menu_item].task ); current_tid = 0; } } task_wait(10); //P2OUT ^= BIT3; } task_close(); }
int task_check_all(struct task **tasks) { /* return 1 if we handled a task */ int ret = 0; struct task *t; restart: for(t = *tasks; t; t = t->next) switch(t->state){ case TASK_COMPLETE: task_rm(tasks, t); ret = 1; goto restart; case TASK_RUNNING: /* asyncronously check for completion */ if(task_wait(tasks, t, 1)){ ret = 1; goto restart; } break; case TASK_BEGIN: break; } return ret; }
// task desc: sit and wait for buzzer request.. // when req recv. timeout and stop buzzer void buzzer_task(void) { task_open(); // some initial init P2SEL0 |= BUZZER; //assign TB2.0 to BUZZER P2DIR |= BUZZER; while(1){ // sit and wait event_wait(buzzerEvent); // configure timer B2 TB2CCR0 = 650; TB2CTL = TASSEL_2 + MC_3 + TACLR; TB2CCTL0 = OUTMOD_4; // timeout? task_wait(20); // clean up, disabling timer will save power // ensure NPN is off to reduce current through buzzer. TB2CCTL0 = 0; // this will clear OUT, setting BUZZER LOW TB2CTL = 0; // disable timer } // never ends task_close(); }
/******************************************************************************* Name : STDVMi_EventTerm() Description : Terminates STDVM event notification task Parameters : BOOL ForceTerminate Return Value : *******************************************************************************/ ST_ErrorCode_t STDVMi_EventTerm(ST_DeviceName_t DVMDeviceName, ST_DeviceName_t PRMDeviceName, ST_DeviceName_t MP3PBDeviceName, BOOL ForceTerminate) { ST_ErrorCode_t ErrorCode; STDVMi_Event_t *Event_p; ErrorCode = STDVMi_UnRegisterAndUnSubscribeEvents(DVMDeviceName, PRMDeviceName, MP3PBDeviceName); if(ErrorCode != ST_NO_ERROR) { STTBX_Report((STTBX_REPORT_LEVEL_ERROR, "STDVMi_UnRegisterAndUnSubscribeEvents()=%08X\n", ErrorCode)); return ErrorCode; } Event_p = (STDVMi_Event_t *)message_claim(STDVMi_EventTaskMQ_p); STDVMi_EventTaskState = TASK_STOPPED; message_send(STDVMi_EventTaskMQ_p, Event_p); task_wait(&STDVMi_EventTask_p, 1, TIMEOUT_INFINITY); if(task_delete(STDVMi_EventTask_p) != 0 ) { STTBX_Report((STTBX_REPORT_LEVEL_ERROR, "task_delete failed\n")); return ST_ERROR_BAD_PARAMETER; } message_delete_queue(STDVMi_EventTaskMQ_p); return ST_NO_ERROR; }
int main(int argc, char *argv[]) { if (argc < 3) { usage(); return -1; } int i; for (i = 1; i < argc; i++) { if (str_cmp(argv[i], "-i") == 0) { i++; if (i >= argc) { usage(); return -2; } reopen(&stdin, 0, argv[i], O_RDONLY, "r"); } else if (str_cmp(argv[i], "-o") == 0) { i++; if (i >= argc) { usage(); return -3; } reopen(&stdout, 1, argv[i], O_WRONLY | O_CREAT, "w"); } else if (str_cmp(argv[i], "-e") == 0) { i++; if (i >= argc) { usage(); return -4; } reopen(&stderr, 2, argv[i], O_WRONLY | O_CREAT, "w"); } else if (str_cmp(argv[i], "--") == 0) { i++; break; } } if (i >= argc) { usage(); return -5; } /* * FIXME: fdopen() should actually detect that we are opening a console * and it should set line-buffering mode automatically. */ setvbuf(stdout, NULL, _IOLBF, BUFSIZ); task_id_t id = spawn(argc - i, argv + i); if (id != 0) { task_exit_t texit; int retval; task_wait(id, &texit, &retval); return retval; } return -6; }
/*check replica basic info*/ EC_BOOL test_case_84_check_replica(const char *home, const UINT32 cdfs_md_id, const UINT32 replica_num, const void *tcid_vec, UINT32 *counter) { void *cdfsnpp_mod_mgr; void *task_mgr; UINT32 index; CSTRING *path[CDFS_TEST_READ_MAX_FILES]; EC_BOOL ret[CDFS_TEST_READ_MAX_FILES]; EC_BOOL continue_flag; for(index = 0; index < CDFS_TEST_READ_MAX_FILES; index ++) { path[ index ] = NULL_PTR; ret[ index ] = EC_FALSE; } cdfsnpp_mod_mgr = cdfs_get_npp_mod_mgr(cdfs_md_id); dbg_log(SEC_0137_DEMO, 5)(LOGSTDOUT, "test_case_84_check_replica: cdfsnpp mod mgr is\n"); mod_mgr_print(LOGSTDOUT, cdfsnpp_mod_mgr); task_mgr = task_new(cdfsnpp_mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(index = 0; index < CDFS_TEST_READ_MAX_FILES; index ++, (*counter) ++) { path[ index ] = cstring_new(NULL_PTR, 0); cstring_format(path[ index ], "%s/%ld.dat", home, (*counter)); ret[ index ] = EC_FALSE; task_inc(task_mgr, &(ret[ index ]), FI_cdfs_check_replicas, ERR_MODULE_ID, path[ index ], replica_num, tcid_vec); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR); continue_flag = EC_TRUE; for(index = 0; index < CDFS_TEST_READ_MAX_FILES; index ++) { if(EC_TRUE == ret[ index ]) { dbg_log(SEC_0137_DEMO, 5)(LOGSTDOUT, "[SUCC] path: %s\n", (char *)cstring_get_str(path[ index ])); } else { continue_flag = EC_FALSE; dbg_log(SEC_0137_DEMO, 0)(LOGCONSOLE, "[FAIL] path: %s\n", (char *)cstring_get_str(path[ index ])); } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } } return (continue_flag); }
static int cmd_runl(const char *path, ...) { va_list ap; const char *arg; int cnt = 0; va_start(ap, path); do { arg = va_arg(ap, const char *); cnt++; } while (arg != NULL); va_end(ap); va_start(ap, path); task_id_t id; task_wait_t wait; int rc = task_spawn(&id, &wait, path, cnt, ap); va_end(ap); if (rc != EOK) { log_msg(LOG_DEFAULT, LVL_ERROR, "Error spawning %s (%s)", path, str_error(rc)); return rc; } if (!id) { log_msg(LOG_DEFAULT, LVL_ERROR, "Error spawning %s " "(invalid task ID)", path); return EINVAL; } task_exit_t texit; int retval; rc = task_wait(&wait, &texit, &retval); if (rc != EOK) { log_msg(LOG_DEFAULT, LVL_ERROR, "Error waiting for %s (%s)", path, str_error(rc)); return rc; } if (texit != TASK_EXIT_NORMAL) { log_msg(LOG_DEFAULT, LVL_ERROR, "Command %s unexpectedly " "terminated", path); return EINVAL; } if (retval != 0) { log_msg(LOG_DEFAULT, LVL_ERROR, "Command %s returned non-zero " "exit code %d)", path, retval); } return retval; }
void th_test() { mycounting_t *my1; mycounting_t *my2; mycounting_t *p; d_print("test"); /* make instance my1 */ my1= (mycounting_t *)malloc(sizeof(mycounting_t)); strcpy(my1->name,"home"); my1->counting=10; my1->running=1; my1->task = task_create (counting,(void *)my1,TASK_STACK_SIZE,TASK_PRIORITY,my1->name,0); /* make nstance my2 */ my2=(mycounting_t *)malloc(sizeof(mycounting_t)); strcpy(my2->name,"office"); my2->counting=100; my2->running=1; my2->task=task_create (counting,(void *)my2,TASK_STACK_SIZE,TASK_PRIORITY,my2->name,0); SDL_Delay(1000*3); my1->running=0; task_wait(my1->task, 1, TIMEOUT_INFINITY); task_delete(my1->task); SDL_Delay(1000*2); my2->running=0; task_wait(my2->task, 1, TIMEOUT_INFINITY); task_delete(my2->task); }
EMBX_ERROR EMBX_OS_ThreadDelete(EMBX_THREAD thread) { EMBX_Info(EMBX_INFO_OS, (">>>>EMBX_OS_ThreadDelete\n")); if(thread == EMBX_INVALID_THREAD) { EMBX_Info(EMBX_INFO_OS, ("<<<<EMBX_OS_ThreadDelete = EMBX_SUCCESS (invalid task)\n")); return EMBX_SUCCESS; } if(task_wait(&thread, 1, TIMEOUT_INFINITY) != 0) { EMBX_DebugMessage(("EMBX_OS_ThreadDelete: task_wait failed.\n")); return EMBX_SYSTEM_INTERRUPT; } task_delete(thread); EMBX_Info(EMBX_INFO_OS, ("<<<<EMBX_OS_ThreadDelete = EMBX_SUCCESS\n")); return EMBX_SUCCESS; }
/** Fibril for spawning the task running after user connects. * * @param arg Corresponding @c telnet_user_t structure. */ static int spawn_task_fibril(void *arg) { telnet_user_t *user = arg; int rc; char term[LOC_NAME_MAXLEN]; snprintf(term, LOC_NAME_MAXLEN, "%s/%s", "/loc", user->service_name); task_id_t task; rc = task_spawnl(&task, APP_GETTERM, APP_GETTERM, "-w", term, APP_SHELL, NULL); if (rc != EOK) { telnet_user_error(user, "Spawning `%s -w %s %s' failed: %s.", APP_GETTERM, term, APP_SHELL, str_error(rc)); fibril_mutex_lock(&user->guard); user->task_finished = true; user->srvs.aborted = true; fibril_condvar_signal(&user->refcount_cv); fibril_mutex_unlock(&user->guard); return EOK; } fibril_mutex_lock(&user->guard); user->task_id = task; fibril_mutex_unlock(&user->guard); task_exit_t task_exit; int task_retval; task_wait(task, &task_exit, &task_retval); telnet_user_log(user, "%s terminated %s, exit code %d.", APP_GETTERM, task_exit == TASK_EXIT_NORMAL ? "normally" : "unexpectedly", task_retval); /* Announce destruction. */ fibril_mutex_lock(&user->guard); user->task_finished = true; user->srvs.aborted = true; fibril_condvar_signal(&user->refcount_cv); fibril_mutex_unlock(&user->guard); return EOK; }
/******************************************************************************* Name : STDVMi_ServiceTaskTerm() Description : Terminates STDVM event notification task Parameters : BOOL ForceTerminate Return Value : *******************************************************************************/ ST_ErrorCode_t STDVMi_ServiceTaskTerm(void) { STDVMi_Handle_t **Msg2Send; Msg2Send = (STDVMi_Handle_t **)message_claim(STDVMi_ServiceTaskMQ_p); STDVMi_ServiceTaskState = TASK_STOPPED; message_send(STDVMi_ServiceTaskMQ_p, Msg2Send); task_wait(&STDVMi_ServiceTask_p, 1, TIMEOUT_INFINITY); if(task_delete(STDVMi_ServiceTask_p) != 0 ) { STTBX_Report((STTBX_REPORT_LEVEL_ERROR, "task_delete failed\n")); return ST_ERROR_BAD_PARAMETER; } message_delete_queue(STDVMi_ServiceTaskMQ_p); return ST_NO_ERROR; }
/*check replica files*/ EC_BOOL test_case_85_cdfs_check_file_content(const char *home, const UINT32 cdfs_md_id, const UINT32 max_test_data_files, UINT32 *counter) { void *cdfsnpp_mod_mgr; void *task_mgr; UINT32 index; CSTRING *path[CDFS_TEST_READ_MAX_FILES]; CSTRING *file_content_cstr[CDFS_TEST_READ_MAX_FILES]; EC_BOOL ret[CDFS_TEST_READ_MAX_FILES]; EC_BOOL continue_flag; for(index = 0; index < CDFS_TEST_READ_MAX_FILES; index ++) { path[ index ] = NULL_PTR; file_content_cstr[ index ] = NULL_PTR; ret[ index ] = EC_FALSE; } cdfsnpp_mod_mgr = cdfs_get_npp_mod_mgr(cdfs_md_id); dbg_log(SEC_0137_DEMO, 5)(LOGSTDOUT, "test_case_85_cdfs_check_file_content: cdfsnpp mod mgr is\n"); mod_mgr_print(LOGSTDOUT, cdfsnpp_mod_mgr); task_mgr = task_new(cdfsnpp_mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(index = 0; index < CDFS_TEST_READ_MAX_FILES; index ++, (*counter) ++) { CBYTES *cbytes_des; cbytes_des = fetch_g_cbytes(cdfs_md_id, max_test_data_files, ((*counter) % max_test_data_files)); path[ index ] = cstring_new(NULL_PTR, 0); cstring_format(path[ index ], "%s/%ld.dat", home, (*counter)); file_content_cstr[ index ] = cstring_new(NULL_PTR, 0); cstring_append_chars(file_content_cstr[ index ], 16, cbytes_buf(cbytes_des)); ret[ index ] = EC_FALSE; task_inc(task_mgr, &(ret[ index ]), FI_cdfs_check_replica_files_content, ERR_MODULE_ID, path[ index ], cbytes_len(cbytes_des), file_content_cstr[ index ]); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR); continue_flag = EC_TRUE; for(index = 0; index < CDFS_TEST_READ_MAX_FILES; index ++) { if(EC_TRUE == ret[ index ]) { dbg_log(SEC_0137_DEMO, 5)(LOGSTDOUT, "[SUCC] path: %s\n", (char *)cstring_get_str(path[ index ])); } else { continue_flag = EC_FALSE; dbg_log(SEC_0137_DEMO, 0)(LOGCONSOLE, "[FAIL] path: %s\n", (char *)cstring_get_str(path[ index ])); } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } if(NULL_PTR != file_content_cstr[ index ]) { cstring_free(file_content_cstr[ index ]); file_content_cstr[ index ] = NULL_PTR; } } return (continue_flag); }
int main(int argc, char *argv[]) { argv++; argc--; if (argc < 4) { usage(); return 1; } char *term = *argv; argv++; argc--; char *locfs = *argv; argv++; argc--; bool print_msg = false; bool wait = false; while ((argc > 0) && (str_cmp(*argv, "--") != 0)) { if (str_cmp(*argv, "--msg") == 0) { print_msg = true; } else if (str_cmp(*argv, "--wait") == 0) { wait = true; } else { usage(); return 2; } argv++; argc--; } if (argc < 1) { usage(); return 3; } /* Skip "--" */ argv++; argc--; char *cmd = *argv; char **args = argv; if (wait) { /* Wait for the terminal service to be ready */ service_id_t service_id; int rc = loc_service_get_id(term, &service_id, IPC_FLAG_BLOCKING); if (rc != EOK) { printf("%s: Error waiting on %s (%s)\n", APP_NAME, term, str_error(rc)); return rc; } } char term_node[LOC_NAME_MAXLEN]; snprintf(term_node, LOC_NAME_MAXLEN, "%s/%s", locfs, term); reopen(&stdin, 0, term_node, O_RDONLY, "r"); reopen(&stdout, 1, term_node, O_WRONLY, "w"); reopen(&stderr, 2, term_node, O_WRONLY, "w"); if (stdin == NULL) return 4; if (stdout == NULL) return 5; if (stderr == NULL) return 6; /* * FIXME: fdopen() should actually detect that we are opening a console * and it should set line-buffering mode automatically. */ setvbuf(stdout, NULL, _IOLBF, BUFSIZ); version_print(term); if (print_msg) welcome_msg_print(); task_id_t id; task_wait_t twait; int rc = task_spawnv(&id, &twait, cmd, (const char * const *) args); if (rc != EOK) { printf("%s: Error spawning %s (%s)\n", APP_NAME, cmd, str_error(rc)); return rc; } task_exit_t texit; int retval; rc = task_wait(&twait, &texit, &retval); if (rc != EOK) { printf("%s: Error waiting for %s (%s)\n", APP_NAME, cmd, str_error(rc)); return rc; } return 0; }
void test_task(u08 cmd, u08 *param) { static u16 i; float time_to_stop=0,distance_to_stop; static t_scan_result scan_result; DEFINE_CFG2(s16,accel, 99,1); DEFINE_CFG2(s16,decel, 99,2); DEFINE_CFG2(s16,speed, 99,3); DEFINE_CFG2(s16,distance, 99,4); DEFINE_CFG2(s16,angle, 99,5); task_open_1(); //code between _1() and _2() will get executed every time the scheduler resumes this task if(cmd==0) { NOP(); } else { NOP(); return; } task_open_2(); //execution below this point will resume wherever it left off when a context switch happens usb_printf("test_task()\n"); PREPARE_CFG2(accel); PREPARE_CFG2(decel); PREPARE_CFG2(speed); PREPARE_CFG2(distance); PREPARE_CFG2(angle); test_task(1,(uint8 *)0x1234); /* for(;;) { dbg_printf("0123456789\n"); task_wait(100); } */ /* task_wait(200); motor_command(2,0,0,0,0); task_wait(200); motor_command(7,0,0,100,100); task_wait(500); motor_command(6,2,2,0,0); task_wait(500); */ while(1) { task_wait(100); UPDATE_CFG2(accel); UPDATE_CFG2(decel); UPDATE_CFG2(speed); UPDATE_CFG2(distance); UPDATE_CFG2(angle); if(s.behavior_state[TEST_LOGIC_FSM]==1) { /* 1) gradually ramp up (at specified rate) to target speed 2) when we are <= 30degrees from the target, start ramping down to speed 15 3) when we are <= 10degrees from the target, apply target speed 5 (w/ feed forward) & regulate to maintain 5 3) when we are at the target, hit the brakes - full stop w/out ramping down */ /* odometry_set_checkpoint(); motor_command(6,1,1,(speed),-(speed)); while ( abs(odometry_get_rotation_since_checkpoint()) < 60 ) { task_wait(10); } motor_command(6,1,1,15,-15); while ( abs(odometry_get_rotation_since_checkpoint()) < 80 ) { task_wait(10); } motor_command(7,1,1,5,-5); while ( abs(odometry_get_rotation_since_checkpoint()) < 90 ) { task_wait(10); } motor_command(7,1,1,0,0); */ /* MOVE(50,100); TURN_IN_PLACE( 50, 90); MOVE(50,100); TURN_IN_PLACE( 50, 90); MOVE(50,100); TURN_IN_PLACE( 50, 90); MOVE(50,100); TURN_IN_PLACE( 50, 90); */ #if 0 //set_digital_output(IO_D1,0); set_digital_output(IO_D0,0); task_wait(2000); //set_digital_output(IO_D1,1); set_digital_output(IO_D0,1); #endif #if 0 //dbg_printf("Starting scan....\n"); TURN_IN_PLACE_AND_SCAN( 40, 220 ); //dbg_printf("....done\n"); scan_result = find_peak_in_scan(scan_data,360,30); dbg_printf("scan_result: %d,%d,%d,%d,%d,%d\n", scan_result.flame_center_value, scan_result.rising_edge_position, scan_result.falling_edge_position, scan_result.center_angle, scan_result.rising_edge_angle, scan_result.falling_edge_angle); for(i=0;i<360;i++) {dbg_printf("scan_data[%03d]=%03d,%03d\n",i, scan_data[i].angle, scan_data[i].flame);task_wait(10);} TURN_IN_PLACE( 40, -(220-scan_result.center_angle) ); #endif TURN_IN_PLACE_AND_SCAN( 40, 90, 1); scan_result = find_path_in_scan(scan_data, 100, 300, 0, 1); dbg_printf("scan_result: %d,%d,%d,%d\n", scan_result.opening, scan_result.center_angle, scan_result.rising_edge_angle, scan_result.falling_edge_angle); //for(i=0;i<100;i++) {dbg_printf("scan_data[%03d]=%03d,%03d\n",i, scan_data[i].angle, scan_data[i].ir_north);task_wait(10);} TURN_IN_PLACE(40,-90); /* task_wait(2000); TURN_IN_PLACE_AND_SCAN( 100, -90 ); scan_result = find_peak_in_scan(scan_data,360,3); task_wait(2000); TURN_IN_PLACE_AND_SCAN( 100, 180 ); scan_result = find_peak_in_scan(scan_data,360,3); task_wait(2000); TURN_IN_PLACE_AND_SCAN( 100, -180 ); scan_result = find_peak_in_scan(scan_data,360,3); */ s.behavior_state[TEST_LOGIC_FSM]=0; } if(s.behavior_state[TEST_LOGIC_FSM]==2) { TURN_IN_PLACE(speed,angle); s.behavior_state[TEST_LOGIC_FSM]=0; } if(s.behavior_state[TEST_LOGIC_FSM]==3) { TURN_IN_PLACE(40, -90); TURN_IN_PLACE_AND_SCAN(40, 180, 4); scan_result = find_flame_in_scan(scan_data,360,30); if(scan_result.flame_center_value > 150) //TODO: make the minimum flame value a parameter { static int i, i_min; static u16 min=999; static float d; static u08 stop=0; TURN_IN_PLACE( 40, -(180-scan_result.center_angle+2) ); /* min=999; for(i=scan_result.rising_edge_position-10; i<=scan_result.falling_edge_position+10; i++) { dbg_printf("scan_data[%3d]: ir_n=%3d, a=%d, f=%d\n",i,scan_data[i].ir_north, scan_data[i].angle, scan_data[i].flame); task_wait(50); if(scan_data[i].ir_north < min) { min=scan_data[i].ir_north; i_min=i; } } dbg_printf("distance to candle: %d @i=%d,a=%d\n",min,i_min,scan_data[i_min].angle); if(min<100) min=100; d = (float) (((min-100)*25)/10); MOVE2(50,d,60,60); */ stop=0; move_manneuver2(1,30,9999,(80),(90)); while(move_manneuver2(0,30,9999,(70),(70))) { OS_SCHEDULE; if( (s.ir[IR_N] <= 60) ) stop |= 0x01; if( (s.ir[IR_NE] <= 60)) stop |= 0x02; if( (s.ir[IR_NW] <= 60)) stop |= 0x04; if( (s.inputs.sonar[0] <= 100) ) stop |= 0x08; if(stop != 0) { dbg_printf("too close to object/wall! reason: 0x%02x\n",stop); HARD_STOP(); break; } } } s.behavior_state[TEST_LOGIC_FSM]=0; } if(s.behavior_state[TEST_LOGIC_FSM]==4) { PUMP_ON(); task_wait(1000); PUMP_OFF(); s.behavior_state[TEST_LOGIC_FSM]=0; } if(s.behavior_state[TEST_LOGIC_FSM]==5) { dbg_printf("start = %d\n",is_digital_input_high(IO_B3)); task_wait(500); } /* while(s.behavior_state[11]==1) { time_to_stop = (float)s.inputs.actual_speed[0] / (float)50; distance_to_stop = ((float)s.inputs.actual_speed[0] * time_to_stop)/2.0; distance_to_stop *= 50.0; //adjust for seconds distance_to_stop *= 0.13466716824940938560464; //adjust for mm if(s.inputs.x + distance_to_stop < distance) { motor_command(6,accel,decel,speed,speed); } else { motor_command(6,accel,decel,0,0); s.behavior_state[TEST_LOGIC_FSM]=0; } task_wait(20); } */ } task_close(); }
/******************************************************************************* Name : metrics_Stack_Test Description : launch tasks to calculate the stack usage made by the driver for an Init Term cycle and in its typical conditions of use Parameters : None Assumptions : Limitations : Returns : None *******************************************************************************/ #if !defined(ST_OSLINUX) /* due to task status not yet implemented. To be done. */ static BOOL metrics_Stack_Test(STTST_Parse_t *pars_p, char *result_sym_p) { task_t *task_p; task_status_t status; int overhead_stackused; char funcname[4][20]= { "test_overhead", "test_init", "test_typical", "NULL" }; void (*func_table[])(void *) = { test_overhead, test_init, test_typical, NULL }; void (*func)(void *); int i; UNUSED_PARAMETER(pars_p); UNUSED_PARAMETER(result_sym_p); overhead_stackused = 0; printf("*************************************\n"); printf("* Stack usage calculation beginning *\n"); printf("*************************************\n"); for (i = 0; func_table[i] != NULL; i++) { func = func_table[i]; /* Start the task */ task_p = task_create(func, NULL, STACK_SIZE, MAX_USER_PRIORITY, "stack_test", task_flags_no_min_stack_size); /* Wait for task to complete */ task_wait(&task_p, 1, TIMEOUT_INFINITY); /* Dump stack usage */ task_status(task_p, &status, task_status_flags_stack_used); /* Report Error */ if(Err) printf("An error occured during the process !!!\n"); /* store overhead value */ if (i==0) { printf("*-----------------------------------*\n"); overhead_stackused = status.task_stack_used; printf("%s \t func=0x%08lx stack = %d bytes used\n", &funcname[i][0], (long) func, status.task_stack_used); printf("*-----------------------------------*\n"); } else { printf("%s \t func=0x%08lx stack = %d bytes used (%d - %d overhead)\n", &funcname[i][0], (long) func, status.task_stack_used-overhead_stackused,status.task_stack_used,overhead_stackused); } /* Tidy up */ task_delete(task_p); } printf("*************************************\n"); printf("* Stack usage calculation end *\n"); printf("*************************************\n"); return(FALSE); }
void test_case_cbgt_delete_group_p(const UINT32 cbgt_md_id, const char *table_name, const UINT32 row_tag) { UINT32 row_idx; UINT32 colf_idx; UINT32 colq_idx; CBYTES table_name_bytes; void *mod_mgr; EC_BOOL continue_flag; ASSERT(mod_mgr = mod_mgr_new(cbgt_md_id, LOAD_BALANCING_OBJ)); mod_mgr_incl(CMPI_LOCAL_TCID, CMPI_LOCAL_COMM, CMPI_LOCAL_RANK, cbgt_md_id, mod_mgr); mod_mgr_print(LOGCONSOLE, mod_mgr); cbytes_mount(&table_name_bytes, strlen(table_name), (UINT8 *)table_name); continue_flag = EC_TRUE; for(row_idx = 0; row_idx < CBGT_TEST_ROW_NUM && EC_TRUE == continue_flag; row_idx ++) { char *row; CBYTES *row_bytes; ASSERT(row = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(row, CBGT_STR_MAX_LEN, "row-%08ld-%08ld", row_tag, row_idx); ASSERT(row_bytes = cbytes_new(0)); cbytes_mount(row_bytes , strlen(row) , (UINT8 *)row ); //cvector_push(bytes_vec, (void *)row_bytes); for(colf_idx = 0; colf_idx < CBGT_TEST_COLF_NUM && EC_TRUE == continue_flag; colf_idx ++) { char *colf; CBYTES *colf_bytes; void *task_mgr; void *bytes_vec; EC_BOOL ret[CBGT_TEST_COLQ_NUM]; ASSERT(bytes_vec = cvector_new(0, MM_CBYTES, 0)); ASSERT(colf = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(colf, CBGT_STR_MAX_LEN, "colf-%ld", colf_idx); ASSERT(colf_bytes = cbytes_new(0)); cbytes_mount(colf_bytes , strlen(colf) , (UINT8 *)colf ); task_mgr = task_new(mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(colq_idx = 0; colq_idx < CBGT_TEST_COLQ_NUM && EC_TRUE == continue_flag; colq_idx ++) { char *colq; CBYTES *colq_bytes; ASSERT(colq = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(colq, CBGT_STR_MAX_LEN, "colq-%08ld-%08ld-%08ld", row_idx, colf_idx, colq_idx); ASSERT(colq_bytes = cbytes_new(0)); cbytes_mount(colq_bytes , strlen(colq) , (UINT8 *)colq ); cvector_push(bytes_vec, (void *)colq_bytes); ret[ colq_idx ] = EC_FALSE; task_inc(task_mgr, &(ret[ colq_idx ]), FI_cbgt_delete, ERR_MODULE_ID, &table_name_bytes, row_bytes, colf_bytes, colq_bytes); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR); for(colq_idx = 0; colq_idx < CBGT_TEST_COLQ_NUM; colq_idx ++) { if(EC_TRUE == ret[ colq_idx ]) { sys_log(LOGSTDNULL, "[DEBUG] test_case_cbgt_delete_group_p: [SUCC] delete %s %s:%s:colq-%08ld-%08ld-%08ld\n", table_name, row, colf, row_idx, colf_idx, colq_idx); } else { //continue_flag = EC_FALSE; sys_log(LOGCONSOLE, "[DEBUG] test_case_cbgt_delete_group_p: [FAIL] delete %s %s:%s:colq-%08ld-%08ld-%08ld\n", table_name, row, colf, row_idx, colf_idx, colq_idx); } } cbytes_free(colf_bytes, 0); cvector_clean_with_location(bytes_vec, (CVECTOR_DATA_LOCATION_CLEANER)cbytes_free, 0); cvector_free(bytes_vec, 0); } cbytes_free(row_bytes, 0); if(EC_TRUE == continue_flag) { sys_log(LOGCONSOLE, "[DEBUG] test_case_cbgt_delete_group_p: [SUCC] row tag %ld, row no. %ld\n", row_tag, row_idx); } else { sys_log(LOGCONSOLE, "[DEBUG] test_case_cbgt_delete_group_p: [FAIL] row tag %ld, row no. %ld\n", row_tag, row_idx); } } sys_log(LOGCONSOLE, "[DEBUG] test_case_cbgt_delete_group_p: row tag %ld end\n", row_tag); return; }
bool task_finish(Task *task, void **result) { bool success = task_wait(task, result); task_detach(task); return success; }
/*check replica files*/ EC_BOOL test_case_85_crfs_check_file_content(const char *home, const UINT32 crfs_tcid, const UINT32 crfs_rank, const UINT32 crfs_modi, const UINT32 max_test_data_files, UINT32 *counter) { MOD_MGR *mod_mgr; TASK_MGR *task_mgr; UINT32 index; CSTRING *path[CRFS_TEST_READ_MAX_FILES]; EC_BOOL ret[CRFS_TEST_READ_MAX_FILES]; EC_BOOL continue_flag; for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++) { path[ index ] = NULL_PTR; ret[ index ] = EC_FALSE; } mod_mgr = mod_mgr_new(CMPI_ERROR_MODI, LOAD_BALANCING_LOOP); mod_mgr_incl(crfs_tcid, CMPI_ANY_COMM, crfs_rank, crfs_modi, mod_mgr); sys_log(LOGSTDOUT, "test_case_85_crfs_check_file_content: npp mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_npp_mod_mgr(crfs_modi)); sys_log(LOGSTDOUT, "test_case_85_crfs_check_file_content: dn mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_dn_mod_mgr(crfs_modi)); task_mgr = task_new(mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++, (*counter) ++) { CBYTES *cbytes_des; cbytes_des = __test_crfs_fetch_g_cbytes(max_test_data_files, ((*counter) % max_test_data_files)); path[ index ] = cstring_new(NULL_PTR, 0); cstring_format(path[ index ], "%s/%ld.dat", home, (*counter)); ret[ index ] = EC_FALSE; task_inc(task_mgr, &(ret[ index ]), FI_crfs_check_file_is, ERR_MODULE_ID, path[ index ], cbytes_des); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR); continue_flag = EC_TRUE; for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++) { if(EC_TRUE == ret[ index ]) { sys_log(LOGSTDOUT, "[SUCC] path: %s\n", (char *)cstring_get_str(path[ index ])); } else { continue_flag = EC_FALSE; sys_log(LOGCONSOLE, "[FAIL] path: %s\n", (char *)cstring_get_str(path[ index ])); } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } } mod_mgr_free(mod_mgr); return (continue_flag); }
EC_BOOL test_case_83_crfs_write(const char *home, const UINT32 crfs_tcid, const UINT32 crfs_rank, const UINT32 crfs_modi, const UINT32 max_test_data_files, UINT32 *counter) { void *mod_mgr; void *task_mgr; UINT32 index; EC_BOOL continue_flag; CSTRING *path[CRFS_TEST_WRITE_MAX_FILES]; EC_BOOL ret[CRFS_TEST_WRITE_MAX_FILES]; for(index = 0; index < CRFS_TEST_WRITE_MAX_FILES; index ++) { path[ index ] = NULL_PTR; ret[ index ] = EC_FALSE; } mod_mgr = mod_mgr_new(CMPI_ERROR_MODI, LOAD_BALANCING_LOOP); mod_mgr_incl(crfs_tcid, CMPI_ANY_COMM, crfs_rank, crfs_modi, mod_mgr); #if 0 sys_log(LOGSTDOUT, "test_case_83_crfs_write: npp mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_npp_mod_mgr(crfs_modi)); sys_log(LOGSTDOUT, "test_case_83_crfs_write: dn mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_dn_mod_mgr(crfs_modi)); #endif task_mgr = task_new(mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(index = 0; index < CRFS_TEST_WRITE_MAX_FILES; index ++, (*counter) ++) { void *cbytes; path[ index ] = cstring_new(NULL_PTR, 0); cstring_format(path[ index ], "%s/%ld.dat", home, (*counter)); ret[ index ] = EC_FALSE; cbytes = __test_crfs_fetch_g_cbytes(max_test_data_files, ((*counter) % max_test_data_files)); if(NULL_PTR == cbytes) { sys_log(LOGSTDOUT, "error:test_case_83_crfs_write: crfs buff is null where index = %ld, max_test_data_files = %ld\n", index, max_test_data_files); cstring_free(path[ index ]); path[ index ] = NULL_PTR; break; } task_inc(task_mgr, &(ret[ index ]), FI_crfs_write, ERR_MODULE_ID, path[ index ], cbytes); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NOT_NEED_RESCHEDULE_FLAG, NULL_PTR); continue_flag = EC_TRUE; for(index = 0; index < CRFS_TEST_WRITE_MAX_FILES; index ++) { if(EC_FALSE == ret[ index ] && NULL_PTR != path[ index ]) { continue_flag = EC_FALSE; sys_log(LOGCONSOLE, "test_case_83_crfs_write: [FAIL] %s\n", (char *)cstring_get_str(path[ index ])); } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } } mod_mgr_free(mod_mgr); return (continue_flag); }
EC_BOOL test_case_82_crfs_read(const char *home, const UINT32 crfs_tcid, const UINT32 crfs_rank, const UINT32 crfs_modi, const UINT32 max_test_data_files, UINT32 *counter) { void *mod_mgr; void *task_mgr; UINT32 index; CSTRING *path[CRFS_TEST_READ_MAX_FILES]; CBYTES *cbytes[CRFS_TEST_READ_MAX_FILES];/*read from dn*/ CBYTES *cbytes_des[CRFS_TEST_READ_MAX_FILES];/*benchmark*/ EC_BOOL ret[CRFS_TEST_READ_MAX_FILES]; EC_BOOL continue_flag; for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++) { path[ index ] = NULL_PTR; cbytes[ index ] = NULL_PTR; cbytes_des[ index ] = NULL_PTR; ret[ index ] = EC_FALSE; } mod_mgr = mod_mgr_new(CMPI_ERROR_MODI, LOAD_BALANCING_LOOP); mod_mgr_incl(crfs_tcid, CMPI_ANY_COMM, crfs_rank, crfs_modi, mod_mgr); #if 0 sys_log(LOGSTDOUT, "test_case_82_crfs_read: npp mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_npp_mod_mgr(crfs_modi)); sys_log(LOGSTDOUT, "test_case_82_crfs_read: dn mod mgr is\n"); mod_mgr_print(LOGSTDOUT, crfs_get_dn_mod_mgr(crfs_modi)); #endif task_mgr = task_new(mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++, (*counter) ++) { path[ index ] = cstring_new(NULL_PTR, 0); cstring_format(path[ index ], "%s/%ld.dat", home, (*counter)); cbytes[ index ] = cbytes_new(0); cbytes_des[ index ] = __test_crfs_fetch_g_cbytes(max_test_data_files, ((*counter) % max_test_data_files)); ret[ index ] = EC_FALSE; task_inc(task_mgr, &(ret[ index ]), FI_crfs_read, ERR_MODULE_ID, path[ index ], cbytes[ index ]); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR); continue_flag = EC_TRUE; for(index = 0; index < CRFS_TEST_READ_MAX_FILES; index ++) { if(NULL_PTR != cbytes[ index ]) { if(EC_TRUE == cbytes_ncmp(cbytes[ index ], cbytes_des[ index ], 16)) { sys_log(LOGSTDOUT, "[SUCC] path: %s, len = %ld ", (char *)cstring_get_str(path[ index ]), cbytes_len(cbytes[ index ])); sys_print(LOGSTDOUT, "text = %.*s\n", cbytes_len(cbytes[ index ]) > 16 ? 16 : cbytes_len(cbytes[ index ]), /*output up to 16 chars*/ (char *)cbytes_buf(cbytes[ index ])); } else { continue_flag = EC_FALSE; sys_log(LOGCONSOLE, "[FAIL] path: %s, read len = %ld ", (char *)cstring_get_str(path[ index ]), cbytes_len(cbytes[ index ])); sys_print(LOGCONSOLE, "text = %.*s <--> ", cbytes_len(cbytes[ index ]) > 16 ? 16 : cbytes_len(cbytes[ index ]), /*output up to 16 chars*/ (char *)cbytes_buf(cbytes[ index ])); sys_print(LOGCONSOLE, "expect len = %ld ", cbytes_len(cbytes_des[ index ])); sys_print(LOGCONSOLE, "text = %.*s\n", cbytes_len(cbytes_des[ index ]) > 16 ? 16 : cbytes_len(cbytes_des[ index ]), (char *)cbytes_buf(cbytes_des[ index ])); } } if(NULL_PTR != path[ index ]) { cstring_free(path[ index ]); path[ index ] = NULL_PTR; } if(NULL_PTR != cbytes[ index ]) { cbytes_free(cbytes[ index ], 0); cbytes[ index ] = NULL_PTR; } if(NULL_PTR != cbytes_des[ index ]) { cbytes_des[ index ] = NULL_PTR; } } mod_mgr_free(mod_mgr); return (continue_flag); }