diff --git a/testsuites/Kconfig b/testsuites/Kconfig index f718b93..6bbc0d9 100644 --- a/testsuites/Kconfig +++ b/testsuites/Kconfig @@ -24,11 +24,6 @@ config TESTS_TESTSUITES_STACKSIZE int "Testsuites stack size" default 16384 -config CM_FS_TEST - bool "enable fs test" - default n - depends on TESTS_TESTSUITES - config CM_SCHED_TEST bool "enbale schedule test" default n @@ -39,11 +34,6 @@ config CM_SYSCALL_TEST default n depends on TESTS_TESTSUITES -config CM_MM_TEST - bool "enbale MM test" - default n - depends on TESTS_TESTSUITES - config CM_KVDB_TEST bool "enbale kvdb test" default n @@ -54,11 +44,6 @@ config CM_TIME_TEST default n depends on TESTS_TESTSUITES -config CM_SOCKET_TEST - bool "enbale socket test" - default n - depends on TESTS_TESTSUITES - config CM_PTHREAD_TEST bool "enbale pthread test" default n @@ -83,6 +68,6 @@ endif config CM_DFX_TEST bool "enbale dfx test" default n - depends on TESTS_TESTSUITES + depends on NETUTILS_CJSON && DFX && DFX_EVENT endif # TESTS_TESTSUITES diff --git a/testsuites/Makefile b/testsuites/Makefile index 0b8adf8..cb5f0f1 100644 --- a/testsuites/Makefile +++ b/testsuites/Makefile @@ -22,15 +22,6 @@ MODULE = $(CONFIG_TESTS_TESTSUITES) # treat all warning as error CFLAGS += -Werror -ifneq ($(CONFIG_CM_FS_TEST),) -CFLAGS += -I$(CURDIR)/kernel/fs/include -CFLAGS += -I$(APPDIR)/nshlib -CSRCS += $(wildcard kernel/fs/cases/*.c) -CSRCS += $(wildcard kernel/fs/common/*.c) -PROGNAME += cmocka_fs_test -MAINSRC += $(CURDIR)/kernel/fs/cmocka_fs_test.c -endif - ifneq ($(CONFIG_CM_SCHED_TEST),) CFLAGS += -I$(CURDIR)/kernel/sched/include CSRCS += $(wildcard kernel/sched/cases/*.c) @@ -48,18 +39,6 @@ PROGNAME += cmocka_syscall_test MAINSRC += $(CURDIR)/kernel/syscall/cmocka_syscall_test.c endif -ifneq ($(CONFIG_CM_MM_TEST),) -CFLAGS += -I$(CURDIR)/kernel/mm/include -CSRCS += $(wildcard kernel/mm/cases/*.c) -CSRCS += $(wildcard kernel/mm/common/*.c) -PROGNAME += cmocka_mm_test -MAINSRC += $(CURDIR)/kernel/mm/cmocka_mm_test.c -PROGNAME += mem_batch_opt_perf_test -MAINSRC += $(CURDIR)/kernel/mm/tool/mem_batch_opt_perf_test.c -PROGNAME += mem_cycle_opt_perf_test -MAINSRC += $(CURDIR)/kernel/mm/tool/mem_cycle_opt_perf_test.c -endif - ifneq ($(CONFIG_CM_KVDB_TEST),) CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/kvdb CFLAGS += -I$(CURDIR)/kernel/kv/include @@ -76,13 +55,6 @@ PROGNAME += cmocka_time_test MAINSRC += $(CURDIR)/kernel/time/cmocka_time_test.c endif -ifneq ($(CONFIG_CM_SOCKET_TEST),) -CFLAGS += -I$(CURDIR)/kernel/socket/include -CSRCS += $(wildcard kernel/socket/cases/*.c) -PROGNAME += cmocka_socket_test -MAINSRC += $(CURDIR)/kernel/socket/cmocka_socket_test.c -endif - ifneq ($(CONFIG_CM_PTHREAD_TEST),) CFLAGS += -I$(CURDIR)/kernel/pthread/include CSRCS += $(wildcard kernel/pthread/cases/*.c) diff --git a/testsuites/kernel/dfx/cases/dfx_test_event.c b/testsuites/kernel/dfx/cases/dfx_test_event.c new file mode 100644 index 0000000..919131a --- /dev/null +++ b/testsuites/kernel/dfx/cases/dfx_test_event.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/dfx/cases/dfx_test_event.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "dfx_debug.h" +#include "dfx_event.h" +#include +#include +#include +#include +#include +#include + +#define sendeventmisight(eventId, eventStr) sendEventMisight(eventId, eventStr) +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void dfx_test_send_event(FAR void **state) +{ + (void)state; + int ret; + const char *dns_error = "{\"ErrorDesc\":\"Cannot found server\"}"; + ret = sendeventmisight(916012001, dns_error); + assert_int_equal(ret, DFX_OK); +} + +void dfx_test_send_syslog(FAR void **state) +{ + (void)state; + int ret; + const char *action = "{\"logger_action\":\"syslog\"}"; + ret = sendeventmisight(901009001, action); + assert_int_equal(ret, DFX_OK); +} diff --git a/testsuites/kernel/dfx/cmocka_dfx_test.c b/testsuites/kernel/dfx/cmocka_dfx_test.c new file mode 100644 index 0000000..99fcddb --- /dev/null +++ b/testsuites/kernel/dfx/cmocka_dfx_test.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/dfx/cmocka_dfx_test.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include "DFXTest.h" +#include + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: cmocka_sched_test_main + ****************************************************************************/ + +int main(int argc, char *argv[]) +{ + /* Add Test Cases */ + + const struct CMUnitTest dfx_test_suites[] = + { + cmocka_unit_test(dfx_test_send_event), + cmocka_unit_test(dfx_test_send_syslog), + }; + + /* Run Test cases */ + + cmocka_run_group_tests(dfx_test_suites, NULL, NULL); + return 0; +} diff --git a/testsuites/kernel/dfx/include/DFXTest.h b/testsuites/kernel/dfx/include/DFXTest.h new file mode 100644 index 0000000..3373ccf --- /dev/null +++ b/testsuites/kernel/dfx/include/DFXTest.h @@ -0,0 +1,47 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/dfx/include/DFXTest.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ +#ifndef __DFX_TEST_H +#define __DFX_TEST_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +void dfx_test_send_event(FAR void **state); +void dfx_test_send_syslog(FAR void **state); +#endif diff --git a/testsuites/kernel/fs/cases/fs_append_test.c b/testsuites/kernel/fs/cases/fs_append_test.c deleted file mode 100644 index 0d92ab0..0000000 --- a/testsuites/kernel/fs/cases/fs_append_test.c +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -#define TESTFILENAME "stream01Testfile" - -/**************************************************************************** - * Name: stream - * Example description: - 1. open a file with "a+". - 2. Write some strings to the file. - 3. Check if the file pointer is offset. - * Test item: fopen() fseek() ftell() - * Expect results: TEST PASSED - ****************************************************************************/ -void TestNuttxFsAppend01(FAR void **state) -{ - FILE *fd; - int pos; - char readstring[80]; - size_t ret; - fd = fopen(TESTFILENAME, "a+"); - if (fd == NULL) - { - syslog(LOG_ERR, "Unable to open file %s, errno %d\n", TESTFILENAME, errno); - assert_true(1 == 0); - } - fprintf(fd, "This is a test of the append.\n"); - pos = ftell(fd); - if (fseek(fd, 0, SEEK_END) < 0) - { - syslog(LOG_ERR, "fseek fail, errno %d\n", errno); - fclose(fd); - assert_true(1 == 0); - } - if (ftell(fd) != pos) - { - syslog(LOG_ERR, "Error opening for append ... data not at EOF\n"); - fclose(fd); - assert_true(1 == 0); - } - if (fseek(fd, -30, SEEK_END) < 0) - { - syslog(LOG_ERR, "fseek fail, errno %d\n", errno); - fclose(fd); - assert_true(1 == 0); - } - readstring[30] = '\0'; - ret = fread(readstring, 1, 30, fd); - readstring[ret] = 0; - fclose(fd); - if (strcmp(readstring, "This is a test of the append.\n") != 0) - { - syslog(LOG_ERR, "strcmp fail\n"); - assert_true(1 == 0); - } -} diff --git a/testsuites/kernel/fs/cases/fs_creat_test.c b/testsuites/kernel/fs/cases/fs_creat_test.c deleted file mode 100644 index df776d0..0000000 --- a/testsuites/kernel/fs/cases/fs_creat_test.c +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TESTFILENAME "creatTestFile" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsCreat01 - ****************************************************************************/ -void TestNuttxFsCreat01(FAR void **state) -{ - int fd, ret; - char buf[20] = {0}; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - sprintf(test_state->filename, "%s", TESTFILENAME); - - memset(buf, 'A', sizeof(buf)); - - /* creat a test file */ - fd = creat(test_state->filename, 0700); - assert_true(fd > 0); - test_state->fd1 = fd; - - /* do write */ - ret = write(fd, buf, sizeof(buf)); - assert_int_in_range(ret, 1, 20); -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_dup_test.c b/testsuites/kernel/fs/cases/fs_dup_test.c deleted file mode 100644 index 056fa24..0000000 --- a/testsuites/kernel/fs/cases/fs_dup_test.c +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TESTFILENAME "testDupFile" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsDup01 - ****************************************************************************/ -void TestNuttxFsDup01(FAR void **state) -{ - int fd, newfd, rval; - char bufFD[5] = "hello"; - char bufNewFD[8] = "littleFS"; - char readBuf[20] = ""; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - /* open file */ - fd = open(TESTFILENAME, O_RDWR | O_CREAT | O_APPEND, 0700); - assert_true(fd > 0); - test_state->fd1 = fd; - - /* do write */ - assert_int_in_range(write(fd, bufFD, sizeof(bufFD)), 1, sizeof(bufFD)); - - /* refresh to storage */ - assert_int_equal(fsync(fd), 0); - - /* do dup */ - newfd = dup(fd); - close(fd); - assert_int_not_equal(newfd, -1); - test_state->fd2 = newfd; - - /* check if file pos is shared */ - off_t currpos = lseek(newfd, 0, SEEK_CUR); - assert_int_equal(currpos, 5); - - /* write newfd after dup */ - rval = write(newfd, bufNewFD, sizeof(bufNewFD)); - assert_int_in_range(rval, 1, sizeof(bufNewFD)); - - /* refresh to storage */ - assert_int_equal(fsync(newfd), 0); - - /* reset file pos use newfd */ - off_t ret = lseek(newfd, 0, SEEK_SET); - assert_int_equal(ret, 0); - - /* do double check */ - rval = read(newfd, readBuf, 20); - assert_int_in_range(rval, 1, 20); - - /* check readBuf*/ - assert_int_equal(strncmp(readBuf, "hellolittleFS", 13), 0); -} diff --git a/testsuites/kernel/fs/cases/fs_eventfd_test.c b/testsuites/kernel/fs/cases/fs_eventfd_test.c deleted file mode 100644 index 664f5b9..0000000 --- a/testsuites/kernel/fs/cases/fs_eventfd_test.c +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: threadFunc - ****************************************************************************/ -__attribute__((unused)) static void *threadFunc(void *args) -{ - eventfd_t Eventfd01_buffer; - int fd = *(int *)args; - for (int i = 1; i < 6; i++) - { - read(fd, &Eventfd01_buffer, sizeof(eventfd_t)); - sleep(1); - } - - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsEventfd - ****************************************************************************/ -void TestNuttxFsEventfd(FAR void **state) -{ -#ifdef CONFIG_EVENT_FD - eventfd_t Eventfd01_buf = 1; - int Eventfd01_ret; - int Eventfd01_efd; - pthread_t Eventfd01_tid; - struct fs_testsuites_state_s *test_state; - test_state = (struct fs_testsuites_state_s *)*state; - - Eventfd01_efd = eventfd(0, 0); - assert_int_not_equal(Eventfd01_efd,-1); - test_state->fd1=Eventfd01_efd; - assert_true(pthread_create(&Eventfd01_tid, NULL, threadFunc, &Eventfd01_efd)>=0); - - for (int i = 1; i < 5; i++) - { - Eventfd01_ret = write(Eventfd01_efd, &Eventfd01_buf, sizeof(eventfd_t)); - assert_int_equal(Eventfd01_ret,sizeof(eventfd_t)); - Eventfd01_buf++; - sleep(1); - } - sleep(2); -#endif -} diff --git a/testsuites/kernel/fs/cases/fs_fcntl_test.c b/testsuites/kernel/fs/cases/fs_fcntl_test.c deleted file mode 100644 index 26584f4..0000000 --- a/testsuites/kernel/fs/cases/fs_fcntl_test.c +++ /dev/null @@ -1,184 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define BUFSIZE 512 -#define TEST_FILE_1 "fcntl01_testfile" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsFcntl01 - ****************************************************************************/ - -void TestNuttxFsFcntl01(FAR void **state) -{ - char *buf = NULL; - int oldfd, newfd, ret; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* open file */ - oldfd = open(TEST_FILE_1, O_CREAT | O_RDWR, 0700); - assert_true(oldfd > 0); - test_state->fd1 = oldfd; - - /* do fcntl */ - newfd = fcntl(oldfd, F_DUPFD, 0); - assert_true(newfd > 0); - test_state->fd2 = newfd; - - /* malloc memory */ - buf = (char *)malloc(BUFSIZ); - assert_non_null(buf); - test_state->ptr = buf; - - /* set memory */ - memset(buf, 'A', BUFSIZ); - - /* do write */ - ret = write(newfd, buf, BUFSIZ); - assert_int_in_range(ret, 1, BUFSIZ); -} - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TEST_FILE_2 "fcntl02_testfile" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsFcntl02 - ****************************************************************************/ -void TestNuttxFsFcntl02(FAR void **state) -{ - int fd, ret, v; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* open file */ - fd = open(TEST_FILE_2, O_RDWR | O_CREAT, 0700); - assert_true(fd > 0); - - /* do fcntl */ - v = fcntl(fd, F_GETFD); - assert_int_in_range(v, 0, 255); - test_state->fd1 = fd; - - v |= FD_CLOEXEC; - - /* do fcntl */ - ret = fcntl(fd, F_SETFD, v); - assert_int_in_range(ret, 0, 255); - test_state->fd2 = ret; - ret = (v == fcntl(fd, F_GETFD) ? 1 : 0); - assert_int_equal(ret, 1); -} - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: FsFcntlSetLileStatus - ****************************************************************************/ -static int FsFcntlSetLileStatus(int mode, int fd) -{ - int flags, ret; - flags = fcntl(fd, F_GETFL); - if (flags == -1) - { - syslog(LOG_ERR, "get file status fail !\n"); - return -1; - } - - flags |= mode; - ret = fcntl(fd, F_SETFL, flags); - if (ret < 0) - { - syslog(LOG_ERR, "set file status fail !\n"); - } - - return 0; -} - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TEST_FILE_3 "fcntl03_testfile_1" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsFcntl03 - ****************************************************************************/ -void TestNuttxFsFcntl03(FAR void **state) -{ - int fd; - int ret, size, ret2; - char path[32] = {0}; - char buf[10] = {0}; - getcwd(path, sizeof(path)); - - /* open file */ - fd = open(TEST_FILE_3, O_RDWR | O_CREAT, 0777); - assert_true(fd > 0); - - /* set memory */ - memset(buf, 'A', 10); - - /* do write */ - ret2 = write(fd, buf, 10); - assert_int_in_range(ret2, 1, 10); - - /* close file */ - assert_int_equal(close(fd), 0); - - sleep(1); - - /* open the file again */ - fd = open(TEST_FILE_3, O_RDWR | O_CREAT, 0777); - assert_true(fd > 0); - - /* F_SETFL */ - ret = FsFcntlSetLileStatus(O_APPEND, fd); - assert_int_equal(ret, 0); - - /* set memory */ - memset(buf, 'B', 10); - - /* do write */ - ret2 = write(fd, buf, 10); - assert_int_in_range(ret2, 1, 10); - - /* get fd size */ - size = lseek(fd, 0, SEEK_END); - - /* close file */ - close(fd); - - /*check size*/ - assert_int_equal(size, 20); -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_fstat_test.c b/testsuites/kernel/fs/cases/fs_fstat_test.c deleted file mode 100644 index fc53592..0000000 --- a/testsuites/kernel/fs/cases/fs_fstat_test.c +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TEST_FILE_1 "fstat_test_file1" -#define TEST_FILE_2 "fstat_test_file2" -#define BUF_SIZE 512 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsFstat01 - ****************************************************************************/ -void TestNuttxFsFstat01(FAR void **state) -{ - struct stat file_s; - int fd, ret; - char *buf; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* open file */ - fd = open(TEST_FILE_1, O_RDWR | O_CREAT, 0777); - assert_true(fd > 0); - test_state->fd1 = fd; - - /* malloc memory */ - buf = malloc(BUF_SIZE); - assert_non_null(buf); - test_state->ptr = buf; - - /* set memory */ - memset(buf, 'A', BUF_SIZE); - - /* get the file size before write */ - ret = fstat(fd, &file_s); - assert_int_equal(ret, 0); - - /* do write */ - ret = write(fd, buf, BUF_SIZE); - assert_int_in_range(ret, 1, BUF_SIZE); - - /* get file size again */ - ret = fstat(fd, &file_s); - assert_int_equal(ret, 0); - - /* check file_s.st_size */ - ret = (file_s.st_size == BUF_SIZE) ? 1 : 0; - assert_int_equal(ret, 1); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsFstat02 - ****************************************************************************/ -void TestNuttxFsFstat02(FAR void **state) -{ - int fd, ret; - struct stat file_s; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* open file */ - fd = open(TEST_FILE_2, O_RDWR | O_CREAT, 0777); - assert_true(fd > 0); - test_state->fd1 = fd; - - /* get the file size before write */ - ret = fstat(fd, &file_s); - assert_int_equal(ret, 0); - - /* close file*/ - assert_int_equal(close(fd), 0); - -// #if defined(CONFIG_NET) -// /* creat socket */ -// fd = socket(AF_INET, SOCK_STREAM, 0); -// assert_int_not_equal(fd, -1); - -// /* get file size again */ -// ret = fstat(fd, &file_s); -// assert_int_equal(ret, 0); - -// assert_true(S_ISSOCK(file_s.st_mode)); -// assert_int_equal(close(fd), 0); -// #endif - -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_fstatfs_test.c b/testsuites/kernel/fs/cases/fs_fstatfs_test.c deleted file mode 100644 index a0f85a4..0000000 --- a/testsuites/kernel/fs/cases/fs_fstatfs_test.c +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TEST_FILE "fstat_test_file" -#define BUF_SIZE 512 - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsPrintStatfs - ****************************************************************************/ -__attribute__((unused)) static void TestNuttxFsPrintStatfs(struct statfs *buf) -{ - syslog(LOG_INFO, "statfs buffer:\n"); - syslog(LOG_INFO, " f_type: %lu\n", (unsigned long)buf->f_type); - syslog(LOG_INFO, " f_namelen: %lu\n", (unsigned long)buf->f_namelen); - syslog(LOG_INFO, " f_bsize: %lu\n", (unsigned long)buf->f_bsize); - syslog(LOG_INFO, " f_blocks: %llu\n", (unsigned long long)buf->f_blocks); - syslog(LOG_INFO, " f_bfree: %llu\n", (unsigned long long)buf->f_bfree); - syslog(LOG_INFO, " f_bavail: %llu\n", (unsigned long long)buf->f_bavail); - syslog(LOG_INFO, " f_files: %llu\n", (unsigned long long)buf->f_files); - syslog(LOG_INFO, " f_ffree: %llu\n", (unsigned long long)buf->f_ffree); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsFstatfs01 - ****************************************************************************/ - -void TestNuttxFsFstatfs01(FAR void **state) -{ - struct statfs statfsbuf; - int ret, fd; - char *buf; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* malloc memory */ - buf = malloc(BUF_SIZE); - assert_non_null(buf); - test_state->ptr = buf; - - /* set memory */ - memset(buf, 'B', BUF_SIZE); - - /* open file */ - fd = open(TEST_FILE, O_RDWR | O_CREAT, 0777); - assert_true(fd > 0); - test_state->fd1 = fd; - - /* call fstatfs() */ - ret = fstatfs(fd, &statfsbuf); - assert_int_equal(ret, 0); -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_fsync_test.c b/testsuites/kernel/fs/cases/fs_fsync_test.c deleted file mode 100644 index 4c02f6d..0000000 --- a/testsuites/kernel/fs/cases/fs_fsync_test.c +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TESTFILE "FsyncTestFile" -#define BUF "testData123#$%*-=/ sdafasd37575sasdfasdf356345634563456ADSFASDFASDFQWREdf4as5df4as5dfsd ###" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsFsync01 - ****************************************************************************/ - -void TestNuttxFsFsync01(FAR void **state) -{ - // clock_t start, finish; - int fd, rval, ret; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* open file */ - fd = open(TESTFILE, O_RDWR | O_CREAT, 0700); - assert_true(fd > 0); - test_state->fd1 = fd; - - for (int i = 0; i < 20; i++) - { - /* do write */ - rval = write(fd, BUF, sizeof(BUF)); - assert_int_equal(rval, sizeof(BUF)); - - /* refresh to storage */ - ret = fsync(fd); - assert_int_equal(ret, 0); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsFsync02 - ****************************************************************************/ - -void TestNuttxFsFsync02(FAR void **state) -{ - int fd, ret; - char *buf = NULL; - int bufsize = 4096; - ssize_t writen = 0; - struct statfs statfsbuf; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* delete test file */ - unlink(TESTFILE); - - /* open file */ - fd = open(TESTFILE, O_CREAT | O_RDWR, 0777); - assert_true(fd > 0); - test_state->fd1 = fd; - - /* call fstatfs() */ - ret = fstatfs(fd, &statfsbuf); - assert_int_equal(ret, 0); - - bufsize = statfsbuf.f_bsize; - - syslog(LOG_INFO, "the bsize = %d\n", statfsbuf.f_bsize); - - /* malloc memory */ - buf = malloc(bufsize * sizeof(char)); - assert_non_null(buf); - test_state->ptr = buf; - - /* set memory */ - memset(buf, 0x66, bufsize); - - /* do write */ - writen = write(fd, buf, bufsize); - assert_int_in_range(writen, 1, bufsize); - - /* refresh to storage */ - fsync(fd); - - /* call fstatfs() */ - ret = fstatfs(fd, &statfsbuf); - assert_int_equal(ret, 0); -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_getfilep_test.c b/testsuites/kernel/fs/cases/fs_getfilep_test.c deleted file mode 100644 index 4ae23ab..0000000 --- a/testsuites/kernel/fs/cases/fs_getfilep_test.c +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TEST_FILE "fstat_test_file" -#define BUF_SIZE 512 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsGetfilep01 - ****************************************************************************/ - -void TestNuttxFsGetfilep01(FAR void **state) -{ - FAR struct file *filep; - int ret, fd; - char *buf = NULL; - FILE *fp; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* create a file for testing */ - fd = creat(TEST_FILE, 0700); - assert_true(fd > 0); - test_state->fd1 = fd; - - /* fdopen file */ - fp = fdopen(fd, "r+"); - assert_non_null(fp); - - /* get struct file */ - ret = fs_getfilep(fileno(fp), &filep); - assert_int_equal(ret, 0); - - /* malloc memory */ - buf = malloc(BUF_SIZE); - assert_non_null(buf); - test_state->ptr = buf; - - /* set memory */ - memset(buf, 'A', BUF_SIZE); - - /* do write*/ - ret = write(fileno(fp), buf, BUF_SIZE); - assert_int_equal(ret, BUF_SIZE); - - /* do fflush */ - fflush(fp); - - /* do fsync */ - fsync(fileno(fp)); - - /* put filep */ - fs_putfilep(filep); - - /* get struct file again*/ - ret = fs_getfilep(fileno(fp), &filep); - assert_int_equal(ret, 0); - - assert_int_equal(filep->f_pos, BUF_SIZE); - - test_state->fd2 = fileno(fp); - - /* put filep */ - fs_putfilep(filep); - - assert_int_equal(fclose(fp), 0); -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_mkdir_test.c b/testsuites/kernel/fs/cases/fs_mkdir_test.c deleted file mode 100644 index ac03fb0..0000000 --- a/testsuites/kernel/fs/cases/fs_mkdir_test.c +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsMkdir01 - ****************************************************************************/ - -void TestNuttxFsMkdir01(FAR void **state) -{ - int status; - - /* do mkdir */ - status = mkdir("testdir1", 0700); - assert_int_equal(status, 0); - - /* do rmdir */ - assert_int_equal(rmdir("testdir1"), 0); - - /* do mkdir */ - status = mkdir("234123412341234", 0700); - assert_int_equal(status, 0); - - /* do rmdir */ - assert_int_equal(rmdir("234123412341234"), 0); - - /* do mkdir */ - status = mkdir("asdfasdfASDFASDF", 0700); - assert_int_equal(status, 0); - - /* do rmdir */ - assert_int_equal(rmdir("asdfasdfASDFASDF"), 0); - - /* do mkdir */ - status = mkdir("ASDFASD@%#%54365465654#@%#%@#", 0700); - assert_int_equal(status, 0); - - /* do rmdir */ - assert_int_equal(rmdir("ASDFASD@%#%54365465654#@%#%@#"), 0); -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_open_test.c b/testsuites/kernel/fs/cases/fs_open_test.c deleted file mode 100644 index 20b3a6c..0000000 --- a/testsuites/kernel/fs/cases/fs_open_test.c +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TESTFILE "testOpenFile" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsOpen01 - ****************************************************************************/ - -void TestNuttxFsOpen01(FAR void **state) -{ - int fd, ret; - char s[] = "test data!", buffer[50] = {0}; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* open file */ - fd = open(TESTFILE, O_WRONLY | O_CREAT, 0700); - assert_true(fd > 0); - - /* do write */ - int ret2 = write(fd, s, sizeof(s)); - close(fd); - assert_int_in_range(ret2, 1, sizeof(s)); - - /* open file*/ - fd = open(TESTFILE, O_RDONLY); - assert_true(fd > 0); - test_state->fd1 = fd; - - /* do read*/ - ret = read(fd, buffer, sizeof(buffer)); - assert_true(ret > 0); -} diff --git a/testsuites/kernel/fs/cases/fs_opendir_test.c b/testsuites/kernel/fs/cases/fs_opendir_test.c deleted file mode 100644 index ea5e920..0000000 --- a/testsuites/kernel/fs/cases/fs_opendir_test.c +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsOpendir01 - ****************************************************************************/ -void TestNuttxFsOpendir01(FAR void **state) -{ - DIR *dir; - struct dirent *ptr; - int ret; - - ret = mkdir("testopendir1", 0777); - assert_int_equal(ret, 0); - - ret = mkdir("testopendir1/dir123", 0777); - assert_int_equal(ret, 0); - - /* do opendir */ - dir = opendir("testopendir1"); - assert_non_null(dir); - - while ((ptr = readdir(dir)) != NULL) - { - if (strncmp(ptr->d_name, ".", 1) == 0) - continue; - if (strncmp(ptr->d_name, "..", 2) == 0) - continue; - if (strncmp(ptr->d_name, "dir123", 6) != 0) - { - closedir(dir); - assert_true(0); - } - } - - /* close dir*/ - assert_int_equal(closedir(dir), 0); -} - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TEST_NUM 1000 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsOpendir02 - ****************************************************************************/ -void TestNuttxFsOpendir02(FAR void **state) -{ - int ret; - DIR *dir; - struct dirent *ptr; - - /* mkdir for test */ - ret = mkdir("testopendir2", 0777); - assert_int_equal(ret, 0); - - /* mkdir for test */ - ret = mkdir("testopendir2/dir_test2", 0777); - assert_int_equal(ret, 0); - - for (int i = 0; i < TEST_NUM; i++) - { - /* open fir for test */ - dir = opendir("testopendir2"); - assert_true(dir != NULL); - while ((ptr = readdir(dir)) != NULL) - { - if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0) - { - continue; - } - else if (strcmp(ptr->d_name, "dir_test2") == 0) - { - break; - } - } - /*close dir*/ - assert_int_equal(closedir(dir), 0); - } -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_poll_test.c b/testsuites/kernel/fs/cases/fs_poll_test.c deleted file mode 100644 index dce96d2..0000000 --- a/testsuites/kernel/fs/cases/fs_poll_test.c +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define I_FILE1 "poll_test1" -#define I_FILE2 "poll_test2" -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsPoll01 - ****************************************************************************/ -void TestNuttxFsPoll01(FAR void **state) -{ - int Poll01_fd1, Poll01_fd2, Poll01_ret; - struct pollfd Poll01_fds[5]; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - Poll01_fd1 = open(I_FILE1, O_RDONLY | O_CREAT); - assert_true(Poll01_fd1>=0); - test_state->fd1=Poll01_fd1; - - Poll01_fds[0].fd = Poll01_fd1; - Poll01_fds[0].events = POLLOUT; - - Poll01_fd2 = open(I_FILE2, O_RDWR | O_CREAT); - assert_true(Poll01_fd2>=0); - test_state->fd2=Poll01_fd2; - - Poll01_fds[1].fd = Poll01_fd2; - Poll01_fds[1].events = POLLIN; - - Poll01_ret = poll(Poll01_fds, 2, 5); - assert_int_equal(Poll01_ret,2); - - close(Poll01_fd1); - close(Poll01_fd2); -} diff --git a/testsuites/kernel/fs/cases/fs_pread_test.c b/testsuites/kernel/fs/cases/fs_pread_test.c deleted file mode 100644 index 2971d37..0000000 --- a/testsuites/kernel/fs/cases/fs_pread_test.c +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TEST_FILE "pread_file" -#define BUF_SIZE 4 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsPread01 - ****************************************************************************/ - -void TestNuttxFsPread01(FAR void **state) -{ - int fd; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* malloc memory */ - char *buf = malloc(BUF_SIZE * sizeof(char)); - assert_non_null(buf); - test_state->ptr = buf; - - /* open file */ - fd = open(TEST_FILE, O_RDWR | O_CREAT, 0777); - assert_int_not_equal(fd, -1); - test_state->fd1 = fd; - - /* do write */ - int ret = write(fd, "ABCD", BUF_SIZE); - assert_int_in_range(ret, 1, 4); - - /* reset file pos use fd */ - lseek(fd, 0, SEEK_SET); - - /* set memory */ - memset(buf, '\0', BUF_SIZE); - - /* do pread */ - pread(fd, buf, 2, 2); - - assert_int_equal(strncmp(buf, "CD", 2), 0); - - /* set memory */ - memset(buf, '\0', BUF_SIZE); - - /* the pread do not change file pointer */ - pread(fd, buf, 3, 1); - assert_int_equal(strncmp(buf, "BCD", 3), 0); -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_pwrite_test.c b/testsuites/kernel/fs/cases/fs_pwrite_test.c deleted file mode 100644 index 888c889..0000000 --- a/testsuites/kernel/fs/cases/fs_pwrite_test.c +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TEST_FILE "pwrite_file" -#define BUF_SIZE 4 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsPwrite01 - ****************************************************************************/ -void TestNuttxFsPwrite01(FAR void **state) -{ - int fd; - char *buf; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* open file */ - fd = open(TEST_FILE, O_RDWR | O_CREAT, 0777); - assert_true(fd > 0); - test_state->fd1 = fd; - - /* malloc memory*/ - buf = malloc(BUF_SIZE * sizeof(char)); - assert_non_null(buf); - test_state->ptr = buf; - - /* set memory */ - memset(buf, 'A', BUF_SIZE); - - /* do write */ - int ret = write(fd, buf, BUF_SIZE); - assert_int_in_range(ret, 1, BUF_SIZE); - - /* reset file pos use fd */ - lseek(fd, 0, SEEK_SET); - - /* set memory */ - memset(buf, 'B', BUF_SIZE); - - /* do pwrite */ - pwrite(fd, buf, BUF_SIZE >> 1, 0); - - /* set memory */ - memset(buf, 'C', BUF_SIZE); - - /* do pwrite */ - pwrite(fd, buf, BUF_SIZE >> 2, 0); - - /* do read */ - assert_int_in_range(read(fd, buf, BUF_SIZE), 1, BUF_SIZE); - - /* check buf*/ - assert_true(strncmp(buf, "CBAA", BUF_SIZE) == 0); -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_read_test.c b/testsuites/kernel/fs/cases/fs_read_test.c deleted file mode 100644 index f76cfd0..0000000 --- a/testsuites/kernel/fs/cases/fs_read_test.c +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TESTFILE "testRead01File1" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsRead01 - ****************************************************************************/ -void TestNuttxFsRead01(FAR void **state) -{ - int fd, size; - char s[] = "Test!", buffer[80]; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - fd = open(TESTFILE, O_WRONLY | O_CREAT, 0777); - assert_true(fd > 0); - test_state->fd1 = fd; - - size = write(fd, s, sizeof(s)); - assert_int_equal(size, sizeof(s)); - - close(fd); - fd = open(TESTFILE, O_RDONLY, 0777); - assert_true(fd > 0); - test_state->fd1 = fd; - size = read(fd, buffer, sizeof(buffer)); - assert_int_equal(size, sizeof(s)); -} diff --git a/testsuites/kernel/fs/cases/fs_readdir_test.c b/testsuites/kernel/fs/cases/fs_readdir_test.c deleted file mode 100644 index 00158b9..0000000 --- a/testsuites/kernel/fs/cases/fs_readdir_test.c +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsReaddir01 - ****************************************************************************/ -void TestNuttxFsReaddir01(FAR void **state) -{ - int fd, ret; - char buf[20] = {0}; - char *filename[] = { - "testFile1", - "testFile2", - "testFile3", - "testFile4", - "testFile5", - "testFile6", - "testFile7"}; - DIR *test_dir; - struct dirent *dptr; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - for (int i = 0; i < 6; i++) - { - /* open file */ - fd = open(filename[i], O_RDWR | O_CREAT, 0700); - assert_true(fd > 0); - test_state->fd1 = fd; - /* do wirte */ - ret = write(fd, "hello!\n", 6); - assert_uint_in_range(ret, 1, 6); - - close(fd); - } - - /* do getcwd */ - getcwd(buf, sizeof(buf)); - - /* open directory */ - test_dir = opendir(buf); - assert_non_null(test_dir); - - while ((dptr = readdir(test_dir)) != 0) - { - if (strcmp(dptr->d_name, ".") && strcmp(dptr->d_name, "..")) - continue; - } - - /* close dir */ - assert_int_equal(closedir(test_dir), 0); -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_readlink_test.c b/testsuites/kernel/fs/cases/fs_readlink_test.c deleted file mode 100644 index ab9068c..0000000 --- a/testsuites/kernel/fs/cases/fs_readlink_test.c +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TEST_FILE "readlink_test_file" -#define PATH_MAX_SIZE 64 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsReadlink01 - ****************************************************************************/ -void TestNuttxFsReadlink01(FAR void **state) -{ - int ret, fd; - - /* test symlink */ - char path[PATH_MAX_SIZE] = {0}; - char buf[PATH_MAX_SIZE] = {0}; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* creat file */ - fd = creat(TEST_FILE, 0700); - assert_true(fd > 0); - test_state->fd1 = fd; - - getcwd(path, sizeof(path)); - strcat(path, "/"); - strcat(path, TEST_FILE); - - /* creating a soft connection */ - ret = symlink(path, "/file_link"); - assert_int_equal(ret, 0); - - /* read link */ - ret = readlink("/file_link", buf, PATH_MAX_SIZE); - assert_true(ret == strlen(path)); - - /* delete test file */ - assert_int_equal(unlink("/file_link"), 0); -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_rename_test.c b/testsuites/kernel/fs/cases/fs_rename_test.c deleted file mode 100644 index 984479c..0000000 --- a/testsuites/kernel/fs/cases/fs_rename_test.c +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsRename01 - ****************************************************************************/ -void TestNuttxFsRename01(FAR void **state) -{ - int fd, status, ret; - char buffer[50]; - char filename1[] = "testRenameFile1"; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* open file */ - fd = open(filename1, O_WRONLY | O_CREAT, 0700); - assert_true(fd > 0); - test_state->fd1 = fd; - - /* set memory */ - memset(buffer, '*', 50); - - /* do write */ - ret = write(fd, buffer, 50); - assert_int_in_range(ret, 1, 50); - - /* do rename */ - status = rename(filename1, "newNameFile1"); - assert_int_equal(status, 0); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsRename02 - ****************************************************************************/ -void TestNuttxFsRename02(FAR void **state) -{ - int status; - - /* make directory */ - status = mkdir("testdir1", 0700); - assert_int_equal(status, 0); - - /* rename directory */ - status = rename("testdir1", "newtestdir1"); - assert_int_equal(status, 0); -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_rewinddir_test.c b/testsuites/kernel/fs/cases/fs_rewinddir_test.c deleted file mode 100644 index f434293..0000000 --- a/testsuites/kernel/fs/cases/fs_rewinddir_test.c +++ /dev/null @@ -1,158 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TEST_PARENT_DIR "parent_dir" -#define TEST_CHILD_DIR1 "parent_dir/child_dir1" -#define TEST_CHILD_DIR2 "parent_dir/child_dir2" -#define TEST_CHILD_DIR3 "parent_dir/child_dir3" -#define TEST_CHILD_DIR4 "parent_dir/child_dir4" -#define TEST_CHILD_DIR5 "parent_dir/child_dir5" - -#define TEST_CHILD_FILE1 "parent_dir/child_file1" -#define TEST_CHILD_FILE2 "parent_dir/child_file2" -#define TEST_CHILD_FILE3 "parent_dir/child_file3" - -#define WRITE_BUF_SIZE 1024 - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsCteatFile - ****************************************************************************/ -static void TestNuttxFsCteatFile(char *filename, size_t write_size) -{ - int fd; - char w_buffer[WRITE_BUF_SIZE] = {0}; - ssize_t size = 0; - - /* open file */ - fd = open(filename, O_CREAT | O_RDWR, 0777); - assert_true(fd > 0); - - /* set memory */ - memset(w_buffer, 0x61, WRITE_BUF_SIZE); - - do - { - if (write_size <= WRITE_BUF_SIZE) - { - /* do write */ - size = write(fd, w_buffer, write_size); - } - else - { - /* do write */ - size = write(fd, w_buffer, WRITE_BUF_SIZE); - } - - write_size = write_size - size; - } while (write_size > (size_t)0); - - /* close file */ - close(fd); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsRewinddir01 - ****************************************************************************/ - -void TestNuttxFsRewinddir01(FAR void **state) -{ - DIR *dir; - struct dirent *ptr; - int count = 0; - int r_count = 0; - int test_flag = -1; - - unsigned long long size; - size = cm_get_partition_available_size(); - if (size == (unsigned long long)-1) - { - fail_msg("Failed to obtain partition information !\n"); - } - /* Stop the test if the available space of the partition is less than 50K */ - if (size < 51200) - { - syslog(LOG_WARNING, "Partitioned free space not enough !\n"); - syslog(LOG_WARNING, "Test case (%s) exits early !\n", __func__); - } - else - { - - /* make directory */ - assert_int_equal(mkdir(TEST_PARENT_DIR, S_IRWXU), 0); - assert_int_equal(mkdir(TEST_CHILD_DIR1, S_IRWXU), 0); - assert_int_equal(mkdir(TEST_CHILD_DIR2, S_IRWXU), 0); - assert_int_equal(mkdir(TEST_CHILD_DIR3, S_IRWXU), 0); - assert_int_equal(mkdir(TEST_CHILD_DIR4, S_IRWXU), 0); - assert_int_equal(mkdir(TEST_CHILD_DIR5, S_IRWXU), 0); - - /* create */ - TestNuttxFsCteatFile(TEST_CHILD_FILE1, 10); - TestNuttxFsCteatFile(TEST_CHILD_FILE2, 10); - TestNuttxFsCteatFile(TEST_CHILD_FILE3, 10); - - /* open directory */ - dir = opendir(TEST_PARENT_DIR); - - while ((ptr = readdir(dir)) != NULL) - { - count++; - } - rewinddir(dir); - - while ((ptr = readdir(dir)) != NULL) - { - r_count++; - } - - /* close directory */ - assert_int_equal(closedir(dir), 0); - - if (count == r_count && count != 0) - { - test_flag = 0; - } - - /* remove directory */ - rmdir(TEST_CHILD_DIR1); - rmdir(TEST_CHILD_DIR2); - rmdir(TEST_CHILD_DIR3); - rmdir(TEST_CHILD_DIR4); - rmdir(TEST_CHILD_DIR5); - - unlink(TEST_CHILD_FILE1); - unlink(TEST_CHILD_FILE2); - unlink(TEST_CHILD_FILE3); - - rmdir(TEST_PARENT_DIR); - - assert_int_equal(test_flag, 0); - } -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_rmdir_test.c b/testsuites/kernel/fs/cases/fs_rmdir_test.c deleted file mode 100644 index e5f8ebc..0000000 --- a/testsuites/kernel/fs/cases/fs_rmdir_test.c +++ /dev/null @@ -1,297 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" -#include "nsh.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define PARENTDIR1 "parentDirName" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsRmdir01 - ****************************************************************************/ -void TestNuttxFsRmdir01(FAR void **state) -{ - int status; - int fd; - char str[5]; - char testFileName[20] = {0}; - char testDirName[20] = {0}; - char absoluteDirectory[100] = {0}; - char currentPath[100] = {0}; - char parentDirectory[PATH_MAX] = {0}; - - unsigned long long size; - size = cm_get_partition_available_size(); - if (size == (unsigned long long)-1) - { - fail_msg("Failed to obtain partition information !\n"); - } - /* Stop the test if the available space of the partition is less than 160K */ - if (size < 163840) - { - syslog(LOG_WARNING, "Partitioned free space not enough !\n"); - syslog(LOG_WARNING, "Test case (%s) exits early !\n", __func__); - } - else - { - /* create directory */ - status = mkdir(PARENTDIR1, 0700); - assert_int_equal(status, 0); - - /* get test path */ - getcwd(currentPath, sizeof(currentPath)); - - strcpy(absoluteDirectory, currentPath); - strcat(currentPath, "/"); - strcat(currentPath, PARENTDIR1); - - strcpy(parentDirectory, currentPath); - - chdir(currentPath); - - /* get test path */ - getcwd(currentPath, sizeof(currentPath)); - - /* create 10 2-level subfolders */ - for (int i = 0; i < 10; i++) - { - itoa(i, str, 10); - status = mkdir(str, 0700); - assert_int_equal(status, 0); - } - - /* switch to directory 5 */ - itoa(5, str, 10); - - /* enter sub-directory */ - strcat(currentPath, "/"); - strcat(currentPath, str); - chdir(currentPath); - - /* get test path */ - getcwd(currentPath, sizeof(currentPath)); - - /* make directory */ - status = mkdir("test_3_dir_1", 0700); - assert_int_equal(status, 0); - - /* make directory */ - status = mkdir("test_3_dir_2", 0700); - assert_int_equal(status, 0); - - /* switch to directory 8 */ - itoa(8, str, 10); - - /* enter sub-directory */ - memset(currentPath, 0, sizeof(currentPath)); - strcpy(currentPath, parentDirectory); - strcat(currentPath, "/"); - strcat(currentPath, str); - chdir(currentPath); - - /* get test path */ - getcwd(currentPath, sizeof(currentPath)); - - for (int j = 1; j <= 10; j++) - { - sprintf(testFileName, "test_3_file_%d", j); - - /* creat a test file */ - fd = creat(testFileName, 0700); - assert_true(fd > 0); - close(fd); - - /* set memory */ - memset(testFileName, 0, sizeof(testFileName)); - } - - /* switch to directory 2 */ - itoa(2, str, 10); - - /* enter sub-directory */ - memset(currentPath, 0, sizeof(currentPath)); - strcpy(currentPath, parentDirectory); - strcat(currentPath, "/"); - strcat(currentPath, str); - chdir(currentPath); - - /* get test path */ - getcwd(currentPath, sizeof(currentPath)); - - for (int k = 1; k <= 5; k++) - { - sprintf(testFileName, "test_3_file_%d", k); - sprintf(testDirName, "test_3_dir_%d", k); - - /* create a test file */ - fd = creat(testFileName, 0700); - assert_true(fd > 0); - close(fd); - /* make directory */ - status = mkdir(testDirName, 0700); - assert_int_equal(status, 0); - - /* set memory */ - memset(testFileName, 0, sizeof(testFileName)); - memset(testDirName, 0, sizeof(testDirName)); - } - - /* wwitch to the test absolute directory */ - chdir(absoluteDirectory); - - /* call the recursive delete interface */ - cm_unlink_recursive(parentDirectory); - } -} - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define PARENTDIR2 "parentDirName2" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsRmdir02 - ****************************************************************************/ -void TestNuttxFsRmdir02(FAR void **state) -{ - int status; - int ret; - char str[20] = {0}; - char absoluteDirectory[20] = {0}; - char parentDirectory[PATH_MAX] = {0}; - char temporaryPath[300] = {0}; - unsigned long long size; - - size = cm_get_partition_available_size(); - if (size == (unsigned long long)-1) - { - fail_msg("Failed to obtain partition information !\n"); - } - /* Stop the test if the available space of the partition is less than 98K */ - if (size < 98304) - { - syslog(LOG_WARNING, "Partitioned free space not enough !\n"); - syslog(LOG_WARNING, "Test case (%s) exits early !\n", __func__); - } - else - { - - getcwd(absoluteDirectory, sizeof(absoluteDirectory)); - - /* create directory */ - status = mkdir(PARENTDIR2, 0700); - assert_int_equal(status, 0); - - strcpy(parentDirectory, absoluteDirectory); - strcat(parentDirectory, "/"); - strcat(parentDirectory, PARENTDIR2); - - /* switch to test PARENTDIR*/ - chdir(parentDirectory); - - /* create a 6-level directory in a loop */ - for (int i = 0; i < 6; i++) - { - /* get current path */ - getcwd(temporaryPath, sizeof(temporaryPath)); - strcat(temporaryPath, "/"); - - /* do snprintf */ - ret = snprintf(str, 20, "test_dir_%d", i); - assert_true(ret > 0); - - strcat(temporaryPath, str); - /* make directory */ - status = mkdir(temporaryPath, 0700); - assert_int_equal(status, 0); - - chdir(temporaryPath); - - /* set memory */ - memset(temporaryPath, 0, sizeof(temporaryPath)); - memset(str, 0, sizeof(str)); - } - - /* wwitch to the test absolute directory */ - chdir(absoluteDirectory); - - /* call the recursive delete interface */ - cm_unlink_recursive(parentDirectory); - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsRmdir03 - ****************************************************************************/ -void TestNuttxFsRmdir03(FAR void **state) -{ - int status; - DIR *dir = NULL; - char str[5]; - char buf[20] = {0}; - struct dirent *ptr; - - unsigned long long size; - size = cm_get_partition_available_size(); - if (size == (unsigned long long)-1) - { - fail_msg("Failed to obtain partition information !\n"); - } - /* Stop the test if the available space of the partition is less than 80K */ - if (size < 81920) - { - syslog(LOG_WARNING, "Partitioned free space not enough !\n"); - syslog(LOG_WARNING, "Test case (%s) exits early !\n", __func__); - } - else - { - - for (int i = 0; i < 5; i++) - { - itoa(i, str, 10); - - /* make directory */ - status = mkdir(str, 0700); - assert_int_equal(status, 0); - } - getcwd(buf, sizeof(buf)); - - /* open directory */ - dir = opendir(buf); - while ((ptr = readdir(dir)) != NULL) - { - status = rmdir(ptr->d_name); - } - - /* close directory flow */ - assert_int_equal(closedir(dir), 0); - } -} diff --git a/testsuites/kernel/fs/cases/fs_seek_test.c b/testsuites/kernel/fs/cases/fs_seek_test.c deleted file mode 100644 index 46f5a17..0000000 --- a/testsuites/kernel/fs/cases/fs_seek_test.c +++ /dev/null @@ -1,215 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TESTFILE "fileSeekTest" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsSeek01 - ****************************************************************************/ -void TestNuttxFsSeek01(FAR void **state) -{ - FILE *fp; - char c[] = "This is fseek test !"; - char buffer[sizeof(c)]; - int ret; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* open file*/ - fp = fopen(TESTFILE, "w+"); - assert_non_null(fp); - test_state->fd1 = fileno(fp); - - /* do fwrite */ - fwrite(c, strlen(c) + 1, 1, fp); - - /* reset file pos use fp */ - ret = fseek(fp, 8, SEEK_SET); - assert_int_equal(ret, 0); - - /* do fread */ - ret = fread(buffer, 1, strlen(c) + 1, fp); - buffer[ret] = 0; - assert_int_equal(strcmp(buffer, "fseek test !"), 0); - - /* reset file pos use fp */ - ret = fseek(fp, 5, SEEK_SET); - assert_int_equal(ret, 0); - - /* do read */ - ret = fread(buffer, 1, strlen(c) + 1, fp); - buffer[ret] = 0; - assert_int_equal(strcmp(buffer, "is fseek test !"), 0); - - /* reset file pos use fp */ - ret = fseek(fp, 14, SEEK_SET); - assert_int_equal(ret, 0); - - /* do fread */ - ret = fread(buffer, 1, strlen(c) + 1, fp); - buffer[ret] = 0; - assert_int_equal(strcmp(buffer, "test !"), 0); - fclose(fp); -} - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define WRITE_STR "abcdefg" -#define TFILE "tfile" - -/**************************************************************************** - * Private Data - ****************************************************************************/ -static int fd; -static struct tcase -{ - off_t off; - int whence; - char *wname; - off_t exp_off; - ssize_t exp_size; - char *exp_data; -} tcases[] = { - {4, SEEK_SET, "SEEK_SET", 4, 3, "efg"}, - {-2, SEEK_CUR, "SEEK_CUR", 5, 2, "fg"}, - {-4, SEEK_END, "SEEK_END", 3, 4, "defg"}, - {0, SEEK_END, "SEEK_END", 7, 0, NULL}, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsVerifyLseek - ****************************************************************************/ -static int TestNuttxFsVerifyLseek(unsigned int n) -{ - char read_buf[64]; - struct tcase *tc = &tcases[n]; - int ret; - /* do read */ - ssize_t sn = read(fd, read_buf, sizeof(read_buf)); - if (sn < 0) - { - return -1; - } - - /* set memory */ - memset(read_buf, 0, sizeof(read_buf)); - - /* do lseek */ - ret = lseek(fd, tc->off, tc->whence); - if (ret == (off_t)-1) - { - syslog(LOG_ERR, "lseek(%s, %lld, %s) failed\n", TFILE, (long long)tc->off, tc->wname); - return -1; - } - - if (ret != tc->exp_off) - { - syslog(LOG_ERR, "lseek(%s, %lld, %s) returned %d, expected %lld\n", TFILE, (long long)tc->off, tc->wname, ret, (long long)tc->exp_off); - return -1; - } - - /* do read*/ - sn = read(fd, read_buf, tc->exp_size); - if (sn < 0) - { - return -1; - } - if (tc->exp_data && strcmp(read_buf, tc->exp_data)) - { - syslog(LOG_ERR, "lseek(%s, %lld, %s) read incorrect data\n", TFILE, (long long)tc->off, tc->wname); - return -1; - } - else - { - return 0; - } -} - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsSet - ****************************************************************************/ -static void TestNuttxFsSet(void) -{ - fd = open(TFILE, O_RDWR | O_CREAT, 0700); - assert_true(fd >= 0); - write(fd, WRITE_STR, sizeof(WRITE_STR) - 1); -} - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsClean - ****************************************************************************/ -static void TestNuttxFsClean(void) -{ - if (fd > 0) - close(fd); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsSeek02 - ****************************************************************************/ -void TestNuttxFsSeek02(FAR void **state) -{ - int ret; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - TestNuttxFsSet(); - test_state->fd1 = fd; - /* do verify lseek*/ - ret = TestNuttxFsVerifyLseek(0); - assert_int_equal(ret, 0); - - /* do verify lseek*/ - ret = TestNuttxFsVerifyLseek(1); - assert_int_equal(ret, 0); - - /* do verify lseek*/ - ret = TestNuttxFsVerifyLseek(2); - assert_int_equal(ret, 0); - - /* do verify lseek*/ - ret = TestNuttxFsVerifyLseek(3); - assert_int_equal(ret, 0); - - /* do clean*/ - TestNuttxFsClean(); -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_sendfile_test.c b/testsuites/kernel/fs/cases/fs_sendfile_test.c deleted file mode 100644 index 198e6ab..0000000 --- a/testsuites/kernel/fs/cases/fs_sendfile_test.c +++ /dev/null @@ -1,159 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -#define O_FILE "outputFile" -#define I_FILE1 "inputFile1" -#define I_FILE2 "inputFile2" - -static void set_test(void) -{ - int fd; - fd = open(O_FILE, O_CREAT | O_RDWR, 0777); - if (fd == -1) - { - syslog(LOG_ERR, "Unable to open file %s, errno %d\n", O_FILE, errno); - assert_true(1 == 0); - } - write(fd, "ABCDEFGHIJ", 10); - close(fd); -} -/**************************************************************************** - * Name: sendfile - * Example description: - 1.Test copy the entire file - * Expect results: TEST PASSED - ****************************************************************************/ - -void TestNuttxFsSendfile01(FAR void **state) -{ - int ret; - int fd_o1, fd_o2, fd_i; - int test_flag = 0; - struct stat f_stat; - set_test(); - - /* open file readonly */ - fd_i = open(O_FILE, O_RDONLY); - if (fd_i == -1) - { - syslog(LOG_ERR, "open file fail !, errno %d\n", errno); - assert_true(1 == 0); - } - - /* open file O_RDWR */ - fd_o1 = open(I_FILE1, O_CREAT | O_RDWR, 0777); - if (fd_o1 == -1) - { - close(fd_i); - syslog(LOG_ERR, "open file fail !, errno %d\n", errno); - assert_true(1 == 0); - } - - if (fstat(fd_i, &f_stat) < 0) - { - syslog(LOG_ERR, "fstat fail !, errno %d\n", errno); - close(fd_i); - close(fd_o1); - assert_true(1 == 0); - } - - /* sendfile , copy the entire file */ - ret = sendfile(fd_o1, fd_i, NULL, f_stat.st_size); - - if (ret != f_stat.st_size) - { - syslog(LOG_ERR, "ret != f_stat.st_size\n"); - test_flag = 1; - } - - lseek(fd_i, 0, SEEK_SET); - - fd_o2 = open(I_FILE2, O_CREAT | O_RDWR, 0777); - if (fd_o2 == -1) - { - syslog(LOG_ERR, "open file fail !, errno %d\n", errno); - close(fd_i); - close(fd_o1); - assert_true(1 == 0); - } - /* sendfile , Copy part of the file */ - ret = sendfile(fd_o2, fd_i, NULL, 5); - - if (ret != 5) - { - syslog(LOG_ERR, "ret != 5\n"); - test_flag = 1; - } - - close(fd_o1); - close(fd_o2); - close(fd_i); - assert_true(test_flag == 0); -} - -/**************************************************************************** - * Name: sendfile - * Example description: - 1.Test copy the entire file - * Expect results: TEST PASSED - ****************************************************************************/ -void TestNuttxFsSendfile02(FAR void **state) -{ - int fd_o, fd_i; - off_t offset; - struct stat f_stat; - set_test(); - - /* open file readonly */ - fd_i = open(O_FILE, O_RDONLY); - if (fd_i == -1) - { - syslog(LOG_ERR, "open file fail !, errno %d\n", errno); - assert_true(1 == 0); - } - - /* open file O_RDWR */ - fd_o = open(I_FILE1, O_CREAT | O_RDWR, 0777); - if (fd_o == -1) - { - syslog(LOG_ERR, "open file fail !, errno %d\n", errno); - close(fd_i); - assert_true(1 == 0); - } - - if (fstat(fd_i, &f_stat) < 0) - { - syslog(LOG_ERR, "fstat fail ! errno %d\n", errno); - close(fd_i); - close(fd_o); - assert_true(1 == 0); - } - offset = 5; - - /* sendfile */ - sendfile(fd_o, fd_i, &offset, f_stat.st_size - offset); - - close(fd_o); - close(fd_i); - - /* Checks whether the file pointer is offset to the specified position */ - assert_int_equal(offset, f_stat.st_size); -} diff --git a/testsuites/kernel/fs/cases/fs_stat_test.c b/testsuites/kernel/fs/cases/fs_stat_test.c deleted file mode 100644 index 1976e48..0000000 --- a/testsuites/kernel/fs/cases/fs_stat_test.c +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TEST_FILE "stat_test_file" -#define BUF_SIZE 1024 - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsPrintTime - ****************************************************************************/ -__attribute__((unused)) static void TestNuttxFsPrintTime(struct tm *TM) -{ - syslog(LOG_INFO, " tm_year: %d\n", TM->tm_year + 1900); - syslog(LOG_INFO, " tm_mon: %d\n", TM->tm_mon); - syslog(LOG_INFO, " tm_mday: %d\n", TM->tm_mday); - syslog(LOG_INFO, " tm_hour: %d\n", TM->tm_hour); - syslog(LOG_INFO, " tm_min: %d\n", TM->tm_min); - syslog(LOG_INFO, " tm_sec: %d\n", TM->tm_sec); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsStat01 - ****************************************************************************/ -void TestNuttxFsStat01(FAR void **state) -{ - int fd; - int ret, ret2; - struct stat file_s; - char buf[BUF_SIZE] = {0}; - struct tm *tm_1 = NULL, *tm_2 = NULL; - int year1, year2, month1, month2, day1, day2, hour1, hour2, min1, min2; - time_t t_1, t_2; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* set memory */ - memset(buf, 65, BUF_SIZE); - - /* open file */ - fd = open(TEST_FILE, O_RDWR | O_CREAT, 0777); - assert_true(fd > 0); - test_state->fd1 = 0; - - /* do write*/ - ret2 = write(fd, buf, BUF_SIZE); - assert_int_in_range(ret2, 1, 1024); - - close(fd); - - /* get system time */ - time(&t_1); - tm_1 = gmtime(&t_1); - assert_non_null(tm_1); - - /* set time */ - year1 = tm_1->tm_year; - month1 = tm_1->tm_mon; - day1 = tm_1->tm_mday; - hour1 = tm_1->tm_hour; - min1 = tm_1->tm_min; - - /* get file info */ - ret = stat(TEST_FILE, &file_s); - assert_int_equal(ret, 0); - - /* output stat struct information */ - t_2 = file_s.st_mtime; - tm_2 = gmtime(&t_2); - - assert_non_null(tm_2); - - /* set time */ - year2 = tm_2->tm_year; - month2 = tm_2->tm_mon; - day2 = tm_2->tm_mday; - hour2 = tm_2->tm_hour; - min2 = tm_2->tm_min; - - /* compare time and size */ - - assert_int_equal(year1, year2); - assert_int_equal(month1, month2); - assert_int_equal(day1, day2); - assert_int_equal(hour1, hour2); - assert_int_equal(min1, min2); - assert_int_equal(file_s.st_size, BUF_SIZE); -} diff --git a/testsuites/kernel/fs/cases/fs_statfs_test.c b/testsuites/kernel/fs/cases/fs_statfs_test.c deleted file mode 100644 index 9f8562b..0000000 --- a/testsuites/kernel/fs/cases/fs_statfs_test.c +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define _1k 1024 - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsPrintStatfs - ****************************************************************************/ -__attribute__((unused)) static void TestNuttxFsPrintStatfs(struct statfs *buf) -{ - syslog(LOG_INFO, "statfs buffer:\n"); - syslog(LOG_INFO, " f_type: %u \n", (unsigned)buf->f_type); - syslog(LOG_INFO, " f_bsize: %zuk\n", (size_t)buf->f_bsize / _1k); - syslog(LOG_INFO, " f_blocks: %llu \n", (unsigned long long)buf->f_blocks); - syslog(LOG_INFO, " f_bfree: %llu \n", (unsigned long long)buf->f_bfree); - syslog(LOG_INFO, " f_bavail: %llu \n", (unsigned long long)buf->f_bavail); - syslog(LOG_INFO, " f_files: %llu \n", (unsigned long long)buf->f_files); - syslog(LOG_INFO, " f_ffree: %llu \n", (unsigned long long)buf->f_ffree); - syslog(LOG_INFO, " f_namelen: %zu \n", (size_t)buf->f_namelen); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsStatfs01 - ****************************************************************************/ -void TestNuttxFsStatfs01(FAR void **state) -{ - struct statfs diskInfo; - /* call statfs() */ - char* buf = getcwd(NULL, 0); - int ret = statfs(buf, &diskInfo); - free(buf); - assert_int_equal(ret, 0); -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_stream_test.c b/testsuites/kernel/fs/cases/fs_stream_test.c deleted file mode 100644 index 62a417b..0000000 --- a/testsuites/kernel/fs/cases/fs_stream_test.c +++ /dev/null @@ -1,373 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" -#define TESTFILENAME "streamTestfile" - -/**************************************************************************** - * Name: stream - * Example description: - 1. open a file with "a+". - 2. Write some strings to the file. - 3. Open it again and Write some strings. - 4. Check the returned results. - * Test item: fopen() fwrite() freopen() - * Expect results: TEST PASSED - ****************************************************************************/ - -void TestNuttxFsStream01(FAR void **state) -{ - FILE *stream; - char buf[10]; - int i; - size_t ret; - if ((stream = fopen(TESTFILENAME, "a+")) == NULL) - { - syslog(LOG_ERR, "open file fail !, errno %d\n", errno); - assert_true(1 == 0); - } - fwrite("a", 1, 1, stream); - if ((stream = freopen(TESTFILENAME, "a+", stream)) == NULL) - { - syslog(LOG_ERR, "reopen file fail !, errno %d\n", errno); - assert_true(1 == 0); - } - fclose(stream); - if ((stream = fopen(TESTFILENAME, "r")) == NULL) - { - syslog(LOG_ERR, "open file fail !, errno %d\n", errno); - assert_true(1 == 0); - } - else - { - for (i = 0; i < 10; i++) - buf[i] = 0; - ret = fread(buf, 1, 1, stream); - if ((buf[0] != 'a') || (buf[1] != 0) || ret == 0) - { - fclose(stream); - syslog(LOG_ERR, "bad contents in \n"); - assert_true(1 == 0); - } - fclose(stream); - } - unlink(TESTFILENAME); -} - -/**************************************************************************** - * Name: stream - * Example description: - 1. open a file with "a+". - 2. Write the file multiple times. - 3. Check that the file pointer is in the correct position after each write. - 4. Reset the file pointer position. Repeat step 2-3 - 4. Check the returned results. - * Test item: fopen() fwrite() rewind() ftell() fseek() fgets() - * Expect results: TEST PASSED - ****************************************************************************/ -void TestNuttxFsStream02(FAR void **state) -{ - FILE *stream; - char buf[30]; - char *junk = "abcdefghijklmnopqrstuvwxyz"; - long pos; - int lc; - for (lc = 0; lc < 100; lc++) - { - - if ((stream = fopen(TESTFILENAME, "a+")) == NULL) - { - syslog(LOG_ERR, "open file failed !, errno %d\n", errno); - assert_true(1 == 0); - } - pos = ftell(stream); - if (pos != 0) - { - syslog(LOG_ERR, "file pointer descrepancy 1, errno %d\n", errno); - fclose(stream); - assert_true(1 == 0); - } - if (fwrite(junk, sizeof(*junk), strlen(junk), stream) == 0) - { - syslog(LOG_ERR, "fwrite failed, errno %d\n", errno); - fclose(stream); - assert_true(1 == 0); - } - pos = ftell(stream); - if (pos != strlen(junk)) - { - syslog(LOG_ERR, "strlen(junk)=%zi: file pointer descrepancy 2 (pos=%li)", strlen(junk), pos); - fclose(stream); - assert_true(1 == 0); - } - rewind(stream); - pos = ftell(stream); - if (pos != 0) - { - fclose(stream); - syslog(LOG_ERR, "file pointer descrepancy 3 (pos=%li, wanted pos=0)", pos); - assert_true(1 == 0); - } - if (fseek(stream, strlen(junk), 1) != 0) - { - syslog(LOG_ERR, "fseek failed !, errno %d\n", errno); - fclose(stream); - assert_true(1 == 0); - } - pos = ftell(stream); - if (pos != strlen(junk)) - { - fclose(stream); - syslog(LOG_ERR, "strlen(junk)=%zi: file pointer descrepancy 4 (pos=%li)", strlen(junk), pos); - assert_true(1 == 0); - } - if (fseek(stream, 0, 2) != 0) - { - syslog(LOG_ERR, "fseek failed !, errno %d\n", errno); - fclose(stream); - assert_true(1 == 0); - } - pos = ftell(stream); - if (pos != strlen(junk)) - { - fclose(stream); - syslog(LOG_ERR, "strlen(junk)=%zi: file pointer descrepancy 5 (pos=%li)", strlen(junk), pos); - assert_true(1 == 0); - } - if (fseek(stream, 0, 0) != 0) - { - syslog(LOG_ERR, "fseek failed !, errno %d\n", errno); - fclose(stream); - assert_true(1 == 0); - } - pos = ftell(stream); - if (pos != 0) - { - fclose(stream); - syslog(LOG_ERR, "file pointer descrepancy 6 (pos=%li, wanted pos=0)", pos); - assert_true(1 == 0); - } - while (fgets(buf, sizeof(buf), stream)) - ; - pos = ftell(stream); - if (pos != strlen(junk)) - { - syslog(LOG_ERR, "strlen(junk)=%zi: file pointer descrepancy 7 (pos=%li)", strlen(junk), pos); - assert_true(1 == 0); - } - fclose(stream); - unlink(TESTFILENAME); - } -} - -/**************************************************************************** - * Name: stream - * Example description: - 1. open a file with "a+". - 2. Write the file multiple times. - 3. close the file. - 4. open the file again with "r+" - 5. Request a piece of memory and read the contents of the file. - 6. Check that the read file class is correct. - 7. repeat step 2-3-4-5-6 for 10 times. - 8. Check that the test returns results. - * Test item: fopen() fwrite() fread() malloc() - * Expect results: TEST PASSED - ****************************************************************************/ -void TestNuttxFsStream03(FAR void **state) -{ - FILE *stream; - char *junk = "abcdefghijklmnopqrstuvwxyz"; - size_t len = strlen(junk); - char *inbuf = NULL; - int ret; - int lc; - for (lc = 0; lc < 10; lc++) - { - if ((stream = fopen(TESTFILENAME, "a+")) == NULL) - { - syslog(LOG_ERR, "fopen a+ failed, errno %d\n", errno); - assert_true(1 == 0); - } - if ((ret = fwrite(junk, sizeof(*junk), len, stream)) == 0) - { - syslog(LOG_ERR, "fwrite failed, errno %d\n", errno); - fclose(stream); - assert_true(1 == 0); - } - if ((size_t)ret != len) - { - syslog(LOG_ERR, "len = %zi != return value from fwrite = %zi", len, ret); - fclose(stream); - assert_true(1 == 0); - } - fclose(stream); - if ((stream = fopen(TESTFILENAME, "r+")) == NULL) - { - syslog(LOG_ERR, "fopen r+ failed, errno %d\n", errno); - assert_true(1 == 0); - } - if ((inbuf = malloc(len)) == 0) - { - syslog(LOG_ERR, "test failed , because of malloc fail, errno %d\n", errno); - fclose(stream); - assert_true(1 == 0); - } - if ((ret = fread(inbuf, sizeof(*junk), len, stream)) == 0) - { - syslog(LOG_ERR, "fread failed, errno %d\n", errno); - free(inbuf); - fclose(stream); - assert_true(1 == 0); - } - if ((size_t)ret != len) - { - syslog(LOG_ERR, "len = %zi != return value from fread = %zi", len, ret); - free(inbuf); - fclose(stream); - assert_true(1 == 0); - } - /* Free memory */ - free(inbuf); - fclose(stream); - unlink(TESTFILENAME); - } -} - -/**************************************************************************** - * Name: stream - * Example description: - 1. Open the file in a different mode, such as "a+" "r+" "rb" etc. - 2. Check that the test returns results. - * Test item: fopen() fprintf() read() fileno() fclose() - * Expect results: TEST PASSED - ****************************************************************************/ -void TestNuttxFsStream04(FAR void **state) -{ - FILE *stream; - char buf[10]; - int nr, fd; - size_t ret; - int lc; - for (lc = 0; lc < 10; lc++) - { - if ((stream = fopen(TESTFILENAME, "a+")) == NULL) - { - syslog(LOG_ERR, "fopen a+ failed, errno %d\n", errno); - assert_true(1 == 0); - } - fprintf(stream, "a"); - fclose(stream); - - if ((stream = fopen(TESTFILENAME, "r+")) == NULL) - { - syslog(LOG_ERR, "fopen r+ failed, errno %d\n", errno); - assert_true(1 == 0); - } - if (ferror(stream) != 0) - { - syslog(LOG_ERR, "ferror did not return zero, return %d\n", ferror(stream)); - fclose(stream); - assert_true(1 == 0); - } - fd = fileno(stream); - if ((nr = read(fd, buf, 1)) < 0) - { - syslog(LOG_ERR, "read failed !, errno %d\n", errno); - fclose(stream); - assert_true(1 == 0); - } - if (nr != 1) - { - syslog(LOG_ERR, "read did not read right number, nr = %d, errno %d\n", nr, errno); - fclose(stream); - assert_true(1 == 0); - } - if (buf[0] != 'a') - { - syslog(LOG_ERR, "read returned bad values %c\n", buf[0]); - fclose(stream); - assert_true(1 == 0); - } - fclose(stream); - - if ((stream = fopen(TESTFILENAME, "r+")) == NULL) - { - syslog(LOG_ERR, "fopen(%s) r+ failed, errno %d\n", TESTFILENAME, errno); - assert_true(1 == 0); - } - if (feof(stream) != 0) - { - syslog(LOG_ERR, "feof returned non-zero when it should not \n"); - fclose(stream); - assert_true(1 == 0); - } - ret = fread(buf, 1, 2, stream); - buf[ret] = 0; - if (feof(stream) == 0) - { - syslog(LOG_ERR, "feof returned zero when it should not \n"); - fclose(stream); - assert_true(1 == 0); - } - fclose(stream); - if ((stream = fopen(TESTFILENAME, "rb")) == NULL) - { - syslog(LOG_ERR, "fopen rb failed, errno %d\n", errno); - fclose(stream); - assert_true(1 == 0); - } - fclose(stream); - if ((stream = fopen(TESTFILENAME, "wb")) == NULL) - { - syslog(LOG_ERR, "fopen wb failed, errno %d\n", errno); - fclose(stream); - assert_true(1 == 0); - } - fclose(stream); - if ((stream = fopen(TESTFILENAME, "ab")) == NULL) - { - syslog(LOG_ERR, "fopen ab failed, errno %d\n", errno); - fclose(stream); - assert_true(1 == 0); - } - fclose(stream); - if ((stream = fopen(TESTFILENAME, "rb+")) == NULL) - { - syslog(LOG_ERR, "fopen rb+ failed"); - fclose(stream); - assert_true(1 == 0); - } - fclose(stream); - if ((stream = fopen(TESTFILENAME, "wb+")) == NULL) - { - syslog(LOG_ERR, "fopen wb+ failed, errno %d\n", errno); - fclose(stream); - assert_true(1 == 0); - } - fclose(stream); - if ((stream = fopen(TESTFILENAME, "ab+")) == NULL) - { - syslog(LOG_ERR, "fopen ab+ failed, errno %d\n", errno); - fclose(stream); - assert_true(1 == 0); - } - fclose(stream); - unlink(TESTFILENAME); - } -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_symlink_test.c b/testsuites/kernel/fs/cases/fs_symlink_test.c deleted file mode 100644 index 2395526..0000000 --- a/testsuites/kernel/fs/cases/fs_symlink_test.c +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TEST_FILE "test_file" -#define PATH_MAX_SIZE 64 - -/**************************************************************************** - * Private Data - ****************************************************************************/ -static char *path; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsRunTest - ****************************************************************************/ - -static int TestNuttxFsRunTest(void) -{ - int ret; - /* test symlink */ - char buf[64] = {0}; - ret = symlink(path, "/file_link"); - // syslog(LOG_INFO, "the symlink return : %d\n", ret); - if (ret != 0) - { - return ERROR; - } - else - { - ret = readlink("/file_link", buf, PATH_MAX_SIZE); - // syslog(LOG_INFO, "buf = %s\n", buf); - unlink("/file_link"); - } - return OK; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsSymlink01 - ****************************************************************************/ -void TestNuttxFsSymlink01(FAR void **state) -{ - int fd, ret; - char* buf; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* malloc memory */ - path = malloc(PATH_MAX_SIZE * sizeof(char)); - assert_non_null(path); - test_state->ptr = path; - - /* set memory */ - buf = getcwd(NULL, 0); - memset(path, '\0', PATH_MAX_SIZE); - sprintf(path, "%s/symlink_test_file", buf); - free(buf); - - /* open file*/ - fd = open(path, O_WRONLY | O_CREAT, 0700); - assert_true(fd > 0); - test_state->fd1 = fd; - - /* do run test */ - ret = TestNuttxFsRunTest(); - - /* do remove */ - unlink(path); - - assert_int_equal(ret, OK); -} diff --git a/testsuites/kernel/fs/cases/fs_truncate_test.c b/testsuites/kernel/fs/cases/fs_truncate_test.c deleted file mode 100644 index c8a4751..0000000 --- a/testsuites/kernel/fs/cases/fs_truncate_test.c +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TESTFILE "truncateTestFile" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsTruncate01 - ****************************************************************************/ -void TestNuttxFsTruncate01(FAR void **state) -{ - int fd, ret, ret2; - char buf[80]; - const char *s1 = "0123456789"; - const char *s2 = "abcde"; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* open file */ - fd = open(TESTFILE, O_CREAT | O_WRONLY | O_TRUNC, 0700); -#ifdef CONFIG_FDCHECK - assert_true(fd > 0); -#else - assert_int_in_range(fd, 0, 512); -#endif - test_state->fd1 = fd; - - /* do write */ - ret2 = write(fd, s1, strlen(s1)); - assert_int_in_range(ret2, 1, strlen(s1)); - - /* refresh to storage */ - ret = fsync(fd); - assert_int_equal(ret, 0); - - /* do ftruncate */ - ret = ftruncate(fd, 5); - assert_int_equal(ret, 0); - - /* do lseek */ - off_t pos = lseek(fd, 0, SEEK_END); - assert_int_equal(pos, 5); - - /* do write*/ - ret2 = write(fd, s2, strlen(s2)); - assert_int_in_range(ret2, 1, strlen(s2)); - - close(fd); - /* open file */ - fd = open(TESTFILE, O_RDONLY); - assert_true(fd > 0); - test_state->fd1 = fd; - - /*read file */ - ret = read(fd, buf, 26); - if (ret >= 0) - { - buf[ret] = 0; - } - /* check buf*/ - assert_true(strncmp(buf, "01234abcde", 10) == 0); - close(fd); -} diff --git a/testsuites/kernel/fs/cases/fs_unlink_test.c b/testsuites/kernel/fs/cases/fs_unlink_test.c deleted file mode 100644 index aad13f3..0000000 --- a/testsuites/kernel/fs/cases/fs_unlink_test.c +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define MAXSIZE 1024 -#define test_file "test_unlink_file01" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsUnlink01 - ****************************************************************************/ -void TestNuttxFsUnlink01(FAR void **state) -{ - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* open file */ - int fd = open(test_file, O_RDWR | O_CREAT, 0777); - assert_true(fd > 0); - test_state->fd1 = fd; - - char buf[MAXSIZE] = {0}; - - /* set memory */ - memset(buf, 65, MAXSIZE); - - /* do write */ - int size = write(fd, buf, MAXSIZE); - assert_int_in_range(size, 1, MAXSIZE); - - close(fd); - - /* delete test file */ - int ret = unlink(test_file); - assert_int_equal(ret, 0); - - /* check if the file was deleted successfully */ - fd = open(test_file, O_RDONLY); - assert_int_equal(fd, -1); -} \ No newline at end of file diff --git a/testsuites/kernel/fs/cases/fs_write_test.c b/testsuites/kernel/fs/cases/fs_write_test.c deleted file mode 100644 index e4b44d4..0000000 --- a/testsuites/kernel/fs/cases/fs_write_test.c +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TESTFILE "testWriteFile" -#define MAXLEN 1024 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsWrite01 - ****************************************************************************/ -void TestNuttxFsWrite01(FAR void **state) -{ - int out, rval; - char buffer[1024]; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* open file */ - out = open(TESTFILE, O_WRONLY | O_CREAT, 0700); - assert_true(out > 0); - test_state->fd1 = out; - - /* set memory */ - memset(buffer, '*', MAXLEN); - - /* do write */ - rval = write(out, buffer, MAXLEN); - assert_int_in_range(rval, 1, MAXLEN); -} - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TESTFILENAME "loopTestFile" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsWrite02 - ****************************************************************************/ -void TestNuttxFsWrite02(FAR void **state) -{ - int rval; - FILE *fp; - long offset; - char content[15] = "asdfgtgtrf"; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* fopen file */ - fp = fopen(TESTFILENAME, "a+"); - assert_non_null(fp); - test_state->fd1 = fileno(fp); - - /* do fwrite */ - rval = fwrite(content, 1, 10, fp); - assert_int_in_range(rval, 1, 10); - - /* refresh to storage */ - fsync(fileno(fp)); - - /* do ffkush */ - fflush(fp); - - /* get ftell */ - offset = ftell(fp); - assert_true(offset == 10); - fclose(fp); -} - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TESTFILENAME3 "loopTestFile" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsWrite03 - ****************************************************************************/ -void TestNuttxFsWrite03(FAR void **state) -{ - int rval; - FILE *fp; - long offset; - char content[15] = "asdfgtgtrf"; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - /* fopen file */ - fp = fopen(TESTFILENAME3, "a+"); - assert_non_null(fp); - test_state->fd1 = fileno(fp); - - /* do fwrite */ - rval = fwrite(content, 1, 10, fp); - assert_int_in_range(rval, 1, 10); - - /* refresh to storage */ - fsync(fileno(fp)); - - /* get ftell */ - offset = ftell(fp); - assert_true(offset == 10); - fclose(fp); -} diff --git a/testsuites/kernel/fs/cmocka_fs_test.c b/testsuites/kernel/fs/cmocka_fs_test.c deleted file mode 100644 index 1b39468..0000000 --- a/testsuites/kernel/fs/cmocka_fs_test.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2020 Xiaomi Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -/**************************************************************************** - * Name: cmocka_fs_test_main - ****************************************************************************/ -int main(int argc, char *argv[]) -{ - /* Add Test Cases */ - const struct CMUnitTest NuttxFsTestSuites[] = { - cmocka_unit_test_setup_teardown(TestNuttxFsCreat01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsDup01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - //cmocka_unit_test_setup_teardown(TestNuttxFsDup201, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsFcntl01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), -#ifndef CONFIG_ARCH_SIM - cmocka_unit_test_setup_teardown(TestNuttxFsFcntl02, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsFcntl03, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), -#endif - cmocka_unit_test_setup_teardown(TestNuttxFsFstat01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), -#ifndef CONFIG_ARCH_SIM - cmocka_unit_test_setup_teardown(TestNuttxFsFstat02, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), -#endif - cmocka_unit_test_setup_teardown(TestNuttxFsFstatfs01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsFsync01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsFsync02, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsGetfilep01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsMkdir01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsOpen01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsOpendir01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsOpendir02, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsPread01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsPwrite01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), -#ifndef CONFIG_ARCH_SIM - cmocka_unit_test_setup_teardown(TestNuttxFsRead01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), -#endif - cmocka_unit_test_setup_teardown(TestNuttxFsReaddir01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsReadlink01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsRename01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsRename02, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsRewinddir01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsRmdir01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsRmdir02, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsRmdir03, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsSeek01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsSeek02, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), -#ifndef CONFIG_ARCH_SIM - cmocka_unit_test_setup_teardown(TestNuttxFsStat01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), -#endif - cmocka_unit_test_setup_teardown(TestNuttxFsStatfs01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsSymlink01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsTruncate01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsUnlink01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsWrite01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsWrite02, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsWrite03, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsAppend01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsSendfile01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsSendfile02, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsStream01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsStream02, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsStream03, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsStream04, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsEventfd, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - cmocka_unit_test_setup_teardown(TestNuttxFsPoll01, TestNuttxFsTestGroupSetUp, TestNuttxFsTestGroupTearDown), - }; - /* Run Test cases */ - cmocka_run_group_tests(NuttxFsTestSuites, NULL, NULL); - return 0; -} diff --git a/testsuites/kernel/fs/common/test_fs_common.c b/testsuites/kernel/fs/common/test_fs_common.c deleted file mode 100644 index 287fc76..0000000 --- a/testsuites/kernel/fs/common/test_fs_common.c +++ /dev/null @@ -1,181 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fstest.h" - -#define CM_FSTESTDIR "CM_fs_testdir" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -unsigned long long cm_get_partition_available_size(void) -{ - unsigned long long size = 0; - int ret; - struct statfs statInfo; - /* call statfs() */ - ret = statfs(MOUNT_DIR, &statInfo); - if (ret == 0) - { - size = (unsigned long long)statInfo.f_bsize * (unsigned long long)statInfo.f_bfree; - } - else - { - size = (unsigned long long)-1; - } - return size; -} - -int cm_unlink_recursive(FAR char *path) -{ - struct dirent *d; - struct stat stat; - size_t len; - int ret; - DIR *dp; - - ret = lstat(path, &stat); - if (ret < 0) - { - return ret; - } - - if (!S_ISDIR(stat.st_mode)) - { - return unlink(path); - } - - dp = opendir(path); - if (dp == NULL) - { - return -1; - } - - len = strlen(path); - if (len > 0 && path[len - 1] == '/') - { - path[--len] = '\0'; - } - - while ((d = readdir(dp)) != NULL) - { - if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) - { - continue; - } - - snprintf(&path[len], PATH_MAX - len, "/%s", d->d_name); - ret = cm_unlink_recursive(path); - if (ret < 0) - { - closedir(dp); - return ret; - } - } - - ret = closedir(dp); - if (ret >= 0) - { - path[len] = '\0'; - ret = rmdir(path); - } - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxFsTestGroupSetUp - ****************************************************************************/ -int TestNuttxFsTestGroupSetUp(void **state) -{ - int res; - struct stat buf; - struct fs_testsuites_state_s *test_state; - - res = chdir(MOUNT_DIR); - if (res != 0) - { - syslog(LOG_INFO, "ERROR: Failed to switch the mount dir\n"); - exit(1); - } - - res = stat(CM_FSTESTDIR, &buf); - if (res == 0 && buf.st_mode == S_IFDIR) - { - res = chdir(CM_FSTESTDIR); - } - else - { - char testdir[PATH_MAX] = {0}; - sprintf(testdir, "%s/%s", MOUNT_DIR, CM_FSTESTDIR); - /* Delete the existing test directory */ - cm_unlink_recursive(testdir); - res = mkdir(CM_FSTESTDIR, 0777); - if (res != 0) - { - syslog(LOG_INFO, "ERROR: Failed to creat the test directory\n"); - exit(1); - } - chdir(CM_FSTESTDIR); - } - - test_state = zalloc(sizeof(struct fs_testsuites_state_s)); - assert_false(test_state == NULL); - test_state->ptr = NULL; - test_state->fd1 = -1; - test_state->fd2 = -1; - memset(test_state->filename, 0, PATH_SIZE); - *state = test_state; - return res; -} - -/**************************************************************************** - * Name: TestNuttxFsTestGroupTearDown - ****************************************************************************/ -int TestNuttxFsTestGroupTearDown(void **state) -{ - int res; - char testdir[PATH_MAX] = {0}; - struct fs_testsuites_state_s *test_state; - - test_state = (struct fs_testsuites_state_s *)*state; - - if (test_state->fd1 > 0) - close(test_state->fd1); - if (test_state->fd2 > 0) - close(test_state->fd2); - if (test_state->ptr != NULL) - free(test_state->ptr); - free(test_state); - - sprintf(testdir, "%s/%s", MOUNT_DIR, CM_FSTESTDIR); - res = chdir(MOUNT_DIR); - if (res != 0) - { - syslog(LOG_INFO, "ERROR: Failed to switch the mount dir\n"); - exit(1); - } - /* Delete the existing test directory */ - cm_unlink_recursive(testdir); - return 0; -} diff --git a/testsuites/kernel/fs/include/fstest.h b/testsuites/kernel/fs/include/fstest.h deleted file mode 100644 index b502136..0000000 --- a/testsuites/kernel/fs/include/fstest.h +++ /dev/null @@ -1,153 +0,0 @@ -#ifndef __TEST_H -#define __TEST_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define TEST_PASS 0 -#define TEST_FAIL -1 - -#define MAX_PATH 300 - -/* The test files generated during the 'fs-test' are stored in this directory */ -#define FS_TEST_DIR "fs_test_dir" -#define MOUNT_DIR CONFIG_TESTS_TESTSUITES_MOUNT_DIR - -#define PATH_SIZE 128 - -struct fs_testsuites_state_s -{ - char filename[PATH_SIZE]; - char *ptr; - int fd1; - int fd2; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ -unsigned long long cm_get_partition_available_size(void); -int cm_unlink_recursive(FAR char *path); -int TestNuttxFsTestGroupSetUp(FAR void **state); -int TestNuttxFsTestGroupTearDown(FAR void **state); - -/* cases/fs_creat_test.c ************************************************/ -void TestNuttxFsCreat01(FAR void **state); - -/* cases/fs_dup_test.c ************************************************/ -void TestNuttxFsDup01(FAR void **state); - -/* cases/fs_dup2_test.c ************************************************/ -void TestNuttxFsDup201(FAR void **state); - -/* cases/fs_fcntl_test.c ************************************************/ -void TestNuttxFsFcntl01(FAR void **state); -void TestNuttxFsFcntl02(FAR void **state); -void TestNuttxFsFcntl03(FAR void **state); - -/* cases/fs_fstat_test.c ************************************************/ -void TestNuttxFsFstat01(FAR void **state); -void TestNuttxFsFstat02(FAR void **state); - -/* cases/fs_fstatfs_test.c ************************************************/ -void TestNuttxFsFstatfs01(FAR void **state); - -/* cases/fs_fsync_test.c ************************************************/ -void TestNuttxFsFsync01(FAR void **state); -void TestNuttxFsFsync02(FAR void **state); - -/* cases/fs_getfilep_test.c ************************************************/ -void TestNuttxFsGetfilep01(FAR void **state); - -/* cases/fs_mkdir_test.c ************************************************/ -void TestNuttxFsMkdir01(FAR void **state); - -/* cases/fs_open_test.c ************************************************/ -void TestNuttxFsOpen01(FAR void **state); - -/* cases/fs_opendir_test.c ************************************************/ -void TestNuttxFsOpendir01(FAR void **state); -void TestNuttxFsOpendir02(FAR void **state); - -/* cases/fs_pread_test.c ************************************************/ -void TestNuttxFsPread01(FAR void **state); - -/* cases/fs_pwrite_test.c ************************************************/ -void TestNuttxFsPwrite01(FAR void **state); - -/* cases/fs_read_test.c ************************************************/ -void TestNuttxFsRead01(FAR void **state); - -/* cases/fs_readdir_test.c ************************************************/ -void TestNuttxFsReaddir01(FAR void **state); - -/* cases/fs_readlink_test.c ************************************************/ -void TestNuttxFsReadlink01(FAR void **state); - -/* cases/fs_rename_test.c ************************************************/ -void TestNuttxFsRename01(FAR void **state); -void TestNuttxFsRename02(FAR void **state); - -/* cases/fs_rewinddir_test.c ************************************************/ -void TestNuttxFsRewinddir01(FAR void **state); - -/* cases/fs_rmdir_test.c ************************************************/ -void TestNuttxFsRmdir01(FAR void **state); -void TestNuttxFsRmdir02(FAR void **state); -void TestNuttxFsRmdir03(FAR void **state); - -/* cases/fs_seek_test.c ************************************************/ -void TestNuttxFsSeek01(FAR void **state); -void TestNuttxFsSeek02(FAR void **state); - -/* cases/fs_stat_test.c ************************************************/ -void TestNuttxFsStat01(FAR void **state); - -/* cases/fs_statfs_test.c ************************************************/ -void TestNuttxFsStatfs01(FAR void **state); - -/* cases/fs_symlink_test.c ************************************************/ -void TestNuttxFsSymlink01(FAR void **state); - -/* cases/fs_truncate_test.c ************************************************/ -void TestNuttxFsTruncate01(FAR void **state); - -/* cases/fs_unlink_test.c ************************************************/ -void TestNuttxFsUnlink01(FAR void **state); - -/* cases/fs_write_test.c ************************************************/ -void TestNuttxFsWrite01(FAR void **state); -void TestNuttxFsWrite02(FAR void **state); -void TestNuttxFsWrite03(FAR void **state); - -/* cases/fs_append_test.c ************************************************/ -void TestNuttxFsAppend01(FAR void **state); - -/* cases/fs_sendfile_test.c ************************************************/ -void TestNuttxFsSendfile01(FAR void **state); -void TestNuttxFsSendfile02(FAR void **state); - -/* cases/fs_stream_test.c ************************************************/ -void TestNuttxFsStream01(FAR void **state); -void TestNuttxFsStream02(FAR void **state); -void TestNuttxFsStream03(FAR void **state); -void TestNuttxFsStream04(FAR void **state); - -/* cases/fs_eventfd_test.c ************************************************/ -void TestNuttxFsEventfd(FAR void **state); - -/* fs_poll_test.c ************************************************/ -void TestNuttxFsPoll01(FAR void **state); - -#endif diff --git a/testsuites/kernel/kv/cases/kv_test_001.c b/testsuites/kernel/kv/cases/kv_test_001.c index a896dc0..8c24578 100644 --- a/testsuites/kernel/kv/cases/kv_test_001.c +++ b/testsuites/kernel/kv/cases/kv_test_001.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_001.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -21,25 +41,43 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv01 + * Name: test_nuttx_kv01 ****************************************************************************/ -void TestNuttxKv01(FAR void **state) + +void test_nuttx_kv01(FAR void **state) { - int ret; - char key[TEST_KEY_LENGTH] = {0}, data[TEST_VALUE_LENGTH] = {0}, value[TEST_VALUE_LENGTH] = {0}; - for (int i = 1; i <= 1000; i++) + int ret; + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + char data[TEST_VALUE_LENGTH] = + { + 0 + }; + + char value[TEST_VALUE_LENGTH] = + { + 0 + }; + + for (int i = 1; i <= 100; i++) { - /* test key */ - sprintf(key, "test_key_%s_%d", __func__, i); - /* test data */ - sprintf(data, "test_data_%s_%d", __func__, i); - ret = property_set(key, data); - assert_int_equal(ret, 0); - - ret = property_get(key, value, ""); - property_delete(key); - - assert_int_equal(ret, strlen(data)); - assert_int_equal(strcmp(value, data), 0); + /* test key */ + + sprintf(key, "test_key_%s_%d", __func__, i); + + /* test data */ + + sprintf(data, "test_data_%s_%d", __func__, i); + ret = property_set(key, data); + assert_int_equal(ret, 0); + + ret = property_get(key, value, ""); + property_delete(key); + + assert_int_equal(ret, strlen(data)); + assert_int_equal(strcmp(value, data), 0); } -} \ No newline at end of file +} diff --git a/testsuites/kernel/kv/cases/kv_test_002.c b/testsuites/kernel/kv/cases/kv_test_002.c index c98fb8f..fad5685 100644 --- a/testsuites/kernel/kv/cases/kv_test_002.c +++ b/testsuites/kernel/kv/cases/kv_test_002.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_002.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -21,26 +41,32 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv02 + * Name: test_nuttx_kv02 ****************************************************************************/ -void TestNuttxKv02(FAR void **state) + +void test_nuttx_kv02(FAR void **state) { - int ret; - int invalid_value_len = PROP_VALUE_MAX + 200; - char key[TEST_KEY_LENGTH] = {0}; - char *value = NULL; + int ret; + int invalid_value_len = PROP_VALUE_MAX + 200; + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + char *value = NULL; + + value = (char *)malloc(invalid_value_len * sizeof(char)); + assert_non_null(value); - value = (char *)malloc(invalid_value_len * sizeof(char)); - assert_non_null(value); + /* test key */ - /* test key */ - sprintf(key, "test_key_%s", __func__); - memset(value, 0, invalid_value_len); - memset(value, 0x67, invalid_value_len - 2); + sprintf(key, "test_key_%s", __func__); + memset(value, 0, invalid_value_len); + memset(value, 0x67, invalid_value_len - 2); - ret = property_set(key, value); + ret = property_set(key, value); - free(value); - assert_int_not_equal(ret, 0); - property_delete(key); -} \ No newline at end of file + free(value); + assert_int_not_equal(ret, 0); + property_delete(key); +} diff --git a/testsuites/kernel/kv/cases/kv_test_003.c b/testsuites/kernel/kv/cases/kv_test_003.c index 05d3220..e95c1f0 100644 --- a/testsuites/kernel/kv/cases/kv_test_003.c +++ b/testsuites/kernel/kv/cases/kv_test_003.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_003.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -20,44 +40,55 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv03 + * Name: test_nuttx_kv03 ****************************************************************************/ -void TestNuttxKv03(FAR void **state) + +void test_nuttx_kv03(FAR void **state) { - int ret; - char key[TEST_KEY_LENGTH] = {0}; - int32_t test_int32_1, test_int32_2; - int64_t test_int64_1, test_int64_2; - - /* test key */ - sprintf(key, "test_key_%s_1", __func__); - ret = property_set_int32(key, 2147483647); - assert_int_equal(ret, 0); - test_int32_1 = property_get_int32(key, 0); - assert_int_equal(test_int32_1, INT32_MAX); - property_delete(key); - - /* test key */ - sprintf(key, "test_key_%s_2", __func__); - ret = property_set_int64(key, 9223372036854775807); - assert_int_equal(ret, 0); - test_int64_1 = property_get_int64(key, 0); - assert_int_equal(test_int64_1, INT64_MAX); - property_delete(key); - - /* test key */ - sprintf(key, "test_key_%s_3", __func__); - ret = property_set_int32(key, -2147483648); - assert_int_equal(ret, 0); - test_int32_2 = property_get_int32(key, 0); - assert_int_equal(test_int32_2, INT32_MIN); - property_delete(key); - - /* test key */ - sprintf(key, "test_key_%s_4", __func__); - ret = property_set_int64(key, INT64_MIN); - assert_int_equal(ret, 0); - test_int64_2 = property_get_int64(key, 0); - assert_int_equal(test_int64_2, INT64_MIN); - property_delete(key); -} \ No newline at end of file + int ret; + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + int32_t test_int32_1; + int32_t test_int32_2; + int64_t test_int64_1; + int64_t test_int64_2; + + /* test key */ + + sprintf(key, "test_key_%s_1", __func__); + ret = property_set_int32(key, 2147483647); + assert_int_equal(ret, 0); + test_int32_1 = property_get_int32(key, 0); + assert_int_equal(test_int32_1, INT32_MAX); + property_delete(key); + + /* test key */ + + sprintf(key, "test_key_%s_2", __func__); + ret = property_set_int64(key, 9223372036854775807); + assert_int_equal(ret, 0); + test_int64_1 = property_get_int64(key, 0); + assert_int_equal(test_int64_1, INT64_MAX); + property_delete(key); + + /* test key */ + + sprintf(key, "test_key_%s_3", __func__); + ret = property_set_int32(key, -2147483648); + assert_int_equal(ret, 0); + test_int32_2 = property_get_int32(key, 0); + assert_int_equal(test_int32_2, INT32_MIN); + property_delete(key); + + /* test key */ + + sprintf(key, "test_key_%s_4", __func__); + ret = property_set_int64(key, INT64_MIN); + assert_int_equal(ret, 0); + test_int64_2 = property_get_int64(key, 0); + assert_int_equal(test_int64_2, INT64_MIN); + property_delete(key); +} diff --git a/testsuites/kernel/kv/cases/kv_test_004.c b/testsuites/kernel/kv/cases/kv_test_004.c index c1ad1e6..3a010cb 100644 --- a/testsuites/kernel/kv/cases/kv_test_004.c +++ b/testsuites/kernel/kv/cases/kv_test_004.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_004.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -20,19 +40,25 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv04 + * Name: test_nuttx_kv04 ****************************************************************************/ -void TestNuttxKv04(FAR void **state) + +void test_nuttx_kv04(FAR void **state) { - int ret; - char key[TEST_KEY_LENGTH] = {0}; - /* test key */ - sprintf(key, "test_key_%s", __func__); - ret = property_set(key, "asdadsasdasd"); - assert_int_equal(ret, 0); - - ret = property_set(key, NULL); - assert_int_equal(ret, 0); - - property_delete(key); -} \ No newline at end of file + int ret; + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + /* test key */ + + sprintf(key, "test_key_%s", __func__); + ret = property_set(key, "asdadsasdasd"); + assert_int_equal(ret, 0); + + ret = property_set(key, NULL); + assert_int_equal(ret, 0); + + property_delete(key); +} diff --git a/testsuites/kernel/kv/cases/kv_test_005.c b/testsuites/kernel/kv/cases/kv_test_005.c index f4e6da4..9fb0e11 100644 --- a/testsuites/kernel/kv/cases/kv_test_005.c +++ b/testsuites/kernel/kv/cases/kv_test_005.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_005.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -20,18 +40,24 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv05 + * Name: test_nuttx_kv05 ****************************************************************************/ -void TestNuttxKv05(FAR void **state) + +void test_nuttx_kv05(FAR void **state) { - int ret; - char key[TEST_KEY_LENGTH] = {0}; + int ret; + char key[TEST_KEY_LENGTH] = + { + 0 + }; - for (int i = 1; i < 10; i++) + for (int i = 1; i < 10; i++) { - sprintf(key, "test_key_%s_%d", __func__, i); - /* delete the data that doesn't exist */ - ret = property_delete(key); - assert_int_not_equal(ret, 0); + sprintf(key, "test_key_%s_%d", __func__, i); + + /* delete the data that doesn't exist */ + + ret = property_delete(key); + assert_int_not_equal(ret, 0); } -} \ No newline at end of file +} diff --git a/testsuites/kernel/kv/cases/kv_test_006.c b/testsuites/kernel/kv/cases/kv_test_006.c index 66291d0..f748c5f 100644 --- a/testsuites/kernel/kv/cases/kv_test_006.c +++ b/testsuites/kernel/kv/cases/kv_test_006.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_006.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -23,65 +43,88 @@ /**************************************************************************** * Name: test_string ****************************************************************************/ + static void test_string(int run_num) { - int ret; - char key[TEST_KEY_LENGTH] = {0}; - char data[TEST_VALUE_LENGTH] = {0}; - char value[TEST_VALUE_LENGTH] = {0}; - for (int i = 0; i < run_num; i++) + int ret; + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + char data[TEST_VALUE_LENGTH] = + { + 0 + }; + + char value[TEST_VALUE_LENGTH] = + { + 0 + }; + + for (int i = 0; i < run_num; i++) { - sprintf(key, "test_key_%s_%d", __func__, i); - sprintf(data, "test_data_%s_%d", __func__, i); - ret = property_set(key, data); - assert_int_equal(ret, 0); - ret = property_get(key, value, ""); - assert_int_in_range(ret, 0, TEST_VALUE_LENGTH + 1); - assert_int_equal(strcmp(value, data), 0); - property_delete(key); + sprintf(key, "test_key_%s_%d", __func__, i); + sprintf(data, "test_data_%s_%d", __func__, i); + ret = property_set(key, data); + assert_int_equal(ret, 0); + ret = property_get(key, value, ""); + assert_int_in_range(ret, 0, TEST_VALUE_LENGTH + 1); + assert_int_equal(strcmp(value, data), 0); + property_delete(key); } } /**************************************************************************** * Name: test_int32 ****************************************************************************/ + static void test_int32(int run_num) { - char key[TEST_KEY_LENGTH] = {0}; - int32_t data; - int32_t value; - int ret; - for (int i = 0; i < run_num; i++) + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + int32_t data; + int32_t value; + int ret; + for (int i = 0; i < run_num; i++) { - sprintf(key, "test_key_%s_%d", __func__, i); - data = rand() % INT32_MAX + 1; - ret = property_set_int32(key, data); - assert_int_equal(ret, 0); - value = property_get_int32(key, 0); - assert_int_equal(value, data); - property_delete(key); + sprintf(key, "test_key_%s_%d", __func__, i); + data = rand() % INT32_MAX + 1; + ret = property_set_int32(key, data); + assert_int_equal(ret, 0); + value = property_get_int32(key, 0); + assert_int_equal(value, data); + property_delete(key); } } /**************************************************************************** * Name: test_int64 ****************************************************************************/ + #ifdef CONFIG_LIBC_LONG_LONG static void test_int64(int run_num) { - char key[TEST_KEY_LENGTH] = {0}; - int64_t data; - int64_t value; - int ret; - for (int i = 0; i < run_num; i++) + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + int64_t data; + int64_t value; + int ret; + for (int i = 0; i < run_num; i++) { - sprintf(key, "test_key_%s_%d", __func__, i); - data = rand() % INT64_MAX + 1; - ret = property_set_int64(key, data); - assert_int_equal(ret, 0); - value = property_get_int64(key, 0); - assert_int_equal(value, data); - property_delete(key); + sprintf(key, "test_key_%s_%d", __func__, i); + data = rand() % INT64_MAX + 1; + ret = property_set_int64(key, data); + assert_int_equal(ret, 0); + value = property_get_int64(key, 0); + assert_int_equal(value, data); + property_delete(key); } } #endif @@ -89,22 +132,27 @@ static void test_int64(int run_num) /**************************************************************************** * Name: test_bool ****************************************************************************/ + static void test_bool(int run_num) { - char key[TEST_KEY_LENGTH] = {0}; - int data; - int ret; - int value; - for (int i = 0; i < run_num; i++) + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + int data; + int ret; + int value; + for (int i = 0; i < run_num; i++) { - srand((unsigned)time(NULL) + i); - data = rand() % 2; - sprintf(key, "test_key_%s_%d", __func__, i); - ret = property_set_bool(key, data); - assert_int_equal(ret, 0); - value = property_get_bool(key, 0); - assert_int_equal(value, data); - property_delete(key); + srand((unsigned)time(NULL) + i); + data = rand() % 2; + sprintf(key, "test_key_%s_%d", __func__, i); + ret = property_set_bool(key, data); + assert_int_equal(ret, 0); + value = property_get_bool(key, 0); + assert_int_equal(value, data); + property_delete(key); } } @@ -113,15 +161,16 @@ static void test_bool(int run_num) ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv06 + * Name: test_nuttx_kv06 ****************************************************************************/ -void TestNuttxKv06(FAR void **state) + +void test_nuttx_kv06(FAR void **state) { - int test_run = 20; - test_string(test_run); - test_int32(test_run); + int test_run = 10; + test_string(test_run); + test_int32(test_run); #ifdef CONFIG_LIBC_LONG_LONG - test_int64(test_run); + test_int64(test_run); #endif - test_bool(test_run); -} \ No newline at end of file + test_bool(test_run); +} diff --git a/testsuites/kernel/kv/cases/kv_test_007.c b/testsuites/kernel/kv/cases/kv_test_007.c index 89ca837..4cbbb41 100644 --- a/testsuites/kernel/kv/cases/kv_test_007.c +++ b/testsuites/kernel/kv/cases/kv_test_007.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_007.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -21,55 +41,73 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv07 + * Name: test_nuttx_kv07 ****************************************************************************/ -void TestNuttxKv07(FAR void **state) + +void test_nuttx_kv07(FAR void **state) { - char key[TEST_KEY_LENGTH] = {0}; - char old_data_string[TEST_VALUE_LENGTH] = {0}; - char new_data_string[TEST_VALUE_LENGTH] = {0}; - char value[TEST_VALUE_LENGTH] = {0}; - int32_t data_32, value_32; - bool data_bool = false; - bool value_bool; - int ret; - - sprintf(key, "test_key_%s", __func__); - sprintf(old_data_string, "test_data_%s_new", __func__); - ret = property_set(key, old_data_string); - assert_int_equal(ret, 0); - - sprintf(new_data_string, "test_data_%s_old", __func__); - ret = property_set(key, new_data_string); - assert_int_equal(ret, 0); - - property_get(key, value, ""); - assert_int_equal(strcmp(value, new_data_string), 0); - property_delete(key); - - sprintf(key, "test_key_%s", __func__); - data_32 = rand() % INT32_MAX + 1; - ret = property_set_int32(key, data_32); - assert_int_equal(ret, 0); - - value_32 = property_get_int32(key, 0); - assert_int_equal(value_32, data_32); + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + char old_data_string[TEST_VALUE_LENGTH] = + { + 0 + }; + + char new_data_string[TEST_VALUE_LENGTH] = + { + 0 + }; + + char value[TEST_VALUE_LENGTH] = + { + 0 + }; + + int32_t data_32; + int32_t value_32; + bool data_bool = false; + bool value_bool; + int ret; + + sprintf(key, "test_key_%s", __func__); + sprintf(old_data_string, "test_data_%s_new", __func__); + ret = property_set(key, old_data_string); + assert_int_equal(ret, 0); + + sprintf(new_data_string, "test_data_%s_old", __func__); + ret = property_set(key, new_data_string); + assert_int_equal(ret, 0); + + property_get(key, value, ""); + assert_int_equal(strcmp(value, new_data_string), 0); + property_delete(key); + + sprintf(key, "test_key_%s", __func__); + data_32 = rand() % INT32_MAX + 1; + ret = property_set_int32(key, data_32); + assert_int_equal(ret, 0); + + value_32 = property_get_int32(key, 0); + assert_int_equal(value_32, data_32); #ifdef CONFIG_LIBC_LONG_LONG - int64_t data_64, value_64; - data_64 = rand() % INT64_MAX + 1; - ret = property_set_int64(key, data_64); - assert_int_equal(ret, 0); + int64_t data_64, value_64; + data_64 = rand() % INT64_MAX + 1; + ret = property_set_int64(key, data_64); + assert_int_equal(ret, 0); - value_64 = property_get_int64(key, 0); - assert_int_equal(value_64, data_64); + value_64 = property_get_int64(key, 0); + assert_int_equal(value_64, data_64); #endif - ret = property_set_bool(key, data_bool); - assert_int_equal(ret, 0); + ret = property_set_bool(key, data_bool); + assert_int_equal(ret, 0); - value_bool = property_get_bool(key, 0); - assert_int_equal(value_bool, data_bool); + value_bool = property_get_bool(key, 0); + assert_int_equal(value_bool, data_bool); - property_delete(key); -} \ No newline at end of file + property_delete(key); +} diff --git a/testsuites/kernel/kv/cases/kv_test_008.c b/testsuites/kernel/kv/cases/kv_test_008.c index a20b15e..4b75470 100644 --- a/testsuites/kernel/kv/cases/kv_test_008.c +++ b/testsuites/kernel/kv/cases/kv_test_008.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_008.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -21,23 +41,36 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv08 + * Name: test_nuttx_kv08 ****************************************************************************/ -void TestNuttxKv08(FAR void **state) + +void test_nuttx_kv08(FAR void **state) { - char key[TEST_KEY_LENGTH] = {0}; - char data[TEST_VALUE_LENGTH] = {0}; - char value[TEST_VALUE_LENGTH] = {0}; - int ret; + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + char data[TEST_VALUE_LENGTH] = + { + 0 + }; + + char value[TEST_VALUE_LENGTH] = + { + 0 + }; + + int ret; - for (int i = 0; i < 100; i++) + for (int i = 0; i < 100; i++) { - sprintf(key, "test_key_%s_%d", __func__, i); - sprintf(data, "test_data_%s_new", __func__); - ret = property_set(key, data); - assert_int_equal(ret, 0); - property_get(key, value, ""); - assert_int_equal(strcmp(value, data), 0); - property_delete(key); + sprintf(key, "test_key_%s_%d", __func__, i); + sprintf(data, "test_data_%s_new", __func__); + ret = property_set(key, data); + assert_int_equal(ret, 0); + property_get(key, value, ""); + assert_int_equal(strcmp(value, data), 0); + property_delete(key); } -} \ No newline at end of file +} diff --git a/testsuites/kernel/kv/cases/kv_test_009.c b/testsuites/kernel/kv/cases/kv_test_009.c index f7ceb65..2a2e1ba 100644 --- a/testsuites/kernel/kv/cases/kv_test_009.c +++ b/testsuites/kernel/kv/cases/kv_test_009.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_009.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -20,21 +40,30 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv09 + * Name: test_nuttx_kv09 ****************************************************************************/ -void TestNuttxKv09(FAR void **state) + +void test_nuttx_kv09(FAR void **state) { - char key[TEST_KEY_LENGTH] = {0}; - char delete_data[TEST_VALUE_LENGTH] = {0}; - int ret; + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + char delete_data[TEST_VALUE_LENGTH] = + { + 0 + }; + + int ret; - for (int i = 0; i < 10; i++) + for (int i = 0; i < 10; i++) { - sprintf(key, "test_key_%s_%d", __func__, i); - sprintf(delete_data, "test_data_%s_new", __func__); - ret = property_set(key, delete_data); - assert_int_equal(ret, 0); - ret = property_delete(key); - assert_int_equal(ret, 0); + sprintf(key, "test_key_%s_%d", __func__, i); + sprintf(delete_data, "test_data_%s_new", __func__); + ret = property_set(key, delete_data); + assert_int_equal(ret, 0); + ret = property_delete(key); + assert_int_equal(ret, 0); } -} \ No newline at end of file +} diff --git a/testsuites/kernel/kv/cases/kv_test_010.c b/testsuites/kernel/kv/cases/kv_test_010.c index 5bdefd7..d2361a4 100644 --- a/testsuites/kernel/kv/cases/kv_test_010.c +++ b/testsuites/kernel/kv/cases/kv_test_010.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_010.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -21,22 +41,35 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv10 + * Name: test_nuttx_kv10 ****************************************************************************/ -void TestNuttxKv10(FAR void **state) + +void test_nuttx_kv10(FAR void **state) { - char key[TEST_KEY_LENGTH] = {0}; - char get_data[TEST_VALUE_LENGTH] = {0}; - char get_value[TEST_VALUE_LENGTH] = {0}; - int ret; - - sprintf(key, "test_key_%s", __func__); - sprintf(get_data, "test_data_%s_old", __func__); - ret = property_set(key, get_data); - assert_int_equal(ret, 0); - - sprintf(get_value, "test_data_%s_new_data", __func__); - ret = property_get(key, get_value, NULL); - assert_int_equal(ret, strlen(get_value)); - property_delete(key); -} \ No newline at end of file + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + char get_data[TEST_VALUE_LENGTH] = + { + 0 + }; + + char get_value[TEST_VALUE_LENGTH] = + { + 0 + }; + + int ret; + + sprintf(key, "test_key_%s", __func__); + sprintf(get_data, "test_data_%s_old", __func__); + ret = property_set(key, get_data); + assert_int_equal(ret, 0); + + sprintf(get_value, "test_data_%s_new_data", __func__); + ret = property_get(key, get_value, NULL); + assert_int_equal(ret, strlen(get_value)); + property_delete(key); +} diff --git a/testsuites/kernel/kv/cases/kv_test_011.c b/testsuites/kernel/kv/cases/kv_test_011.c index f62f8da..1b97780 100644 --- a/testsuites/kernel/kv/cases/kv_test_011.c +++ b/testsuites/kernel/kv/cases/kv_test_011.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_011.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -21,15 +41,20 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv11 + * Name: test_nuttx_kv11 ****************************************************************************/ -void TestNuttxKv11(FAR void **state) + +void test_nuttx_kv11(FAR void **state) { - char key[TEST_KEY_LENGTH] = {0}; - int8_t getbool_ret; - sprintf(key, "test_key_%s", __func__); - property_set_bool(key, 1); - getbool_ret = property_get_bool(key, 0); - assert_int_equal(getbool_ret, 1); - property_delete(key); -} \ No newline at end of file + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + int8_t getbool_ret; + sprintf(key, "test_key_%s", __func__); + property_set_bool(key, 1); + getbool_ret = property_get_bool(key, 0); + assert_int_equal(getbool_ret, 1); + property_delete(key); +} diff --git a/testsuites/kernel/kv/cases/kv_test_012.c b/testsuites/kernel/kv/cases/kv_test_012.c index f795f79..f9e5fa5 100644 --- a/testsuites/kernel/kv/cases/kv_test_012.c +++ b/testsuites/kernel/kv/cases/kv_test_012.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_012.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -20,27 +40,32 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv12 + * Name: test_nuttx_kv12 ****************************************************************************/ -void TestNuttxKv12(FAR void **state) + +void test_nuttx_kv12(FAR void **state) { - char key[TEST_KEY_LENGTH] = {0}; - int32_t getint32_data1 = -2102323233; - int32_t getint32_data2 = 1054545457; - int32_t getint32_value; - int getint32_ret; - sprintf(key, "test_key_%s", __func__); - getint32_ret = property_set_int32(key, getint32_data1); - assert_int_equal(getint32_ret, 0); - - getint32_value = property_get_int32(key, 0); - assert_int_equal(getint32_value, getint32_data1); - property_delete(key); - - getint32_ret = property_set_int32(key, getint32_data2); - assert_int_equal(getint32_ret, 0); - - getint32_value = property_get_int32(key, 0); - assert_int_equal(getint32_value, getint32_data2); - property_delete(key); -} \ No newline at end of file + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + int32_t getint32_data1 = -2102323233; + int32_t getint32_data2 = 1054545457; + int32_t getint32_value; + int getint32_ret; + sprintf(key, "test_key_%s", __func__); + getint32_ret = property_set_int32(key, getint32_data1); + assert_int_equal(getint32_ret, 0); + + getint32_value = property_get_int32(key, 0); + assert_int_equal(getint32_value, getint32_data1); + property_delete(key); + + getint32_ret = property_set_int32(key, getint32_data2); + assert_int_equal(getint32_ret, 0); + + getint32_value = property_get_int32(key, 0); + assert_int_equal(getint32_value, getint32_data2); + property_delete(key); +} diff --git a/testsuites/kernel/kv/cases/kv_test_013.c b/testsuites/kernel/kv/cases/kv_test_013.c index 74e9d80..b152604 100644 --- a/testsuites/kernel/kv/cases/kv_test_013.c +++ b/testsuites/kernel/kv/cases/kv_test_013.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_013.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -20,29 +40,34 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv13 + * Name: test_nuttx_kv13 ****************************************************************************/ -void TestNuttxKv13(FAR void **state) + +void test_nuttx_kv13(FAR void **state) { - char key[TEST_KEY_LENGTH] = {0}; - int64_t getint64_data1 = INT64_MAX; - int64_t getint64_data2 = INT64_MIN; - int64_t getint64_value; - int getint64_ret; - - sprintf(key, "test_key_%s", __func__); - getint64_ret = property_set_int64(key, getint64_data1); - assert_int_equal(getint64_ret, 0); - - getint64_value = property_get_int64(key, 0); - assert_int_equal(getint64_value, getint64_data1); - property_delete(key); - - sprintf(key, "test_key_%s", __func__); - getint64_ret = property_set_int64(key, getint64_data2); - assert_int_equal(getint64_ret, 0); - - getint64_value = property_get_int64(key, 0); - assert_int_equal(getint64_value, getint64_data2); - property_delete(key); -} \ No newline at end of file + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + int64_t getint64_data1 = INT64_MAX; + int64_t getint64_data2 = INT64_MIN; + int64_t getint64_value; + int getint64_ret; + + sprintf(key, "test_key_%s", __func__); + getint64_ret = property_set_int64(key, getint64_data1); + assert_int_equal(getint64_ret, 0); + + getint64_value = property_get_int64(key, 0); + assert_int_equal(getint64_value, getint64_data1); + property_delete(key); + + sprintf(key, "test_key_%s", __func__); + getint64_ret = property_set_int64(key, getint64_data2); + assert_int_equal(getint64_ret, 0); + + getint64_value = property_get_int64(key, 0); + assert_int_equal(getint64_value, getint64_data2); + property_delete(key); +} diff --git a/testsuites/kernel/kv/cases/kv_test_014.c b/testsuites/kernel/kv/cases/kv_test_014.c index 8b0cf9e..7e5b533 100644 --- a/testsuites/kernel/kv/cases/kv_test_014.c +++ b/testsuites/kernel/kv/cases/kv_test_014.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_014.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -17,14 +37,14 @@ struct kv_struct { - char key[TEST_KEY_LENGTH]; - char value[TEST_VALUE_LENGTH]; - struct kv_struct *next; + char key[TEST_KEY_LENGTH]; + char value[TEST_VALUE_LENGTH]; + struct kv_struct *next; }; static struct kv_struct *head; static struct kv_struct *tail; -static void callback(const char* key, const char* value, void* cookie); +static void callback(const char *key, const char *value, void *cookie); static void freedata(void); /**************************************************************************** @@ -32,46 +52,54 @@ static void freedata(void); ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv14 + * Name: test_nuttx_kv14 ****************************************************************************/ -void TestNuttxKv14(FAR void **state) + +void test_nuttx_kv14(FAR void **state) { - int ret = 0; - char data[TEST_VALUE_LENGTH] = {0}; + int ret = 0; + char data[TEST_VALUE_LENGTH] = + { + 0 + }; - head = (struct kv_struct *)malloc(sizeof(struct kv_struct)); - tail = head; - property_list(callback, NULL); + head = (struct kv_struct *)zalloc(sizeof(struct kv_struct)); + tail = head; + property_list(callback, NULL); - for(struct kv_struct *item = head->next; item != NULL; item = item->next){ - syslog(LOG_INFO, "%s: %s\n", item->key, item->value); + for (struct kv_struct *item = head->next; item != NULL; + item = item->next) + { + syslog(LOG_INFO, "%s: %s\n", item->key, item->value); - ret = property_get(item->key, data, ""); - assert_int_equal(ret, strlen(item->value)); - assert_int_equal(strcmp(item->value, data), 0); + ret = property_get(item->key, data, ""); + assert_int_equal(ret, strlen(item->value)); + assert_int_equal(strcmp(item->value, data), 0); } - freedata(); + freedata(); } -static void callback(const char* key, const char* value, void* cookie){ +static void callback(const char *key, const char *value, void *cookie) +{ + struct kv_struct *data = + (struct kv_struct *)malloc(sizeof(struct kv_struct)); + strcpy(data->key, key); + strcpy(data->value, value); + data->next = NULL; - struct kv_struct *data = (struct kv_struct *)malloc(sizeof(struct kv_struct)); - strcpy(data->key, key); - strcpy(data->value, value); - data->next = NULL; - - tail->next = data; - tail = data; + tail->next = data; + tail = data; } -static void freedata(void){ +static void freedata(void) +{ + struct kv_struct *tmp; - struct kv_struct *tmp; - - while (head){ - tmp = head; - head = head->next; - free(tmp); + while (head) + { + tmp = head; + head = head->next; + free(tmp); }; -} \ No newline at end of file +} diff --git a/testsuites/kernel/kv/cases/kv_test_015.c b/testsuites/kernel/kv/cases/kv_test_015.c index c17117d..c1f78ee 100644 --- a/testsuites/kernel/kv/cases/kv_test_015.c +++ b/testsuites/kernel/kv/cases/kv_test_015.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_015.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -20,19 +40,28 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv15 + * Name: test_nuttx_kv15 ****************************************************************************/ -void TestNuttxKv15(FAR void **state) + +void test_nuttx_kv15(FAR void **state) { - char key[TEST_KEY_LENGTH] = {0}; - char set_data[TEST_VALUE_LENGTH] = {0}; - int set_ret; - - sprintf(key, "test_key_%s", __func__); - sprintf(set_data, "test_data_%s_new", __func__); - set_ret = property_set(key, set_data); - assert_int_equal(set_ret, 0); - - set_ret = property_delete(key); - assert_int_equal(set_ret, 0); -} \ No newline at end of file + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + char set_data[TEST_VALUE_LENGTH] = + { + 0 + }; + + int set_ret; + + sprintf(key, "test_key_%s", __func__); + sprintf(set_data, "test_data_%s_new", __func__); + set_ret = property_set(key, set_data); + assert_int_equal(set_ret, 0); + + set_ret = property_delete(key); + assert_int_equal(set_ret, 0); +} diff --git a/testsuites/kernel/kv/cases/kv_test_016.c b/testsuites/kernel/kv/cases/kv_test_016.c index c44f81d..b5f7653 100644 --- a/testsuites/kernel/kv/cases/kv_test_016.c +++ b/testsuites/kernel/kv/cases/kv_test_016.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_016.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -20,20 +40,25 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv16 + * Name: test_nuttx_kv16 ****************************************************************************/ -void TestNuttxKv16(FAR void **state) + +void test_nuttx_kv16(FAR void **state) { - char key[TEST_KEY_LENGTH] = {0}; - int setbool_ret; + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + int setbool_ret; - sprintf(key, "test_key_%s", __func__); - setbool_ret = property_set_bool(key, 1); - assert_int_equal(setbool_ret, 0); - property_delete(key); + sprintf(key, "test_key_%s", __func__); + setbool_ret = property_set_bool(key, 1); + assert_int_equal(setbool_ret, 0); + property_delete(key); - sprintf(key, "test_key_%s", __func__); - setbool_ret = property_set_bool(key, 0); - assert_int_equal(setbool_ret, 0); - property_delete(key); -} \ No newline at end of file + sprintf(key, "test_key_%s", __func__); + setbool_ret = property_set_bool(key, 0); + assert_int_equal(setbool_ret, 0); + property_delete(key); +} diff --git a/testsuites/kernel/kv/cases/kv_test_017.c b/testsuites/kernel/kv/cases/kv_test_017.c index b83d970..baa46c8 100644 --- a/testsuites/kernel/kv/cases/kv_test_017.c +++ b/testsuites/kernel/kv/cases/kv_test_017.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_017.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -20,40 +40,45 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv17 + * Name: test_nuttx_kv17 ****************************************************************************/ -void TestNuttxKv17(FAR void **state) + +void test_nuttx_kv17(FAR void **state) { - char key[TEST_KEY_LENGTH] = {0}; - int32_t setint32_data1 = -2147483648; - int32_t setint32_data2 = -2135555587; - int32_t setint32_data3 = 0; - int32_t setint32_data4 = 1135555587; - int32_t setint32_data5 = 2147483647; - int setint32_ret; - - sprintf(key, "test_key_%s_1", __func__); - setint32_ret = property_set_int32(key, setint32_data1); - assert_int_equal(setint32_ret, 0); - property_delete(key); - - sprintf(key, "test_key_%s_2", __func__); - setint32_ret = property_set_int32(key, setint32_data2); - assert_int_equal(setint32_ret, 0); - property_delete(key); - - sprintf(key, "test_key_%s_3", __func__); - setint32_ret = property_set_int32(key, setint32_data3); - assert_int_equal(setint32_ret, 0); - property_delete(key); - - sprintf(key, "test_key_%s_4", __func__); - setint32_ret = property_set_int32(key, setint32_data4); - assert_int_equal(setint32_ret, 0); - property_delete(key); - - sprintf(key, "test_key_%s__5", __func__); - setint32_ret = property_set_int32(key, setint32_data5); - assert_int_equal(setint32_ret, 0); - property_delete(key); -} \ No newline at end of file + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + int32_t setint32_data1 = -2147483648; + int32_t setint32_data2 = -2135555587; + int32_t setint32_data3 = 0; + int32_t setint32_data4 = 1135555587; + int32_t setint32_data5 = 2147483647; + int setint32_ret; + + sprintf(key, "test_key_%s_1", __func__); + setint32_ret = property_set_int32(key, setint32_data1); + assert_int_equal(setint32_ret, 0); + property_delete(key); + + sprintf(key, "test_key_%s_2", __func__); + setint32_ret = property_set_int32(key, setint32_data2); + assert_int_equal(setint32_ret, 0); + property_delete(key); + + sprintf(key, "test_key_%s_3", __func__); + setint32_ret = property_set_int32(key, setint32_data3); + assert_int_equal(setint32_ret, 0); + property_delete(key); + + sprintf(key, "test_key_%s_4", __func__); + setint32_ret = property_set_int32(key, setint32_data4); + assert_int_equal(setint32_ret, 0); + property_delete(key); + + sprintf(key, "test_key_%s__5", __func__); + setint32_ret = property_set_int32(key, setint32_data5); + assert_int_equal(setint32_ret, 0); + property_delete(key); +} diff --git a/testsuites/kernel/kv/cases/kv_test_018.c b/testsuites/kernel/kv/cases/kv_test_018.c index 5376536..3469eda 100644 --- a/testsuites/kernel/kv/cases/kv_test_018.c +++ b/testsuites/kernel/kv/cases/kv_test_018.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_018.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -20,40 +40,45 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv18 + * Name: test_nuttx_kv18 ****************************************************************************/ -void TestNuttxKv18(FAR void **state) + +void test_nuttx_kv18(FAR void **state) { - char key[TEST_KEY_LENGTH] = {0}; - int64_t setint64_data1 = INT64_MIN + 1; - int64_t setint64_data2 = -6727346527346527834; - int64_t setint64_data3 = 0; - int64_t setint64_data4 = 8757357537575373757; - int64_t setint64_data5 = 9223372036854775807; - int setint64_ret; - - sprintf(key, "test_key_%s_1", __func__); - setint64_ret = property_set_int64(key, setint64_data1); - assert_int_equal(setint64_ret, 0); - property_delete(key); - - sprintf(key, "test_key_%s_2", __func__); - setint64_ret = property_set_int64(key, setint64_data2); - assert_int_equal(setint64_ret, 0); - property_delete(key); - - sprintf(key, "test_key_%s_3", __func__); - setint64_ret = property_set_int64(key, setint64_data3); - assert_int_equal(setint64_ret, 0); - property_delete(key); - - sprintf(key, "test_key_%s_4", __func__); - setint64_ret = property_set_int64(key, setint64_data4); - assert_int_equal(setint64_ret, 0); - property_delete(key); - - sprintf(key, "test_key_%s_5", __func__); - setint64_ret = property_set_int64(key, setint64_data5); - assert_int_equal(setint64_ret, 0); - property_delete(key); -} \ No newline at end of file + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + int64_t setint64_data1 = INT64_MIN + 1; + int64_t setint64_data2 = -6727346527346527834; + int64_t setint64_data3 = 0; + int64_t setint64_data4 = 8757357537575373757; + int64_t setint64_data5 = 9223372036854775807; + int setint64_ret; + + sprintf(key, "test_key_%s_1", __func__); + setint64_ret = property_set_int64(key, setint64_data1); + assert_int_equal(setint64_ret, 0); + property_delete(key); + + sprintf(key, "test_key_%s_2", __func__); + setint64_ret = property_set_int64(key, setint64_data2); + assert_int_equal(setint64_ret, 0); + property_delete(key); + + sprintf(key, "test_key_%s_3", __func__); + setint64_ret = property_set_int64(key, setint64_data3); + assert_int_equal(setint64_ret, 0); + property_delete(key); + + sprintf(key, "test_key_%s_4", __func__); + setint64_ret = property_set_int64(key, setint64_data4); + assert_int_equal(setint64_ret, 0); + property_delete(key); + + sprintf(key, "test_key_%s_5", __func__); + setint64_ret = property_set_int64(key, setint64_data5); + assert_int_equal(setint64_ret, 0); + property_delete(key); +} diff --git a/testsuites/kernel/kv/cases/kv_test_019.c b/testsuites/kernel/kv/cases/kv_test_019.c index 76c4dbf..96fc2aa 100644 --- a/testsuites/kernel/kv/cases/kv_test_019.c +++ b/testsuites/kernel/kv/cases/kv_test_019.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_019.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -5,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -23,33 +44,48 @@ /**************************************************************************** * Name: store_data ****************************************************************************/ + static void *store_data(void *arg) { + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + char data[TEST_VALUE_LENGTH] = + { + 0 + }; - char key[TEST_KEY_LENGTH] = {0}; - char data[TEST_VALUE_LENGTH] = {0}; - int ret; - for (int k = 0; k < 100; k++) + int ret; + for (int k = 0; k < 30; k++) { - sprintf(key, "TestNuttxKv19-%d-%d", gettid(), k); - sprintf(data, "test_data_%s_%d_%d", __func__, gettid(), k); - ret = property_set(key, data); - if (ret != 0) + sprintf(key, "test_nuttx_kv19-%d-%d", gettid(), k); + sprintf(data, "test_data_%s_%d_%d", __func__, gettid(), k); + ret = property_set(key, data); + if (ret != 0) { - syslog(LOG_ERR, "Failed to insert data. The test thread number:%d Key:%s value:%s\n", gettid(), key, data); - (*((int *)arg)) = -1; - return NULL; + syslog(LOG_ERR, + "Failed to insert data. The test thread number:%d " + "Key:%s value:%s\n", + gettid(), key, data); + (*((int *)arg)) = -1; + return NULL; } - ret = property_delete(key); - if (ret != 0) + ret = property_delete(key); + if (ret != 0) { - syslog(LOG_ERR, "Failed to delete data. The test thread number:%d Key:%s value:%s\n", gettid(), key, data); - (*((int *)arg)) = -1; - return NULL; + syslog(LOG_ERR, + "Failed to delete data. The test thread number:%d " + "Key:%s value:%s\n", + gettid(), key, data); + (*((int *)arg)) = -1; + return NULL; } } - return NULL; + + return NULL; } /**************************************************************************** @@ -57,24 +93,34 @@ static void *store_data(void *arg) ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv19 + * Name: test_nuttx_kv19 ****************************************************************************/ -void TestNuttxKv19(FAR void **state) + +void test_nuttx_kv19(FAR void **state) { - pthread_t nthread[10]; - int status; - int num_thread = 3; - int test_flag = 0; + pthread_t nthread[10]; + pthread_attr_t attr; + int status; + int num_thread = 3; + int test_flag = 0; + + status = pthread_attr_init(&attr); + assert_int_equal(status, 0); + status = pthread_attr_setstacksize(&attr, 8192); + assert_int_equal(status, 0); - for (int i = 0; i < num_thread; i++) + for (int i = 0; i < num_thread; i++) { - /* creat test thread */ - status = pthread_create(&nthread[i], NULL, store_data, &test_flag); - assert_int_equal(status, 0); + /* creat test thread */ + + status = pthread_create(&nthread[i], &attr, store_data, &test_flag); + assert_int_equal(status, 0); } - for (int j = 0; j < num_thread; j++) - pthread_join(nthread[j], NULL); - /* Check whether any child threads failed to run */ - assert_int_equal(test_flag, 0); + for (int j = 0; j < num_thread; j++) + pthread_join(nthread[j], NULL); + + /* Check whether any child threads failed to run */ + + assert_int_equal(test_flag, 0); } diff --git a/testsuites/kernel/kv/cases/kv_test_020.c b/testsuites/kernel/kv/cases/kv_test_020.c index e3e9620..61cd13b 100644 --- a/testsuites/kernel/kv/cases/kv_test_020.c +++ b/testsuites/kernel/kv/cases/kv_test_020.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_020.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -22,34 +42,46 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv20 + * Name: test_nuttx_kv20 ****************************************************************************/ -void TestNuttxKv20(FAR void **state) + +void test_nuttx_kv20(FAR void **state) { - char data[TEST_VALUE_LENGTH] = {0}; - struct timespec t_start; - struct timespec t_end; - long timedif; - int ret; - char key[32] = {0}; - int test_round = 3000; - - sprintf(data, "test_data_%s", __func__); - clock_gettime(CLOCK_MONOTONIC, &t_start); - for (int i = 0; i < test_round; i++) + char data[TEST_VALUE_LENGTH] = + { + 0 + }; + + struct timespec t_start; + struct timespec t_end; + long timedif; + int ret; + char key[32] = + { + 0 + }; + + int test_round = 300; + + sprintf(data, "test_data_%s", __func__); + clock_gettime(CLOCK_MONOTONIC, &t_start); + for (int i = 0; i < test_round; i++) { - sprintf(key, "%s%s-%d", KV_TEST_PREFIX, __func__, i); - ret = property_set(key, data); - assert_int_equal(ret, 0); + sprintf(key, "%s%s-%d", KV_TEST_PREFIX, __func__, i); + ret = property_set(key, data); + assert_int_equal(ret, 0); } - clock_gettime(CLOCK_MONOTONIC, &t_end); - timedif = 1000000 * (t_end.tv_sec - t_start.tv_sec) + (t_end.tv_nsec - t_start.tv_nsec) / 1000; - syslog(LOG_INFO, "set data:%d takes:%ld microseconds\n", test_round, timedif); - for (int k = 0; k < test_round; k++) + clock_gettime(CLOCK_MONOTONIC, &t_end); + timedif = 1000000 * (t_end.tv_sec - t_start.tv_sec) + + (t_end.tv_nsec - t_start.tv_nsec) / 1000; + syslog(LOG_INFO, "set data:%d takes:%ld microseconds\n", test_round, + timedif); + + for (int k = 0; k < test_round; k++) { - sprintf(key, "%s%s-%d", KV_TEST_PREFIX, __func__, k); - ret = property_delete(key); - assert_int_equal(ret, 0); + sprintf(key, "%s%s-%d", KV_TEST_PREFIX, __func__, k); + ret = property_delete(key); + assert_int_equal(ret, 0); } -} \ No newline at end of file +} diff --git a/testsuites/kernel/kv/cases/kv_test_021.c b/testsuites/kernel/kv/cases/kv_test_021.c index 983e0ad..34fec2c 100644 --- a/testsuites/kernel/kv/cases/kv_test_021.c +++ b/testsuites/kernel/kv/cases/kv_test_021.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_021.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -23,32 +43,56 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv21 + * Name: test_nuttx_kv21 ****************************************************************************/ -void TestNuttxKv21(FAR void **state){ +void test_nuttx_kv21(FAR void **state) +{ + char *str = "persist.test.kv.reload=test"; + FILE *file; + int ret; + + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + char value[TEST_VALUE_LENGTH] = + { + 0 + }; + + char data[TEST_VALUE_LENGTH] = + { + 0 + }; + + if (strlen(CONFIG_KVDB_LOAD_TEST_SOURCE_PATH) == 0) + return; + + strcpy(key, "persist.test.kv.reload"); + strcpy(value, "test"); + + /* open test path */ + + file = fopen(CONFIG_KVDB_LOAD_TEST_SOURCE_PATH, "w"); + assert_non_null(file); + + fputs(str, file); + fclose(file); + + /* load */ - int ret = 0; - char key[TEST_KEY_LENGTH] = {0}; - char value[TEST_VALUE_LENGTH] = {0}; - char data[TEST_VALUE_LENGTH] = {0}; + property_load(CONFIG_KVDB_LOAD_TEST_SOURCE_PATH); - strcpy(key, "persist.test.kv.reload"); - strcpy(value, "test"); + /* get key */ - // get key - ret = property_get(key, data, ""); - assert_int_equal(ret, strlen(value)); - assert_int_equal(strcmp(value, data), 0); - - // delete persist key - ret = property_delete(key); - assert_int_equal(ret, 0); + ret = property_get(key, data, ""); + assert_int_equal(ret, strlen(value)); + assert_int_equal(strcmp(value, data), 0); - property_reload(); + /* del key */ - // get key - ret = property_get(key, data, ""); - assert_int_equal(ret, strlen(value)); - assert_int_equal(strcmp(value, data), 0); + ret = property_delete(key); + assert_int_equal(ret, 0); } diff --git a/testsuites/kernel/kv/cases/kv_test_022.c b/testsuites/kernel/kv/cases/kv_test_022.c index 8d41227..2137890 100644 --- a/testsuites/kernel/kv/cases/kv_test_022.c +++ b/testsuites/kernel/kv/cases/kv_test_022.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_022.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -23,37 +43,53 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv22 + * Name: test_nuttx_kv22 ****************************************************************************/ -void TestNuttxKv22(FAR void **state){ - int ret; - char key[50] = {0}, data[50] = {0}, value[50] = {0}; - - /* test key */ - strcpy(key, "test_key_buffer"); - /* test data */ - strcpy(value, "test_value_buffer"); - - ret = property_set_buffer(key, value, 50); - assert_int_equal(ret, 0); - - ret = property_get_buffer(key, data, 50); - assert_int_equal(ret, 50); - assert_int_equal(strcmp(value, data), 0); - - strcat(value, "2"); - ret = property_set_buffer(key, value, 50); - assert_int_equal(ret, 0); - - ret = property_get_buffer(key, data, 50); - assert_int_equal(ret, 50); - assert_int_equal(strcmp(value, data), 0); - - ret = property_delete(key); - assert_int_equal(ret, 0); - - ret = property_get_buffer(key, data, 50); - assert_int_not_equal(ret, 0); - -} \ No newline at end of file +void test_nuttx_kv22(FAR void **state) +{ + int ret; + char key[50] = + { + 0 + }; + + char data[50] = + { + 0 + }; + + char value[50] = + { + 0 + }; + + /* test key */ + + strcpy(key, "test_key_buffer"); + + /* test data */ + + strcpy(value, "test_value_buffer"); + + ret = property_set_buffer(key, value, 50); + assert_int_equal(ret, 0); + + ret = property_get_buffer(key, data, 50); + assert_int_equal(ret, 50); + assert_int_equal(strcmp(value, data), 0); + + strcat(value, "2"); + ret = property_set_buffer(key, value, 50); + assert_int_equal(ret, 0); + + ret = property_get_buffer(key, data, 50); + assert_int_equal(ret, 50); + assert_int_equal(strcmp(value, data), 0); + + ret = property_delete(key); + assert_int_equal(ret, 0); + + ret = property_get_buffer(key, data, 50); + assert_int_not_equal(ret, 0); +} diff --git a/testsuites/kernel/kv/cases/kv_test_023.c b/testsuites/kernel/kv/cases/kv_test_023.c index 560152e..2ff25a1 100644 --- a/testsuites/kernel/kv/cases/kv_test_023.c +++ b/testsuites/kernel/kv/cases/kv_test_023.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_023.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -23,28 +43,45 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv23 + * Name: test_nuttx_kv23 ****************************************************************************/ -void TestNuttxKv23(FAR void **state){ - int ret; - char key[50] = {0}, data[50] = {0}, value[50] = {0}; - for (int i = 1; i <= 1000; i++) +void test_nuttx_kv23(FAR void **state) +{ + int ret; + char key[50] = + { + 0 + }; + + char data[50] = + { + 0 + }; + + char value[50] = + { + 0 + }; + + for (int i = 1; i <= 100; i++) { - /* test key */ - sprintf(key, "test_key_%d", i); - /* test data */ - sprintf(data, "test_data_%d", i); - - ret = property_set_buffer(key, data, 50); - assert_int_equal(ret, 0); - - ret = property_get_buffer(key, value, 50); - assert_int_equal(ret, 50); - assert_int_equal(strcmp(value, data), 0); - - ret = property_delete(key); - assert_int_equal(ret, 0); - } + /* test key */ -} \ No newline at end of file + sprintf(key, "test_key_%d", i); + + /* test data */ + + sprintf(data, "test_data_%d", i); + + ret = property_set_buffer(key, data, 50); + assert_int_equal(ret, 0); + + ret = property_get_buffer(key, value, 50); + assert_int_equal(ret, 50); + assert_int_equal(strcmp(value, data), 0); + + ret = property_delete(key); + assert_int_equal(ret, 0); + } +} diff --git a/testsuites/kernel/kv/cases/kv_test_024.c b/testsuites/kernel/kv/cases/kv_test_024.c index 847f308..a3afb42 100644 --- a/testsuites/kernel/kv/cases/kv_test_024.c +++ b/testsuites/kernel/kv/cases/kv_test_024.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_024.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -23,55 +43,77 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv24 + * Name: test_nuttx_kv24 ****************************************************************************/ -void TestNuttxKv24(FAR void **state){ - int ret; - char key[50] = {0}, data[50] = {0}, value[50] = {0}; +void test_nuttx_kv24(FAR void **state) +{ + int ret; + char key[50] = + { + 0 + }; + + char data[50] = + { + 0 + }; + + char value[50] = + { + 0 + }; - /* test key */ - strcpy(key, "persist.kv24_buffer"); - /* test data */ - strcpy(value, "test_value_kv24"); + /* test key */ - ret = property_set_buffer(key, value, 50); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + strcpy(key, "persist.kv24_buffer"); + + /* test data */ + + strcpy(value, "test_value_kv24"); + + ret = property_set_buffer(key, value, 50); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after inserting data. Key:%s Value:%s", key, value); - assert_int_equal(ret, 0); + syslog(LOG_ERR, + "Failed to commit after inserting data. Key:%s Value:%s", + key, value); + assert_int_equal(ret, 0); } - ret = property_get_buffer(key, data, 50); - assert_int_equal(ret, 50); - assert_int_equal(strcmp(value, data), 0); + ret = property_get_buffer(key, data, 50); + assert_int_equal(ret, 50); + assert_int_equal(strcmp(value, data), 0); - strcat(value, "2"); - ret = property_set_buffer(key, value, 50); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + strcat(value, "2"); + ret = property_set_buffer(key, value, 50); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after updating data. Key:%s Value:%s", key, value); - assert_int_equal(ret, 0); + syslog(LOG_ERR, + "Failed to commit after updating data. Key:%s Value:%s", + key, value); + assert_int_equal(ret, 0); } - ret = property_get_buffer(key, data, 50); - assert_int_equal(ret, 50); - assert_int_equal(strcmp(value, data), 0); + ret = property_get_buffer(key, data, 50); + assert_int_equal(ret, 50); + assert_int_equal(strcmp(value, data), 0); - ret = property_delete(key); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + ret = property_delete(key); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s Value:%s", key, value); - assert_int_equal(ret, 0); + syslog(LOG_ERR, + "Failed to commit after deleting data. Key:%s Value:%s", + key, value); + assert_int_equal(ret, 0); } - ret = property_get_buffer(key, data, 50); - assert_int_not_equal(ret, 0); - + ret = property_get_buffer(key, data, 50); + assert_int_not_equal(ret, 0); } diff --git a/testsuites/kernel/kv/cases/kv_test_025.c b/testsuites/kernel/kv/cases/kv_test_025.c index fdaf52c..1654d44 100644 --- a/testsuites/kernel/kv/cases/kv_test_025.c +++ b/testsuites/kernel/kv/cases/kv_test_025.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_025.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -21,40 +41,62 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv25 + * Name: test_nuttx_kv25 ****************************************************************************/ -void TestNuttxKv25(FAR void **state) + +void test_nuttx_kv25(FAR void **state) { - int ret; - char key[50] = {0}, data[50] = {0}, value[50] = {0}; + int ret; + char key[50] = + { + 0 + }; + + char data[50] = + { + 0 + }; - for (int i = 1; i <= 300; i++) + char value[50] = + { + 0 + }; + + for (int i = 1; i <= 30; i++) { - /* test key */ - sprintf(key, "persist.kv25_%d", i); - /* test data */ - sprintf(value, "test_value_kv25_%d_", i); - - ret = property_set_buffer(key, value, 50); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + /* test key */ + + sprintf(key, "persist.kv25_%d", i); + + /* test data */ + + sprintf(value, "test_value_kv25_%d_", i); + + ret = property_set_buffer(key, value, 50); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after inserting data. Key:%s Value:%s", key, value); - assert_int_equal(ret, 0); + syslog( + LOG_ERR, + "Failed to commit after inserting data. Key:%s Value:%s", + key, value); + assert_int_equal(ret, 0); } - ret = property_get_buffer(key, data, 50); - assert_int_equal(ret, 50); - assert_int_equal(strcmp(value, data), 0); + ret = property_get_buffer(key, data, 50); + assert_int_equal(ret, 50); + assert_int_equal(strcmp(value, data), 0); - ret = property_delete(key); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + ret = property_delete(key); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s Value:%s", key, value); - assert_int_equal(ret, 0); + syslog(LOG_ERR, + "Failed to commit after deleting data. Key:%s Value:%s", + key, value); + assert_int_equal(ret, 0); } } } diff --git a/testsuites/kernel/kv/cases/kv_test_026.c b/testsuites/kernel/kv/cases/kv_test_026.c index dce07b6..ba9ce4d 100644 --- a/testsuites/kernel/kv/cases/kv_test_026.c +++ b/testsuites/kernel/kv/cases/kv_test_026.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_026.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -21,36 +41,43 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv26 + * Name: test_nuttx_kv26 ****************************************************************************/ -void TestNuttxKv26(FAR void **state) + +void test_nuttx_kv26(FAR void **state) { - int ret; - char key[TEST_KEY_LENGTH] = {0}; - int8_t getbool_ret; + int ret; + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + int8_t getbool_ret; - for (int i = 1; i <= 300; i++) + for (int i = 1; i <= 30; i++) { - sprintf(key, "persist.kv26_bool_%d", i); - ret = property_set_bool(key, 1); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + sprintf(key, "persist.kv26_bool_%d", i); + ret = property_set_bool(key, 1); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after inserting data. Key:%s", key); - assert_int_equal(ret, 0); + syslog(LOG_ERR, + "Failed to commit after inserting data. Key:%s", key); + assert_int_equal(ret, 0); } - getbool_ret = property_get_bool(key, 0); - assert_int_equal(getbool_ret, 1); + getbool_ret = property_get_bool(key, 0); + assert_int_equal(getbool_ret, 1); - ret = property_delete(key); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + ret = property_delete(key); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s", key); - assert_int_equal(ret, 0); + syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s", + key); + assert_int_equal(ret, 0); } } } diff --git a/testsuites/kernel/kv/cases/kv_test_027.c b/testsuites/kernel/kv/cases/kv_test_027.c index 5a62108..d836439 100644 --- a/testsuites/kernel/kv/cases/kv_test_027.c +++ b/testsuites/kernel/kv/cases/kv_test_027.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_027.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -23,105 +43,128 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv27 + * Name: test_nuttx_kv27 ****************************************************************************/ -void TestNuttxKv27(FAR void **state){ - - int ret; - char key[TEST_KEY_LENGTH] = {0}; - int32_t test_int32_1, test_int32_2; - - /* test key */ - sprintf(key, "persist.kv27_int32_1"); - ret = property_set_int32(key, 2147483647); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + +void test_nuttx_kv27(FAR void **state) +{ + int ret; + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + int32_t test_int32_1; + int32_t test_int32_2; + + /* test key */ + + sprintf(key, "persist.kv27_int32_1"); + ret = property_set_int32(key, 2147483647); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after inserting data. Key:%s", key); - assert_int_equal(ret, 0); + syslog(LOG_ERR, "Failed to commit after inserting data. Key:%s", + key); + assert_int_equal(ret, 0); } - test_int32_1 = property_get_int32(key, 0); - assert_int_equal(test_int32_1, INT32_MAX); - ret = property_delete(key); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + test_int32_1 = property_get_int32(key, 0); + assert_int_equal(test_int32_1, INT32_MAX); + + ret = property_delete(key); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s", key); - assert_int_equal(ret, 0); + syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s", + key); + assert_int_equal(ret, 0); } - /* test key */ + /* test key */ + #ifdef CONFIG_LIBC_LONG_LONG - int64_t test_int64_1; - sprintf(key, "persist.kv27_int64_1"); - ret = property_set_int64(key, 9223372036854775807); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + int64_t test_int64_1; + sprintf(key, "persist.kv27_int64_1"); + ret = property_set_int64(key, 9223372036854775807); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after inserting data. Key:%s", key); - assert_int_equal(ret, 0); + syslog(LOG_ERR, "Failed to commit after inserting data. Key:%s", + key); + assert_int_equal(ret, 0); } - test_int64_1 = property_get_int64(key, 0); - assert_int_equal(test_int64_1, INT64_MAX); - ret = property_delete(key); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + test_int64_1 = property_get_int64(key, 0); + assert_int_equal(test_int64_1, INT64_MAX); + + ret = property_delete(key); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s", key); - assert_int_equal(ret, 0); + syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s", + key); + assert_int_equal(ret, 0); } + #endif - /* test key */ - sprintf(key, "persist.kv27_int32_2"); - ret = property_set_int32(key, -2147483648); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + /* test key */ + + sprintf(key, "persist.kv27_int32_2"); + ret = property_set_int32(key, -2147483648); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after inserting data. Key:%s", key); - assert_int_equal(ret, 0); + syslog(LOG_ERR, "Failed to commit after inserting data. Key:%s", + key); + assert_int_equal(ret, 0); } - test_int32_2 = property_get_int32(key, 0); - assert_int_equal(test_int32_2, INT32_MIN); - ret = property_delete(key); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + test_int32_2 = property_get_int32(key, 0); + assert_int_equal(test_int32_2, INT32_MIN); + + ret = property_delete(key); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s", key); - assert_int_equal(ret, 0); + syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s", + key); + assert_int_equal(ret, 0); } - /* test key */ + /* test key */ + #ifdef CONFIG_LIBC_LONG_LONG - int64_t test_int64_2; - sprintf(key, "persist.kv27_int64_2"); - ret = property_set_int64(key, INT64_MIN); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + int64_t test_int64_2; + sprintf(key, "persist.kv27_int64_2"); + ret = property_set_int64(key, INT64_MIN); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after inserting data. Key:%s", key); - assert_int_equal(ret, 0); + syslog(LOG_ERR, "Failed to commit after inserting data. Key:%s", + key); + assert_int_equal(ret, 0); } - test_int64_2 = property_get_int64(key, 0); - assert_int_equal(test_int64_2, INT64_MIN); - ret = property_delete(key); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + test_int64_2 = property_get_int64(key, 0); + assert_int_equal(test_int64_2, INT64_MIN); + + ret = property_delete(key); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s", key); - assert_int_equal(ret, 0); + syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s", + key); + assert_int_equal(ret, 0); } #endif -} \ No newline at end of file +} diff --git a/testsuites/kernel/kv/cases/kv_test_028.c b/testsuites/kernel/kv/cases/kv_test_028.c index 0f0d205..4c27f39 100644 --- a/testsuites/kernel/kv/cases/kv_test_028.c +++ b/testsuites/kernel/kv/cases/kv_test_028.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_028.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -23,62 +43,80 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv28 + * Name: test_nuttx_kv28 ****************************************************************************/ -void TestNuttxKv28(FAR void **state) + +void test_nuttx_kv28(FAR void **state) { - int ret; - char key[TEST_KEY_LENGTH] = {0}; - int32_t test_int32; + int ret; + char key[TEST_KEY_LENGTH] = + { + 0 + }; - for (int i = 1; i <= 300; i++) + int32_t test_int32; + int test_round = 30; + + for (int i = 1; i <= test_round; i++) { - sprintf(key, "persist.kv28_int32_%d", i); - ret = property_set_int32(key, i); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + sprintf(key, "persist.kv28_int32_%d", i); + ret = property_set_int32(key, i); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after inserting data. Key:%s Value:%d", key, i); - assert_int_equal(ret, 0); + syslog( + LOG_ERR, + "Failed to commit after inserting data. Key:%s Value:%d", + key, i); + assert_int_equal(ret, 0); } - test_int32 = property_get_int32(key, 0); - assert_int_equal(test_int32, i); - ret = property_delete(key); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + test_int32 = property_get_int32(key, 0); + assert_int_equal(test_int32, i); + + ret = property_delete(key); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s Value:%d", key, i); - assert_int_equal(ret, 0); + syslog(LOG_ERR, + "Failed to commit after deleting data. Key:%s Value:%d", + key, i); + assert_int_equal(ret, 0); } } #ifdef CONFIG_LIBC_LONG_LONG - int64_t test_int64; - for (int i = 1; i <= 300; i++) + int64_t test_int64; + for (int i = 1; i <= test_round; i++) { - sprintf(key, "persist.kv28_int64_%d", i); - ret = property_set_int64(key, i); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + sprintf(key, "persist.kv28_int64_%d", i); + ret = property_set_int64(key, i); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after inserting data. Key:%s Value:%d", key, i); - assert_int_equal(ret, 0); + syslog( + LOG_ERR, + "Failed to commit after inserting data. Key:%s Value:%d", + key, i); + assert_int_equal(ret, 0); } - test_int64 = property_get_int64(key, 0); - assert_int_equal(test_int64, i); - ret = property_delete(key); - assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + test_int64 = property_get_int64(key, 0); + assert_int_equal(test_int64, i); + + ret = property_delete(key); + assert_int_equal(ret, 0); + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s Value:%d", key, i); - assert_int_equal(ret, 0); + syslog(LOG_ERR, + "Failed to commit after deleting data. Key:%s Value:%d", + key, i); + assert_int_equal(ret, 0); } } #endif -} \ No newline at end of file +} diff --git a/testsuites/kernel/kv/cases/kv_test_029.c b/testsuites/kernel/kv/cases/kv_test_029.c index 041df00..c369d90 100644 --- a/testsuites/kernel/kv/cases/kv_test_029.c +++ b/testsuites/kernel/kv/cases/kv_test_029.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_029.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -23,41 +43,64 @@ ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv29 + * Name: test_nuttx_kv29 ****************************************************************************/ -void TestNuttxKv29(FAR void **state){ - int ret; - char key[50] = {0}, value[50] = {0}, data[50] = {0}; - for (int i = 1; i <= 300; i++) +void test_nuttx_kv29(FAR void **state) +{ + int ret; + char key[50] = + { + 0 + }; + + char value[50] = + { + 0 + }; + + char data[50] = + { + 0 + }; + + for (int i = 1; i <= 30; i++) { - /* test key */ - sprintf(key, "persist.kv29_%d", i); - /* test data */ - sprintf(value, "test_value_kv29_%d", i); + /* test key */ + + sprintf(key, "persist.kv29_%d", i); + + /* test data */ - ret = property_set(key, value); - assert_int_equal(ret, 0); + sprintf(value, "test_value_kv29_%d", i); - ret = property_commit(); - if (ret != 0) + ret = property_set(key, value); + assert_int_equal(ret, 0); + + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after inserting data. Key:%s value:%s\n", key, value); - assert_int_equal(ret, 0); + syslog( + LOG_ERR, + "Failed to commit after inserting data. Key:%s value:%s\n", + key, value); + assert_int_equal(ret, 0); } - ret = property_get(key, data, ""); - assert_int_equal(ret, strlen(value)); + ret = property_get(key, data, ""); + assert_int_equal(ret, strlen(value)); - ret = property_delete(key); - assert_int_equal(ret, 0); + ret = property_delete(key); + assert_int_equal(ret, 0); - ret = property_commit(); - if (ret != 0) + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s value:%s\n", key, value); - assert_int_equal(ret, 0); + syslog( + LOG_ERR, + "Failed to commit after deleting data. Key:%s value:%s\n", + key, value); + assert_int_equal(ret, 0); } } - -} \ No newline at end of file +} diff --git a/testsuites/kernel/kv/cases/kv_test_030.c b/testsuites/kernel/kv/cases/kv_test_030.c index 1058be4..81fa988 100644 --- a/testsuites/kernel/kv/cases/kv_test_030.c +++ b/testsuites/kernel/kv/cases/kv_test_030.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cases/kv_test_030.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -24,57 +44,80 @@ /**************************************************************************** * Name: store_data ****************************************************************************/ + pthread_mutex_t mutex_kv; static void *store_persist_data(void *arg) { + char key[TEST_KEY_LENGTH] = + { + 0 + }; - char key[TEST_KEY_LENGTH] = {0}; - char value[TEST_VALUE_LENGTH] = {0}; - int ret; - for (int k = 0; k < 100; k++) + char value[TEST_VALUE_LENGTH] = + { + 0 + }; + + int ret; + for (int k = 0; k < 30; k++) { - sprintf(key, "persist.kv30_%d_%d", gettid(), k); - sprintf(value, "test_value_kv30_%d_%d", gettid(), k); - ret = property_set(key, value); - if (ret != 0) + sprintf(key, "persist.kv30_%d_%d", gettid(), k); + sprintf(value, "test_value_kv30_%d_%d", gettid(), k); + ret = property_set(key, value); + if (ret != 0) { - syslog(LOG_ERR, "Failed to insert data. The test thread number:%d Key:%s value:%s\n", gettid(), key, value); - pthread_mutex_lock(&mutex_kv); - (*((int *)arg)) = -1; - pthread_mutex_unlock(&mutex_kv); - return NULL; + syslog(LOG_ERR, + "Failed to insert data. The test thread number:%d " + "Key:%s value:%s\n", + gettid(), key, value); + pthread_mutex_lock(&mutex_kv); + (*((int *)arg)) = -1; + pthread_mutex_unlock(&mutex_kv); + return NULL; } - ret = property_commit(); - if (ret != 0) + + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after inserting data. The test thread number:%d Key:%s value:%s\n", gettid(), key, value); - pthread_mutex_lock(&mutex_kv); - (*((int *)arg)) = -1; - pthread_mutex_unlock(&mutex_kv); - return NULL; + syslog(LOG_ERR, + "Failed to commit after inserting data. The test " + "thread number:%d Key:%s value:%s\n", + gettid(), key, value); + pthread_mutex_lock(&mutex_kv); + (*((int *)arg)) = -1; + pthread_mutex_unlock(&mutex_kv); + return NULL; } - ret = property_delete(key); - if (ret != 0) + ret = property_delete(key); + if (ret != 0) { - syslog(LOG_ERR, "Failed to delete data. The test thread number:%d Key:%s value:%s\n", gettid(), key, value); - pthread_mutex_lock(&mutex_kv); - (*((int *)arg)) = -1; - pthread_mutex_unlock(&mutex_kv); - return NULL; + syslog(LOG_ERR, + "Failed to delete data. The test thread number:%d " + "Key:%s value:%s\n", + gettid(), key, value); + pthread_mutex_lock(&mutex_kv); + (*((int *)arg)) = -1; + pthread_mutex_unlock(&mutex_kv); + return NULL; } - ret = property_commit(); - if (ret != 0) + + ret = property_commit(); + if (ret != 0) { - syslog(LOG_ERR, "Failed to commit after deleting data. The test thread number:%d Key:%s value:%s\n", gettid(), key, value); - pthread_mutex_lock(&mutex_kv); - (*((int *)arg)) = -1; - pthread_mutex_unlock(&mutex_kv); - return NULL; + syslog(LOG_ERR, + "Failed to commit after deleting data. The test thread " + "number:%d Key:%s value:%s\n", + gettid(), key, value); + pthread_mutex_lock(&mutex_kv); + (*((int *)arg)) = -1; + pthread_mutex_unlock(&mutex_kv); + return NULL; } } - return NULL; + + return NULL; } /**************************************************************************** @@ -82,30 +125,40 @@ static void *store_persist_data(void *arg) ****************************************************************************/ /**************************************************************************** - * Name: TestNuttxKv30 + * Name: test_nuttx_kv30 ****************************************************************************/ -void TestNuttxKv30(FAR void **state) + +void test_nuttx_kv30(FAR void **state) { - pthread_t nthread[3]; - int status; - int num_thread = 3; - int test_flag = 0; + pthread_t nthread[3]; + pthread_attr_t attr; + int status; + int num_thread = 3; + int test_flag = 0; - pthread_mutex_init(&mutex_kv, NULL); + pthread_mutex_init(&mutex_kv, NULL); + status = pthread_attr_init(&attr); + assert_int_equal(status, 0); + status = pthread_attr_setstacksize(&attr, 8192); + assert_int_equal(status, 0); - for (int i = 0; i < num_thread; i++) + for (int i = 0; i < num_thread; i++) { - /* creat test thread */ - status = pthread_create(&nthread[i], NULL, store_persist_data, &test_flag); - assert_int_equal(status, 0); + /* creat test thread */ + + status = pthread_create(&nthread[i], &attr, store_persist_data, + &test_flag); + assert_int_equal(status, 0); } - for (int j = 0; j < num_thread; j++) { - pthread_join(nthread[j], NULL); + for (int j = 0; j < num_thread; j++) + { + pthread_join(nthread[j], NULL); } - pthread_mutex_destroy(&mutex_kv); + pthread_mutex_destroy(&mutex_kv); + + /* Check whether any child threads failed to run */ - /* Check whether any child threads failed to run */ - assert_int_equal(test_flag, 0); -} \ No newline at end of file + assert_int_equal(test_flag, 0); +} diff --git a/testsuites/kernel/kv/cmocka_kv_test.c b/testsuites/kernel/kv/cmocka_kv_test.c index 7d29381..38caf88 100644 --- a/testsuites/kernel/kv/cmocka_kv_test.c +++ b/testsuites/kernel/kv/cmocka_kv_test.c @@ -1,18 +1,22 @@ -/* - * Copyright (C) 2020 Xiaomi Corporation +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cmocka_kv_test.c * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ /**************************************************************************** * Included Files @@ -29,54 +33,92 @@ #include "KvTest.h" #include +/**************************************************************************** + * Private Functions + ****************************************************************************/ + /**************************************************************************** * Name: cmocka_sched_test_main ****************************************************************************/ + int main(int argc, char *argv[]) { /* Add Test Cases */ - const struct CMUnitTest NuttxKvdbTestSuites[] = { + + const struct CMUnitTest nuttx_kvdb_test_suites[] = + { #ifdef CONFIG_KVDB_TEMPORARY_STORAGE - cmocka_unit_test_setup_teardown(TestNuttxKv01, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv02, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv03, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv04, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv05, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv06, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv07, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv08, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv09, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv10, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv11, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv12, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv13, TestNuttxKvsetup, TestNuttxKvteardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv01, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv02, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv03, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv04, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv05, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv06, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv07, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv08, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv09, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv10, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv11, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv12, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv13, test_nuttx_kv_setup, + test_nuttx_kv_teardown), #endif - cmocka_unit_test_setup_teardown(TestNuttxKv14, TestNuttxKvsetup, TestNuttxKvteardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv14, test_nuttx_kv_setup, + test_nuttx_kv_teardown), #ifdef CONFIG_KVDB_TEMPORARY_STORAGE - cmocka_unit_test_setup_teardown(TestNuttxKv15, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv16, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv17, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv18, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv19, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv20, TestNuttxKvsetup, TestNuttxKvteardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv15, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv16, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv17, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv18, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv19, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv20, test_nuttx_kv_setup, + test_nuttx_kv_teardown), #endif -#ifdef CONFIG_NSH_ROMFSETC - cmocka_unit_test_setup_teardown(TestNuttxKv21, TestNuttxKvsetup, TestNuttxKvteardown), +#ifdef CONFIG_KVDB_SERVER + cmocka_unit_test_setup_teardown(test_nuttx_kv21, test_nuttx_kv_setup, + test_nuttx_kv_teardown), #endif #ifdef CONFIG_KVDB_TEMPORARY_STORAGE - cmocka_unit_test_setup_teardown(TestNuttxKv22, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv23, TestNuttxKvsetup, TestNuttxKvteardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv22, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv23, test_nuttx_kv_setup, + test_nuttx_kv_teardown), #endif - cmocka_unit_test_setup_teardown(TestNuttxKv24, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv25, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv26, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv27, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv28, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv29, TestNuttxKvsetup, TestNuttxKvteardown), - cmocka_unit_test_setup_teardown(TestNuttxKv30, TestNuttxKvsetup, TestNuttxKvteardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv24, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv25, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv26, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv27, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv28, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv29, test_nuttx_kv_setup, + test_nuttx_kv_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_kv30, test_nuttx_kv_setup, + test_nuttx_kv_teardown), }; /* Run Test cases */ - cmocka_run_group_tests(NuttxKvdbTestSuites, NULL, NULL); + + cmocka_run_group_tests(nuttx_kvdb_test_suites, NULL, NULL); return 0; -} \ No newline at end of file +} diff --git a/testsuites/kernel/kv/common/test_kv_common.c b/testsuites/kernel/kv/common/test_kv_common.c index f70fd66..3d2dd43 100644 --- a/testsuites/kernel/kv/common/test_kv_common.c +++ b/testsuites/kernel/kv/common/test_kv_common.c @@ -1,3 +1,23 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/common/test_kv_common.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ @@ -19,18 +39,21 @@ /**************************************************************************** * Public Functions ****************************************************************************/ + /**************************************************************************** - * Name: TestNuttxKvsetup + * Name: test_nuttx_kvsetup ****************************************************************************/ -int TestNuttxKvsetup(void **state) + +int test_nuttx_kv_setup(void **state) { - return 0; + return 0; } /**************************************************************************** - * Name: TestNuttxKvteardown + * Name: test_nuttx_kvteardown ****************************************************************************/ -int TestNuttxKvteardown(void **state) + +int test_nuttx_kv_teardown(void **state) { - return 0; + return 0; } diff --git a/testsuites/kernel/kv/include/KvTest.h b/testsuites/kernel/kv/include/KvTest.h index 08c770c..7f3ea86 100644 --- a/testsuites/kernel/kv/include/KvTest.h +++ b/testsuites/kernel/kv/include/KvTest.h @@ -1,18 +1,22 @@ -/* - * Copyright (C) 2020 Xiaomi Corporation +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/include/KvTest.h * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ #ifndef __SYSCALLTEST_H #define __SYSCALLTEST_H @@ -27,7 +31,11 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -/* The test files generated during the 'syscall-test' are stored in this directory */ + +/* The test files generated during the 'syscall-test' are stored in this + * directory + */ + #define TEST_KEY_LENGTH PROP_NAME_MAX - 1 #define TEST_VALUE_LENGTH PROP_VALUE_MAX - 1 #define MOUNT_DIR CONFIG_TESTS_TESTSUITES_MOUNT_DIR @@ -35,74 +43,166 @@ #define DEFAULT_STACKSIZE CONFIG_DEFAULT_TASK_STACKSIZE #define TASK_PRIORITY SCHED_PRIORITY_DEFAULT #define KV_TEST_PREFIX "KVtest." + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ -char *CM_random_string(int length); -void Cm_Kv_get_a_random_key(char *buf, int size); -int TestNuttxKvsetup(void **state); -int TestNuttxKvteardown(void **state); +char *cm_random_string(int length); +void cm_kv_get_a_random_key(char *buf, int size); + +int test_nuttx_kv_setup(void **state); +int test_nuttx_kv_teardown(void **state); /* test case function */ -/* cases/kv_test_001.c *****************************************************/ -void TestNuttxKv01(FAR void **state); -/* cases/kv_test_002.c *****************************************************/ -void TestNuttxKv02(FAR void **state); -/* cases/kv_test_003.c *****************************************************/ -void TestNuttxKv03(FAR void **state); -/* cases/kv_test_004.c *****************************************************/ -void TestNuttxKv04(FAR void **state); -/* cases/kv_test_005.c *****************************************************/ -void TestNuttxKv05(FAR void **state); -/* cases/kv_test_006.c *****************************************************/ -void TestNuttxKv06(FAR void **state); -/* cases/kv_test_007.c *****************************************************/ -void TestNuttxKv07(FAR void **state); -/* cases/kv_test_008.c *****************************************************/ -void TestNuttxKv08(FAR void **state); -/* cases/kv_test_009.c *****************************************************/ -void TestNuttxKv09(FAR void **state); -/* cases/kv_test_010.c *****************************************************/ -void TestNuttxKv10(FAR void **state); -/* cases/kv_test_011.c *****************************************************/ -void TestNuttxKv11(FAR void **state); -/* cases/kv_test_012.c *****************************************************/ -void TestNuttxKv12(FAR void **state); -/* cases/kv_test_013.c *****************************************************/ -void TestNuttxKv13(FAR void **state); -/* cases/kv_test_014.c *****************************************************/ -void TestNuttxKv14(FAR void **state); -/* cases/kv_test_015.c *****************************************************/ -void TestNuttxKv15(FAR void **state); -/* cases/kv_test_016.c *****************************************************/ -void TestNuttxKv16(FAR void **state); -/* cases/kv_test_017.c *****************************************************/ -void TestNuttxKv17(FAR void **state); -/* cases/kv_test_018.c *****************************************************/ -void TestNuttxKv18(FAR void **state); -/* cases/kv_test_019.c *****************************************************/ -void TestNuttxKv19(FAR void **state); -/* cases/kv_test_020.c *****************************************************/ -void TestNuttxKv20(FAR void **state); -/* cases/kv_test_021.c *****************************************************/ -void TestNuttxKv21(FAR void **state); -/* cases/kv_test_022.c *****************************************************/ -void TestNuttxKv22(FAR void **state); -/* cases/kv_test_023.c *****************************************************/ -void TestNuttxKv23(FAR void **state); -/* cases/kv_test_024.c *****************************************************/ -void TestNuttxKv24(FAR void **state); -/* cases/kv_test_025.c *****************************************************/ -void TestNuttxKv25(FAR void **state); -/* cases/kv_test_026.c *****************************************************/ -void TestNuttxKv26(FAR void **state); -/* cases/kv_test_027.c *****************************************************/ -void TestNuttxKv27(FAR void **state); -/* cases/kv_test_028.c *****************************************************/ -void TestNuttxKv28(FAR void **state); -/* cases/kv_test_029.c *****************************************************/ -void TestNuttxKv29(FAR void **state); -/* cases/kv_test_030.c *****************************************************/ -void TestNuttxKv30(FAR void **state); + +/* cases/kv_test_001.c + * *****************************************************/ + +void test_nuttx_kv01(FAR void **state); + +/* cases/kv_test_002.c + * *****************************************************/ + +void test_nuttx_kv02(FAR void **state); + +/* cases/kv_test_003.c + * *****************************************************/ + +void test_nuttx_kv03(FAR void **state); + +/* cases/kv_test_004.c + * *****************************************************/ + +void test_nuttx_kv04(FAR void **state); + +/* cases/kv_test_005.c + * *****************************************************/ + +void test_nuttx_kv05(FAR void **state); + +/* cases/kv_test_006.c + * *****************************************************/ + +void test_nuttx_kv06(FAR void **state); + +/* cases/kv_test_007.c + * *****************************************************/ + +void test_nuttx_kv07(FAR void **state); + +/* cases/kv_test_008.c + * *****************************************************/ + +void test_nuttx_kv08(FAR void **state); + +/* cases/kv_test_009.c + * *****************************************************/ + +void test_nuttx_kv09(FAR void **state); + +/* cases/kv_test_010.c + * *****************************************************/ + +void test_nuttx_kv10(FAR void **state); + +/* cases/kv_test_011.c + * *****************************************************/ + +void test_nuttx_kv11(FAR void **state); + +/* cases/kv_test_012.c + * *****************************************************/ + +void test_nuttx_kv12(FAR void **state); + +/* cases/kv_test_013.c + * *****************************************************/ + +void test_nuttx_kv13(FAR void **state); + +/* cases/kv_test_014.c + * *****************************************************/ + +void test_nuttx_kv14(FAR void **state); + +/* cases/kv_test_015.c + * *****************************************************/ + +void test_nuttx_kv15(FAR void **state); + +/* cases/kv_test_016.c + * *****************************************************/ + +void test_nuttx_kv16(FAR void **state); + +/* cases/kv_test_017.c + * *****************************************************/ + +void test_nuttx_kv17(FAR void **state); + +/* cases/kv_test_018.c + * *****************************************************/ + +void test_nuttx_kv18(FAR void **state); + +/* cases/kv_test_019.c + * *****************************************************/ + +void test_nuttx_kv19(FAR void **state); + +/* cases/kv_test_020.c + * *****************************************************/ + +void test_nuttx_kv20(FAR void **state); + +/* cases/kv_test_021.c + * *****************************************************/ + +void test_nuttx_kv21(FAR void **state); + +/* cases/kv_test_022.c + * *****************************************************/ + +void test_nuttx_kv22(FAR void **state); + +/* cases/kv_test_023.c + * *****************************************************/ + +void test_nuttx_kv23(FAR void **state); + +/* cases/kv_test_024.c + * *****************************************************/ + +void test_nuttx_kv24(FAR void **state); + +/* cases/kv_test_025.c + * *****************************************************/ + +void test_nuttx_kv25(FAR void **state); + +/* cases/kv_test_026.c + * *****************************************************/ + +void test_nuttx_kv26(FAR void **state); + +/* cases/kv_test_027.c + * *****************************************************/ + +void test_nuttx_kv27(FAR void **state); + +/* cases/kv_test_028.c + * *****************************************************/ + +void test_nuttx_kv28(FAR void **state); + +/* cases/kv_test_029.c + * *****************************************************/ + +void test_nuttx_kv29(FAR void **state); + +/* cases/kv_test_030.c + * *****************************************************/ + +void test_nuttx_kv30(FAR void **state); #endif \ No newline at end of file diff --git a/testsuites/kernel/mm/cases/mm_test_001.c b/testsuites/kernel/mm/cases/mm_test_001.c deleted file mode 100644 index 3929787..0000000 --- a/testsuites/kernel/mm/cases/mm_test_001.c +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "MmTest.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxMm01 - ****************************************************************************/ -void TestNuttxMm01(FAR void **state) -{ - int i, flag = 0; - char *pm1, *pm2; - unsigned long memsize; - - memsize = mmtest_get_memsize(); - pm2 = pm1 = malloc(memsize); - assert_non_null(pm1); - - for (i = 0; i < memsize; i++) - *pm2++ = 'X'; - pm2 = pm1; - for (i = 0; i < memsize; i++) - { - if (*pm2++ != 'X') - { - flag = 1; - } - } - - free(pm1); - assert_int_equal(flag, 0); -} \ No newline at end of file diff --git a/testsuites/kernel/mm/cases/mm_test_002.c b/testsuites/kernel/mm/cases/mm_test_002.c deleted file mode 100644 index b9b0711..0000000 --- a/testsuites/kernel/mm/cases/mm_test_002.c +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "MmTest.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxMm02 - ****************************************************************************/ -void TestNuttxMm02(FAR void **state) -{ - int i, flag = 0; - char *pm1, *pm2; - unsigned long memsize; - - memsize = mmtest_get_memsize(); - pm2 = pm1 = calloc(memsize, 1); - assert_non_null(pm2); - - for (i = 0; i < memsize; i++) - { - if (*pm2++ != 0) - { - flag = 1; - } - } - - pm2 = pm1; - for (i = 0; i < memsize; i++) - *pm2++ = 'X'; - pm2 = pm1; - for (i = 0; i < memsize; i++) - { - if (*pm2++ != 'X') - { - flag = 1; - } - } - free(pm1); - assert_int_equal(flag, 0); -} \ No newline at end of file diff --git a/testsuites/kernel/mm/cases/mm_test_003.c b/testsuites/kernel/mm/cases/mm_test_003.c deleted file mode 100644 index f073223..0000000 --- a/testsuites/kernel/mm/cases/mm_test_003.c +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "MmTest.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxMm03 - ****************************************************************************/ -void TestNuttxMm03(FAR void **state) -{ - int i, flag = 0; - char *pm1, *pm2; - pm2 = pm1 = malloc(10); - assert_non_null(pm2); - for (i = 0; i < 10; i++) - *pm2++ = 'X'; - - pm2 = realloc(pm1, 5); - pm1 = pm2; - for (i = 0; i < 5; i++) - { - if (*pm2++ != 'X') - { - flag = 1; - } - } - - pm2 = realloc(pm1, 15); - pm1 = pm2; - for (i = 0; i < 5; i++) - { - if (*pm2++ != 'X') - { - flag = 1; - } - } - - free(pm1); - assert_int_equal(flag, 0); -} \ No newline at end of file diff --git a/testsuites/kernel/mm/cases/mm_test_004.c b/testsuites/kernel/mm/cases/mm_test_004.c deleted file mode 100644 index adea672..0000000 --- a/testsuites/kernel/mm/cases/mm_test_004.c +++ /dev/null @@ -1,36 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "MmTest.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxMm04 - ****************************************************************************/ -void TestNuttxMm04(FAR void **state) -{ - int i; - char *temp_ptr = NULL; - - for (i = 0; i < 10; i++) - { - temp_ptr = memalign(64, 1024 * sizeof(char)); - assert_non_null(temp_ptr); - - memset(temp_ptr, 0x33, 1024 * sizeof(char)); - free(temp_ptr); - } -} \ No newline at end of file diff --git a/testsuites/kernel/mm/cases/mm_test_005.c b/testsuites/kernel/mm/cases/mm_test_005.c deleted file mode 100644 index acc1f77..0000000 --- a/testsuites/kernel/mm/cases/mm_test_005.c +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "MmTest.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ -/**************************************************************************** - * Name: TestNuttxMm05 - ****************************************************************************/ -void TestNuttxMm05(FAR void **state) -{ - int i, flag = 0; - char *ptr, *temp_ptr = NULL; - - ptr = temp_ptr = zalloc(1024 * sizeof(char)); - assert_non_null(temp_ptr); - - for (i = 0; i < 1024; i++) - { - if (*temp_ptr++ != 0) - { - flag = 1; - } - } - free(ptr); - assert_int_equal(flag, 0); -} \ No newline at end of file diff --git a/testsuites/kernel/mm/cases/mm_test_006.c b/testsuites/kernel/mm/cases/mm_test_006.c deleted file mode 100644 index 1b869fc..0000000 --- a/testsuites/kernel/mm/cases/mm_test_006.c +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "MmTest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -/* Random size range, we will apply the memory size in this range */ -#define MALLOC_MIN_SIZE 64 -#define MALLOC_MAX_SIZE 8192 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ -/**************************************************************************** - * Name: TestNuttxMm06 - ****************************************************************************/ -void TestNuttxMm06(FAR void **state) -{ - int malloc_size, test_num = 1000; - char check_character = 0x67; /* Memory write content check character */ - char *address_ptr = NULL; - - for (int i = 0; i < test_num; i++) - { - srand(i + gettid()); - /* Produces a random size */ - malloc_size = mmtest_get_rand_size(MALLOC_MIN_SIZE, MALLOC_MAX_SIZE); - address_ptr = (char *)malloc(malloc_size * sizeof(char)); - assert_non_null(address_ptr); - memset(address_ptr, check_character, malloc_size); - - /* Checking Content Consistency */ - for (int j = 0; j < malloc_size; j++) - { - if (address_ptr[j] != check_character) - { - free(address_ptr); - fail_msg("check fail !\n"); - } - } - /* Free test memory */ - free(address_ptr); - } -} \ No newline at end of file diff --git a/testsuites/kernel/mm/cases/mm_test_007.c b/testsuites/kernel/mm/cases/mm_test_007.c deleted file mode 100644 index 159a088..0000000 --- a/testsuites/kernel/mm/cases/mm_test_007.c +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "MmTest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define MEMORY_LIST_LENGTH 200 -/* Random size range, we will apply the memory size in this range */ -#define MALLOC_MIN_SIZE 32 -#define MALLOC_MAX_SIZE 2048 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ -/**************************************************************************** - * Name: TestNuttxMm07 - ****************************************************************************/ -void TestNuttxMm07(FAR void **state) -{ - char *mem_list[MEMORY_LIST_LENGTH], *tmp_str = NULL; - int malloc_size, index = 0; - int total_size = 0, flag = 0; - struct mallinfo test_befor_info, test_during_info, test_after_info; - - for (int i = 0; i < MEMORY_LIST_LENGTH; i++) - { - mem_list[i] = NULL; - } - - test_befor_info = mallinfo(); - - /* get a random size */ - malloc_size = mmtest_get_rand_size(MALLOC_MIN_SIZE, MALLOC_MAX_SIZE); - for (int k = 0; k < MEMORY_LIST_LENGTH; k++) - { - if (malloc_size > 0) - { - tmp_str = (char *)malloc(malloc_size * sizeof(char)); - } - else - { - malloc_size = 512; - tmp_str = (char *)malloc(malloc_size * sizeof(char)); - } - - mem_list[k] = tmp_str; - if (tmp_str != NULL) - { - memset(tmp_str, 0x67, malloc_size); - total_size = total_size + malloc_size; - for (int j = 0; j < malloc_size; j++) - { - if (*tmp_str++ != 0x67) - { - syslog(LOG_ERR, "check error !\n"); - flag = 1; - } - } - } - } - - test_during_info = mallinfo(); - - /* Random memory release */ - for (int n = 0; n < MEMORY_LIST_LENGTH; n++) - { - srand(n); - index = rand() % 2; - if (index == 0 && mem_list[n] != NULL) - { - free(mem_list[n]); - mem_list[n] = NULL; - } - } - - for (int l = 0; l < MEMORY_LIST_LENGTH; l++) - { - if (mem_list[l] != NULL) - free(mem_list[l]); - } - test_after_info = mallinfo(); - assert_int_in_range(test_befor_info.fordblks, test_during_info.fordblks, test_befor_info.arena); - assert_int_in_range(test_after_info.fordblks, test_during_info.fordblks, test_befor_info.arena); - assert_int_equal(flag, 0); -} \ No newline at end of file diff --git a/testsuites/kernel/mm/cases/mm_test_008.c b/testsuites/kernel/mm/cases/mm_test_008.c deleted file mode 100644 index 1dcfe10..0000000 --- a/testsuites/kernel/mm/cases/mm_test_008.c +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "MmTest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define MEMORY_LIST_LENGTH 200 -/* Random size range, we will apply the memory size in this range */ -#define MALLOC_MIN_SIZE 32 -#define MALLOC_MAX_SIZE 2048 - -static int TestNuttx08_routine_1(int argc, char *argv[]) -{ - char *ptr = NULL, *tmp_ptr = NULL; - int malloc_size, flag = 0; - - for (int n = 0; n < 1000; n++) - { - malloc_size = mmtest_get_rand_size(64, 512); - tmp_ptr = ptr = malloc(sizeof(char) * malloc_size); - if (ptr == NULL) - { - flag = 1; - break; - } - - for (int i = 0; i < malloc_size; i++) - *tmp_ptr++ = 'X'; - tmp_ptr = ptr; - for (int j = 0; j < malloc_size; j++) - { - if (*tmp_ptr++ != 'X') - { - flag = 1; - } - } - free(ptr); - } - assert_int_equal(flag, 0); - return 0; -} - -static int TestNuttx08_routine_2(int argc, char *argv[]) -{ - char *temp_ptr = NULL; - int flag = 0; - - for (int n = 0; n < 1000; n++) - { - temp_ptr = memalign(64, 1024 * sizeof(char)); - if (temp_ptr == NULL) - { - flag = 1; - break; - } - assert_non_null(temp_ptr); - - memset(temp_ptr, 0x33, 1024 * sizeof(char)); - free(temp_ptr); - } - assert_int_equal(flag, 0); - return 0; -} - -static int TestNuttx08_routine_3(int argc, char *argv[]) -{ - char *pm; - unsigned long memsize; - for (int i = 0; i < 500; i++) - { - /* Apply for as much memory as a system allows */ - memsize = mmtest_get_rand_size(1024, 2048); - pm = malloc(memsize); - assert_non_null(pm); - free(pm); - } - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ -/**************************************************************************** - * Name: TestNuttxMm08 - ****************************************************************************/ -void TestNuttxMm08(FAR void **state) -{ - pid_t pid; - int status; - - pid = task_create("TestNuttx08_routine_1", TASK_PRIORITY, DEFAULT_STACKSIZE, TestNuttx08_routine_1, NULL); - assert_true(pid > 0); - pid = task_create("TestNuttx08_routine_2", TASK_PRIORITY, DEFAULT_STACKSIZE, TestNuttx08_routine_2, NULL); - assert_true(pid > 0); - pid = task_create("TestNuttx08_routine_3", TASK_PRIORITY, DEFAULT_STACKSIZE, TestNuttx08_routine_3, NULL); - assert_true(pid > 0); - waitpid(pid, &status, 0); -} \ No newline at end of file diff --git a/testsuites/kernel/mm/cmocka_mm_test.c b/testsuites/kernel/mm/cmocka_mm_test.c deleted file mode 100644 index 9e3f5de..0000000 --- a/testsuites/kernel/mm/cmocka_mm_test.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2020 Xiaomi Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "MmTest.h" -#include - -/**************************************************************************** - * Name: cmocka_sched_test_main - ****************************************************************************/ -int main(int argc, char *argv[]) -{ - - /* Add Test Cases */ - const struct CMUnitTest NuttxMmTestSuites[] = { - cmocka_unit_test_setup_teardown(TestNuttxMm01, TestNuttxMmsetup, TestNuttxMmteardown), - cmocka_unit_test_setup_teardown(TestNuttxMm02, TestNuttxMmsetup, TestNuttxMmteardown), - cmocka_unit_test_setup_teardown(TestNuttxMm03, TestNuttxMmsetup, TestNuttxMmteardown), - cmocka_unit_test_setup_teardown(TestNuttxMm04, TestNuttxMmsetup, TestNuttxMmteardown), - cmocka_unit_test_setup_teardown(TestNuttxMm05, TestNuttxMmsetup, TestNuttxMmteardown), - cmocka_unit_test_setup_teardown(TestNuttxMm06, TestNuttxMmsetup, TestNuttxMmteardown), - cmocka_unit_test_setup_teardown(TestNuttxMm07, TestNuttxMmsetup, TestNuttxMmteardown), - cmocka_unit_test_setup_teardown(TestNuttxMm08, TestNuttxMmsetup, TestNuttxMmteardown), - }; - - /* Run Test cases */ - cmocka_run_group_tests(NuttxMmTestSuites, NULL, NULL); - - return 0; -} \ No newline at end of file diff --git a/testsuites/kernel/mm/common/test_mm_common.c b/testsuites/kernel/mm/common/test_mm_common.c deleted file mode 100644 index 5ed8e28..0000000 --- a/testsuites/kernel/mm/common/test_mm_common.c +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "MmTest.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ -/**************************************************************************** - * Name: get_rand_size - ****************************************************************************/ -int mmtest_get_rand_size(int min, int max) -{ - int rval = 1; - if (min > 0 && max > 0 && (max - min) > 0) - { - rval = rand() % (max - min) + min; - } - return rval; -} -/**************************************************************************** - * Name: mm_showmallinfo - ****************************************************************************/ -void mmtest_showmallinfo(void) -{ - struct mallinfo alloc_info; - alloc_info = mallinfo(); - syslog(LOG_INFO, " mallinfo:\n"); - syslog(LOG_INFO, " Total space allocated from system = %lu\n", - (unsigned long)alloc_info.arena); - syslog(LOG_INFO, " Number of non-inuse chunks = %lu\n", - (unsigned long)alloc_info.ordblks); - syslog(LOG_INFO, " Largest non-inuse chunk = %lu\n", - (unsigned long)alloc_info.mxordblk); - syslog(LOG_INFO, " Total allocated space = %lu\n", - (unsigned long)alloc_info.uordblks); - syslog(LOG_INFO, " Total non-inuse space = %lu\n", - (unsigned long)alloc_info.fordblks); -} - -/**************************************************************************** - * Name: mmtest_get_memsize - ****************************************************************************/ -unsigned long mmtest_get_memsize(void) -{ - -#ifdef CONFIG_ARCH_SIM - return 2048; -#else - unsigned long memsize; - unsigned long mem_largest; - struct mallinfo alloc_info; - - alloc_info = mallinfo(); - mem_largest = alloc_info.mxordblk; - memsize = mem_largest * 0.5; - - /* - During the test, the maximum memory is less than 2M - */ - if (memsize > 1024 * 1024 * 2) - { - memsize = 1024 * 1024 * 2; - } - return memsize; -#endif -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxMmsetup - ****************************************************************************/ -int TestNuttxMmsetup(void **state) -{ - return 0; -} - -/**************************************************************************** - * Name: TestNuttxMmteardown - ****************************************************************************/ -int TestNuttxMmteardown(void **state) -{ - return 0; -} diff --git a/testsuites/kernel/mm/include/MmTest.h b/testsuites/kernel/mm/include/MmTest.h deleted file mode 100644 index 1dff2d3..0000000 --- a/testsuites/kernel/mm/include/MmTest.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2020 Xiaomi Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __SYSCALLTEST_H -#define __SYSCALLTEST_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define PTHREAD_STACK_SIZE CONFIG_DEFAULT_TASK_STACKSIZE -#define DEFAULT_STACKSIZE CONFIG_DEFAULT_TASK_STACKSIZE -#define TASK_PRIORITY SCHED_PRIORITY_DEFAULT - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ -int mmtest_get_rand_size(int min, int max); -void mmtest_showmallinfo(void); -unsigned long mmtest_get_memsize(void); - -int TestNuttxMmsetup(void **state); -int TestNuttxMmteardown(void **state); - -/* test case function */ -/* cases/mm_test_001.c *****************************************************/ -void TestNuttxMm01(FAR void **state); -/* cases/mm_test_002.c *****************************************************/ -void TestNuttxMm02(FAR void **state); -/* cases/mm_test_003.c *****************************************************/ -void TestNuttxMm03(FAR void **state); -/* cases/mm_test_004.c *****************************************************/ -void TestNuttxMm04(FAR void **state); -/* cases/mm_test_005.c *****************************************************/ -void TestNuttxMm05(FAR void **state); -/* cases/mm_test_006.c *****************************************************/ -void TestNuttxMm06(FAR void **state); -/* cases/mm_test_007.c *****************************************************/ -void TestNuttxMm07(FAR void **state); -/* cases/mm_test_008.c *****************************************************/ -void TestNuttxMm08(FAR void **state); - -#endif \ No newline at end of file diff --git a/testsuites/kernel/mm/tool/mem_batch_opt_perf_test.c b/testsuites/kernel/mm/tool/mem_batch_opt_perf_test.c deleted file mode 100644 index b405659..0000000 --- a/testsuites/kernel/mm/tool/mem_batch_opt_perf_test.c +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include "MmTest.h" - -/**************************************************************************** - * Name: show_usage - ****************************************************************************/ -static void show_usage(void) -{ - printf("\nUsage: mm_stress_test \n"); - printf("\nWhere:\n"); - printf(" Minimum number of memory requests.\n"); - printf(" Maximum number of memory requests.\n"); - printf(" The length of the memory request list.\n"); - printf(" Number of tests.\n"); -} - -/**************************************************************************** - * Name: main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int malloc_size = 0; - int mallc_min_size; /* The minimum memory length requested in the test */ - int mallc_max_size; /* The maximum memory length requested in the test */ - int list_length; - int test_num = 1; - struct timespec t_start; - struct timespec t_end; - long timedif; - char *address_ptr = NULL; - char **mem_list = NULL; - - if (argc < 5) - { - syslog(LOG_WARNING, "Missing required arguments\n"); - show_usage(); - exit(1); - } - - mallc_min_size = atoi(argv[1]); - mallc_max_size = atoi(argv[2]); - list_length = atoi(argv[3]); - test_num = atoi(argv[4]); - - for (int n = 1; n <= test_num; n++) - { - mem_list = (char **)malloc(sizeof(char *) * list_length); - if (mem_list == NULL) - { - syslog(LOG_ERR, "Failed to apply for the memory list !\n"); - exit(1); - } - - for (int i = 0; i < list_length; i++) - { - srand(i + gettid()); - malloc_size = mmtest_get_rand_size(mallc_min_size, mallc_max_size); - - clock_gettime(CLOCK_MONOTONIC, &t_start); - address_ptr = (char *)malloc(malloc_size * sizeof(char)); - clock_gettime(CLOCK_MONOTONIC, &t_end); - timedif = 1000000 * (t_end.tv_sec - t_start.tv_sec) + (t_end.tv_nsec - t_start.tv_nsec) / 1000; - if (address_ptr != NULL) - { - syslog(LOG_INFO, "[Test %d Round] Allocate success -> mem_list[%d] (address:%p size:%d) takes:%ld microseconds\n", n, i, address_ptr, malloc_size, timedif); - memset(address_ptr, 0x67, malloc_size); - /* Add to list */ - mem_list[i] = address_ptr; - } - else - { - syslog(LOG_ERR, "Malloc failed ! The remaining memory may be insufficient\n"); - syslog(LOG_ERR, "Continue to test !!\n"); - /* Memory allocation failure */ - mem_list[i] = NULL; - continue; - } - } - - for (int k = 0; k < list_length; k++) - { - address_ptr = mem_list[k]; - if (address_ptr != NULL) - { - clock_gettime(CLOCK_MONOTONIC, &t_start); - free(address_ptr); - clock_gettime(CLOCK_MONOTONIC, &t_end); - timedif = 1000000 * (t_end.tv_sec - t_start.tv_sec) + (t_end.tv_nsec - t_start.tv_nsec) / 1000; - syslog(LOG_INFO, "[Test %d Round] Free -> mem_list[%d] (size:%d) takes:%ld microseconds\n", n, k, malloc_size, timedif); - mem_list[k] = NULL; - } - } - - free(mem_list); - } - - return 0; -} \ No newline at end of file diff --git a/testsuites/kernel/mm/tool/mem_cycle_opt_perf_test.c b/testsuites/kernel/mm/tool/mem_cycle_opt_perf_test.c deleted file mode 100644 index ec98b8c..0000000 --- a/testsuites/kernel/mm/tool/mem_cycle_opt_perf_test.c +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include "MmTest.h" - -/**************************************************************************** - * Name: show_usage - ****************************************************************************/ -static void show_usage(void) -{ - printf("\nUsage: mm_stress_test \n"); - printf("\nWhere:\n"); - printf(" Minimum number of memory requests.\n"); - printf(" Maximum number of memory requests.\n"); - printf(" Number of tests.\n"); - printf(" Malloc delay time, Unit: microseconds.\n"); -} - -/**************************************************************************** - * Name: main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - int malloc_size; - int mallc_min_size; /* The minimum memory length requested in the test */ - int mallc_max_size; /* The maximum memory length requested in the test */ - int test_num; - int application_delay_time = 1; /* Delay in test */ - char check_character; /* Memory write content check character */ - char *address_ptr = NULL; - struct timespec t_start; - struct timespec t_end; - long timedif; - - if (argc < 5) - { - syslog(LOG_WARNING, "Missing required arguments\n"); - show_usage(); - exit(1); - } - - mallc_min_size = atoi(argv[1]); - mallc_max_size = atoi(argv[2]); - test_num = atoi(argv[3]); - application_delay_time = atoi(argv[4]); - - for (int i = 0; i < test_num; i++) - { - srand(i + gettid()); - malloc_size = mmtest_get_rand_size(mallc_min_size, mallc_max_size); - check_character = 0x65; - clock_gettime(CLOCK_MONOTONIC, &t_start); - address_ptr = (char *)malloc(malloc_size * sizeof(char)); - clock_gettime(CLOCK_MONOTONIC, &t_end); - timedif = 1000000 * (t_end.tv_sec - t_start.tv_sec) + (t_end.tv_nsec - t_start.tv_nsec) / 1000; - if (address_ptr != NULL) - { - syslog(LOG_INFO, "[Test malloc] (address:%p size:%d) takes:%ld microseconds\n", address_ptr, malloc_size, timedif); - memset(address_ptr, check_character, malloc_size); - } - else - { - syslog(LOG_ERR, "Malloc failed ! The remaining memory may be insufficient\n"); - syslog(LOG_ERR, "Continue to test !!\n"); - continue; - } - - /* Checking Content Consistency */ - for (int j = 0; j < malloc_size; j++) - { - if (address_ptr[j] != check_character) - { - syslog(LOG_ERR, "ERROR:Inconsistent content checking\n"); - free(address_ptr); - return -1; - } - } - - clock_gettime(CLOCK_MONOTONIC, &t_start); - /* Free test memory */ - - clock_gettime(CLOCK_MONOTONIC, &t_end); - timedif = 1000000 * (t_end.tv_sec - t_start.tv_sec) + (t_end.tv_nsec - t_start.tv_nsec) / 1000; - syslog(LOG_INFO, "[Test free] (address:%p size:%d) takes:%ld microseconds\n\n", address_ptr, malloc_size, timedif); - free(address_ptr); - usleep(application_delay_time); - } - - return 0; -} \ No newline at end of file diff --git a/testsuites/kernel/socket/cases/net_socket_test_005.c b/testsuites/kernel/socket/cases/net_socket_test_005.c deleted file mode 100644 index a7bb3b7..0000000 --- a/testsuites/kernel/socket/cases/net_socket_test_005.c +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include - -#include "SocketTest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: TestNuttxNetSocketTest05 - ****************************************************************************/ - -void TestNuttxNetSocketTest05(FAR void **state) -{ -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - uint32_t hl = ntohl(0x12345678); - syslog(LOG_INFO,"hl %#"PRIx32, hl); - assert_int_equal(hl, 0x78563412); - - uint32_t nl = htonl(0x12345678); - syslog(LOG_INFO,"nl %#"PRIx32, nl); - assert_int_equal(nl, 0x78563412); - - uint16_t hs = ntohs(0x1234); - syslog(LOG_INFO,"hs %#"PRIx16, hs); - assert_int_equal(hs, 0x3412); - - uint16_t ns = htons(0x1234); - syslog(LOG_INFO,"ns %#"PRIx16, ns); - assert_int_equal(ns, 0x3412); -#else - uint32_t hl = ntohl(0x12345678); - syslog(LOG_INFO,"hl %#"PRIx32, hl); - assert_int_equal(hl, 0x12345678); - - uint32_t nl = htonl(0x12345678); - syslog(LOG_INFO,"nl %#"PRIx32, nl); - assert_int_equal(nl, 0x12345678); - - uint16_t hs = ntohs(0x1234); - syslog(LOG_INFO,"hs %#"PRIx16, hs); - assert_int_equal(hs, 0x1234); - - uint16_t ns = htons(0x1234); - syslog(LOG_INFO,"ns %#"PRIx16, ns); - assert_int_equal(ns, 0x1234); -#endif -} diff --git a/testsuites/kernel/socket/cases/net_socket_test_006.c b/testsuites/kernel/socket/cases/net_socket_test_006.c deleted file mode 100644 index 7690b29..0000000 --- a/testsuites/kernel/socket/cases/net_socket_test_006.c +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "SocketTest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - - -/**************************************************************************** - * Name: TestNuttxNetSocketTest06 - ****************************************************************************/ - -void TestNuttxNetSocketTest06(FAR void **state) -{ - struct in_addr in; - int ret = inet_pton(AF_INET, "300.10.10.10", &in); - syslog(LOG_INFO,"ret: %d", ret); - assert_int_equal(ret, 0); - - ret = inet_pton(AF_INET, "10.11.12.13", &in); - syslog(LOG_INFO,"ret: %d", ret); - assert_int_equal(ret, 1); -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - syslog(LOG_INFO,"in.s_addr: %#"PRIx32, in.s_addr); - assert_int_equal(in.s_addr, 0x0d0c0b0a); -#else - syslog(LOG_INFO,"in.s_addr: %#"PRIx32, in.s_addr); - assert_int_equal(in.s_addr, 0x0a0b0c0d); -#endif - /*Currently nuttx does not support the following interfaces inet_lnaof, inet_netof, inet_makeaddr*/ - // // host order - // in_addr_t lna = inet_lnaof(in); - // syslog(LOG_INFO,"lna: %#"PRIx32, lna); - // assert_int_equal(lna, 0x000b0c0d); - - // // host order - // in_addr_t net = inet_netof(in); - // syslog(LOG_INFO,"net: %#"PRIx32, net); - // assert_int_equal(net, 0x0000000a); - - // in = inet_makeaddr(net, lna); -// #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -// syslog(LOG_INFO,"in.s_addr: %#"PRIx32, in.s_addr); -// assert_int_equal(in.s_addr, 0x0d0c0b0a); -// #else -// syslog(LOG_INFO,"in.s_addr: %#"PRIx32, in.s_addr); -// assert_int_equal(in.s_addr, 0x0a0b0c0d); -// #endif - - in_addr_t net = inet_network("300.10.10.10"); - syslog(LOG_INFO,"net: %#"PRIx32, net); - assert_int_equal((int32_t)net, -1); - - // host order - net = inet_network("10.11.12.13"); - syslog(LOG_INFO,"host order net: %#"PRIx32, net); - assert_int_equal(net, 0x0a0b0c0d); - - const char *p = inet_ntoa(in); - syslog(LOG_INFO,"inet_ntoa p: %s", p); - assert_int_equal(strcmp(p, "10.11.12.13"), 0); - - char buf[32]; - p = inet_ntop(AF_INET, &in, buf, sizeof(buf)); - syslog(LOG_INFO,"inet_ntop p: %s", p); - assert_string_equal(p, buf); - assert_int_equal(strcmp(p, "10.11.12.13"), 0); - -} diff --git a/testsuites/kernel/socket/cases/net_socket_test_008.c b/testsuites/kernel/socket/cases/net_socket_test_008.c deleted file mode 100644 index 7f32f15..0000000 --- a/testsuites/kernel/socket/cases/net_socket_test_008.c +++ /dev/null @@ -1,261 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "SocketTest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define SERVER_PORT 9001 // -#define INVALID_SOCKET -1 // -#define BACKLOG CLIENT_NUM - -/**************************************************************************** - * Public Functions - ****************************************************************************/ -static int gFds[FD_SETSIZE]; -static int gBye; - -static void InitFds(void) -{ - for (int i = 0; i < FD_SETSIZE; ++i) { - gFds[i] = INVALID_SOCKET; - } -} - -static void GetReadfds(fd_set *fds, int *nfd) -{ - for (int i = 0; i < FD_SETSIZE; i++) { - if (gFds[i] == INVALID_SOCKET) { - continue; - } - FD_SET(gFds[i], fds); - if (*nfd < gFds[i]) { - *nfd = gFds[i]; - } - } -} - -static int AddFd(int fd) -{ - for (int i = 0; i < FD_SETSIZE; ++i) { - if (gFds[i] == INVALID_SOCKET) { - gFds[i] = fd; - return 0; - } - } - return -1; -} - -static void DelFd(int fd) -{ - for (int i = 0; i < FD_SETSIZE; ++i) { - if (gFds[i] == fd) { - gFds[i] = INVALID_SOCKET; - } - } - (void)close(fd); -} - -static int CloseAllFd(void) -{ - for (int i = 0; i < FD_SETSIZE; ++i) { - if (gFds[i] != INVALID_SOCKET) { - (void)close(gFds[i]); - gFds[i] = INVALID_SOCKET; - } - } - return 0; -} - -static int HandleRecv(int fd) -{ - char buf[256]; - int ret = recv(fd, buf, sizeof(buf)-1, 0); - if (ret < 0) { - syslog(LOG_INFO,"[%d]Error: %s", fd, strerror(errno)); - DelFd(fd); - } else if (ret == 0) { - syslog(LOG_INFO,"[%d]Closed", fd); - DelFd(fd); - } else { - buf[ret] = 0; - syslog(LOG_INFO,"[%d]Received: %s", fd, buf); - if (strstr(buf, "Bye") != NULL) { - DelFd(fd); - gBye++; - } - } - return -(ret < 0); -} - -static int HandleAccept(int lsfd) -{ - struct sockaddr_in sa; - socklen_t saLen = sizeof(sa); - int fd = accept(lsfd, (struct sockaddr *)&sa, &saLen);//? - if (fd == INVALID_SOCKET) { - perror("accept"); - return -1; - } - - if (AddFd(fd) == -1) { - syslog(LOG_INFO,"Too many clients, refuse %s:%d", inet_ntoa(sa.sin_addr), ntohs(sa.sin_port)); - close(fd); - return -1; - } - syslog(LOG_INFO,"New client %d: %s:%d", fd, inet_ntoa(sa.sin_addr), ntohs(sa.sin_port)); - return 0; -} - -static int HandleReadfds(fd_set *fds, int lsfd) -{ - int ret = 0; - for (int i = 0; i < FD_SETSIZE; ++i) { - if (gFds[i] == INVALID_SOCKET || !FD_ISSET(gFds[i], fds)) { - continue; - } - if (gFds[i] == lsfd) { - ret += HandleAccept(lsfd); - } else { - ret += HandleRecv(gFds[i]); - } - } - return ret; -} - -static void *ClientsThread(void *param) -{ - int fd; - int thrNo = (int)(intptr_t)param; - - syslog(LOG_INFO,"<%d>socket client thread started", thrNo); - fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (fd == INVALID_SOCKET) { - perror("socket"); - return NULL; - } - - struct sockaddr_in sa; - sa.sin_family = AF_INET; - sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - sa.sin_port = htons(SERVER_PORT); - if (connect(fd, (struct sockaddr *)(&sa), sizeof(sa)) == -1) { - perror("connect"); - return NULL; - } - - syslog(LOG_INFO,"[%d]<%d>connected to %s:%d successful", fd, thrNo, inet_ntoa(sa.sin_addr), SERVER_PORT); - - const char *msg[] = { - "hello, ", - "ohos, ", - "my name is net_socket_test_008, ", - "see u next time, ", - "Bye!" - }; - - for (int i = 0; i < sizeof(msg) / sizeof(msg[0]); ++i) { - if (send(fd, msg[i], strlen(msg[i]), 0) < 0) { - syslog(LOG_INFO,"[%d]<%d>send msg [%s] fail", fd, thrNo, msg[i]); - } - } - - (void)shutdown(fd, SHUT_RDWR); - (void)close(fd); - return param; -} - -static int StartClients(pthread_t *cli, int cliNum) -{ - int ret; - pthread_attr_t attr; - - for (int i = 0; i < cliNum; ++i) { - ret = pthread_attr_init(&attr); - assert_int_equal(ret, 0); - - ret = pthread_create(&cli[i], &attr, ClientsThread, (void *)(intptr_t)i); - assert_int_equal(ret, 0); - - ret = pthread_attr_destroy(&attr); - assert_int_equal(ret, 0); - } - return 0; -} - -/**************************************************************************** - * Name: TestNuttxNetSocketTest08 - ****************************************************************************/ - -void TestNuttxNetSocketTest08(FAR void **state) -{ - struct sockaddr_in sa = {0}; - int lsfd; - int ret; - - lsfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - assert_int_not_equal(lsfd, -1); - - sa.sin_family = AF_INET; - sa.sin_addr.s_addr = htonl(INADDR_ANY); - sa.sin_port = htons(SERVER_PORT); - ret = bind(lsfd, (struct sockaddr *)(&sa), sizeof(sa)); - assert_int_not_equal(ret, -1); - - ret = listen(lsfd, BACKLOG); - assert_int_not_equal(ret, -1); - - InitFds(); - AddFd(lsfd); - syslog(LOG_INFO,"[%d]Waiting for client to connect on port %d", lsfd, SERVER_PORT); - - pthread_t clients[CLIENT_NUM]; - - ret = StartClients(clients, CLIENT_NUM); - assert_int_equal(ret, 0); - - for ( ; ; ) { - int nfd; - fd_set readfds; - struct timeval timeout; - - timeout.tv_sec = 3; - timeout.tv_usec = 0; - - nfd = 0; - FD_ZERO(&readfds); - - GetReadfds(&readfds, &nfd); - - ret = select(nfd + 1, &readfds, NULL, NULL, &timeout); - syslog(LOG_INFO,"select %d", ret); - if (ret == -1) { - perror("select"); - break; // error occurred - } else if (ret == 0) { - break; // timed out - } - - if (HandleReadfds(&readfds, lsfd) < 0) { - break; - } - } - - for (int i = 0; i < CLIENT_NUM; ++i) { - ret = pthread_join(clients[i], NULL); - assert_int_equal(ret, 0); - } - - assert_int_equal(gBye, CLIENT_NUM); - (void)CloseAllFd(); -} diff --git a/testsuites/kernel/socket/cases/net_socket_test_009.c b/testsuites/kernel/socket/cases/net_socket_test_009.c deleted file mode 100644 index 2c2224b..0000000 --- a/testsuites/kernel/socket/cases/net_socket_test_009.c +++ /dev/null @@ -1,259 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "SocketTest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define SERVER_PORT 8888 -#define INVALID_SOCKET -1 -#define BACKLOG CLIENT_NUM - -/**************************************************************************** - * Public Functions - ****************************************************************************/ -static int gFds[FD_SETSIZE]; -static int gBye; - -static void InitFds(void) -{ - for (int i = 0; i < FD_SETSIZE; ++i) { - gFds[i] = INVALID_SOCKET; - } -} - -static void GetReadfds(struct pollfd *fds, int *nfd) -{ - for (int i = 0; i < FD_SETSIZE; i++) { - if (gFds[i] == INVALID_SOCKET) { - continue; - } - fds[*nfd].fd = gFds[i]; - fds[*nfd].events = POLLIN; - (*nfd)++; - } -} - -static int AddFd(int fd) -{ - for (int i = 0; i < FD_SETSIZE; ++i) { - if (gFds[i] == INVALID_SOCKET) { - gFds[i] = fd; - return 0; - } - } - return -1; -} - -static void DelFd(int fd) -{ - for (int i = 0; i < FD_SETSIZE; ++i) { - if (gFds[i] == fd) { - gFds[i] = INVALID_SOCKET; - } - } - (void)close(fd); -} - -static int CloseAllFd(void) -{ - for (int i = 0; i < FD_SETSIZE; ++i) { - if (gFds[i] != INVALID_SOCKET) { - (void)close(gFds[i]); - gFds[i] = INVALID_SOCKET; - } - } - return 0; -} - -static int HandleRecv(int fd) -{ - char buf[256]; - int ret = recv(fd, buf, sizeof(buf)-1, 0); - if (ret < 0) { - syslog(LOG_INFO,"[%d]Error: %s", fd, strerror(errno)); - DelFd(fd); - } else if (ret == 0) { - syslog(LOG_INFO,"[%d]Closed", fd); - DelFd(fd); - } else { - buf[ret] = 0; - syslog(LOG_INFO,"[%d]Received: %s", fd, buf); - if (strstr(buf, "Bye") != NULL) { - DelFd(fd); - gBye++; - } - } - return -(ret < 0); -} - -static int HandleAccept(int lsfd) -{ - struct sockaddr_in sa; - int saLen = sizeof(sa); - int fd = accept(lsfd, (struct sockaddr *)&sa, (socklen_t *)&saLen); - if (fd == INVALID_SOCKET) { - perror("accept"); - return -1; - } - - if (AddFd(fd) == -1) { - syslog(LOG_INFO,"Too many clients, refuse %s:%d", inet_ntoa(sa.sin_addr), ntohs(sa.sin_port)); - close(fd); - return -1; - } - syslog(LOG_INFO,"New client %d: %s:%d", fd, inet_ntoa(sa.sin_addr), ntohs(sa.sin_port)); - return 0; -} - -static int HandleReadfds(struct pollfd *fds, int nfds, int lsfd) -{ - int ret = 0; - for (int i = 0; i < nfds; ++i) { - if (fds[i].revents == 0) { - continue; - } - syslog(LOG_INFO,"[%d]revents: %04"PRIx32, fds[i].fd, fds[i].revents); - if (fds[i].fd == lsfd) { - ret += HandleAccept(lsfd); - } else { - ret += HandleRecv(fds[i].fd); - } - } - return ret; -} - -static void *ClientsThread(void *param) -{ - int fd; - int thrNo = (int)(intptr_t)param; - - syslog(LOG_INFO,"<%d>socket client thread started", thrNo); - fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (fd == INVALID_SOCKET) { - perror("socket"); - return NULL; - } - - struct sockaddr_in sa; - sa.sin_family = AF_INET; - sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - sa.sin_port = htons(SERVER_PORT); - if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) { - perror("connect"); - return NULL; - } - - syslog(LOG_INFO,"[%d]<%d>connected to %s:%d successful", fd, thrNo, inet_ntoa(sa.sin_addr), SERVER_PORT); - - const char *msg[] = { - "hello, ", - "ohos, ", - "my name is net_socket_test_009, ", - "see u next time, ", - "Bye!" - }; - - for (int i = 0; i < sizeof(msg) / sizeof(msg[0]); ++i) { - if (send(fd, msg[i], strlen(msg[i]), 0) < 0) { - syslog(LOG_INFO,"[%d]<%d>send msg [%s] fail", fd, thrNo, msg[i]); - } - } - - (void)shutdown(fd, SHUT_RDWR); - (void)close(fd); - return param; -} - -static int StartClients(pthread_t *cli, int cliNum) -{ - int ret; - pthread_attr_t attr; - - for (int i = 0; i < cliNum; ++i) { - ret = pthread_attr_init(&attr); - assert_int_equal(ret, 0); - - ret = pthread_create(&cli[i], &attr, ClientsThread, (void *)(intptr_t)i); - assert_int_equal(ret, 0); - - ret = pthread_attr_destroy(&attr); - assert_int_equal(ret, 0); - } - return 0; -} - -/**************************************************************************** - * Name: TestNuttxNetSocketTest09 - ****************************************************************************/ - -void TestNuttxNetSocketTest09(FAR void **state) -{ - struct sockaddr_in sa = {0}; - int lsfd; - int ret; - - lsfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - assert_int_not_equal(lsfd, -1); - - sa.sin_family = AF_INET; - sa.sin_addr.s_addr = htonl(INADDR_ANY); - sa.sin_port = htons(SERVER_PORT); - ret = bind(lsfd, (struct sockaddr *)&sa, sizeof(sa)); - assert_int_not_equal(ret, -1); - - ret = listen(lsfd, BACKLOG); - assert_int_not_equal(ret, -1); - - InitFds(); - AddFd(lsfd); - syslog(LOG_INFO,"[%d]Waiting for client to connect on port %d", lsfd, SERVER_PORT); - - pthread_t clients[CLIENT_NUM]; - - ret = StartClients(clients, CLIENT_NUM); - assert_int_equal(ret, 0); - - for ( ; ; ) { - int nfd; - struct pollfd readfds[FD_SETSIZE]; - int timeoutMs; - - timeoutMs = 3000; - nfd = 0; - GetReadfds(readfds, &nfd); - - ret = poll(readfds, nfd, timeoutMs); - syslog(LOG_INFO,"poll %d", ret); - if (ret == -1) { - perror("poll"); - break; // error occurred - } else if (ret == 0) { - break; // timed out - } - - if (HandleReadfds(readfds, nfd, lsfd) < 0) { - break; - } - } - - for (int i = 0; i < CLIENT_NUM; ++i) { - ret = pthread_join(clients[i], NULL); - assert_int_equal(ret, 0); - } - - assert_int_equal(gBye, CLIENT_NUM); - (void)CloseAllFd(); -} diff --git a/testsuites/kernel/socket/cases/net_socket_test_010.c b/testsuites/kernel/socket/cases/net_socket_test_010.c deleted file mode 100644 index 6504729..0000000 --- a/testsuites/kernel/socket/cases/net_socket_test_010.c +++ /dev/null @@ -1,184 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "SocketTest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define IFF_PROMISC 0x100 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ -static char gDefaultNetif[IFNAMSIZ] = "eth0"; - -static void InitIfreq(struct ifreq *ifr) -{ - *ifr = (struct ifreq){{0}}; - //(void)strncpy_s(ifr->ifr_name, sizeof(ifr->ifr_name) - 1, gDefaultNetif, sizeof(ifr->ifr_name) - 1); - (void)strlcpy(ifr->ifr_name, gDefaultNetif, sizeof(ifr->ifr_name)); - ifr->ifr_name[sizeof(ifr->ifr_name) - 1] = '\0'; -} - -static char *IfIndex2Name(int fd, unsigned index, char *name) -{ -#ifdef CONFIG_NETDEV_IFINDEX - return if_indextoname(index, name); -#else - struct ifreq ifr; - int ret; - - ifr.ifr_ifindex = index; - ret = ioctl(fd, SIOCGIFNAME, &ifr); - if (ret < 0) { - return NULL; - } - //ret = strncpy_s(name, IF_NAMESIZE - 1, ifr.ifr_name, IF_NAMESIZE - 1); - strncpy(name, ifr.ifr_name, IF_NAMESIZE - 1); - name[IF_NAMESIZE - 1] = '\0'; - return name; -#endif -} - -static unsigned IfName2Index(int fd, const char *name) -{ -#ifdef CONFIG_NETDEV_IFINDEX - return if_nametoindex(name); -#else - struct ifreq ifr; - int ret; - - //(void)strncpy_s(ifr.ifr_name, sizeof(ifr.ifr_name) - 1, name, sizeof(ifr.ifr_name) - 1); - (void)strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name) - 1); - ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0'; - ret = ioctl(fd, SIOCGIFINDEX, &ifr); - return ret < 0 ? 0 : ifr.ifr_ifindex; -#endif -} -/**************************************************************************** - * Name: TestNuttxNetSocketTest10 - ****************************************************************************/ - -static int IoctlTestInternal(int sfd) -{ - struct ifreq ifr = {{0}}; - char ifName[IFNAMSIZ] = {0}, *p = NULL; - unsigned int loIndex = 0; - unsigned int lanIndex = 0; - char lanName[IFNAMSIZ]; - int maxIndex = 256; - int ret; - char *ret_s = NULL; - - for (int i = 0; i < maxIndex; ++i) { - p = IfIndex2Name(sfd, i, ifName); - if (p) { - if (strcmp(p, "lo") == 0) { - loIndex = i; - } else { - lanIndex = i; - strcpy(lanName, p); - syslog(LOG_INFO,"name of lan: %s", lanName); - } - } - } - - syslog(LOG_INFO,"ifindex of lo: %u, ifindex of lan: %u", loIndex, lanIndex); - assert_int_not_equal(loIndex, 0); - assert_int_not_equal(lanIndex, 0); - - p = IfIndex2Name(sfd, loIndex, ifName); - syslog(LOG_INFO,"ifindex %u: %s", loIndex, p); - assert_non_null(p); - assert_string_equal(p, "lo"); - - p = IfIndex2Name(sfd, lanIndex, ifName); - syslog(LOG_INFO,"ifindex %u: %s", lanIndex, p); - assert_non_null(p); - assert_string_equal(p, lanName); - - //ret = strncpy_s(gDefaultNetif, sizeof(gDefaultNetif) -1, p, sizeof(gDefaultNetif) - 1); - ret_s = strncpy(gDefaultNetif, p, sizeof(gDefaultNetif) - 1); - assert_non_null(ret_s); - gDefaultNetif[sizeof(gDefaultNetif) - 1] = '\0'; - - ret = (int)IfName2Index(sfd, p); - syslog(LOG_INFO,"index of %s: %d", p, ret); - assert_int_not_equal(ret, 0); - assert_int_equal(ret, lanIndex); - - ifr.ifr_ifindex = lanIndex; - ret = ioctl(sfd, SIOCGIFNAME, &ifr); - assert_int_equal(ret, 0); - syslog(LOG_INFO,"name of ifindex %u: %s", lanIndex, ifr.ifr_name); - assert_string_equal(ifr.ifr_name, lanName); - - InitIfreq(&ifr); - ret = ioctl(sfd, SIOCGIFINDEX, &ifr); - assert_int_equal(ret, 0); - syslog(LOG_INFO,"index of ifname %s: %d", ifr.ifr_name, ifr.ifr_ifindex); - assert_int_equal(ifr.ifr_ifindex, lanIndex); - - InitIfreq(&ifr); - ret = ioctl(sfd, SIOCGIFHWADDR, &ifr); - assert_int_equal(ret, 0); - syslog(LOG_INFO,"hwaddr: %02hhX:%02hhX:%02hhX:XX:XX:XX", ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2]); - - InitIfreq(&ifr); - ret = ioctl(sfd, SIOCGIFFLAGS, &ifr); - assert_int_equal(ret, 0); - syslog(LOG_INFO,"FLAGS of ifname %s: %#"PRIx32", IFF_PROMISC: %d", ifr.ifr_name, ifr.ifr_flags, !!(ifr.ifr_flags & IFF_PROMISC)); - - if (ifr.ifr_flags & IFF_PROMISC) { - ifr.ifr_flags &= ~(IFF_PROMISC); - } else { - ifr.ifr_flags |= IFF_PROMISC; - } - syslog(LOG_INFO,"SIOCSIFFLAGS FLAGS: %#"PRIx32, ifr.ifr_flags); - ret = ioctl(sfd, SIOCSIFFLAGS, &ifr); - if (ret == -1) { - assert_int_equal(errno, EPERM); - } else { - assert_int_equal(ret, 0); - } - - InitIfreq(&ifr); - ret = ioctl(sfd, SIOCGIFFLAGS, &ifr); - assert_int_equal(ret, 0); - syslog(LOG_INFO,"FLAGS of ifname %s: %#"PRIx32", IFF_PROMISC: %d", ifr.ifr_name, ifr.ifr_flags, !!(ifr.ifr_flags & IFF_PROMISC)); - - ret = fcntl(sfd, F_GETFL, 0); - assert_int_equal(ret < 0, 0); - - ret = fcntl(sfd, F_SETFL, ret | O_NONBLOCK); - assert_int_equal(ret < 0, 0); - - return 0; -} - -void TestNuttxNetSocketTest10(FAR void **state) -{ - int sfd; - - sfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); - syslog(LOG_INFO,"socket(PF_INET, SOCK_STREAM, IPPROTO_TCP): %d", sfd); - assert_int_not_equal(sfd, -1); - - (void)IoctlTestInternal(sfd); - - (void)close(sfd); -} diff --git a/testsuites/kernel/socket/cases/net_socket_test_011.c b/testsuites/kernel/socket/cases/net_socket_test_011.c deleted file mode 100644 index 9a19d10..0000000 --- a/testsuites/kernel/socket/cases/net_socket_test_011.c +++ /dev/null @@ -1,237 +0,0 @@ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "SocketTest.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define SERVER_PORT 7777 -#define INVALID_SOCKET -1 -/**************************************************************************** - * Public Functions - ****************************************************************************/ -static int gFds[FD_SETSIZE]; -static int gBye; - -static void InitFds(void) -{ - for (int i = 0; i < FD_SETSIZE; ++i) { - gFds[i] = INVALID_SOCKET; - } -} - -static void GetReadfds(fd_set *fds, int *nfd) -{ - for (int i = 0; i < FD_SETSIZE; i++) { - if (gFds[i] == INVALID_SOCKET) { - continue; - } - FD_SET(gFds[i], fds); - if (*nfd < gFds[i]) { - *nfd = gFds[i]; - } - } -} - -static int AddFd(int fd) -{ - for (int i = 0; i < FD_SETSIZE; ++i) { - if (gFds[i] == INVALID_SOCKET) { - gFds[i] = fd; - return 0; - } - } - return -1; -} - -static void DelFd(int fd) -{ - for (int i = 0; i < FD_SETSIZE; ++i) { - if (gFds[i] == fd) { - gFds[i] = INVALID_SOCKET; - } - } - (void)close(fd); -} - -static int CloseAllFd(void) -{ - for (int i = 0; i < FD_SETSIZE; ++i) { - if (gFds[i] != INVALID_SOCKET) { - (void)close(gFds[i]); - gFds[i] = INVALID_SOCKET; - } - } - return 0; -} - -static int HandleRecv(int fd) -{ - char buf[128]; - int ret = recv(fd, buf, sizeof(buf)-1, 0); - if (ret < 0) { - syslog(LOG_INFO,"[%d]Error: %s", fd, strerror(errno)); - DelFd(fd); - } else if (ret == 0) { - syslog(LOG_INFO,"[%d]Closed", fd); - DelFd(fd); - } else { - buf[ret] = 0; - syslog(LOG_INFO,"[%d]Received: %s", fd, buf); - if (strstr(buf, "Bye") != NULL) { - gBye++; - } - } - return -(ret < 0); -} - -static int HandleReadfds(fd_set *fds, int lsfd) -{ - int ret = 0; - for (int i = 0; i < FD_SETSIZE; ++i) { - if (gFds[i] == INVALID_SOCKET || !FD_ISSET(gFds[i], fds)) { - continue; - } - ret += HandleRecv(gFds[i]); - } - return ret; -} - -static void *ClientsThread(void *param) -{ - int fd; - int thrNo = (int)(intptr_t)param; - - syslog(LOG_INFO,"<%d>socket client thread started", thrNo); - fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (fd == INVALID_SOCKET) { - perror("socket"); - return NULL; - } - - struct sockaddr_in sa; - sa.sin_family = AF_INET; - sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - sa.sin_port = htons(SERVER_PORT); - if (connect(fd, (struct sockaddr *)(&sa), sizeof(sa)) == -1) { - perror("connect"); - return NULL; - } - - syslog(LOG_INFO,"[%d]<%d>connected to udp://%s:%d successful", fd, thrNo, inet_ntoa(sa.sin_addr), SERVER_PORT); - - const char *msg[] = { - "ohos, ", - "hello, ", - "my name is net_socket_test_011, ", - "see u next time, ", - "Bye!", - }; - - for (int i = 0; i < sizeof(msg) / sizeof(msg[0]); ++i) { - if (send(fd, msg[i], strlen(msg[i]), 0) < 0) { - syslog(LOG_INFO,"[%d]<%d>send msg [%s] fail", fd, thrNo, msg[i]); - } - } - - (void)shutdown(fd, SHUT_RDWR); - (void)close(fd); - return param; -} - -static int StartClients(pthread_t *cli, int cliNum) -{ - int ret; - pthread_attr_t attr = {0}; - struct sched_param param = { 0 }; - int policy; - ret = pthread_getschedparam(pthread_self(), &policy, ¶m); - assert_int_equal(ret, 0); - - for (int i = 0; i < cliNum; ++i) { - ret = pthread_attr_init(&attr); - param.sched_priority = param.sched_priority + 1; - pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); - pthread_attr_setschedparam(&attr, ¶m); - - ret = pthread_create(&cli[i], &attr, ClientsThread, (void *)(intptr_t)i); - assert_int_equal(ret, 0); - ret = pthread_attr_destroy(&attr); - assert_int_equal(ret, 0); - } - return 0; -} -/**************************************************************************** - * Name: TestNuttxNetSocketTest11 - ****************************************************************************/ - -void TestNuttxNetSocketTest11(FAR void **state) -{ - struct sockaddr_in sa = {0}; - int lsfd; - int ret; - - lsfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - assert_int_not_equal(lsfd, -1); - - sa.sin_family = AF_INET; - sa.sin_addr.s_addr = htonl(INADDR_ANY); - sa.sin_port = htons(SERVER_PORT); - ret = bind(lsfd, (struct sockaddr *)(&sa), sizeof(sa)); - assert_int_not_equal(ret, -1); - - InitFds(); - AddFd(lsfd); - syslog(LOG_INFO,"[%d]Waiting for client to connect on UDP port %d", lsfd, SERVER_PORT); - - pthread_t clients[CLIENT_NUM]; - - ret = StartClients(clients, CLIENT_NUM); - assert_int_equal(ret, 0); - - for ( ; ; ) { - int nfd; - fd_set readfds; - struct timeval timeout; - - timeout.tv_sec = 3; - timeout.tv_usec = 0; - - nfd = 0; - FD_ZERO(&readfds); - - GetReadfds(&readfds, &nfd); - - ret = select(nfd + 1, &readfds, NULL, NULL, &timeout); - syslog(LOG_INFO,"select %d", ret); - if (ret == -1) { - perror("select"); - break; // error occurred - } else if (ret == 0) { - break; // timed out - } - - if (HandleReadfds(&readfds, lsfd) < 0) { - break; - } - } - - for (int i = 0; i < CLIENT_NUM; ++i) { - ret = pthread_join(clients[i], NULL); - assert_int_equal(ret, 0); - } - #ifdef CONFIG_NET_UDP_NOTIFIER - assert_int_equal(gBye, CLIENT_NUM); - #endif - (void)CloseAllFd(); -} \ No newline at end of file diff --git a/testsuites/kernel/socket/cmocka_socket_test.c b/testsuites/kernel/socket/cmocka_socket_test.c deleted file mode 100644 index 579a5f8..0000000 --- a/testsuites/kernel/socket/cmocka_socket_test.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2020 Xiaomi Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "SocketTest.h" -#include - -/**************************************************************************** - * Name: cmocka_sched_test_main - ****************************************************************************/ -int main(int argc, char *argv[]) -{ - - /* Add Test Cases */ - const struct CMUnitTest NuttxSocketTestSuites[] = { - cmocka_unit_test_setup_teardown(TestNuttxNetSocketTest05, NULL, NULL), - cmocka_unit_test_setup_teardown(TestNuttxNetSocketTest06, NULL, NULL), -#if defined(CONFIG_NET_LOOPBACK) || defined(CONFIG_NET_USRSOCK) - cmocka_unit_test_setup_teardown(TestNuttxNetSocketTest08, NULL, NULL), - cmocka_unit_test_setup_teardown(TestNuttxNetSocketTest09, NULL, NULL), - cmocka_unit_test_setup_teardown(TestNuttxNetSocketTest10, NULL, NULL), - cmocka_unit_test_setup_teardown(TestNuttxNetSocketTest11, NULL, NULL), -#endif - }; - - /* Run Test cases */ - cmocka_run_group_tests(NuttxSocketTestSuites, NULL, NULL); - - return 0; -} \ No newline at end of file diff --git a/testsuites/kernel/socket/include/SocketTest.h b/testsuites/kernel/socket/include/SocketTest.h deleted file mode 100644 index d5f304f..0000000 --- a/testsuites/kernel/socket/include/SocketTest.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef __TEST_H -#define __TEST_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -#define CLIENT_NUM 8 - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* test case function */ -/* cases/net_socket_test_005.c ************************************************/ -void TestNuttxNetSocketTest05(FAR void **state); -/* cases/net_socket_test_006.c ************************************************/ -void TestNuttxNetSocketTest06(FAR void **state); -/* cases/net_socket_test_008.c ************************************************/ -void TestNuttxNetSocketTest08(FAR void **state); -/* cases/net_socket_test_009.c ************************************************/ -void TestNuttxNetSocketTest09(FAR void **state); -/* cases/net_socket_test_010.c ************************************************/ -void TestNuttxNetSocketTest10(FAR void **state); -/* cases/net_socket_test_011.c ************************************************/ -void TestNuttxNetSocketTest11(FAR void **state); - -#endif