summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMeco Jianting Man <[email protected]>2021-06-13 16:19:59 +0800
committerMeco Jianting Man <[email protected]>2021-06-13 16:19:59 +0800
commit4fd407461793613fd2f0fc74f85b194b68df9447 (patch)
tree46c71c9be7294a5d9870f83c4f2edb4a28b75729 /examples
parentfbcaa667f87be5c5a3e1502d12facd24ca5b2234 (diff)
parentb24447a60a6941568d58dd1ca358951674924ed2 (diff)
Merge branch 'RT-Thread:master' into ioctl
Diffstat (limited to 'examples')
-rw-r--r--examples/file/listdir.c9
-rw-r--r--examples/libc/ex3.c2
-rw-r--r--examples/libc/ex6.c2
-rw-r--r--examples/libc/ex7.c2
-rw-r--r--examples/libc/file.c2
-rw-r--r--examples/libc/memory.c2
-rw-r--r--examples/utest/configs/kernel/config.h304
-rw-r--r--examples/utest/configs/utest_self/config.h1
-rw-r--r--examples/utest/testcases/Kconfig1
-rw-r--r--examples/utest/testcases/kernel/Kconfig8
-rw-r--r--examples/utest/testcases/kernel/SConscript15
-rw-r--r--examples/utest/testcases/kernel/memheap_tc.c100
-rw-r--r--examples/utest/testcases/utest/pass_tc.c2
13 files changed, 441 insertions, 9 deletions
diff --git a/examples/file/listdir.c b/examples/file/listdir.c
index 98fbc5ea2c..06c746a642 100644
--- a/examples/file/listdir.c
+++ b/examples/file/listdir.c
@@ -13,7 +13,7 @@
void list_dir(const char* path)
{
- char * fullpath;
+ char * fullpath = RT_NULL;
DIR *dir;
dir = opendir(path);
@@ -57,7 +57,10 @@ void list_dir(const char* path)
rt_kprintf("open %s directory failed\n", path);
}
- rt_free(fullpath);
+ if (RT_NULL != fullpath)
+ {
+ rt_free(fullpath);
+ }
}
#ifdef RT_USING_FINSH
@@ -80,6 +83,6 @@ static void cmd_list_dir(int argc, char *argv[])
}
list_dir(filename);
}
-FINSH_FUNCTION_EXPORT_ALIAS(cmd_list_dir, __cmd_list_dir, list directory);
+MSH_CMD_EXPORT_ALIAS(cmd_list_dir, list_dir, list directory);
#endif /* FINSH_USING_MSH */
#endif /* RT_USING_FINSH */
diff --git a/examples/libc/ex3.c b/examples/libc/ex3.c
index 1697e7145b..615ed8f35c 100644
--- a/examples/libc/ex3.c
+++ b/examples/libc/ex3.c
@@ -9,7 +9,7 @@
/* Multi-thread searching.
Illustrates: thread cancellation, cleanup handlers. */
-#include <errno.h>
+#include <sys/errno.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
diff --git a/examples/libc/ex6.c b/examples/libc/ex6.c
index ac6319d74c..ba687aa46f 100644
--- a/examples/libc/ex6.c
+++ b/examples/libc/ex6.c
@@ -6,7 +6,7 @@
* Change Logs:
* Date Author Notes
*/
-#include <errno.h>
+#include <sys/errno.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
diff --git a/examples/libc/ex7.c b/examples/libc/ex7.c
index e885f79c57..d1f05dbdcd 100644
--- a/examples/libc/ex7.c
+++ b/examples/libc/ex7.c
@@ -11,7 +11,7 @@
* Test case that illustrates a timed wait on a condition variable.
*/
-#include <errno.h>
+#include <sys/errno.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
diff --git a/examples/libc/file.c b/examples/libc/file.c
index 79cdce3092..878d3a98d7 100644
--- a/examples/libc/file.c
+++ b/examples/libc/file.c
@@ -11,7 +11,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <finsh.h>
-#include <errno.h>
+#include <sys/errno.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
diff --git a/examples/libc/memory.c b/examples/libc/memory.c
index 063d90cfdc..4a31b69017 100644
--- a/examples/libc/memory.c
+++ b/examples/libc/memory.c
@@ -11,7 +11,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <finsh.h>
-#include <errno.h>
+#include <sys/errno.h>
static int errors = 0;
static void merror(const char *msg)
diff --git a/examples/utest/configs/kernel/config.h b/examples/utest/configs/kernel/config.h
new file mode 100644
index 0000000000..c7fcb763fb
--- /dev/null
+++ b/examples/utest/configs/kernel/config.h
@@ -0,0 +1,304 @@
+#ifndef RT_CONFIG_H__
+#define RT_CONFIG_H__
+
+/* Automatically generated file; DO NOT EDIT. */
+/* RT-Thread Project Configuration */
+
+/* RT-Thread Kernel */
+
+#define RT_NAME_MAX 8
+#define RT_USING_SMP
+#define RT_CPUS_NR 2
+#define RT_ALIGN_SIZE 4
+#define RT_THREAD_PRIORITY_32
+#define RT_THREAD_PRIORITY_MAX 32
+#define RT_TICK_PER_SECOND 100
+#define RT_USING_OVERFLOW_CHECK
+#define RT_USING_HOOK
+#define RT_USING_IDLE_HOOK
+#define RT_IDLE_HOOK_LIST_SIZE 4
+#define IDLE_THREAD_STACK_SIZE 1024
+#define RT_USING_TIMER_SOFT
+#define RT_TIMER_THREAD_PRIO 4
+#define RT_TIMER_THREAD_STACK_SIZE 1024
+
+/* kservice optimization */
+
+#define RT_DEBUG
+#define RT_DEBUG_COLOR
+
+/* Inter-Thread communication */
+
+#define RT_USING_SEMAPHORE
+#define RT_USING_MUTEX
+#define RT_USING_EVENT
+#define RT_USING_MAILBOX
+#define RT_USING_MESSAGEQUEUE
+#define RT_USING_SIGNALS
+
+/* Memory Management */
+
+#define RT_USING_MEMPOOL
+#define RT_USING_MEMHEAP
+#define RT_USING_SMALL_MEM
+#define RT_USING_MEMTRACE
+#define RT_USING_HEAP
+
+/* Kernel Device Object */
+
+#define RT_USING_DEVICE
+#define RT_USING_DEVICE_OPS
+#define RT_USING_INTERRUPT_INFO
+#define RT_USING_CONSOLE
+#define RT_CONSOLEBUF_SIZE 256
+#define RT_CONSOLE_DEVICE_NAME "uart0"
+#define RT_VER_NUM 0x40004
+#define ARCH_ARM
+#define RT_USING_CPU_FFS
+#define ARCH_ARM_CORTEX_A
+#define RT_USING_GIC_V2
+#define ARCH_ARM_CORTEX_A9
+
+/* RT-Thread Components */
+
+#define RT_USING_COMPONENTS_INIT
+#define RT_USING_USER_MAIN
+#define RT_MAIN_THREAD_STACK_SIZE 2048
+#define RT_MAIN_THREAD_PRIORITY 10
+
+/* C++ features */
+
+#define RT_USING_CPLUSPLUS
+
+/* Command shell */
+
+#define RT_USING_FINSH
+#define FINSH_THREAD_NAME "tshell"
+#define FINSH_USING_HISTORY
+#define FINSH_HISTORY_LINES 5
+#define FINSH_USING_SYMTAB
+#define FINSH_USING_DESCRIPTION
+#define FINSH_THREAD_PRIORITY 20
+#define FINSH_THREAD_STACK_SIZE 4096
+#define FINSH_CMD_SIZE 80
+#define FINSH_USING_MSH
+#define FINSH_USING_MSH_DEFAULT
+#define FINSH_ARG_MAX 10
+
+/* Device virtual file system */
+
+#define RT_USING_DFS
+#define DFS_USING_WORKDIR
+#define DFS_FILESYSTEMS_MAX 4
+#define DFS_FILESYSTEM_TYPES_MAX 8
+#define DFS_FD_MAX 32
+#define RT_USING_DFS_ELMFAT
+
+/* elm-chan's FatFs, Generic FAT Filesystem Module */
+
+#define RT_DFS_ELM_CODE_PAGE 437
+#define RT_DFS_ELM_WORD_ACCESS
+#define RT_DFS_ELM_USE_LFN_3
+#define RT_DFS_ELM_USE_LFN 3
+#define RT_DFS_ELM_LFN_UNICODE_0
+#define RT_DFS_ELM_LFN_UNICODE 0
+#define RT_DFS_ELM_MAX_LFN 255
+#define RT_DFS_ELM_DRIVES 2
+#define RT_DFS_ELM_MAX_SECTOR_SIZE 4096
+#define RT_DFS_ELM_REENTRANT
+#define RT_USING_DFS_DEVFS
+#define RT_USING_DFS_ROMFS
+#define RT_USING_DFS_RAMFS
+
+/* Device Drivers */
+
+#define RT_USING_DEVICE_IPC
+#define RT_PIPE_BUFSZ 512
+#define RT_USING_SYSTEM_WORKQUEUE
+#define RT_SYSTEM_WORKQUEUE_STACKSIZE 2048
+#define RT_SYSTEM_WORKQUEUE_PRIORITY 23
+#define RT_USING_SERIAL
+#define RT_SERIAL_USING_DMA
+#define RT_SERIAL_RB_BUFSZ 64
+#define RT_USING_I2C
+#define RT_USING_I2C_BITOPS
+#define RT_USING_PIN
+#define RT_USING_MTD_NOR
+#define RT_USING_MTD_NAND
+#define RT_MTD_NAND_DEBUG
+#define RT_USING_RTC
+#define RT_USING_SOFT_RTC
+#define RT_USING_SDIO
+#define RT_SDIO_STACK_SIZE 512
+#define RT_SDIO_THREAD_PRIORITY 15
+#define RT_MMCSD_STACK_SIZE 1024
+#define RT_MMCSD_THREAD_PREORITY 22
+#define RT_MMCSD_MAX_PARTITION 16
+#define RT_USING_SPI
+#define RT_USING_SPI_MSD
+#define RT_USING_SFUD
+#define RT_SFUD_USING_SFDP
+#define RT_SFUD_USING_FLASH_INFO_TABLE
+#define RT_SFUD_SPI_MAX_HZ 50000000
+#define RT_USING_WDT
+
+/* Using USB */
+
+
+/* POSIX layer and C standard library */
+
+#define RT_USING_LIBC
+#define RT_USING_PTHREADS
+#define PTHREAD_NUM_MAX 8
+#define RT_USING_POSIX
+#define RT_USING_POSIX_MMAP
+#define RT_USING_POSIX_TERMIOS
+#define RT_USING_POSIX_GETLINE
+#define RT_USING_POSIX_AIO
+#define RT_LIBC_FIXED_TIMEZONE 8
+
+/* Network */
+
+/* Socket abstraction layer */
+
+#define RT_USING_SAL
+#define SAL_INTERNET_CHECK
+
+/* protocol stack implement */
+
+#define SAL_USING_LWIP
+#define SAL_USING_POSIX
+
+/* Network interface device */
+
+#define RT_USING_NETDEV
+#define NETDEV_USING_IFCONFIG
+#define NETDEV_USING_PING
+#define NETDEV_USING_NETSTAT
+#define NETDEV_USING_AUTO_DEFAULT
+#define NETDEV_IPV4 1
+#define NETDEV_IPV6 0
+
+/* light weight TCP/IP stack */
+
+#define RT_USING_LWIP
+#define RT_USING_LWIP202
+#define RT_LWIP_MEM_ALIGNMENT 4
+#define RT_LWIP_ICMP
+#define RT_LWIP_DNS
+#define RT_LWIP_DHCP
+#define IP_SOF_BROADCAST 1
+#define IP_SOF_BROADCAST_RECV 1
+
+/* Static IPv4 Address */
+
+#define RT_LWIP_IPADDR "192.168.1.30"
+#define RT_LWIP_GWADDR "192.168.1.1"
+#define RT_LWIP_MSKADDR "255.255.255.0"
+#define RT_LWIP_UDP
+#define RT_LWIP_TCP
+#define RT_LWIP_RAW
+#define RT_MEMP_NUM_NETCONN 8
+#define RT_LWIP_PBUF_NUM 16
+#define RT_LWIP_RAW_PCB_NUM 4
+#define RT_LWIP_UDP_PCB_NUM 4
+#define RT_LWIP_TCP_PCB_NUM 4
+#define RT_LWIP_TCP_SEG_NUM 40
+#define RT_LWIP_TCP_SND_BUF 8196
+#define RT_LWIP_TCP_WND 8196
+#define RT_LWIP_TCPTHREAD_PRIORITY 10
+#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8
+#define RT_LWIP_TCPTHREAD_STACKSIZE 1024
+#define RT_LWIP_ETHTHREAD_PRIORITY 12
+#define RT_LWIP_ETHTHREAD_STACKSIZE 1024
+#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8
+#define RT_LWIP_REASSEMBLY_FRAG
+#define LWIP_NETIF_STATUS_CALLBACK 1
+#define LWIP_NETIF_LINK_CALLBACK 1
+#define SO_REUSE 1
+#define LWIP_SO_RCVTIMEO 1
+#define LWIP_SO_SNDTIMEO 1
+#define LWIP_SO_RCVBUF 1
+#define LWIP_SO_LINGER 0
+#define LWIP_NETIF_LOOPBACK 0
+#define RT_LWIP_USING_PING
+
+/* AT commands */
+
+
+/* VBUS(Virtual Software BUS) */
+
+
+/* Utilities */
+
+#define RT_USING_UTEST
+#define UTEST_THR_STACK_SIZE 4096
+#define UTEST_THR_PRIORITY 20
+#define RT_USING_LWP
+
+/* RT-Thread Utestcases */
+
+#define RT_USING_UTESTCASES
+
+/* Utest Self Testcase */
+
+#define UTEST_SELF_PASS_TC
+
+/* Kernel memheap stability Testcase */
+
+#define UTEST_MEMHEAP_TC
+
+/* RT-Thread online packages */
+
+/* IoT - internet of things */
+
+
+/* Wi-Fi */
+
+/* Marvell WiFi */
+
+
+/* Wiced WiFi */
+
+
+/* IoT Cloud */
+
+
+/* security packages */
+
+
+/* language packages */
+
+
+/* multimedia packages */
+
+
+/* tools packages */
+
+
+/* system packages */
+
+
+/* Micrium: Micrium software products porting for RT-Thread */
+
+
+/* peripheral libraries and drivers */
+
+
+/* AI packages */
+
+
+/* miscellaneous packages */
+
+
+/* samples: kernel and components samples */
+
+
+/* entertainment: terminal games and other interesting software packages */
+
+#define SOC_VEXPRESS_A9
+#define RT_USING_UART0
+#define RT_USING_UART1
+#define BSP_DRV_EMAC
+
+#endif
diff --git a/examples/utest/configs/utest_self/config.h b/examples/utest/configs/utest_self/config.h
index 2080a544b0..fa94023c42 100644
--- a/examples/utest/configs/utest_self/config.h
+++ b/examples/utest/configs/utest_self/config.h
@@ -54,6 +54,7 @@
#define RT_CONSOLE_DEVICE_NAME "uart0"
#define RT_VER_NUM 0x40004
#define ARCH_ARM
+#define RT_USING_CPU_FFS
#define ARCH_ARM_CORTEX_A
#define RT_USING_GIC_V2
#define ARCH_ARM_CORTEX_A9
diff --git a/examples/utest/testcases/Kconfig b/examples/utest/testcases/Kconfig
index da80eb30ae..a9b556f1e3 100644
--- a/examples/utest/testcases/Kconfig
+++ b/examples/utest/testcases/Kconfig
@@ -8,6 +8,7 @@ config RT_USING_UTESTCASES
if RT_USING_UTESTCASES
source "$RTT_DIR/examples/utest/testcases/utest/Kconfig"
+source "$RTT_DIR/examples/utest/testcases/kernel/Kconfig"
endif
diff --git a/examples/utest/testcases/kernel/Kconfig b/examples/utest/testcases/kernel/Kconfig
new file mode 100644
index 0000000000..14334af16f
--- /dev/null
+++ b/examples/utest/testcases/kernel/Kconfig
@@ -0,0 +1,8 @@
+menu "Kernel Testcase"
+
+config UTEST_MEMHEAP_TC
+ bool "memheap stability test"
+ default y
+ depends on RT_USING_MEMHEAP
+
+endmenu
diff --git a/examples/utest/testcases/kernel/SConscript b/examples/utest/testcases/kernel/SConscript
new file mode 100644
index 0000000000..9411cdd9a0
--- /dev/null
+++ b/examples/utest/testcases/kernel/SConscript
@@ -0,0 +1,15 @@
+Import('rtconfig')
+from building import *
+
+cwd = GetCurrentDir()
+src = Split('''
+''')
+
+if GetDepend(['UTEST_MEMHEAP_TC']):
+ src += ['memheap_tc.c']
+
+CPPPATH = [cwd]
+
+group = DefineGroup('utestcases', src, depend = [], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/examples/utest/testcases/kernel/memheap_tc.c b/examples/utest/testcases/kernel/memheap_tc.c
new file mode 100644
index 0000000000..ee52bdb185
--- /dev/null
+++ b/examples/utest/testcases/kernel/memheap_tc.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2006-2019, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2019-01-16 flybreak the first version
+ */
+
+#include <rtthread.h>
+#include <stdlib.h>
+#include "utest.h"
+
+#define HEAP_SIZE (64 * 1024)
+#define HEAP_ALIGN (4)
+#define SLICE_NUM (40)
+#define TEST_TIMES (100000)
+#define HEAP_NAME "heap1"
+#define SLICE_SIZE_MAX (HEAP_SIZE/SLICE_NUM)
+
+static void memheap_test(void)
+{
+ struct rt_memheap heap1;
+ rt_uint32_t ptr_start;
+ void *ptr[SLICE_NUM];
+ int i, cnt = 0;
+
+ /* init heap */
+ ptr_start = (rt_uint32_t)rt_malloc_align(HEAP_SIZE, HEAP_ALIGN);
+ if (ptr_start == RT_NULL)
+ {
+ rt_kprintf("totle size too big,can not malloc memory!");
+ return;
+ }
+
+ rt_memheap_init(&heap1, HEAP_NAME, (void *)ptr_start, HEAP_SIZE);
+
+ /* test start */
+ for (i = 0; i < SLICE_NUM; i++)
+ {
+ ptr[i] = 0;
+ }
+ /* test alloc */
+ for (i = 0; i < SLICE_NUM; i++)
+ {
+ rt_uint32_t slice_size = rand() % SLICE_SIZE_MAX;
+ ptr[i] = rt_memheap_alloc(&heap1, slice_size);
+ }
+ /* test realloc */
+ while (cnt < TEST_TIMES)
+ {
+ rt_uint32_t slice_size = rand() % SLICE_SIZE_MAX;
+ rt_uint32_t ptr_index = rand() % SLICE_NUM;
+ rt_uint32_t operation = rand() % 2;
+
+ if (ptr[ptr_index])
+ {
+ if (operation == 0) /* free and malloc */
+ {
+ if (ptr[ptr_index])
+ {
+ rt_memheap_free(ptr[ptr_index]);
+ }
+ ptr[ptr_index] = rt_memheap_alloc(&heap1, slice_size);
+ }
+ else /* realloc */
+ {
+ ptr[ptr_index] = rt_memheap_realloc(&heap1, ptr[ptr_index], slice_size);
+ }
+ }
+ cnt ++;
+ if (cnt % (TEST_TIMES / 10) == 0)
+ {
+ rt_kprintf(">");
+ }
+ }
+
+ rt_kprintf("test OK!\n");
+
+ /* test end */
+ rt_memheap_detach(&heap1);
+ rt_free_align((void *)ptr_start);
+}
+
+static rt_err_t utest_tc_init(void)
+{
+ return RT_EOK;
+}
+
+static rt_err_t utest_tc_cleanup(void)
+{
+ return RT_EOK;
+}
+
+static void testcase(void)
+{
+ UTEST_UNIT_RUN(memheap_test);
+}
+UTEST_TC_EXPORT(testcase, "testcases.kernel.memheap_tc", utest_tc_init, utest_tc_cleanup, 10);
diff --git a/examples/utest/testcases/utest/pass_tc.c b/examples/utest/testcases/utest/pass_tc.c
index 8e93e35b9b..c9ee912fbf 100644
--- a/examples/utest/testcases/utest/pass_tc.c
+++ b/examples/utest/testcases/utest/pass_tc.c
@@ -43,4 +43,4 @@ static void testcase(void)
{
UTEST_UNIT_RUN(test_assert_pass);
}
-UTEST_TC_EXPORT(testcase, "testcases.utest.pass_tc", utest_tc_init, utest_tc_cleanup, 10); \ No newline at end of file
+UTEST_TC_EXPORT(testcase, "testcases.utest.pass_tc", utest_tc_init, utest_tc_cleanup, 10);