服务的简单测试
This commit is contained in:
@@ -46,6 +46,7 @@ int main(int argc, char *args[])
|
||||
{
|
||||
printf("app load fail, 0x%x\n", ret);
|
||||
}
|
||||
ns_init();
|
||||
ns_pre_alloc_map_fd(thread_get_cur_ipc_msg());
|
||||
rpc_loop(ipc_hd, ns_dispatch);
|
||||
task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, TASK_THIS)); // 删除当前task,以及申请得所有对象
|
||||
|
||||
@@ -23,6 +23,14 @@ namespace_t;
|
||||
|
||||
static namespace_t ns;
|
||||
|
||||
void ns_init(void)
|
||||
{
|
||||
for (int i = 0; i < NAMESAPCE_NR; i++)
|
||||
{
|
||||
ns.ne_list[i].hd = HANDLER_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
static int ns_alloc(const char *path, obj_handler_t hd)
|
||||
{
|
||||
for (int i = 0; i < NAMESAPCE_NR; i++)
|
||||
@@ -57,7 +65,7 @@ int ns_register(const char *path, obj_handler_t hd)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
printf("register svr, name is %d, hd is %d\n", path, hd);
|
||||
printf("register svr, name is %s, hd is %d\n", path, hd);
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
@@ -111,9 +119,9 @@ msg_tag_t ns_dispatch(ipc_msg_t *msg)
|
||||
break;
|
||||
}
|
||||
((char *)&(msg->msg_buf[2]))[len] = 0;
|
||||
ns_register((char*)msg->msg_buf[2], pre_alloc_hd);
|
||||
int ret = ns_register((char *)(&msg->msg_buf[2]), pre_alloc_hd);
|
||||
ns_pre_alloc_map_fd(msg);
|
||||
tag = msg_tag_init4(0, 0, 0, 0);
|
||||
tag = msg_tag_init4(0, 0, 0, ret);
|
||||
}
|
||||
break;
|
||||
case OP_QUERY:
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "u_types.h"
|
||||
#include "u_prot.h"
|
||||
|
||||
void ns_init(void);
|
||||
int ns_register(const char *path, obj_handler_t hd);
|
||||
int ns_query(const char *path, obj_handler_t *hd);
|
||||
msg_tag_t ns_dispatch(ipc_msg_t *msg);
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
#include "u_task.h"
|
||||
#include "u_ipc.h"
|
||||
#include "u_env.h"
|
||||
#include "u_hd_man.h"
|
||||
#include "test.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include <string.h>
|
||||
void malloc_test(void)
|
||||
{
|
||||
void *mem = malloc(1024);
|
||||
@@ -27,26 +28,36 @@ void malloc_test(void)
|
||||
assert(mem1);
|
||||
free(mem1);
|
||||
}
|
||||
void ns_test(void)
|
||||
{
|
||||
char *buf;
|
||||
ipc_msg_t *ipc_msg;
|
||||
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);
|
||||
|
||||
thread_msg_buf_get(THREAD_MAIN, (umword_t *)(&buf), NULL);
|
||||
ipc_msg = (ipc_msg_t *)buf;
|
||||
ipc_msg->msg_buf[0] = 0;
|
||||
ipc_msg->msg_buf[1] = strlen("shell") + 1;
|
||||
ipc_msg->map_buf[0] = vpage_create_raw3(0, 0, tmp_ipc_hd).raw;
|
||||
strcpy((char *)(&ipc_msg->msg_buf[2]), "shell");
|
||||
tag = ipc_call(u_get_global_env()->ns_hd, msg_tag_init4(0, 2 + ROUND_UP(strlen("shell"), WORD_BYTES), 1, 0), ipc_timeout_create2(0, 0));
|
||||
printf("msg %d\n", tag.msg_buf_len);
|
||||
handler_free_umap(tmp_ipc_hd);
|
||||
}
|
||||
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();
|
||||
char *buf;
|
||||
ipc_msg_t *ipc_msg;
|
||||
thread_msg_buf_get(THREAD_MAIN, (umword_t *)(&buf), NULL);
|
||||
ipc_msg = (ipc_msg_t *)buf;
|
||||
ipc_msg->msg_buf[0] = 0x112233;
|
||||
ipc_msg->msg_buf[1] = 0x223344;
|
||||
msg_tag_t tag = ipc_call(u_get_global_env()->ns_hd, msg_tag_init4(0, 2, 0, 0), ipc_timeout_create2(0, 0));
|
||||
printf("msg %d\n", tag.msg_buf_len);
|
||||
irq_test();
|
||||
// ipc_wait(12, 0);
|
||||
// ipc_reply(12, msg_tag_init4(0, 0, 0, 0));
|
||||
// umword_t len;
|
||||
// thread_msg_buf_get(THREAD_MAIN, (umword_t *)(&buf), NULL);
|
||||
// printf(buf);
|
||||
#endif
|
||||
ns_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;
|
||||
|
||||
Reference in New Issue
Block a user