This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 6d31e66c4b7241300d70437f2cce514aa77d33c6 Author: huojianchao <[email protected]> AuthorDate: Tue Nov 24 14:28:39 2026 +0800 testing: fix the nxstyle and codespell errors in the mm tests The CI checks the whole of the files that the following patches change. Add the blank lines after the declarations, indent the code after the getopt() loop of memorystress, add the braces after the if in test_nuttx_mm07(), and fix "conditon" and "statistc" in iob_main.c. No functional change. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: huojianchao <[email protected]> --- testing/mm/iob/iob_main.c | 18 +++---- testing/mm/kasantest/kasantest.c | 18 +++++++ testing/mm/memstress/memorystress_main.c | 63 +++++++++++++----------- testing/testsuites/kernel/mm/cases/mm_test_007.c | 5 +- 4 files changed, 64 insertions(+), 40 deletions(-) diff --git a/testing/mm/iob/iob_main.c b/testing/mm/iob/iob_main.c index 69cfa08cb..1cba7d22b 100644 --- a/testing/mm/iob/iob_main.c +++ b/testing/mm/iob/iob_main.c @@ -293,7 +293,7 @@ int main(int argc, FAR char *argv[]) iob_free_chain(iob); - /* test race conditon between nothrottled and nothrottled */ + /* test race condition between nothrottled and nothrottled */ failed_count[0] = 0; failed_count[1] = 0; @@ -320,12 +320,12 @@ int main(int argc, FAR char *argv[]) pthread_join(thread[0], NULL); pthread_join(thread[1], NULL); - printf("nothrottled thread 0 statistc failed_count %d success_count %d\n", + printf("nothrottled thread 0 statistic failed_count %d success_count %d\n", failed_count[0], success_count[0]); - printf("nothrottled thread 1 statistc failed_count %d success_count %d\n", + printf("nothrottled thread 1 statistic failed_count %d success_count %d\n", failed_count[1], success_count[1]); - /* test race conditon between throttled and nothrottled */ + /* test race condition between throttled and nothrottled */ failed_count[0] = 0; failed_count[1] = 0; @@ -352,12 +352,12 @@ int main(int argc, FAR char *argv[]) pthread_join(thread[0], NULL); pthread_join(thread[1], NULL); - printf("nothrottled thread 0 statistc failed_count %d success_count %d\n", + printf("nothrottled thread 0 statistic failed_count %d success_count %d\n", failed_count[0], success_count[0]); - printf("throttled thread 1 statistc failed_count %d success_count %d\n", + printf("throttled thread 1 statistic failed_count %d success_count %d\n", failed_count[1], success_count[1]); - /* test race conditon between throttled and throttled */ + /* test race condition between throttled and throttled */ failed_count[0] = 0; failed_count[1] = 0; @@ -384,9 +384,9 @@ int main(int argc, FAR char *argv[]) pthread_join(thread[0], NULL); pthread_join(thread[1], NULL); - printf("throttled thread 0 statistc failed_count %d success_count %d\n", + printf("throttled thread 0 statistic failed_count %d success_count %d\n", failed_count[0], success_count[0]); - printf("throttled thread 1 statistc failed_count %d success_count %d\n", + printf("throttled thread 1 statistic failed_count %d success_count %d\n", failed_count[1], success_count[1]); return 0; diff --git a/testing/mm/kasantest/kasantest.c b/testing/mm/kasantest/kasantest.c index bf8317b54..a43cce7a8 100644 --- a/testing/mm/kasantest/kasantest.c +++ b/testing/mm/kasantest/kasantest.c @@ -207,6 +207,7 @@ static void timespec_sub(struct timespec *dest, static bool test_heap_underflow(FAR struct mm_heap_s *heap, size_t size) { FAR uint8_t *mem = mm_malloc(heap, size); + *(mem - 1) = 0x12; return false; } @@ -214,6 +215,7 @@ static bool test_heap_underflow(FAR struct mm_heap_s *heap, size_t size) static bool test_heap_overflow(FAR struct mm_heap_s *heap, size_t size) { FAR uint8_t *mem = mm_malloc(heap, size); + size = mm_malloc_size(heap, mem); mem[size + 1] = 0x11; @@ -232,6 +234,7 @@ static bool test_heap_use_after_free(FAR struct mm_heap_s *heap, size_t size) static bool test_heap_invalid_free(FAR struct mm_heap_s *heap, size_t size) { int x; + mm_free(heap, &x); return false; } @@ -248,6 +251,7 @@ static bool test_heap_double_free(FAR struct mm_heap_s *heap, size_t size) static bool test_heap_poison(FAR struct mm_heap_s *heap, size_t size) { FAR uint8_t *mem = mm_malloc(heap, size); + size = mm_malloc_size(heap, mem); kasan_poison(mem, size); @@ -269,6 +273,7 @@ static bool test_heap_unpoison(FAR struct mm_heap_s *heap, size_t size) static bool test_heap_illegal_memchr(FAR struct mm_heap_s *heap, size_t size) { FAR uint8_t *mem = mm_malloc(heap, size); + size = mm_malloc_size(heap, mem); return memchr(mem, 0x00, size + 1) == NULL; @@ -292,6 +297,7 @@ static bool test_heap_illegal_memcpy(FAR struct mm_heap_s *heap, size_t size) static bool test_heap_illegal_memcmp(FAR struct mm_heap_s *heap, size_t size) { FAR uint8_t *mem = mm_malloc(heap, size); + size = mm_malloc_size(heap, mem); return memcmp(mem, mem + size, 1) < 0; @@ -316,6 +322,7 @@ static bool test_heap_illegal_memmove(FAR struct mm_heap_s *heap, static bool test_heap_illegal_memset(FAR struct mm_heap_s *heap, size_t size) { FAR uint8_t *mem = mm_malloc(heap, size); + size = mm_malloc_size(heap, mem); memset(mem, 0x11, size + 1); @@ -325,6 +332,7 @@ static bool test_heap_illegal_memset(FAR struct mm_heap_s *heap, size_t size) static bool test_heap_illegal_strcmp(FAR struct mm_heap_s *heap, size_t size) { FAR char *mem = mm_malloc(heap, size); + size = mm_malloc_size(heap, mem); *(int *)mem = rand(); @@ -336,6 +344,7 @@ static bool test_heap_illegal_strcpy(FAR struct mm_heap_s *heap, size_t size) FAR char *dst = mm_malloc(heap, 16); FAR char *src; int i; + size = mm_malloc_size(heap, dst); src = mm_malloc(heap, size + 16); @@ -351,6 +360,7 @@ static bool test_heap_illegal_strcpy(FAR struct mm_heap_s *heap, size_t size) static bool test_heap_illegal_strlen(FAR struct mm_heap_s *heap, size_t size) { FAR char *mem = mm_malloc(heap, size); + size = mm_malloc_size(heap, mem); return strlen(mem + size) < 0; @@ -370,6 +380,7 @@ static bool test_heap_illegal_strncpy(FAR struct mm_heap_s *heap, static bool test_heap_illegal_strchr(FAR struct mm_heap_s *heap, size_t size) { FAR char *mem = mm_malloc(heap, size); + size = mm_malloc_size(heap, mem); return strchr(mem + size, 0x00) == NULL; @@ -380,6 +391,7 @@ static bool test_heap_illegal_strncmp(FAR struct mm_heap_s *heap, { FAR char *mem1 = mm_malloc(heap, size / 2); FAR char *mem2 = mm_malloc(heap, size / 2); + size = mm_malloc_size(heap, mem2); *(int *)mem1 = rand(); @@ -390,6 +402,7 @@ static bool test_heap_illegal_strnlen(FAR struct mm_heap_s *heap, size_t size) { FAR char *mem = mm_malloc(heap, size); + size = mm_malloc_size(heap, mem); return strnlen(mem + size, size) < 0; @@ -399,6 +412,7 @@ static bool test_heap_illegal_strrchr(FAR struct mm_heap_s *heap, size_t size) { FAR char *mem = mm_malloc(heap, size); + size = mm_malloc_size(heap, mem); return strrchr(mem + size, 0x00) == NULL; @@ -407,6 +421,7 @@ static bool test_heap_illegal_strrchr(FAR struct mm_heap_s *heap, static bool test_heap_legal_memchr(FAR struct mm_heap_s *heap, size_t size) { FAR char *mem = mm_malloc(heap, size); + size = mm_malloc_size(heap, mem); memset(mem, 0, size); @@ -451,6 +466,7 @@ static bool test_heap_legal_memmove(FAR struct mm_heap_s *heap, size_t size) static bool test_heap_legal_memset(FAR struct mm_heap_s *heap, size_t size) { FAR char *des = mm_malloc(heap, size / 2); + size = mm_malloc_size(heap, des); return memset(des, 0xef, size); @@ -517,6 +533,7 @@ static bool test_heap_legal_strncmp(FAR struct mm_heap_s *heap, size_t size) static bool test_heap_legal_strnlen(FAR struct mm_heap_s *heap, size_t size) { FAR char *mem = mm_malloc(heap, size); + size = mm_malloc_size(heap, mem); mem[size - 1] = 0x00; @@ -526,6 +543,7 @@ static bool test_heap_legal_strnlen(FAR struct mm_heap_s *heap, size_t size) static bool test_heap_legal_strrchr(FAR struct mm_heap_s *heap, size_t size) { FAR char *mem = mm_malloc(heap, size); + size = mm_malloc_size(heap, mem); mem[size - 1] = 0; diff --git a/testing/mm/memstress/memorystress_main.c b/testing/mm/memstress/memorystress_main.c index f3952e08d..59ceae7c4 100644 --- a/testing/mm/memstress/memorystress_main.c +++ b/testing/mm/memstress/memorystress_main.c @@ -141,6 +141,7 @@ static void show_usage(FAR const char *progname) static uint32_t randnum(uint32_t max, FAR uint32_t *seed) { uint32_t x = *seed; + x ^= x << 13; x ^= x >> 17; x ^= x << 5; @@ -338,6 +339,7 @@ static bool memorystress_iter(FAR struct memorystress_thread_context_s static FAR void *debug_malloc(size_t size) { void *ptr = malloc(size); + syslog(LOG_INFO, MEMSTRESS_PREFIX "malloc: %zu bytes, ptr = %p\n", size, ptr); return ptr; @@ -360,6 +362,7 @@ static void debug_free(FAR void *ptr) static FAR void *debug_aligned_alloc(size_t align, size_t nbytes) { void *ptr = memalign(align, nbytes); + syslog(LOG_INFO, MEMSTRESS_PREFIX "aligned_alloc: %zu bytes, align: %zu," " ptr: %p\n", nbytes, align, ptr); return ptr; @@ -420,36 +423,36 @@ static void global_init(FAR struct memorystress_global_s *global, int argc, } } - if (global->debug) - { - global->func.malloc = debug_malloc; - global->func.aligned_alloc = debug_aligned_alloc; - global->func.realloc = debug_realloc; - global->func.freefunc = debug_free; - } - else - { - global->func.malloc = malloc; - global->func.aligned_alloc = aligned_alloc; - global->func.realloc = realloc; - global->func.freefunc = free; - } - - global->threads = (FAR pthread_t *)malloc(sizeof(pthread_t) * - global->nthreads); - if (global->threads == NULL) - { - syslog(LOG_ERR, MEMSTRESS_PREFIX "Malloc threads Failed\n"); - exit(EXIT_FAILURE); - } - - syslog(LOG_INFO, MEMSTRESS_PREFIX "\n max_allocsize: %zu\n" - " nodelen: %zu\n sleep_us: %" PRIu32 "\n nthreads: %zu\n " - "debug: %s\n", - global->max_allocsize, global->nodelen, global->sleep_us, - global->nthreads, global->debug ? "true" : "false"); - - srand(time(NULL)); + if (global->debug) + { + global->func.malloc = debug_malloc; + global->func.aligned_alloc = debug_aligned_alloc; + global->func.realloc = debug_realloc; + global->func.freefunc = debug_free; + } + else + { + global->func.malloc = malloc; + global->func.aligned_alloc = aligned_alloc; + global->func.realloc = realloc; + global->func.freefunc = free; + } + + global->threads = (FAR pthread_t *)malloc(sizeof(pthread_t) * + global->nthreads); + if (global->threads == NULL) + { + syslog(LOG_ERR, MEMSTRESS_PREFIX "Malloc threads Failed\n"); + exit(EXIT_FAILURE); + } + + syslog(LOG_INFO, MEMSTRESS_PREFIX "\n max_allocsize: %zu\n" + " nodelen: %zu\n sleep_us: %" PRIu32 "\n nthreads: %zu\n " + "debug: %s\n", + global->max_allocsize, global->nodelen, global->sleep_us, + global->nthreads, global->debug ? "true" : "false"); + + srand(time(NULL)); } /**************************************************************************** diff --git a/testing/testsuites/kernel/mm/cases/mm_test_007.c b/testing/testsuites/kernel/mm/cases/mm_test_007.c index decbdec52..b6291693b 100644 --- a/testing/testsuites/kernel/mm/cases/mm_test_007.c +++ b/testing/testsuites/kernel/mm/cases/mm_test_007.c @@ -71,6 +71,7 @@ void test_nuttx_mm07(FAR void **state) struct mallinfo test_during_info; struct mallinfo test_after_info; struct mallinfo mem_info; + memset(&mem_info, 0, sizeof(mem_info)); for (int i = 0; i < MEMORY_LIST_LENGTH; i++) { @@ -145,7 +146,9 @@ void test_nuttx_mm07(FAR void **state) for (int l = 0; l < MEMORY_LIST_LENGTH; l++) { if (mem_list[l] != NULL) - free(mem_list[l]); + { + free(mem_list[l]); + } } test_after_info = mallinfo();
