This commit is contained in:
lr
2024-05-29 15:37:20 +08:00
139 changed files with 4951 additions and 486 deletions
+17 -3
View File
@@ -10,6 +10,12 @@ cflags = -std=c11 -O2 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -
board_specs = stub.o
#cflags = -Wall -g -std=c11
endif
ifeq ($(BOARD), ok1028a-c)
toolchain ?= aarch64-none-elf-
user_ldflags = -N -Ttext 0
cflags = -Wall -g -std=c11 -mtune=cortex-a72 -nostdlib -nodefaultlibs -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie
board_specs = stub.o
endif
cc = ${toolchain}gcc
ld = ${toolchain}g++
@@ -37,9 +43,9 @@ INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \
-I$(KERNEL_ROOT)/services/app
ifeq ($(BOARD), imx6q-sabrelite)
all: init test_fs simple_client simple_server shell fs_server semaphore_server test_thread test_irq_hdlr test_irq_block test_irq_send eth_driver epit_server test_net lwip readme.txt | bin
all: init test_fault simple_client simple_server shell fs_server semaphore_server test_semaphore test_ipc_null test_thread test_irq_hdlr test_irq_block test_irq_send eth_driver epit_server readme.txt | bin
else
all: init test_fs simple_client simple_server shell fs_server test_irq_hdlr readme.txt | bin
all: init test_fault simple_client simple_server shell fs_server test_ipc_null test_thread test_semaphore readme.txt | bin
endif
../tools/mkfs/mkfs ./fs.img $^
@mv $(filter-out readme.txt, $^) bin
@@ -63,6 +69,14 @@ epit_server: timer.o epit.o ccm_pll.o usyscall.o arch_usyscall.o libserial.o pri
@${objdump} -S $@ > $@.asm
endif
test_semaphore: test_semaphore.o libserial.o printf.o usyscall.o arch_usyscall.o
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
@${objdump} -S $@ > $@.asm
test_ipc_null: test_ipc_null.o libserial.o printf.o usyscall.o arch_usyscall.o libipc.o session.o
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
@${objdump} -S $@ > $@.asm
semaphore_server: semaphore_server.o libserial.o printf.o usyscall.o arch_usyscall.o libipc.o session.o
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
@${objdump} -S $@ > $@.asm
@@ -87,7 +101,7 @@ init: init.o libfs.o libipc.o session.o libserial.o printf.o usyscall.o arch_usy
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
@${objdump} -S $@ > $@.asm
test_fs: test_fs.o libfs.o libipc.o session.o libserial.o printf.o usyscall.o arch_usyscall.o libmem.o
test_fault: test_fault.o libserial.o printf.o usyscall.o arch_usyscall.o
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
@${objdump} -S $@ > $@.asm
@@ -56,10 +56,10 @@ int main(void)
printf("session connect faield\n");
return -1;
}
shellTask(&shell);
free_session(&session_fs);
exit(0);
return 0;
}
@@ -85,7 +85,6 @@ int main(int argc, char** argv)
if (argc >= 2) {
id = string_to_integer(argv[1]);
}
// printf("This is Simple Client %d, size is 0x%x\n", id, task_heap_base());
struct Session session_wait;
struct Session session_nowait;
@@ -94,37 +93,39 @@ int main(int argc, char** argv)
exit(1);
}
// test no wait ipc
char *buf1 = NULL, *buf2 = NULL;
struct IpcMsg* msg1 = hello_string_nowait(&session_nowait, &buf1, 32);
struct IpcMsg* msg2 = hello_string_nowait(&session_nowait, &buf2, 128);
int ret = add(&session_wait, 17, 22);
// test ipc add(wait version)
int ret = 0;
ret = add(&session_wait, 17, 22);
printf("ipc_add 17 + 22 = %d\n", ret);
char buf[32];
ret = add(&session_wait, 9, 9);
printf("ipc_add 9 + 9 = %d\n", ret);
struct Session session;
struct Session fs_session;
static char id_buf[33] = { 0 };
if (id > 1) {
if (connect_session(&session, "MemFS", 8092) < 0) {
printf("connect session failed\n");
if (connect_session(&fs_session, "MemFS", 8192) < 0) {
printf("connect fs_session failed\n");
} else {
int fd;
itoa(id - 1, id_buf, 10);
char* shell_task_param[3] = { "/simple_client", id_buf, 0 };
if ((fd = open(&session, shell_task_param[0])) >= 0) {
if (spawn(&session, fd, read, fsize, shell_task_param[0], shell_task_param) < 0) {
if ((fd = open(&fs_session, shell_task_param[0])) >= 0) {
if (spawn(&fs_session, fd, read, fsize, shell_task_param[0], shell_task_param) < 0) {
printf("Syscall Spawn simple_client failed\n");
}
if (spawn(&session, fd, read, fsize, shell_task_param[0], shell_task_param) < 0) {
if (spawn(&fs_session, fd, read, fsize, shell_task_param[0], shell_task_param) < 0) {
printf("Syscall Spawn simple_client failed\n");
}
close(&session, fd);
close(&fs_session, fd);
} else {
printf("Open %s failed\n", shell_task_param[0]);
}
free_session(&session);
free_session(&fs_session);
}
}
@@ -44,4 +44,5 @@ int main(int argc, char* argv[])
// never reached
exit(0);
return 0;
}
@@ -10,34 +10,18 @@
* See the Mulan PSL v2 for more details.
*/
// test_priority: Test the priority scheduler of task
// test_fs: Test the file io control of fs
#include <assert.h>
#include <stdbool.h>
#include <string.h>
#include "libserial.h"
#include "usyscall.h"
static void count_down()
{
int time = 500000000;
while (time >= 0) {
if (time % 10000000 == 0) {
printf("Priority-based preempting, time remained %d\n", time);
}
time--;
}
return;
}
int main(int argc, char* argv[])
{
// set priority
sys_state_info info;
info.priority = 0;
set_priority(&info);
// test function
count_down();
printf("Test memry error %s.\n", 0x50000000);
printf("After error computing.\n");
exit(0);
return 0;
@@ -1,53 +0,0 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
// test_fs: Test the file io control of fs
#include <assert.h>
#include <stdbool.h>
#include <string.h>
#include "libfs.h"
#include "libserial.h"
#include "usyscall.h"
#define BLOCK_SIZE 256
int main(int argc, char* argv[])
{
printf("file system test\n");
struct Session session;
connect_session(&session, "MemFS", 4096);
int fd;
char* fd_path = "/readme.txt";
fd = open(&session, fd_path);
/// @todo support malloc for user
char buffer[BLOCK_SIZE] = { 0 };
read(&session, fd, buffer, 0, BLOCK_SIZE);
printf("file content: %s\n", buffer);
char* write_data = "hello world\n";
write(&session, fd, write_data, 0, strlen(write_data) + 1);
memset(buffer, 0, BLOCK_SIZE);
read(&session, fd, buffer, 0, BLOCK_SIZE);
printf("file content: %s\n", buffer);
close(&session, fd);
free_session(&session);
printf("file test done.\n");
printf("Test memry error %s.\n", 0x50000000);
printf("After error computing.\n");
exit(0);
return 0;
}
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#include <stdbool.h>
#include <string.h>
#include "libipc.h"
#include "libserial.h"
#include "usyscall.h"
IPC_SERVICES(IpcTestNull, Ipc_test_null);
#define TEST_BUF_SIZE 32
static char test_null_server_name[] = "TestNullServer";
static char test_null_client_name[] = "TestNullClient";
// client side
static char buf[TEST_BUF_SIZE];
IPC_INTERFACE(Ipc_test_null, 1, ptr, sizeof(buf));
int test_null(struct Session* session, char* ptr)
{
return IPC_CALL(Ipc_test_null)(session, ptr);
}
// client thread
int server_thread(int argc, char** argv);
int main(int argc, char** argv)
{
struct Session session;
bool server_enabled = false;
while (connect_session(&session, test_null_server_name, 4096) < 0) {
if (!server_enabled) {
char* server_param[] = { test_null_server_name, NULL };
if (thread(server_thread, test_null_server_name, server_param) >= 0) {
server_enabled = true;
}
}
}
printf("[%s] Call using NULL ptr.\n", test_null_client_name);
test_null(&session, NULL);
printf("[%s] Call using non-NULL ptr.\n", test_null_client_name);
test_null(&session, buf);
exit(0);
return 0;
}
// server side
int IPC_DO_SERVE_FUNC(Ipc_test_null)(void* ptr)
{
if (ptr == NULL) {
printf("[%s]: A NULL ptr ipc call.\n", test_null_server_name);
} else {
printf("[%s]: A non-NULL ptr ipc call.\n", test_null_server_name);
}
return 0;
}
IPC_SERVER_INTERFACE(Ipc_test_null, 1);
IPC_SERVER_REGISTER_INTERFACES(IpcTestNull, 1, Ipc_test_null);
// server threads
int server_thread(int argc, char** argv)
{
if (register_server(test_null_server_name) < 0) {
printf("[%s] Register %s server failed.\n", test_null_server_name, test_null_server_name);
exit(1);
return 1;
}
ipc_server_loop(&IpcTestNull);
exit(0);
return 0;
}
@@ -52,4 +52,5 @@ int main()
ipc_server_loop(&IpcSwIntrHandler);
exit(0);
return 0;
}
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#include <stdint.h>
#include "libserial.h"
#include "usyscall.h"
enum {
NR_THREADS = 16,
LOOP_TIMES = 0x1000000,
};
static int sem_id = -1;
static uint32_t sum = 0;
static int nr_thds = NR_THREADS;
int do_calculation(int argc, char** argv)
{
for (uint32_t i = 0; i < LOOP_TIMES; i++) {
sum++;
}
printf("test semaphore thd signal.\n");
semaphore_signal(sem_id);
char* params[] = { "do_cal", NULL };
if (nr_thds != 0) {
int tid = thread(do_calculation, "test_sem_thd", params);
nr_thds--;
}
exit(0);
return 0;
}
int main(int argc, char** argv)
{
printf("Test Semaphore.\n");
sem_id = semaphore_new(0);
if (sem_id < 0) {
printf("new a kernel sem failed.\n");
exit(1);
}
sum = 0;
nr_thds = NR_THREADS;
char* params[] = { "do_cal", NULL };
if (nr_thds != 0) {
int tid = thread(do_calculation, "test_sem_thd", params);
nr_thds--;
}
for (int i = 0; i < NR_THREADS; i++) {
semaphore_wait(sem_id);
}
printf("test thread sum after %d signal: 0x%x\n", NR_THREADS, sum);
exit(0);
return 0;
}
@@ -25,6 +25,8 @@ int sub_thread_entry(int argc, char** argv)
global_value++;
}
/// @warning session is single threaded, so that each thread cannot share a common session.
// sub thread connect to semaphore server
struct Session sem_session;
while (connect_session(&sem_session, sem_server_name, 4096) < 0) {
yield(SYS_TASK_YIELD_NO_REASON);