优化代码结构
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
int fs_open(const char *path, int flags, int mode);
|
||||
int fs_read(int fd, void *buf, size_t len);
|
||||
int fs_write(int fd, void *buf, size_t len);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
#define HEAP_SIZE 4
|
||||
#define STACK_SIZE 1024 * 3
|
||||
#define STACK_SIZE 1024 * 2
|
||||
|
||||
#if defined(__CC_ARM)
|
||||
#define HEAP_ATTR SECTION("HEAP") __attribute__((zero_init))
|
||||
|
||||
@@ -40,6 +40,13 @@ int main(int argc, char *args[])
|
||||
int ret = rpc_creaite_bind_ipc(THREAD_MAIN, NULL, &ipc_hd);
|
||||
assert(ret >= 0);
|
||||
env.ns_hd = ipc_hd;
|
||||
|
||||
ret = app_load("fatfs", &env);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("app load fail, 0x%x\n", ret);
|
||||
}
|
||||
|
||||
ret = app_load("shell", &env);
|
||||
if (ret < 0)
|
||||
{
|
||||
@@ -47,11 +54,6 @@ int main(int argc, char *args[])
|
||||
}
|
||||
namespace_init(ipc_hd);
|
||||
|
||||
ret = app_load("fatfs", &env);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("app load fail, 0x%x\n", ret);
|
||||
}
|
||||
namespace_loop();
|
||||
task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, TASK_THIS)); // 删除当前task,以及申请得所有对象
|
||||
printf("exit init.\n");
|
||||
|
||||
@@ -11,82 +11,20 @@
|
||||
#include "u_ns.h"
|
||||
#include "test.h"
|
||||
#include "u_rpc.h"
|
||||
#include "ns_cli.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
void malloc_test(void)
|
||||
{
|
||||
void *mem = malloc(1024);
|
||||
assert(mem);
|
||||
void *mem1 = malloc(1024);
|
||||
assert(mem1);
|
||||
free(mem);
|
||||
free(mem1);
|
||||
mem = malloc(4 * 1024);
|
||||
assert(mem);
|
||||
free(mem);
|
||||
mem1 = malloc(1024);
|
||||
assert(mem1);
|
||||
free(mem1);
|
||||
}
|
||||
void ns_test(void)
|
||||
{
|
||||
#if 0
|
||||
int ret;
|
||||
obj_handler_t tmp_ipc_hd;
|
||||
|
||||
tmp_ipc_hd = handler_alloc();
|
||||
assert(tmp_ipc_hd != HANDLER_INVALID);
|
||||
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, vpage_create_raw3(0, 0, tmp_ipc_hd));
|
||||
assert(msg_tag_get_val(tag) >= 0);
|
||||
ret = cli_ns_register("shell", tmp_ipc_hd);
|
||||
assert(ret >= 0);
|
||||
ret = cli_ns_query("shell", &tmp_ipc_hd);
|
||||
assert(ret >= 0);
|
||||
ulog_write_str(u_get_global_env()->log_hd, "ns test success.\n");
|
||||
#endif
|
||||
obj_handler_t tmp_ipc_hd;
|
||||
|
||||
tmp_ipc_hd = handler_alloc();
|
||||
assert(tmp_ipc_hd != HANDLER_INVALID);
|
||||
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, vpage_create_raw3(0, 0, tmp_ipc_hd));
|
||||
|
||||
assert(ns_register("shell", tmp_ipc_hd) >= 0);
|
||||
obj_handler_t rcv_ipc_hd;
|
||||
|
||||
assert(ns_query("shell", &rcv_ipc_hd) >= 0);
|
||||
|
||||
handler_free_umap(rcv_ipc_hd);
|
||||
}
|
||||
#include "fs_cli.h"
|
||||
void fs_test(void)
|
||||
{
|
||||
char tmp[4] = "123";
|
||||
int fd = fs_open("/test", 0, 0x1 | 0x2 | 0x8);
|
||||
assert(fd >= 0);
|
||||
int wlen = fs_write(fd, tmp, 4);
|
||||
assert(wlen == 4);
|
||||
int ret = fs_lseek(fd, 0, SEEK_SET);
|
||||
assert(ret >= 0);
|
||||
int rlen = fs_read(fd, tmp, 4);
|
||||
assert(rlen == 4);
|
||||
assert(strcmp(tmp, "123") == 0);
|
||||
fs_close(fd);
|
||||
}
|
||||
int main(int argc, char *args[])
|
||||
{
|
||||
printf("argc:%d args[0]:%s\n", argc, args[0]);
|
||||
ulog_write_str(u_get_global_env()->log_hd, "MKRTOS:\n");
|
||||
#if 0
|
||||
malloc_test();
|
||||
irq_test();
|
||||
#endif
|
||||
rpc_test();
|
||||
ns_test();
|
||||
#endif
|
||||
fs_test();
|
||||
irq_test();
|
||||
task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, TASK_THIS));
|
||||
ulog_write_str(u_get_global_env()->log_hd, "Error.\n");
|
||||
return 0;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
void irq_test(void);
|
||||
void rpc_test(void);
|
||||
void rpc_test(void);
|
||||
void fs_test(void);
|
||||
void ns_test(void);
|
||||
void malloc_test(void);
|
||||
|
||||
21
mkrtos_user/server/shell/test/fs_test.c
Normal file
21
mkrtos_user/server/shell/test/fs_test.c
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
|
||||
#include "fs_cli.h"
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
void fs_test(void)
|
||||
{
|
||||
char tmp[4] = "123";
|
||||
int fd = fs_open("/test", 0, 0x1 | 0x2 | 0x8);
|
||||
assert(fd >= 0);
|
||||
int wlen = fs_write(fd, tmp, 4);
|
||||
assert(wlen == 4);
|
||||
int ret = fs_lseek(fd, 0, SEEK_SET);
|
||||
assert(ret >= 0);
|
||||
int rlen = fs_read(fd, tmp, 4);
|
||||
assert(rlen == 4);
|
||||
assert(strcmp(tmp, "123") == 0);
|
||||
fs_close(fd);
|
||||
}
|
||||
@@ -56,4 +56,5 @@ void irq_test(void)
|
||||
}
|
||||
}
|
||||
ulog_write_str(LOG_PROT, "irq test success.\n");
|
||||
handler_free_umap(obj);
|
||||
}
|
||||
18
mkrtos_user/server/shell/test/malloc_test.c
Normal file
18
mkrtos_user/server/shell/test/malloc_test.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
void malloc_test(void)
|
||||
{
|
||||
void *mem = malloc(1024);
|
||||
assert(mem);
|
||||
void *mem1 = malloc(1024);
|
||||
assert(mem1);
|
||||
free(mem);
|
||||
free(mem1);
|
||||
mem = malloc(4 * 1024);
|
||||
assert(mem);
|
||||
free(mem);
|
||||
mem1 = malloc(1024);
|
||||
assert(mem1);
|
||||
free(mem1);
|
||||
}
|
||||
43
mkrtos_user/server/shell/test/ns_test.c
Normal file
43
mkrtos_user/server/shell/test/ns_test.c
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
#include "u_log.h"
|
||||
#include "u_prot.h"
|
||||
#include "u_mm.h"
|
||||
#include "u_factory.h"
|
||||
#include "u_thread.h"
|
||||
#include "u_task.h"
|
||||
#include "u_ipc.h"
|
||||
#include "u_env.h"
|
||||
#include "u_hd_man.h"
|
||||
#include "u_ns.h"
|
||||
#include "ns_cli.h"
|
||||
#include <assert.h>
|
||||
|
||||
void ns_test(void)
|
||||
{
|
||||
#if 0
|
||||
int ret;
|
||||
obj_handler_t tmp_ipc_hd;
|
||||
|
||||
tmp_ipc_hd = handler_alloc();
|
||||
assert(tmp_ipc_hd != HANDLER_INVALID);
|
||||
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, vpage_create_raw3(0, 0, tmp_ipc_hd));
|
||||
assert(msg_tag_get_val(tag) >= 0);
|
||||
ret = cli_ns_register("shell", tmp_ipc_hd);
|
||||
assert(ret >= 0);
|
||||
ret = cli_ns_query("shell", &tmp_ipc_hd);
|
||||
assert(ret >= 0);
|
||||
ulog_write_str(u_get_global_env()->log_hd, "ns test success.\n");
|
||||
#endif
|
||||
obj_handler_t tmp_ipc_hd;
|
||||
|
||||
tmp_ipc_hd = handler_alloc();
|
||||
assert(tmp_ipc_hd != HANDLER_INVALID);
|
||||
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, vpage_create_raw3(0, 0, tmp_ipc_hd));
|
||||
|
||||
assert(ns_register("shell", tmp_ipc_hd) >= 0);
|
||||
obj_handler_t rcv_ipc_hd;
|
||||
|
||||
assert(ns_query("shell", &rcv_ipc_hd) >= 0);
|
||||
|
||||
handler_free_umap(rcv_ipc_hd);
|
||||
}
|
||||
Reference in New Issue
Block a user