struct finsh_syscall* finsh_syscall_lookup(const char* name) { struct finsh_syscall* index; struct finsh_syscall_item* item; for (index = _syscall_table_begin; index < _syscall_table_end; FINSH_NEXT_SYSCALL(index)) { if (strcmp(index->name, name) == 0) return index; } /* find on syscall list */ item = global_syscall_list; while (item != NULL) { if (strncmp(item->syscall.name, name, strlen(name)) == 0) { return &(item->syscall); } item = item->next; } return NULL; }
void tc_thread_entry(void* parameter) { struct finsh_syscall* index; /* create tc semaphore */ rt_sem_init(&_tc_sem, "tc", 0, RT_IPC_FLAG_FIFO); while (_tc_stat & TC_STAT_RUNNING) { for (index = _syscall_table_begin; index < _syscall_table_end; FINSH_NEXT_SYSCALL(index)) { /* search testcase */ if (rt_strstr(index->name, _tc_prefix) == index->name) { long tick; _tc_current = index->name + 4; rt_kprintf("Run TestCase: %s\n", _tc_current); _tc_stat = TC_STAT_PASSED | TC_STAT_RUNNING; tick = index->func(); if (tick > 0) { rt_sem_take(&_tc_sem, tick * _tc_scale); if (_tc_cleanup != RT_NULL) { /* perform testcase cleanup */ _tc_cleanup(); _tc_cleanup = RT_NULL; } rt_sem_trytake(&_tc_sem);/* by nl1031 */ if (_tc_stat & TC_STAT_FAILED) rt_kprintf("TestCase[%s] failed\n", _tc_current); else rt_kprintf("TestCase[%s] passed\n", _tc_current); } else { if (_tc_cleanup != RT_NULL) { /* perform testcase cleanup */ _tc_cleanup(); _tc_cleanup = RT_NULL; } } } } } rt_kprintf("RT-Thread TestCase Running Done!\n"); /* detach tc semaphore */ rt_sem_detach(&_tc_sem); }
void list_tc() { struct finsh_syscall* index; rt_kprintf("TestCases List:\n"); for (index = _syscall_table_begin; index < _syscall_table_end; FINSH_NEXT_SYSCALL(index)) { /* search testcase */ if (rt_strstr(index->name, "_tc_") == index->name) { #ifdef FINSH_USING_DESCRIPTION rt_kprintf("%-16s -- %s\n", index->name + 4, index->desc); #else rt_kprintf("%s\n", index->name + 4); #endif } } }
static cmd_function_t msh_get_cmd(char *cmd, int size) { struct finsh_syscall *index; cmd_function_t cmd_func = RT_NULL; for (index = _syscall_table_begin; index < _syscall_table_end; FINSH_NEXT_SYSCALL(index)) { if (strncmp(index->name, "__cmd_", 6) != 0) continue; if (strncmp(&index->name[6], cmd, size) == 0 && index->name[6 + size] == '\0') { cmd_func = (cmd_function_t)index->func; break; } } return cmd_func; }
int msh_help(int argc, char **argv) { rt_kprintf("RT-Thread shell commands:\n"); { struct finsh_syscall *index; for (index = _syscall_table_begin; index < _syscall_table_end; FINSH_NEXT_SYSCALL(index)) { if (strncmp(index->name, "__cmd_", 6) != 0) continue; #if defined(FINSH_USING_DESCRIPTION) && defined(FINSH_USING_SYMTAB) rt_kprintf("%-16s - %s\n", &index->name[6], index->desc); #else rt_kprintf("%s ", &index->name[6]); #endif } } rt_kprintf("\n"); return 0; }
void msh_auto_complete(char *prefix) { int length, min_length; const char *name_ptr, *cmd_name; struct finsh_syscall *index; min_length = 0; name_ptr = RT_NULL; if (*prefix == '\0') { msh_help(0, RT_NULL); return; } #ifdef RT_USING_DFS /* check whether a spare in the command */ { char *ptr; ptr = prefix + rt_strlen(prefix); while (ptr != prefix) { if (*ptr == ' ') { msh_auto_complete_path(ptr + 1); break; } ptr --; } #ifdef RT_USING_MODULE /* There is a chance that the user want to run the module directly. So * try to complete the file names. If the completed path is not a * module, the system won't crash anyway. */ if (ptr == prefix) { msh_auto_complete_path(ptr); } #endif } #endif /* checks in internal command */ { for (index = _syscall_table_begin; index < _syscall_table_end; FINSH_NEXT_SYSCALL(index)) { /* skip finsh shell function */ if (strncmp(index->name, "__cmd_", 6) != 0) continue; cmd_name = (const char *) &index->name[6]; if (strncmp(prefix, cmd_name, strlen(prefix)) == 0) { if (min_length == 0) { /* set name_ptr */ name_ptr = cmd_name; /* set initial length */ min_length = strlen(name_ptr); } length = str_common(name_ptr, cmd_name); if (length < min_length) min_length = length; rt_kprintf("%s\n", cmd_name); } } } /* auto complete string */ if (name_ptr != NULL) { rt_strncpy(prefix, name_ptr, min_length); } return ; }