优先级继承协议支持
This commit is contained in:
@@ -38,30 +38,35 @@ int ls(int argc, char *agrv[])
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
strcpy(path, in_path);
|
||||
dir = opendir(in_path);
|
||||
ret = getcwd(path, PAGE_SIZE);
|
||||
if (ret < 0)
|
||||
{
|
||||
u_free(path);
|
||||
return ret;
|
||||
}
|
||||
ret = chdir(in_path);
|
||||
if (ret < 0)
|
||||
{
|
||||
u_free(path);
|
||||
return ret;
|
||||
}
|
||||
dir = opendir(".");
|
||||
if (!dir)
|
||||
{
|
||||
u_free(path);
|
||||
return 0;
|
||||
}
|
||||
printf("%-20s%10s\n", "name", "size");
|
||||
|
||||
while ((ptr = readdir(dir)) != NULL)
|
||||
{
|
||||
struct stat st = {0};
|
||||
// strcat(path, "/");
|
||||
strcat(path, ptr->d_name);
|
||||
ret = stat(path, &st);
|
||||
// if (ret >= 0)
|
||||
// {
|
||||
printf("%s\t\t\t%dB\n", path, st.st_size);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// printf("error:%d\n", ret);
|
||||
// }
|
||||
strcpy(path, in_path);
|
||||
|
||||
ret = stat(ptr->d_name, &st);
|
||||
printf("%-20s%10d\n", ptr->d_name, st.st_size);
|
||||
}
|
||||
closedir(dir);
|
||||
chdir(path);
|
||||
u_free(path);
|
||||
return 0;
|
||||
}
|
||||
@@ -234,7 +239,7 @@ int shell_sys_info(int argc, char *argv[])
|
||||
size_t free;
|
||||
|
||||
printf("sys:\n");
|
||||
printf("\tcpu usage:%2.1f\n", sys_read_cpu_usage() / 10.0f);
|
||||
printf("\tcpu usage:%d.%d\n", sys_read_cpu_usage() / 10, sys_read_cpu_usage() % 10);
|
||||
return 0;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), sys, shell_sys_info, sys command);
|
||||
|
||||
88
mkrtos_user/server/init/src/test/mutex_test.c
Normal file
88
mkrtos_user/server/init/src/test/mutex_test.c
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
#include "u_factory.h"
|
||||
#include "u_hd_man.h"
|
||||
#include "u_task.h"
|
||||
#include "u_thread.h"
|
||||
#include <CuTest.h>
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <u_mutex.h>
|
||||
#include <u_sleep.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static pthread_t pth1;
|
||||
static pthread_t pth2;
|
||||
static pthread_t pth3;
|
||||
static u_mutex_t mutex_lock;
|
||||
static int test_cn;
|
||||
static __attribute__((optimize(0))) void hard_sleep(void)
|
||||
{
|
||||
int i = 99999999;
|
||||
while(i--);
|
||||
}
|
||||
static void *thread_th1(void *arg)
|
||||
{
|
||||
thread_run(-1, 5);
|
||||
u_mutex_lock(&mutex_lock, 0, NULL);
|
||||
hard_sleep();
|
||||
u_mutex_unlock(&mutex_lock);
|
||||
return NULL;
|
||||
}
|
||||
static void *thread_th2(void *arg)
|
||||
{
|
||||
u_sleep_ms(10);
|
||||
thread_run(-1, 6);
|
||||
u_sleep_ms(20);
|
||||
while(test_cn < 10000000) {
|
||||
test_cn++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
static void *thread_th3(void *arg)
|
||||
{
|
||||
u_sleep_ms(20);
|
||||
thread_run(-1, 7);
|
||||
u_mutex_lock(&mutex_lock, 0, NULL);
|
||||
hard_sleep();
|
||||
if (test_cn != 0) {
|
||||
u_mutex_unlock(&mutex_lock);
|
||||
return (void *)-1;
|
||||
}
|
||||
u_mutex_unlock(&mutex_lock);
|
||||
return NULL;
|
||||
}
|
||||
static void u_mutex_test(CuTest *tc)
|
||||
{
|
||||
obj_handler_t mutex_hd;
|
||||
int ret;
|
||||
|
||||
mutex_hd = handler_alloc();
|
||||
CuAssert(tc, "hd alloc fail.\n", mutex_hd != HANDLER_INVALID);
|
||||
ret = u_mutex_init(&mutex_lock, mutex_hd);
|
||||
CuAssert(tc, "u_mutex_init fail.\n", ret >= 0);
|
||||
|
||||
CuAssert(tc, "pthread_create fail.\n", pthread_create(&pth1, NULL, thread_th1, NULL) == 0);
|
||||
CuAssert(tc, "pthread_create fail.\n", pthread_create(&pth2, NULL, thread_th2, NULL) == 0);
|
||||
CuAssert(tc, "pthread_create fail.\n", pthread_create(&pth3, NULL, thread_th3, NULL) == 0);
|
||||
if (pth1 != PTHREAD_NULL) {
|
||||
CuAssert(tc, "pthread_join fail.\n", pthread_join(pth1, NULL) == 0);
|
||||
}
|
||||
if (pth2 != PTHREAD_NULL) {
|
||||
CuAssert(tc, "pthread_join fail.\n", pthread_join(pth2, NULL) == 0);
|
||||
}
|
||||
if (pth3 != PTHREAD_NULL) {
|
||||
umword_t arg;
|
||||
CuAssert(tc, "pthread_join fail.\n", pthread_join(pth3, (void **)&arg) == 0);
|
||||
CuAssert(tc, "pthread_join fail.\n", arg == 0);
|
||||
}
|
||||
}
|
||||
static CuSuite suite;
|
||||
CuSuite *mutex_test_suite(void)
|
||||
{
|
||||
CuSuiteInit(&suite);
|
||||
|
||||
SUITE_ADD_TEST(&suite, u_mutex_test);
|
||||
|
||||
return &suite;
|
||||
}
|
||||
@@ -15,6 +15,8 @@ CuSuite *pthread_base_test_suite(void);
|
||||
CuSuite *thread_base_test_suite(void);
|
||||
CuSuite *ipc_test_suite(void);
|
||||
CuSuite *sharem_mem_test_suite(void);
|
||||
CuSuite *mutex_test_suite(void);
|
||||
|
||||
void test_main(void);
|
||||
|
||||
void mm_test(void);
|
||||
|
||||
@@ -26,6 +26,7 @@ static void RunAllTests(void)
|
||||
CuSuiteAddSuite(&suite, map_test_suite());
|
||||
#endif
|
||||
CuSuiteAddSuite(&suite, thread_base_test_suite());
|
||||
CuSuiteAddSuite(&suite, mutex_test_suite());
|
||||
CuSuiteAddSuite(&suite, sema_test_suite());
|
||||
CuSuiteAddSuite(&suite, pthread_base_test_suite());
|
||||
CuSuiteAddSuite(&suite, pthread_press_test_suite());
|
||||
|
||||
Reference in New Issue
Block a user