diff --git a/testing/testsuites/CMakeLists.txt b/testing/testsuites/CMakeLists.txt new file mode 100644 index 000000000..01c4db41f --- /dev/null +++ b/testing/testsuites/CMakeLists.txt @@ -0,0 +1,268 @@ +# ############################################################################## +# apps/testing/testsuites/CMakeLists.txt +# +# 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. +# +# ############################################################################## + +if(CONFIG_CM_FS_TEST) + set(INCDIR + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/fs/include ${NUTTX_DIR}/../apps/nshlib + ${NUTTX_DIR}/../apps/testing/cmocka/include) + file(GLOB FS_CSRCS ${CMAKE_CURRENT_SOURCE_DIR}/kernel/fs/cases/*.c + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/fs/common/*.c) + nuttx_add_application( + NAME + cmocka_fs_test + STACKSIZE + ${CONFIG_TESTING_TESTCASES_STACKSIZE} + PRIORITY + ${CONFIG_TESTING_TESTCASES_PRIORITY} + SRCS + kernel/fs/cmocka_fs_test.c + ${FS_CSRCS} + INCLUDE_DIRECTORIES + ${INCDIR} + DEPENDS + cmocka) +endif() + +if(CONFIG_CM_SCHED_TEST) + set(INCDIR ${CMAKE_CURRENT_SOURCE_DIR}/kernel/sched/include + ${NUTTX_DIR}/../apps/testing/cmocka/include) + file(GLOB SCHED_CSRCS ${CMAKE_CURRENT_SOURCE_DIR}/kernel/sched/cases/*.c + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/sched/common/*.c) + nuttx_add_application( + NAME + cmocka_sched_test + STACKSIZE + ${CONFIG_TESTING_TESTCASES_STACKSIZE} + PRIORITY + ${CONFIG_TESTING_TESTCASES_PRIORITY} + SRCS + kernel/sched/cmocka_sched_test.c + ${SCHED_CSRCS} + INCLUDE_DIRECTORIES + ${INCDIR} + DEPENDS + cmocka) +endif() + +if(CONFIG_CM_SYSCALL_TEST) + set(INCDIR + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/syscall/include + ${NUTTX_DIR}/../apps/nshlib ${NUTTX_DIR}/../apps/testing/cmocka/include) + file(GLOB SYSCALL_CSRCS ${CMAKE_CURRENT_SOURCE_DIR}/kernel/syscall/cases/*.c + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/syscall/common/*.c) + nuttx_add_application( + NAME + cmocka_syscall_test + STACKSIZE + ${CONFIG_TESTING_TESTCASES_STACKSIZE} + PRIORITY + ${CONFIG_TESTING_TESTCASES_PRIORITY} + SRCS + kernel/syscall/cmocka_syscall_test.c + ${SYSCALL_CSRCS} + INCLUDE_DIRECTORIES + ${INCDIR} + DEPENDS + cmocka) +endif() + +if(CONFIG_CM_MM_TEST) + set(INCDIR ${CMAKE_CURRENT_SOURCE_DIR}/kernel/mm/include + ${NUTTX_DIR}/../apps/testing/cmocka/include) + file(GLOB MM_CSRCS ${CMAKE_CURRENT_SOURCE_DIR}/kernel/mm/cases/*.c + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/mm/common/*.c) + + nuttx_add_application( + NAME + cmocka_mm_test + STACKSIZE + ${CONFIG_TESTING_TESTCASES_STACKSIZE} + PRIORITY + ${CONFIG_TESTING_TESTCASES_PRIORITY} + SRCS + kernel/mm/cmocka_mm_test.c + ${MM_CSRCS} + INCLUDE_DIRECTORIES + ${INCDIR} + DEPENDS + cmocka) + nuttx_add_application( + NAME + mem_batch_opt_perf_test + STACKSIZE + ${CONFIG_TESTING_TESTCASES_STACKSIZE} + PRIORITY + ${CONFIG_TESTING_TESTCASES_PRIORITY} + SRCS + kernel/mm/tool/mem_batch_opt_perf_test.c + INCLUDE_DIRECTORIES + ${INCDIR} + DEPENDS + cmocka) + nuttx_add_application( + NAME + mem_cycle_opt_perf_test + STACKSIZE + ${CONFIG_TESTING_TESTCASES_STACKSIZE} + PRIORITY + ${CONFIG_TESTING_TESTCASES_PRIORITY} + SRCS + kernel/mm/tool/mem_cycle_opt_perf_test.c + INCLUDE_DIRECTORIES + ${INCDIR} + DEPENDS + cmocka) +endif() + +if(CONFIG_CM_KVDB_TEST) + set(INCDIR + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/kv/include + ${NUTTX_DIR}/../frameworks/utils/include + ${NUTTX_DIR}/../apps/testing/cmocka/include) + file(GLOB KVDB_CSRCS ${CMAKE_CURRENT_SOURCE_DIR}/kernel/kv/cases/*.c + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/kv/common/*.c) + nuttx_add_application( + NAME + cmocka_kv_test + STACKSIZE + ${CONFIG_TESTING_TESTCASES_STACKSIZE} + PRIORITY + ${CONFIG_TESTING_TESTCASES_PRIORITY} + SRCS + kernel/kv/cmocka_kv_test.c + ${KVDB_CSRCS} + INCLUDE_DIRECTORIES + ${INCDIR} + DEPENDS + cmocka) +endif() + +if(CONFIG_CM_TIME_TEST) + set(INCDIR ${CMAKE_CURRENT_SOURCE_DIR}/kernel/time/include + ${NUTTX_DIR}/../apps/testing/cmocka/include ${NUTTX_DIR}/include) + file(GLOB TIME_CSRCS ${CMAKE_CURRENT_SOURCE_DIR}/kernel/time/cases/*.c) + nuttx_add_application( + NAME + cmocka_time_test + STACKSIZE + ${CONFIG_TESTING_TESTCASES_STACKSIZE} + PRIORITY + ${CONFIG_TESTING_TESTCASES_PRIORITY} + SRCS + kernel/time/cmocka_time_test.c + ${TIME_CSRCS} + INCLUDE_DIRECTORIES + ${INCDIR} + DEPENDS + cmocka) +endif() + +if(CONFIG_CM_SOCKET_TEST) + set(INCDIR ${CMAKE_CURRENT_SOURCE_DIR}/kernel/socket/include + ${NUTTX_DIR}/../apps/testing/cmocka/include) + file(GLOB SOCKET_CSRCS ${CMAKE_CURRENT_SOURCE_DIR}/kernel/socket/cases/*.c) + nuttx_add_application( + NAME + cmocka_socket_test + STACKSIZE + ${CONFIG_TESTING_TESTCASES_STACKSIZE} + PRIORITY + ${CONFIG_TESTING_TESTCASES_PRIORITY} + SRCS + kernel/socket/cmocka_socket_test.c + ${SOCKET_CSRCS} + INCLUDE_DIRECTORIES + ${INCDIR} + DEPENDS + cmocka) +endif() + +if(CONFIG_CM_PTHREAD_TEST) + set(INCDIR ${CMAKE_CURRENT_SOURCE_DIR}/kernel/pthread/include + ${NUTTX_DIR}/../apps/testing/cmocka/include) + file(GLOB PTHREAD_CSRCS ${CMAKE_CURRENT_SOURCE_DIR}/kernel/pthread/cases/*.c + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/pthread/common/*.c) + nuttx_add_application( + NAME + cmocka_pthread_test + STACKSIZE + ${CONFIG_TESTING_TESTCASES_STACKSIZE} + PRIORITY + ${CONFIG_TESTING_TESTCASES_PRIORITY} + SRCS + kernel/pthread/cmocka_pthread_test.c + ${PTHREAD_CSRCS} + INCLUDE_DIRECTORIES + ${INCDIR} + DEPENDS + cmocka) +endif() + +if(CONFIG_CM_MUTEX_TEST) + set(INCDIR ${CMAKE_CURRENT_SOURCE_DIR}/kernel/mutex/include + ${NUTTX_DIR}/../apps/testing/cmocka/include) + file(GLOB MUTEX_CSRCS ${CMAKE_CURRENT_SOURCE_DIR}/kernel/mutex/cases/*.c + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/mutex/common/*.c) + nuttx_add_application( + NAME + cmocka_mutex_test + STACKSIZE + ${CONFIG_TESTING_TESTCASES_STACKSIZE} + PRIORITY + ${CONFIG_TESTING_TESTCASES_PRIORITY} + SRCS + kernel/mutex/cmocka_mutex_test.c + ${MUTEX_CSRCS} + INCLUDE_DIRECTORIES + ${INCDIR} + DEPENDS + cmocka) +endif() + +if(CONFIG_TEST_TELEPHONY) + set(INCDIR + ${NUTTX_DIR}/../apps/frameworks/telephony/include + ${NUTTX_DIR}/../apps/testing/cmocka/cmocka/include + ${NUTTX_DIR}/../apps/testing/cmocka/include) + file( + GLOB + TELEPHONY_CSRCS + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/telephony/telephony_sim_test.c + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/telephony/telephony_call_test.c + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/telephony/telephony_data_test.c + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/telephony/telephony_sms_test.c + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/telephony/telephony_network_test.c + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/telephony/telephony_common_test.c + ${CMAKE_CURRENT_SOURCE_DIR}/kernel/telephony/telephony_ims_test.c) + nuttx_add_application( + NAME + cmocka_telephony_test + STACKSIZE + ${CONFIG_TESTING_TESTCASES_STACKSIZE} + PRIORITY + ${CONFIG_TESTING_TESTCASES_PRIORITY} + SRCS + kernel/telephony/cmocka_telephony_test.c + ${TELEPHONY_CSRCS} + INCLUDE_DIRECTORIES + ${INCDIR} + DEPENDS + cmocka) +endif() diff --git a/testing/testsuites/Kconfig b/testing/testsuites/Kconfig new file mode 100644 index 000000000..cefc9c405 --- /dev/null +++ b/testing/testsuites/Kconfig @@ -0,0 +1,88 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config TESTS_TESTSUITES + tristate "vela test suite" + default n + depends on TESTING_CMOCKA + ---help--- + Enable testsuites for the vela + +if TESTS_TESTSUITES + +config TESTS_TESTSUITES_MOUNT_DIR + string "Mount directory for the testsuites" + default "/data" + +config TESTS_TESTSUITES_PRIORITY + int "Testsuites task priority" + default 99 + +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 + depends on TESTS_TESTSUITES + +config CM_SYSCALL_TEST + bool "enbale 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 + depends on TESTS_TESTSUITES + +config CM_TIME_TEST + bool "enbale 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 + depends on TESTS_TESTSUITES + +config CM_MUTEX_TEST + bool "enbale mutex test" + default n + depends on TESTS_TESTSUITES + +config TEST_TELEPHONY + bool "enbale telephony test" + default n + depends on TESTS_TESTSUITES + +if TEST_TELEPHONY + config TEST_PHONE_NUMBER + string "test phone number" + default "10086" +endif + +config CM_DFX_TEST + bool "enbale dfx test" + default n + depends on TESTS_TESTSUITES + +endif # TESTS_TESTSUITES diff --git a/testing/testsuites/Make.defs b/testing/testsuites/Make.defs new file mode 100644 index 000000000..03ab762a1 --- /dev/null +++ b/testing/testsuites/Make.defs @@ -0,0 +1,24 @@ +############################################################################ +# apps/testing/testsuites/Make.defs +# +# 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. +# +# +############################################################################ + +ifneq ($(CONFIG_TESTS_TESTSUITES),) +CONFIGURED_APPS += $(APPDIR)/testing/testsuites +endif diff --git a/testing/testsuites/Makefile b/testing/testsuites/Makefile new file mode 100644 index 000000000..0424203eb --- /dev/null +++ b/testing/testsuites/Makefile @@ -0,0 +1,132 @@ +# apps/tests/testsuites/Makefile +# +# 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. + +include $(APPDIR)/Make.defs + + +PRIORITY = $(CONFIG_TESTS_TESTSUITES_PRIORITY) +STACKSIZE = $(CONFIG_TESTS_TESTSUITES_STACKSIZE) +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) +CSRCS += $(wildcard kernel/sched/common/*.c) +PROGNAME += cmocka_sched_test +MAINSRC += $(CURDIR)/kernel/sched/cmocka_sched_test.c +endif + +ifneq ($(CONFIG_CM_SYSCALL_TEST),) +CFLAGS += -I$(CURDIR)/kernel/syscall/include +CFLAGS += -I$(APPDIR)/nshlib +CSRCS += $(wildcard kernel/syscall/cases/*.c) +CSRCS += $(wildcard kernel/syscall/common/*.c) +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 +CSRCS += $(wildcard kernel/kv/cases/*.c) +CSRCS += $(wildcard kernel/kv/common/*.c) +PROGNAME += cmocka_kv_test +MAINSRC += $(CURDIR)/kernel/kv/cmocka_kv_test.c +endif + +ifneq ($(CONFIG_CM_TIME_TEST),) +CFLAGS += -I$(CURDIR)/kernel/time/include +CSRCS += $(wildcard kernel/time/cases/*.c) +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) +CSRCS += $(wildcard kernel/pthread/common/*.c) +PROGNAME += cmocka_pthread_test +MAINSRC += $(CURDIR)/kernel/pthread/cmocka_pthread_test.c +endif + +ifneq ($(CONFIG_CM_MUTEX_TEST),) +CFLAGS += -I$(CURDIR)/kernel/mutex/include +CSRCS += $(wildcard kernel/mutex/cases/*.c) +CSRCS += $(wildcard kernel/mutex/common/*.c) +PROGNAME += cmocka_mutex_test +MAINSRC += $(CURDIR)/kernel/mutex/cmocka_mutex_test.c +endif + +ifneq ($(CONFIG_TEST_TELEPHONY),) + CFLAGS += -I$(APPDIR)/frameworks/telephony/include + CFLAGS += -I$(APPDIR)/testing/cmocka/cmocka/include + CSRCS += $(CURDIR)/kernel/telephony/telephony_sim_test.c \ + $(CURDIR)/kernel/telephony/telephony_call_test.c \ + $(CURDIR)/kernel/telephony/telephony_data_test.c \ + $(CURDIR)/kernel/telephony/telephony_sms_test.c \ + $(CURDIR)/kernel/telephony/telephony_network_test.c \ + $(CURDIR)/kernel/telephony/telephony_common_test.c \ + $(CURDIR)/kernel/telephony/telephony_ims_test.c \ + $(CURDIR)/kernel/telephony/telephony_ss_test.c + PROGNAME += cmocka_telephony_test + ifneq ($(CONFIG_GOLDFISH_RIL),) + MAINSRC += $(CURDIR)/kernel/telephony/cmocka_telephony_test.c + else + MAINSRC += $(CURDIR)/kernel/telephony/product_telephony_test.c + endif + +depend:: + $(Q) touch $(MAINSRC) +endif + +ifneq ($(CONFIG_CM_DFX_TEST),) +CFLAGS += -I$(CURDIR)/kernel/dfx/include +CFLAGS += -I$(APPDIR)/frameworks/dfx/include +CSRCS += $(wildcard kernel/dfx/cases/*.c) +PROGNAME += cmocka_dfx_test +MAINSRC += $(CURDIR)/kernel/dfx/cmocka_dfx_test.c +endif + +include $(APPDIR)/Application.mk diff --git a/testing/testsuites/kernel/dfx/cases/dfx_test_event.c b/testing/testsuites/kernel/dfx/cases/dfx_test_event.c new file mode 100644 index 000000000..59446cd2c --- /dev/null +++ b/testing/testsuites/kernel/dfx/cases/dfx_test_event.c @@ -0,0 +1,54 @@ +/**************************************************************************** + * 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 + +/**************************************************************************** + * 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/testing/testsuites/kernel/dfx/cmocka_dfx_test.c b/testing/testsuites/kernel/dfx/cmocka_dfx_test.c new file mode 100644 index 000000000..356d9405e --- /dev/null +++ b/testing/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/testing/testsuites/kernel/dfx/include/DFXTest.h b/testing/testsuites/kernel/dfx/include/DFXTest.h new file mode 100644 index 000000000..d73dab857 --- /dev/null +++ b/testing/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/testing/testsuites/kernel/fs/cases/fs_append_test.c b/testing/testsuites/kernel/fs/cases/fs_append_test.c new file mode 100644 index 000000000..691109c4c --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_append_test.c @@ -0,0 +1,103 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_append_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 +#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 + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void test_nuttx_fs_append01(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/testing/testsuites/kernel/fs/cases/fs_creat_test.c b/testing/testsuites/kernel/fs/cases/fs_creat_test.c new file mode 100644 index 000000000..af88a4292 --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_creat_test.c @@ -0,0 +1,81 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_creat_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 +#include +#include +#include +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define TESTFILENAME "creatTestFile" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_creat01 + ****************************************************************************/ + +void test_nuttx_fs_creat01(FAR void **state) +{ + int fd; + int 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); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_dup2_test.c b/testing/testsuites/kernel/fs/cases/fs_dup2_test.c new file mode 100644 index 000000000..7e5faefe5 --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_dup2_test.c @@ -0,0 +1,115 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_dup2_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 +#include +#include +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define TESTFILE "testDup2File1" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_dup201 + ****************************************************************************/ + +void test_nuttx_fs_dup201(FAR void **state) +{ + char buf[16] = + { + 0 + }; + + off_t currpos; + struct fs_testsuites_state_s *test_state; + + test_state = (struct fs_testsuites_state_s *)*state; + + /* open file */ + + int fd1 = open(TESTFILE, O_RDWR | O_CREAT, 0777); + assert_true(fd1 > 0); + test_state->fd1 = fd1; + + /* open file */ + + int fd2 = open(TESTFILE, O_RDWR | O_CREAT, 0777); + assert_true(fd2 > 0); + test_state->fd2 = fd2; + + /* do dup2 */ + + int ret = dup2(fd1, fd2); + assert_int_not_equal(ret, -1); + + char *buf1 = "hello "; + char *buf2 = "world!"; + + /* do write */ + + int ret2; + ret2 = write(fd1, buf1, strlen(buf1)); + assert_int_in_range(ret2, 1, strlen(buf1)); + ret2 = write(fd2, buf2, strlen(buf2)); + assert_int_in_range(ret2, 1, strlen(buf2)); + + /* refresh to storage */ + + assert_int_equal(fsync(fd1), 0); + + /* reset file pos use fd2 */ + + lseek(fd2, 0, SEEK_SET); + + /* check if file pos is shared */ + + currpos = lseek(fd1, 0, SEEK_CUR); + assert_int_equal(currpos, 0); + + /* read file */ + + ret = read(fd1, buf, 12); + assert_int_equal(ret, 12); + + /* check buf */ + + ret = strncmp(buf, "hello world!", 12); + assert_int_equal(ret, 0); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_dup_test.c b/testing/testsuites/kernel/fs/cases/fs_dup_test.c new file mode 100644 index 000000000..7b57379ca --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_dup_test.c @@ -0,0 +1,113 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_dup_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 +#include +#include +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define TESTFILENAME "testDupFile" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_dup01 + ****************************************************************************/ + +void test_nuttx_fs_dup01(FAR void **state) +{ + int fd; + int newfd; + int 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/testing/testsuites/kernel/fs/cases/fs_eventfd_test.c b/testing/testsuites/kernel/fs/cases/fs_eventfd_test.c new file mode 100644 index 000000000..805311eb5 --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_eventfd_test.c @@ -0,0 +1,96 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_eventfd_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 +#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: test_nuttx_fs_eventfd + ****************************************************************************/ + +void test_nuttx_fs_eventfd(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/testing/testsuites/kernel/fs/cases/fs_fcntl_test.c b/testing/testsuites/kernel/fs/cases/fs_fcntl_test.c new file mode 100644 index 000000000..94007b22a --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_fcntl_test.c @@ -0,0 +1,243 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_fcntl_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 +#include +#include "fstest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +#define BUFSIZE 512 +#define TEST_FILE_1 "fcntl01_testfile" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_fcntl01 + ****************************************************************************/ + +void test_nuttx_fs_fcntl01(FAR void **state) +{ + char *buf = NULL; + int oldfd; + int newfd; + int 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: test_nuttx_fs_fcntl02 + ****************************************************************************/ + +void test_nuttx_fs_fcntl02(FAR void **state) +{ + int fd; + int ret; + int 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; + int 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: test_nuttx_fs_fcntl03 + ****************************************************************************/ + +void test_nuttx_fs_fcntl03(FAR void **state) +{ + int fd; + int ret; + int size; + int 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); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_fstat_test.c b/testing/testsuites/kernel/fs/cases/fs_fstat_test.c new file mode 100644 index 000000000..e0eb6c8de --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_fstat_test.c @@ -0,0 +1,146 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_fstat_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 +#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: test_nuttx_fs_fstat01 + ****************************************************************************/ + +void test_nuttx_fs_fstat01(FAR void **state) +{ + struct stat file_s; + int fd; + int 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: test_nuttx_fs_fstat02 + ****************************************************************************/ + +void test_nuttx_fs_fstat02(FAR void **state) +{ + int fd; + int 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 + */ +} diff --git a/testing/testsuites/kernel/fs/cases/fs_fstatfs_test.c b/testing/testsuites/kernel/fs/cases/fs_fstatfs_test.c new file mode 100644 index 000000000..ab6653878 --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_fstatfs_test.c @@ -0,0 +1,109 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_fstatfs_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 +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define TEST_FILE "fstat_test_file" +#define BUF_SIZE 512 + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_printstatfs + ****************************************************************************/ + +__attribute__((unused)) static void +test_nuttx_fs_printstatfs(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: test_nuttx_fs_fstatfs01 + ****************************************************************************/ + +void test_nuttx_fs_fstatfs01(FAR void **state) +{ + struct statfs statfsbuf; + int ret; + int 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); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_fsync_test.c b/testing/testsuites/kernel/fs/cases/fs_fsync_test.c new file mode 100644 index 000000000..6c2895cab --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_fsync_test.c @@ -0,0 +1,166 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_fsync_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 +#include +#include +#include +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define TESTFILE "FsyncTestFile" +#define BUF \ + "testData123#$%*-=/ " \ + "sdafasd37575sasdfasdf356345634563456ADSFASDFASDFQWREdf4as5df4as5dfs" \ + "d ###" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_fsync01 + ****************************************************************************/ + +void test_nuttx_fs_fsync01(FAR void **state) +{ + /* clock_t start, finish; */ + + int fd; + int rval; + int 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: test_nuttx_fs_fsync02 + ****************************************************************************/ + +void test_nuttx_fs_fsync02(FAR void **state) +{ + int fd; + int ret; + char *buf = NULL; + int bufsize = 4096; + ssize_t writen = 0; + struct statfs statfsbuf; + struct fs_testsuites_state_s *test_state; + struct mallinfo mem_info; + + memset(&mem_info, 0, sizeof(mem_info)); + 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); +#ifdef CONFIG_ARCH_SIM + bufsize = statfsbuf.f_bsize; +#else + get_mem_info(&mem_info); + if (mem_info.mxordblk < statfsbuf.f_bsize) + { + bufsize = mem_info.mxordblk - 16; + } + + else + { + bufsize = statfsbuf.f_bsize; + } + +#endif + syslog(LOG_INFO, "the fbsize = %d,buffer size=%d\n", statfsbuf.f_bsize, + bufsize); + + /* 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); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_getfilep_test.c b/testing/testsuites/kernel/fs/cases/fs_getfilep_test.c new file mode 100644 index 000000000..41a19cbd7 --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_getfilep_test.c @@ -0,0 +1,117 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_getfilep_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 +#include "fstest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define TEST_FILE "fstat_test_file" +#define BUF_SIZE 512 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_getfilep01 + ****************************************************************************/ + +void test_nuttx_fs_getfilep01(FAR void **state) +{ + FAR struct file *filep; + int ret; + int 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); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_mkdir_test.c b/testing/testsuites/kernel/fs/cases/fs_mkdir_test.c new file mode 100644 index 000000000..a44eed1c7 --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_mkdir_test.c @@ -0,0 +1,86 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_mkdir_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 +#include +#include +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_mkdir01 + ****************************************************************************/ + +void test_nuttx_fs_mkdir01(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); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_open_test.c b/testing/testsuites/kernel/fs/cases/fs_open_test.c new file mode 100644 index 000000000..cd45266ce --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_open_test.c @@ -0,0 +1,120 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_open_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 +#include +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define TESTFILE "testOpenFile" +#define TESTDIR "testOpenDir" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_open01 + ****************************************************************************/ + +void test_nuttx_fs_open01(FAR void **state) +{ + int fd; + int ret; + char s[] = "test data!"; + char 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); +} + +/**************************************************************************** + * Name: test_nuttx_fs_open02 + ****************************************************************************/ + +void test_nuttx_fs_open02(FAR void **state) +{ + int fd = -1; + int ret = 0; + + /* create a dir for test */ + + ret = mkdir(TESTDIR, 0777); + assert_int_equal(ret, 0); + + /* open file with RDONLY:fatfs will fail,so skip currently 2024-9-25 + */ + +#if 0 + fd = open(TESTDIR, O_RDONLY); + assert_true(fd > 0); + close(fd); +#endif + /* open file with RDWR */ + + fd = open(TESTDIR, O_RDWR); + assert_true(fd < 0); + + /* do rmdir */ + + assert_int_equal(rmdir(TESTDIR), 0); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_opendir_test.c b/testing/testsuites/kernel/fs/cases/fs_opendir_test.c new file mode 100644 index 000000000..83864b49d --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_opendir_test.c @@ -0,0 +1,135 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_opendir_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 +#include +#include +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_opendir01 + ****************************************************************************/ + +void test_nuttx_fs_opendir01(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: test_nuttx_fs_opendir02 + ****************************************************************************/ + +void test_nuttx_fs_opendir02(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); + } +} diff --git a/testing/testsuites/kernel/fs/cases/fs_poll_test.c b/testing/testsuites/kernel/fs/cases/fs_poll_test.c new file mode 100644 index 000000000..896ea7b9d --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_poll_test.c @@ -0,0 +1,82 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_poll_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 +#include +#include +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define I_FILE1 "poll_test1" +#define I_FILE2 "poll_test2" +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_poll01 + ****************************************************************************/ + +void test_nuttx_fs_poll01(FAR void **state) +{ + int poll01_fd1; + int poll01_fd2; + int 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/testing/testsuites/kernel/fs/cases/fs_pread_test.c b/testing/testsuites/kernel/fs/cases/fs_pread_test.c new file mode 100644 index 000000000..8af428459 --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_pread_test.c @@ -0,0 +1,102 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_pread_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 +#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: test_nuttx_fs_pread01 + ****************************************************************************/ + +void test_nuttx_fs_pread01(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); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_pwrite_test.c b/testing/testsuites/kernel/fs/cases/fs_pwrite_test.c new file mode 100644 index 000000000..9c8fadd1b --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_pwrite_test.c @@ -0,0 +1,111 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_pwrite_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 +#include +#include +#include +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define TEST_FILE "pwrite_file" +#define BUF_SIZE 4 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_pwrite01 + ****************************************************************************/ + +void test_nuttx_fs_pwrite01(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); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_read_test.c b/testing/testsuites/kernel/fs/cases/fs_read_test.c new file mode 100644 index 000000000..f0164894a --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_read_test.c @@ -0,0 +1,77 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_read_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 +#include +#include +#include +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define TESTFILE "testRead01File1" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_read01 + ****************************************************************************/ + +void test_nuttx_fs_read01(FAR void **state) +{ + int fd; + int size; + char s[] = "Test!"; + char 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/testing/testsuites/kernel/fs/cases/fs_readdir_test.c b/testing/testsuites/kernel/fs/cases/fs_readdir_test.c new file mode 100644 index 000000000..c7b9b0e5c --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_readdir_test.c @@ -0,0 +1,104 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_readdir_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 +#include +#include +#include +#include +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_readdir01 + ****************************************************************************/ + +void test_nuttx_fs_readdir01(FAR void **state) +{ + int fd; + int 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); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_readlink_test.c b/testing/testsuites/kernel/fs/cases/fs_readlink_test.c new file mode 100644 index 000000000..b01da9607 --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_readlink_test.c @@ -0,0 +1,100 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_readlink_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 +#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: test_nuttx_fs_readlink01 + ****************************************************************************/ + +void test_nuttx_fs_readlink01(FAR void **state) +{ + int ret; + int 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); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_rename_test.c b/testing/testsuites/kernel/fs/cases/fs_rename_test.c new file mode 100644 index 000000000..656d575d1 --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_rename_test.c @@ -0,0 +1,99 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_rename_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 +#include +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_rename01 + ****************************************************************************/ + +void test_nuttx_fs_rename01(FAR void **state) +{ + int fd; + int status; + int ret; + char buffer[50]; + char filename1[] = "testRenameFile1"; + + /* open file */ + + fd = open(filename1, O_WRONLY | O_CREAT, 0700); + assert_true(fd > 0); + + /* set memory */ + + memset(buffer, '*', 50); + + /* do write */ + + ret = write(fd, buffer, 50); + assert_int_in_range(ret, 1, 50); + + /* close file befor rename */ + + close(fd); + + /* do rename */ + + status = rename(filename1, "newNameFile1"); + assert_int_equal(status, 0); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_rename02 + ****************************************************************************/ + +void test_nuttx_fs_rename02(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); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_rewinddir_test.c b/testing/testsuites/kernel/fs/cases/fs_rewinddir_test.c new file mode 100644 index 000000000..f88645e14 --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_rewinddir_test.c @@ -0,0 +1,200 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_rewinddir_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 +#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: test_nuttx_fs_cteatfile + ****************************************************************************/ + +static void test_nuttx_fs_cteatfile(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: test_nuttx_fs_rewinddir01 + ****************************************************************************/ + +void test_nuttx_fs_rewinddir01(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 */ + + test_nuttx_fs_cteatfile(TEST_CHILD_FILE1, 10); + test_nuttx_fs_cteatfile(TEST_CHILD_FILE2, 10); + test_nuttx_fs_cteatfile(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); + } +} diff --git a/testing/testsuites/kernel/fs/cases/fs_rmdir_test.c b/testing/testsuites/kernel/fs/cases/fs_rmdir_test.c new file mode 100644 index 000000000..57e84ca2f --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_rmdir_test.c @@ -0,0 +1,408 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_rmdir_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 +#include +#include +#include +#include +#include +#include "fstest.h" +#include "nsh.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define PARENTDIR1 "parentDirName" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_rmdir01 + ****************************************************************************/ + +void test_nuttx_fs_rmdir01(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: test_nuttx_fs_rmdir02 + ****************************************************************************/ + +void test_nuttx_fs_rmdir02(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: test_nuttx_fs_rmdir03 + ****************************************************************************/ + +void test_nuttx_fs_rmdir03(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/testing/testsuites/kernel/fs/cases/fs_seek_test.c b/testing/testsuites/kernel/fs/cases/fs_seek_test.c new file mode 100644 index 000000000..da49382ea --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_seek_test.c @@ -0,0 +1,281 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_seek_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 +#include +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define TESTFILE "fileSeekTest" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_seek01 + ****************************************************************************/ + +void test_nuttx_fs_seek01(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: test_nuttx_fs_verifylseek + ****************************************************************************/ + +static int test_nuttx_fs_verifylseek(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: test_nuttx_fs_set + ****************************************************************************/ + +static void test_nuttx_fs_set(void) +{ + fd = open(TFILE, O_RDWR | O_CREAT, 0700); + assert_true(fd >= 0); + write(fd, WRITE_STR, sizeof(WRITE_STR) - 1); +} + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_clean + ****************************************************************************/ + +static void test_nuttx_fs_clean(void) +{ + if (fd > 0) + close(fd); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_seek02 + ****************************************************************************/ + +void test_nuttx_fs_seek02(FAR void **state) +{ + int ret; + struct fs_testsuites_state_s *test_state; + + test_state = (struct fs_testsuites_state_s *)*state; + test_nuttx_fs_set(); + test_state->fd1 = fd; + + /* do verify lseek */ + + ret = test_nuttx_fs_verifylseek(0); + assert_int_equal(ret, 0); + + /* do verify lseek */ + + ret = test_nuttx_fs_verifylseek(1); + assert_int_equal(ret, 0); + + /* do verify lseek */ + + ret = test_nuttx_fs_verifylseek(2); + assert_int_equal(ret, 0); + + /* do verify lseek */ + + ret = test_nuttx_fs_verifylseek(3); + assert_int_equal(ret, 0); + + /* do clean */ + + test_nuttx_fs_clean(); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_sendfile_test.c b/testing/testsuites/kernel/fs/cases/fs_sendfile_test.c new file mode 100644 index 000000000..eb6dec014 --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_sendfile_test.c @@ -0,0 +1,200 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_sendfile_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 +#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 + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void test_nuttx_fs_sendfile01(FAR void **state) +{ + int ret; + int fd_o1; + int fd_o2; + int 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 test_nuttx_fs_sendfile02(FAR void **state) +{ + int fd_o; + int 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/testing/testsuites/kernel/fs/cases/fs_stat_test.c b/testing/testsuites/kernel/fs/cases/fs_stat_test.c new file mode 100644 index 000000000..3420b3073 --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_stat_test.c @@ -0,0 +1,165 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_stat_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 +#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: test_nuttx_fs_printtime + ****************************************************************************/ + +__attribute__((unused)) static void test_nuttx_fs_printtime(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: test_nuttx_fs_stat01 + ****************************************************************************/ + +void test_nuttx_fs_stat01(FAR void **state) +{ + int fd; + int ret; + int ret2; + struct stat file_s; + char buf[BUF_SIZE] = + { + 0 + }; + + struct tm *tm_1 = NULL; + struct tm *tm_2 = NULL; + int year1; + int year2; + int month1; + int month2; + int day1; + int day2; + int hour1; + int hour2; + int min1; + int min2; + time_t t_1; + time_t 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/testing/testsuites/kernel/fs/cases/fs_statfs_test.c b/testing/testsuites/kernel/fs/cases/fs_statfs_test.c new file mode 100644 index 000000000..8fa30b8e3 --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_statfs_test.c @@ -0,0 +1,93 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_statfs_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 +#include +#include +#include +#include +#include +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define _1k 1024 + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_printstatfs + ****************************************************************************/ + +__attribute__((unused)) static void +test_nuttx_fs_printstatfs(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: test_nuttx_fs_statfs01 + ****************************************************************************/ + +void test_nuttx_fs_statfs01(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); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_stream_test.c b/testing/testsuites/kernel/fs/cases/fs_stream_test.c new file mode 100644 index 000000000..2c8534d85 --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_stream_test.c @@ -0,0 +1,469 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_stream_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 +#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 + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void test_nuttx_fs_stream01(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 test_nuttx_fs_stream02(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); + } + + usleep(1000); + 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); + usleep(40000); + } +} + +/**************************************************************************** + * 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 test_nuttx_fs_stream03(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 test_nuttx_fs_stream04(FAR void **state) +{ + FILE *stream; + char buf[10]; + int nr; + int 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); + } +} diff --git a/testing/testsuites/kernel/fs/cases/fs_symlink_test.c b/testing/testsuites/kernel/fs/cases/fs_symlink_test.c new file mode 100644 index 000000000..05f6a908e --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_symlink_test.c @@ -0,0 +1,141 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_symlink_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 +#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: test_nuttx_fs_runtest + ****************************************************************************/ + +static int test_nuttx_fs_runtest(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: test_nuttx_fs_symlink01 + ****************************************************************************/ + +void test_nuttx_fs_symlink01(FAR void **state) +{ + int fd; + int 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); + + /* do run test */ + + ret = test_nuttx_fs_runtest(); + + /* close file */ + + close(fd); + + /* do remove */ + + unlink(path); + + assert_int_equal(ret, OK); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_truncate_test.c b/testing/testsuites/kernel/fs/cases/fs_truncate_test.c new file mode 100644 index 000000000..32afc989c --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_truncate_test.c @@ -0,0 +1,119 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_truncate_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 +#include +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define TESTFILE "truncateTestFile" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_truncate01 + ****************************************************************************/ + +void test_nuttx_fs_truncate01(FAR void **state) +{ + int fd; + int ret; + int 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/testing/testsuites/kernel/fs/cases/fs_unlink_test.c b/testing/testsuites/kernel/fs/cases/fs_unlink_test.c new file mode 100644 index 000000000..7097bc114 --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_unlink_test.c @@ -0,0 +1,94 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_unlink_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 +#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: test_nuttx_fs_unlink01 + ****************************************************************************/ + +void test_nuttx_fs_unlink01(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); +} diff --git a/testing/testsuites/kernel/fs/cases/fs_write_test.c b/testing/testsuites/kernel/fs/cases/fs_write_test.c new file mode 100644 index 000000000..954704ed2 --- /dev/null +++ b/testing/testsuites/kernel/fs/cases/fs_write_test.c @@ -0,0 +1,172 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cases/fs_write_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 +#include +#include +#include +#include +#include "fstest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define TESTFILE "testWriteFile" +#define MAXLEN 1024 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_fs_write01 + ****************************************************************************/ + +void test_nuttx_fs_write01(FAR void **state) +{ + int out; + int 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: test_nuttx_fs_write02 + ****************************************************************************/ + +void test_nuttx_fs_write02(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: test_nuttx_fs_write03 + ****************************************************************************/ + +void test_nuttx_fs_write03(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/testing/testsuites/kernel/fs/cmocka_fs_test.c b/testing/testsuites/kernel/fs/cmocka_fs_test.c new file mode 100644 index 000000000..f4b581f81 --- /dev/null +++ b/testing/testsuites/kernel/fs/cmocka_fs_test.c @@ -0,0 +1,203 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/cmocka_fs_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 "fstest.h" + +/**************************************************************************** + * Name: cmocka_fs_test_main + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int main(int argc, char *argv[]) +{ + /* Add Test Cases */ + + const struct CMUnitTest nuttx_fs_test_suites[] = + { + cmocka_unit_test_setup_teardown(test_nuttx_fs_creat01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_dup01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + /* cmocka_unit_test_setup_teardown(test_nuttx_fs_dup201, + * test_nuttx_fs_test_group_setup, test_nuttx_fs_test_group_teardown), + */ + + cmocka_unit_test_setup_teardown(test_nuttx_fs_fcntl01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), +#ifndef CONFIG_ARCH_SIM + cmocka_unit_test_setup_teardown(test_nuttx_fs_fcntl02, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_fcntl03, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), +#endif + cmocka_unit_test_setup_teardown(test_nuttx_fs_fstat01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), +#ifndef CONFIG_ARCH_SIM + cmocka_unit_test_setup_teardown(test_nuttx_fs_fstat02, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), +#endif + cmocka_unit_test_setup_teardown(test_nuttx_fs_fstatfs01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_fsync01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_fsync02, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_getfilep01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_mkdir01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_open01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_open02, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_opendir01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_opendir02, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_pread01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_pwrite01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), +#ifndef CONFIG_ARCH_SIM + cmocka_unit_test_setup_teardown(test_nuttx_fs_read01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), +#endif + cmocka_unit_test_setup_teardown(test_nuttx_fs_readdir01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_readlink01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_rename01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_rename02, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_rewinddir01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_rmdir01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_rmdir02, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_rmdir03, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_seek01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_seek02, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), +#ifndef CONFIG_ARCH_SIM + cmocka_unit_test_setup_teardown(test_nuttx_fs_stat01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), +#endif + cmocka_unit_test_setup_teardown(test_nuttx_fs_statfs01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_symlink01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_truncate01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_unlink01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_write01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_write02, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_write03, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_append01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_sendfile01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_sendfile02, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_stream01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_stream02, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_stream03, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_stream04, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_eventfd, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_fs_poll01, + test_nuttx_fs_test_group_setup, + test_nuttx_fs_test_group_teardown), + }; + + /* Run Test cases */ + + cmocka_run_group_tests(nuttx_fs_test_suites, NULL, NULL); + return 0; +} diff --git a/testing/testsuites/kernel/fs/common/test_fs_common.c b/testing/testsuites/kernel/fs/common/test_fs_common.c new file mode 100644 index 000000000..3761f8fac --- /dev/null +++ b/testing/testsuites/kernel/fs/common/test_fs_common.c @@ -0,0 +1,226 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/common/test_fs_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 + ****************************************************************************/ +#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 get_mem_info(struct mallinfo *mem_info) +{ + *mem_info = mallinfo(); + return 0; +} + +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: test_nuttx_fs_test_group_setup + ****************************************************************************/ + +int test_nuttx_fs_test_group_setup(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: test_nuttx_fs_testgroupteardown + ****************************************************************************/ + +int test_nuttx_fs_test_group_teardown(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/testing/testsuites/kernel/fs/include/fstest.h b/testing/testsuites/kernel/fs/include/fstest.h new file mode 100644 index 000000000..f16677fb6 --- /dev/null +++ b/testing/testsuites/kernel/fs/include/fstest.h @@ -0,0 +1,244 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/fs/include/fstest.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 __TEST_H +#define __TEST_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#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 test_nuttx_fs_test_group_setup(FAR void **state); +int test_nuttx_fs_test_group_teardown(FAR void **state); +int get_mem_info(struct mallinfo *mem_info); + +/* cases/fs_creat_test.c + * ************************************************/ + +void test_nuttx_fs_creat01(FAR void **state); + +/* cases/fs_dup_test.c + * ************************************************/ + +void test_nuttx_fs_dup01(FAR void **state); + +/* cases/fs_dup2_test.c + * ************************************************/ + +void test_nuttx_fs_dup201(FAR void **state); + +/* cases/fs_fcntl_test.c + * ************************************************/ + +void test_nuttx_fs_fcntl01(FAR void **state); +void test_nuttx_fs_fcntl02(FAR void **state); +void test_nuttx_fs_fcntl03(FAR void **state); + +/* cases/fs_fstat_test.c + * ************************************************/ + +void test_nuttx_fs_fstat01(FAR void **state); +void test_nuttx_fs_fstat02(FAR void **state); + +/* cases/fs_fstatfs_test.c + * ************************************************/ + +void test_nuttx_fs_fstatfs01(FAR void **state); + +/* cases/fs_fsync_test.c + * ************************************************/ + +void test_nuttx_fs_fsync01(FAR void **state); +void test_nuttx_fs_fsync02(FAR void **state); + +/* cases/fs_getfilep_test.c + * ************************************************/ + +void test_nuttx_fs_getfilep01(FAR void **state); + +/* cases/fs_mkdir_test.c + * ************************************************/ + +void test_nuttx_fs_mkdir01(FAR void **state); + +/* cases/fs_open_test.c + * ************************************************/ + +void test_nuttx_fs_open01(FAR void **state); +void test_nuttx_fs_open02(FAR void **state); + +/* cases/fs_opendir_test.c + * ************************************************/ + +void test_nuttx_fs_opendir01(FAR void **state); +void test_nuttx_fs_opendir02(FAR void **state); + +/* cases/fs_pread_test.c + * ************************************************/ + +void test_nuttx_fs_pread01(FAR void **state); + +/* cases/fs_pwrite_test.c + * ************************************************/ + +void test_nuttx_fs_pwrite01(FAR void **state); + +/* cases/fs_read_test.c + * ************************************************/ + +void test_nuttx_fs_read01(FAR void **state); + +/* cases/fs_readdir_test.c + * ************************************************/ + +void test_nuttx_fs_readdir01(FAR void **state); + +/* cases/fs_readlink_test.c + * ************************************************/ + +void test_nuttx_fs_readlink01(FAR void **state); + +/* cases/fs_rename_test.c + * ************************************************/ + +void test_nuttx_fs_rename01(FAR void **state); +void test_nuttx_fs_rename02(FAR void **state); + +/* cases/fs_rewinddir_test.c + * ************************************************/ + +void test_nuttx_fs_rewinddir01(FAR void **state); + +/* cases/fs_rmdir_test.c + * ************************************************/ + +void test_nuttx_fs_rmdir01(FAR void **state); +void test_nuttx_fs_rmdir02(FAR void **state); +void test_nuttx_fs_rmdir03(FAR void **state); + +/* cases/fs_seek_test.c + * ************************************************/ + +void test_nuttx_fs_seek01(FAR void **state); +void test_nuttx_fs_seek02(FAR void **state); + +/* cases/fs_stat_test.c + * ************************************************/ + +void test_nuttx_fs_stat01(FAR void **state); + +/* cases/fs_statfs_test.c + * ************************************************/ + +void test_nuttx_fs_statfs01(FAR void **state); + +/* cases/fs_symlink_test.c + * ************************************************/ + +void test_nuttx_fs_symlink01(FAR void **state); + +/* cases/fs_truncate_test.c + * ************************************************/ + +void test_nuttx_fs_truncate01(FAR void **state); + +/* cases/fs_unlink_test.c + * ************************************************/ + +void test_nuttx_fs_unlink01(FAR void **state); + +/* cases/fs_write_test.c + * ************************************************/ + +void test_nuttx_fs_write01(FAR void **state); +void test_nuttx_fs_write02(FAR void **state); +void test_nuttx_fs_write03(FAR void **state); + +/* cases/fs_append_test.c + * ************************************************/ + +void test_nuttx_fs_append01(FAR void **state); + +/* cases/fs_sendfile_test.c + * ************************************************/ + +void test_nuttx_fs_sendfile01(FAR void **state); +void test_nuttx_fs_sendfile02(FAR void **state); + +/* cases/fs_stream_test.c + * ************************************************/ + +void test_nuttx_fs_stream01(FAR void **state); +void test_nuttx_fs_stream02(FAR void **state); +void test_nuttx_fs_stream03(FAR void **state); +void test_nuttx_fs_stream04(FAR void **state); + +/* cases/fs_eventfd_test.c + * ************************************************/ + +void test_nuttx_fs_eventfd(FAR void **state); + +/* fs_poll_test.c + * ************************************************/ + +void test_nuttx_fs_poll01(FAR void **state); + +#endif diff --git a/testing/testsuites/kernel/kv/cases/kv_test_001.c b/testing/testsuites/kernel/kv/cases/kv_test_001.c new file mode 100644 index 000000000..7a93d341a --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_001.c @@ -0,0 +1,83 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv01 + ****************************************************************************/ + +void test_nuttx_kv01(FAR void **state) +{ + 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 <= 1000; 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); + } +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_002.c b/testing/testsuites/kernel/kv/cases/kv_test_002.c new file mode 100644 index 000000000..7c43c27fd --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_002.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv02 + ****************************************************************************/ + +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; + + value = (char *)malloc(invalid_value_len * sizeof(char)); + assert_non_null(value); + + /* test key */ + + sprintf(key, "test_key_%s", __func__); + memset(value, 0, invalid_value_len); + memset(value, 0x67, invalid_value_len - 2); + + ret = property_set(key, value); + + free(value); + assert_int_not_equal(ret, 0); + property_delete(key); +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_003.c b/testing/testsuites/kernel/kv/cases/kv_test_003.c new file mode 100644 index 000000000..d5ffaeff3 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_003.c @@ -0,0 +1,94 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv03 + ****************************************************************************/ + +void test_nuttx_kv03(FAR void **state) +{ + 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/testing/testsuites/kernel/kv/cases/kv_test_004.c b/testing/testsuites/kernel/kv/cases/kv_test_004.c new file mode 100644 index 000000000..9c00be175 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_004.c @@ -0,0 +1,64 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv04 + ****************************************************************************/ + +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); +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_005.c b/testing/testsuites/kernel/kv/cases/kv_test_005.c new file mode 100644 index 000000000..40abee432 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_005.c @@ -0,0 +1,63 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv05 + ****************************************************************************/ + +void test_nuttx_kv05(FAR void **state) +{ + int ret; + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + 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); + } +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_006.c b/testing/testsuites/kernel/kv/cases/kv_test_006.c new file mode 100644 index 000000000..79d2a6302 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_006.c @@ -0,0 +1,176 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * 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++) + { + 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++) + { + 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++) + { + 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 + +/**************************************************************************** + * 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++) + { + 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); + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv06 + ****************************************************************************/ + +void test_nuttx_kv06(FAR void **state) +{ + int test_run = 20; + test_string(test_run); + test_int32(test_run); +#ifdef CONFIG_LIBC_LONG_LONG + test_int64(test_run); +#endif + test_bool(test_run); +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_007.c b/testing/testsuites/kernel/kv/cases/kv_test_007.c new file mode 100644 index 000000000..f723727dd --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_007.c @@ -0,0 +1,113 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv07 + ****************************************************************************/ + +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; + 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); + + 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); + + value_bool = property_get_bool(key, 0); + assert_int_equal(value_bool, data_bool); + + property_delete(key); +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_008.c b/testing/testsuites/kernel/kv/cases/kv_test_008.c new file mode 100644 index 000000000..7aaf54ce6 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_008.c @@ -0,0 +1,76 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv08 + ****************************************************************************/ + +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; + + 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); + } +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_009.c b/testing/testsuites/kernel/kv/cases/kv_test_009.c new file mode 100644 index 000000000..9a6fa10e6 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_009.c @@ -0,0 +1,69 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv09 + ****************************************************************************/ + +void test_nuttx_kv09(FAR void **state) +{ + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + char delete_data[TEST_VALUE_LENGTH] = + { + 0 + }; + + int ret; + + 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); + } +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_010.c b/testing/testsuites/kernel/kv/cases/kv_test_010.c new file mode 100644 index 000000000..f8fe22fe0 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_010.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv10 + ****************************************************************************/ + +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); +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_011.c b/testing/testsuites/kernel/kv/cases/kv_test_011.c new file mode 100644 index 000000000..d5d6150fe --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_011.c @@ -0,0 +1,60 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv11 + ****************************************************************************/ + +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); +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_012.c b/testing/testsuites/kernel/kv/cases/kv_test_012.c new file mode 100644 index 000000000..6dff8e491 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_012.c @@ -0,0 +1,71 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv12 + ****************************************************************************/ + +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); +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_013.c b/testing/testsuites/kernel/kv/cases/kv_test_013.c new file mode 100644 index 000000000..d70d44c6d --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_013.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv13 + ****************************************************************************/ + +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); +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_014.c b/testing/testsuites/kernel/kv/cases/kv_test_014.c new file mode 100644 index 000000000..3d8ce11c6 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_014.c @@ -0,0 +1,105 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +struct kv_struct +{ + 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 freedata(void); + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv14 + ****************************************************************************/ + +void test_nuttx_kv14(FAR void **state) +{ + int ret = 0; + char data[TEST_VALUE_LENGTH] = + { + 0 + }; + + 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); + + ret = property_get(item->key, data, ""); + assert_int_equal(ret, strlen(item->value)); + assert_int_equal(strcmp(item->value, data), 0); + } + + freedata(); +} + +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; + + tail->next = data; + tail = data; +} + +static void freedata(void) +{ + struct kv_struct *tmp; + + while (head) + { + tmp = head; + head = head->next; + free(tmp); + }; +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_015.c b/testing/testsuites/kernel/kv/cases/kv_test_015.c new file mode 100644 index 000000000..6744025bd --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_015.c @@ -0,0 +1,67 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv15 + ****************************************************************************/ + +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); +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_016.c b/testing/testsuites/kernel/kv/cases/kv_test_016.c new file mode 100644 index 000000000..728daa042 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_016.c @@ -0,0 +1,64 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv16 + ****************************************************************************/ + +void test_nuttx_kv16(FAR void **state) +{ + 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, 0); + assert_int_equal(setbool_ret, 0); + property_delete(key); +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_017.c b/testing/testsuites/kernel/kv/cases/kv_test_017.c new file mode 100644 index 000000000..f0e9e4dd1 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_017.c @@ -0,0 +1,84 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv17 + ****************************************************************************/ + +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); +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_018.c b/testing/testsuites/kernel/kv/cases/kv_test_018.c new file mode 100644 index 000000000..9059356b0 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_018.c @@ -0,0 +1,84 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv18 + ****************************************************************************/ + +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); +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_019.c b/testing/testsuites/kernel/kv/cases/kv_test_019.c new file mode 100644 index 000000000..975cf0015 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_019.c @@ -0,0 +1,119 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: store_data + ****************************************************************************/ + +static void *store_data(void *arg) +{ + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + char data[TEST_VALUE_LENGTH] = + { + 0 + }; + + int ret; + for (int k = 0; k < 100; k++) + { + 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; + } + + 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; + } + } + + return NULL; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv19 + ****************************************************************************/ + +void test_nuttx_kv19(FAR void **state) +{ + pthread_t nthread[10]; + int status; + int num_thread = 3; + int test_flag = 0; + + 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); + } + + 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/testing/testsuites/kernel/kv/cases/kv_test_020.c b/testing/testsuites/kernel/kv/cases/kv_test_020.c new file mode 100644 index 000000000..cbc68483a --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_020.c @@ -0,0 +1,87 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv20 + ****************************************************************************/ + +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++) + { + 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++) + { + sprintf(key, "%s%s-%d", KV_TEST_PREFIX, __func__, k); + ret = property_delete(key); + assert_int_equal(ret, 0); + } +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_021.c b/testing/testsuites/kernel/kv/cases/kv_test_021.c new file mode 100644 index 000000000..46a34065c --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_021.c @@ -0,0 +1,88 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv21 + ****************************************************************************/ + +void test_nuttx_kv21(FAR void **state) +{ + int ret = 0; + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + char value[TEST_VALUE_LENGTH] = + { + 0 + }; + + char data[TEST_VALUE_LENGTH] = + { + 0 + }; + + strcpy(key, "persist.test.kv.reload"); + strcpy(value, "test"); + + /* 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); + + property_reload(); + + /* get key */ + + ret = property_get(key, data, ""); + assert_int_equal(ret, strlen(value)); + assert_int_equal(strcmp(value, data), 0); +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_022.c b/testing/testsuites/kernel/kv/cases/kv_test_022.c new file mode 100644 index 000000000..d722ca291 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_022.c @@ -0,0 +1,95 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv22 + ****************************************************************************/ + +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/testing/testsuites/kernel/kv/cases/kv_test_023.c b/testing/testsuites/kernel/kv/cases/kv_test_023.c new file mode 100644 index 000000000..e9341f1af --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_023.c @@ -0,0 +1,87 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv23 + ****************************************************************************/ + +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 <= 1000; 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); + } +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_024.c b/testing/testsuites/kernel/kv/cases/kv_test_024.c new file mode 100644 index 000000000..4d08e7a67 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_024.c @@ -0,0 +1,119 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv24 + ****************************************************************************/ + +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"); + + 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); + } + + 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) + { + 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_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); + } + + ret = property_get_buffer(key, data, 50); + assert_int_not_equal(ret, 0); +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_025.c b/testing/testsuites/kernel/kv/cases/kv_test_025.c new file mode 100644 index 000000000..d8bb7d616 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_025.c @@ -0,0 +1,102 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv25 + ****************************************************************************/ + +void test_nuttx_kv25(FAR void **state) +{ + int ret; + char key[50] = + { + 0 + }; + + char data[50] = + { + 0 + }; + + char value[50] = + { + 0 + }; + + for (int i = 1; i <= 300; 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) + { + 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_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); + } + } +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_026.c b/testing/testsuites/kernel/kv/cases/kv_test_026.c new file mode 100644 index 000000000..3dcb429ec --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_026.c @@ -0,0 +1,83 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv26 + ****************************************************************************/ + +void test_nuttx_kv26(FAR void **state) +{ + int ret; + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + int8_t getbool_ret; + + for (int i = 1; i <= 300; 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) + { + 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); + + 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); + } + } +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_027.c b/testing/testsuites/kernel/kv/cases/kv_test_027.c new file mode 100644 index 000000000..4537d19ec --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_027.c @@ -0,0 +1,170 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv27 + ****************************************************************************/ + +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); + } + + 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); + } + + /* 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) + { + 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) + { + 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) + { + 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) + { + syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s", + key); + assert_int_equal(ret, 0); + } + + /* 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) + { + 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) + { + syslog(LOG_ERR, "Failed to commit after deleting data. Key:%s", + key); + assert_int_equal(ret, 0); + } +#endif +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_028.c b/testing/testsuites/kernel/kv/cases/kv_test_028.c new file mode 100644 index 000000000..113a39bf0 --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_028.c @@ -0,0 +1,121 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv28 + ****************************************************************************/ + +void test_nuttx_kv28(FAR void **state) +{ + int ret; + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + int32_t test_int32; + + for (int i = 1; i <= 300; 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) + { + 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) + { + 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++) + { + 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); + } + + 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); + } + } +#endif +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_029.c b/testing/testsuites/kernel/kv/cases/kv_test_029.c new file mode 100644 index 000000000..9db8bb3ba --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_029.c @@ -0,0 +1,106 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv29 + ****************************************************************************/ + +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 <= 300; i++) + { + /* test key */ + + sprintf(key, "persist.kv29_%d", i); + + /* test data */ + + sprintf(value, "test_value_kv29_%d", i); + + 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); + } + + ret = property_get(key, data, ""); + assert_int_equal(ret, strlen(value)); + + 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\n", + key, value); + assert_int_equal(ret, 0); + } + } +} diff --git a/testing/testsuites/kernel/kv/cases/kv_test_030.c b/testing/testsuites/kernel/kv/cases/kv_test_030.c new file mode 100644 index 000000000..3a6c76d6b --- /dev/null +++ b/testing/testsuites/kernel/kv/cases/kv_test_030.c @@ -0,0 +1,159 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: store_data + ****************************************************************************/ + +pthread_mutex_t mutex_kv; + +static void *store_persist_data(void *arg) +{ + char key[TEST_KEY_LENGTH] = + { + 0 + }; + + char value[TEST_VALUE_LENGTH] = + { + 0 + }; + + int ret; + for (int k = 0; k < 100; 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) + { + 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) + { + 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) + { + 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) + { + 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; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kv30 + ****************************************************************************/ + +void test_nuttx_kv30(FAR void **state) +{ + pthread_t nthread[3]; + int status; + int num_thread = 3; + int test_flag = 0; + + pthread_mutex_init(&mutex_kv, NULL); + + 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); + } + + for (int j = 0; j < num_thread; j++) + { + pthread_join(nthread[j], NULL); + } + + pthread_mutex_destroy(&mutex_kv); + + /* Check whether any child threads failed to run */ + + assert_int_equal(test_flag, 0); +} diff --git a/testing/testsuites/kernel/kv/cmocka_kv_test.c b/testing/testsuites/kernel/kv/cmocka_kv_test.c new file mode 100644 index 000000000..466d24363 --- /dev/null +++ b/testing/testsuites/kernel/kv/cmocka_kv_test.c @@ -0,0 +1,124 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/cmocka_kv_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 +#include +#include "KvTest.h" +#include + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: cmocka_sched_test_main + ****************************************************************************/ + +int main(int argc, char *argv[]) +{ + /* Add Test Cases */ + + const struct CMUnitTest nuttx_kvdb_test_suites[] = + { +#ifdef CONFIG_KVDB_TEMPORARY_STORAGE + 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(test_nuttx_kv14, test_nuttx_kv_setup, + test_nuttx_kv_teardown), +#ifdef CONFIG_KVDB_TEMPORARY_STORAGE + 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_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(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(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(nuttx_kvdb_test_suites, NULL, NULL); + return 0; +} diff --git a/testing/testsuites/kernel/kv/common/test_kv_common.c b/testing/testsuites/kernel/kv/common/test_kv_common.c new file mode 100644 index 000000000..4724149a0 --- /dev/null +++ b/testing/testsuites/kernel/kv/common/test_kv_common.c @@ -0,0 +1,59 @@ +/**************************************************************************** + * 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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "KvTest.h" +#include "kvdb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_kvsetup + ****************************************************************************/ + +int test_nuttx_kv_setup(void **state) +{ + return 0; +} + +/**************************************************************************** + * Name: test_nuttx_kvteardown + ****************************************************************************/ + +int test_nuttx_kv_teardown(void **state) +{ + return 0; +} diff --git a/testing/testsuites/kernel/kv/include/KvTest.h b/testing/testsuites/kernel/kv/include/KvTest.h new file mode 100644 index 000000000..9c9c58a34 --- /dev/null +++ b/testing/testsuites/kernel/kv/include/KvTest.h @@ -0,0 +1,208 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/kv/include/KvTest.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 __SYSCALLTEST_H +#define __SYSCALLTEST_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* 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 +#define PTHREAD_STACK_SIZE CONFIG_DEFAULT_TASK_STACKSIZE +#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 test_nuttx_kv_setup(void **state); +int test_nuttx_kv_teardown(void **state); + +/* test case function */ + +/* 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/testing/testsuites/kernel/mm/cases/mm_test_001.c b/testing/testsuites/kernel/mm/cases/mm_test_001.c new file mode 100644 index 000000000..7eb27c541 --- /dev/null +++ b/testing/testsuites/kernel/mm/cases/mm_test_001.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mm/cases/mm_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "MmTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_mm01 + ****************************************************************************/ + +void test_nuttx_mm01(FAR void **state) +{ + int i; + int flag = 0; + char *pm1; + char *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); +} diff --git a/testing/testsuites/kernel/mm/cases/mm_test_002.c b/testing/testsuites/kernel/mm/cases/mm_test_002.c new file mode 100644 index 000000000..e749b84ee --- /dev/null +++ b/testing/testsuites/kernel/mm/cases/mm_test_002.c @@ -0,0 +1,77 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mm/cases/mm_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "MmTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_mm02 + ****************************************************************************/ + +void test_nuttx_mm02(FAR void **state) +{ + int i; + int flag = 0; + char *pm1; + char *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); +} diff --git a/testing/testsuites/kernel/mm/cases/mm_test_003.c b/testing/testsuites/kernel/mm/cases/mm_test_003.c new file mode 100644 index 000000000..cfa9935cf --- /dev/null +++ b/testing/testsuites/kernel/mm/cases/mm_test_003.c @@ -0,0 +1,76 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mm/cases/mm_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "MmTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_mm03 + ****************************************************************************/ + +void test_nuttx_mm03(FAR void **state) +{ + int i; + int flag = 0; + char *pm1; + char *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); +} diff --git a/testing/testsuites/kernel/mm/cases/mm_test_004.c b/testing/testsuites/kernel/mm/cases/mm_test_004.c new file mode 100644 index 000000000..2dafc6f23 --- /dev/null +++ b/testing/testsuites/kernel/mm/cases/mm_test_004.c @@ -0,0 +1,57 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mm/cases/mm_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "MmTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_mm04 + ****************************************************************************/ + +void test_nuttx_mm04(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); + } +} diff --git a/testing/testsuites/kernel/mm/cases/mm_test_005.c b/testing/testsuites/kernel/mm/cases/mm_test_005.c new file mode 100644 index 000000000..6329c7346 --- /dev/null +++ b/testing/testsuites/kernel/mm/cases/mm_test_005.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mm/cases/mm_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "MmTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_mm05 + ****************************************************************************/ + +void test_nuttx_mm05(FAR void **state) +{ + int i; + int flag = 0; + char *ptr; + char *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); +} diff --git a/testing/testsuites/kernel/mm/cases/mm_test_006.c b/testing/testsuites/kernel/mm/cases/mm_test_006.c new file mode 100644 index 000000000..98a19c1f2 --- /dev/null +++ b/testing/testsuites/kernel/mm/cases/mm_test_006.c @@ -0,0 +1,91 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mm/cases/mm_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 + ****************************************************************************/ +#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: test_nuttx_mm06 + ****************************************************************************/ + +void test_nuttx_mm06(FAR void **state) +{ + int malloc_size; + int 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); + } +} diff --git a/testing/testsuites/kernel/mm/cases/mm_test_007.c b/testing/testsuites/kernel/mm/cases/mm_test_007.c new file mode 100644 index 000000000..efe33221c --- /dev/null +++ b/testing/testsuites/kernel/mm/cases/mm_test_007.c @@ -0,0 +1,155 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mm/cases/mm_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 + ****************************************************************************/ +#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: test_nuttx_mm07 + ****************************************************************************/ + +void test_nuttx_mm07(FAR void **state) +{ + char *mem_list[MEMORY_LIST_LENGTH]; + char *tmp_str = NULL; + int malloc_size; + int index = 0; + int total_size = 0; + int flag = 0; + struct mallinfo test_befor_info; + struct mallinfo test_during_info; + struct mallinfo test_after_info; + struct mallinfo mem_info; + memset(&mem_info, 0, sizeof(mem_info)); + for (int i = 0; i < MEMORY_LIST_LENGTH; i++) + { + mem_list[i] = NULL; + } + + test_befor_info = mallinfo(); + + /* get a random size */ + + for (int k = 0; k < MEMORY_LIST_LENGTH; k++) + { + get_mem_info(&mem_info); + malloc_size = + mmtest_get_rand_size(MALLOC_MIN_SIZE, MALLOC_MAX_SIZE); + if (mem_info.mxordblk - 16 < 0) + { + syslog(LOG_INFO, + "TEST END because of the mem_info.mxordblk is:%d", + mem_info.mxordblk); + break; + } + + if (malloc_size > mem_info.mxordblk - 16) + { + syslog(LOG_INFO, "SET memsize to:%d", mem_info.mxordblk - 16); + malloc_size = mem_info.mxordblk - 16; + } + + 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); +} diff --git a/testing/testsuites/kernel/mm/cases/mm_test_008.c b/testing/testsuites/kernel/mm/cases/mm_test_008.c new file mode 100644 index 000000000..99aab0c67 --- /dev/null +++ b/testing/testsuites/kernel/mm/cases/mm_test_008.c @@ -0,0 +1,170 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mm/cases/mm_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 + ****************************************************************************/ +#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 test_nuttx_08_routine_1(int argc, char *argv[]) +{ + char *ptr = NULL; + char *tmp_ptr = NULL; + int malloc_size; + int 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 test_nuttx_08_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 test_nuttx_08_routine_3(int argc, char *argv[]) +{ + char *pm; + unsigned long memsize; + struct mallinfo mem_info; + memset(&mem_info, 0, sizeof(mem_info)); + for (int i = 0; i < 500; i++) + { + /* Apply for as much memory as a system allows */ + + get_mem_info(&mem_info); + memsize = mmtest_get_rand_size(1024, 2048); + if (mem_info.mxordblk - 16 < 0) + { + syslog(LOG_INFO, + "TEST END because of the mem_info.mxordblk is:%d", + mem_info.mxordblk); + break; + } + + if (memsize > mem_info.mxordblk - 16) + { + syslog(LOG_INFO, "SET memsize to:%d", mem_info.mxordblk - 16); + memsize = mem_info.mxordblk - 16; + } + + pm = malloc(memsize); + assert_non_null(pm); + free(pm); + } + + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_mm08 + ****************************************************************************/ + +void test_nuttx_mm08(FAR void **state) +{ + pid_t pid; + int status; + + pid = task_create("test_nuttx_08_routine_1", TASK_PRIORITY, + DEFAULT_STACKSIZE, test_nuttx_08_routine_1, NULL); + assert_true(pid > 0); + pid = task_create("test_nuttx_08_routine_2", TASK_PRIORITY, + DEFAULT_STACKSIZE, test_nuttx_08_routine_2, NULL); + assert_true(pid > 0); + pid = task_create("test_nuttx_08_routine_3", TASK_PRIORITY, + DEFAULT_STACKSIZE, test_nuttx_08_routine_3, NULL); + assert_true(pid > 0); + waitpid(pid, &status, 0); +} diff --git a/testing/testsuites/kernel/mm/cmocka_mm_test.c b/testing/testsuites/kernel/mm/cmocka_mm_test.c new file mode 100644 index 000000000..27341a84a --- /dev/null +++ b/testing/testsuites/kernel/mm/cmocka_mm_test.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mm/cmocka_mm_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 +#include +#include "MmTest.h" +#include + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: cmocka_sched_test_main + ****************************************************************************/ + +int main(int argc, char *argv[]) +{ + /* Add Test Cases */ + + const struct CMUnitTest nuttx_mm_test_suites[] = + { + cmocka_unit_test_setup_teardown(test_nuttx_mm01, test_nuttx_mm_setup, + test_nuttx_mm_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_mm02, test_nuttx_mm_setup, + test_nuttx_mm_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_mm03, test_nuttx_mm_setup, + test_nuttx_mm_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_mm04, test_nuttx_mm_setup, + test_nuttx_mm_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_mm05, test_nuttx_mm_setup, + test_nuttx_mm_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_mm06, test_nuttx_mm_setup, + test_nuttx_mm_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_mm07, test_nuttx_mm_setup, + test_nuttx_mm_teardown), + cmocka_unit_test_setup_teardown(test_nuttx_mm08, test_nuttx_mm_setup, + test_nuttx_mm_teardown), + }; + + /* Run Test cases */ + + cmocka_run_group_tests(nuttx_mm_test_suites, NULL, NULL); + + return 0; +} diff --git a/testing/testsuites/kernel/mm/common/test_mm_common.c b/testing/testsuites/kernel/mm/common/test_mm_common.c new file mode 100644 index 000000000..071575791 --- /dev/null +++ b/testing/testsuites/kernel/mm/common/test_mm_common.c @@ -0,0 +1,125 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mm/common/test_mm_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 + ****************************************************************************/ +#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: test_nuttx_mm_setup + ****************************************************************************/ + +int test_nuttx_mm_setup(void **state) +{ + return 0; +} + +/**************************************************************************** + * Name: test_nuttx_mm_teardown + ****************************************************************************/ + +int test_nuttx_mm_teardown(void **state) +{ + return 0; +} diff --git a/testing/testsuites/kernel/mm/include/MmTest.h b/testing/testsuites/kernel/mm/include/MmTest.h new file mode 100644 index 000000000..6d1812d9a --- /dev/null +++ b/testing/testsuites/kernel/mm/include/MmTest.h @@ -0,0 +1,98 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mm/include/MmTest.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 __SYSCALLTEST_H +#define __SYSCALLTEST_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include +#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); +static int __attribute__((unused)) +get_mem_info(struct mallinfo *mem_info) +{ + *mem_info = mallinfo(); + return 0; +} + +int test_nuttx_mm_setup(void **state); +int test_nuttx_mm_teardown(void **state); + +/* test case function */ + +/* cases/mm_test_001.c + * *****************************************************/ + +void test_nuttx_mm01(FAR void **state); + +/* cases/mm_test_002.c + * *****************************************************/ + +void test_nuttx_mm02(FAR void **state); + +/* cases/mm_test_003.c + * *****************************************************/ + +void test_nuttx_mm03(FAR void **state); + +/* cases/mm_test_004.c + * *****************************************************/ + +void test_nuttx_mm04(FAR void **state); + +/* cases/mm_test_005.c + * *****************************************************/ + +void test_nuttx_mm05(FAR void **state); + +/* cases/mm_test_006.c + * *****************************************************/ + +void test_nuttx_mm06(FAR void **state); + +/* cases/mm_test_007.c + * *****************************************************/ + +void test_nuttx_mm07(FAR void **state); + +/* cases/mm_test_008.c + * *****************************************************/ + +void test_nuttx_mm08(FAR void **state); + +#endif \ No newline at end of file diff --git a/testing/testsuites/kernel/mm/tool/mem_batch_opt_perf_test.c b/testing/testsuites/kernel/mm/tool/mem_batch_opt_perf_test.c new file mode 100644 index 000000000..740aa3435 --- /dev/null +++ b/testing/testsuites/kernel/mm/tool/mem_batch_opt_perf_test.c @@ -0,0 +1,154 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mm/tool/mem_batch_opt_perf_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 +#include "MmTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * 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; +} diff --git a/testing/testsuites/kernel/mm/tool/mem_cycle_opt_perf_test.c b/testing/testsuites/kernel/mm/tool/mem_cycle_opt_perf_test.c new file mode 100644 index 000000000..858f7abb5 --- /dev/null +++ b/testing/testsuites/kernel/mm/tool/mem_cycle_opt_perf_test.c @@ -0,0 +1,144 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mm/tool/mem_cycle_opt_perf_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 +#include "MmTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * 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 */ + + /* Memory write content check character */ + + char 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; +} diff --git a/testing/testsuites/kernel/mutex/cases/posix_mutex_test_001.c b/testing/testsuites/kernel/mutex/cases/posix_mutex_test_001.c new file mode 100644 index 000000000..de3c521d7 --- /dev/null +++ b/testing/testsuites/kernel/mutex/cases/posix_mutex_test_001.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mutex/cases/posix_mutex_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 + ****************************************************************************/ +#include +#include +#include +#include +#include "MutexTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_mutex_test01 + ****************************************************************************/ + +void test_nuttx_mutex_test01(FAR void **state) +{ + pthread_mutexattr_t mta; + int rc; + + /* Initialize a mutex attributes object */ + + rc = pthread_mutexattr_init(&mta); + syslog(LOG_INFO, "rc : %d\n", rc); + assert_int_equal(rc, 0); + + rc = pthread_mutexattr_destroy(&mta); + syslog(LOG_INFO, "rc : %d\n", rc); + assert_int_equal(rc, 0); +} diff --git a/testing/testsuites/kernel/mutex/cases/posix_mutex_test_019.c b/testing/testsuites/kernel/mutex/cases/posix_mutex_test_019.c new file mode 100644 index 000000000..ed4326e53 --- /dev/null +++ b/testing/testsuites/kernel/mutex/cases/posix_mutex_test_019.c @@ -0,0 +1,276 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mutex/cases/posix_mutex_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 + ****************************************************************************/ +#include +#include +#include +#include +#include "MutexTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +static pthread_mutex_t *g_mtx; +static sem_t g_sema; +static sem_t g_semb; +static pthread_mutex_t g_mtxnull; +static pthread_mutex_t g_mtxdef; +static int g_testmutexretval; +static UINT32 g_testmutexcount; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static void *taskf01(void *arg) +{ + int ret; + + /* testbusytaskdelay(20); */ + + usleep(50000); + g_testmutexcount++; + + if ((ret = pthread_mutex_lock(g_mtx))) + { + syslog(LOG_INFO, "ret: %d \n", ret); + goto EXIT; + } + + if ((ret = sem_post(&g_sema))) + { + syslog(LOG_INFO, "ret: %d \n", ret); + goto EXIT; + } + + if ((ret = sem_wait(&g_semb))) + { + syslog(LOG_INFO, "ret: %d \n", ret); + goto EXIT; + } + + if (g_testmutexretval != 0) + { + /* parent thread failed to unlock the mutex) */ + + if ((ret = pthread_mutex_unlock(g_mtx))) + { + syslog(LOG_INFO, "ret: %d \n", ret); + goto EXIT; + } + } + + g_testmutexcount++; + return NULL; + +EXIT: + assert_int_equal(1, 0); + return NULL; +} + +/**************************************************************************** + * Name: test_nuttx_mutex_test19 + ****************************************************************************/ + +void test_nuttx_mutex_test19(FAR void **state) +{ + pthread_mutexattr_t mattr; + pthread_t thr; + + pthread_mutex_t *tabmutex[2]; + int tabres[2][3] = + { + { + 0, 0, 0 + }, + { + 0, 0, 0 + } + }; + + int ret; + void *thret = NULL; + int i; + g_testmutexretval = 0; + g_testmutexcount = 0; + + /* We first initialize the two mutexes. */ + + if ((ret = pthread_mutex_init(&g_mtxnull, NULL))) + { + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(1, 0); + } + + if ((ret = pthread_mutexattr_init(&mattr))) + { + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(1, 0); + } + + if ((ret = pthread_mutex_init(&g_mtxdef, &mattr))) + { + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(1, 0); + } + + if ((ret = pthread_mutexattr_destroy(&mattr))) + { + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(1, 0); + } + + tabmutex[0] = &g_mtxnull; + tabmutex[1] = &g_mtxdef; + + if ((ret = sem_init(&g_sema, 0, 0))) + { + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(1, 0); + } + + if ((ret = sem_init(&g_semb, 0, 0))) + { + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(1, 0); + } + + /* OK let's go for the first part of the test : abnormals unlocking */ + + /* We first check if unlocking an unlocked mutex returns an uwErr. */ + + ret = pthread_mutex_unlock(tabmutex[0]); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_not_equal(ret, ENOERR); + + ret = pthread_mutex_unlock(tabmutex[1]); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_not_equal(ret, ENOERR); + + /* Now we focus on unlocking a mutex lock by another thread */ + + for (i = 0; i < 2; i++) + { + /* 2, Set the timeout of runtime */ + + g_mtx = tabmutex[i]; + tabres[i][0] = 0; + tabres[i][1] = 0; + tabres[i][2] = 0; /* 2, buffer index. */ + + if ((ret = pthread_create(&thr, NULL, taskf01, NULL))) + { + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(1, 0); + } + + if (i == 0) + { + syslog(LOG_INFO, "g_testmutexcount: %d \n", g_testmutexcount); + assert_int_equal(g_testmutexcount, 0); + } + + if (i == 1) + { + syslog(LOG_INFO, "g_testmutexcount: %d \n", g_testmutexcount); + assert_int_equal(g_testmutexcount, + 2); /* 2, Here, assert the g_testmutexcount. */ + } + + if ((ret = sem_wait(&g_sema))) + { + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(1, 0); + } + + g_testmutexretval = pthread_mutex_unlock(g_mtx); + syslog(LOG_INFO, "g_testmutexretval: %d \n", g_testmutexretval); + assert_int_equal(g_testmutexretval, EPERM); + + if (i == 0) + { + syslog(LOG_INFO, "g_testmutexcount: %d \n", g_testmutexcount); + assert_int_equal(g_testmutexcount, 1); + } + + if (i == 1) + { + syslog(LOG_INFO, "g_testmutexcount: %d \n", g_testmutexcount); + assert_int_equal(g_testmutexcount, + 3); /* 3, Here, assert the g_testmutexcount. */ + } + + if ((ret = sem_post(&g_semb))) + { + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(1, 0); + } + + if ((ret = pthread_join(thr, &thret))) + { + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(1, 0); + } + + if (i == 0) + { + syslog(LOG_INFO, "g_testmutexcount: %d \n", g_testmutexcount); + assert_int_equal(g_testmutexcount, + 2); /* 2, Here, assert the g_testmutexcount. */ + } + + if (i == 1) + { + syslog(LOG_INFO, "g_testmutexcount: %d \n", g_testmutexcount); + assert_int_equal(g_testmutexcount, + 4); /* 4, Here, assert the g_testmutexcount. */ + } + + tabres[i][0] = g_testmutexretval; + } + + if (tabres[0][0] != tabres[1][0]) + { + assert_int_equal(1, 0); + } + + /* We start with testing the NULL mutex features */ + + (void)pthread_mutexattr_destroy(&mattr); + ret = pthread_mutex_destroy(&g_mtxnull); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); + + ret = pthread_mutex_destroy(&g_mtxdef); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); + + ret = sem_destroy(&g_sema); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); + + ret = sem_destroy(&g_semb); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); +} diff --git a/testing/testsuites/kernel/mutex/cases/posix_mutex_test_020.c b/testing/testsuites/kernel/mutex/cases/posix_mutex_test_020.c new file mode 100644 index 000000000..c4c795ff0 --- /dev/null +++ b/testing/testsuites/kernel/mutex/cases/posix_mutex_test_020.c @@ -0,0 +1,89 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mutex/cases/posix_mutex_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 + ****************************************************************************/ +#include +#include +#include +#include +#include "MutexTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_mutex_test20 + ****************************************************************************/ + +void test_nuttx_mutex_test20(FAR void **state) +{ + pthread_mutex_t mutex; + int rc; + + /* Initialize a mutex object */ + + rc = pthread_mutex_init(&mutex, NULL); + syslog(LOG_INFO, "rc : %d\n", rc); + assert_int_equal(rc, ENOERR); + + /* Acquire the mutex object using pthread_mutex_lock */ + + if ((rc = pthread_mutex_lock(&mutex))) + { + syslog(LOG_INFO, "rc: %d \n", rc); + goto EXIT1; + } + + sleep(1); + + /* Release the mutex object using pthread_mutex_unlock */ + + if ((rc = pthread_mutex_unlock(&mutex))) + { + syslog(LOG_INFO, "rc: %d \n", rc); + goto EXIT2; + } + + /* Destroy the mutex object */ + + if ((rc = pthread_mutex_destroy(&mutex))) + { + syslog(LOG_INFO, "rc: %d \n", rc); + goto EXIT1; + } + + return; + +EXIT2: + pthread_mutex_unlock(&mutex); + assert_int_equal(1, 0); + +EXIT1: + pthread_mutex_destroy(&mutex); + assert_int_equal(1, 0); + return; +} diff --git a/testing/testsuites/kernel/mutex/cmocka_mutex_test.c b/testing/testsuites/kernel/mutex/cmocka_mutex_test.c new file mode 100644 index 000000000..8ac241bec --- /dev/null +++ b/testing/testsuites/kernel/mutex/cmocka_mutex_test.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mutex/cmocka_mutex_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 +#include +#include "MutexTest.h" +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: cmocka_sched_test_main + ****************************************************************************/ + +int main(int argc, char *argv[]) +{ + /* Add Test Cases */ + + const struct CMUnitTest nuttx_mutex_test_suites[] = + { + cmocka_unit_test_setup_teardown(test_nuttx_mutex_test01, NULL, NULL), +#ifdef CONFIG_PTHREAD_MUTEX_ROBUST + cmocka_unit_test_setup_teardown(test_nuttx_mutex_test19, NULL, NULL), +#endif + cmocka_unit_test_setup_teardown(test_nuttx_mutex_test20, NULL, NULL), + }; + + /* Run Test cases */ + + cmocka_run_group_tests(nuttx_mutex_test_suites, NULL, NULL); + + return 0; +} diff --git a/testing/testsuites/kernel/mutex/include/MutexTest.h b/testing/testsuites/kernel/mutex/include/MutexTest.h new file mode 100644 index 000000000..f99a775de --- /dev/null +++ b/testing/testsuites/kernel/mutex/include/MutexTest.h @@ -0,0 +1,66 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/mutex/include/MutexTest.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 PTHREAD_TEST_H +#define PTHREAD_TEST_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "sched.h" +#include "semaphore.h" +#include "unistd.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +#define MUTEX_TEST_NUM 100 +#define ENOERR 0 +typedef unsigned int UINT32; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/* test case function */ + +/* cases/posix_mutex_test_001.c + * ************************************************/ + +void test_nuttx_mutex_test01(FAR void **state); + +/* cases/posix_mutex_test_019.c + * ************************************************/ + +void test_nuttx_mutex_test19(FAR void **state); + +/* cases/posix_mutex_test_020.c + * ************************************************/ + +void test_nuttx_mutex_test20(FAR void **state); +#endif diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_003.c b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_003.c new file mode 100644 index 000000000..1fe33deff --- /dev/null +++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_003.c @@ -0,0 +1,87 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include +#include "PthreadTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static void *threadf01(void *arg) +{ + pthread_exit(NULL); + return NULL; +} + +/**************************************************************************** + * Name: test_nuttx_pthread_test03 + ****************************************************************************/ + +void test_nuttx_pthread_test03(FAR void **state) +{ + pthread_t athread; + pthread_t ptid; + pthread_t a = 0; + pthread_t b = 0; + int tmp; + pthread_attr_t aa = + { + 0 + }; + + int detachstate; + UINT32 ret; + + ptid = pthread_self(); + syslog(LOG_INFO, "ptid: %d \n", ptid); + assert_int_not_equal(ptid, 0); + pthread_create(&athread, NULL, threadf01, NULL); + + tmp = pthread_equal(a, b); + syslog(LOG_INFO, "ret: %d\n", tmp); + assert_int_not_equal(tmp, 0); + + pthread_attr_init(&aa); + + ret = pthread_attr_getdetachstate(&aa, &detachstate); + syslog(LOG_INFO, "ret of getdetachstate: %d\n", ret); + assert_int_equal(ret, 0); + + ret = pthread_attr_setdetachstate(&aa, PTHREAD_CREATE_DETACHED); + syslog(LOG_INFO, "ret of setdetachstate: %d\n", ret); + assert_int_equal(ret, 0); + + pthread_attr_destroy(&aa); + + ret = pthread_join(athread, NULL); + syslog(LOG_INFO, "ret of pthread_join: %d\n", ret); + assert_int_equal(ret, 0); +} diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_004.c b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_004.c new file mode 100644 index 000000000..bd968c576 --- /dev/null +++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_004.c @@ -0,0 +1,89 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include + +#include "PthreadTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static void *threadf01(void *arg) +{ + pthread_exit((void *)2); /* 2, here set value of the exit status. */ + return NULL; +} + +/**************************************************************************** + * Name: test_nuttx_pthread_test04 + ****************************************************************************/ + +void test_nuttx_pthread_test04(FAR void **state) +{ + pthread_t mainth; + pthread_t newth; + UINT32 ret; + UINTPTR temp; + + if (pthread_create(&newth, NULL, threadf01, NULL) != 0) + { + printf("Error creating thread\n"); + assert_int_equal(1, 0); + } + + usleep(1000); + + /* los_taskdelay(1); */ + + /* Obtain the thread ID of this main function */ + + mainth = testpthreadself(); + + /* Compare the thread ID of the new thread to the main thread. + * They should be different. If not, the test fails. + */ + + if (pthread_equal(newth, mainth) != 0) + { + printf("Test FAILED: A new thread wasn't created\n"); + assert_int_equal(1, 0); + } + + usleep(1000); + + /* testextrataskdelay(1); */ + + ret = pthread_join(newth, (void *)&temp); + syslog(LOG_INFO, "ret: %d \n", ret); + syslog(LOG_INFO, "temp: %ld \n", temp); + assert_int_equal(ret, 0); + assert_int_equal(temp, 2); /* 2, here assert the result. */ +} diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_005.c b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_005.c new file mode 100644 index 000000000..32ec5f8c5 --- /dev/null +++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_005.c @@ -0,0 +1,93 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include "PthreadTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static void *threadf01(void *arg) +{ + sleep(500); + + /* Shouldn't reach here. If we do, then the pthread_cancel() + * function did not succeed. + */ + + pthread_exit((void *)6); + return NULL; +} + +/**************************************************************************** + * Name: test_nuttx_pthread_test05 + ****************************************************************************/ + +void test_nuttx_pthread_test05(FAR void **state) +{ + pthread_t newth; + UINT32 ret; + UINTPTR temp; + clock_t start, finish; + double duration; + + start = clock(); + if (pthread_create(&newth, NULL, threadf01, NULL) < 0) + { + syslog(LOG_INFO, "Error creating thread\n"); + assert_int_equal(1, 0); + } + + usleep(1000); + + /* los_taskdelay(1); */ + + /* Try to cancel the newly created thread. If an error is returned, + * then the thread wasn't created successfully. + */ + + if (pthread_cancel(newth) != 0) + { + syslog(LOG_INFO, "Test FAILED: A new thread wasn't created\n"); + assert_int_equal(1, 0); + } + + ret = pthread_join(newth, (void *)&temp); + finish = clock(); + duration = (double)(finish - start) / CLOCKS_PER_SEC * 1000; + syslog(LOG_INFO, "duration: %f \n", duration); + assert_int_equal(duration < 500, 1); + syslog(LOG_INFO, "ret: %d \n", ret); + syslog(LOG_INFO, "temp: %ld \n", temp); + assert_int_equal(ret, 0); + assert_int_not_equal(temp, 6); +} diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_006.c b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_006.c new file mode 100644 index 000000000..64c326699 --- /dev/null +++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_006.c @@ -0,0 +1,83 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include + +#include "PthreadTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static void *threadf01(void *arg) +{ + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + + sleep(1); + + pthread_exit((void *)0); + return NULL; +} + +/**************************************************************************** + * Name: test_nuttx_pthread_test06 + ****************************************************************************/ + +void test_nuttx_pthread_test06(FAR void **state) +{ + UINT32 ret; + void *temp = NULL; + pthread_t a; + + /* SIGALRM will be sent in 5 seconds. */ + + /* Create a new thread. */ + + if (pthread_create(&a, NULL, threadf01, NULL) != 0) + { + printf("Error creating thread\n"); + assert_int_equal(1, 0); + } + + usleep(1000); + + /* los_taskdelay(1); */ + + pthread_cancel(a); + + /* If 'main' has reached here, then the test passed because it means + * that the thread is truly asynchronise, and main isn't waiting for + * it to return in order to move on. + */ + + ret = pthread_join(a, &temp); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); +} diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_009.c b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_009.c new file mode 100644 index 000000000..731c097f9 --- /dev/null +++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_009.c @@ -0,0 +1,101 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include + +#include "PthreadTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static void *pthreadf01(void *arg) +{ + g_testpthreadcount++; + + pthread_exit(NULL); + + return (void *)9; /* 9, here set value about the return status. */ +} + +/**************************************************************************** + * Name: test_nuttx_pthread_test09 + ****************************************************************************/ + +void test_nuttx_pthread_test09(FAR void **state) +{ + pthread_t newth; + UINT32 ret; + UINTPTR temp = 1; + + /* _pthread_data *joinee = NULL; */ + + g_testpthreadcount = 0; + g_testpthreadtaskmaxnum = 128; + + ret = pthread_create(&newth, NULL, pthreadf01, NULL); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); + usleep(1000); + + /* los_taskdelay(1); */ + + syslog(LOG_INFO, "g_testpthreadcount: %d \n", g_testpthreadcount); + assert_int_equal(g_testpthreadcount, 1); + + ret = pthread_join(g_testpthreadtaskmaxnum, (void *)&temp); + syslog(LOG_INFO, "ret: %d \n", ret); + syslog(LOG_INFO, "temp: %ld \n", temp); + assert_int_equal(ret, ESRCH); + assert_int_equal(temp, 1); + + ret = pthread_join(LOSCFG_BASE_CORE_TSK_CONFIG + 1, (void *)&temp); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, ESRCH); + syslog(LOG_INFO, "temp: %ld \n", temp); + assert_int_equal(temp, 1); + + ret = pthread_detach(g_testpthreadtaskmaxnum); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, ESRCH); + + ret = pthread_join(newth, NULL); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); + + sleep(1); + ret = pthread_detach(newth); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, ESRCH); + + ret = pthread_join(newth, NULL); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, ESRCH); +} diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_018.c b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_018.c new file mode 100644 index 000000000..b4ca6b9ee --- /dev/null +++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_018.c @@ -0,0 +1,153 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include "PthreadTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +static sem_t re_pthreadf01; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static void *pthreadf01(void *argument) +{ + g_testpthreadcount++; + sem_wait(&re_pthreadf01); + + return argument; +} + +/**************************************************************************** + * Name: test_nuttx_pthread_test18 + ****************************************************************************/ + +void test_nuttx_pthread_test18(FAR void **state) +{ + pthread_attr_t attr; + pthread_t newth; + UINT32 ret; + UINTPTR temp; + int policy; + struct sched_param param; + struct sched_param param2 = + { + 2 + }; /* 2, init */ + + g_testpthreadcount = 0; + + ret = sem_init(&re_pthreadf01, 0, 0); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); + + ret = pthread_attr_init(&attr); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); + + ret = pthread_create(&newth, NULL, pthreadf01, + (void *)9); /* 9, test param of the function. */ + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); + usleep(1000); + + /* los_taskdelay(1); */ + + syslog(LOG_INFO, "g_testpthreadcount: %d \n", g_testpthreadcount); + assert_int_equal(g_testpthreadcount, 1); + + ret = pthread_setschedparam(newth, -1, ¶m); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, EINVAL); + + ret = pthread_setschedparam(newth, 100, + ¶m); /* 4, test for invalid param. */ + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, EINVAL); + +#if CONFIG_RR_INTERVAL > 0 + param.sched_priority = 31; /* 31, init */ + ret = pthread_setschedparam(newth, SCHED_RR, ¶m); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); +#endif + + ret = pthread_getschedparam(newth, NULL, ¶m2); + syslog(LOG_INFO, "ret: %d \n", ret); + syslog(LOG_INFO, "param2.sched_priority: %d \n", + param2.sched_priority); + assert_int_equal(ret, EINVAL); + assert_int_equal(param2.sched_priority, + 2); /* 2, here assert the result. */ + + ret = pthread_getschedparam(newth, &policy, NULL); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, EINVAL); + + ret = pthread_getschedparam(newth, &policy, ¶m2); + syslog(LOG_INFO, "ret: %d \n", ret); + syslog(LOG_INFO, "param2.sched_priority: %d \n", + param2.sched_priority); + assert_int_equal(ret, 0); +#if CONFIG_RR_INTERVAL > 0 + assert_int_equal(param2.sched_priority, + 31); /* 31, here assert the result. */ +#endif + + ret = sem_post(&re_pthreadf01); + syslog(LOG_INFO, "ret of sem_post: %d \n", ret); + assert_int_equal(ret, 0); + ret = pthread_join(newth, (void *)&temp); + syslog(LOG_INFO, "ret: %d \n", ret); + syslog(LOG_INFO, "temp: %ld \n", temp); + assert_int_equal(ret, 0); + assert_int_equal(temp, 9); /* 9, here assert the result. */ + +#if CONFIG_RR_INTERVAL > 0 + ret = pthread_setschedparam(newth + 9, SCHED_RR, + ¶m); /* 9, test for invalid param. */ + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, ESRCH); +#endif + + ret = pthread_getschedparam(newth + 8, &policy, + ¶m2); /* 8, test for invalid param. */ + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, ESRCH); + + ret = pthread_attr_destroy(&attr); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); + + ret = sem_destroy(&re_pthreadf01); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); +} diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_019.c b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_019.c new file mode 100644 index 000000000..58134db05 --- /dev/null +++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_019.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include + +#include "PthreadTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static void pthreadoncef01(void) +{ + g_testpthreadcount++; +} + +/**************************************************************************** + * Name: test_nuttx_pthread_test19 + ****************************************************************************/ + +void test_nuttx_pthread_test19(FAR void **state) +{ + UINT32 ret; + pthread_once_t onceblock = PTHREAD_ONCE_INIT; + + g_testpthreadcount = 0; + + ret = pthread_once(NULL, pthreadoncef01); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, EINVAL); + + ret = pthread_once(&onceblock, NULL); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, EINVAL); + + ret = pthread_once(&onceblock, pthreadoncef01); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); + syslog(LOG_INFO, "g_testpthreadcount: %d \n", g_testpthreadcount); + assert_int_equal(g_testpthreadcount, 1); + + ret = pthread_once(&onceblock, pthreadoncef01); + syslog(LOG_INFO, "ret: %d \n", ret); + syslog(LOG_INFO, "g_testpthreadcount: %d \n", g_testpthreadcount); + assert_int_equal(ret, 0); + assert_int_equal(g_testpthreadcount, 1); +} diff --git a/testing/testsuites/kernel/pthread/cases/posix_pthread_test_021.c b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_021.c new file mode 100644 index 000000000..93a833a02 --- /dev/null +++ b/testing/testsuites/kernel/pthread/cases/posix_pthread_test_021.c @@ -0,0 +1,90 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/pthread/cases/posix_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include + +#include "PthreadTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_pthread_test21 + ****************************************************************************/ + +void test_nuttx_pthread_test21(FAR void **state) +{ + UINT32 ret; + int oldstate; + int oldstype; + + ret = + pthread_setcancelstate(2, &oldstate); /* 2, test for invalid param. */ + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, EINVAL); + + ret = + pthread_setcancelstate(3, &oldstate); /* 3, test for invalid param. */ + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, EINVAL); + + ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); + + ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); + syslog(LOG_INFO, "oldstate: %d \n", oldstate); + assert_int_equal(oldstate, PTHREAD_CANCEL_ENABLE); + + ret = + pthread_setcanceltype(2, &oldstype); /* 2, test for invalid param. */ + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, EINVAL); + + ret = + pthread_setcanceltype(3, &oldstype); /* 3, test for invalid param. */ + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, EINVAL); + + ret = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + syslog(LOG_INFO, "ret: %d \n", ret); + assert_int_equal(ret, 0); + +#ifdef CONFIG_CANCELLATION_POINTS + ret = pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldstate); + syslog(LOG_INFO, "ret: %d \n", ret); + syslog(LOG_INFO, "oldstate: %d \n", oldstate); + assert_int_equal(ret, 0); + assert_int_equal(oldstate, PTHREAD_CANCEL_ASYNCHRONOUS); +#endif +} diff --git a/testing/testsuites/kernel/pthread/cmocka_pthread_test.c b/testing/testsuites/kernel/pthread/cmocka_pthread_test.c new file mode 100644 index 000000000..1045ff6fe --- /dev/null +++ b/testing/testsuites/kernel/pthread/cmocka_pthread_test.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/pthread/cmocka_pthread_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 +#include +#include "PthreadTest.h" +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: cmocka_sched_test_main + ****************************************************************************/ + +int main(int argc, char *argv[]) +{ + /* Add Test Cases */ + + const struct CMUnitTest nuttx_pthread_test_suites[] = + { + cmocka_unit_test_setup_teardown(test_nuttx_pthread_test03, NULL, + NULL), + cmocka_unit_test_setup_teardown(test_nuttx_pthread_test04, NULL, + NULL), + cmocka_unit_test_setup_teardown(test_nuttx_pthread_test05, NULL, + NULL), + cmocka_unit_test_setup_teardown(test_nuttx_pthread_test06, NULL, + NULL), + cmocka_unit_test_setup_teardown(test_nuttx_pthread_test09, NULL, + NULL), + cmocka_unit_test_setup_teardown(test_nuttx_pthread_test18, NULL, + NULL), + cmocka_unit_test_setup_teardown(test_nuttx_pthread_test19, NULL, + NULL), + cmocka_unit_test_setup_teardown(test_nuttx_pthread_test21, NULL, + NULL), + }; + + /* Run Test cases */ + + cmocka_run_group_tests(nuttx_pthread_test_suites, NULL, NULL); + + return 0; +} diff --git a/testing/testsuites/kernel/pthread/common/test_pthread_common.c b/testing/testsuites/kernel/pthread/common/test_pthread_common.c new file mode 100644 index 000000000..0c395f5b4 --- /dev/null +++ b/testing/testsuites/kernel/pthread/common/test_pthread_common.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/pthread/common/test_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "PthreadTest.h" + +UINT32 g_testpthreadcount; +UINT32 g_testpthreadtaskmaxnum = 128; +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: testpthreadself + ****************************************************************************/ + +pthread_t testpthreadself(void) +{ + pthread_t tid = pthread_self(); + return tid; +} + +/**************************************************************************** + * Name: TestNuttxSyscallTestGroupTearDown + ****************************************************************************/ diff --git a/testing/testsuites/kernel/pthread/include/PthreadTest.h b/testing/testsuites/kernel/pthread/include/PthreadTest.h new file mode 100644 index 000000000..8a0c8655f --- /dev/null +++ b/testing/testsuites/kernel/pthread/include/PthreadTest.h @@ -0,0 +1,138 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/pthread/include/PthreadTest.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 PTHREAD_TEST_H +#define PTHREAD_TEST_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "sched.h" +#include "signal.h" +#include "semaphore.h" +#include "sched.h" +#include "pthread.h" +#include "limits.h" +#include "unistd.h" +#include "mqueue.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +typedef unsigned int UINT32; +typedef unsigned long UINTPTR; + +#define PTHREAD_NO_ERROR 0 +#define PTHREAD_IS_ERROR (-1) +#define PTHREAD_SIGNAL_SUPPORT 0 /* 0 means that not support the signal */ +#define PTHREAD_PRIORITY_TEST 20 +#define PTHREAD_DEFAULT_STACK_SIZE (LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE) +#define PTHREAD_KEY_NUM 10 +#define THREAD_NUM 3 +#define PTHREAD_TIMEOUT (THREAD_NUM * 2) +#define PTHREAD_INTHREAD_TEST 0 /* Control going to or is already for Thread */ + +/* Control going to or is already for Main */ + +#define PTHREAD_INMAIN_TEST 1 +#define INVALID_PSHARED_VALUE (-100) +#define NUM_OF_CONDATTR 10 +#define RUNTIME 5 +#define PTHREAD_THREADS_NUM 3 +#define TCOUNT 5 // Number of single-threaded polling +#define COUNT_LIMIT 7 // The number of times the signal is sent +#define HIGH_PRIORITY 5 +#define LOW_PRIORITY 10 +#define PTHREAD_EXIT_VALUE ((void *)100) /* The return code of the thread when using pthread_exit(). */ + +#define PTHREAD_EXISTED_NUM TASK_EXISTED_NUM +#define PTHREAD_EXISTED_SEM_NUM SEM_EXISTED_NUM + +/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ + +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200112L +#endif + +#define PRIORITY_OTHER (-1) +#define PRIORITY_FIFO 20 +#define PRIORITY_RR 20 +#define LOSCFG_BASE_CORE_TSK_CONFIG 1024 + +extern UINT32 g_testpthreadcount; +extern UINT32 g_testpthreadtaskmaxnum; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +pthread_t testpthreadself(void); + +/* test case function */ + +/* cases/posix_pthread_test_003.c + * ************************************************/ + +void test_nuttx_pthread_test03(FAR void **state); + +/* cases/posix_pthread_test_004.c + * ************************************************/ + +void test_nuttx_pthread_test04(FAR void **state); + +/* cases/posix_pthread_test_005.c + * ************************************************/ + +void test_nuttx_pthread_test05(FAR void **state); + +/* cases/posix_pthread_test_006.c + * ************************************************/ + +void test_nuttx_pthread_test06(FAR void **state); + +/* cases/posix_pthread_test_009.c + * ************************************************/ + +void test_nuttx_pthread_test09(FAR void **state); + +/* cases/posix_pthread_test_018.c + * ************************************************/ + +void test_nuttx_pthread_test18(FAR void **state); + +/* cases/posix_pthread_test_019.c + * ************************************************/ + +void test_nuttx_pthread_test19(FAR void **state); + +/* cases/posix_pthread_test_021.c + * ************************************************/ + +void test_nuttx_pthread_test21(FAR void **state); +#endif diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_001.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_001.c new file mode 100644 index 000000000..f7e3dd367 --- /dev/null +++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_001.c @@ -0,0 +1,78 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cases/api_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: schedpthread01threadroutine + ****************************************************************************/ + +static void *schedpthread01threadroutine(void *arg) +{ + int flag; + flag = 1; + *((int *)arg) = flag; + return NULL; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_pthread01 + ****************************************************************************/ + +void test_nuttx_sched_pthread01(FAR void **state) +{ + pthread_t p_t; + int run_flag = 0; + + /* create thread */ + + pthread_create(&p_t, NULL, schedpthread01threadroutine, &run_flag); + + /* pthread_join Wait for the thread to end */ + + pthread_join(p_t, NULL); + assert_int_equal(run_flag, 1); +} diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_002.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_002.c new file mode 100644 index 000000000..bc70ca809 --- /dev/null +++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_002.c @@ -0,0 +1,104 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cases/api_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: schedpthread02threadroutine + ****************************************************************************/ + +static void *schedpthread02threadroutine(void *arg) +{ + return NULL; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_pthread02 + ****************************************************************************/ + +void test_nuttx_sched_pthread02(FAR void **state) +{ + int res; + pthread_t p_t; + pthread_attr_t attr; + size_t statck_size; + struct sched_param param; + struct sched_param o_param; + + /* Initializes thread attributes object (attr) */ + + res = pthread_attr_init(&attr); + assert_int_equal(res, OK); + + res = pthread_attr_setstacksize(&attr, PTHREAD_STACK_SIZE); + assert_int_equal(res, OK); + + res = pthread_attr_setschedpolicy(&attr, SCHED_FIFO); + assert_int_equal(res, OK); + + param.sched_priority = TASK_PRIORITY + 1; + + res = pthread_attr_setschedparam(&attr, ¶m); + assert_int_equal(res, OK); + + /* create thread */ + + pthread_create(&p_t, &attr, schedpthread02threadroutine, NULL); + + /* Wait for the child thread finish */ + + pthread_join(p_t, NULL); + + /* get schedparam */ + + res = pthread_attr_getschedparam(&attr, &o_param); + assert_int_equal(res, OK); + + /* get stack size */ + + res = pthread_attr_getstacksize(&attr, &statck_size); + assert_int_equal(res, OK); +} diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_003.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_003.c new file mode 100644 index 000000000..2d4998043 --- /dev/null +++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_003.c @@ -0,0 +1,89 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cases/api_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: schedpthread03threadroutine + ****************************************************************************/ + +static void *schedpthread03threadroutine(void *arg) +{ + int i = 0; + for (i = 0; i <= 5; i++) + { + if (i == 3) + { + pthread_exit(0); + } + } + + /* This part of the code will not be executed */ + + *((int *)arg) = 1; + return NULL; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_pthread03 + ****************************************************************************/ + +void test_nuttx_sched_pthread03(FAR void **state) +{ + pthread_t pid_1; + int ret; + int run_flag = 0; + + /* create test thread */ + + ret = pthread_create(&pid_1, NULL, (void *)schedpthread03threadroutine, + &run_flag); + assert_int_equal(ret, 0); + + pthread_join(pid_1, NULL); + + assert_int_not_equal(run_flag, 1); +} diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_004.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_004.c new file mode 100644 index 000000000..5c37ac9b3 --- /dev/null +++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_004.c @@ -0,0 +1,99 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cases/api_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: schedpthread04threadroutine + ****************************************************************************/ + +static void *schedpthread04threadroutine(void *arg) +{ + /* set enable */ + + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + + pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); + + sleep(1); + + /* cancel point */ + + pthread_testcancel(); + + /* It can not be executed here */ + + *((int *)arg) = 1; + return NULL; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_pthread04 + ****************************************************************************/ + +void test_nuttx_sched_pthread04(FAR void **state) +{ + int res; + pthread_t p_t_1; + + /* int flag */ + + int schedpthreadtest04_run_flag = 0; + + /* create thread_1 */ + + res = pthread_create(&p_t_1, NULL, schedpthread04threadroutine, + &schedpthreadtest04_run_flag); + assert_int_equal(res, OK); + + res = pthread_cancel(p_t_1); + assert_int_equal(res, OK); + + /* join thread_1 */ + + pthread_join(p_t_1, NULL); + assert_int_equal(schedpthreadtest04_run_flag, 0); +} diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_005.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_005.c new file mode 100644 index 000000000..5dc47df2f --- /dev/null +++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_005.c @@ -0,0 +1,83 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cases/api_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: schedpthread05threadroutine + ****************************************************************************/ + +static void *schedpthread05threadroutine(void *arg) +{ + int i; + for (i = 0; i <= 5; i++) + { + if (i == 2) + { + pthread_yield(); + } + } + + return NULL; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_pthread05 + ****************************************************************************/ + +void test_nuttx_sched_pthread05(FAR void **state) +{ + int res; + pthread_t p_t; + + /* create thread */ + + res = pthread_create(&p_t, NULL, schedpthread05threadroutine, NULL); + + assert_int_equal(res, 0); + + pthread_join(p_t, NULL); +} diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_006.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_006.c new file mode 100644 index 000000000..9a962f5fe --- /dev/null +++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_006.c @@ -0,0 +1,93 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cases/api_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: schedpthread06threadroutine + ****************************************************************************/ + +static void *schedpthread06threadroutine(void *arg) +{ + int pid; + + /* call pthread_self() */ + + pid = pthread_self(); + assert_true(pid > 0); + if (pid > 0) + { + *((int *)arg) = 0; + } + + else + { + *((int *)arg) = 1; + } + + return NULL; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_pthread06 + ****************************************************************************/ + +void test_nuttx_sched_pthread06(FAR void **state) +{ + pthread_t p_t; + int run_flag = 0; + int res; + + /* create thread */ + + res = + pthread_create(&p_t, NULL, schedpthread06threadroutine, &run_flag); + assert_int_equal(res, OK); + + pthread_join(p_t, NULL); + + assert_int_equal(run_flag, 0); +} diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_007.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_007.c new file mode 100644 index 000000000..f26d3e179 --- /dev/null +++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_007.c @@ -0,0 +1,93 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cases/api_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: schedpthread07threadroutine + ****************************************************************************/ + +static void *schedpthread07threadroutine(void *arg) +{ + int i; + pthread_mutex_t schedpthreadtest07_mutex = PTHREAD_MUTEX_INITIALIZER; + for (i = 0; i < 100; i++) + { + pthread_mutex_lock(&schedpthreadtest07_mutex); + (*((int *)arg))++; + pthread_mutex_unlock(&schedpthreadtest07_mutex); + } + + return NULL; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_pthread07 + ****************************************************************************/ + +void test_nuttx_sched_pthread07(FAR void **state) +{ + int res; + pthread_t pt_1, pt_2, pt_3; + int run_flag = 0; + + res = pthread_create(&pt_1, NULL, (void *)schedpthread07threadroutine, + &run_flag); + assert_int_equal(res, OK); + res = pthread_create(&pt_2, NULL, (void *)schedpthread07threadroutine, + &run_flag); + assert_int_equal(res, OK); + res = pthread_create(&pt_3, NULL, (void *)schedpthread07threadroutine, + &run_flag); + assert_int_equal(res, OK); + + pthread_join(pt_1, NULL); + pthread_join(pt_2, NULL); + pthread_join(pt_3, NULL); + sleep(5); + + assert_int_equal(run_flag, 300); +} diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_008.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_008.c new file mode 100644 index 000000000..e180fc8d0 --- /dev/null +++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_008.c @@ -0,0 +1,102 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cases/api_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static sem_t schedtask08_sem; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: schedpthread08threadroutine + ****************************************************************************/ + +static void *schedpthread08threadroutine(void *arg) +{ + int i; + for (i = 0; i < 5; i++) + { + sem_wait(&schedtask08_sem); + (*((int *)arg))++; + } + + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_pthread08 + ****************************************************************************/ + +void test_nuttx_sched_pthread08(FAR void **state) +{ + int res; + pthread_t pthread_id; + int run_flag = 0; + + res = sem_init(&schedtask08_sem, 0, 0); + assert_int_equal(res, OK); + + /* create pthread */ + + res = pthread_create(&pthread_id, NULL, + (void *)schedpthread08threadroutine, &run_flag); + assert_int_equal(res, OK); + + while (1) + { + sleep(2); + res = sem_post(&schedtask08_sem); + assert_int_equal(res, OK); + if (run_flag == 5) + break; + } + + res = sem_destroy(&schedtask08_sem); + assert_int_equal(res, OK); + assert_int_equal(run_flag, 5); +} diff --git a/testing/testsuites/kernel/sched/cases/api_pthread_test_009.c b/testing/testsuites/kernel/sched/cases/api_pthread_test_009.c new file mode 100644 index 000000000..1885d5dc3 --- /dev/null +++ b/testing/testsuites/kernel/sched/cases/api_pthread_test_009.c @@ -0,0 +1,105 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cases/api_pthread_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static sem_t schedtask09_sem; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: schedpthread09threadroutine + ****************************************************************************/ + +static void *schedpthread09threadroutine(void *arg) +{ + int i; + int res; + for (i = 0; i < 10; i++) + { + res = sem_wait(&schedtask09_sem); + assert_int_equal(res, OK); + (*((int *)arg))++; + res = sem_post(&schedtask09_sem); + assert_int_equal(res, OK); + } + + return NULL; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_pthread09 + ****************************************************************************/ + +void test_nuttx_sched_pthread09(FAR void **state) +{ + int res; + pthread_t pthread_id[10]; + int run_flag = 0; + + res = sem_init(&schedtask09_sem, 0, 1); + assert_int_equal(res, OK); + + int i; + for (i = 0; i < 10; i++) + { + res = + pthread_create(&pthread_id[i], NULL, + (void *)schedpthread09threadroutine, &run_flag); + assert_int_equal(res, OK); + } + + int j; + for (j = 0; j < 10; j++) + pthread_join(pthread_id[j], NULL); + + res = sem_destroy(&schedtask09_sem); + assert_int_equal(res, OK); + + assert_int_equal(run_flag, 100); +} diff --git a/testing/testsuites/kernel/sched/cases/api_task_test_001.c b/testing/testsuites/kernel/sched/cases/api_task_test_001.c new file mode 100644 index 000000000..d2ebc9d12 --- /dev/null +++ b/testing/testsuites/kernel/sched/cases/api_task_test_001.c @@ -0,0 +1,79 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cases/api_task_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: schedtask01routine + ****************************************************************************/ + +static int schedtask01routine(int argc, char *argv[]) +{ + char *str = NULL; + str = (char *)malloc(sizeof(char) * 1024); + assert_non_null(str); + memset(str, 'A', 1024); + free(str); + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_task01 + ****************************************************************************/ + +void test_nuttx_sched_task01(FAR void **state) +{ + pid_t pid; + int status; + + pid = task_create("schedtask01routine", TASK_PRIORITY, + DEFAULT_STACKSIZE, schedtask01routine, NULL); + assert_true(pid > 0); + waitpid(pid, &status, 0); +} diff --git a/testing/testsuites/kernel/sched/cases/api_task_test_002.c b/testing/testsuites/kernel/sched/cases/api_task_test_002.c new file mode 100644 index 000000000..13242e962 --- /dev/null +++ b/testing/testsuites/kernel/sched/cases/api_task_test_002.c @@ -0,0 +1,88 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cases/api_task_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: schedtask02routine + ****************************************************************************/ + +static int schedtask02routine(int argc, char *argv[]) +{ + int i; + for (i = 0; i < 10; i++) + { + sleep(1); + } + + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_task02 + ****************************************************************************/ + +void test_nuttx_sched_task02(FAR void **state) +{ + pid_t pid; + int status; + int res; + + pid = task_create("schedtask02routine", TASK_PRIORITY, + DEFAULT_STACKSIZE, schedtask02routine, NULL); + assert_true(pid > 0); + for (int i = 0; i < 2; i++) + { + sleep(2); + res = task_restart(pid); + assert_int_equal(res, OK); + } + + waitpid(pid, &status, 0); +} diff --git a/testing/testsuites/kernel/sched/cases/api_task_test_003.c b/testing/testsuites/kernel/sched/cases/api_task_test_003.c new file mode 100644 index 000000000..b2dd239bf --- /dev/null +++ b/testing/testsuites/kernel/sched/cases/api_task_test_003.c @@ -0,0 +1,89 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cases/api_task_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: schedtask03routine + ****************************************************************************/ + +static int schedtask03routine(int argc, char *argv[]) +{ + int i; + for (i = 0; i < 100; ++i) + { + usleep(20000); + + /* Run some simulated tasks */ + } + + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_task03 + ****************************************************************************/ + +void test_nuttx_sched_task03(FAR void **state) +{ + pid_t pid; + int res; + pid = task_create("schedtask03routine", TASK_PRIORITY, + DEFAULT_STACKSIZE, schedtask03routine, NULL); + assert_true(pid > 0); + + int i; + for (i = 0; i < 5; ++i) + { + usleep(2000); + } + + res = task_delete(pid); + assert_int_equal(res, 0); +} diff --git a/testing/testsuites/kernel/sched/cases/api_task_test_004.c b/testing/testsuites/kernel/sched/cases/api_task_test_004.c new file mode 100644 index 000000000..915c31477 --- /dev/null +++ b/testing/testsuites/kernel/sched/cases/api_task_test_004.c @@ -0,0 +1,114 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cases/api_task_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: schedtask04routine + ****************************************************************************/ + +static int schedtask04routine(int argc, char *argv[]) +{ + for (int i = 0; i < 5; i++) + { + /* Run some simulated tasks */ + + sleep(1); + } + + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_task04 + ****************************************************************************/ + +void test_nuttx_sched_task04(FAR void **state) +{ + pid_t pid; + int status; + int ret; + struct sched_param task_entry_param; + + /* create a test task */ + + pid = task_create("schedtask04routine", TASK_PRIORITY, + DEFAULT_STACKSIZE, schedtask04routine, NULL); + assert_true(pid > 0); + ret = sched_getparam(pid, &task_entry_param); + assert_int_equal(ret, 0); +#if CONFIG_RR_INTERVAL > 0 + ret = sched_setscheduler(pid, SCHED_RR, &task_entry_param); + assert_int_equal(ret, OK); + if (ret != OK) + { + syslog(LOG_ERR, "RR scheduling is not supported !\n"); + } + + switch (sched_getscheduler(pid)) + { + case SCHED_FIFO: + syslog(LOG_INFO, "[%s]:scheduling policy is FIFO!\n", __func__); + break; + case SCHED_RR: + syslog(LOG_INFO, "[%s]:scheduling policy is RR!\n", __func__); + break; + case SCHED_OTHER: + syslog(LOG_INFO, "[%s]:scheduling policy is OTHER!\n", __func__); + break; + default: + break; + } + +#endif + task_entry_param.sched_priority = 100; + ret = sched_setparam(pid, &task_entry_param); + assert_int_equal(ret, OK); + waitpid(pid, &status, 0); +} diff --git a/testing/testsuites/kernel/sched/cases/api_task_test_005.c b/testing/testsuites/kernel/sched/cases/api_task_test_005.c new file mode 100644 index 000000000..2d46a75ad --- /dev/null +++ b/testing/testsuites/kernel/sched/cases/api_task_test_005.c @@ -0,0 +1,85 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cases/api_task_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: schedtask05routine + ****************************************************************************/ + +static int schedtask05routine(int argc, char *argv[]) +{ + int ret; + int i; + for (i = 1; i <= 10; i++) + { + if (i >= 4 && i <= 7) + { + ret = sched_yield(); + assert_int_equal(ret, OK); + } + } + + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_task05 + ****************************************************************************/ + +void test_nuttx_sched_task05(FAR void **state) +{ + pid_t pid; + int status; + + pid = task_create("schedtask05routine", TASK_PRIORITY, + DEFAULT_STACKSIZE, schedtask05routine, NULL); + assert_true(pid > 0); + waitpid(pid, &status, 0); +} diff --git a/testing/testsuites/kernel/sched/cases/api_task_test_006.c b/testing/testsuites/kernel/sched/cases/api_task_test_006.c new file mode 100644 index 000000000..c0031409c --- /dev/null +++ b/testing/testsuites/kernel/sched/cases/api_task_test_006.c @@ -0,0 +1,83 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cases/api_task_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: schedtask06routine + ****************************************************************************/ + +static int schedtask06routine(int argc, char *argv[]) +{ + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_task06 + ****************************************************************************/ + +void test_nuttx_sched_task06(FAR void **state) +{ + pid_t pid; + int status; + int priority_max; + int priority_min; + + /* struct sched_param task_entry_param */ + + pid = task_create("schedtask06routine", TASK_PRIORITY, + DEFAULT_STACKSIZE, schedtask06routine, NULL); + assert_true(pid > 0); + priority_max = sched_get_priority_max(SCHED_FIFO); + priority_min = sched_get_priority_min(SCHED_FIFO); + assert_int_equal(priority_max, SCHED_PRIORITY_MAX); + assert_int_equal(priority_min, SCHED_PRIORITY_MIN); + waitpid(pid, &status, 0); +} diff --git a/testing/testsuites/kernel/sched/cases/api_task_test_007.c b/testing/testsuites/kernel/sched/cases/api_task_test_007.c new file mode 100644 index 000000000..de279236b --- /dev/null +++ b/testing/testsuites/kernel/sched/cases/api_task_test_007.c @@ -0,0 +1,96 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cases/api_task_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: schedtask07routine + ****************************************************************************/ + +static int schedtask07routine(int argc, char *argv[]) +{ + /* lock */ + + sched_lock(); + int i; + for (i = 0; i < 10; i++) + { + usleep(2000); + + /* Run some simulated tasks */ + } + + if (sched_lockcount() != 1) + { + fail_msg("test fail !"); + return 0; + } + + /* unlock */ + + sched_unlock(); + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_task07 + ****************************************************************************/ + +void test_nuttx_sched_task07(FAR void **state) +{ + pid_t pid; + int status; + + pid = task_create("schedtask07routine", TASK_PRIORITY, + DEFAULT_STACKSIZE, schedtask07routine, NULL); + assert_true(pid > 0); + + waitpid(pid, &status, 0); +} diff --git a/testing/testsuites/kernel/sched/cmocka_sched_test.c b/testing/testsuites/kernel/sched/cmocka_sched_test.c new file mode 100644 index 000000000..c71569a47 --- /dev/null +++ b/testing/testsuites/kernel/sched/cmocka_sched_test.c @@ -0,0 +1,71 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/cmocka_sched_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 "SchedTest.h" +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: cmocka_sched_test_main + ****************************************************************************/ + +int main(int argc, char *argv[]) +{ + /* Add Test Cases */ + + const struct CMUnitTest nuttx_sched_test_suites[] = + { + cmocka_unit_test(test_nuttx_sched_pthread01), + cmocka_unit_test(test_nuttx_sched_pthread02), + cmocka_unit_test(test_nuttx_sched_pthread03), + cmocka_unit_test(test_nuttx_sched_pthread04), + cmocka_unit_test(test_nuttx_sched_pthread05), + cmocka_unit_test(test_nuttx_sched_pthread06), + cmocka_unit_test(test_nuttx_sched_pthread07), + cmocka_unit_test(test_nuttx_sched_pthread08), + cmocka_unit_test(test_nuttx_sched_pthread09), + cmocka_unit_test(test_nuttx_sched_task01), + cmocka_unit_test(test_nuttx_sched_task02), + cmocka_unit_test(test_nuttx_sched_task03), + cmocka_unit_test(test_nuttx_sched_task04), + cmocka_unit_test(test_nuttx_sched_task05), + cmocka_unit_test(test_nuttx_sched_task06), + cmocka_unit_test(test_nuttx_sched_task07), + }; + + /* Run Test cases */ + + cmocka_run_group_tests(nuttx_sched_test_suites, + test_nuttx_sched_test_group_setup, + test_nuttx_sched_test_group_teardown); + return 0; +} diff --git a/testing/testsuites/kernel/sched/common/test_sched_common.c b/testing/testsuites/kernel/sched/common/test_sched_common.c new file mode 100644 index 000000000..4495a2a2a --- /dev/null +++ b/testing/testsuites/kernel/sched/common/test_sched_common.c @@ -0,0 +1,58 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/common/test_sched_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include "SchedTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_sched_test_group_setup + ****************************************************************************/ + +int test_nuttx_sched_test_group_setup(void **state) +{ + /* syslog(LOG_INFO, "This is goup setup !\n"); */ + + return 0; +} + +/**************************************************************************** + * Name: test_nuttx_sched_test_group_teardown + ****************************************************************************/ + +int test_nuttx_sched_test_group_teardown(void **state) +{ + /* syslog(LOG_INFO, "This is goup tearDown !\n"); */ + + return 0; +} diff --git a/testing/testsuites/kernel/sched/include/SchedTest.h b/testing/testsuites/kernel/sched/include/SchedTest.h new file mode 100644 index 000000000..a1070fdab --- /dev/null +++ b/testing/testsuites/kernel/sched/include/SchedTest.h @@ -0,0 +1,129 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/sched/include/SchedTest.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 __SCHEDTEST_H +#define __SCHEDTEST_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 + ****************************************************************************/ + +/* common/common_test.c + * *****************************************************/ + +int test_nuttx_sched_test_group_setup(void **state); +int test_nuttx_sched_test_group_teardown(void **state); + +/* testcase function */ + +/* cases/api_pthread_test_001.c + * *********************************************/ + +void test_nuttx_sched_pthread01(FAR void **state); + +/* cases/api_pthread_test_002.c + * *********************************************/ + +void test_nuttx_sched_pthread02(FAR void **state); + +/* cases/api_pthread_test_003.c + * *********************************************/ + +void test_nuttx_sched_pthread03(FAR void **state); + +/* cases/api_pthread_test_004.c + * *********************************************/ + +void test_nuttx_sched_pthread04(FAR void **state); + +/* cases/api_pthread_test_005.c + * *********************************************/ + +void test_nuttx_sched_pthread05(FAR void **state); + +/* cases/api_pthread_test_006.c + * *********************************************/ + +void test_nuttx_sched_pthread06(FAR void **state); + +/* cases/api_pthread_test_007.c + * *********************************************/ + +void test_nuttx_sched_pthread07(FAR void **state); + +/* cases/api_pthread_test_008.c + * *********************************************/ + +void test_nuttx_sched_pthread08(FAR void **state); + +/* cases/api_pthread_test_009.c + * *********************************************/ + +void test_nuttx_sched_pthread09(FAR void **state); + +/* cases/api_task_test_001.c + * ************************************************/ + +void test_nuttx_sched_task01(FAR void **state); + +/* cases/api_task_test_002.c + * ************************************************/ + +void test_nuttx_sched_task02(FAR void **state); + +/* cases/api_task_test_003.c + * ************************************************/ + +void test_nuttx_sched_task03(FAR void **state); + +/* cases/api_task_test_004.c + * ************************************************/ + +void test_nuttx_sched_task04(FAR void **state); + +/* cases/api_task_test_005.c + * ************************************************/ + +void test_nuttx_sched_task05(FAR void **state); + +/* cases/api_task_test_006.c + * ************************************************/ + +void test_nuttx_sched_task06(FAR void **state); + +/* cases/api_task_test_007.c + * ************************************************/ + +void test_nuttx_sched_task07(FAR void **state); + +#endif \ No newline at end of file diff --git a/testing/testsuites/kernel/socket/cases/net_socket_test_005.c b/testing/testsuites/kernel/socket/cases/net_socket_test_005.c new file mode 100644 index 000000000..7b9853d05 --- /dev/null +++ b/testing/testsuites/kernel/socket/cases/net_socket_test_005.c @@ -0,0 +1,81 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/socket/cases/net_socket_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + +#include "SocketTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_net_socket_test05 + ****************************************************************************/ + +void test_nuttx_net_socket_test05(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/testing/testsuites/kernel/socket/cases/net_socket_test_006.c b/testing/testsuites/kernel/socket/cases/net_socket_test_006.c new file mode 100644 index 000000000..c959e75cd --- /dev/null +++ b/testing/testsuites/kernel/socket/cases/net_socket_test_006.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/socket/cases/net_socket_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "SocketTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_net_socket_test06 + ****************************************************************************/ + +void test_nuttx_net_socket_test06(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/testing/testsuites/kernel/socket/cases/net_socket_test_008.c b/testing/testsuites/kernel/socket/cases/net_socket_test_008.c new file mode 100644 index 000000000..c3268f78b --- /dev/null +++ b/testing/testsuites/kernel/socket/cases/net_socket_test_008.c @@ -0,0 +1,339 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/socket/cases/net_socket_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 + ****************************************************************************/ +#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: test_nuttx_net_socket_test08 + ****************************************************************************/ + +void test_nuttx_net_socket_test08(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/testing/testsuites/kernel/socket/cases/net_socket_test_009.c b/testing/testsuites/kernel/socket/cases/net_socket_test_009.c new file mode 100644 index 000000000..56ad3ced6 --- /dev/null +++ b/testing/testsuites/kernel/socket/cases/net_socket_test_009.c @@ -0,0 +1,337 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/socket/cases/net_socket_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 + ****************************************************************************/ +#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: test_nuttx_net_socket_test09 + ****************************************************************************/ + +void test_nuttx_net_socket_test09(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/testing/testsuites/kernel/socket/cases/net_socket_test_010.c b/testing/testsuites/kernel/socket/cases/net_socket_test_010.c new file mode 100644 index 000000000..3902de841 --- /dev/null +++ b/testing/testsuites/kernel/socket/cases/net_socket_test_010.c @@ -0,0 +1,259 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/socket/cases/net_socket_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "SocketTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define IFF_PROMISC 0x100 + +/**************************************************************************** + * Private 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: test_nuttx_net_socket_test10 + ****************************************************************************/ + +static int ioctltestinternal(int sfd) +{ + struct ifreq ifr = + { + { + 0 + } + }; + + char ifname[IFNAMSIZ] = + { + 0 + }; + + char *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 test_nuttx_net_socket_test10(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/testing/testsuites/kernel/socket/cases/net_socket_test_011.c b/testing/testsuites/kernel/socket/cases/net_socket_test_011.c new file mode 100644 index 000000000..f10c04aaa --- /dev/null +++ b/testing/testsuites/kernel/socket/cases/net_socket_test_011.c @@ -0,0 +1,319 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/socket/cases/net_socket_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 + ****************************************************************************/ +#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: test_nuttx_net_socket_test11 + ****************************************************************************/ + +void test_nuttx_net_socket_test11(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(); +} diff --git a/testing/testsuites/kernel/socket/cmocka_socket_test.c b/testing/testsuites/kernel/socket/cmocka_socket_test.c new file mode 100644 index 000000000..5f694031c --- /dev/null +++ b/testing/testsuites/kernel/socket/cmocka_socket_test.c @@ -0,0 +1,71 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/socket/cmocka_socket_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 +#include +#include "SocketTest.h" +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: cmocka_sched_test_main + ****************************************************************************/ + +int main(int argc, char *argv[]) +{ + /* Add Test Cases */ + + const struct CMUnitTest nuttx_socket_test_suites[] = + { + cmocka_unit_test_setup_teardown(test_nuttx_net_socket_test05, NULL, + NULL), + cmocka_unit_test_setup_teardown(test_nuttx_net_socket_test06, NULL, + NULL), +#if defined(CONFIG_NET_LOOPBACK) || defined(CONFIG_NET_USRSOCK) + cmocka_unit_test_setup_teardown(test_nuttx_net_socket_test08, NULL, + NULL), + cmocka_unit_test_setup_teardown(test_nuttx_net_socket_test09, NULL, + NULL), + cmocka_unit_test_setup_teardown(test_nuttx_net_socket_test10, NULL, + NULL), + cmocka_unit_test_setup_teardown(test_nuttx_net_socket_test11, NULL, + NULL), +#endif + }; + + /* Run Test cases */ + + cmocka_run_group_tests(nuttx_socket_test_suites, NULL, NULL); + + return 0; +} diff --git a/testing/testsuites/kernel/socket/include/SocketTest.h b/testing/testsuites/kernel/socket/include/SocketTest.h new file mode 100644 index 000000000..56440c3fc --- /dev/null +++ b/testing/testsuites/kernel/socket/include/SocketTest.h @@ -0,0 +1,80 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/socket/include/SocketTest.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 __TEST_H +#define __TEST_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#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 test_nuttx_net_socket_test05(FAR void **state); + +/* cases/net_socket_test_006.c + * ************************************************/ + +void test_nuttx_net_socket_test06(FAR void **state); + +/* cases/net_socket_test_008.c + * ************************************************/ + +void test_nuttx_net_socket_test08(FAR void **state); + +/* cases/net_socket_test_009.c + * ************************************************/ + +void test_nuttx_net_socket_test09(FAR void **state); + +/* cases/net_socket_test_010.c + * ************************************************/ + +void test_nuttx_net_socket_test10(FAR void **state); + +/* cases/net_socket_test_011.c + * ************************************************/ + +void test_nuttx_net_socket_test11(FAR void **state); + +#endif diff --git a/testing/testsuites/kernel/syscall/cases/Fstatfs_test.c b/testing/testsuites/kernel/syscall/cases/Fstatfs_test.c new file mode 100644 index 000000000..d08113ebe --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/Fstatfs_test.c @@ -0,0 +1,104 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/Fstatfs_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 +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_fstatfs01 + ****************************************************************************/ + +void test_nuttx_syscall_fstatfs01(FAR void **state) +{ + int file_fd; + int pipe_fd; + int lc; + int i; + int ret; + int p[2]; + struct statfs stats; + char fname[256] = ""; + + struct tcase + { + int *fd; + const char *msg; + } + + tcases[2] = + { + { + NULL, "fstatfs() on a file" + }, + + { + NULL, "fstatfs() on a pipe" + }, + }; + + tcases[0].fd = &file_fd; + tcases[1].fd = &pipe_fd; + + sprintf(fname, "Fstatfs01_%d", gettid()); + + file_fd = open(fname, O_RDWR | O_CREAT, 0700); + assert_true(file_fd > 0); + + assert_int_equal(pipe(p), 0); + pipe_fd = p[0]; + assert_int_equal(close(p[1]), 0); + + for (lc = 0; lc < 2; lc++) + { + for (i = 0; i < 1; i++) + { + ret = fstatfs(*(tcases[i].fd), &stats); + assert_int_equal(ret, 0); + } + } + + if (file_fd > 0) + assert_int_equal(close(file_fd), 0); + + if (pipe_fd > 0) + assert_int_equal(close(pipe_fd), 0); + + assert_int_equal(unlink(fname), 0); +} diff --git a/testing/testsuites/kernel/syscall/cases/accept_test.c b/testing/testsuites/kernel/syscall/cases/accept_test.c new file mode 100644 index 000000000..2954a9068 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/accept_test.c @@ -0,0 +1,154 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/accept_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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_verityaccept01 + ****************************************************************************/ + +__attribute__((unused)) void test_nuttx_syscall_verityaccept01( + int testno, int domain, int type, int proto, int fd, + struct sockaddr *sockaddr, unsigned int *salen, int experrno) +{ +#ifdef CONFIG_NET_TCP + int ret; + errno = 0; + ret = accept(fd, sockaddr, salen); + close(fd); + assert_int_equal(ret, -1); + + /* syslog(LOG_INFO, "ret=%d errnor=%d\n experrno=%d", ret, + * errno,experrno); + */ + +#endif +} + +/**************************************************************************** + * Name: test_nuttx_syscall_accept01 + ****************************************************************************/ + +void test_nuttx_syscall_accept01(FAR void **state) +{ +#ifdef CONFIG_NET_TCP + struct sockaddr_in sin0; + struct sockaddr_in sin1; + struct sockaddr_in fsin1; + int invalid_socketfd = -400; + int devnull_fd; + int socket_fd; + int udp_fd; + + sin0.sin_family = AF_INET; + sin0.sin_port = 0; + sin0.sin_addr.s_addr = INADDR_ANY; + + devnull_fd = open("/dev/null", O_WRONLY); + + socket_fd = socket(PF_INET, SOCK_STREAM, 0); + assert_int_not_equal(socket_fd, -1); + bind(socket_fd, (struct sockaddr *)&sin0, sizeof(sin0)); + + sin1.sin_family = AF_INET; + sin1.sin_port = 0; + sin1.sin_addr.s_addr = INADDR_ANY; + udp_fd = socket(PF_INET, SOCK_DGRAM, 0); + assert_int_not_equal(udp_fd, -1); + bind(udp_fd, (struct sockaddr *)&sin1, sizeof(sin1)); + + struct test_case + { + int domain; + int type; + int proto; + int *fd; + struct sockaddr *sockaddr; + socklen_t salen; + int experrno; + } + + tcases[] = + { + { + PF_INET, SOCK_STREAM, 0, &invalid_socketfd, + (struct sockaddr *)&fsin1, sizeof(fsin1), EBADF + }, + + { + PF_INET, SOCK_STREAM, 0, &devnull_fd, (struct sockaddr *)&fsin1, + sizeof(fsin1), ENOTSOCK + }, + + { + PF_INET, SOCK_STREAM, 0, &socket_fd, (struct sockaddr *)3, + sizeof(fsin1), EINVAL + }, + + { + PF_INET, SOCK_STREAM, 0, &socket_fd, (struct sockaddr *)&fsin1, 1, + EINVAL + }, + + { + PF_INET, SOCK_STREAM, 0, &socket_fd, (struct sockaddr *)&fsin1, + sizeof(fsin1), EINVAL + }, + + { + PF_INET, SOCK_STREAM, 0, &udp_fd, (struct sockaddr *)&fsin1, + sizeof(fsin1), EOPNOTSUPP + }, + }; + + for (int i = 0; i < 6; i++) + { + test_nuttx_syscall_verityaccept01( + i, tcases[i].domain, tcases[i].type, tcases[i].proto, + *tcases[i].fd, tcases[i].sockaddr, &tcases[i].salen, + tcases[i].experrno); + } +#endif +} diff --git a/testing/testsuites/kernel/syscall/cases/bind_test.c b/testing/testsuites/kernel/syscall/cases/bind_test.c new file mode 100644 index 000000000..e035bf8a1 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/bind_test.c @@ -0,0 +1,137 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/bind_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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_bind01 + ****************************************************************************/ + +void test_nuttx_syscall_bind01(FAR void **state) +{ + int inet_socket; + int dev_null; + + struct sockaddr_in sin1; + struct sockaddr_in sin2; + struct sockaddr_un sun; + struct test_case + { + int *socket_fd; + struct sockaddr *sockaddr; + socklen_t salen; + int retval; + int experrno; + char *desc; + } + + tcases[] = + { + { + &inet_socket, (struct sockaddr *)&sin1, 3, -1, EINVAL, + "invalid salen" + }, + + { + &dev_null, (struct sockaddr *)&sin1, sizeof(sin1), -1, ENOTSOCK, + "invalid socket" + }, + + { + &inet_socket, (struct sockaddr *)&sin2, sizeof(sin2), 0, 0, + "INADDR_ANYPORT" + }, + + { + &inet_socket, (struct sockaddr *)&sun, sizeof(sun), -1, + EAFNOSUPPORT, "UNIX-domain of current directory" + }, + }; + + /* initialize sockaddr's */ + + sin1.sin_family = AF_INET; + sin1.sin_port = 25197; + sin1.sin_addr.s_addr = INADDR_ANY; + sin2.sin_family = AF_INET; + sin2.sin_port = 0; + sin2.sin_addr.s_addr = INADDR_ANY; + + sun.sun_family = AF_UNIX; + strncpy(sun.sun_path, ".", sizeof(sun.sun_path)); + inet_socket = socket(PF_INET, SOCK_STREAM, 0); + dev_null = open("/dev/null", O_WRONLY); + + int test_ret; + int test_err; + int i; + for (i = 0; i < 4; i++) + { + inet_socket = socket(PF_INET, SOCK_STREAM, 0); + dev_null = open("/dev/null", O_WRONLY); + if (tcases[i].experrno) + { + test_ret = bind(*tcases[i].socket_fd, tcases[i].sockaddr, + tcases[i].salen); + test_err = errno; + close(inet_socket); + close(dev_null); + assert_int_not_equal(test_ret, 0); + assert_int_equal(test_ret, -1); + assert_int_equal(test_err, tcases[i].experrno); + } + + else + { + test_ret = bind(*tcases[i].socket_fd, tcases[i].sockaddr, + tcases[i].salen); + close(inet_socket); + close(dev_null); + assert_int_not_equal(test_ret, -1); + assert_int_equal(test_ret, 0); + } + } +} diff --git a/testing/testsuites/kernel/syscall/cases/chdir_test.c b/testing/testsuites/kernel/syscall/cases/chdir_test.c new file mode 100644 index 000000000..73c8d750c --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/chdir_test.c @@ -0,0 +1,103 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/chdir_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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_chdir01 + ****************************************************************************/ + +void test_nuttx_syscall_chdir01(FAR void **state) +{ + char testdir[64] = + { + 0 + }; + + int ret; + + sprintf(testdir, "%s_dir", __func__); + rmdir(testdir); + assert_int_equal(mkdir(testdir, S_IRWXU), 0); + + ret = chdir(testdir); + assert_int_equal(ret, 0); + rmdir(testdir); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_chdir02 + ****************************************************************************/ + +void test_nuttx_syscall_chdir02(FAR void **state) +{ + int ret; + char dirs[64] = + { + 0 + }; + + getcwd(dirs, sizeof(dirs)); + + /* Switch the directory 100 times */ + + for (int lc = 0; lc < 100; lc++) + { + if (lc % 2 == 0) + { + ret = chdir("/"); + assert_int_equal(ret, 0); + } + + else + { + ret = chdir(dirs); + assert_int_equal(ret, 0); + } + } +} diff --git a/testing/testsuites/kernel/syscall/cases/clock_gettime_test.c b/testing/testsuites/kernel/syscall/cases/clock_gettime_test.c new file mode 100644 index 000000000..60495c72b --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/clock_gettime_test.c @@ -0,0 +1,106 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/clock_gettime_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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_clockgettime01 + ****************************************************************************/ + +void test_nuttx_syscall_clockgettime01(FAR void **state) +{ + int ret; + clockid_t type; + struct test_case + { + clockid_t clktype; + int allow_inval; + } + + tc[] = + { + { + CLOCK_REALTIME, + }, + + { + CLOCK_MONOTONIC, + }, + + { + CLOCK_BOOTTIME, 1 + }, + }; + + struct timespec spec; + + for (int i = 0; i < 3; i++) + { + type = tc[i].clktype; + switch (type) + { + case CLOCK_REALTIME: + + /* syslog(LOG_INFO, "clock_gettime test CLOCK_REALTIME\n"); */ + + break; + case CLOCK_MONOTONIC: + + /* syslog(LOG_INFO, "clock_gettime test CLOCK_MONOTONIC\n"); */ + + break; + case CLOCK_BOOTTIME: + + /* syslog(LOG_INFO, "clock_gettime test CLOCK_BOOTTIME\n"); */ + + break; + default: + break; + } + + ret = clock_gettime(type, &spec); + assert_int_equal(ret, 0); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/clock_nanosleep_test.c b/testing/testsuites/kernel/syscall/cases/clock_nanosleep_test.c new file mode 100644 index 000000000..f0a45ff61 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/clock_nanosleep_test.c @@ -0,0 +1,91 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/clock_nanosleep_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 +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_clocknanosleep01 + ****************************************************************************/ + +void test_nuttx_syscall_clocknanosleep01(FAR void **state) +{ + int ret; + clockid_t type = CLOCK_REALTIME; + struct timespec t; + clock_t start_time, end_time; + t.tv_sec = 2; + t.tv_nsec = 0; + start_time = clock(); + ret = clock_nanosleep(type, 0, &t, NULL); + assert_int_equal(ret, 0); + end_time = clock(); + assert_int_equal((time_t)(end_time - start_time) / CLOCKS_PER_SEC, + t.tv_sec); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_clocknanosleep02 + ****************************************************************************/ + +void test_nuttx_syscall_clocknanosleep02(FAR void **state) +{ + int ret; + struct timespec ts; + clockid_t tcase[] = + { + CLOCK_MONOTONIC, + CLOCK_REALTIME, + }; + + ret = clock_gettime(tcase[0], &ts); + assert_int_equal(ret, 0); + + ts.tv_sec = 4; + ts.tv_nsec = 1000; + + ret = clock_nanosleep(tcase[0], TIMER_ABSTIME, &ts, NULL); + assert_int_equal(ret, 0); + + ret = clock_gettime(tcase[1], &ts); + assert_int_equal(ret, 0); + + ts.tv_sec = 4; + ts.tv_nsec = 1000; + + ret = clock_nanosleep(tcase[1], TIMER_ABSTIME, &ts, NULL); + assert_int_equal(ret, 0); +} diff --git a/testing/testsuites/kernel/syscall/cases/clock_settime_test.c b/testing/testsuites/kernel/syscall/cases/clock_settime_test.c new file mode 100644 index 000000000..b819508a8 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/clock_settime_test.c @@ -0,0 +1,67 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/clock_settime_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 +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_clocksettime01 + ****************************************************************************/ + +void test_nuttx_syscall_clocksettime01(FAR void **state) +{ + int ret; + struct timespec ts; + time_t begin_time; + time_t end_time; + + /* do clock_gettime */ + + ret = clock_gettime(CLOCK_REALTIME, &ts); + assert_int_equal(ret, 0); + + begin_time = ts.tv_sec; + ts.tv_sec = ts.tv_sec + 10; + ret = clock_settime(CLOCK_REALTIME, &ts); + assert_int_equal(ret, 0); + + ret = clock_gettime(CLOCK_REALTIME, &ts); + assert_int_equal(ret, 0); + + end_time = ts.tv_sec; + assert_true((end_time - begin_time) >= 10); +} diff --git a/testing/testsuites/kernel/syscall/cases/close_test.c b/testing/testsuites/kernel/syscall/cases/close_test.c new file mode 100644 index 000000000..1893d0d68 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/close_test.c @@ -0,0 +1,150 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/close_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 +#include +#include +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_close01 + ****************************************************************************/ + +void test_nuttx_syscall_close01(FAR void **state) +{ + int fd; + int newfd; + int pipefd[2] = + { + 0 + }; + + char filename[128] = + { + 0 + }; + + int ret; + + sprintf(filename, "%s_dir", __func__); + + fd = creat(filename, 0777); + + newfd = dup(fd); + + ret = pipe(pipefd); + assert_int_equal(ret, 0); + + for (int i = 0; i < 2; i++) + { + if (pipefd[i] > 0) + { + ret = close(pipefd[i]); + assert_int_equal(ret, 0); + } + } + + if (fd > 0) + close(fd); + if (newfd > 0) + close(newfd); + remove(filename); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_close02 + ****************************************************************************/ + +void test_nuttx_syscall_close02(FAR void **state) +{ +#ifndef CONFIG_FDSAN + int ret; + int badfd1 = -1; + int badfd2 = 99999999; + + ret = close(badfd1); + assert_int_equal(ret, ERROR); + + /* Check that an invalid file descriptor returns EBADF + */ + + assert_int_equal(errno, EBADF); + + ret = close(badfd2); + assert_int_equal(ret, ERROR); + + /* Check that an invalid file descriptor returns EBADF + */ + + assert_int_equal(errno, EBADF); +#endif +} + +/**************************************************************************** + * Name: test_nuttx_syscall_close03 + ****************************************************************************/ + +void test_nuttx_syscall_close03(FAR void **state) +{ + char filename[128] = + { + 0 + }; + + int fd; + int ret; + + for (int i = 0; i < 100; i++) + { + memset(filename, 0, sizeof(filename)); + sprintf(filename, "%s_dir%d", __func__, i + 1); + + fd = open(filename, O_RDWR | O_CREAT, 0700); + if (fd < 0) + { + fail_msg("open test file fail !\n"); + } + + ret = close(fd); + assert_int_equal(ret, 0); + + unlink(filename); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/connect_test.c b/testing/testsuites/kernel/syscall/cases/connect_test.c new file mode 100644 index 000000000..9e252b470 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/connect_test.c @@ -0,0 +1,372 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/connect_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 + ****************************************************************************/ +#ifndef UCLINUX +#define UCLINUX +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef CONFIG_FDCHECK +#include +#endif +#include "SyscallTest.h" + +__attribute__((unused)) static int s; /* socket descriptor */ +__attribute__((unused)) static int testno; +__attribute__((unused)) static struct sockaddr_in sin1, sin2, sin4; +__attribute__((unused)) static pthread_t thread; +__attribute__((unused)) static int + sfd; /* shared between start_server and do_child */ +__attribute__((unused)) static int setup(void), setup0(void), + setup1(void), setup2(void), cleanup(void), cleanup0(void), + cleanup1(void); +__attribute__((unused)) static void do_child(void); + +__attribute__((unused)) static void *start_server(void *); + +__attribute__((unused)) static struct test_case_t +{ + int domain; /* PF_INET, PF_UNIX, ... */ + int type; /* SOCK_STREAM, SOCK_DGRAM ... */ + int proto; /* protocol number (usually 0 = default) */ + struct sockaddr *sockaddr; /* socket address buffer */ + int salen; /* connect's 3rd argument */ + int retval; /* syscall return value */ + int experrno; /* expected errno */ + int (*setup)(void); + int (*cleanup)(void); + char *desc; +} + +tdat[] = + { + { + PF_INET, SOCK_STREAM, 0, (struct sockaddr *)&sin1, + sizeof(struct sockaddr_in), -1, EBADF, setup0, cleanup0, + "bad file descriptor" + }, + #ifndef UCLINUX + + /* Skip since uClinux does not implement memory protection */ + + { + PF_INET, SOCK_STREAM, 0, (struct sockaddr *)-1, + sizeof(struct sockaddr_in), -1, EFAULT, setup1, cleanup1, + "invalid socket buffer" + }, + + #endif + { + PF_INET, SOCK_STREAM, 0, (struct sockaddr *)&sin1, 3, -1, EINVAL, + setup1, cleanup1, "invalid salen" + }, + + { + 0, 0, 0, (struct sockaddr *)&sin1, sizeof(sin1), -1, ENOTSOCK, + setup0, cleanup0, "invalid socket" + }, + + { + PF_INET, SOCK_STREAM, 0, (struct sockaddr *)&sin1, + sizeof(sin1), -1, EISCONN, setup2, cleanup1, + "already connected" + }, + + { + PF_INET, SOCK_STREAM, 0, (struct sockaddr *)&sin2, + sizeof(sin2), -1, ECONNREFUSED, setup1, cleanup1, + "connection refused" + }, + + /* if CONFIG_DEBUG_ASSERTIONS is set, + * the connect operation will be crash + */ + + #ifndef CONFIG_DEBUG_ASSERTIONS + { + PF_INET, SOCK_STREAM, 0, (struct sockaddr *)&sin4, + sizeof(sin4), -1, EAFNOSUPPORT, setup1, cleanup1, + "invalid address family" + }, + #endif + }; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_connect01 + ****************************************************************************/ + +void test_nuttx_syscall_connect01(FAR void **state) +{ +#ifdef CONFIG_NET_TCP + int ret; + int flag = 1; + setup(); + + for (testno = 0; testno < sizeof(tdat) / sizeof((tdat)[0]); ++testno) + { + usleep(100000); + if (tdat[testno].setup() < 0) + { + tdat[testno].cleanup(); + continue; + } + + ret = connect(s, tdat[testno].sockaddr, tdat[testno].salen); + + if (ret != tdat[testno].retval || + (ret < 0 && errno != tdat[testno].experrno)) + { + syslog(LOG_ERR, + "test connect %s failed; " + "returned %d (expected %d), errno %d " + "(expected %d)\n", + tdat[testno].desc, ret, tdat[testno].retval, errno, + tdat[testno].experrno); + + /* fail_msg("test fail !"); */ + + flag = 1; + } + + tdat[testno].cleanup(); + } + + cleanup(); + assert_true(flag); +#endif +} + +__attribute__((unused)) static int setup(void) +{ + int r = pthread_create(&thread, NULL, start_server, (void *)&sin1); + if (r < 0) + return -1; + + sin2.sin_family = AF_INET; + + /* this port must be unused! */ + + sin2.sin_port = get_unused_port(NULL, AF_INET, SOCK_STREAM); + if (sin2.sin_port < 0) + return -1; + sin2.sin_addr.s_addr = INADDR_ANY; + + sin4.sin_family = 47; /* bogus address family */ + sin4.sin_port = 0; + sin4.sin_addr.s_addr = htonl(0x0afffefd); + return 0; +} + +__attribute__((unused)) static int cleanup(void) +{ + assert_true(pthread_cancel(thread) == 0); + assert_true(pthread_join(thread, NULL) == 0); + return 0; +} + +__attribute__((unused)) static int setup0(void) +{ + if (tdat[testno].experrno == EBADF) + s = -400; /* anything not an open file */ + else if ((s = open("/dev/null", O_WRONLY)) == -1) + { + syslog(LOG_ERR, "open /dev/null fail, errno %d\n", errno); + fail_msg("test fail !"); + return -1; + } + + return 0; +} + +__attribute__((unused)) static int cleanup0(void) +{ + close(s); + s = -1; + return 0; +} + +__attribute__((unused)) static int setup1(void) +{ + s = safe_socket(tdat[testno].domain, tdat[testno].type, + tdat[testno].proto); + return s; +} + +__attribute__((unused)) static int cleanup1(void) +{ + (void)close(s); + s = -1; + return 0; +} + +__attribute__((unused)) static int setup2(void) +{ + if (setup1() < 0) /* get a socket in s */ + return -1; + return safe_connect(s, (const struct sockaddr *)&sin1, sizeof(sin1)); +} + +__attribute__((unused)) static void *start_server(void *arg) +{ + /* 设置取消状态为启用 */ + + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + + /* 设置取消类型为异步取消 */ + + pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + + struct sockaddr_in *sin0 = (struct sockaddr_in *)arg; + socklen_t slen = sizeof(*sin0); + + sin0->sin_family = AF_INET; + sin0->sin_port = 0; /* pick random free port */ + sin0->sin_addr.s_addr = INADDR_ANY; + + sfd = socket(PF_INET, SOCK_STREAM, 0); + if (sfd < 0) + { + syslog(LOG_ERR, "server socket failed\n"); + fail_msg("test fail !"); + return NULL; + } + + if (bind(sfd, (struct sockaddr *)sin0, sizeof(*sin0)) < 0) + { + syslog(LOG_ERR, "server bind failed\n"); + close(sfd); + fail_msg("test fail !"); + return NULL; + } + + if (listen(sfd, 10) < 0) + { + syslog(LOG_ERR, "server listen failed\n"); + close(sfd); + fail_msg("test fail !"); + return NULL; + } + + safe_getsockname(sfd, (struct sockaddr *)sin0, &slen); + do_child(); + return NULL; +} + +__attribute__((unused)) static void do_child(void) +{ + struct sockaddr_in fsin; + fd_set afds; + fd_set rfds; + int nfds; + int cc; + int fd; +#ifdef CONFIG_FDCHECK + int fd_tmp = 0; +#endif + char c; + + FD_ZERO(&afds); + FD_SET(sfd, &afds); + + nfds = sfd + 1; + + /* accept connections until killed */ + + while (1) + { + socklen_t fromlen; + + memcpy(&rfds, &afds, sizeof(rfds)); + + if (select(nfds, &rfds, NULL, NULL, NULL) < 0) + if (errno != EINTR) + { + syslog(LOG_ERR, "select exit fail\n"); + fail_msg("test fail !"); + return; + } + + if (FD_ISSET(sfd, &rfds)) + { + int newfd; + + fromlen = sizeof(fsin); + newfd = accept(sfd, (struct sockaddr *)&fsin, &fromlen); + if (newfd >= 0) + { + FD_SET(newfd, &afds); + nfds = (nfds > newfd + 1) ? (nfds) : (newfd + 1); + } + } + +#ifdef CONFIG_FDCHECK + for (fd = 0; fd < fdcheck_restore(nfds - 1) + 1; ++fd) + { + fd_tmp = fdcheck_protect(fd); + if (fd_tmp != sfd && FD_ISSET(fd_tmp, &rfds)) + { + if ((cc = read(fd_tmp, &c, 1)) == 0) + { + (void)close(fd_tmp); + FD_CLR(fd_tmp, &afds); + } + } + } + +#else + for (fd = 0; fd < nfds; ++fd) + if (fd != sfd && FD_ISSET(fd, &rfds)) + { + if ((cc = read(fd, &c, 1)) == 0) + { + (void)close(fd); + FD_CLR(fd, &afds); + } + } + +#endif + pthread_testcancel(); + } +} + +#undef UCLINUX +#endif diff --git a/testing/testsuites/kernel/syscall/cases/creat_test.c b/testing/testsuites/kernel/syscall/cases/creat_test.c new file mode 100644 index 000000000..ccf0239c0 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/creat_test.c @@ -0,0 +1,123 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/creat_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 +#include +#include +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_creat01 + ****************************************************************************/ + +void test_nuttx_syscall_creat01(FAR void **state) +{ + char filename[50] = ""; + int fd; + int res; + struct tcase + { + int mode; + } + + tcases[] = + { + { + 0644 + }, + + { + 0444 + }, + }; + + sprintf(filename, "Creat01%d", gettid()); + + struct stat buf; + char c; + char w_buf[2] = "A"; + + for (int i = 0; i < 2; i++) + { + fd = creat(filename, tcases[0].mode); + if (fd > 0) + { + res = stat(filename, &buf); + assert_int_equal(res, 0); + assert_int_equal(buf.st_size, 0); + assert_int_equal(write(fd, w_buf, 1), 1); + assert_int_equal(read(fd, &c, 1), -1); + close(fd); + } + } + + res = unlink(filename); + assert_int_equal(res, 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_creat02 + ****************************************************************************/ + +void test_nuttx_syscall_creat02(FAR void **state) +{ + char filename[50] = ""; + int fd; + int res; + struct stat statbuf; + + sprintf(filename, "Creat02%d", gettid()); + + fd = creat(filename, 444); + if (fd > 0) + { + res = fstat(fd, &statbuf); + assert_int_equal(res, 0); + assert_int_equal((statbuf.st_mode & S_ISVTX), 0); + + close(fd); + res = unlink(filename); + assert_int_equal(res, 0); + } + else + { + fail_msg("open test file fail !\n"); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/dup2_test.c b/testing/testsuites/kernel/syscall/cases/dup2_test.c new file mode 100644 index 000000000..7d6a605f8 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/dup2_test.c @@ -0,0 +1,157 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/dup2_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 +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_dup201 + ****************************************************************************/ + +void test_nuttx_syscall_dup201(FAR void **state) +{ +#ifndef CONFIG_FDSAN + int ret; + int goodfd = 5; + int badfd = -1; + int mystdout = 0; + + struct test_case_t + { + int *ofd; + int *nfd; + int error; + } + + TC[] = + { + /* First fd argument is less than 0 - EBADF */ + + { + NULL, NULL, EBADF + }, + + /* Second fd argument is less than 0 - EBADF */ + + { + NULL, NULL, EBADF + }, + }; + + TC[0].ofd = &badfd; + TC[0].nfd = &goodfd; + + TC[1].ofd = &mystdout; + TC[1].nfd = &badfd; + + for (int i = 0; i < 2; i++) + { + ret = dup2(*TC[i].ofd, *TC[i].nfd); + assert_int_equal(ret, -1); + assert_int_equal(errno, TC[i].error); + } + +#endif +} + +/**************************************************************************** + * Name: test_nuttx_syscall_dup202 + ****************************************************************************/ + +void test_nuttx_syscall_dup202(FAR void **state) +{ + char testfile[64] = ""; + int ret; + int i; + int ofd; + int duprdo = 10; + int dupwro = 20; + int duprdwr = 30; + struct stat oldbuf; + struct stat newbuf; + + struct test_case_t + { + int *nfd; + mode_t mode; + } + + TC[] = + { + { + NULL, (S_IRUSR | S_IRGRP | S_IROTH) + }, + + { + NULL, (S_IWUSR | S_IWGRP | S_IWOTH) + }, + + { + NULL, (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | S_IWOTH) + }, + }; + + TC[0].nfd = &duprdo; + TC[1].nfd = &dupwro; + TC[2].nfd = &duprdwr; + + sprintf(testfile, "%s_file", __func__); + + for (i = 0; i < 3; i++) + { + ofd = creat(testfile, TC[i].mode); + assert_true(ofd > 0); + + ret = dup2(ofd, *TC[i].nfd); + assert_int_not_equal(ret, -1); + if (ret == -1) + { + continue; + } + + assert_int_equal(fstat(ofd, &oldbuf), 0); + assert_int_equal(fstat(*(TC[i].nfd), &newbuf), 0); + assert_int_equal(oldbuf.st_mode, newbuf.st_mode); + + close(*TC[i].nfd); + close(ofd); + close(ret); + + assert_int_equal(unlink(testfile), 0); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/dup_test.c b/testing/testsuites/kernel/syscall/cases/dup_test.c new file mode 100644 index 000000000..03fec26e0 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/dup_test.c @@ -0,0 +1,244 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/dup_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 +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_dup01 + ****************************************************************************/ + +void test_nuttx_syscall_dup01(FAR void **state) +{ + char filename[64]; + int fd = -1; + int ret; + + sprintf(filename, "%s_file", __func__); + + fd = open(filename, O_RDWR | O_CREAT, 0700); + if (fd < 0) + { + fail_msg("open test file fail !\n"); + } + + ret = dup(fd); + + assert_true(ret > 0); + if (fd > 0) + { + close(fd); + } + + if (ret > 0) + close(ret); + + assert_int_equal(unlink(filename), 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_dup02 + ****************************************************************************/ + +void test_nuttx_syscall_dup02(FAR void **state) +{ +#ifndef CONFIG_FDSAN + int fds[] = + { + -1, 1500 + }; + + int ret; + int nfds; + int ind; + + nfds = sizeof(fds) / sizeof(int); + + for (ind = 0; ind < nfds; ind++) + { + ret = dup(fds[ind]); + assert_int_equal(ret, -1); + if (ret == -1) + { + assert_int_equal(errno, EBADF); + } + } +#endif +} + +/**************************************************************************** + * Name: test_nuttx_syscall_dup03 + ****************************************************************************/ + +void test_nuttx_syscall_dup03(FAR void **state) +{ + int fd[2]; + int ret; + + fd[0] = -1; + pipe(fd); + + ret = dup(fd[0]); + assert_true(ret > 0); + if (ret > 0) + close(ret); + + ret = dup(fd[1]); + assert_true(ret > 0); + if (ret > 0) + close(ret); + + if (fd[0] > 0) + close(fd[0]); + if (fd[1] > 0) + close(fd[1]); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_dup04 + ****************************************************************************/ + +void test_nuttx_syscall_dup04(FAR void **state) +{ + char fname[64]; + int fd = -1; + int ret; + + sprintf(fname, "%s_file", __func__); + + fd = open(fname, O_RDWR | O_CREAT, 0700); + assert_true(fd > 0); + + ret = dup(fd); + assert_true(ret > 0); + + if (fd > 0) + { + close(fd); + } + + if (ret > 0) + close(ret); + + assert_int_equal(unlink(fname), 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_dup05 + ****************************************************************************/ + +void test_nuttx_syscall_dup05(FAR void **state) +{ + struct stat retbuf; + struct stat dupbuf; + int rdoret; + int wroret; + int rdwret; + int duprdo; + int dupwro; + int duprdwr; + char testfile[64] = ""; + + sprintf(testfile, "%s_file", __func__); + + rdoret = creat(testfile, 0444); + if (rdoret > 0) + { + duprdo = dup(rdoret); + if (duprdo > 0) + { + assert_int_equal(fstat(rdoret, &retbuf), 0); + assert_int_equal(fstat(duprdo, &dupbuf), 0); + assert_int_equal(retbuf.st_mode, dupbuf.st_mode); + + assert_int_equal(close(duprdo), 0); + assert_int_equal(close(rdoret), 0); + } + } + + else + { + fail_msg("create test fail fail !\n"); + } + + assert_int_equal(unlink(testfile), 0); + + wroret = creat(testfile, 0222); + if (wroret > 0) + { + dupwro = dup(wroret); + if (dupwro) + { + assert_int_equal(fstat(wroret, &retbuf), 0); + assert_int_equal(fstat(dupwro, &dupbuf), 0); + assert_int_equal(retbuf.st_mode, dupbuf.st_mode); + + assert_int_equal(close(dupwro), 0); + assert_int_equal(close(wroret), 0); + } + } + + else + { + fail_msg("create test fail fail !\n"); + } + + assert_int_equal(unlink(testfile), 0); + + rdwret = creat(testfile, 0666); + if (rdwret > 0) + { + duprdwr = dup(rdwret); + if (duprdwr > 0) + { + assert_int_equal(fstat(rdwret, &retbuf), 0); + assert_int_equal(fstat(duprdwr, &dupbuf), 0); + assert_int_equal(retbuf.st_mode, dupbuf.st_mode); + + assert_int_equal(close(duprdwr), 0); + assert_int_equal(close(rdwret), 0); + } + } + + else + { + fail_msg("create test fail fail !\n"); + } + + assert_int_equal(unlink(testfile), 0); +} diff --git a/testing/testsuites/kernel/syscall/cases/fcntl_test.c b/testing/testsuites/kernel/syscall/cases/fcntl_test.c new file mode 100644 index 000000000..a2b97c489 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/fcntl_test.c @@ -0,0 +1,318 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/fcntl_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 +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_fcntl01 + ****************************************************************************/ + +void test_nuttx_syscall_fcntl01(FAR void **state) +{ + int flags; + int is_pass = 0; + int ret; + char fname[40] = ""; + int fd[10]; + int fd2[10]; + + for (int i = 0; i < 8; i++) + { + sprintf(fname, "Fcntl01%d-%d", gettid(), i); + fd[i] = open(fname, O_WRONLY | O_CREAT, 0666); + if (fd[i] < 0) + { + syslog(LOG_ERR, "open test file fail !\n"); + is_pass = -1; + break; + } + + fd2[i] = fd[i]; + } + + assert_int_equal(is_pass, 0); + close(fd[2]); + close(fd[3]); + close(fd[4]); + close(fd[5]); + + assert_false((fd[2] = fcntl(fd[1], F_DUPFD, 1)) == -1); + + assert_false(fd[2] < fd2[2]); + + assert_false((fd[4] = fcntl(fd[1], F_DUPFD, fd2[3])) < 0); + + assert_false(fd[4] < fd2[3]); + + assert_false((fd[8] = fcntl(fd[1], F_DUPFD, fd2[5])) < 0); + + assert_false(fd[8] != fd2[5]); + + /* //block1: */ + + flags = fcntl(fd[2], F_GETFL, 0); + assert_false((flags & O_WRONLY) == 0); + + /* Check setting of no_delay flag */ + + assert_false(fcntl(fd[2], F_SETFL, O_NDELAY) == -1); + + flags = fcntl(fd[2], F_GETFL, 0); + assert_false((flags & (O_NDELAY | O_WRONLY)) == 0); + + /* Check of setting append flag */ + + assert_false(fcntl(fd[2], F_SETFL, O_APPEND) == -1); + + flags = fcntl(fd[2], F_GETFL, 0); + assert_false((flags & (O_APPEND | O_WRONLY)) == 0); + + /* Check setting flags together */ + + assert_false(fcntl(fd[2], F_SETFL, O_NDELAY | O_APPEND) < 0); + + flags = fcntl(fd[2], F_GETFL, 0); + assert_false((flags & (O_NDELAY | O_APPEND | O_WRONLY)) == 0); + + /* Check that flags are not cummulative */ + + assert_false(fcntl(fd[2], F_SETFL, 0) == -1); + + flags = fcntl(fd[2], F_GETFL, 0); + assert_false((flags & O_WRONLY) == 0); + assert_false((flags = fcntl(fd[2], F_GETFD, 0)) < 0); + assert_false(flags != 0); + assert_false((flags = fcntl(fd[2], F_SETFD, 1)) == -1); + assert_false((flags = fcntl(fd[2], F_GETFD, 0)) == -1); + assert_false(flags != 1); + + for (int j = 0; j < 10; j++) + close(fd[j]); + for (int k = 0; k < 8; k++) + { + sprintf(fname, "Fcntl01%d-%d", gettid(), k); + ret = unlink(fname); + if (ret != 0) + { + syslog(LOG_ERR, "unlink test file(%s) fail !\n", fname); + is_pass = -1; + } + } + + assert_int_equal(is_pass, 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_fcntl02 + ****************************************************************************/ + +void test_nuttx_syscall_fcntl02(FAR void **state) +{ + char fname[256] = ""; + int fd; + int min_fd; + int ret = 0; + int min_fds[] = + { + 0, 1, 2, 3, 10, 100 + }; + + sprintf(fname, "Fcntl02_%d", gettid()); + fd = open(fname, O_RDWR | O_CREAT, 0700); + assert_true(fd > 0); + + if (fd > 0) + { + min_fd = min_fds[0]; + ret = fcntl(fd, F_DUPFD, min_fd); + assert_true(ret > min_fd); + } + + if (ret > 0) + close(ret); + if (fd > 0) + close(fd); + ret = unlink(fname); + assert_int_equal(ret, 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_fcntl03 + ****************************************************************************/ + +void test_nuttx_syscall_fcntl03(FAR void **state) +{ + int fd; + int ret; + char fname[256] = ""; + sprintf(fname, "fcntl03_%d", gettid()); + fd = open(fname, O_RDWR | O_CREAT, 0700); + assert_true(fd > 0); + + ret = fcntl(fd, F_GETFD, 0); + assert_true(ret != -1); + + close(fd); + ret = unlink(fname); + assert_int_equal(ret, 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_fcntl04 + ****************************************************************************/ + +void test_nuttx_syscall_fcntl04(FAR void **state) +{ + int fd; + int ret; + char fname[256] = ""; + sprintf(fname, "fcntl04_%d", gettid()); + + fd = open(fname, O_RDWR | O_CREAT, 0700); + assert_true(fd > 0); + + ret = fcntl(fd, F_GETFL, 0); + assert_int_equal(ret & O_ACCMODE, O_RDWR); + + close(fd); + ret = unlink(fname); + assert_int_equal(ret, 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_fcntl05 + ****************************************************************************/ + +void test_nuttx_syscall_fcntl05(FAR void **state) +{ + int file_fd; + int fifo_fd; + int lc; + int ret; + int pipe_fds[2]; + char fname[256] = ""; + struct tcase + { + int *fd; + const char *msg; + } + + tcases[] = + { + { + NULL, "regular file" + }, + + { + NULL, "pipe (write end)" + }, + + { + NULL, "pipe (read end)" + }, + + { + NULL, "fifo" + }, + }; + + sprintf(fname, "fcntl05_%d", gettid()); + + file_fd = open(fname, O_CREAT | O_RDWR, 0666); + assert_true(file_fd > 0); + assert_int_equal(pipe(pipe_fds), 0); + unlink("/fcntl05_fifo"); + assert_int_equal(mkfifo("/fcntl05_fifo", 0777), 0); + + fifo_fd = open("/fcntl05_fifo", O_RDWR); + assert_true(fifo_fd > 0); + + tcases[0].fd = &file_fd; + tcases[1].fd = pipe_fds; + tcases[2].fd = pipe_fds + 1; + tcases[3].fd = &fifo_fd; + + for (lc = 0; lc < 1; lc++) + { + for (int i = 0; i < 4; i++) + { + ret = fcntl(*((tcases + i)->fd), F_SETFD, FD_CLOEXEC); + assert_int_equal(ret, 0); + } + } + + if (file_fd > 0) + assert_int_equal(close(file_fd), 0); + if (pipe_fds[0] > 0) + assert_int_equal(close(pipe_fds[0]), 0); + if (pipe_fds[1] > 0) + assert_int_equal(close(pipe_fds[1]), 0); + if (fifo_fd > 0) + assert_int_equal(close(fifo_fd), 0); + + assert_int_equal(unlink(fname), 0); + assert_int_equal(unlink("/fcntl05_fifo"), 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_fcntl06 + ****************************************************************************/ + +void test_nuttx_syscall_fcntl06(FAR void **state) +{ + int fd; + int ret; + int lc; + char fname[256] = ""; + + sprintf(fname, "fcntl06_%d", gettid()); + + fd = open(fname, O_RDWR | O_CREAT); + assert_true(fd > 0); + + for (lc = 0; lc < 10; lc++) + { + ret = fcntl(fd, F_SETFL, O_NDELAY | O_APPEND | O_NONBLOCK); + assert_true(ret != -1); + } + + assert_int_equal(close(fd), 0); + assert_int_equal(unlink(fname), 0); +} diff --git a/testing/testsuites/kernel/syscall/cases/fpathconf_test.c b/testing/testsuites/kernel/syscall/cases/fpathconf_test.c new file mode 100644 index 000000000..03ea5b0a1 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/fpathconf_test.c @@ -0,0 +1,103 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/fpathconf_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 +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_fpathconf01 + ****************************************************************************/ + +void test_nuttx_syscall_fpathconf01(FAR void **state) +{ + int fd; + int i; + int ret; + char filename[64] = ""; + + struct pathconf_args + { + char name[16]; + int value; + } + + test_cases[] = + { + { + "_PC_MAX_CANON", _PC_MAX_CANON + }, + + { + "_PC_MAX_INPUT", _PC_MAX_INPUT + }, + + { + "_PC_LINK_MAX", _PC_LINK_MAX + }, + + { + "_PC_NAME_MAX", _PC_NAME_MAX + }, + + { + "_PC_PATH_MAX", _PC_PATH_MAX + }, + + { + "_PC_PIPE_BUF", _PC_PIPE_BUF + }, + }; + + /* setup */ + + sprintf(filename, "%s_file", __func__); + fd = open(filename, O_RDWR | O_CREAT, 0700); + assert_true(fd > 0); + + for (i = 0; i < 6; i++) + { + ret = fpathconf(fd, test_cases[i].value); + assert_int_not_equal(ret, -1); + } + + if (fd > 0) + { + assert_int_equal(close(fd), 0); + } + + assert_int_equal(unlink(filename), 0); +} diff --git a/testing/testsuites/kernel/syscall/cases/fsync_test.c b/testing/testsuites/kernel/syscall/cases/fsync_test.c new file mode 100644 index 000000000..1d8cf4fa2 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/fsync_test.c @@ -0,0 +1,253 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/fsync_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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_fsync01 + ****************************************************************************/ + +void test_nuttx_syscall_fsync01(FAR void **state) +{ + char fname[255]; + char buf[8] = "davef"; + int fd; + int ret; + ssize_t w_size; + + sprintf(fname, "Fsync01_%d", gettid()); + + /* creat a test file */ + + fd = open(fname, O_RDWR | O_CREAT, 0700); + assert_true(fd > 0); + + for (int i = 0; i < 10; i++) + { + /* write file */ + + w_size = write(fd, buf, sizeof(buf)); + assert_true(w_size != -1); + + /* do sync */ + + ret = fsync(fd); + assert_int_equal(ret, 0); + } + + assert_int_equal(close(fd), 0); + assert_int_equal(unlink(fname), 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_fsync02 + ****************************************************************************/ + +void test_nuttx_syscall_fsync02(FAR void **state) +{ + int fifo_rfd; + int fifo_wfd; + int pipe_fd[2]; +#ifndef CONFIG_FDSAN + int bad_fd = -1; +#endif + int ret; + int test_flag = 0; + + struct tcase + { + int *fd; + int error; + } + + tcases[] = + { + /* EINVAL - fsync() on pipe should not succeed. */ + + { + &pipe_fd[1], EINVAL + }, + + /* EBADF - fd is closed */ + + { + &pipe_fd[0], EBADF + }, + + /* EBADF - fd is invalid (-1) */ + + #ifndef CONFIG_FDSAN + { + &bad_fd, EBADF + }, + #endif + + /* EINVAL - fsync() on fifo should not succeed. */ + + { + &fifo_wfd, EINVAL + }, + }; + + ret = mkfifo("/var/Test_Fifo_SyscallFsync02", 0666); + assert_int_equal(ret, 0); + + ret = pipe(pipe_fd); + assert_int_not_equal(ret, -1); + + fifo_rfd = + open("/var/Test_Fifo_SyscallFsync02", O_RDONLY | O_NONBLOCK); + fifo_wfd = open("/var/Test_Fifo_SyscallFsync02", O_WRONLY); + + close(pipe_fd[0]); + + for (int i = 0; i < sizeof(tcases) / sizeof(tcases[0]); i++) + { + ret = fsync(*(tcases[i].fd)); + if (ret != -1) + { + syslog(LOG_ERR, "fsync() returned unexpected value %d", ret); + test_flag = -1; + } + else if (errno != tcases[i].error) + { + syslog(LOG_ERR, "fsync(): unexpected error. exp=%d errno=%d", + tcases[i].error, errno); + } + else + { + /* test PASS */ + + test_flag = 0; + } + } + + close(fifo_wfd); + close(fifo_rfd); + close(pipe_fd[1]); + unlink("/var/Test_Fifo_SyscallFsync02"); + + assert_int_equal(test_flag, 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_fsync03 + ****************************************************************************/ + +void test_nuttx_syscall_fsync03(FAR void **state) +{ + int fd; + int BLOCKSIZE = 8192; + unsigned long MAXBLKS = 65536; + int TIME_LIMIT = 120; + int BUF_SIZE = 2048; + char fname[255]; + struct statvfs stat_buf; + unsigned long f_bavail; + char pbuf[2048]; + + off_t max_blks = 65536; + + sprintf(fname, "Fsync03_%d", getpid()); + fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0777); + + if (fstatvfs(fd, &stat_buf) != 0) + { + syslog(LOG_ERR, "FAIL, fstatvfs failed\n"); + } + + f_bavail = (stat_buf.f_bavail * stat_buf.f_bsize) / BLOCKSIZE; + if (f_bavail && (f_bavail < MAXBLKS)) + { + max_blks = f_bavail; + } + + off_t offset; + int i; + int ret; + int max_block = 0; + int data_blocks = 0; + time_t time_start; + time_t time_end; + double time_delta; + long int random_number; + + random_number = rand(); + max_block = random_number % max_blks + 1; + data_blocks = random_number % max_block; + + for (i = 1; i <= data_blocks; i++) + { + offset = i * ((BLOCKSIZE * max_block) / data_blocks); + offset -= BUF_SIZE; + lseek(fd, offset, SEEK_SET); + write(fd, pbuf, BUF_SIZE); + } + + time_start = time(0); + + ret = fsync(fd); + + time_end = time(0); + assert_true(time_end != (time_t)-1); + assert_int_not_equal(ret, -1); + assert_int_equal(ret, 0); + assert_false(time_end < time_start); + assert_false((time_delta = difftime(time_end, time_start)) > + TIME_LIMIT); + + /* SAFE_FTRUNCATE(fd, 0); */ + + ret = ftruncate(fd, 0); + assert_int_equal(ret, 0); + + close(fd); + unlink(fname); +} diff --git a/testing/testsuites/kernel/syscall/cases/ftruncate_test.c b/testing/testsuites/kernel/syscall/cases/ftruncate_test.c new file mode 100644 index 000000000..a08799ebf --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/ftruncate_test.c @@ -0,0 +1,126 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/ftruncate_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 +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: checkandreportftruncatetest + ****************************************************************************/ + +static int checkandreportftruncatetest(int fd, off_t offset, char data, + off_t trunc_len) +{ + int i; + int file_length; + int ret; + char buf[1024]; + struct stat stat_buf; + off_t ret_offset; + ssize_t rval; + + memset(buf, '*', sizeof(buf)); + ret = fstat(fd, &stat_buf); + assert_int_equal(ret, 0); + file_length = stat_buf.st_size; + if (file_length != trunc_len) + { + syslog(LOG_ERR, "FAIL, ftruncate() got incorrected size: %d\n", + file_length); + return -1; + } + + ret_offset = lseek(fd, offset, SEEK_SET); + assert_int_in_range(ret_offset, 0, offset); + rval = read(fd, buf, sizeof(buf)); + assert_int_in_range(rval, 0, 1024); + + for (i = 0; i < 256; i++) + { + if (buf[i] != data) + { + syslog( + LOG_ERR, + "FAIL, ftruncate() got incorrect data %d, expected %d\n", + buf[i], data); + return -1; + } + } + + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_ftruncate01 + ****************************************************************************/ + +void test_nuttx_syscall_ftruncate01(FAR void **state) +{ + int fd; + int ret; + char fname[256] = ""; + + sprintf(fname, "Ftruncate01_%d", gettid()); + + assert_int_equal(cmtestfillfile(fname, 'a', 1024, 1), 0); + + fd = open(fname, O_RDWR); + + /* ftruncate to 256 */ + + ret = ftruncate(fd, 256); + assert_int_equal(ret, 0); + + ret = checkandreportftruncatetest(fd, 0, 'a', 256); + assert_int_equal(ret, 0); + + ret = ftruncate(fd, 512); + assert_int_equal(ret, 0); + + ret = checkandreportftruncatetest(fd, 256, 0, 512); + assert_int_equal(ret, 0); + + assert_int_equal(close(fd), 0); + assert_int_equal(unlink(fname), 0); +} diff --git a/testing/testsuites/kernel/syscall/cases/getTimeofday_test.c b/testing/testsuites/kernel/syscall/cases/getTimeofday_test.c new file mode 100644 index 000000000..992edeba0 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/getTimeofday_test.c @@ -0,0 +1,94 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/getTimeofday_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 +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static int done; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: breakout + ****************************************************************************/ + +static void breakout(int sig) +{ + done = sig; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_gettimeofday01 + ****************************************************************************/ + +void test_nuttx_syscall_gettimeofday01(FAR void **state) +{ + int rtime = 3; + struct timeval tv1; + struct timeval tv2; + unsigned long long cnt = 0; + + signal(SIGALRM, breakout); + + done = 0; + + alarm(rtime); + + if (gettimeofday(&tv1, NULL)) + fail_msg("FAIL, gettimeofday() failed\n"); + + while (!done) + { + if (gettimeofday(&tv2, NULL)) + fail_msg("FAIL, gettimeofday() failed\n"); + + if (tv2.tv_sec < tv1.tv_sec || + (tv2.tv_sec == tv1.tv_sec && tv2.tv_usec < tv1.tv_usec)) + { + fail_msg("test fail !"); + } + + sleep(1); + tv1 = tv2; + cnt++; + } +} diff --git a/testing/testsuites/kernel/syscall/cases/getcwd_test.c b/testing/testsuites/kernel/syscall/cases/getcwd_test.c new file mode 100644 index 000000000..49153b45e --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/getcwd_test.c @@ -0,0 +1,133 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/getcwd_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 +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_getcwd01 + ****************************************************************************/ + +void test_nuttx_syscall_getcwd01(FAR void **state) +{ + char buffer[5] = "/"; + char *res; + int ret; + struct t_case + { + char *buf; + size_t size; + int exp_err; + } + + tcases[] = + { + { + buffer, 0, EINVAL + }, + + { + buffer, 1, ERANGE + }, + + { + NULL, 1, ERANGE + }, + }; + + for (int i = 0; i < 3; i++) + { + errno = 0; + res = getcwd(tcases[i].buf, tcases[i].size); + assert_null(res); + ret = errno; + assert_int_equal(ret, tcases[i].exp_err); + } +} + +/**************************************************************************** + * Name: test_nuttx_syscall_getcwd02 + ****************************************************************************/ + +void test_nuttx_syscall_getcwd02(FAR void **state) +{ + char *datadir = MOUNT_DIR; + char exp_buf[PATH_MAX] = ""; + char buffer[PATH_MAX] = ""; + char *res = NULL; + + struct t_case + { + char *buf; + size_t size; + } + + tcases[] = + { + { + NULL, 0 + }, + + { + NULL, 0 + }, + + { + NULL, PATH_MAX + }, + }; + + tcases[0].buf = buffer; + tcases[0].size = sizeof(buffer); + + assert_int_equal(chdir(datadir), 0); + assert_non_null(realpath(datadir, exp_buf)); + + for (int i = 0; i < 3; i++) + { + errno = 0; + res = getcwd(tcases[i].buf, tcases[i].size); + + assert_non_null(res); + assert_string_equal(exp_buf, res); + + if (!tcases[i].buf) + free(res); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/getegid_test.c b/testing/testsuites/kernel/syscall/cases/getegid_test.c new file mode 100644 index 000000000..f8f1edb2f --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/getegid_test.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/getegid_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 +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_getegid01 + ****************************************************************************/ + +void test_nuttx_syscall_getegid01(FAR void **state) +{ + int ret; + for (int lc = 0; lc < 5; lc++) + { + ret = getegid(); + assert_int_not_equal(ret, -1); + } +} + +/**************************************************************************** + * Name: test_nuttx_syscall_getegid02 + ****************************************************************************/ + +void test_nuttx_syscall_getegid02(FAR void **state) +{ + int lc; + int ret; + uid_t euid; + struct passwd *pwent; + + for (lc = 0; lc < 5; lc++) + { + ret = getegid(); + euid = geteuid(); + pwent = getpwuid(euid); + assert_non_null(pwent); + assert_int_equal(pwent->pw_gid, ret); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/geteuid_test.c b/testing/testsuites/kernel/syscall/cases/geteuid_test.c new file mode 100644 index 000000000..4a561db34 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/geteuid_test.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/geteuid_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 +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_geteuid01 + ****************************************************************************/ + +void test_nuttx_syscall_geteuid01(FAR void **state) +{ + int ret; + for (int lc = 0; lc < 5; lc++) + { + ret = geteuid(); + assert_int_not_equal(ret, -1); + } +} + +/**************************************************************************** + * Name: test_nuttx_syscall_geteuid02 + ****************************************************************************/ + +void test_nuttx_syscall_geteuid02(FAR void **state) +{ + int lc; + int ret; + uid_t euid; + struct passwd *pwent; + + for (lc = 0; lc < 5; lc++) + { + ret = getegid(); + assert_true(ret > 0); + euid = geteuid(); + pwent = getpwuid(euid); + assert_non_null(pwent); + assert_int_equal(pwent->pw_gid, ret); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/getgid_test.c b/testing/testsuites/kernel/syscall/cases/getgid_test.c new file mode 100644 index 000000000..7fafa3854 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/getgid_test.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/getgid_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 +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_getgid01 + ****************************************************************************/ + +void test_nuttx_syscall_getgid01(FAR void **state) +{ + int lc; + int ret; + for (lc = 0; lc < 5; lc++) + { + ret = getgid(); + assert_int_not_equal(ret, -1); + } +} + +/**************************************************************************** + * Name: test_nuttx_syscall_getgid02 + ****************************************************************************/ + +void test_nuttx_syscall_getgid02(FAR void **state) +{ + int lc; + int ret; + uid_t uid; + struct passwd *pwent; + + for (lc = 0; lc < 5; lc++) + { + ret = getgid(); + uid = getuid(); + pwent = getpwuid(uid); + assert_non_null(pwent); + assert_int_equal(pwent->pw_gid, ret); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/gethostname_test.c b/testing/testsuites/kernel/syscall/cases/gethostname_test.c new file mode 100644 index 000000000..4b729c629 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/gethostname_test.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/gethostname_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 +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_gethostname01 + ****************************************************************************/ + +void test_nuttx_syscall_gethostname01(FAR void **state) +{ + int lc; + int ret; + char hname[100]; /* host name */ + + for (lc = 0; lc < 10; lc++) + { + ret = gethostname(hname, sizeof(hname)); + assert_int_equal(ret, 0); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/getitimer_test.c b/testing/testsuites/kernel/syscall/cases/getitimer_test.c new file mode 100644 index 000000000..1b43cbcfc --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/getitimer_test.c @@ -0,0 +1,139 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/getitimer_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 +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#define ITIMER_REAL 0 +#define ITIMER_VIRTUAL 1 +#define ITIMER_PROF 2 +#define CLOCK_MONOTONIC_COARSE 6 +#define SEC 100 +#define USEC 10000 +struct timeval tv; +struct itimerval value; +struct timespec time_res; +long jiffy; + +/**************************************************************************** + * Name: TestNuttxAccept01 + ****************************************************************************/ + +void set_settitimer_value(int sec, int usec) +{ + value.it_value.tv_sec = sec; + value.it_value.tv_usec = usec; + value.it_interval.tv_sec = sec; + value.it_interval.tv_usec = usec; +} + +void test_nuttx_syscall_veritygetitimer(int which, char *dec) +{ + if (which == ITIMER_REAL) + { + assert_int_not_equal(gettimeofday(&tv, NULL), -1); + } + + int ret = getitimer(which, &value); + assert_int_equal(ret, 0); + assert_int_equal(value.it_value.tv_sec, 0); + assert_int_equal(value.it_value.tv_usec, 0); + assert_int_equal(value.it_interval.tv_sec, 0); + assert_int_equal(value.it_interval.tv_usec, 0); + set_settitimer_value(SEC, USEC); + int ret2 = setitimer(which, &value, NULL); + assert_int_equal(ret2, 0); + set_settitimer_value(0, 0); + int ret3 = getitimer(which, &value); + assert_int_equal(ret3, 0); + + assert_int_equal(value.it_interval.tv_sec, SEC); + assert_int_equal(value.it_interval.tv_usec, USEC); + + /* syslog(LOG_INFO,"value.it_value.tv_sec=%lld, + * value.it_value.tv_usec=%ld", value.it_value.tv_sec, + * value.it_value.tv_usec); + */ + + long margin = (which == ITIMER_REAL) ? (2 * USEC_PER_TICK) : jiffy; + if (value.it_value.tv_sec == SEC) + { + assert_in_range(value.it_value.tv_usec, 0, USEC + margin); + } + + else + { + assert_in_range(value.it_value.tv_sec, 0, SEC); + } + + /* syslog(LOG_INFO,"timer value is within the expected range"); */ + + if (which == ITIMER_REAL) + { + assert_int_not_equal(gettimeofday(&tv, NULL), -1); + } + + set_settitimer_value(0, 0); + int ret4 = setitimer(which, &value, NULL); + assert_int_equal(ret4, 0); +} + +void test_nuttx_syscall_getitimer01(FAR void **state) +{ + struct tcase + { + int which; + char *des; + } + + tcases[] = + { + { + ITIMER_REAL, "ITIMER_REAL" + }, + + /* {ITIMER_VIRTUAL, "ITIMER_VIRTUAL"}, + * {ITIMER_PROF, "ITIMER_PROF"}, + */ + }; + + clock_getres(CLOCK_MONOTONIC_COARSE, &time_res); + jiffy = (time_res.tv_nsec + 999) / 1000; + + test_nuttx_syscall_veritygetitimer(tcases[0].which, tcases[0].des); +} diff --git a/testing/testsuites/kernel/syscall/cases/getpeername_test.c b/testing/testsuites/kernel/syscall/cases/getpeername_test.c new file mode 100644 index 000000000..be725e138 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/getpeername_test.c @@ -0,0 +1,197 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/getpeername_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 + ****************************************************************************/ +#ifndef UCLINUX +#define UCLINUX + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +__attribute__((unused)) static struct sockaddr_in server_addr; +__attribute__((unused)) static struct sockaddr_in fsin1; +__attribute__((unused)) static socklen_t sinlen; + +/* static socklen_t invalid_sinlen = -1; */ + +__attribute__((unused)) static void setup(void); +__attribute__((unused)) static void setup2(int); +__attribute__((unused)) static void setup3(int); + +/* static void setup4(int); */ + +__attribute__((unused)) static void cleanup2(int); + +/* static void cleanup4(int); */ + +__attribute__((unused)) static struct test_case_t +{ + int sockfd; + struct sockaddr *sockaddr; + socklen_t *addrlen; + int expretval; + int experrno; + void (*setup)(int); + void (*cleanup)(int); + char *name; +} + +test_cases[] = +{ + { + -1, (struct sockaddr *)&fsin1, &sinlen, -1, EBADF, NULL, NULL, + "EBADF" + }, + + { + -1, (struct sockaddr *)&fsin1, &sinlen, -1, ENOTSOCK, setup2, + cleanup2, "ENOTSOCK" + }, + + { + -1, (struct sockaddr *)&fsin1, &sinlen, -1, ENOTCONN, setup3, + cleanup2, "ENOTCONN" + }, + + /* { + * -1, (struct sockaddr *)&fsin1, &invalid_sinlen, -1, EINVAL, setup4, + * cleanup4, "EINVAL" + * }, + */ +#if 0 +#ifndef UCLINUX + { + -1, (struct sockaddr *)-1, &sinlen, -1, EFAULT, setup4, cleanup4, + "EFAULT" + }, + + { + -1, (struct sockaddr *)&fsin1, NULL, -1, EFAULT, setup4, + cleanup4, "EFAULT" + }, + + { + -1, (struct sockaddr *)&fsin1, (socklen_t *)1, -1, EFAULT, setup4, + cleanup4, "EFAULT" + }, +#endif +#endif +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_getpeername01 + ****************************************************************************/ + +void test_nuttx_syscall_getpeername01(FAR void **state) +{ +#ifdef CONFIG_NET_TCP + int total = sizeof(test_cases) / sizeof(test_cases[0]); + int ret; + setup(); + for (int i = 0; i < total; ++i) + { + if (test_cases[i].setup != NULL) + test_cases[i].setup(i); + + assert_false(test_cases[i].setup != NULL && + test_cases[i].sockfd <= 0); + ret = getpeername(test_cases[i].sockfd, test_cases[i].sockaddr, + test_cases[i].addrlen); + + assert_false(ret != test_cases[i].expretval || + errno != test_cases[i].experrno); + if (test_cases[i].cleanup != NULL) + test_cases[i].cleanup(i); + } +#endif +} + +__attribute__((unused)) static void setup(void) +{ + server_addr.sin_family = AF_INET; + server_addr.sin_port = 0; + server_addr.sin_addr.s_addr = INADDR_ANY; + sinlen = sizeof(fsin1); +} + +__attribute__((unused)) static void setup2(int i) +{ + int ret; + ret = open("/dev/null", O_WRONLY, 0666); + assert_true(ret >= 0); + test_cases[i].sockfd = ret; +} + +__attribute__((unused)) static void setup3(int i) +{ + test_cases[i].sockfd = socket(PF_INET, SOCK_STREAM, 0); + if (test_cases[i].sockfd < 0) + { + return; + } + + if (safe_bind(test_cases[i].sockfd, (struct sockaddr *)&server_addr, + sizeof(server_addr)) < 0) + { + fail_msg("test fail !"); + } +} + +/* static void setup4(int i) + * { + * if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) < 0) + * { + * syslog(LOG_ERR, "socketpair failed for getpeername test %d", + * i); faiL_msg("test fail !"); return; + * } + * test_cases[i].sockfd = sv[0]; + * } + */ + +__attribute__((unused)) static void cleanup2(int i) +{ + if (safe_close(test_cases[i].sockfd) < 0) + { + fail_msg("test fail !"); + } +} + +#undef UCLINUX +#endif diff --git a/testing/testsuites/kernel/syscall/cases/getpid_test.c b/testing/testsuites/kernel/syscall/cases/getpid_test.c new file mode 100644 index 000000000..3dc5915c1 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/getpid_test.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/getpid_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 +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_getpid01 + ****************************************************************************/ + +void test_nuttx_syscall_getpid01(FAR void **state) +{ + int lc; + int ret; + + for (lc = 0; lc < 5; lc++) + { + ret = getpid(); + assert_true(ret > 0); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/getppid_test.c b/testing/testsuites/kernel/syscall/cases/getppid_test.c new file mode 100644 index 000000000..1f8a91cda --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/getppid_test.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/getppid_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 +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_getppid01 + ****************************************************************************/ + +void test_nuttx_syscall_getppid01(FAR void **state) +{ + int lc; + int ret; + + for (lc = 0; lc < 5; lc++) + { + ret = getppid(); + assert_true(ret > 0); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/getsocketopt_test.c b/testing/testsuites/kernel/syscall/cases/getsocketopt_test.c new file mode 100644 index 000000000..4674e61d3 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/getsocketopt_test.c @@ -0,0 +1,214 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/getsocketopt_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 + ****************************************************************************/ + +#ifndef UCLINUX +#define UCLINUX +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +__attribute__((unused)) static int testno; +__attribute__((unused)) static int s; /* socket descriptor */ +__attribute__((unused)) static struct sockaddr_in sin0, fsin1; +__attribute__((unused)) static int sinlen; +__attribute__((unused)) static int optval; +__attribute__((unused)) static socklen_t optlen; + +__attribute__((unused)) static void setup(void); +__attribute__((unused)) static void setup0(void); +__attribute__((unused)) static void setup1(void); +__attribute__((unused)) static void cleanup0(void); +__attribute__((unused)) static void cleanup1(void); + +__attribute__((unused)) static struct test_case_t +{ + int domain; /* PF_INET, PF_UNIX, ... */ + int type; /* SOCK_STREAM, SOCK_DGRAM ... */ + int proto; /* protocol number (usually 0 = default) */ + int level; /* IPPROTO_* */ + int optname; + void *optval; + socklen_t *optlen; + struct sockaddr *sin; + int salen; + int retval; /* syscall return value */ + int experrno; /* expected errno */ + void (*setup)(void); + void (*cleanup)(void); + char *desc; +} + +tdat[] = +{ + { + PF_INET, SOCK_STREAM, 0, SOL_SOCKET, SO_OOBINLINE, &optval, &optlen, + (struct sockaddr *)&fsin1, sizeof(fsin1), -1, EBADF, setup0, + cleanup0, "bad file descriptor" + }, + + { + PF_INET, SOCK_STREAM, 0, SOL_SOCKET, SO_OOBINLINE, &optval, &optlen, + (struct sockaddr *)&fsin1, sizeof(fsin1), -1, ENOTSOCK, setup0, + cleanup0, "bad file descriptor" + }, +#ifndef UCLINUX + { + PF_INET, SOCK_STREAM, 0, SOL_SOCKET, SO_OOBINLINE, 0, &optlen, + (struct sockaddr *)&fsin1, sizeof(fsin1), -1, EFAULT, setup1, + cleanup1, "invalid option buffer" + }, + + { + PF_INET, SOCK_STREAM, 0, SOL_SOCKET, SO_OOBINLINE, &optval, 0, + (struct sockaddr *)&fsin1, sizeof(fsin1), -1, EFAULT, setup1, + cleanup1, "invalid optlen" + }, +#endif /* UCLINUX */ + /* {PF_INET, SOCK_STREAM, 0, 500, SO_OOBINLINE, &optval, &optlen, + * (struct sockaddr *)&fsin1, sizeof(fsin1), -1, + * EOPNOTSUPP, setup1, cleanup1, "invalid level"}, + * {PF_INET, SOCK_STREAM, 0, IPPROTO_UDP, SO_OOBINLINE, &optval, + * &optlen, (struct sockaddr *)&fsin1, sizeof(fsin1), + * -1, EOPNOTSUPP, setup1, cleanup1, "invalid option name"}, + * {PF_INET, SOCK_STREAM, 0, IPPROTO_UDP, SO_OOBINLINE, &optval, + * &optlen, (struct sockaddr *)&fsin1, sizeof(fsin1), + * -1, EOPNOTSUPP, setup1, cleanup1, + * "invalid option name (UDP)"}, + */ + + { + PF_INET, SOCK_STREAM, 0, IPPROTO_IP, -1, &optval, &optlen, + (struct sockaddr *)&fsin1, sizeof(fsin1), -1, ENOPROTOOPT, setup1, + cleanup1, "invalid option name (IP)" + }, + + { + PF_INET, SOCK_STREAM, 0, IPPROTO_TCP, -1, &optval, &optlen, + (struct sockaddr *)&fsin1, sizeof(fsin1), -1, ENOPROTOOPT, setup1, + cleanup1, "invalid option name (TCP)" + }, +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_getsockopt01 + ****************************************************************************/ + +void test_nuttx_syscall_getsockopt01(FAR void **state) +{ +#if defined(CONFIG_NET) && defined(CONFIG_NET_SOCKOPTS) + int ret; + int flag = 1; + setup(); + for (testno = 0; testno < sizeof(tdat) / sizeof(tdat[0]); ++testno) + { + tdat[testno].setup(); + if (s < 0) + continue; + ret = getsockopt(s, tdat[testno].level, tdat[testno].optname, + tdat[testno].optval, tdat[testno].optlen); + if (ret != tdat[testno].retval || errno != tdat[testno].experrno) + { + syslog(LOG_ERR, + "%s ; returned" + " %d (expected %d), errno %d (expected" + " %d)\n", + tdat[testno].desc, ret, tdat[testno].retval, errno, + tdat[testno].experrno); + flag = 0; + } + + tdat[testno].cleanup(); + } + + assert_true(flag); +#endif +} + +__attribute__((unused)) static void setup(void) +{ + /* initialize local sockaddr */ + + sin0.sin_family = AF_INET; + sin0.sin_port = 0; + sin0.sin_addr.s_addr = INADDR_ANY; +} + +__attribute__((unused)) static void setup0(void) +{ + if (tdat[testno].experrno == EBADF) + s = -400; /* anything not an open file */ + else if ((s = open("/dev/null", O_WRONLY)) == -1) + { + syslog(LOG_ERR, + "error opening /dev/null - " + "errno: %s", + strerror(errno)); + fail_msg("test fail !"); + } +} + +__attribute__((unused)) static void cleanup0(void) +{ + if (tdat[testno].experrno != EBADF && s > 0) + (void)close(s); + s = -1; +} + +__attribute__((unused)) static void setup1(void) +{ + s = safe_socket(tdat[testno].domain, tdat[testno].type, + tdat[testno].proto); + if (s < 0) + fail_msg("setup1 fail"); + int ret = safe_bind(s, (struct sockaddr *)&sin0, sizeof(sin0)); + assert_int_not_equal(ret, -1); + sinlen = sizeof(fsin1); + optlen = sizeof(optval); +} + +__attribute__((unused)) static void cleanup1(void) +{ + (void)close(s); + s = -1; +} + +#undef UCLINUX +#endif diff --git a/testing/testsuites/kernel/syscall/cases/getuid_test.c b/testing/testsuites/kernel/syscall/cases/getuid_test.c new file mode 100644 index 000000000..c2ffc1921 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/getuid_test.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/getuid_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 +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_getuid01 + ****************************************************************************/ + +void test_nuttx_syscall_getuid01(FAR void **state) +{ + int ret; + for (int lc = 0; lc < 5; lc++) + { + ret = getuid(); + assert_int_not_equal(ret, -1); + } +} + +/**************************************************************************** + * Name: test_nuttx_syscall_getuid02 + ****************************************************************************/ + +void test_nuttx_syscall_getuid02(FAR void **state) +{ + int lc; + int ret; + uid_t uid; + struct passwd *pwent; + + for (lc = 0; lc < 5; lc++) + { + ret = getuid(); + assert_true(ret > 0); + uid = getuid(); + pwent = getpwuid(uid); + assert_non_null(pwent); + assert_int_equal(pwent->pw_uid, ret); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/listen_test.c b/testing/testsuites/kernel/syscall/cases/listen_test.c new file mode 100644 index 000000000..a533b523a --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/listen_test.c @@ -0,0 +1,145 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/listen_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 +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_listen01 + ****************************************************************************/ + +void test_nuttx_syscall_listen01(FAR void **state) +{ +#ifdef CONFIG_NET_TCP + int testno; + int flag = 1; + int s; /* socket descriptor */ + struct test_case_t + { /* test case structure */ + int domain; /* PF_INET, PF_UNIX, ... */ + int type; /* SOCK_STREAM, SOCK_DGRAM ... */ + int proto; /* protocol number (usually 0 = default) */ + int backlog; /* connect's 3rd argument */ + int retval; /* syscall return value */ + int experrno; /* expected errno */ + const char setup[10]; + const char cleanup[10]; + char desc[20]; + } + + tdat[] = + { + { + 0, 0, 0, 0, -1, EBADF, "setup0", "cleanup0", + "bad file descriptor" + }, + + { + 0, 0, 0, 0, -1, ENOTSOCK, "setup0", "cleanup0", "not a socket" + }, + + { + PF_INET, SOCK_DGRAM, 0, 0, -1, EOPNOTSUPP, "setup1", "cleanup1", + "UDP listen" + }, + }; + + const char set[] = "setup0"; + const char clean[] = "cleanup0"; + + for (testno = 0; testno < sizeof(tdat) / sizeof(tdat[0]); ++testno) + { + /* setup0(void) */ + + if (!strcmp(tdat[testno].setup, set)) + { + if (tdat[testno].experrno == EBADF) + s = -400; /* anything not an open file */ + else if ((s = open("/dev/null", O_WRONLY)) == -1) + syslog(LOG_ERR, "error opening /dev/null - errno: %s\n", + strerror(errno)); + } + + else + { + /* setup1(void) */ + + s = safe_socket(tdat[testno].domain, tdat[testno].type, + tdat[testno].proto); + } + + int rec = safe_listen(s, tdat[testno].backlog); + + if (rec != tdat[testno].retval || + (rec < 0 && errno != tdat[testno].experrno)) + { + syslog(LOG_ERR, + "%s ; returned" + " %d (expected %d), errno %d (expected" + " %d)\n", + tdat[testno].desc, rec, tdat[testno].retval, errno, + tdat[testno].experrno); + flag = 0; + } + + else + { + syslog(LOG_INFO, "%s successful\n", tdat[testno].desc); + } + + if (!strcmp(tdat[testno].cleanup, clean)) + { + /* cleanup0(void) */ + + s = -1; + } + + else + { + /* cleanup1(void) */ + + (void)close(s); + s = -1; + } + } + + assert_true(flag); +#endif +} diff --git a/testing/testsuites/kernel/syscall/cases/lseek_test.c b/testing/testsuites/kernel/syscall/cases/lseek_test.c new file mode 100644 index 000000000..5116d7126 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/lseek_test.c @@ -0,0 +1,230 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/lseek_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 +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_lseek01 + ****************************************************************************/ + +void test_nuttx_syscall_lseek01(FAR void **state) +{ + int fd; + char filename[32] = + { + 0 + }; + + ssize_t rval; + char read_buf[64] = + { + 0 + }; + + off_t test_ret; + struct tcase + { + off_t off; + int whence; + char wname[64]; + 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 + }, + }; + + snprintf(filename, sizeof(filename), "%s_file", __func__); + + fd = open(filename, O_RDWR | O_CREAT); + + if (fd > 0) + { + rval = write(fd, "abcdefg", 7); + assert_int_in_range(rval, 0, 7); + } + + else + { + fail_msg("creat test file fail !\n"); + } + + for (int i = 0; i < 4; i++) + { + /* reset the offset to end of file */ + + rval = read(fd, read_buf, sizeof(read_buf)); + assert_int_in_range(rval, 0, 64); + memset(read_buf, 0, sizeof(read_buf)); + test_ret = lseek(fd, tcases[i].off, tcases[i].whence); + if (test_ret == (off_t)-1) + { + syslog(LOG_ERR, "lseek() failed"); + fail_msg("test fail !\n"); + } + + if (test_ret != tcases[i].exp_off) + { + syslog(LOG_ERR, "lseek() returned not expected\n"); + fail_msg("test fail !\n"); + } + + rval = read(fd, read_buf, tcases[i].exp_size); + assert_int_in_range(rval, 0, 64); + + if (tcases[i].exp_data && strcmp(read_buf, tcases[i].exp_data)) + { + syslog(LOG_ERR, "lseek() read incorrect data\n"); + fail_msg("test fail !\n"); + } + } + + if (fd > 0) + { + close(fd); + } + + unlink(filename); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_lseek07 + ****************************************************************************/ + +void test_nuttx_syscall_lseek07(FAR void **state) +{ + int fd1; + int fd2; + int flag = 1; + int ret; + char read_buf[64] = + { + 0 + }; + + struct tcase + { + int *fd; + char fname[32]; + off_t off; + off_t exp_off; + int exp_size; + char exp_data[16]; + } + + tcases[] = + { + { + NULL, "", 7, 7, 10, "abcdefgijk" + }, + + { + NULL, "", 2, 2, 7, "abijkfg" + }, + }; + + tcases[0].fd = &fd1; + tcases[1].fd = &fd2; + snprintf(tcases[0].fname, sizeof(tcases[0].fname), "%s_file", + __func__); + snprintf(tcases[1].fname, sizeof(tcases[1].fname), "%s_file", + __func__); + + fd1 = open(tcases[0].fname, O_RDWR | O_CREAT, 0644); + fd2 = open(tcases[1].fname, O_RDWR | O_CREAT, 0644); + + write(fd1, "abcdefg", sizeof("abcdefg") - 1); + write(fd2, "abcdefg", sizeof("abcdefg") - 1); + + for (int i = 0; i < 2; i++) + { + memset(read_buf, 0, sizeof(read_buf)); + + ret = lseek(*(tcases[i].fd), tcases[i].off, SEEK_SET); + if (ret == (off_t)-1) + flag = 0; + + if (ret != tcases[i].exp_off) + flag = 0; + + write(*(tcases[i].fd), "ijk", sizeof("ijk") - 1); + + close(*(tcases[i].fd)); + + *(tcases[i].fd) = open(tcases[i].fname, O_RDWR); + + read(*(tcases[i].fd), read_buf, tcases[i].exp_size); + + if (strcmp(read_buf, tcases[i].exp_data)) + { + flag = 0; + syslog(LOG_ERR, "FAIL, lseek() wrote incorrect data\n"); + } + } + + if (fd1 > 0) + close(fd1); + + if (fd2 > 0) + close(fd2); + unlink(tcases[0].fname); + unlink(tcases[1].fname); + assert_true(flag); +} diff --git a/testing/testsuites/kernel/syscall/cases/lstat_test.c b/testing/testsuites/kernel/syscall/cases/lstat_test.c new file mode 100644 index 000000000..af25f6a06 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/lstat_test.c @@ -0,0 +1,80 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/lstat_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 +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_lstat01 + ****************************************************************************/ + +void test_nuttx_syscall_lstat01(FAR void **state) +{ + uid_t user_id; + gid_t group_id; + struct stat stat_buf; + int ret; + + char filename[64] = ""; + char symlink_path[64] = "/Lstat01_tst_syml"; + + sprintf(filename, "%s_file", __func__); + user_id = getuid(); + group_id = getgid(); + + ret = open(filename, O_CREAT | O_WRONLY, 0644); + assert_true(ret > 0); + + ret = close(ret); + assert_int_equal(ret, 0); + + ret = symlink(filename, symlink_path); + assert_int_equal(ret, 0); + + memset(&stat_buf, 0, sizeof(stat_buf)); + + ret = lstat(symlink_path, &stat_buf); + assert_int_equal(ret, 0); + + assert_true(stat_buf.st_gid == group_id); + assert_true(stat_buf.st_uid == user_id); + assert_true((stat_buf.st_mode & S_IFMT) == S_IFLNK); + assert_int_equal(unlink(symlink_path), 0); + assert_int_equal(unlink(filename), 0); +} diff --git a/testing/testsuites/kernel/syscall/cases/memcmp_test.c b/testing/testsuites/kernel/syscall/cases/memcmp_test.c new file mode 100644 index 000000000..65394738b --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/memcmp_test.c @@ -0,0 +1,130 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/memcmp_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 +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +#define BSIZE 4096 +#define LEN 100 + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: TestNuttxSyscallFill + ****************************************************************************/ + +static void test_nuttx_syscall_lfill(char *str, int len) +{ + int i; + for (i = 0; i < len; i++) + *str++ = 'a'; +} + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_setup + ****************************************************************************/ + +static void test_nuttx_syscall_setup(char *buf) +{ + int i; + for (i = 0; i < BSIZE; i++) + buf[i] = 0; + return; +} + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_verifymemcmp + ****************************************************************************/ + +static void test_nuttx_syscall_verifymemcmp(char *p, char *q, int len) +{ + test_nuttx_syscall_lfill(p, len); + test_nuttx_syscall_lfill(q, len); + + assert_int_equal(memcmp(p, q, len), 0); + + p[len - 1] = 0; + assert_true(memcmp(p, q, len) < 0); + + p[len - 1] = 'a'; + p[0] = 0; + assert_true(memcmp(p, q, len) < 0); + + p[0] = 'a'; + q[len - 1] = 0; + assert_true(memcmp(p, q, len) > 0); + + q[len - 1] = 'a'; + q[0] = 0; + assert_true(memcmp(p, q, len) > 0); + + q[0] = 'a'; + assert_int_equal(memcmp(p, q, len), 0); +} + +/**************************************************************************** + * Pubilc Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_memcmptest01 + ****************************************************************************/ + +void test_nuttx_syscall_memcmptest01(FAR void **state) +{ + char *buf = NULL; + buf = malloc(BSIZE); + assert_non_null(buf); + test_nuttx_syscall_setup(buf); + + test_nuttx_syscall_verifymemcmp(&buf[100], &buf[800], LEN); + test_nuttx_syscall_verifymemcmp(&buf[800], &buf[100], LEN); + + free(buf); +} diff --git a/testing/testsuites/kernel/syscall/cases/memcpy_test.c b/testing/testsuites/kernel/syscall/cases/memcpy_test.c new file mode 100644 index 000000000..0628b4a0e --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/memcpy_test.c @@ -0,0 +1,135 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/memcpy_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 +#include +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +#define BSIZE 4096 +#define LEN 100 + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_fill + ****************************************************************************/ + +static void test_nuttx_syscall_fill(char *str, int len) +{ + int i; + for (i = 0; i < len; i++) + *str++ = 'a'; +} + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_check + ****************************************************************************/ + +static int test_nuttx_syscall_check(char *str, int len) +{ + int i; + for (i = 0; i < len; i++) + if (*str++ != 'a') + return (-1); + + return 0; +} + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_setup + ****************************************************************************/ + +static void test_nuttx_syscall_setup(char *buf) +{ + int i; + for (i = 0; i < BSIZE; i++) + buf[i] = 0; +} + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_verifymemcpy + ****************************************************************************/ + +static void test_nuttx_syscall_verifymemcpy(char *p, char *q, int len) +{ + test_nuttx_syscall_fill(p, len); + memcpy(q, p, LEN); + + assert_int_equal(test_nuttx_syscall_check(q, len), 0); + + assert_true(*(p - 1) == '\0'); + assert_true(p[LEN] == '\0'); + + assert_true(*(q - 1) == '\0'); + assert_true(q[LEN] == '\0'); +} + +/**************************************************************************** + * Pubilc Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_memcpytest01 + ****************************************************************************/ + +void test_nuttx_syscall_memcpytest01(FAR void **state) +{ + char *buf = NULL; + buf = malloc(BSIZE); + assert_non_null(buf); + test_nuttx_syscall_setup(buf); + + test_nuttx_syscall_verifymemcpy(&buf[100], &buf[800], LEN); + test_nuttx_syscall_verifymemcpy(&buf[800], &buf[100], LEN); + free(buf); +} diff --git a/testing/testsuites/kernel/syscall/cases/memset_test.c b/testing/testsuites/kernel/syscall/cases/memset_test.c new file mode 100644 index 000000000..9ec1bbf40 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/memset_test.c @@ -0,0 +1,108 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/memset_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 +#include +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +#define BSIZE 4096 + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_fill + ****************************************************************************/ + +static void test_nuttx_syscall_fill(char *buf) +{ + int i; + for (i = 0; i < BSIZE; i++) + buf[i] = 'a'; +} + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_check + ****************************************************************************/ + +static int test_nuttx_syscall_check(char *str) +{ + int i = 0; + while (!*str++) + i++; + return i; +} + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_memsettest01 + ****************************************************************************/ + +void test_nuttx_syscall_memsettest01(FAR void **state) +{ + char *buf = NULL; + buf = malloc(BSIZE); + assert_non_null(buf); + test_nuttx_syscall_fill(buf); + + int i; + int j; + char *p = &buf[400]; + + for (i = 0; i < 200; i++) + { + test_nuttx_syscall_fill(buf); + memset(p, 0, i); + j = test_nuttx_syscall_check(p); + + assert_true(j == i); + assert_true(*(p - 1) && p[i]); + } + + assert_int_equal(i, 200); + free(buf); +} diff --git a/testing/testsuites/kernel/syscall/cases/mkdir_test.c b/testing/testsuites/kernel/syscall/cases/mkdir_test.c new file mode 100644 index 000000000..c908e69a1 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/mkdir_test.c @@ -0,0 +1,198 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/mkdir_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 +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_mkdir01 + ****************************************************************************/ + +void test_nuttx_syscall_mkdir01(FAR void **state) +{ + int ret; + int j; + int times = 100; + char tmpdir[40]; + + for (j = 0; j < 5; j += 3) + { + sprintf(tmpdir, "%s_%d_dir", __func__, j); + ret = mkdir(tmpdir, 0777); + if (ret < 0) + { + if (errno != EEXIST) + { + syslog(LOG_ERR, + "Error creating permanent directories, ERRNO = %d", + errno); + fail_msg("test fail !\n"); + goto out; + } + } + } + + while (times--) + { + for (j = 0; j < 5; j += 3) + { + sprintf(tmpdir, "%s_%d_dir", __func__, j); + ret = mkdir(tmpdir, 0777); + if (ret < 0) + { + if (errno != EEXIST) + { + syslog(LOG_ERR, + "MKDIR %s, errno = %d; Wrong error detected.", + tmpdir, errno); + fail_msg("test fail !\n"); + goto out; + } + } + else + { + syslog(LOG_ERR, + "MKDIR %s succeded when it shoud have failed.", + tmpdir); + fail_msg("test fail !\n"); + goto out; + } + } + } + +out: + for (j = 0; j < 5; j += 3) + { + sprintf(tmpdir, "%s_%d_dir", __func__, j); + assert_int_equal(rmdir(tmpdir), 0); + } +} + +/**************************************************************************** + * Name: test_nuttx_syscall_mkdir02 + ****************************************************************************/ + +void test_nuttx_syscall_mkdir02(FAR void **state) +{ + int ret; + int j; + int times = 1000; + char tmpdir[40]; + + while (times--) + { + for (j = 1; j < 5; j += 3) + { + sprintf(tmpdir, "%s_%d_dir", __func__, j); + ret = rmdir(tmpdir); + if (ret < 0) + { + if (errno != ENOENT) + { + syslog(LOG_ERR, + "RMDIR %s, errno = %d; Wrong error detected.", + tmpdir, errno); + fail_msg("test fail !\n"); + } + } + + else + { + syslog(LOG_ERR, + "RMDIR %s succeded when it should have failed.", + tmpdir); + fail_msg("test fail !\n"); + } + } + } +} + +/**************************************************************************** + * Name: test_nuttx_syscall_mkdir03 + ****************************************************************************/ + +void test_nuttx_syscall_mkdir03(FAR void **state) +{ + int ret; + int j; + int times = 1000; + char tmpdir[40]; + + while (times--) + { + for (j = 2; j < 5; j += 3) + { + sprintf(tmpdir, "%s_%d_dir", __func__, j); + ret = mkdir(tmpdir, 0777); + if (ret < 0) + { + syslog(LOG_ERR, + "MKDIR %s, errno = %d; Wrong error detected.", + tmpdir, errno); + goto out; + } + } + + for (j = 2; j < 5; j += 3) + { + sprintf(tmpdir, "%s_%d_dir", __func__, j); + ret = rmdir(tmpdir); + if (ret < 0) + { + syslog(LOG_ERR, + "RMDIR %s, errno = %d; Wrong error detected.", + tmpdir, errno); + goto out; + } + } + } + + goto testpass; + +out: + for (j = 2; j < 5; j += 3) + { + sprintf(tmpdir, "%s/test%d", __func__, j); + rmdir(tmpdir); + } + + assert_true(0); +testpass: + assert_true(1); +} diff --git a/testing/testsuites/kernel/syscall/cases/nansleep_test.c b/testing/testsuites/kernel/syscall/cases/nansleep_test.c new file mode 100644 index 000000000..44c23403b --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/nansleep_test.c @@ -0,0 +1,91 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/nansleep_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 +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_nansleep01 + ****************************************************************************/ + +void test_nuttx_syscall_nansleep01(FAR void **state) +{ + time_t ret; + struct timespec t = + { + .tv_sec = 2, .tv_nsec = 9999 + }; + + ret = nanosleep(&t, NULL); + assert_int_equal(ret, 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_nansleep02 + ****************************************************************************/ + +void test_nuttx_syscall_nansleep02(FAR void **state) +{ + int ret; + struct timespec tcases[] = + { + {.tv_sec = 0, .tv_nsec = (long)1000000000}, + {.tv_sec = 1, .tv_nsec = (long)-100}, + }; + + int n = 0; + for (n = 0; n < 2; n++) + { + ret = nanosleep(&tcases[n], NULL); + if (ret != -1) + { + syslog(LOG_ERR, + "test no.%d, FAIL, nanosleep() returned %d, expected " + "-1\n", + n + 1, ret); + fail_msg("test fail !\n"); + } + + if (errno != EINVAL) + { + syslog(LOG_ERR, + "test no.%d, FAIL, nanosleep() failed,expected " + "EINVAL, got\n", + n + 1); + fail_msg("test fail !\n"); + } + } +} diff --git a/testing/testsuites/kernel/syscall/cases/pathconf_test.c b/testing/testsuites/kernel/syscall/cases/pathconf_test.c new file mode 100644 index 000000000..3daa08967 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/pathconf_test.c @@ -0,0 +1,86 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/pathconf_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 +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_pathconf01 + ****************************************************************************/ + +void test_nuttx_syscall_pathconf01(FAR void **state) +{ + long ret; + char *path; + + struct pathconf_args + { + char define_tag[16]; + int value; + } + + args[] = + { + { + "_PC_LINK_MAX", _PC_LINK_MAX + }, + + { + "_PC_NAME_MAX", _PC_NAME_MAX + }, + + { + "_PC_PATH_MAX", _PC_PATH_MAX + }, + + { + "_PC_PIPE_BUF", _PC_PIPE_BUF + }, + }; + + path = strdup(MOUNT_DIR); + assert_non_null(path); + + for (int i = 0; i < 4; i++) + { + ret = pathconf(path, args[i].value); + assert_int_not_equal(ret, -1); + } + + free(path); +} diff --git a/testing/testsuites/kernel/syscall/cases/pipe_test.c b/testing/testsuites/kernel/syscall/cases/pipe_test.c new file mode 100644 index 000000000..0edacef0b --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/pipe_test.c @@ -0,0 +1,98 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/pipe_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 +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_pipe01 + ****************************************************************************/ + +void test_nuttx_syscall_pipe01(FAR void **state) +{ + int fds[2]; + int ret; + int rd_size; + int wr_size; + char wrbuf[64] = "abcdefghijklmnopqrstuvwxyz"; + char rdbuf[128]; + + memset(rdbuf, 0, sizeof(rdbuf)); + + ret = pipe(fds); + assert_int_not_equal(ret, -1); + + /* write fds[1] */ + + wr_size = write(fds[1], wrbuf, sizeof(wrbuf)); + + /* read fds[0] */ + + rd_size = read(fds[0], rdbuf, sizeof(rdbuf)); + + assert_int_equal(rd_size, wr_size); + assert_int_equal(strncmp(rdbuf, wrbuf, wr_size), 0); + + assert_int_equal(close(fds[0]), 0); + assert_int_equal(close(fds[1]), 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_pipe02 + ****************************************************************************/ + +void test_nuttx_syscall_pipe02(FAR void **state) +{ + int fd[2]; + int ret; + char buf[2]; + + ret = pipe(fd); + assert_int_not_equal(ret, -1); + + ret = write(fd[0], "A", 1); + assert_int_equal(ret, -1); + assert_int_equal(errno, EACCES); + + ret = read(fd[1], buf, 1); + assert_int_equal(ret, -1); + assert_int_equal(errno, EACCES); + + assert_int_equal(close(fd[0]), 0); + assert_int_equal(close(fd[1]), 0); +} diff --git a/testing/testsuites/kernel/syscall/cases/pread_test.c b/testing/testsuites/kernel/syscall/cases/pread_test.c new file mode 100644 index 000000000..dfa9bcd6f --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/pread_test.c @@ -0,0 +1,377 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/pread_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 +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define K1 32 +#define K2 (K1 * 2) +#define K3 (K1 * 3) +#define K4 (K1 * 4) +#define K5 (K1 * 5) + +/**************************************************************************** + * Private data Prototypes + ****************************************************************************/ + +char pread01_filename[64] = ""; +int pread01_fildes; /* file descriptor for tempfile */ +char *pread01_write_buf[4]; /* buffer to hold data to be written */ +char *pread01_read_buf[4]; /* buffer to hold data read from file */ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +void pread01_setup(void); /* Main setup function of test */ +void pread01_cleanup(void); /* cleanup function for the test */ +void pread01_l_seek(int, off_t, int, + off_t); /* function to call lseek() */ +void pread01_init_buffers( + void); /* function to initialize/allocate buffers */ +int pread01_compare_bufers( + void); /* function to compare o/p of pread/pwrite */ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pread01_init_buffers + ****************************************************************************/ + +/* init_buffers - allocates both write_buf and read_buf arrays. + * Allocate the read and write buffers. + * Fill the write buffer with the following data like, + * write_buf[0] has 0's, write_buf[1] has 1's, write_buf[2] has 2's + * write_buf[3] has 3's. + */ + +void pread01_init_buffers(void) +{ + int count; /* counter variable for loop */ + + /* Allocate and Initialize read/write buffer */ + + for (count = 0; count < 4; count++) + { + pread01_write_buf[count] = (char *)malloc(K1); + pread01_read_buf[count] = (char *)malloc(K1); + + if ((pread01_write_buf[count] == NULL) || + (pread01_read_buf[count] == NULL)) + { + syslog(LOG_ERR, "malloc() failed on read/write buffers\n"); + } + + memset(pread01_write_buf[count], count, K1); + } +} + +/**************************************************************************** + * Name: pread01_setup + ****************************************************************************/ + +/* setup() - performs all ONE TIME setup for this test. + * + * Initialize/allocate read/write buffers. + * Create a temporary directory and a file under it and + * write know data at different offset positions. + */ + +void pread01_setup(void) +{ + int nwrite = 0; /* no. of bytes written by pwrite() */ + + /* Allocate/Initialize the read/write buffer with know data */ + + pread01_init_buffers(); + + sprintf(pread01_filename, "%s_tstfile", __func__); + + /* Creat a temporary file used for mapping */ + + if ((pread01_fildes = open(pread01_filename, O_RDWR | O_CREAT, 0666)) < + 0) + { + syslog(LOG_ERR, "FAIL, open() on %s failed, errno=%d : %s\n", + pread01_filename, errno, strerror(errno)); + } + + if (pread01_fildes > 0) + { + /* pwrite() K1 of data (0's) at offset 0 of temporary file */ + + if ((nwrite = pwrite(pread01_fildes, pread01_write_buf[0], K1, + 0)) != K1) + { + syslog(LOG_ERR, + "pwrite() failed to write on %s, " + "errno=%d : %s\n", + pread01_filename, errno, strerror(errno)); + } + + /* We should still be at offset 0. */ + + pread01_l_seek(pread01_fildes, 0, SEEK_CUR, 0); + + /* Now, lseek() to a non K boundary, just to be different. */ + + pread01_l_seek(pread01_fildes, K1 / 2, SEEK_SET, K1 / 2); + + /* Again, pwrite() K1 of data (2's) at offset K2 of temporary file + */ + + if ((nwrite = pwrite(pread01_fildes, pread01_write_buf[2], K1, + K2)) != K1) + { + syslog(LOG_ERR, + "FAIL, pwrite() failed to write at %d off. " + "on %s, errno=%d : %s\n", + K2, pread01_filename, errno, strerror(errno)); + } + + /* We should still be at our non K boundary. */ + + pread01_l_seek(pread01_fildes, 0, SEEK_CUR, K1 / 2); + + /* lseek() to an offset of K3. */ + + pread01_l_seek(pread01_fildes, K3, SEEK_SET, K3); + + /* Using write(), write of K1 of data (3's) which should take + * place at an offset of K3, moving the file pointer to K4. + */ + + if ((nwrite = write(pread01_fildes, pread01_write_buf[3], K1)) != + K1) + { + syslog(LOG_ERR, + "write() failed: nwrite=%d, errno=%d " + ": %s\n", + nwrite, errno, strerror(errno)); + } + + /* We should be at offset K4. */ + + pread01_l_seek(pread01_fildes, 0, SEEK_CUR, K4); + + /* Again, pwrite() K1 of data (1's) at offset K1. */ + + if ((nwrite = pwrite(pread01_fildes, pread01_write_buf[1], K1, + K1)) != K1) + { + syslog(LOG_ERR, + "pwrite() failed to write at %d off. " + "on %s, errno=%d : %s\n", + K1, pread01_filename, errno, strerror(errno)); + } + } +} + +/**************************************************************************** + * Name: pread01_l_seek + ****************************************************************************/ + +/* l_seek() - local front end to lseek(). + * + * "checkoff" is the offset at which we believe we should be at. + * Used to validate pread/pwrite don't move the offset. + */ + +void pread01_l_seek(int fdesc, off_t offset, int whence, off_t checkoff) +{ + off_t offloc; /* offset ret. from lseek() */ + + if ((offloc = lseek(fdesc, offset, whence)) != checkoff) + { + syslog(LOG_WARNING, + "return = %" PRId64 " , expected %" PRId64 "\n", + (int64_t)offloc, (int64_t)checkoff); + syslog(LOG_ERR, "lseek() on %s failed\n", pread01_filename); + } +} + +/**************************************************************************** + * Name: pread01_compare_bufers + ****************************************************************************/ + +/* compare_bufers() - Compare the contents of read buffer aganist the + * write buffer contents. + * + * The contents of the index of each buffer should be as follows: + * [0] has 0's, [1] has 1's, [2] has 2's, and [3] has 3's. + * + * This function does memcmp of read/write buffer and display message + * about the functionality of pread(). + */ + +int pread01_compare_bufers(void) +{ + int count; /* index for the loop */ + int err_flg = 0; /* flag to indicate error */ + + for (count = 0; count < 4; count++) + { + if (memcmp(pread01_write_buf[count], pread01_read_buf[count], + K1) != 0) + { + syslog(LOG_ERR, "FAIL, read/write buffer data mismatch\n"); + err_flg++; + } + } + + /* If no erros, Test successful */ + + if (!err_flg) + { + /* syslog(LOG_INFO, "PASS, Functionality of pread() is correct\n"); */ + + return 0; + } + + else + { + return -1; + } +} + +/**************************************************************************** + * Name: pread01_cleanup + ****************************************************************************/ + +void pread01_cleanup(void) +{ + int count; + + /* Free the memory allocated for the read/write buffer */ + + for (count = 0; count < 4; count++) + { + free(pread01_write_buf[count]); + free(pread01_read_buf[count]); + } + + /* Close the temporary file */ + + close(pread01_fildes); + + unlink(pread01_filename); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_pread01 + ****************************************************************************/ + +void test_nuttx_syscall_pread01(FAR void **state) +{ + int lc; + int nread; /* no. of bytes read by pread() */ + + pread01_setup(); + + for (lc = 0; lc < 1; lc++) + { + /* Call pread() of K1 data (should be 2's) at offset K2. + */ + + nread = pread(pread01_fildes, pread01_read_buf[2], K1, K2); + + /* Check for the return value of pread() */ + + assert_int_equal(nread, K1); + + /* We should still be at offset K4, + * which we were at the end of block 0. + */ + + pread01_l_seek(pread01_fildes, 0, SEEK_CUR, K4); + + /* Now lseek() to offset 0. */ + + pread01_l_seek(pread01_fildes, 0, SEEK_SET, 0); + + /* pread() K1 of data (should be 3's) at offset K3. */ + + nread = pread(pread01_fildes, pread01_read_buf[3], K1, K3); + assert_int_equal(nread, K1); + + /* We should still be at offset 0. */ + + pread01_l_seek(pread01_fildes, 0, SEEK_CUR, 0); + + /* Do a normal read() of K1 data (should be 0's) + * which should take place at offset 0 and move the + * file pointer to an offset of K1. + */ + + nread = read(pread01_fildes, pread01_read_buf[0], K1); + assert_int_equal(nread, K1); + + /* We should now be at an offset of K1. */ + + pread01_l_seek(pread01_fildes, 0, SEEK_CUR, K1); + + /* pread() of K1 data (should be 1's) at offset K1. */ + + nread = pread(pread01_fildes, pread01_read_buf[1], K1, K1); + assert_int_equal(nread, K1); + + /* We should still be at offset K1. */ + + pread01_l_seek(pread01_fildes, 0, SEEK_CUR, K1); + + /* Compare the read buffer data read + * with the data written to write buffer + * in the setup. + */ + + assert_int_equal(pread01_compare_bufers(), 0); + + /* reset our location to offset K4 in case we are looping */ + + pread01_l_seek(pread01_fildes, K4, SEEK_SET, K4); + } + + pread01_cleanup(); +} diff --git a/testing/testsuites/kernel/syscall/cases/pwrite_test.c b/testing/testsuites/kernel/syscall/cases/pwrite_test.c new file mode 100644 index 000000000..13d452c89 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/pwrite_test.c @@ -0,0 +1,322 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/pwrite_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 +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define K1 32 +#define K2 (K1 * 2) +#define K3 (K1 * 3) +#define K4 (K1 * 4) +#define K5 (K1 * 5) + +/**************************************************************************** + * Private data Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +int pwrite02_init_buffers(char *[]); +int pwrite02_l_seek(int, off_t, int, off_t); + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pwrite02_init_buffers + ****************************************************************************/ + +int pwrite02_init_buffers(char *wbuf[]) +{ + int i; + + for (i = 0; i < 4; i++) + { + wbuf[i] = (char *)malloc(K1); + if (wbuf[i] == NULL) + { + syslog(LOG_ERR, "ib: malloc failed: errno=%d\n", errno); + return -1; + } + + memset(wbuf[i], i, K1); + } + + return 0; +} + +void pwrite02_free_buffers(char *wbuf[]) +{ + int i; + + for (i = 0; i < 4; i++) + { + if (wbuf[i] != NULL) + { + free(wbuf[i]); + } + } +} + +/**************************************************************************** + * Name: pwrite02_l_seek + ****************************************************************************/ + +/* l_seek() is a local front end to lseek(). + * "checkoff" is the offset at which we believe we should be at. + * Used to validate pwrite doesn't move the offset. + */ + +int pwrite02_l_seek(int fdesc, off_t offset, int whence, off_t checkoff) +{ + off_t offloc; + + if ((offloc = lseek(fdesc, offset, whence)) != checkoff) + { + syslog(LOG_ERR, + "FAIL, (%ld = lseek(%d, %ld, %d)) != %ld) errno = %d\n", + (long int)offloc, fdesc, (long int)offset, whence, + (long int)checkoff, errno); + return -1; + } + + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_pwrite01 + ****************************************************************************/ + +void test_nuttx_syscall_pwrite01(FAR void **state) +{ + int fd; + int ret; + char filename[64] = ""; + + sprintf(filename, "%s_file", __func__); + + fd = open(filename, O_RDWR | O_CREAT, 0700); + assert_true(fd > 0); + ret = pwrite(fd, NULL, 0, 0); + assert_int_equal(ret, 0); + + if (fd > 0) + assert_int_equal(close(fd), 0); + + assert_int_equal(unlink(filename), 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_pwrite02 + ****************************************************************************/ + +void test_nuttx_syscall_pwrite02(FAR void **state) +{ + char fname[256] = ""; + char *wbuf[4]; + int fd; + int nbytes; + int lc; + struct stat statbuf; + + sprintf(fname, "%s_file", __func__); + + for (lc = 0; lc < 2; lc++) + { + assert_int_equal(pwrite02_init_buffers(wbuf), 0); + + fd = open(fname, O_RDWR | O_CREAT, 0666); + assert_true(fd > 0); + + /* pwrite() K1 of data (0's) at offset 0. + */ + + nbytes = pwrite(fd, wbuf[0], K1, 0); + assert_int_equal(nbytes, K1); + if (nbytes != K1) + { + syslog(LOG_ERR, + "FAIL, pwrite at 0 failed: nbytes=%d, errno=%d\n", + nbytes, errno); + assert_int_equal(unlink(fname), 0); + } + + /* We should still be at offset 0. + */ + + assert_int_equal(pwrite02_l_seek(fd, 0, SEEK_CUR, 0), 0); + + /* lseek() to a non K boundary, just to be different. + */ + + assert_int_equal(pwrite02_l_seek(fd, K1 / 2, SEEK_SET, K1 / 2), 0); + + /* pwrite() K1 of data (2's) at offset K2. + */ + + nbytes = pwrite(fd, wbuf[2], K1, K2); + assert_int_equal(nbytes, K1); + if (nbytes != K1) + { + syslog(LOG_ERR, + "FAIL, pwrite at K2 failed: nbytes=%d, errno=%d\n", + nbytes, errno); + assert_int_equal(unlink(fname), 0); + } + + /* We should still be at our non K boundary. + */ + + assert_int_equal(pwrite02_l_seek(fd, 0, SEEK_CUR, K1 / 2), 0); + + /* lseek() to an offset of K3. + */ + + assert_int_equal(pwrite02_l_seek(fd, K3, SEEK_SET, K3), 0); + + /* This time use a normal write() of K1 of data (3's) which should + * take place at an offset of K3, moving the file pointer to K4. + */ + + nbytes = write(fd, wbuf[3], K1); + assert_int_equal(nbytes, K1); + if (nbytes != K1) + { + syslog(LOG_ERR, "FAIL, write failed: nbytes=%d, errno=%d\n", + nbytes, errno); + assert_int_equal(unlink(fname), 0); + } + + /* We should be at offset K4. + */ + + assert_int_equal(pwrite02_l_seek(fd, 0, SEEK_CUR, K4), 0); + + /* pwrite() K1 of data (1's) at offset K1. + */ + + nbytes = pwrite(fd, wbuf[1], K1, K1); + assert_int_equal(nbytes, K1); + if (nbytes != K1) + { + syslog(LOG_ERR, "FAIL, pwrite failed: nbytes=%d, errno=%d\n", + nbytes, errno); + assert_int_equal(unlink(fname), 0); + } + + /* -------------------------------------------------------------- */ + + /* Now test that O_APPEND takes precedence over any + * offset specified by pwrite(), but that the file + * pointer remains unchanged. First, close then reopen + * the file and ensure it is already K4 in length and + * set the file pointer to it's midpoint, K2. + */ + + close(fd); + fd = open(fname, O_RDWR | O_APPEND, 0666); + assert_true(fd > 0); + if (fd < 0) + { + fail_msg("TEST FAIL !\n"); + syslog(LOG_ERR, "FAIL, open failed: fname = %s, errno = %d\n", + fname, errno); + assert_int_equal(unlink(fname), 0); + } + + if (fstat(fd, &statbuf) == -1) + { + fail_msg("TEST FAIL !\n"); + syslog(LOG_ERR, "FAIl, fstat failed: errno = %d\n", errno); + assert_int_equal(unlink(fname), 0); + } + + if (statbuf.st_size != K4) + { + fail_msg("TEST FAIL !\n"); + syslog(LOG_ERR, "FAIl, file size is %ld != K4\n", + (long int)statbuf.st_size); + assert_int_equal(unlink(fname), 0); + } + + assert_int_equal(pwrite02_l_seek(fd, K2, SEEK_SET, K2), 0); + + /* Finally, pwrite() some K1 of data at offset 0. + * What we should end up with is: + * -The file pointer should still be at K2. + * -The data should have been written to the end + * of the file (O_APPEND) and should be K5 in size. + */ + + if ((nbytes = pwrite(fd, wbuf[0], K1, 0)) != K1) + { + fail_msg("TEST FAIL !\n"); + syslog(LOG_ERR, + "FAIl, pwrite at 0 failed: nbytes=%d, errno=%d\n", + nbytes, errno); + } + + assert_int_equal(pwrite02_l_seek(fd, 0, SEEK_CUR, K2), 0); + if (fstat(fd, &statbuf) == -1) + { + fail_msg("TEST FAIL !\n"); + syslog(LOG_ERR, "FAIl, fstat failed: errno = %d\n", errno); + } + + if (statbuf.st_size != K5) + { + fail_msg("TEST FAIL !\n"); + syslog(LOG_ERR, "FAIl, file size is %ld != K4\n", + (long int)statbuf.st_size); + } + + close(fd); + assert_int_equal(unlink(fname), 0); + pwrite02_free_buffers(wbuf); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/read_test.c b/testing/testsuites/kernel/syscall/cases/read_test.c new file mode 100644 index 000000000..41b12659a --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/read_test.c @@ -0,0 +1,201 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/read_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 +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_read01 + ****************************************************************************/ + +void test_nuttx_syscall_read01(FAR void **state) +{ + int fd; + char buf[512]; + char filename[64] = ""; + + memset(buf, '*', 512); + sprintf(filename, "%s_file", __func__); + + fd = open(filename, O_RDWR | O_CREAT, 0700); + assert_true(fd > 0); + assert_int_equal(write(fd, buf, 512), (ssize_t)512); + + lseek(fd, 0, SEEK_SET); + + assert_int_equal(read(fd, buf, 512), (ssize_t)512); + + if (fd > 0) + assert_int_equal(close(fd), 0); + + assert_int_equal(unlink(filename), 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_read02 + ****************************************************************************/ + +void test_nuttx_syscall_read02(FAR void **state) +{ +#ifndef CONFIG_FDSAN + + /* Define an invalid file descriptor */ + + int badfd = 99999999; + int ret; + char buf[64]; + size_t count = 1; + + /* Read with an invalid file descriptor */ + + ret = read(badfd, buf, count); + + /* Read fail */ + + assert_int_equal(ret, -1); + + /* Check whether the error code meets the expectation */ + + assert_int_equal(errno, EBADF); +#endif +} + +/**************************************************************************** + * Name: test_nuttx_syscall_read03 + ****************************************************************************/ + +void test_nuttx_syscall_read03(FAR void **state) +{ + char fname[255]; + char palfa[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + int fild; + + int lc; + int ret; + int rfild; + char prbuf[BUFSIZ]; + + sprintf(fname, "%s_tfile", __func__); + + fild = creat(fname, 0777); + if (fild > 0) + { + assert_int_equal(write(fild, palfa, 27), 27); + close(fild); + } + + for (lc = 0; lc < 2; lc++) + { + if ((rfild = open(fname, O_RDONLY)) == -1) + { + syslog(LOG_ERR, "can't open for reading\n"); + continue; + } + + ret = read(rfild, prbuf, BUFSIZ); + + if (ret == -1) + { + fail_msg("test fail !\n"); + syslog(LOG_ERR, "FAIL, call failed unexpectedly\n"); + close(rfild); + continue; + } + + if (ret != 27) + { + fail_msg("test fail !\n"); + syslog(LOG_ERR, + "FAIL, Bad read count - got %d - " + "expected %d\n", + ret, 27); + close(rfild); + continue; + } + + if (memcmp(palfa, prbuf, 27) != 0) + { + fail_msg("test fail !\n"); + syslog(LOG_ERR, + "FAIL, read buffer not equal " + "to write buffer\n"); + close(rfild); + continue; + } + + close(rfild); + } + + assert_int_equal(unlink(fname), 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_read04 + ****************************************************************************/ + +void test_nuttx_syscall_read04(FAR void **state) +{ + int ret; + + /* Define an invalid file descriptor */ + + int badfd = -1; + char buf[64]; + size_t count = 1; + + /* Read with an invalid file descriptor */ + + ret = read(badfd, buf, count); + + /* Read succeeded */ + + if (ret != -1) + { + fail_msg("FAIL, read() succeeded unexpectedly"); + } + + /* Check whether the error code meets the expectation */ + + if (errno != EBADF) + { + syslog(LOG_ERR, + "FAIL, read() failed unexpectedly, expected " + "EBADF:%d,actually:%d\n", + EBADF, errno); + fail_msg("read() failed unexpectedly"); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/readdir_test.c b/testing/testsuites/kernel/syscall/cases/readdir_test.c new file mode 100644 index 000000000..09555c2e9 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/readdir_test.c @@ -0,0 +1,108 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/readdir_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 +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_setup + ****************************************************************************/ + +static void test_nuttx_syscall_setup(char *prefix, int nfiles) +{ + char fname[255] = + { + 0 + }; + + int i; + int fd; + int ret; + + for (i = 0; i < nfiles; i++) + { + sprintf(fname, "%s_%d", prefix, i); + fd = open(fname, O_RDWR | O_CREAT, 0700); + assert_true(fd > 0); + + ret = write(fd, "hello\n", 6); + assert_int_in_range(ret, 1, 6); + + assert_int_equal(close(fd), 0); + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_readdirtest01 + ****************************************************************************/ + +void test_nuttx_syscall_readdirtest01(FAR void **state) +{ + char *prefix = "readdirfile"; + int nfiles = 10; + test_nuttx_syscall_setup(prefix, nfiles); + + int cnt = 0; + DIR *test_dir; + struct dirent *ent; + + char buf[20] = + { + 0 + }; + + getcwd(buf, sizeof(buf)); + test_dir = opendir(buf); + assert_non_null(test_dir); + + while ((ent = readdir(test_dir))) + { + if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) + continue; + if (!strncmp(ent->d_name, prefix, sizeof(prefix) - 1)) + cnt++; + } + + assert_int_equal(cnt, nfiles); + assert_int_equal(closedir(test_dir), 0); +} diff --git a/testing/testsuites/kernel/syscall/cases/recvfrom_test.c b/testing/testsuites/kernel/syscall/cases/recvfrom_test.c new file mode 100644 index 000000000..fb9d5907d --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/recvfrom_test.c @@ -0,0 +1,448 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/recvfrom_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 + ****************************************************************************/ +#ifndef UCLINUX +#define UCLINUX +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Private data Prototypes + ****************************************************************************/ + +__attribute__((unused)) static char buf[1024]; +__attribute__((unused)) static int s; /* socket descriptor */ +__attribute__((unused)) static int testno; +__attribute__((unused)) static struct sockaddr_in sin1, from; +__attribute__((unused)) static pthread_t thread; +__attribute__((unused)) static int + sfd; /* shared between do_child and start_server */ +__attribute__((unused)) static socklen_t fromlen; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +__attribute__((unused)) static int setup(void), setup0(void), + setup1(void), setup2(void), cleanup(void), cleanup0(void), + cleanup1(void); +__attribute__((unused)) static void do_child(void); + +__attribute__((unused)) static void *start_server(void *); + +__attribute__((unused)) static struct test_case_t +{ + int domain; /* PF_INET, PF_UNIX, ... */ + int type; /* SOCK_STREAM, SOCK_DGRAM ... */ + int proto; /* protocol number (usually 0 = default) */ + void *buf; /* recv data buffer */ + size_t buflen; /* recv's 3rd argument */ + unsigned flags; /* recv's 4th argument */ + struct sockaddr *from; /* from address */ + socklen_t *salen; /* from address value/result buffer length */ + int retval; /* syscall return value */ + int experrno; /* expected errno */ + int (*setup)(void); + int (*cleanup)(void); + char *desc; +} + +tdat[] = +{ + /* 1 */ + + { + PF_INET, SOCK_STREAM, 0, buf, sizeof(buf), 0, + (struct sockaddr *)&from, &fromlen, -1, EBADF, setup0, cleanup0, + "bad file descriptor" + }, + + /* 2 */ + + { + 0, 0, 0, buf, sizeof(buf), 0, (struct sockaddr *)&from, &fromlen, + -1, ENOTSOCK, setup0, cleanup0, "invalid socket" + }, + + /* 3 */ + + { + PF_INET, SOCK_STREAM, 0, (void *)buf, sizeof(buf), 0, + (struct sockaddr *)-1, &fromlen, 0, ENOTSOCK, setup1, cleanup1, + "invalid socket buffer" + }, + + /* 4 */ + + { + PF_INET, SOCK_STREAM, 0, (void *)buf, sizeof(buf), 0, + (struct sockaddr *)&from, &fromlen, -1, EINVAL, setup2, cleanup1, + "invalid socket addr length" + }, +#ifndef UCLINUX + + /* 5 */ + + { + PF_INET, SOCK_STREAM, 0, (void *)-1, sizeof(buf), 0, + (struct sockaddr *)&from, &fromlen, -1, EFAULT, setup1, cleanup1, + "invalid recv buffer" + }, +#endif + /* 6 */ + +/* { + * PF_INET, SOCK_STREAM, 0, (void *)buf, sizeof(buf), MSG_OOB, + * (struct sockaddr *)&from, &fromlen, + * -1, EINVAL, setup1, cleanup1, "invalid MSG_OOB flag set" + * }, + */ + + /* 7 */ + + { + PF_INET, SOCK_STREAM, 0, (void *)buf, sizeof(buf), + MSG_ERRQUEUE, (struct sockaddr *)&from, &fromlen, -1, EAGAIN, + setup1, cleanup1, "invalid MSG_ERRQUEUE flag set" + }, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: setup + ****************************************************************************/ + +__attribute__((unused)) static int setup(void) +{ + int r = pthread_create(&thread, NULL, start_server, (void *)&sin1); + if (r < 0) + { + syslog(LOG_ERR, "pthread_create fail, errno %d\n", errno); + return -1; + } + + return 0; +} + +/**************************************************************************** + * Name: cleanup + ****************************************************************************/ + +__attribute__((unused)) static int cleanup(void) +{ + assert_true(pthread_cancel(thread) == 0); + assert_true(pthread_join(thread, NULL) == 0); + return 0; +} + +/**************************************************************************** + * Name: setup0 + ****************************************************************************/ + +__attribute__((unused)) static int setup0(void) +{ + if (tdat[testno].experrno == EBADF) + { + s = 400; /* anything not an open file */ + } + + else if ((s = open("/dev/null", O_WRONLY)) == -1) + { + syslog(LOG_ERR, "open /dev/null fail, errno %d\n", errno); + fail_msg("test fail !"); + return -1; + } + + fromlen = sizeof(from); + return 0; +} + +/**************************************************************************** + * Name: cleanup0 + ****************************************************************************/ + +__attribute__((unused)) static int cleanup0(void) +{ + s = -1; + return 0; +} + +/**************************************************************************** + * Name: setup1 + ****************************************************************************/ + +__attribute__((unused)) static int setup1(void) +{ +#ifdef CONFIG_NET_TCP + fd_set rdfds; + struct timeval timeout; + int n; + + s = safe_socket(tdat[testno].domain, tdat[testno].type, + tdat[testno].proto); + assert_true(s >= 0); + if (tdat[testno].type == SOCK_STREAM && + connect(s, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) + { + syslog(LOG_ERR, "connect failed, errno %d\n", errno); + fail_msg("test fail"); + } + + /* Wait for something to be readable, else we won't detect EFAULT on + * recv + */ + + FD_ZERO(&rdfds); + FD_SET(s, &rdfds); + timeout.tv_sec = 2; + timeout.tv_usec = 0; + n = select(s + 1, &rdfds, 0, 0, &timeout); + if (n != 1 || !FD_ISSET(s, &rdfds)) + { + syslog( + LOG_ERR, + "client setup1 failed - no message ready in 2 sec, errno %d\n", + errno); + fail_msg("test fail"); + } + + fromlen = sizeof(from); +#endif + return s; +} + +/**************************************************************************** + * Name: setup2 + ****************************************************************************/ + +__attribute__((unused)) static int setup2(void) +{ + setup1(); + fromlen = -1; + return 0; +} + +/**************************************************************************** + * Name: cleanup1 + ****************************************************************************/ + +__attribute__((unused)) static int cleanup1(void) +{ + (void)close(s); + s = -1; + return 0; +} + +/**************************************************************************** + * Name: start_server + ****************************************************************************/ + +__attribute__((unused)) static void *start_server(void *arg) +{ + /* 设置取消状态为启用 */ + + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + + /* 设置取消类型为异步取消 */ + + pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + + struct sockaddr_in *sin0 = (struct sockaddr_in *)arg; + socklen_t slen = sizeof(*sin0); + + sin0->sin_family = AF_INET; + sin0->sin_port = 0; /* pick random free port */ + sin0->sin_addr.s_addr = INADDR_ANY; + + sfd = socket(PF_INET, SOCK_STREAM, 0); + if (sfd < 0) + { + syslog(LOG_ERR, "server socket failed\n"); + fail_msg("test fail !"); + return NULL; + } + + if (bind(sfd, (struct sockaddr *)sin0, sizeof(*sin0)) < 0) + { + syslog(LOG_ERR, "server bind failed\n"); + close(sfd); + fail_msg("test fail"); + return NULL; + } + + if (listen(sfd, 10) < 0) + { + syslog(LOG_ERR, "server listen failed\n"); + close(sfd); + fail_msg("test fail"); + return NULL; + } + + /* assert_int_not_equal(-1,safe_getsockname(sfd, (struct sockaddr + * *)sin0, &slen)); + */ + + safe_getsockname(sfd, (struct sockaddr *)sin0, &slen); + do_child(); + return NULL; +} + +/**************************************************************************** + * Name: do_child + ****************************************************************************/ + +__attribute__((unused)) static void do_child(void) +{ + struct sockaddr_in fsin; + fd_set afds; + fd_set rfds; + int nfds; + int cc; + int fd; + + FD_ZERO(&afds); + FD_SET(sfd, &afds); + + nfds = sfd + 1; + + /* accept connections until killed */ + + while (1) + { + socklen_t fromlen_s; + memcpy(&rfds, &afds, sizeof(rfds)); + + if (select(nfds, &rfds, NULL, NULL, NULL) < 0) + if (errno != EINTR) + { + syslog(LOG_ERR, "select exit fail\n"); + fail_msg("test fail !"); + return; + } + + if (FD_ISSET(sfd, &rfds)) + { + int newfd; + + fromlen_s = sizeof(fsin); + newfd = accept(sfd, (struct sockaddr *)&fsin, &fromlen_s); + if (newfd >= 0) + { + FD_SET(newfd, &afds); + nfds = (nfds > newfd + 1) ? (nfds) : (newfd + 1); + + /* send something back */ + + (void)write(newfd, "hoser\n", 6); + } + } + + for (fd = 0; fd < nfds; ++fd) + if (fd != sfd && FD_ISSET(fd, &rfds)) + { + cc = read(fd, buf, sizeof(buf)); + if (cc == 0 || (cc < 0 && errno != EINTR)) + { + (void)close(fd); + FD_CLR(fd, &afds); + } + } + + pthread_testcancel(); + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_recvfromtest01 + ****************************************************************************/ + +void test_nuttx_syscall_recvfromtest01(FAR void **state) +{ +#ifdef CONFIG_NET_TCP + int ret; + int flag = 1; + setup(); + + for (testno = 0; testno < sizeof(tdat) / sizeof(tdat[0]); ++testno) + { + usleep(100000); + if (tdat[testno].setup() < 0) + { + tdat[testno].cleanup(); + continue; + } + + ret = recvfrom(s, tdat[testno].buf, tdat[testno].buflen, + tdat[testno].flags, tdat[testno].from, + tdat[testno].salen); + if (ret >= 0) + { + ret = 0; /* all nonzero equal here */ + } + + if (ret != tdat[testno].retval || + (ret < 0 && errno != tdat[testno].experrno)) + { + syslog(LOG_ERR, + "test recvfrom01 %s failed; " + "returned %d (expected %d), errno %d " + "(expected %d)\n", + tdat[testno].desc, ret, tdat[testno].retval, errno, + tdat[testno].experrno); + flag = 0; + } + + tdat[testno].cleanup(); + } + + cleanup(); + assert_true(flag); +#endif +} + +#undef UCLINUX +#endif diff --git a/testing/testsuites/kernel/syscall/cases/rmdir_test.c b/testing/testsuites/kernel/syscall/cases/rmdir_test.c new file mode 100644 index 000000000..063e6b634 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/rmdir_test.c @@ -0,0 +1,121 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/rmdir_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 +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_rmdir01 + ****************************************************************************/ + +void test_nuttx_syscall_rmdir01(FAR void **state) +{ + int ret; + struct stat buf; + char testdir[64] = ""; + + sprintf(testdir, "%s_dir", __func__); + + ret = mkdir(testdir, 0777); + assert_int_equal(ret, 0); + + ret = rmdir(testdir); + assert_int_equal(ret, 0); + + assert_int_not_equal(stat(testdir, &buf), 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_rmdir02 + ****************************************************************************/ + +void test_nuttx_syscall_rmdir02(FAR void **state) +{ + int ret; + int fd; + + /* Description: + * 1) attempt to rmdir() non-empty directory -> ENOTEMPTY + * 2) attempt to rmdir() non-existing directory -> ENOENT + * 3) attempt to rmdir() a file -> ENOTDIR + */ + + struct testcase + { + char dir[32]; + int exp_errno; + } + + tcases[] = + { + { + "Rmdir02_testdir", ENOTEMPTY + }, + + { + "nosuchdir/testdir2", ENOENT + }, + + { + "Rmdir02_testfile2", ENOTDIR + }, + }; + + ret = mkdir("Rmdir02_testdir", (S_IRWXU | S_IRWXG | S_IRWXO)); + assert_int_equal(ret, 0); + ret = mkdir("Rmdir02_testdir/test1", (S_IRWXU | S_IRWXG | S_IRWXO)); + assert_int_equal(ret, 0); + fd = open("Rmdir02_testfile2", O_CREAT | O_RDWR); + + if (fd > 0) + close(fd); + for (int i = 0; i < 3; i++) + { + ret = rmdir(tcases[i].dir); + assert_int_not_equal(ret, 0); + if (ret != -1) + { + continue; + } + } + + assert_int_equal(rmdir("Rmdir02_testdir/test1"), 0); + assert_int_equal(rmdir("Rmdir02_testdir"), 0); + assert_int_equal(unlink("Rmdir02_testfile2"), 0); +} diff --git a/testing/testsuites/kernel/syscall/cases/sched_test.c b/testing/testsuites/kernel/syscall/cases/sched_test.c new file mode 100644 index 000000000..9aa5edd62 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/sched_test.c @@ -0,0 +1,204 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/sched_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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_sched01 + ****************************************************************************/ + +void test_nuttx_syscall_sched01(FAR void **state) +{ + struct test_case_t + { + int prio; + int policy; + } + + TC[] = + { + /* set scheduling policy to SCHED_RR */ + + { + 1, SCHED_RR + }, + + /* set scheduling policy to SCHED_FIFO */ + + { + 1, SCHED_FIFO + } + }; + + int i; + int rec; + struct sched_param param; + + i = 0; +#if CONFIG_RR_INTERVAL > 0 + param.sched_priority = TC[i].prio; + + assert_int_not_equal(sched_setscheduler(0, TC[i].policy, ¶m), -1); + + rec = sched_getscheduler(0); + assert_int_not_equal(rec, -1); + assert_int_equal(rec, TC[i].policy); +#endif + + i = 1; + param.sched_priority = TC[i].prio; + assert_int_not_equal(sched_setscheduler(0, TC[i].policy, ¶m), -1); + + rec = sched_getscheduler(0); + assert_int_not_equal(rec, -1); + assert_int_equal(rec, TC[i].policy); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_sched02 + ****************************************************************************/ + +void test_nuttx_syscall_sched02(FAR void **state) +{ +#if CONFIG_RR_INTERVAL > 0 + int ret; + struct timespec tp; + struct sched_param p = + { + 1 + }; + + /* Change scheduling policy to SCHED_RR */ + + assert_int_not_equal(sched_setscheduler(0, SCHED_RR, &p), -1); + ret = sched_rr_get_interval(0, &tp); + assert_int_equal(ret, 0); +#else + assert_true(1); +#endif +} + +/**************************************************************************** + * Name: test_nuttx_syscall_sched03 + ****************************************************************************/ + +void test_nuttx_syscall_sched03(FAR void **state) +{ + struct timespec tp; + struct sched_param p = + { + 1 + }; + + int ret; + + /* Change scheduling policy to SCHED_FIFO */ + + assert_int_not_equal(sched_setscheduler(0, SCHED_FIFO, &p), -1); + + tp.tv_sec = 99; + tp.tv_nsec = 99; + + ret = sched_rr_get_interval(0, &tp); + + assert_int_equal(ret, 0); + assert_int_equal(tp.tv_sec, 0); + assert_int_equal(tp.tv_nsec, 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_sched04 + ****************************************************************************/ + +void test_nuttx_syscall_sched04(FAR void **state) +{ + struct timespec tp; + + static pid_t inval_pid = -1; + + int i; + int ret; + + struct test_cases_t + { + pid_t *pid; + struct timespec *tp; + int exp_errno; + } + + test_cases[] = + { + { + &inval_pid, &tp, EINVAL + } + }; + + int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]); + +#if CONFIG_RR_INTERVAL > 0 + struct sched_param p = + { + 1 + }; + + /* Change scheduling policy to SCHED_RR */ + + assert_int_not_equal(sched_setscheduler(0, SCHED_RR, &p), -1); +#endif + for (i = 0; i < TST_TOTAL; ++i) + { + /* Call sched_rr_get_interval(2) + */ + + ret = + sched_rr_get_interval(*(test_cases[i].pid), test_cases[i].tp); + int ret_error = errno; + + assert_int_equal(ret, -1); + assert_int_equal(ret_error, test_cases[i].exp_errno); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/setsocketopt01_test.c b/testing/testsuites/kernel/syscall/cases/setsocketopt01_test.c new file mode 100644 index 000000000..8e2bb42ef --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/setsocketopt01_test.c @@ -0,0 +1,162 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/setsocketopt01_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 +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_setsockopt01 + ****************************************************************************/ + +void test_nuttx_syscall_setsockopt01(FAR void **state) +{ +#if defined(CONFIG_NET) && defined(CONFIG_NET_SOCKOPTS) + struct sockaddr_in addr; + int optval; + struct test_case + { /* test case structure */ + int domain; /* PF_INET, PF_UNIX, ... */ + int type; /* SOCK_STREAM, SOCK_DGRAM ... */ + int proto; /* protocol number (usually 0 = default) */ + int level; /* IPPROTO_* */ + int optname; + void *optval; + int optlen; + int experrno; /* expected errno */ + char *desc; + } + + testcase_list[] = + { + { + -1, -1, -1, SOL_SOCKET, SO_OOBINLINE, &optval, sizeof(optval), + EBADF, "invalid file descriptor" + }, + + { + -1, -1, -1, SOL_SOCKET, SO_OOBINLINE, &optval, sizeof(optval), + ENOTSOCK, "non-socket file descriptor" + }, + + { + PF_INET, SOCK_STREAM, 0, SOL_SOCKET, SO_OOBINLINE, NULL, + sizeof(optval), EFAULT, "invalid option buffer" + }, + + { + PF_INET, SOCK_STREAM, 0, SOL_SOCKET, SO_OOBINLINE, &optval, 0, + EINVAL, "invalid optlen" + }, + + { + PF_INET, SOCK_STREAM, 0, 500, SO_OOBINLINE, &optval, + sizeof(optval), ENOPROTOOPT, "invalid level" + }, + + { + PF_INET, SOCK_STREAM, 0, IPPROTO_UDP, SO_OOBINLINE, &optval, + sizeof(optval), ENOPROTOOPT, "invalid option name (UDP)" + }, + + { + PF_INET, SOCK_STREAM, 0, IPPROTO_IP, -1, &optval, sizeof(optval), + ENOPROTOOPT, "invalid option name (IP)" + }, + + { + PF_INET, SOCK_STREAM, 0, IPPROTO_TCP, -1, &optval, sizeof(optval), + ENOPROTOOPT, "invalid option name (TCP)" + } + }; + + /* initialize local sockaddr */ + + addr.sin_family = AF_INET; + addr.sin_port = 0; + addr.sin_addr.s_addr = INADDR_ANY; + for (int n = 0; n < sizeof(testcase_list) / sizeof(testcase_list[0]); + n++) + { + int ret; + struct test_case *tc = testcase_list + n; + int tmpfd; + int fd; + if (tc->domain == -1) + { + tmpfd = fd = SAFE_OPEN("/dev/null", O_WRONLY); + if (fd < 0) + continue; + } + + else + { + tmpfd = fd = safe_socket(tc->domain, tc->type, tc->proto); + if (fd < 0) + continue; + if (safe_bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) + continue; + } + + /* Use closed file descriptor rather than -1 */ + + if (tc->experrno == EBADF) + if (safe_close(tmpfd) < 0) + continue; + ret = + setsockopt(fd, tc->level, tc->optname, tc->optval, tc->optlen); + if (tc->experrno != EBADF) + { + safe_close(fd); + fd = -1; + } + + if (ret != -1 || errno != tc->experrno) + { + syslog(LOG_ERR, + "setsockopt %s fail, returned %d (expected -1), " + "errno %d (expected %d)\n", + tc->desc, ret, errno, tc->experrno); + fail_msg("test fail !"); + continue; + } + } + +#endif +} diff --git a/testing/testsuites/kernel/syscall/cases/socket_test.c b/testing/testsuites/kernel/syscall/cases/socket_test.c new file mode 100644 index 000000000..7bad8a0ba --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/socket_test.c @@ -0,0 +1,208 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/socket_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 +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_verifysocket01 + ****************************************************************************/ + +void test_nuttx_syscall_verifysocket01(int testno, int domain, int type, + int proto, int retval, int experrno) +{ + int fd; + int ret; + errno = 0; + fd = socket(domain, type, proto); + ret = fd; + if (fd > 0) + { + ret = 0; + close(fd); + } + + else + { + ret = -1; + } + + if (errno != experrno || ret != retval) + { + syslog(LOG_WARNING, + "NO.%d do socket() test, ret=%d erron=%d experrno=%d\n", + testno, fd, errno, experrno); + } + + assert_int_equal(ret, retval); +} + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_verifysocket02 + ****************************************************************************/ + +void test_nuttx_syscall_verifysocket02(int type, int flag, int fl_flag) +{ + int fd; + int res; + int tmp; + + fd = socket(PF_INET, type, 0); + assert_int_not_equal(fd, -1); + + res = fcntl(fd, fl_flag); + tmp = (res & flag); + + if (flag != 0) + { + assert_int_not_equal(tmp, 0); + } + + else + { + assert_int_equal(tmp, 0); + } + + assert_int_equal(close(fd), 0); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_sockettest01 + ****************************************************************************/ + +void test_nuttx_syscall_sockettest01(FAR void **state) +{ + struct test_case_t + { + int domain; + int type; + int proto; + int retval; + int experrno; + } + + tdat[] = + { + { + 0, SOCK_STREAM, 0, -1, EAFNOSUPPORT + }, + + { + PF_INET, 75, 0, -1, EAFNOSUPPORT + }, + + { + PF_INET, SOCK_RAW, 0, -1, EAFNOSUPPORT + }, + + { + PF_INET, SOCK_STREAM, 17, -1, EAFNOSUPPORT + }, + + { + PF_INET, SOCK_DGRAM, 6, -1, EAFNOSUPPORT + }, + + { + PF_INET, SOCK_STREAM, 6, 0, 0 + }, + + { + PF_INET, SOCK_STREAM, 1, -1, EAFNOSUPPORT + } + }; + + for (int i = 0; i < 7; i++) + { + test_nuttx_syscall_verifysocket01(i, tdat[i].domain, tdat[i].type, + tdat[i].proto, tdat[i].retval, + tdat[i].experrno); + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_sockettest02 + ****************************************************************************/ + +void test_nuttx_syscall_sockettest02(FAR void **state) +{ + static struct tcase + { + int type; + int flag; + int fl_flag; + } + + tcases[] = + { + { + SOCK_STREAM, 0, F_GETFD + }, + + { + SOCK_STREAM | SOCK_CLOEXEC, FD_CLOEXEC, F_GETFD + }, + + { + SOCK_STREAM, 0, F_GETFL + }, + + { + SOCK_STREAM | SOCK_NONBLOCK, O_NONBLOCK, F_GETFL + } + }; + + for (int i = 0; i < 4; i++) + { + test_nuttx_syscall_verifysocket02(tcases[i].type, tcases[i].flag, + tcases[i].fl_flag); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/socketpair_test.c b/testing/testsuites/kernel/syscall/cases/socketpair_test.c new file mode 100644 index 000000000..2b4e6209d --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/socketpair_test.c @@ -0,0 +1,230 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/socketpair_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 + ****************************************************************************/ +#ifndef UCLINUX +#define UCLINUX +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_socketpair01 + ****************************************************************************/ + +void test_nuttx_syscall_socketpair01(FAR void **state) +{ +#ifdef CONFIG_NET_TCP + int fds[2]; + int ret; + struct test_case_t + { + int domain; + int type; + int proto; + int *sv; + int retval; + int experrno; + char *desc; + } + + tdat[] = + { + { + 0, SOCK_STREAM, 0, fds, -1, EAFNOSUPPORT, "invalid domain" + }, + + { + PF_INET, 75, 0, fds, -1, EINVAL, "invalid type" + }, + + { + PF_UNIX, SOCK_DGRAM, 0, fds, 0, 0, "UNIX domain dgram" + }, + + { + PF_INET, SOCK_RAW, 0, fds, -1, EPROTONOSUPPORT, + "raw open as non-root" + }, + + #ifndef UCLINUX + { + PF_UNIX, SOCK_STREAM, 0, 0, -1, EFAULT, "bad aligned pointer" + }, + + { + PF_UNIX, SOCK_STREAM, 0, (int *)7, -1, EFAULT, + "bad unaligned pointer" + }, + + #endif + /* {PF_INET, SOCK_DGRAM, 17, fds, -1, EOPNOTSUPP, "UDP socket"}, */ + + { + PF_INET, SOCK_DGRAM, 6, fds, -1, EPROTONOSUPPORT, "TCP dgram" + }, + + /* {PF_INET, SOCK_STREAM, 6, fds, -1, EOPNOTSUPP, "TCP socket"}, */ + + { + PF_INET, SOCK_STREAM, 1, fds, -1, EPROTONOSUPPORT, + "ICMP stream" + } + }; + + for (int n = 0; n < sizeof(tdat) / sizeof(tdat[0]); n++) + { + struct test_case_t *tc = &tdat[n]; + ret = socketpair(tc->domain, tc->type, tc->proto, tc->sv); + if (ret == 0) + { + SAFE_CLOSE(fds[0]); + SAFE_CLOSE(fds[1]); + } + + if (ret != tc->retval || errno != tc->experrno) + { + syslog(LOG_ERR, + "test socketpair01 %s failed; " + "returned %d (expected %d), errno %d " + "(expected %d)\n", + tc->desc, ret, tc->retval, errno, tc->experrno); + assert_true(0); + } + } + +#endif +} + +/**************************************************************************** + * Name: test_nuttx_syscall_socketpair02 + ****************************************************************************/ + +void test_nuttx_syscall_socketpair02(FAR void **state) +{ +#ifdef CONFIG_NET_TCP + int fds[2]; + int ret; + int flag = 1; + struct tcase + { + int type; + int flag; + int fl_flag; + char *des; + } + + tcases[] = + { + { + SOCK_STREAM, 0, F_GETFD, "no close-on-exec" + }, + + { + SOCK_STREAM | SOCK_CLOEXEC, FD_CLOEXEC, F_GETFD, "close-on-exec" + }, + + { + SOCK_STREAM, 0, F_GETFL, "no non-blocking" + }, + + { + SOCK_STREAM | SOCK_NONBLOCK, O_NONBLOCK, F_GETFL, + "non-blocking" + } + }; + + for (int n = 0; n < sizeof(tcases) / sizeof(tcases[0]); n++) + { + int res; + struct tcase *tc = &tcases[n]; + ret = socketpair(PF_UNIX, tc->type, 0, fds); + if (ret == -1) + { + flag = 0; + syslog(LOG_ERR, + "test socketpair02 %s failed; " + "returned -1, errno %d\n", + tc->des, errno); + continue; + } + + for (int i = 0; i < 2; i++) + { + res = SAFE_FCNTL(fds[i], tc->fl_flag); + + if (tc->flag != 0 && (res & tc->flag) == 0) + { + flag = 0; + syslog(LOG_ERR, + "socketpair() failed to set %s flag for fds[%d]\n", + tc->des, i); + break; + } + + if (tc->flag == 0 && (res & tc->flag) != 0) + { + flag = 0; + syslog(LOG_ERR, + "socketpair() failed to set %s flag for fds[%d]\n", + tc->des, i); + break; + } + } + + SAFE_CLOSE(fds[0]); + SAFE_CLOSE(fds[1]); + } + + if (fds[0] > 0) + { + SAFE_CLOSE(fds[0]); + } + + if (fds[1] > 0) + { + SAFE_CLOSE(fds[1]); + } + + assert_true(flag); +#endif +} + +#undef UCLINUX +#endif \ No newline at end of file diff --git a/testing/testsuites/kernel/syscall/cases/symlink_test.c b/testing/testsuites/kernel/syscall/cases/symlink_test.c new file mode 100644 index 000000000..40f653c1f --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/symlink_test.c @@ -0,0 +1,132 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/symlink_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 +#include +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_symlink01 + ****************************************************************************/ + +void test_nuttx_syscall_symlink01(FAR void **state) +{ + char fname[255]; + char symlnk[255]; + int fd; + int ret; + + sprintf(fname, "%s_tfile", __func__); + fd = open(fname, O_RDWR | O_CREAT, 0700); + assert_true(fd > 0); + if (fd > 0) + close(fd); + sprintf(symlnk, "/%s_t_%d", __func__, gettid()); + ret = symlink(fname, symlnk); + if (fd > 0) + close(fd); + assert_int_equal(ret, OK); + + assert_int_equal(unlink(fname), 0); + assert_int_equal(unlink(symlnk), 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_symlink02 + ****************************************************************************/ + +void test_nuttx_syscall_symlink02(FAR void **state) +{ + int fd; + int ret; + struct stat stat_buf; + char testfile[128] = + { + 0 + }; + + snprintf(testfile, sizeof(testfile), "%s_file", __func__); + + /* creat/open a testfile */ + + fd = open(testfile, O_RDWR | O_CREAT, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (fd < 0) + { + syslog(LOG_ERR, "open test file fail !\n"); + fail_msg("test fail !"); + } + + /* Close the temporary file created above */ + + assert_int_equal(close(fd), 0); + + ret = symlink(testfile, "/Symlink02_file"); + if (ret == -1) + { + syslog(LOG_ERR, "symlink testfile to symfile Failed, errno=%d \n", + errno); + fail_msg("test fail!"); + } + else + { + /* Get the symlink file status information + * using lstat(2). + */ + + if (lstat("/Symlink02_file", &stat_buf) < 0) + { + syslog(LOG_ERR, "lstat(2) of symfile failed, error:%d \n", + errno); + fail_msg("test fail!"); + } + + /* Check if the st_mode contains a link */ + + if (!S_ISLNK(stat_buf.st_mode)) + { + syslog(LOG_ERR, "symlink of testfile doesn't exist \n"); + fail_msg("test fail!"); + } + } + + assert_int_equal(unlink(testfile), 0); + assert_int_equal(unlink("/Symlink02_file"), 0); +} diff --git a/testing/testsuites/kernel/syscall/cases/time_test.c b/testing/testsuites/kernel/syscall/cases/time_test.c new file mode 100644 index 000000000..9a17d3572 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/time_test.c @@ -0,0 +1,84 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/time_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 +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_time01 + ****************************************************************************/ + +void test_nuttx_syscall_time01(FAR void **state) +{ + int lc; + time_t ret; + + for (lc = 0; lc < 5; lc++) + { + /* Call time() + */ + + ret = time(NULL); + + /* check return code */ + + assert_int_not_equal(ret, (time_t)-1); + } +} + +/**************************************************************************** + * Name: test_nuttx_syscall_time02 + ****************************************************************************/ + +void test_nuttx_syscall_time02(FAR void **state) +{ + int lc; + time_t tloc; + time_t ret; /* time_t variables for time(2) */ + + for (lc = 0; lc < 5; lc++) + { + /* Call time() to get the time in seconds$ + * since Epoch. + */ + + ret = time(&tloc); + + /* Check return code from time(2) */ + + assert_int_equal(tloc, ret); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/timer_create_test.c b/testing/testsuites/kernel/syscall/cases/timer_create_test.c new file mode 100644 index 000000000..ac3bf7abe --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/timer_create_test.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/timer_create_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 +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_timercreate01 + ****************************************************************************/ + +void test_nuttx_syscall_timercreate01(FAR void **state) +{ + int ret; + struct sigevent evp; + clock_t clock = CLOCK_MONOTONIC; + timer_t created_timer_id; + + memset(&evp, 0, sizeof(evp)); + + evp.sigev_signo = SIGALRM; + evp.sigev_notify = SIGEV_SIGNAL; + + ret = timer_create(clock, &evp, &created_timer_id); + assert_int_equal(ret, 0); + + ret = timer_delete(created_timer_id); + assert_int_equal(ret, 0); +} diff --git a/testing/testsuites/kernel/syscall/cases/timer_delete_test.c b/testing/testsuites/kernel/syscall/cases/timer_delete_test.c new file mode 100644 index 000000000..d8bf5ae1e --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/timer_delete_test.c @@ -0,0 +1,64 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/timer_delete_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 +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_timerdelete01 + ****************************************************************************/ + +void test_nuttx_syscall_timerdelete01(FAR void **state) +{ + int ret; + timer_t timer_id; + clock_t clock_list[] = + { + CLOCK_REALTIME, + CLOCK_MONOTONIC, + CLOCK_BOOTTIME, + }; + + for (int i = 0; i < 3; i++) + { + ret = timer_create(clock_list[i], NULL, &timer_id); + assert_int_equal(ret, 0); + + ret = timer_delete(timer_id); + assert_int_equal(ret, 0); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/timer_gettime_test.c b/testing/testsuites/kernel/syscall/cases/timer_gettime_test.c new file mode 100644 index 000000000..772678956 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/timer_gettime_test.c @@ -0,0 +1,69 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/timer_gettime_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 +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_timergettime01 + ****************************************************************************/ + +void test_nuttx_syscall_timergettime01(FAR void **state) +{ + int lc; + int ret; + struct sigevent ev; + struct itimerspec spec; + timer_t timer; + + ev.sigev_value = (union sigval)0; + ev.sigev_signo = SIGALRM; + ev.sigev_notify = SIGEV_SIGNAL; + + ret = timer_create(CLOCK_REALTIME, &ev, &timer); + assert_int_equal(ret, 0); + + for (lc = 0; lc < 1; ++lc) + { + ret = timer_gettime(timer, &spec); + assert_int_equal(ret, 0); + + ret = timer_gettime(timer, NULL); + assert_int_equal(ret, -1); + assert_int_equal(errno, EINVAL); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/truncate_test.c b/testing/testsuites/kernel/syscall/cases/truncate_test.c new file mode 100644 index 000000000..6589cd51a --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/truncate_test.c @@ -0,0 +1,150 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/truncate_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 +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_truncate01 + ****************************************************************************/ + +void test_nuttx_syscall_truncate01(FAR void **state) +{ + int BUF_SIZE = 256; /* buffer size */ + int FILE_SIZE = 1024; /* test file size */ + int TRUNC_LEN = 256; /* truncation length */ + struct stat stat_buf; /* stat(2) struct contents */ + int lc; + int ret; + off_t file_length; /* test file length */ + char truncate01_fileneme[128] = ""; + + /* setup */ + + int fd; + int i; /* file handler for testfile */ + int c; + int c_total = 0; /* no. bytes to be written to file */ + char tst_buff[BUF_SIZE]; /* buffer to hold data */ + + snprintf(truncate01_fileneme, sizeof(truncate01_fileneme), "%s_file", + __func__); + + /* Fill the test buffer with the known data */ + + for (i = 0; i < BUF_SIZE; i++) + { + tst_buff[i] = 'a'; + } + + /* Creat a testfile under temporary directory */ + + fd = open(truncate01_fileneme, O_RDWR | O_CREAT, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (fd < 0) + { + syslog(LOG_ERR, "open test file fail !\n"); + fail_msg("test fail !"); + } + + /* Write to the file 1k data from the buffer */ + + while (c_total < FILE_SIZE) + { + c = write(fd, tst_buff, sizeof(tst_buff)); + if (c > 0) + { + c_total += c; + } + } + + /* Close the testfile after writing data into it */ + + close(fd); + + /* do test */ + + for (lc = 0; lc < 2; lc++) + { + ret = truncate(truncate01_fileneme, TRUNC_LEN); + + if (ret == -1) + { + syslog(LOG_ERR, + "FAIL, truncate(%s, %d) Failed, errno=%d : %s\n", + truncate01_fileneme, TRUNC_LEN, errno, strerror(errno)); + fail_msg("test fail !"); + } + else + { + /* Get the testfile information using + * stat(2). + */ + + if (stat(truncate01_fileneme, &stat_buf) < 0) + { + syslog(LOG_ERR, + "FAIL, stat(2) of " + "%s failed, error:%d\n", + truncate01_fileneme, errno); + fail_msg("test fail !"); + } + + stat_buf.st_mode &= ~S_IFREG; + file_length = stat_buf.st_size; + + /* Check for expected size of testfile after + * truncate(2) on it. + */ + + if (file_length != TRUNC_LEN) + { + syslog(LOG_ERR, + "FAIL, %s: Incorrect file " + "size %" PRId64 " , Expected %d\n", + truncate01_fileneme, (int64_t)file_length, + TRUNC_LEN); + fail_msg("test fail !"); + } + } + } + + assert_int_equal(unlink(truncate01_fileneme), 0); +} diff --git a/testing/testsuites/kernel/syscall/cases/unlink_test.c b/testing/testsuites/kernel/syscall/cases/unlink_test.c new file mode 100644 index 000000000..78b3e6f57 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/unlink_test.c @@ -0,0 +1,78 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/unlink_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 +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_unlink01 + ****************************************************************************/ + +void test_nuttx_syscall_unlink01(FAR void **state) +{ + char fname[64] = + { + 0 + }; + + int fd; + int ret; + + sprintf(fname, "%s_file", __func__); + + fd = open(fname, O_RDWR | O_CREAT); + if (fd > 0) + { + close(fd); + } + + else + { + syslog(LOG_ERR, "open test file fail !\n"); + fail_msg("test fail"); + } + + ret = unlink(fname); + assert_int_equal(ret, 0); + + if (!access(fname, F_OK)) + { + fail_msg("test fail !\n"); + syslog(LOG_ERR, + "FAIL, unlink(%s) succeeded, but %s still existed\n", fname, + fname); + } +} diff --git a/testing/testsuites/kernel/syscall/cases/write_test.c b/testing/testsuites/kernel/syscall/cases/write_test.c new file mode 100644 index 000000000..dcd10cc36 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cases/write_test.c @@ -0,0 +1,177 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cases/write_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 +#include +#include +#include +#include "SyscallTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_syscall_write01 + ****************************************************************************/ + +void test_nuttx_syscall_write01(FAR void **state) +{ + ssize_t ret; + char filename[64]; + int fd; + int i; + int badcount = 0; + char buf[BUFSIZ]; + + sprintf(filename, "%s_file", __func__); + + /* setup */ + + fd = open(filename, O_RDWR | O_CREAT, 0700); + assert_true(fd > 0); + + /* do test */ + + assert_non_null(memset(buf, 'w', BUFSIZ)); + + assert_int_equal(lseek(fd, 0, SEEK_SET), 0); + + for (i = BUFSIZ; i > 0; i--) + { + ret = write(fd, buf, i); + if (ret == -1) + { + fail_msg("FAIL, write failed !\n"); + break; + } + + if (ret != i) + { + badcount++; + syslog(LOG_INFO, + "INFO, write() returned %" PRId64 ", expected %d\n", + (int64_t)ret, i); + } + } + + if (badcount != 0) + { + fail_msg("FAIL, write() failed to return proper count\n"); + } + + if (fd > 0) + { + assert_int_equal(close(fd), 0); + } + + assert_int_equal(unlink(filename), 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_write02 + ****************************************************************************/ + +void test_nuttx_syscall_write02(FAR void **state) +{ + int fd; + int ret; + char filename[64]; + sprintf(filename, "%s_file", __func__); + fd = open(filename, O_RDWR | O_CREAT, 0700); + assert_true(fd > 0); + + ret = write(fd, NULL, 3); + assert_true(ret < 0); + + if (fd > 0) + { + assert_int_equal(close(fd), 0); + } + + assert_int_equal(unlink(filename), 0); +} + +/**************************************************************************** + * Name: test_nuttx_syscall_write03 + ****************************************************************************/ + +void test_nuttx_syscall_write03(FAR void **state) +{ + int fd; + ssize_t ret; + char filename[64]; + int i; + int badcount = 0; + char buf[100]; + + sprintf(filename, "%s_file.wav", __func__); + + /* setup */ + + fd = open(filename, O_RDWR | O_CREAT, 0700); + assert_true(fd > 0); + + /* do test */ + + assert_non_null(memset(buf, 'w', 100)); + + assert_int_equal(lseek(fd, 0, SEEK_SET), 0); + + for (i = 100; i > 0; i--) + { + ret = write(fd, buf, i); + if (ret == -1) + { + fail_msg("FAIL, write failed !\n"); + break; + } + + if (ret != i) + { + badcount++; + syslog(LOG_INFO, + "INFO, write() returned %" PRId64 ", expected %d\n", + (int64_t)ret, i); + } + } + + if (badcount != 0) + { + fail_msg("FAIL, write() failed to return proper count\n"); + } + + if (fd > 0) + { + assert_int_equal(close(fd), 0); + } + + assert_int_equal(unlink(filename), 0); +} diff --git a/testing/testsuites/kernel/syscall/cmocka_syscall_test.c b/testing/testsuites/kernel/syscall/cmocka_syscall_test.c new file mode 100644 index 000000000..957977b07 --- /dev/null +++ b/testing/testsuites/kernel/syscall/cmocka_syscall_test.c @@ -0,0 +1,458 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/cmocka_syscall_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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: cmocka_sched_test_main + ****************************************************************************/ + +int main(int argc, char *argv[]) +{ + /* Add Test Cases */ + + const struct CMUnitTest nuttx_syscall_test_suites[] = + { + /* cmocka_unit_test_setup_teardown(test_nuttx_syscall_bind01, + * test_nuttx_syscall_test_group_setup, + * test_nuttx_syscall_test_group_teardown), + */ + + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_chdir01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_chdir02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + + /* cmocka_unit_test_setup_teardown(test_nuttx_syscall_accept01, + * test_nuttx_syscall_test_group_setup, + * test_nuttx_syscall_test_group_teardown), + */ + + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_getitimer01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_clockgettime01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_clocknanosleep01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_clocksettime01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_close01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_close02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_close03, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_creat01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_creat02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + + /* cmocka_unit_test_setup_teardown(test_nuttx_syscall_fcntl01, + * NULL, NULL), + */ + + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_fcntl02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_fcntl03, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_fcntl04, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + + /* cmocka_unit_test_setup_teardown(test_nuttx_syscall_fcntl05, NULL, + * NULL), + */ + +#ifndef CONFIG_ARCH_SIM + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_fcntl06, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), +#endif + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_fstatfs01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_fsync01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), +#ifdef CONFIG_NET + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_fsync02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_fsync03, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_getpeername01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_getsockopt01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + + /* cmocka_unit_test_setup_teardown(test_nuttx_syscall_recvfromtest01, + * test_nuttx_syscall_test_group_setup, + * test_nuttx_syscall_test_group_teardown), + */ + + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_setsockopt01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_listen01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + + /* cmocka_unit_test_setup_teardown(test_nuttx_syscall_socketpair01, + * test_nuttx_syscall_test_group_setup, + * test_nuttx_syscall_test_group_teardown), + */ + +#ifdef CONFIG_NET_LOCAL_DGRAM + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_socketpair02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), +#endif +#endif + + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_ftruncate01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_getcwd01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_getcwd02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_getpid01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_getppid01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_gethostname01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_gettimeofday01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_lseek01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_lseek07, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_lstat01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_dup01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_dup02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_dup03, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_dup04, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_dup05, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_dup201, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_dup202, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_fpathconf01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_getegid01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_getegid02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_geteuid01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + + /* not implement + * cmocka_unit_test_setup_teardown(test_nuttx_syscall_geteuid02, + * estnuttxsyscalltestgroupsetup, + * test_nuttx_syscall_test_group_teardown), + */ + + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_getgid01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_getgid02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_getuid01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + + /* not implement + * cmocka_unit_test_setup_teardown(test_nuttx_syscall_getuid02, + * test_nuttx_syscall_test_group_setup, + * test_nuttx_syscall_test_group_teardown), + */ + + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_pathconf01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_pipe01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_pipe02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_pread01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_pwrite01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_pwrite02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_rmdir01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_rmdir02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_truncate01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_unlink01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_nansleep01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_nansleep02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_time01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_time02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_timercreate01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_timerdelete01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_timergettime01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_mkdir01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_mkdir02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_mkdir03, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_sched01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_sched02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_sched03, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_sched04, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_write01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_write02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_write03, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_read01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_read02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_read03, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_read04, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_symlink01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_symlink02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + + /* cmocka_unit_test_setup_teardown(test_nuttx_syscall_connect01, + * test_nuttx_syscall_test_group_setup, + * test_nuttx_syscall_test_group_teardown), + */ + +#if !defined(CONFIG_ARCH_SIM) && defined(CONFIG_NET) + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_sockettest01, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), + cmocka_unit_test_setup_teardown( + test_nuttx_syscall_sockettest02, + test_nuttx_syscall_test_group_setup, + test_nuttx_syscall_test_group_teardown), +#endif + }; + + /* Run Test cases */ + + cmocka_run_group_tests(nuttx_syscall_test_suites, NULL, NULL); + return 0; +} diff --git a/testing/testsuites/kernel/syscall/common/test_syscall_common.c b/testing/testsuites/kernel/syscall/common/test_syscall_common.c new file mode 100644 index 000000000..def66d1b6 --- /dev/null +++ b/testing/testsuites/kernel/syscall/common/test_syscall_common.c @@ -0,0 +1,767 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/common/test_syscall_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 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SyscallTest.h" + +#define CM_SYSCALL_TESTDIR "CM_syscall_testdir" +#define PATH_SIZE 128 + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int rm_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 = rm_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: test_nuttx_syscall_testgroupsetup + ****************************************************************************/ + +int test_nuttx_syscall_test_group_setup(void **state) +{ + int res; + struct stat buf; + + res = chdir(MOUNT_DIR); + if (res != 0) + { + syslog(LOG_INFO, "ERROR: Failed to switch the mount dir\n"); + exit(1); + } + + res = stat(CM_SYSCALL_TESTDIR, &buf); + if (res == 0 && buf.st_mode == S_IFDIR) + { + res = chdir(CM_SYSCALL_TESTDIR); + return res; + } + + else + { + char testdir[PATH_MAX] = + { + 0 + }; + + sprintf(testdir, "%s/%s", MOUNT_DIR, CM_SYSCALL_TESTDIR); + + /* Delete the existing test directory */ + + rm_recursive(testdir); + res = mkdir(CM_SYSCALL_TESTDIR, 0777); + if (res != 0) + { + syslog(LOG_ERR, "ERROR: Failed to creat the test directory\n"); + exit(1); + } + + res = chdir(CM_SYSCALL_TESTDIR); + } + + return res; +} + +/**************************************************************************** + * Name: test_nuttx_syscall_test_group_teardown + ****************************************************************************/ + +int test_nuttx_syscall_test_group_teardown(void **state) +{ + int res; + char testdir[PATH_MAX] = + { + 0 + }; + + sprintf(testdir, "%s", CM_SYSCALL_TESTDIR); + + res = chdir(MOUNT_DIR); + if (res != 0) + { + syslog(LOG_INFO, "ERROR: Failed to switch the mount dir\n"); + exit(1); + } + + /* call the recursive delete interface */ + + rm_recursive(testdir); + + return 0; +} + +/**************************************************************************** + * Name: cmtestfillfilewithfd + ****************************************************************************/ + +static int cmtestfillfilewithfd(int fd, char pattern, size_t bs, + size_t bcount) +{ + size_t i; + char *buf; + + /* Filling a memory buffer with provided pattern */ + + buf = (char *)malloc(bs); + if (buf == NULL) + return -1; + + for (i = 0; i < bs; i++) + buf[i] = pattern; + + /* Filling the file */ + + for (i = 0; i < bcount; i++) + { + if (write(fd, buf, bs) != (ssize_t)bs) + { + free(buf); + return -1; + } + } + + free(buf); + + return 0; +} + +/**************************************************************************** + * Name: cmtestfillfile + ****************************************************************************/ + +int cmtestfillfile(const char *path, char pattern, size_t bs, + size_t bcount) +{ + int fd; + + fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR); + if (fd < 0) + return -1; + + if (cmtestfillfilewithfd(fd, pattern, bs, bcount)) + { + close(fd); + unlink(path); + return -1; + } + + if (close(fd) < 0) + { + unlink(path); + + return -1; + } + + return 0; +} + +/**************************************************************************** + * Name: checknames + ****************************************************************************/ + +int checknames(char *pfilnames, DIR *ddir) +{ + struct dirent *dir; + while ((dir = readdir(ddir)) != NULL) + { + /* cout << "file name=" << dir->d_name << endl; */ + + if (strcmp(pfilnames, dir->d_name) == 0) + return 0; + } + + return -1; +} + +/**************************************************************************** + * Name: check_and_report_ftruncatetest + ****************************************************************************/ + +int check_and_report_ftruncatetest(int fd, off_t offset, char data, + off_t trunc_len) +{ + int i; + int file_length; + char buf[1024]; + struct stat stat_buf; + + memset(buf, '*', sizeof(buf)); + + fstat(fd, &stat_buf); + file_length = stat_buf.st_size; + + if (file_length != trunc_len) + { + syslog(LOG_ERR, "FAIL, ftruncate() got incorrected size: %d\n", + file_length); + return -1; + } + + lseek(fd, offset, SEEK_SET); + read(fd, buf, sizeof(buf)); + + for (i = 0; i < 256; i++) + { + if (buf[i] != data) + { + syslog( + LOG_ERR, + "FAIL, ftruncate() got incorrect data %i, expected %i\n", + buf[i], data); + return -1; + } + } + + return 0; +} + +/**************************************************************************** + * Name: tst_fill_fd + ****************************************************************************/ + +int tst_fill_fd(int fd, char pattern, size_t bs, size_t bcount) +{ + size_t i; + char *buf; + + /* Filling a memory buffer with provided pattern */ + + buf = (char *)malloc(bs); + if (buf == NULL) + return -1; + + for (i = 0; i < bs; i++) + buf[i] = pattern; + + /* Filling the file */ + + for (i = 0; i < bcount; i++) + { + if (write(fd, buf, bs) != (ssize_t)bs) + { + free(buf); + return -1; + } + } + + free(buf); + + return 0; +} + +/**************************************************************************** + * Name: tst_fill_file + ****************************************************************************/ + +int tst_fill_file(const char *path, char pattern, size_t bs, + size_t bcount) +{ + int fd; + + fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR); + if (fd < 0) + return -1; + + if (tst_fill_fd(fd, pattern, bs, bcount)) + { + close(fd); + unlink(path); + return -1; + } + + if (close(fd) < 0) + { + unlink(path); + + return -1; + } + + return 0; +} + +/**************************************************************************** + * Name: safe_open + ****************************************************************************/ + +int safe_open(const char *pathname, int oflags, ...) +{ + va_list ap; + int rval; + mode_t mode; + + va_start(ap, oflags); + mode = va_arg(ap, int); + va_end(ap); + + rval = open(pathname, oflags, mode); + if (rval == -1) + { + syslog(LOG_ERR, "open(%s,%d,0%o) failed\n", pathname, oflags, + mode); + fail_msg("test fail !"); + } + + return rval; +} + +/**************************************************************************** + * Name: safe_write + ****************************************************************************/ + +ssize_t safe_write(int fildes, const void *buf, size_t nbyte) +{ + ssize_t rval; + + rval = write(fildes, buf, nbyte); + if (rval == -1 || ((size_t)rval != nbyte)) + { + syslog(LOG_ERR, "write(%d,%p,%zu) failed\n", fildes, buf, rval); + } + + return rval; +} + +/**************************************************************************** + * Name: safe_lseek + ****************************************************************************/ + +off_t safe_lseek(int fd, off_t offset, int whence) +{ + off_t rval; + + rval = lseek(fd, offset, whence); + + if (rval == (off_t)-1) + { + syslog(LOG_ERR, "lseek(%d, %ld, %d) failed\n", fd, + (long int)offset, whence); + } + + return rval; +} + +/**************************************************************************** + * Name: safe_close + ****************************************************************************/ + +int safe_close(int fildes) +{ + int rval; + + rval = close(fildes); + if (rval == -1) + { + syslog(LOG_ERR, "close(%d) failed, errno %d\n", fildes, errno); + fail_msg("test fail !"); + } + + return rval; +} + +/**************************************************************************** + * Function Name: safe_touch + * + * Description: + * This Function is used to touch a file. + * + * Input Parameters: + * file + * lineno + * pathname - name of the file to be created + * mode - mode + ****************************************************************************/ + +void safe_touch(const char *file, const int lineno, const char *pathname, + mode_t mode) +{ + int ret; + + /* Open the file */ + + ret = open(pathname, O_CREAT | O_WRONLY, mode); + + /* Open file fail */ + + if (ret == -1) + { + syslog(LOG_ERR, "Failed to open file '%s' at %s:%d \n", pathname, + file, lineno); + return; + } + + /* Close the file */ + + ret = close(ret); + + /* Close file fail */ + + if (ret == -1) + { + syslog(LOG_ERR, "Failed to close file '%s' at %s:%d \n", pathname, + file, lineno); + return; + } +} + +#ifdef CONFIG_NET + +/**************************************************************************** + * Name: sock_addr + ****************************************************************************/ + +char *sock_addr(const struct sockaddr *sa, socklen_t salen, char *res, + size_t len) +{ + char portstr[8]; + + switch (sa->sa_family) + { + case AF_INET: + { + struct sockaddr_in *sin = (struct sockaddr_in *)sa; + + if (!inet_ntop(AF_INET, &sin->sin_addr, res, len)) + return NULL; + + if (ntohs(sin->sin_port) != 0) + { + snprintf(portstr, sizeof(portstr), ":%d", + ntohs(sin->sin_port)); + strcat(res, portstr); + } + + return res; + } + + case AF_INET6: + { + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; + + res[0] = '['; + if (!inet_ntop(AF_INET6, &sin6->sin6_addr, res + 1, len - 1)) + return NULL; + + if (ntohs(sin6->sin6_port) != 0) + { + snprintf(portstr, sizeof(portstr), "]:%d", + ntohs(sin6->sin6_port)); + strcat(res, portstr); + return res; + } + + return res + 1; + } + + case AF_UNIX: + { + struct sockaddr_un *unp = (struct sockaddr_un *)sa; + + if (unp->sun_path[0] == '\0') + strcpy(res, "(no pathname bound)"); + else + snprintf(res, len, "%s", unp->sun_path); + + return res; + } + + default: + { + snprintf(res, len, "sock_ntop: unknown AF_xxx: %d, len: %d\n", + sa->sa_family, salen); + + return res; + } + } +} + +/**************************************************************************** + * Name: get_unused_port + * * + * Description: + * return port in network byte order. + ****************************************************************************/ + +unsigned short get_unused_port(void(cleanup_fn)(void), + unsigned short family, int type) +{ + int sock; + socklen_t slen; + struct sockaddr_storage _addr; + struct sockaddr *addr = (struct sockaddr *)&_addr; + struct sockaddr_in *addr4 = (struct sockaddr_in *)addr; + struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr; + + switch (family) + { + case AF_INET: + addr4->sin_family = AF_INET; + addr4->sin_port = 0; + addr4->sin_addr.s_addr = INADDR_ANY; + slen = sizeof(*addr4); + break; + + case AF_INET6: + addr6->sin6_family = AF_INET6; + addr6->sin6_port = 0; + addr6->sin6_addr = in6addr_any; + slen = sizeof(*addr6); + break; + + default: + syslog(LOG_ERR, "nknown family\n"); + fail_msg("test fail !"); + return -1; + } + + sock = socket(addr->sa_family, type, 0); + if (sock < 0) + { + syslog(LOG_ERR, "socket failed\n"); + fail_msg("test fail !"); + return -1; + } + + if (bind(sock, addr, slen) < 0) + { + syslog(LOG_ERR, "bind failed\n"); + fail_msg("test fail !"); + return -1; + } + + if (getsockname(sock, addr, &slen) == -1) + { + syslog(LOG_ERR, "getsockname failed\n"); + fail_msg("test fail !"); + return -1; + } + + if (close(sock) == -1) + { + syslog(LOG_ERR, "close failed\n"); + fail_msg("test fail !"); + return -1; + } + + switch (family) + { + case AF_INET: + return addr4->sin_port; + case AF_INET6: + return addr6->sin6_port; + default: + return -1; + } +} + +/**************************************************************************** + * Name: safe_socket + ****************************************************************************/ + +int safe_socket(int domain, int type, int protocol) +{ + int rval; + + rval = socket(domain, type, protocol); + + if (rval < 0) + { + syslog(LOG_ERR, "socket(%d, %d, %d) failed\n", domain, type, + protocol); + fail_msg("test fail !"); + } + + return rval; +} + +/**************************************************************************** + * Name: safe_connect + ****************************************************************************/ + +int safe_connect(int sockfd, const struct sockaddr *addr, + socklen_t addrlen) +{ + int rval; + char buf[128]; + + rval = connect(sockfd, addr, addrlen); + + if (rval < 0) + { + syslog(LOG_ERR, "connect(%d, %s, %d) failed, errno %d\n", sockfd, + sock_addr(addr, addrlen, buf, sizeof(buf)), addrlen, errno); + fail_msg("test fail !"); + } + + return rval; +} + +/**************************************************************************** + * Name: safe_getsockname + ****************************************************************************/ + +int safe_getsockname(int sockfd, struct sockaddr *addr, + socklen_t *addrlen) +{ + int rval; + char buf[128]; + + rval = getsockname(sockfd, addr, addrlen); + + if (rval < 0) + { + syslog(LOG_ERR, "getsockname(%d, %s, %d) failed\n", sockfd, + sock_addr(addr, *addrlen, buf, sizeof(buf)), *addrlen); + } + + return rval; +} + +/**************************************************************************** + * Name: safe_bind + ****************************************************************************/ + +int safe_bind(int socket, const struct sockaddr *address, + socklen_t address_len) +{ + int i; + char buf[128]; + + for (i = 0; i < 120; i++) + { + if (!bind(socket, address, address_len)) + return 0; + + if (errno != EADDRINUSE) + { + syslog(LOG_ERR, "bind(%d, %s, %d) failed\n", socket, + sock_addr(address, address_len, buf, sizeof(buf)), + address_len); + fail_msg("test fail !"); + return -1; + } + + if ((i + 1) % 10 == 0) + { + syslog(LOG_INFO, "address is in use, waited %3i sec\n", i + 1); + } + + sleep(1); + } + + syslog(LOG_ERR, "Failed to bind(%d, %s, %d) after 120 retries\n", + socket, sock_addr(address, address_len, buf, sizeof(buf)), + address_len); + fail_msg("test fail !"); + return -1; +} + +/**************************************************************************** + * Name: safe_listen + ****************************************************************************/ + +int safe_listen(int socket, int backlog) +{ + int rval; + + rval = listen(socket, backlog); + + if (rval < 0) + { + syslog(LOG_ERR, "listen(%d, %d) failed\n", socket, backlog); + } + + return rval; +} + +#endif \ No newline at end of file diff --git a/testing/testsuites/kernel/syscall/include/SyscallTest.h b/testing/testsuites/kernel/syscall/include/SyscallTest.h new file mode 100644 index 000000000..786aea21a --- /dev/null +++ b/testing/testsuites/kernel/syscall/include/SyscallTest.h @@ -0,0 +1,457 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/syscall/include/SyscallTest.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 __SYSCALLTEST_H +#define __SYSCALLTEST_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Functions to help test */ + +int checknames(char *pfilnames, DIR *ddir); +int check_and_report_ftruncatetest(int fd, off_t offset, char data, + off_t trunc_len); +int tst_fill_file(const char *path, char pattern, size_t bs, + size_t bcount); + +char *sock_addr(const struct sockaddr *sa, socklen_t salen, char *res, + size_t len); + +/* @return port in network byte order. + */ + +unsigned short get_unused_port(void(cleanup_fn)(void), + unsigned short family, int type); + +int safe_close(int fildes); + +int safe_socket(int domain, int type, int protocol); + +int safe_connect(int sockfd, const struct sockaddr *addr, + socklen_t addrlen); + +int safe_getsockname(int sockfd, struct sockaddr *addr, + socklen_t *addrlen); + +int safe_bind(int socket, const struct sockaddr *address, + socklen_t address_len); + +int safe_listen(int socket, int backlog); + +int safe_open(const char *pathname, int oflags, ...); + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* The test files generated during the 'syscall-test' are stored in this + * directory + */ + +#define SYSCALL_TEST_DIR "syscall_test_dir" + +#define MOUNT_DIR CONFIG_TESTS_TESTSUITES_MOUNT_DIR + +#define SAFE_OPEN(pathname, oflags, ...) \ + safe_open((pathname), (oflags), ##__VA_ARGS__) + +#define SAFE_FCNTL(fd, cmd, ...) \ + ({ \ + int tst_ret_ = fcntl(fd, cmd, ##__VA_ARGS__); \ + if (tst_ret_ == -1) \ + { \ + syslog(LOG_ERR, "fcntl(%i,%s,...) failed", fd, #cmd); \ + fail_msg("test fail !"); \ + } \ + tst_ret_ == -1 ? 0 : tst_ret_; \ + }) + +#define SAFE_CLOSE(fd) \ + do \ + { \ + safe_close((fd)); \ + fd = -1; \ + } while (0) + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/* quickly fill a test file */ + +int cmtestfillfile(const char *path, char pattern, size_t bs, + size_t bcount); + +/* setup function */ + +int test_nuttx_syscall_test_group_setup(void **state); + +/* teardown function */ + +int test_nuttx_syscall_test_group_teardown(void **state); + +/* tools */ + +int checknames(char *pfilnames, DIR *ddir); +int check_and_report_ftruncatetest(int fd, off_t offset, char data, + off_t trunc_len); +int tst_fill_fd(int fd, char pattern, size_t bs, size_t bcount); +int tst_fill_file(const char *path, char pattern, size_t bs, + size_t bcount); +int safe_open(const char *pathname, int oflags, ...); +ssize_t safe_write(int fildes, const void *buf, size_t nbyte); +off_t safe_lseek(int fd, off_t offset, int whence); +int safe_close(int fildes); +void safe_touch(const char *file, const int lineno, const char *pathname, + mode_t mode); +#ifdef CONFIG_NET +char *sock_addr(const struct sockaddr *sa, socklen_t salen, char *res, + size_t len); +unsigned short get_unused_port(void(cleanup_fn)(void), + unsigned short family, int type); +int safe_socket(int domain, int type, int protocol); +int safe_connect(int sockfd, const struct sockaddr *addr, + socklen_t addrlen); +int safe_getsockname(int sockfd, struct sockaddr *addr, + socklen_t *addrlen); +int safe_bind(int socket, const struct sockaddr *address, + socklen_t address_len); +int safe_listen(int socket, int backlog); +#endif + +/* test case function */ + +/* cases/chdir_test.c + * ***********************************************/ + +void test_nuttx_syscall_chdir01(FAR void **state); +void test_nuttx_syscall_chdir02(FAR void **state); + +/* cases/accept_test.c + * ***********************************************/ + +void test_nuttx_syscall_accept01(FAR void **state); + +/* cases/getitimer_test.c + * ***********************************************/ + +void test_nuttx_syscall_getitimer01(FAR void **state); + +/* cases/clock_gettime_test.c + * ****************************************/ + +void test_nuttx_syscall_clockgettime01(FAR void **state); + +/* cases/clock_nanosleep_test.c + * **************************************/ + +void test_nuttx_syscall_clocknanosleep01(FAR void **state); +void test_nuttx_syscall_clocknanosleep02(FAR void **state); + +/* cases/clock_settime_test.c + * ****************************************/ + +void test_nuttx_syscall_clocksettime01(FAR void **state); + +/* cases/close_test.c + * ************************************************/ + +void test_nuttx_syscall_close01(FAR void **state); +void test_nuttx_syscall_close02(FAR void **state); +void test_nuttx_syscall_close03(FAR void **state); + +/* cases/creat_test.c + * ************************************************/ + +void test_nuttx_syscall_creat01(FAR void **state); +void test_nuttx_syscall_creat02(FAR void **state); + +/* cases/fcntl_test.c + * ************************************************/ + +void test_nuttx_syscall_fcntl01(FAR void **state); +void test_nuttx_syscall_fcntl02(FAR void **state); +void test_nuttx_syscall_fcntl03(FAR void **state); +void test_nuttx_syscall_fcntl04(FAR void **state); +void test_nuttx_syscall_fcntl05(FAR void **state); +void test_nuttx_syscall_fcntl06(FAR void **state); + +/* cases/fsatfs_test.c + * ***********************************************/ + +void test_nuttx_syscall_fstatfs01(FAR void **state); + +/* cases/fsync_test.c + * ************************************************/ + +void test_nuttx_syscall_fsync01(FAR void **state); +void test_nuttx_syscall_fsync02(FAR void **state); +void test_nuttx_syscall_fsync03(FAR void **state); + +/* cases/ftruncate_test.c + * ********************************************/ + +void test_nuttx_syscall_ftruncate01(FAR void **state); + +/* cases/getcwd_test.c + * ***********************************************/ + +void test_nuttx_syscall_getcwd01(FAR void **state); +void test_nuttx_syscall_getcwd02(FAR void **state); + +/* cases/getpid_test.c + * ***********************************************/ + +void test_nuttx_syscall_getpid01(FAR void **state); + +/* cases/getppid_test.c + * **********************************************/ + +void test_nuttx_syscall_getppid01(FAR void **state); + +/* cases/gethostname_test.c + * ******************************************/ + +void test_nuttx_syscall_gethostname01(FAR void **state); + +/* cases/getTimeofday_test.c + * *****************************************/ + +void test_nuttx_syscall_gettimeofday01(FAR void **state); + +/* cases/lseek_test.c + * ************************************************/ + +void test_nuttx_syscall_lseek01(FAR void **state); +void test_nuttx_syscall_lseek07(FAR void **state); + +/* cases/lstat_test.c + * ************************************************/ + +void test_nuttx_syscall_lstat01(FAR void **state); + +/* cases/dup_test.c + * **************************************************/ + +void test_nuttx_syscall_dup01(FAR void **state); +void test_nuttx_syscall_dup02(FAR void **state); +void test_nuttx_syscall_dup03(FAR void **state); +void test_nuttx_syscall_dup04(FAR void **state); +void test_nuttx_syscall_dup05(FAR void **state); + +/* cases/dup2_test.c + * **************************************************/ + +void test_nuttx_syscall_dup201(FAR void **state); +void test_nuttx_syscall_dup202(FAR void **state); + +/* cases/fpathconf_test.c + * *********************************************/ + +void test_nuttx_syscall_fpathconf01(FAR void **state); + +/* cases/getegid_test.c + * ***********************************************/ + +void test_nuttx_syscall_getegid01(FAR void **state); +void test_nuttx_syscall_getegid02(FAR void **state); + +/* cases/geteuid_test.c + * ***********************************************/ + +void test_nuttx_syscall_geteuid01(FAR void **state); +void test_nuttx_syscall_geteuid02(FAR void **state); + +/* cases/getgid_test.c + * ***********************************************/ + +void test_nuttx_syscall_getgid01(FAR void **state); +void test_nuttx_syscall_getgid02(FAR void **state); + +/* cases/getuid_test.c + * ***********************************************/ + +void test_nuttx_syscall_getuid01(FAR void **state); +void test_nuttx_syscall_getuid02(FAR void **state); + +/* cases/pathconf_test.c + * *********************************************/ + +void test_nuttx_syscall_pathconf01(FAR void **state); + +/* cases/pipe_test.c + * *************************************************/ + +void test_nuttx_syscall_pipe01(FAR void **state); +void test_nuttx_syscall_pipe02(FAR void **state); + +/* cases/pread_test.c + * ************************************************/ + +void test_nuttx_syscall_pread01(FAR void **state); + +/* cases/pwrite_test.c + * ***********************************************/ + +void test_nuttx_syscall_pwrite01(FAR void **state); +void test_nuttx_syscall_pwrite02(FAR void **state); + +/* cases/rmdir_test.c + * ************************************************/ + +void test_nuttx_syscall_rmdir01(FAR void **state); +void test_nuttx_syscall_rmdir02(FAR void **state); + +/* ases/syscall_truncate_test.c + * **********************************************/ + +void test_nuttx_syscall_truncate01(FAR void **state); + +/* cases/unlink_test.c + * ***********************************************/ + +void test_nuttx_syscall_unlink01(FAR void **state); + +/* cases/nansleep_test.c + * *********************************************/ + +void test_nuttx_syscall_nansleep01(FAR void **state); +void test_nuttx_syscall_nansleep02(FAR void **state); + +/* cases/time_test.c + * *************************************************/ + +void test_nuttx_syscall_time01(FAR void **state); +void test_nuttx_syscall_time02(FAR void **state); + +/* cases/timer_create_test.c + * *****************************************/ + +void test_nuttx_syscall_timercreate01(FAR void **state); + +/* cases/timer_delete_test.c + * *****************************************/ + +void test_nuttx_syscall_timerdelete01(FAR void **state); + +/* cases/timer_gettime_test.c + * ****************************************/ + +void test_nuttx_syscall_timergettime01(FAR void **state); + +/* cases/mkdir_test.c + * ************************************************/ + +void test_nuttx_syscall_mkdir01(FAR void **state); +void test_nuttx_syscall_mkdir02(FAR void **state); +void test_nuttx_syscall_mkdir03(FAR void **state); + +/* cases/syscall_sched_test.c + * ***********************************************/ + +void test_nuttx_syscall_sched01(FAR void **state); +void test_nuttx_syscall_sched02(FAR void **state); +void test_nuttx_syscall_sched03(FAR void **state); +void test_nuttx_syscall_sched04(FAR void **state); + +/* cases/write_test.c + * ************************************************/ + +void test_nuttx_syscall_write01(FAR void **state); +void test_nuttx_syscall_write02(FAR void **state); +void test_nuttx_syscall_write03(FAR void **state); + +/* cases/read_test.c + * *************************************************/ + +void test_nuttx_syscall_read01(FAR void **state); +void test_nuttx_syscall_read02(FAR void **state); +void test_nuttx_syscall_read03(FAR void **state); +void test_nuttx_syscall_read04(FAR void **state); + +/* cases/symlink_test.c + * **********************************************/ + +void test_nuttx_syscall_symlink01(FAR void **state); +void test_nuttx_syscall_symlink02(FAR void **state); + +/* cases/socket_test.c + * **********************************************/ + +void test_nuttx_syscall_sockettest01(FAR void **state); +void test_nuttx_syscall_sockettest02(FAR void **state); + +/* cases/getpeername_test.c + * **********************************************/ + +void test_nuttx_syscall_connect01(FAR void **state); + +/* cases/getpeername_test.c + * **********************************************/ + +void test_nuttx_syscall_getpeername01(FAR void **state); + +/* cases/getsocketopt_test.c + * **********************************************/ + +void test_nuttx_syscall_getsockopt01(FAR void **state); + +/* cases/recvfrom_test.c + * **********************************************/ + +void test_nuttx_syscall_recvfromtest01(FAR void **state); + +/* cases/setsocketopt01_test.c + * **********************************************/ + +void test_nuttx_syscall_setsockopt01(FAR void **state); + +/* cases/listen_test.c + * **********************************************/ + +void test_nuttx_syscall_listen01(FAR void **state); + +/* cases/socketpair_test.c + * **********************************************/ + +void test_nuttx_syscall_socketpair01(FAR void **state); +void test_nuttx_syscall_socketpair02(FAR void **state); + +/* cases/bind_test.c + * **********************************************/ + +void test_nuttx_syscall_bind01(FAR void **state); + +#endif diff --git a/testing/testsuites/kernel/telephony/cmocka_telephony_test.c b/testing/testsuites/kernel/telephony/cmocka_telephony_test.c new file mode 100644 index 000000000..df304836a --- /dev/null +++ b/testing/testsuites/kernel/telephony/cmocka_telephony_test.c @@ -0,0 +1,2512 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/cmocka_telephony_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 +#include +#include + +#include + +#include "telephony_call_test.h" +#include "telephony_common_test.h" +#include "telephony_data_test.h" +#include "telephony_ims_test.h" +#include "telephony_network_test.h" +#include "telephony_sim_test.h" +#include "telephony_sms_test.h" +#include "telephony_ss_test.h" +#include "telephony_test.h" + +#define REPEAT_TEST_MORE_FOR for (int _i = 0; _i < 10; _i++) +#define REPEAT_TEST_LESS_FOR for (int _i = 0; _i < 3; _i++) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +char *phone_num = NULL; +static uv_async_t g_uv_exit; +static int ready_done; +tapi_context context = NULL; +static int count = 0; +typedef enum +{ + CASE_NORMAL_MODE = 0, + CASE_AIRPLANE_MODE = 1, + CASE_CALL_DIALING = 2, + CASE_MODEM_POWEROFF = 3, +} case_type; + +struct judge_type judge_data; + +char *short_english_text = "test"; +char *long_english_text = + "testtesttesttesttesttesttesttesttesttesttesttest" + "testtesttesttesttesttesttesttesttesttesttesttesttesttest" + "testtesttesttesttesttesttesttesttesttesttesttesttesttesttest" + "testtesttesttesttesttesttesttesttesttesttesttesttesttesttest" + "testtesttesttesttesttesttesttesttesttesttesttesttesttesttest" + "testtesttesttesttesttesttesttesttesttesttesttesttesttesttest" + "testtesttesttesttesttesttesttesttesttesttesttesttesttesttest" + "testtesttesttesttesttesttesttesttesttesttesttesttesttesttest" + "testtesttest"; +char *short_chinese_text = "测试"; +char *long_chinese_text = + "测试测试测试测试测试测试测试测试测试测试" + "测试测试测试测试测试测试测试测试测试测试" + "测试测试测试测试测试测试测试测试测试测试" + "测试测试测试测试测试测试测试测试测试测试" + "测试测试测试测试测试测试测试测试测试测试" + "测试测试测试测试测试测试测试测试测试测试" + "测试测试测试测试测试测试测试测试测试测试" + "测试测试测试测试测试测试测试测试测试测试" + "测试测试测试测试测试测试测试测试测试测试"; + +static void exit_async_cleanup(uv_async_t *handle) +{ + /* let's close the handle and stop the loop here as + * we must be running in the same thread where the `uv_run` is + * NOTE that uv_stop is not thread-safe! + */ + + uv_stop(uv_default_loop()); +} + +tapi_context get_tapi_ctx(void) +{ + return context; +} + +int judge(void) +{ + int timeout = TIMEOUT; + + while (timeout-- > 0) + { + if (judge_data.flag == judge_data.expect) + { + if (judge_data.result != 0) + syslog(LOG_ERR, "result error\n"); + else + syslog(LOG_INFO, "result correct\n"); + + return 0; + } + + sleep(1); + syslog(LOG_INFO, "There is %d second(s) remain.\n", timeout); + } + + syslog(LOG_ERR, "judge timeout\n"); + assert(0); + return -ETIME; +} + +void judge_data_init(void) +{ + judge_data.flag = INVALID_VALUE; + judge_data.expect = INVALID_VALUE; + judge_data.result = INVALID_VALUE; +} + +static void test_nuttx_has_icc_card(void **state) +{ + (void)state; + int ret = tapi_sim_has_icc_card_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_has_icc_card_numerous_times(void **state) +{ + (void)state; + int ret = tapi_sim_multi_has_icc_card_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_sim_operator(void **state) +{ + (void)state; + int ret = tapi_sim_get_sim_operator_test(0, "310260"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_sim_operator_name(void **state) +{ + (void)state; + int ret = tapi_sim_get_sim_operator_name_test(0, "T-Mobile"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_sim_operator_name_numeroustimes(void **state) +{ + (void)state; + int ret = tapi_sim_get_sim_operator_name_numerous(0, "T-Mobile"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_sim_operator_numeroustimes(void **state) +{ + (void)state; + int ret = tapi_sim_multi_get_sim_operator(0, "310260"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_sim_subscriberid(void **state) +{ + (void)state; + int ret = tapi_sim_get_sim_subscriber_id_test(0, "310260000000000"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_sim_subscriberid_numerous_times(void **state) +{ + (void)state; + int ret = + tapi_sim_multi_get_sim_subscriber_id_test(0, "310260000000000"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_iccid(void **state) +{ + (void)state; + int ret = tapi_sim_get_sim_iccid_test(0, "89860318640220133897"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_iccid_numeroustimes(void **state) +{ + (void)state; + int ret = tapi_sim_multi_get_sim_iccid_test(0, "89860318640220133897"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_msisdn(void **state) +{ + (void)state; + int ret = tapi_sim_get_ef_msisdn_test(0, "+15551234567"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_msisdn_numeroustimes(void **state) +{ + (void)state; + int ret = tapi_sim_multi_get_ef_msisdn_test(0, "+15551234567"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_transmit_apdu_inbasic_channel(void **state) +{ + (void)state; + int ret = tapi_transmit_apdu_basic_channel_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_sim_state(void **state) +{ + (void)state; + int ret = tapi_sim_get_state_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_open_logical_channel(void **state) +{ + (void)state; + int ret = tapi_open_logical_channel_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_close_logical_channel(void **state) +{ + (void)state; + int ret = tapi_close_logical_channel_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_logical_channel_open_close_numerous(void **state) +{ + (void)state; + int ret = sim_open_close_logical_channel_numerous(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_transmit_apduin_logical_channel(void **state) +{ + int ret = sim_transmit_apdu_by_logical_channel(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_set_uiccenablement(void **state) +{ + (void)state; + int ret = tapi_sim_set_uicc_enablement_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_uiccenablement(void **state) +{ + (void)state; + int ret = tapi_sim_get_uicc_enablement_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_transmit_apdu_basic_channel(void **state) +{ + (void)state; + int ret = tapi_transmit_apdu_basic_channel_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_enter_pin(void **state) +{ + (void)state; + int ret = tapi_sim_enter_pin_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_change_pin(void **state) +{ + (void)state; + int ret = sim_change_pin_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_lockpin(void **state) +{ + (void)state; + int ret = tapi_sim_lock_pin_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_unlockpin(void **state) +{ + (void)state; + int ret = tapi_sim_unlock_pin_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_load_adnentries(void **state) +{ + (void)state; + int ret = tapi_phonebook_load_adn_entries_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_load_fdnentries(void **state) +{ + (void)state; + int ret = tapi_phonebook_load_fdn_entries_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_insert_fdnentry(void **state) +{ + (void)state; + int ret = tapi_phonebook_insert_fdn_entry_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_update_fdnentry(void **state) +{ + (void)state; + int ret = tapi_phonebook_update_fdn_entry_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_delete_fdnentry(void **state) +{ + (void)state; + int ret = tapi_phonebook_delete_fdn_entry_test(0); + assert_int_equal(ret, OK); +} + +/* static void cmocka_tapi_sim_listen_sim_state_change(void **state) + * { + * int ret = tapi_sim_listen_sim_test(0, 23); + * assert_int_equal(ret, OK); + * } + + * static void cmocka_tapi_sim_listen_sim_uicc_app_enabled_change(void + * **state) + * { + * int ret = tapi_sim_listen_sim_test(0, 24); + * assert_int_equal(ret, OK); + * } + + * static void test_nuttx_load_ecclist(void** state) + * { + * (void)state; + * int ret = tapi_call_load_ecc_list_test(0); + * assert_int_equal(ret, 0); + * } + */ + +static void test_nuttx_set_voice_call_slot(void **state) +{ + (void)state; + int ret = tapi_call_set_default_voicecall_slot_test(0); + assert_int_equal(ret, 0); +} + +static void test_nuttx_get_voice_call_slot(void **state) +{ + (void)state; + int ret = tapi_call_get_default_voicecall_slot_test(0); + assert_int_equal(ret, 0); +} + +static void test_nuttx_clear_voice_call_slotset(void **state) +{ + (void)state; + int ret = call_clear_voicecall_slot_set(); + assert_int_equal(ret, 0); +} + +static void test_nuttx_listen_call(void **state) +{ + (void)state; + int ret = tapi_call_listen_call_test(0); + assert_int_equal(ret, 0); +} + +static void test_nuttx_unlisten_call(void **state) +{ + (void)state; + int ret = tapi_call_unlisten_call_test(); + assert_int_equal(ret, 0); +} + +static void test_nuttx_start_dtmf(void **state) +{ + (void)state; + int ret = tapi_start_dtmf_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_stop_dtmf(void **state) +{ + (void)state; + int ret = tapi_stop_dtmf_test(0); + assert_int_equal(ret, OK); +} + +/* static void test_nuttx_hangup_betweendialingandanswering(void** state) + * { + * (void)state; + * sleep(2); + * int ret = call_hangup_between_dialing_and_answering(0); + * assert_int_equal(ret, 0); + * } + + * static void test_nuttx_answerandhanguptheincomingcall(void ** state) { + * int ret = call_incoming_answer_and_hangup(0); + * assert_int_equal(ret, 0); + * } + + * static void test_nuttx_dial_againafterremotehangup(void **state) { + * int ret = call_dial_after_caller_reject(0); + * assert_int_equal(ret, 0); + * } + + * static void test_nuttx_hangup_callafterremoteanswer(void **state) { + * int ret = call_hangup_after_caller_answer(0); + * assert_int_equal(ret, 0); + * } + + * static void test_nuttx_dial_thenremoteanswerandhangup(void **state) { + * int ret = call_dial_active_and_hangup_by_caller(0); + * assert_int_equal(ret, 0); + * } + + * static void test_nuttx_remotehangupthenincomingnewcall(void **state) { + * int ret = call_dial_caller_reject_and_incoming(0); + * assert_int_equal(ret, 0); + * } + + * static void test_nuttx_remotehangupthendialanother(void **state) { + * int ret = call_dial_caller_reject_and_dial_another(0); + * assert_int_equal(ret, 0); + * } + */ + +static void test_nuttx_hangup_currentcall(void **state) +{ + (void)state; + int ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_callcount(void **state) +{ + (void)state; + int ret = tapi_get_call_count(0); + assert_true(ret >= 0); +} + +static void test_nuttx_dial_number(void **state) +{ + (void)state; + int ret = tapi_dial_number(0); + assert_int_equal(ret, OK); + sleep(2); +} + +static void test_nuttx_dial_eccnumber(void **state) +{ + (void)state; + int ret = tapi_dial_ecc_number(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_dial_long_phonenumber(void **state) +{ + (void)state; + int ret = tapi_dial_with_long_phone_number(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_dial_shot_phonenumber(void **state) +{ + (void)state; + int ret = tapi_dial_with_short_phone_number(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_dial_with_enable_hide_callid(void **state) +{ + (void)state; + int ret = tapi_dial_with_enable_hide_callerid(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_dial_with_disabled_hide_callid(void **state) +{ + (void)state; + int ret = tapi_dial_with_disabled_hide_callerid(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_dial_with_default_hide_callid(void **state) +{ + (void)state; + int ret = tapi_dial_with_default_hide_callerid(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +/* static void test_nuttx_incomingnewcallthenremotehangup(void **state) { + * int ret = call_incoming_and_hangup_by_dialer_before_answer(0); + * assert_int_equal(ret, 0); + * } + */ + +static void test_nuttx_dial_with_areacode(void **state) +{ + (void)state; + int ret = tapi_call_dial_using_phone_number_with_area_code_test(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_dial_with_pausecode(void **state) +{ + (void)state; + int ret = tapi_call_dial_using_phone_number_with_pause_code_test(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_dial_with_waitcode(void **state) +{ + (void)state; + int ret = tapi_call_dial_using_phone_number_with_wait_code_test(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_dial_with_numerouscode(void **state) +{ + (void)state; + int ret = tapi_call_dial_using_phone_number_with_numerous_code_test(0); + assert_int_equal(ret, OK); + sleep(2); + ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, OK); +} + +/* static void test_nuttx_checkstatusin_dialing(void **state) + * { + * int ret = call_check_status_in_dialing(0); + * assert_int_equal(ret, 0); + * } + */ + +/* data testcases */ + +static void test_nuttx_data_load_apn_contexts(void **state) +{ + (void)state; + int ret = tapi_data_load_apn_contexts_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_save_apn_context_supl(void **state) +{ + (void)state; + int ret = tapi_data_save_apn_context_test("0", "3", "supl", "supl", + "2", "2"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_save_apn_context_emergency(void **state) +{ + (void)state; + int ret = tapi_data_save_apn_context_test("0", "7", "emergency", + "emergency", "2", "2"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_save_long_apn_contex(void **state) +{ + (void)state; + int ret = tapi_data_save_apn_context_test( + "0", "1", + "longname-----------------------------------------" + "-----------------------------------------longname", + "cmnet4", "2", "2"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_save_apn_context(void **state) +{ + (void)state; + int ret = tapi_data_save_apn_context_test("0", "1", "cmcc1", "cmnet1", + "2", "2"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_data_remove_apn_context(void **state) +{ + (void)state; + int ret = tapi_data_remove_apn_context_test("0", "/ril_0/context3"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_reset_apn_contexts(void **state) +{ + (void)state; + int ret = tapi_data_reset_apn_contexts_test("0"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_reset_apn_contexts_repeatedly(void **state) +{ + (void)state; + REPEAT_TEST_MORE_FOR + { + int ret = tapi_data_reset_apn_contexts_test("0"); + assert_int_equal(ret, OK); + } +} + +static void test_nuttx_data_edit_apn_name(void **state) +{ + (void)state; + int ret; + ret = tapi_data_save_apn_context_test("0", "1", "cmcc1", "cmnet1", "2", + "2"); + assert_int_equal(ret, OK); + ret = tapi_data_edit_apn_context_test("0", "/ril_0/context3", "1", + "cmname", "cmname", "2", "2"); + assert_int_equal(ret, OK); + ret = tapi_data_load_apn_contexts_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_edit_apn_type(void **state) +{ + (void)state; + int ret = tapi_data_edit_apn_context_test( + "0", "/ril_0/context3", "3", "cmname", "cmname", "2", "2"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_edit_apn_proto(void **state) +{ + (void)state; + int ret = tapi_data_edit_apn_context_test( + "0", "/ril_0/context3", "3", "cmname", "cmname", "0", "2"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_edit_apn_auth(void **state) +{ + (void)state; + int ret = tapi_data_edit_apn_context_test( + "0", "/ril_0/context3", "3", "cmname", "cmname", "0", "0"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_edit_apn_all(void **state) +{ + (void)state; + int ret; + ret = tapi_data_edit_apn_context_test( + "0", "/ril_0/context3", "2", "cmnameall", "cmnameall", "1", "1"); + assert_int_equal(ret, OK); + ret = tapi_data_load_apn_contexts_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_edit_apn_and_remove(void **state) +{ + (void)state; + int ret; + ret = tapi_data_edit_apn_context_test( + "0", "/ril_0/context3", "2", "cmnameall", "cmnameall", "2", "2"); + assert_int_equal(ret, OK); + ret = tapi_data_remove_apn_context_test("0", "/ril_0/context3"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_edit_apn_and_reset(void **state) +{ + (void)state; + int ret; + ret = tapi_data_save_apn_context_test("0", "1", "cmcc1", "cmnet1", "2", + "2"); + assert_int_equal(ret, OK); + ret = tapi_data_edit_apn_context_test("0", "/ril_0/context3", "1", + "cmname", "cmname", "2", "2"); + assert_int_equal(ret, OK); + ret = tapi_data_reset_apn_contexts_test("0"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_edit_apn_repeatedly_and_load(void **state) +{ + (void)state; + int ret; + ret = tapi_data_save_apn_context_test("0", "1", "cmcc1", "cmnet1", "2", + "2"); + assert_int_equal(ret, OK); + ret = tapi_data_edit_apn_context_test("0", "/ril_0/context1", "1", + "cmname11", "cmname", "2", "2"); + assert_int_equal(ret, OK); + ret = tapi_data_edit_apn_context_test("0", "/ril_0/context1", "1", + "cmname22", "cmname", "2", "2"); + assert_int_equal(ret, OK); + ret = tapi_data_edit_apn_context_test("0", "/ril_0/context1", "1", + "cmname33", "cmname", "2", "2"); + assert_int_equal(ret, OK); + ret = tapi_data_load_apn_contexts_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_enable(void **state) +{ + (void)state; + int ret = data_enabled_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_disable(void **state) +{ + (void)state; + int ret = data_disabled_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_enable_repeatedly(void **state) +{ + (void)state; + REPEAT_TEST_MORE_FOR + { + test_nuttx_data_enable(state); + test_nuttx_data_disable(state); + } +} + +static void test_nuttx_data_isenable(void **state) +{ + (void)state; + bool enable = false; + int ret = tapi_data_get_enabled_test(&enable); + assert_int_equal(ret, OK); + assert_int_equal(enable, 1); +} + +static void test_nuttx_data_isdisable(void **state) +{ + (void)state; + bool enable = true; + int ret = tapi_data_get_enabled_test(&enable); + assert_int_equal(ret, OK); + assert_int_equal(enable, 0); +} + +static void test_nuttx_data_register(void **state) +{ + (void)state; + int ret = tapi_data_listen_data_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_unregister(void **state) +{ + (void)state; + int ret = tapi_data_unlisten_data_test(); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_request_network_internet(void **state) +{ + (void)state; + int ret = data_request_network_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_release_network_internet(void **state) +{ + (void)state; + int ret = data_release_network_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_release_network_internet_repeatedly(void **state) +{ + (void)state; + REPEAT_TEST_MORE_FOR + { + test_nuttx_data_release_network_internet(state); + test_nuttx_data_request_network_internet(state); + } +} + +static void test_nuttx_data_request_network_ims(void **state) +{ + (void)state; + int ret = data_request_ims(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_release_network_ims(void **state) +{ + (void)state; + int ret = data_release_ims(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_release_network_ims_repeatedly(void **state) +{ + (void)state; + REPEAT_TEST_MORE_FOR + { + test_nuttx_data_request_network_ims(state); + test_nuttx_data_release_network_ims(state); + } +} + +static void test_nuttx_data_set_preferred_apn(void **state) +{ + (void)state; + int ret = tapi_data_set_preferred_apn_test(0, "/ril_0/context1"); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_get_preferred_apn(void **state) +{ + (void)state; + int ret = tapi_data_get_preferred_apn_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_send_screen_state(void **state) +{ + (void)state; + int ret = tapi_data_send_screen_stat_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_ispsattached(void **state) +{ + (void)state; + int ret = tapi_data_is_ps_attached_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_get_network_type(void **state) +{ + (void)state; + int ret = tapi_data_get_network_type_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_set_default_data_slot(void **state) +{ + (void)state; + int ret = tapi_data_set_default_data_slot_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_get_default_data_slot(void **state) +{ + (void)state; + sleep(2); + int ret = tapi_data_get_default_data_slot_test(); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_set_data_allow(void **state) +{ + (void)state; + int ret = tapi_data_set_data_allow_test(0); + assert_true(ret == OK); +} + +static void test_nuttx_data_get_call_list(void **state) +{ + (void)state; + int ret = data_get_call_list(0); + assert_true(ret == OK); +} + +static void test_nuttx_enable_data_roaming(void **state) +{ + (void)state; + int ret = data_enable_roaming_test(); + assert_true(ret == OK); +} + +static void test_nuttx_disable_data_roaming(void **state) +{ + (void)state; + int ret = data_disable_roaming_test(); + assert_true(ret == OK); +} + +static void test_nuttx_sms_set_service_center_num(void **state) +{ + (void)state; + int ret = sms_set_service_center_number_test(0); + assert_int_equal(ret, 0); +} + +static void test_nuttx_sms_get_service_center_num(void **state) +{ + (void)state; + sleep(5); + int ret = sms_check_service_center_number_test(0); + assert_int_equal(ret, 0); +} + +static void test_nuttx_sms_send_short_message_in_english(void **state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, + short_english_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_sms_send_short_message_in_chinese(void **state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, + short_chinese_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_sms_send_short_data_message_in_english(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, short_english_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_sms_send_short_data_message_in_chinese(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, short_chinese_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_sms_send_long_message_in_english(void **state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, + long_english_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_sms_send_long_message_in_chinese(void **state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, + long_chinese_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_sms_send_long_data_message_in_english(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, long_english_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_sms_send_long_data_message_in_chinese(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, long_chinese_text); + assert_int_equal(ret, 0); +} + +static void +test_nuttx_sms_send_short_english_message_in_dialing +(void **state) +{ + (void)state; + int ret = + sms_send_message_in_dialing(0, phone_num, short_english_text); + assert_int_equal(ret, 0); +} + +static void +test_nuttx_sms_send_short_chinese_message_in_dialing +(void **state) +{ + (void)state; + int ret = + sms_send_message_in_dialing(0, phone_num, short_chinese_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_sms_send_long_english_message_in_dialing(void **state) +{ + (void)state; + int ret = sms_send_message_in_dialing(0, phone_num, long_english_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_sms_send_long_chinese_message_in_dialing(void **state) +{ + (void)state; + int ret = sms_send_message_in_dialing(0, phone_num, long_chinese_text); + assert_int_equal(ret, 0); +} + +static void +test_nuttx_sms_send_short_english_data_message_in_dialing(void **state) +{ + (void)state; + int ret = sms_send_data_message_in_dialing(0, phone_num, + short_english_text, 0); + assert_int_equal(ret, 0); +} + +static void +test_nuttx_sms_send_short_chinese_data_message_in_dialing(void **state) +{ + (void)state; + int ret = sms_send_data_message_in_dialing(0, phone_num, + short_chinese_text, 0); + assert_int_equal(ret, 0); +} + +static void +test_nuttx_sms_send_long_english_data_message_in_dialing +(void **state) +{ + (void)state; + int ret = sms_send_data_message_in_dialing(0, phone_num, + long_english_text, 0); + assert_int_equal(ret, 0); +} + +static void +test_nuttx_sms_send_long_chinese_data_message_in_dialing +(void **state) +{ + (void)state; + int ret = sms_send_data_message_in_dialing(0, phone_num, + long_chinese_text, 0); + assert_int_equal(ret, 0); +} + +static void test_nuttx_send_english_message_in_voice_imscap(void **state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, + short_english_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_send_chinese_message_in_voice_imscap(void **state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, + short_chinese_text); + assert_int_equal(ret, 0); +} + +static void +test_nuttx_send_long_english_message_in_voice_imscap +(void **state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, + long_english_text); + assert_int_equal(ret, 0); +} + +static void +test_nuttx_send_long_chinese_message_in_voice_imscap +(void **state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, + long_chinese_text); + assert_int_equal(ret, 0); +} + +static void +test_nuttx_send_english_data_message_in_voice_imscap +(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, short_english_text); + assert_int_equal(ret, 0); +} + +static void +test_nuttx_send_chinese_data_message_in_voice_imscap +(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, short_chinese_text); + assert_int_equal(ret, 0); +} + +static void +test_nuttx_send_long_english_data_message_in_voice_imscap(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, long_english_text); + assert_int_equal(ret, 0); +} + +static void +test_nuttx_send_long_chinese_data_message_in_voice_imscap(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, long_chinese_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_send_english_message_in_smsimscap(void **state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, + short_english_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_send_chinese_message_in_smsimscap(void **state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, + short_chinese_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_send_long_english_message_in_smsimscap(void **state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, + long_english_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_send_long_chinese_message_in_smsimscap(void **state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, + long_chinese_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_send_english_data_message_in_smsimscap(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, short_english_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_send_chinese_data_message_in_smsimscap(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, short_chinese_text); + assert_int_equal(ret, 0); +} + +static void +test_nuttx_send_long_english_data_message_in_smsimscap +(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, long_english_text); + assert_int_equal(ret, 0); +} + +static void +test_nuttx_send_long_chinese_data_message_in_smsimscap +(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, long_chinese_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_send_english_message_insmsvoicecap(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, short_english_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_send_chinese_message_insmsvoicecap(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, short_chinese_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_send_long_english_message_insmsvoicecap(void **state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, + long_english_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_send_long_chinese_message_insmsvoicecap(void **state) +{ + (void)state; + int ret = sms_send_message_test(get_tapi_ctx(), 0, phone_num, + long_chinese_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_send_english_data_message_in_smsvoicecap(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, short_english_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_send_chinese_data_message_in_smsvoicecap(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, short_chinese_text); + assert_int_equal(ret, 0); +} + +static void +test_nuttx_send_long_english_data_message_in_smsvoicecap(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, long_english_text); + assert_int_equal(ret, 0); +} + +static void +test_nuttx_send_long_chinese_data_message_in_smsvoicecap(void **state) +{ + (void)state; + int ret = + sms_send_data_message_test(0, phone_num, 0, long_chinese_text); + assert_int_equal(ret, 0); +} + +static void test_nuttx_set_sms_default_slot(void **state) +{ + (void)state; + int ret = tapi_sms_set_default_slot(get_tapi_ctx(), 0); + sleep(5); + assert_int_equal(ret, 0); +} + +static void test_nuttx_get_sms_default_slot(void **state) +{ + (void)state; + int result = -1; + int ret = tapi_sms_get_default_slot(context, &result); + syslog(LOG_INFO, "%s, ret: %d, result: %d", __func__, ret, result); + assert_int_equal(ret, 0); + assert_int_equal(result, 0); +} + +static void test_nuttx_sms_set_cell_broad_cast_power(void **state) +{ + (void)state; + int ret = tapi_sms_set_cell_broadcast_power_on(get_tapi_ctx(), 0, 1); + sleep(5); + assert_int_equal(ret, 0); +} + +static void test_nuttx_sms_get_cell_broad_cast_power(void **state) +{ + (void)state; + bool result = false; + int ret = + tapi_sms_get_cell_broadcast_power_on(get_tapi_ctx(), 0, &result); + syslog(LOG_INFO, "%s, ret: %d, result: %d", __func__, 0, (int)result); + assert_int_equal(ret, 0); + assert_int_equal(result, 1); +} + +static void test_nuttx_sms_set_cell_broad_cast_topics(void **state) +{ + (void)state; + int ret = tapi_sms_set_cell_broadcast_topics(get_tapi_ctx(), 0, "1"); + sleep(5); + assert_int_equal(ret, 0); +} + +static void test_nuttx_sms_get_cell_broad_cast_topics(void **state) +{ + (void)state; + char *result = NULL; + int ret = + tapi_sms_get_cell_broadcast_topics(get_tapi_ctx(), 0, &result); + assert_int_equal(ret, 0); + assert_int_equal(strcmp(result, "1"), 0); +} + +static void test_nuttx_net_select_auto(void **state) +{ + (void)state; + int ret = tapi_net_select_auto_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_net_select_manual(void **state) +{ + (void)state; + sleep(4); + int ret = tapi_net_select_manual_test(0, "310", "260", "lte"); + sleep(4); + assert_int_equal(ret, OK); +} + +static void test_nuttx_net_scan(void **state) +{ + (void)state; + int ret = tapi_net_scan_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_net_get_serving_cellinfos(void **state) +{ + (void)state; + int ret = tapi_net_get_serving_cellinfos_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_net_get_neighbouring_cellinfos(void **state) +{ + (void)state; + int ret = tapi_net_get_neighbouring_cellinfos_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_net_registration_info(void **state) +{ + (void)state; + int ret = tapi_net_registration_info_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_net_get_operator_name(void **state) +{ + (void)state; + int ret = tapi_net_get_operator_name_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_net_query_signal_strength(void **state) +{ + (void)state; + int ret = tapi_net_query_signalstrength_test(0); + assert_int_equal(ret, OK); +} + +/* static void test_nuttx_net_set_cellinfo_listrate(void **state) + * { + * int ret = tapi_net_set_cell_info_list_rate_test(0, 10); + * assert_int_equal(ret, OK); + * } + */ + +static void test_nuttx_net_getvoiceregistered(void **state) +{ + (void)state; + int ret = tapi_net_get_voice_registered_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_voicenwtype(void **state) +{ + (void)state; + tapi_network_type type = NETWORK_TYPE_UNKNOWN; + int ret = + tapi_network_get_voice_network_type(get_tapi_ctx(), 0, &type); + syslog(LOG_INFO, "%s, ret: %d, type: %d", __func__, ret, (int)type); + assert_int_equal(ret, OK); + assert_int_equal((int)type, 13); +} + +static void test_nuttx_get_voiceroaming(void **state) +{ + (void)state; + bool value = true; + int ret = tapi_network_is_voice_roaming(get_tapi_ctx(), 0, &value); + syslog(LOG_INFO, "%s, ret: %d, value: %d", __func__, ret, (int)value); + assert_int_equal(ret, OK); + assert_int_equal((int)value, 0); +} + +/* modem */ + +static void test_nuttx_modem_getimei(void **state) +{ + (void)state; + int ret = tapi_get_imei_test(0); + assert_int_equal(ret, OK); +} + +/* static void test_nuttx_modem_set_umts_pref_net_mode(void** state) + * { + * // defalut rat mode is NETWORK_PREF_NET_TYPE_LTE_GSM_WCDMA (9) + * tapi_pref_net_mode set_value = NETWORK_PREF_NET_TYPE_UMTS; + * int ret = tapi_set_pref_net_mode_test(0, set_value); + * assert_int_equal(ret, OK); + * } + + * static void test_nuttx_modem_set_gsm_only_pref_net_mode(void** state) + * { + * tapi_pref_net_mode set_value = NETWORK_PREF_NET_TYPE_GSM_ONLY; + * int ret = tapi_set_pref_net_mode_test(0, set_value); + * assert_int_equal(ret, OK); + * } + + * static void test_nuttx_modem_set_wcdma_only_pref_netmode(void** state) + * { + * tapi_pref_net_mode set_value = NETWORK_PREF_NET_TYPE_WCDMA_ONLY; + * int ret = tapi_set_pref_net_mode_test(0, set_value); + * assert_int_equal(ret, OK); + * } + + * static void test_nuttx_modem_set_lte_only_pref_net_mode(void** state) + * { + * tapi_pref_net_mode set_value = NETWORK_PREF_NET_TYPE_LTE_ONLY; + * int ret = tapi_set_pref_net_mode_test(0, set_value); + * assert_int_equal(ret, OK); + * } + + * static void test_nuttx_modem_set_lte_wcdma_pref_net_mode(void** state) + * { + * tapi_pref_net_mode set_value = NETWORK_PREF_NET_TYPE_LTE_WCDMA; + * int ret = tapi_set_pref_net_mode_test(0, set_value); + * assert_int_equal(ret, OK); + * } + + * static void test_nuttx_modem_set_lte_gsmwcdma_pref_net_mode(void** state) + * { + * tapi_pref_net_mode set_value = + * NETWORK_PREF_NET_TYPE_LTE_GSM_WCDMA; int ret = + * tapi_set_pref_net_mode_test(0, set_value); assert_int_equal(ret, + * OK); + * } + */ + +static void test_nuttx_modem_get_pref_net_mode(void **state) +{ + sleep(5); + tapi_pref_net_mode get_value = NETWORK_PREF_NET_TYPE_ANY; + int ret = tapi_get_pref_net_mode_test(0, &get_value); + assert_int_equal(ret, OK); +} + +static void test_nuttx_modem_set_radio_poweron(void **state) +{ + (void)state; + int ret = tapi_set_radio_power_test(0, 1); + assert_int_equal(ret, OK); + sleep(10); +} + +static void test_nuttx_modem_set_radio_poweroff(void **state) +{ + (void)state; + int ret = tapi_set_radio_power_test(0, 0); + assert_int_equal(ret, OK); + sleep(10); +} + +static void test_nuttx_modem_set_radio_poweron_off_repeatedly(void **state) +{ + (void)state; + REPEAT_TEST_LESS_FOR + { + test_nuttx_modem_set_radio_poweron(state); + test_nuttx_modem_set_radio_poweroff(state); + } +} + +static void test_nuttx_get_modem_enable_status(void **state) +{ + (void)state; + int get_state = 1; + int ret = tapi_get_modem_status_test(0, &get_state); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_modem_dsiable_status(void **state) +{ + (void)state; + int get_state = 0; + int ret = tapi_get_modem_status_test(0, &get_state); + assert_int_equal(ret, OK); +} + +static void test_nuttx_modem_enable(void **state) +{ + (void)state; + int ret = tapi_enable_modem_test(0, 1); + assert_int_equal(ret, OK); + sleep(10); +} + +static void test_nuttx_modem_disable(void **state) +{ + (void)state; + int ret = tapi_enable_modem_test(0, 0); + assert_int_equal(ret, OK); + sleep(10); +} + +static void test_nuttx_modem_enable_disable_repeatedly(void **state) +{ + (void)state; + REPEAT_TEST_LESS_FOR + { + test_nuttx_modem_enable(state); + test_nuttx_get_modem_enable_status(state); + test_nuttx_modem_disable(state); + test_nuttx_get_modem_dsiable_status(state); + } +} + +static void test_nuttx_modem_register(void **state) +{ + (void)state; + int ret = tapi_modem_register_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_modem_unregister(void **state) +{ + (void)state; + int ret = tapi_modem_unregister_test(); + assert_true(ret == OK); +} + +static void test_nuttx_get_modem_revision(void **state) +{ + int ret; + ret = tapi_get_modem_revision_test(0); + assert_int_equal(ret, OK); +} + +/* static void test_nuttx_ims_servicestatus(void** state) + * { + * case_type* mode = *state; + * // device default info.reg_info is 1, info.ext_info is 5 + * REPEAT_TEST_LESS_FOR + * { + * tapi_ims_registration_info info; + * int ret = tapi_ims_set_service_status_test(0, 1); + * if (*mode == CASE_NORMAL_MODE || *mode == CASE_AIRPLANE_MODE + * || *mode == CASE_CALL_DIALING) { + * assert_int_equal(ret, OK); + * ret = tapi_ims_get_registration_test(0, &info); + * assert_int_equal(ret, OK); + * assert_int_equal(info.reg_info, 1); + * assert_int_equal(info.ext_info, 1); + * } else { + * assert_int_equal(ret, -5); + * } + * sleep(1); + + * ret = tapi_ims_set_service_status_test(0, 5); + * if (*mode == CASE_NORMAL_MODE || *mode == CASE_AIRPLANE_MODE + * || *mode == CASE_CALL_DIALING) { + * assert_int_equal(ret, OK); + * ret = tapi_ims_get_registration_test(0, &info); + * assert_int_equal(ret, OK); + * assert_int_equal(info.reg_info, 1); + * assert_int_equal(info.ext_info, 5); + * sleep(1); + * } else { + * assert_int_equal(ret, -5); + * } + * } + * } + + * *static void test_nuttx_modem_dialcall(void** state) + * { + * int slot_id = 0; + * int ret1 = tapi_call_listen_call_test(slot_id); + * int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + * int ret = ret1 || ret2; + * assert_int_equal(ret, OK); + * sleep(2); + * } + + * static void test_nuttx_modem_hangupcall(void** state) + * { + * int slot_id = 0; + * int ret1 = tapi_call_hanup_current_call_test(slot_id); + * int ret2 = tapi_call_unlisten_call_test(); + * int ret = ret1 || ret2; + * assert_int_equal(ret, OK); + * } + */ + +static void test_nuttx_modem_invokeoem_shot_ril_request_raw(void **state) +{ + int ret = tapi_invoke_oem_ril_request_raw_test(0, "01A0B023", 4); + assert_int_equal(ret, OK); +} + +static void test_nuttx_modem_invokeoem_long_ril_request_raw(void **state) +{ + int ret = tapi_invoke_oem_ril_request_raw_test( + 0, "01A0B02301A0B02301A0B02301A0B02301A0B02301", 21); + assert_int_equal(ret, OK); +} + +static void test_nuttx_modem_invokeoem_seperate_ril_request_raw(void **state) +{ + int ret = tapi_invoke_oem_ril_request_raw_test(0, "10|22", 2); + assert_int_equal(ret, OK); +} + +static void test_nuttx_modem_invokeoem_normal_ril_request_raw(void **state) +{ + int ret = tapi_invoke_oem_ril_request_raw_test(0, "01A0B023", 2); + assert_int_equal(ret, OK); +} + +static void test_nuttx_modem_invokeoem_ril_request_atcmdstrings(void **state) +{ + char *req_data = "AT+CPIN?"; + int ret = tapi_invoke_oem_ril_request_strings_test(0, req_data, 1); + assert_int_equal(ret, OK); +} + +static void +test_nuttx_modem_invokeoem_ril_request_notatcmdstrings(void **state) +{ + /* not AT cmd */ + + char *req_data = "10|22"; + int ret = tapi_invoke_oem_ril_request_strings_test(0, req_data, 2); + assert_int_equal(ret, OK); +} + +static void test_nuttx_modem_invokeoem_ril_request_hexstrings(void **state) +{ + char *req_data = "0x10|0x01"; + int ret = tapi_invoke_oem_ril_request_strings_test(0, req_data, 2); + assert_int_equal(ret, OK); +} + +/* static void test_nuttx_modem_invokeoemrilrequestlongstrings(void **state) + * { + * char req_data[MAX_INPUT_ARGS_LEN]; + + * // test error + * // FIXME: tapi_invoke_oem_ril_request_strings_test interface + * buffer overflow + * // when req_data len is 21, current max len is 20 + * strcpy(req_data, + * "10|22|10|22|10|22|10|22|10|22|10|22|10|22|10|22|10|22|10|22"); + * int ret = tapi_invoke_oem_ril_request_strings_test(0, req_data, + * 20); assert_int_equal(ret, -1); + + * // strcpy(req_data, "10|22"); + * // // FIXME: _dbus_check_is_valid_utf8 is called by + * dbus_message_iter_append_basic + * // // cannot handle \0 in char * string; + * // ret = tapi_invoke_oem_ril_request_strings_test(0, req_data, + * 20); + * // assert_int_equal(ret, -1); + * } + + * static void cmocka_set_radio_power_on_off_test(void **state) + * { + * for(int i = 0; i < 3; i++) + * { + * tapi_set_radio_power_test(0, 0); + * sleep(1); + * tapi_set_radio_power_test(0, 1); + * sleep(1); + * } + * int ret = tapi_get_radio_power_test(0); + * assert_int_equal(ret, 1); + * } + */ + +static void test_nuttx_ims_listen(void **state) +{ + (void)state; + int ret = tapi_ims_listen_ims_test(0); + assert_int_equal(ret, 0); +} + +static void test_nuttx_ims_turnon(void **state) +{ + (void)state; + int ret = tapi_ims_turn_on_test(0); + assert_int_equal(ret, 0); +} + +static void test_nuttx_ims_get_registration(void **state) +{ + (void)state; + int ret = tapi_ims_get_registration_test(0); + assert_int_equal(ret, 0); +} + +static void test_nuttx_ims_getenabled(void **state) +{ + (void)state; + int ret = tapi_ims_get_enabled_test(0); + assert_int_equal(ret, 0); +} + +static void test_nuttx_ims_set_service_status(void **state) +{ + (void)state; + int ret = tapi_ims_set_service_status_test(0, 5); + assert_int_equal(ret, 0); + sleep(5); +} + +static void test_nuttx_ims_set_sms_cap(void **state) +{ + (void)state; + int ret = tapi_ims_set_service_status_test(0, 4); + assert_int_equal(ret, 0); +} + +static void test_nuttx_ims_setsmsvoicecap(void **state) +{ + (void)state; + int ret = tapi_ims_set_service_status_test(0, 5); + assert_int_equal(ret, 0); +} + +static void test_nuttx_ims_reset_ims_cap(void **state) +{ + (void)state; + int ret = tapi_ims_set_service_status_test(0, 1); + assert_int_equal(ret, 0); +} + +static void test_nuttx_ims_turnoff(void **state) +{ + (void)state; + int ret = tapi_ims_turn_off_test(0); + assert_int_equal(ret, 0); +} + +static void test_nuttx_ims_turnonoff(void **state) +{ + (void)state; + REPEAT_TEST_LESS_FOR + { + test_nuttx_ims_turnon(state); + test_nuttx_ims_getenabled(state); + test_nuttx_ims_get_registration(state); + test_nuttx_ims_turnoff(state); + } +} + +static void test_nuttx_ssregister(void **state) +{ + (void)state; + int ret = tapi_listen_ss_test(0); + assert_int_equal(ret, 0); +} + +static void test_nuttx_ssunregister(void **state) +{ + (void)state; + int ret = tapi_unlisten_ss_test(); + assert_int_equal(ret, 0); +} + +static void test_nuttx_request_call_barring(void **state) +{ + (void)state; + int ret = tapi_ss_request_call_barring_test(0); + assert_int_equal(ret, 0); +} + +static void test_nuttx_set_call_barring(void **state) +{ + (void)state; + int ret = tapi_ss_set_call_barring_option_test(0, "AI", "1234"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_get_call_barring(void **state) +{ + (void)state; + sleep(5); + int ret = + tapi_ss_get_call_barring_option_test(0, "VoiceIncoming", "always"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_change_call_barring_password(void **state) +{ + (void)state; + int ret = tapi_ss_change_call_barring_password_test(0, "1234", "2345"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_reset_call_barring_password(void **state) +{ + (void)state; + int ret = tapi_ss_change_call_barring_password_test(0, "2345", "1234"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_disable_all_in_coming(void **state) +{ + (void)state; + int ret = tapi_ss_disable_all_incoming_test(0, "1234"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_disable_all_out_going(void **state) +{ + (void)state; + int ret = tapi_ss_disable_all_outgoing_test(0, "1234"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_disable_all_call_barrings(void **state) +{ + (void)state; + int ret = tapi_ss_disable_all_call_barrings_test(0, "1234"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_set_call_forwarding_unconditional(void **state) +{ + (void)state; + int ret = tapi_ss_set_call_forwarding_option_test(0, 0, "10086"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_get_call_forwarding_unconditional(void **state) +{ + (void)state; + int ret = tapi_ss_get_call_forwarding_option_test(0, 0); + assert_int_equal(ret, 0); +} + +static void test_nuttx_clear_call_forwarding_unconditional(void **state) +{ + (void)state; + int ret = tapi_ss_set_call_forwarding_option_test(0, 0, "\0"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_set_call_forwarding_busy(void **state) +{ + (void)state; + int ret = tapi_ss_set_call_forwarding_option_test(0, 1, "10086"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_get_call_forwarding_busy(void **state) +{ + (void)state; + int ret = tapi_ss_get_call_forwarding_option_test(0, 1); + assert_int_equal(ret, 0); +} + +static void test_nuttx_clear_call_forwarding_busy(void **state) +{ + (void)state; + int ret = tapi_ss_set_call_forwarding_option_test(0, 1, "\0"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_set_call_forwarding_noreply(void **state) +{ + (void)state; + int ret = tapi_ss_set_call_forwarding_option_test(0, 2, "10086"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_get_call_forwarding_noreply(void **state) +{ + (void)state; + int ret = tapi_ss_get_call_forwarding_option_test(0, 2); + assert_int_equal(ret, 0); +} + +static void test_nuttx_clear_call_forwarding_noreply(void **state) +{ + (void)state; + int ret = tapi_ss_set_call_forwarding_option_test(0, 2, "\0"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_set_call_forwarding_not_reachable(void **state) +{ + (void)state; + int ret = tapi_ss_set_call_forwarding_option_test(0, 3, "10086"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_get_call_forwarding_not_reachable(void **state) +{ + (void)state; + int ret = tapi_ss_get_call_forwarding_option_test(0, 3); + assert_int_equal(ret, 0); +} + +static void test_nuttx_clear_call_forwarding_not_reachable(void **state) +{ + (void)state; + int ret = tapi_ss_set_call_forwarding_option_test(0, 3, "\0"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_enable_call_waiting(void **state) +{ + (void)state; + int ret = tapi_ss_set_call_waiting_test(0, true); + assert_int_equal(ret, 0); +} + +static void test_nuttx_get_enable_call_waiting(void **state) +{ + (void)state; + int ret = tapi_ss_get_call_waiting_test(0, true); + assert_int_equal(ret, 0); +} + +static void test_nuttx_disable_call_waiting(void **state) +{ + (void)state; + int ret = tapi_ss_set_call_waiting_test(0, false); + assert_int_equal(ret, 0); +} + +static void test_nuttx_get_disable_call_waiting(void **state) +{ + (void)state; + int ret = tapi_ss_get_call_waiting_test(0, false); + assert_int_equal(ret, 0); +} + +static void test_nuttx_enablefdn(void **state) +{ + (void)state; + int ret = tapi_ss_enable_fdn_test(0, true, "1234"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_get_fdn_enabled(void **state) +{ + (void)state; + int ret = tapi_ss_query_fdn_test(0, true); + assert_int_equal(ret, 0); +} + +static void test_nuttx_disable_fdn(void **state) +{ + (void)state; + int ret = tapi_ss_enable_fdn_test(0, false, "1234"); + assert_int_equal(ret, 0); +} + +static void test_nuttx_get_fdn_disabled(void **state) +{ + (void)state; + int ret = tapi_ss_query_fdn_test(0, false); + assert_int_equal(ret, 0); +} + +static void on_tapi_client_ready(const char *client_name, + void *user_data) +{ + if (client_name != NULL) + syslog(LOG_DEBUG, "tapi is ready for %s\n", client_name); + + ready_done = 1; +} + +static void *run_test_loop(void *args) +{ + uv_run(uv_default_loop(), UV_RUN_DEFAULT); + uv_loop_close(uv_default_loop()); + + return NULL; +} + +static void tapi_cb(tapi_async_result *result) +{ + if (result->msg_id == EVENT_MODEM_ENABLE_DONE && result->status == OK) + { + ready_done = 1; + } + else if (result->msg_id == MSG_VOICE_REGISTRATION_STATE_CHANGE_IND) + { + ready_done = 1; + } + else + { + ready_done = -1; + } +} + +static int wait_for_async_result(const char *str) +{ + while (ready_done != 1) + { + if (ready_done == -1 || count >= 10) + { + syslog(LOG_ERR, "%s\n", str); + tapi_close(context); + return -1; + } + else + { + sleep(1); + count++; + } + } + + return 0; +} + +int main(int argc, char *argv[]) +{ +#ifndef CONFIG_TEST_PHONE_NUMBER + printf("Please config phone number in Kconfig!\n"); + return 0; +#endif + int ret; + + ready_done = 0; + phone_num = CONFIG_TEST_PHONE_NUMBER; + + context = tapi_open("vela.telephony.test", on_tapi_client_ready, NULL); + if (context == NULL) + { + return 0; + } + + /* initialize async handler before the thread creation + * in case we have some race issues + */ + + uv_async_init(uv_default_loop(), &g_uv_exit, exit_async_cleanup); + + pthread_t thread; + pthread_attr_t attr; + struct sched_param param; + pthread_attr_init(&attr); + param.sched_priority = 100; + pthread_attr_setschedparam(&attr, ¶m); + pthread_attr_setstacksize(&attr, 262144); + ret = pthread_create(&thread, &attr, run_test_loop, NULL); + if (ret != 0) + { + tapi_close(context); + return ret; + } + + while (!ready_done) + sleep(1); + + ready_done = 0; + count = 0; + tapi_enable_modem(get_tapi_ctx(), 0, EVENT_MODEM_ENABLE_DONE, 1, + tapi_cb); + ret = wait_for_async_result( + "modem failed to start and cannot be tested"); + if (ret == -1) + return -1; + + ready_done = 0; + count = 0; + tapi_network_register(get_tapi_ctx(), 0, + MSG_VOICE_REGISTRATION_STATE_CHANGE_IND, NULL, + tapi_cb); + ret = wait_for_async_result( + "Network connection failure, unable to perform the test."); + if (ret == -1) + return -1; + + const struct CMUnitTest simtestsuites[] = + { + cmocka_unit_test(test_nuttx_has_icc_card), + cmocka_unit_test(test_nuttx_has_icc_card_numerous_times), + cmocka_unit_test(test_nuttx_get_sim_operator_name), + cmocka_unit_test(test_nuttx_get_sim_operator_name_numeroustimes), + cmocka_unit_test(test_nuttx_get_sim_operator), + cmocka_unit_test(test_nuttx_get_sim_operator_numeroustimes), + cmocka_unit_test(test_nuttx_get_sim_subscriberid), + cmocka_unit_test(test_nuttx_get_sim_subscriberid_numerous_times), + cmocka_unit_test(test_nuttx_get_iccid), + cmocka_unit_test(test_nuttx_get_iccid_numeroustimes), + cmocka_unit_test(test_nuttx_get_msisdn), + cmocka_unit_test(test_nuttx_get_msisdn_numeroustimes), + cmocka_unit_test(test_nuttx_transmit_apdu_inbasic_channel), + cmocka_unit_test(test_nuttx_open_logical_channel), + cmocka_unit_test(test_nuttx_close_logical_channel), + cmocka_unit_test(test_nuttx_logical_channel_open_close_numerous), + cmocka_unit_test(test_nuttx_transmit_apduin_logical_channel), + cmocka_unit_test(test_nuttx_set_uiccenablement), + cmocka_unit_test(test_nuttx_get_uiccenablement), + cmocka_unit_test(test_nuttx_transmit_apdu_basic_channel), + cmocka_unit_test(test_nuttx_get_sim_state), + cmocka_unit_test(test_nuttx_enter_pin), + cmocka_unit_test(test_nuttx_change_pin), + cmocka_unit_test(test_nuttx_lockpin), + cmocka_unit_test(test_nuttx_unlockpin), + cmocka_unit_test(test_nuttx_load_adnentries), + cmocka_unit_test(test_nuttx_load_fdnentries), + cmocka_unit_test(test_nuttx_insert_fdnentry), + cmocka_unit_test(test_nuttx_update_fdnentry), + cmocka_unit_test(test_nuttx_delete_fdnentry), + }; + + const struct CMUnitTest calltestsuites[] = + { + cmocka_unit_test(test_nuttx_listen_call), + cmocka_unit_test(test_nuttx_dial_eccnumber), + cmocka_unit_test(test_nuttx_dial_long_phonenumber), + cmocka_unit_test(test_nuttx_dial_shot_phonenumber), + cmocka_unit_test(test_nuttx_dial_with_enable_hide_callid), + cmocka_unit_test(test_nuttx_dial_with_disabled_hide_callid), + cmocka_unit_test(test_nuttx_dial_with_default_hide_callid), + cmocka_unit_test(test_nuttx_dial_with_areacode), + cmocka_unit_test(test_nuttx_dial_with_pausecode), + cmocka_unit_test(test_nuttx_dial_with_waitcode), + cmocka_unit_test(test_nuttx_dial_with_numerouscode), + cmocka_unit_test(test_nuttx_start_dtmf), + cmocka_unit_test(test_nuttx_stop_dtmf), + cmocka_unit_test(test_nuttx_dial_number), + cmocka_unit_test(test_nuttx_get_callcount), + cmocka_unit_test(test_nuttx_hangup_currentcall), + + /* cmocka_unit_test(test_nuttx_load_ecclist), */ + + cmocka_unit_test(test_nuttx_set_voice_call_slot), + cmocka_unit_test(test_nuttx_get_voice_call_slot), + cmocka_unit_test(test_nuttx_clear_voice_call_slotset), + cmocka_unit_test(test_nuttx_unlisten_call), + +#if 0 + /* hangup between dialing and answering */ + + cmocka_unit_test(test_nuttx_hangup_betweendialingandanswering), + + /* answer the incoming call then hangup it */ + + cmocka_unit_test(test_nuttx_answerandhanguptheincomingcall), + + /* dial again after remote hangup */ + + /* cmocka_unit_test(test_nuttx_dial_againafterremotehangup), */ + + /* hangup after remote answer */ + + cmocka_unit_test(test_nuttx_hangup_callafterremoteanswer), + + /* dial then remote answer and hangup */ + + /* cmocka_unit_test(test_nuttx_dial_thenremoteanswerandhangup), */ + + /* remote hangup then incoming new call */ + + /* cmocka_unit_test(test_nuttx_remotehangupthenincomingnewcall), */ + + /* remote hangup then dial another */ + + /* cmocka_unit_test(test_nuttx_remotehangupthendialanother), */ + + /* dial with numerous hide call id */ + + cmocka_unit_test(test_nuttx_dial_with_numeroushidecallid), + + /* incoming new call then remote hangup */ + + /* cmocka_unit_test(test_nuttx_incomingnewcallthenremotehangup), */ + + /* dial using a phone number with area code */ + + cmocka_unit_test(test_nuttx_dial_with_areacode), +#endif + }; + + const struct CMUnitTest datatestsuites[] = + { + cmocka_unit_test(test_nuttx_data_register), + cmocka_unit_test(test_nuttx_data_unregister), + cmocka_unit_test(test_nuttx_data_register), + cmocka_unit_test(test_nuttx_data_load_apn_contexts), + cmocka_unit_test(test_nuttx_data_save_apn_context), + cmocka_unit_test(test_nuttx_data_remove_apn_context), + cmocka_unit_test(test_nuttx_data_reset_apn_contexts), + cmocka_unit_test(test_nuttx_data_reset_apn_contexts_repeatedly), + cmocka_unit_test(test_nuttx_data_edit_apn_name), + cmocka_unit_test(test_nuttx_data_edit_apn_type), + cmocka_unit_test(test_nuttx_data_edit_apn_proto), + cmocka_unit_test(test_nuttx_data_edit_apn_auth), + cmocka_unit_test(test_nuttx_data_edit_apn_all), + cmocka_unit_test(test_nuttx_data_edit_apn_and_remove), + cmocka_unit_test(test_nuttx_data_edit_apn_and_reset), + cmocka_unit_test(test_nuttx_data_edit_apn_repeatedly_and_load), + cmocka_unit_test(test_nuttx_data_reset_apn_contexts), + cmocka_unit_test(test_nuttx_data_enable), + cmocka_unit_test(test_nuttx_data_isenable), + cmocka_unit_test(test_nuttx_data_disable), + cmocka_unit_test(test_nuttx_data_isdisable), + cmocka_unit_test(test_nuttx_data_enable_repeatedly), + cmocka_unit_test(test_nuttx_data_enable), + cmocka_unit_test(test_nuttx_data_release_network_internet), + cmocka_unit_test(test_nuttx_data_request_network_internet), + cmocka_unit_test(test_nuttx_data_release_network_internet_repeatedly), + cmocka_unit_test(test_nuttx_data_disable), + cmocka_unit_test(test_nuttx_data_request_network_ims), + cmocka_unit_test(test_nuttx_data_release_network_ims), + cmocka_unit_test(test_nuttx_data_release_network_ims_repeatedly), + cmocka_unit_test(test_nuttx_data_save_apn_context_supl), + cmocka_unit_test(test_nuttx_data_save_apn_context_emergency), + cmocka_unit_test(test_nuttx_data_reset_apn_contexts), + cmocka_unit_test(test_nuttx_data_set_preferred_apn), + cmocka_unit_test(test_nuttx_data_get_preferred_apn), + cmocka_unit_test(test_nuttx_data_send_screen_state), + cmocka_unit_test(test_nuttx_data_get_network_type), + cmocka_unit_test(test_nuttx_data_ispsattached), + cmocka_unit_test(test_nuttx_data_set_default_data_slot), + cmocka_unit_test(test_nuttx_data_get_default_data_slot), + cmocka_unit_test(test_nuttx_data_set_data_allow), + cmocka_unit_test(test_nuttx_data_get_call_list), + cmocka_unit_test(test_nuttx_data_save_long_apn_contex), + cmocka_unit_test(test_nuttx_data_reset_apn_contexts), + cmocka_unit_test(test_nuttx_enable_data_roaming), + cmocka_unit_test(test_nuttx_disable_data_roaming), + cmocka_unit_test(test_nuttx_data_unregister), + }; + + const struct CMUnitTest smstestsuites[] = + { + cmocka_unit_test(test_nuttx_listen_call), + cmocka_unit_test(test_nuttx_ims_listen), + cmocka_unit_test(test_nuttx_ims_turnon), + cmocka_unit_test(test_nuttx_sms_set_service_center_num), + cmocka_unit_test(test_nuttx_sms_get_service_center_num), + cmocka_unit_test(test_nuttx_sms_send_short_message_in_english), + cmocka_unit_test(test_nuttx_sms_send_short_message_in_chinese), + cmocka_unit_test(test_nuttx_sms_send_short_data_message_in_english), + cmocka_unit_test(test_nuttx_sms_send_short_data_message_in_chinese), + cmocka_unit_test(test_nuttx_sms_send_long_message_in_english), + cmocka_unit_test(test_nuttx_sms_send_long_message_in_chinese), + cmocka_unit_test(test_nuttx_sms_send_long_data_message_in_english), + cmocka_unit_test(test_nuttx_sms_send_long_data_message_in_chinese), + cmocka_unit_test(test_nuttx_sms_send_short_english_message_in_dialing), + cmocka_unit_test(test_nuttx_sms_send_short_chinese_message_in_dialing), + cmocka_unit_test(test_nuttx_sms_send_long_english_message_in_dialing), + cmocka_unit_test(test_nuttx_sms_send_long_chinese_message_in_dialing), + cmocka_unit_test + (test_nuttx_sms_send_short_english_data_message_in_dialing), + cmocka_unit_test + (test_nuttx_sms_send_short_chinese_data_message_in_dialing), + cmocka_unit_test + (test_nuttx_sms_send_long_english_data_message_in_dialing), + cmocka_unit_test + (test_nuttx_sms_send_long_chinese_data_message_in_dialing), + cmocka_unit_test(test_nuttx_send_english_message_in_voice_imscap), + cmocka_unit_test(test_nuttx_send_chinese_message_in_voice_imscap), + cmocka_unit_test(test_nuttx_send_long_english_message_in_voice_imscap), + cmocka_unit_test(test_nuttx_send_long_chinese_message_in_voice_imscap), + cmocka_unit_test(test_nuttx_send_english_data_message_in_voice_imscap), + cmocka_unit_test(test_nuttx_send_chinese_data_message_in_voice_imscap), + cmocka_unit_test + (test_nuttx_send_long_english_data_message_in_voice_imscap), + cmocka_unit_test + (test_nuttx_send_long_chinese_data_message_in_voice_imscap), + cmocka_unit_test(test_nuttx_ims_set_sms_cap), + cmocka_unit_test(test_nuttx_send_english_message_in_smsimscap), + cmocka_unit_test(test_nuttx_send_chinese_message_in_smsimscap), + cmocka_unit_test(test_nuttx_send_long_english_message_in_smsimscap), + cmocka_unit_test(test_nuttx_send_long_chinese_message_in_smsimscap), + cmocka_unit_test(test_nuttx_send_english_data_message_in_smsimscap), + cmocka_unit_test(test_nuttx_send_chinese_data_message_in_smsimscap), + cmocka_unit_test + (test_nuttx_send_long_english_data_message_in_smsimscap), + cmocka_unit_test + (test_nuttx_send_long_chinese_data_message_in_smsimscap), + cmocka_unit_test(test_nuttx_ims_setsmsvoicecap), + cmocka_unit_test(test_nuttx_send_english_message_insmsvoicecap), + cmocka_unit_test(test_nuttx_send_chinese_message_insmsvoicecap), + cmocka_unit_test(test_nuttx_send_long_english_message_insmsvoicecap), + cmocka_unit_test(test_nuttx_send_long_chinese_message_insmsvoicecap), + cmocka_unit_test(test_nuttx_send_english_data_message_in_smsvoicecap), + cmocka_unit_test(test_nuttx_send_chinese_data_message_in_smsvoicecap), + cmocka_unit_test + (test_nuttx_send_long_english_data_message_in_smsvoicecap), + cmocka_unit_test + (test_nuttx_send_long_chinese_data_message_in_smsvoicecap), + cmocka_unit_test(test_nuttx_set_sms_default_slot), + cmocka_unit_test(test_nuttx_get_sms_default_slot), + cmocka_unit_test(test_nuttx_sms_set_cell_broad_cast_power), + cmocka_unit_test(test_nuttx_sms_get_cell_broad_cast_power), + cmocka_unit_test(test_nuttx_sms_set_cell_broad_cast_topics), + cmocka_unit_test(test_nuttx_sms_get_cell_broad_cast_topics), + cmocka_unit_test(test_nuttx_ims_reset_ims_cap), + cmocka_unit_test(test_nuttx_ims_turnoff), + cmocka_unit_test(test_nuttx_unlisten_call), + }; + + const struct CMUnitTest nettestsuites[] = + { + cmocka_unit_test(test_nuttx_net_select_manual), + cmocka_unit_test(test_nuttx_net_select_auto), + cmocka_unit_test(test_nuttx_net_scan), + cmocka_unit_test(test_nuttx_net_get_serving_cellinfos), + cmocka_unit_test(test_nuttx_net_get_neighbouring_cellinfos), + cmocka_unit_test(test_nuttx_net_registration_info), + cmocka_unit_test(test_nuttx_net_get_operator_name), + cmocka_unit_test(test_nuttx_net_query_signal_strength), + + /* cmocka_unit_test(test_nuttx_net_set_cellinfo_listrate), */ + + cmocka_unit_test(test_nuttx_net_getvoiceregistered), + cmocka_unit_test(test_nuttx_get_voicenwtype), + cmocka_unit_test(test_nuttx_get_voiceroaming), + }; + + const struct CMUnitTest imstestsuits[] = + { + cmocka_unit_test(test_nuttx_ims_turnon), + cmocka_unit_test(test_nuttx_ims_get_registration), + cmocka_unit_test(test_nuttx_ims_getenabled), + cmocka_unit_test(test_nuttx_ims_set_service_status), + cmocka_unit_test(test_nuttx_ims_reset_ims_cap), + cmocka_unit_test(test_nuttx_ims_turnoff), + cmocka_unit_test(test_nuttx_ims_turnonoff), + }; + + const struct CMUnitTest sstestsuits[] = + { + cmocka_unit_test(test_nuttx_ssregister), + cmocka_unit_test(test_nuttx_ssunregister), + cmocka_unit_test(test_nuttx_request_call_barring), + cmocka_unit_test(test_nuttx_set_call_barring), + cmocka_unit_test(test_nuttx_get_call_barring), + cmocka_unit_test(test_nuttx_change_call_barring_password), + cmocka_unit_test(test_nuttx_reset_call_barring_password), + cmocka_unit_test(test_nuttx_disable_all_in_coming), + cmocka_unit_test(test_nuttx_disable_all_out_going), + cmocka_unit_test(test_nuttx_disable_all_call_barrings), + cmocka_unit_test(test_nuttx_set_call_forwarding_unconditional), + cmocka_unit_test(test_nuttx_get_call_forwarding_unconditional), + cmocka_unit_test(test_nuttx_clear_call_forwarding_unconditional), + cmocka_unit_test(test_nuttx_set_call_forwarding_busy), + cmocka_unit_test(test_nuttx_get_call_forwarding_busy), + cmocka_unit_test(test_nuttx_clear_call_forwarding_busy), + cmocka_unit_test(test_nuttx_set_call_forwarding_noreply), + cmocka_unit_test(test_nuttx_get_call_forwarding_noreply), + cmocka_unit_test(test_nuttx_clear_call_forwarding_noreply), + cmocka_unit_test(test_nuttx_set_call_forwarding_not_reachable), + cmocka_unit_test(test_nuttx_get_call_forwarding_not_reachable), + cmocka_unit_test(test_nuttx_clear_call_forwarding_not_reachable), + cmocka_unit_test(test_nuttx_enable_call_waiting), + cmocka_unit_test(test_nuttx_get_enable_call_waiting), + cmocka_unit_test(test_nuttx_disable_call_waiting), + cmocka_unit_test(test_nuttx_get_disable_call_waiting), + cmocka_unit_test(test_nuttx_enablefdn), + cmocka_unit_test(test_nuttx_get_fdn_enabled), + cmocka_unit_test(test_nuttx_disable_fdn), + cmocka_unit_test(test_nuttx_get_fdn_disabled), + }; + + const struct CMUnitTest commontestsuites[] = + { + cmocka_unit_test(test_nuttx_modem_getimei), + + /* cmocka_unit_test(test_nuttx_modem_set_umts_pref_net_mode), + * cmocka_unit_test(test_nuttx_modem_set_gsm_only_pref_net_mode), + * cmocka_unit_test(test_nuttx_modem_set_wcdma_only_pref_netmode), + * cmocka_unit_test(test_nuttx_modem_set_lte_only_pref_net_mode), + * cmocka_unit_test(test_nuttx_modem_set_lte_wcdma_pref_net_mode), + * cmocka_unit_test(test_nuttx_modem_set_lte_gsmwcdma_pref_net_mode), + */ + + cmocka_unit_test(test_nuttx_modem_get_pref_net_mode), + cmocka_unit_test(test_nuttx_modem_register), + cmocka_unit_test(test_nuttx_modem_unregister), + cmocka_unit_test(test_nuttx_modem_invokeoem_shot_ril_request_raw), + cmocka_unit_test(test_nuttx_modem_invokeoem_long_ril_request_raw), + cmocka_unit_test(test_nuttx_modem_invokeoem_normal_ril_request_raw), + cmocka_unit_test(test_nuttx_modem_invokeoem_seperate_ril_request_raw), + cmocka_unit_test(test_nuttx_modem_invokeoem_ril_request_atcmdstrings), + cmocka_unit_test + (test_nuttx_modem_invokeoem_ril_request_notatcmdstrings), + cmocka_unit_test(test_nuttx_modem_invokeoem_ril_request_hexstrings), + cmocka_unit_test(test_nuttx_ims_listen), + cmocka_unit_test(test_nuttx_get_modem_revision), + cmocka_unit_test(test_nuttx_modem_disable), + cmocka_unit_test(test_nuttx_get_modem_dsiable_status), + cmocka_unit_test(test_nuttx_modem_enable_disable_repeatedly), + cmocka_unit_test(test_nuttx_modem_enable), + cmocka_unit_test(test_nuttx_get_modem_enable_status), + cmocka_unit_test(test_nuttx_modem_set_radio_poweroff), + cmocka_unit_test(test_nuttx_modem_set_radio_poweron_off_repeatedly), + cmocka_unit_test(test_nuttx_modem_set_radio_poweron), + cmocka_unit_test(test_nuttx_modem_disable), + + /* cmocka_unit_test_setup_teardown( + * test_nuttx_modem_set_radio_poweron_off_repeatedly, + * setup_normal_mode, free_mode), + * // Airplane mode + * cmocka_unit_test(test_nuttx_modem_set_radio_poweroff), + * cmocka_unit_test_setup_teardown(test_nuttx_ims_servicestatus, + * // setup_airplane_mode, free_mode), + * cmocka_unit_test(test_nuttx_modem_set_radio_poweron), + + * // Call dialing + * cmocka_unit_test(test_nuttx_modem_dialcall), + * // TODO: enable disable modem + * cmocka_unit_test(test_nuttx_modem_set_radio_poweron), + * // cmocka_unit_test_setup_teardown(test_nuttx_ims_servicestatus, + * // setup_call_dialing, free_mode), + * cmocka_unit_test(test_nuttx_modem_hangupcall), + + * // Modem poweroff + + * cmocka_unit_test_setup_teardown(test_nuttx_ims_servicestatus, + * // setup_modem_poweroff, free_mode), + * cmocka_unit_test_setup_teardown( + * test_nuttx_modem_set_radio_poweron_off_repeatedly, + * setup_modem_poweroff, free_mode), + * // FIXME: Cannot enable because of RADIO_NOT_AVAILABLE + * // cmocka_unit_test(test_nuttx_modem_enable), + */ + }; + + sleep(3); + cmocka_run_group_tests(simtestsuites, NULL, NULL); + + cmocka_run_group_tests(calltestsuites, NULL, NULL); + + cmocka_run_group_tests(datatestsuites, NULL, NULL); + + cmocka_run_group_tests(smstestsuites, NULL, NULL); + + cmocka_run_group_tests(nettestsuites, NULL, NULL); + + cmocka_run_group_tests(imstestsuits, NULL, NULL); + + cmocka_run_group_tests(sstestsuits, NULL, NULL); + + cmocka_run_group_tests(commontestsuites, NULL, NULL); + + tapi_close(context); + uv_async_send(&g_uv_exit); + + pthread_join(thread, NULL); + uv_close((uv_handle_t *)&g_uv_exit, NULL); + + return 0; +} diff --git a/testing/testsuites/kernel/telephony/product_telephony_test.c b/testing/testsuites/kernel/telephony/product_telephony_test.c new file mode 100644 index 000000000..e2c01f61d --- /dev/null +++ b/testing/testsuites/kernel/telephony/product_telephony_test.c @@ -0,0 +1,434 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/product_telephony_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 +#include +#include + +#include + +#include "telephony_call_test.h" +#include "telephony_common_test.h" +#include "telephony_data_test.h" +#include "telephony_ims_test.h" +#include "telephony_network_test.h" +#include "telephony_sim_test.h" +#include "telephony_sms_test.h" +#include "telephony_test.h" + +#define REPEAT_TEST_MORE_FOR for (int _i = 0; _i < 10; _i++) +#define REPEAT_TEST_LESS_FOR for (int _i = 0; _i < 3; _i++) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +char *phone_num = NULL; +static uv_async_t g_uv_exit; +static int ready_done; +tapi_context context = NULL; +typedef enum +{ + CASE_NORMAL_MODE = 0, + CASE_AIRPLANE_MODE = 1, + CASE_CALL_DIALING = 2, + CASE_MODEM_POWEROFF = 3, +} case_type; + +int modem_status = -1; + +struct judge_type judge_data; + +static void exit_async_cleanup(uv_async_t *handle) +{ + /* let's close the handle and stop the loop here as + * we must be running in the same thread where the `uv_run` is + * NOTE that uv_stop is not thread-safe! + */ + + uv_stop(uv_default_loop()); +} + +tapi_context get_tapi_ctx(void) +{ + return context; +} + +int judge(void) +{ + int timeout = TIMEOUT; + + while (timeout-- > 0) + { + if (judge_data.flag == judge_data.expect) + { + if (judge_data.result != 0) + syslog(LOG_ERR, "result error\n"); + else + syslog(LOG_INFO, "result correct\n"); + + return 0; + } + + sleep(1); + syslog(LOG_INFO, "There is %d second(s) remain.\n", timeout); + } + + syslog(LOG_ERR, "judge timeout\n"); + assert(0); + return -ETIME; +} + +void judge_data_init(void) +{ + judge_data.flag = INVALID_VALUE; + judge_data.expect = INVALID_VALUE; + judge_data.result = INVALID_VALUE; +} + +static void test_nuttx_data_enable(void **state) +{ + (void)state; + int ret = data_enabled_test(0); + assert_int_equal(ret, OK); + sleep(20); +} + +static void test_nuttx_data_disable(void **state) +{ + (void)state; + int ret = data_disabled_test(0); + assert_int_equal(ret, OK); + sleep(20); +} + +static void test_nuttx_data_isenable(void **state) +{ + (void)state; + bool enable = false; + sleep(5); + int ret = tapi_data_get_enabled_test(&enable); + assert_int_equal(ret, OK); + assert_int_equal(enable, 1); +} + +static void test_nuttx_data_isdisable(void **state) +{ + (void)state; + bool enable = true; + sleep(5); + int ret = tapi_data_get_enabled_test(&enable); + assert_int_equal(ret, OK); + assert_int_equal(enable, 0); +} + +static void test_nuttx_data_register(void **state) +{ + (void)state; + int ret = tapi_data_listen_data_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_unregister(void **state) +{ + (void)state; + int ret = tapi_data_unlisten_data_test(); + assert_int_equal(ret, OK); +} + +/* modem */ + +static void test_nuttx_modem_getimei(void **state) +{ + (void)state; + int ret = tapi_get_imei_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_modemenablestatus(void **state) +{ + (void)state; + int get_state = 1; + int ret = tapi_get_modem_status_test(0, &get_state); + assert_int_equal(ret, OK); +} + +static void test_nuttx_get_modemdsiablestatus(void **state) +{ + (void)state; + int get_state = 0; + int ret = tapi_get_modem_status_test(0, &get_state); + assert_int_equal(ret, OK); +} + +static void test_nuttx_modem_enable(void **state) +{ + (void)state; + int ret = tapi_enable_modem_test(0, 1); + assert_int_equal(ret, OK); + sleep(60); +} + +static void test_nuttx_modem_disable(void **state) +{ + (void)state; + int ret = tapi_enable_modem_test(0, 0); + assert_int_equal(ret, OK); + sleep(10); +} + +static void test_nuttx_modem_enabledisablerepeatedly(void **state) +{ + REPEAT_TEST_LESS_FOR + { + test_nuttx_modem_enable(state); + sleep(60); + test_nuttx_get_modemenablestatus(state); + test_nuttx_modem_disable(state); + sleep(60); + test_nuttx_get_modemdsiablestatus(state); + } +} + +static void test_nuttx_modem_register(void **state) +{ + (void)state; + int ret = tapi_modem_register_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_modem_unregister(void **state) +{ + (void)state; + int ret = tapi_modem_unregister_test(); + assert_true(ret == OK); +} + +static void test_nuttx_get_modemrevision(void **state) +{ + int ret; + ret = tapi_get_modem_revision_test(0); + assert_int_equal(ret, OK); +} + +static void modem_status_cb(tapi_async_result *result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) + { + syslog(LOG_DEBUG, "%s msg id : %d result err, return.\n", __func__, + result->msg_id); + assert(0); + return; + } + + if (result->msg_id == EVENT_MODEM_STATUS_QUERY_DONE) + { + modem_status = result->arg2; + } +} + +static void on_tapi_client_ready(const char *client_name, + void *user_data) +{ + if (client_name != NULL) + syslog(LOG_DEBUG, "tapi is ready for %s\n", client_name); + + ready_done = 1; +} + +static void test_nuttx_has_icc_card(void **state) +{ + (void)state; + int ret = tapi_sim_has_icc_card_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_has_icc_card_numerous_times(void **state) +{ + (void)state; + int ret = tapi_sim_multi_has_icc_card_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_net_getoperatorname(void **state) +{ + (void)state; + int ret = tapi_net_get_operator_name_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_data_ispsattached(void **state) +{ + (void)state; + int ret = tapi_data_is_ps_attached_test(0); + assert_int_equal(ret, OK); +} + +static void test_nuttx_listen_call(void **state) +{ + (void)state; + int ret = tapi_call_listen_call_test(0); + assert_int_equal(ret, 0); +} + +static void test_nuttx_unlisten_call(void **state) +{ + (void)state; + int ret = tapi_call_unlisten_call_test(); + assert_int_equal(ret, 0); +} + +static void test_nuttx_dial_call(void **state) +{ + sleep(30); + (void)state; + int ret = tapi_call_dial_test(0, "10086", 0); + assert_int_equal(ret, 0); + sleep(30); +} + +static void test_nuttx_hangup_call(void **state) +{ + (void)state; + int ret = tapi_call_hanup_current_call_test(0); + assert_int_equal(ret, 0); + sleep(30); +} + +static void *run_test_loop(void *args) +{ + uv_run(uv_default_loop(), UV_RUN_DEFAULT); + uv_loop_close(uv_default_loop()); + + return NULL; +} + +int main(int argc, char *argv[]) +{ +#ifndef CONFIG_TEST_PHONE_NUMBER + printf("Please config phone number in Kconfig!\n"); + return 0; +#endif + int ret; + + ready_done = 0; + phone_num = CONFIG_TEST_PHONE_NUMBER; + + context = tapi_open("vela.telephony.test", on_tapi_client_ready, NULL); + if (context == NULL) + { + return 0; + } + + /* initialize async handler before the thread creation + * in case we have some race issues + */ + + uv_async_init(uv_default_loop(), &g_uv_exit, exit_async_cleanup); + + pthread_t thread; + pthread_attr_t attr; + struct sched_param param; + pthread_attr_init(&attr); + param.sched_priority = 100; + pthread_attr_setschedparam(&attr, ¶m); + pthread_attr_setstacksize(&attr, 262144); + ret = pthread_create(&thread, &attr, run_test_loop, NULL); + if (ret != 0) + { + tapi_close(context); + return ret; + } + + while (!ready_done) + sleep(1); + + const struct CMUnitTest stabilitytestsuites[] = + { + cmocka_unit_test(test_nuttx_listen_call), + cmocka_unit_test(test_nuttx_modem_register), + cmocka_unit_test(test_nuttx_modem_unregister), + cmocka_unit_test(test_nuttx_data_register), + cmocka_unit_test(test_nuttx_data_unregister), + cmocka_unit_test(test_nuttx_data_register), + cmocka_unit_test(test_nuttx_modem_enable), + cmocka_unit_test(test_nuttx_get_modemenablestatus), + cmocka_unit_test(test_nuttx_has_icc_card), + cmocka_unit_test(test_nuttx_has_icc_card_numerous_times), + cmocka_unit_test(test_nuttx_data_ispsattached), + cmocka_unit_test(test_nuttx_net_getoperatorname), + cmocka_unit_test(test_nuttx_modem_getimei), + cmocka_unit_test(test_nuttx_get_modemrevision), + cmocka_unit_test(test_nuttx_dial_call), + cmocka_unit_test(test_nuttx_hangup_call), + cmocka_unit_test(test_nuttx_data_enable), + cmocka_unit_test(test_nuttx_data_isenable), + cmocka_unit_test(test_nuttx_data_disable), + cmocka_unit_test(test_nuttx_data_isdisable), + cmocka_unit_test(test_nuttx_data_unregister), + cmocka_unit_test(test_nuttx_modem_disable), + cmocka_unit_test(test_nuttx_get_modemdsiablestatus), + cmocka_unit_test(test_nuttx_modem_enabledisablerepeatedly), + cmocka_unit_test(test_nuttx_unlisten_call), + }; + + sleep(120); + tapi_get_modem_status(get_tapi_ctx(), 0, EVENT_MODEM_STATUS_QUERY_DONE, + modem_status_cb); + sleep(30); + if (modem_status == -1) + { + assert(0); + } + else if (modem_status == 1) + { + tapi_data_enable_data(get_tapi_ctx(), false); + sleep(30); + tapi_enable_modem(get_tapi_ctx(), 0, EVENT_MODEM_ENABLE_DONE, + false, NULL); + sleep(60); + } + + cmocka_run_group_tests(stabilitytestsuites, NULL, NULL); + + tapi_close(context); + uv_async_send(&g_uv_exit); + + pthread_join(thread, NULL); + uv_close((uv_handle_t *)&g_uv_exit, NULL); + + return 0; +} diff --git a/testing/testsuites/kernel/telephony/telephony_call_test.c b/testing/testsuites/kernel/telephony/telephony_call_test.c new file mode 100644 index 000000000..36cefb8cb --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_call_test.c @@ -0,0 +1,3284 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_call_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 "telephony_call_test.h" +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +extern char *phone_num; +extern int sock_fd; +char modem_command_buf[512]; + +extern struct judge_type judge_data; + +static struct +{ + int call_state_watch_id; + int call_emergencylist_change_watch_id; + int call_ring_back_tone_change_watch_id; + int call_slot_change_watch_id; + int ss_call_barring_watch_id; + int ss_ussd_property_change_watch_id; + int ss_ussd_notification_received_watch_id; + int ss_ussd_request_received_watch_id; + int default_voicecall_slot; +} global_data; + +static struct +{ + char call_id[101]; + char network_name[101]; + unsigned int call_count; + int two_call_state_sum; + char hold_call_id[101]; + int current_call_state; +} test_case_data; + +static void test_case_data_init(void) +{ + memset(&test_case_data, 0, sizeof(test_case_data)); + test_case_data.current_call_state = -1; +} + +static int incoming_call(char *incoming_number) +{ + return 0; +} + +static int hangup_remote_call(int call_id) +{ + return 0; +} + +static void call_state_change_cb(tapi_async_result *result) +{ + tapi_call_info *call_info; + + syslog(LOG_DEBUG, "%s : %d\n", __func__, result->status); + call_info = (tapi_call_info *)result->data; + + syslog(LOG_DEBUG, "call changed call_id : %s\n", call_info->call_id); + syslog(LOG_DEBUG, "call state: %d \n", call_info->state); + syslog(LOG_DEBUG, "call IncomingLine: %s \n", + call_info->incoming_line); + syslog(LOG_DEBUG, "call Name: %s \n", call_info->name); + syslog(LOG_DEBUG, "call StartTime: %s \n", call_info->start_time); + syslog(LOG_DEBUG, "call Multiparty: %d \n", call_info->multiparty); + syslog(LOG_DEBUG, "call RemoteHeld: %d \n", call_info->remote_held); + syslog(LOG_DEBUG, "call RemoteMultiparty: %d \n", + call_info->remote_multiparty); + syslog(LOG_DEBUG, "call Information: %s \n", call_info->info); + syslog(LOG_DEBUG, "call Icon: %d \n", call_info->icon); + syslog(LOG_DEBUG, "call Emergency: %d \n", + call_info->is_emergency_number); + syslog(LOG_DEBUG, "call disconnect_reason: %d \n\n", + call_info->disconnect_reason); + + if (judge_data.expect == CALL_LOCAL_HANGUP) + { + if (call_info->disconnect_reason == + CALL_DISCONNECT_REASON_LOCAL_HANGUP) + { + judge_data.result = 0; + } + + judge_data.flag = CALL_LOCAL_HANGUP; + } + + else if (judge_data.expect == CALL_STATE_CHANGE_TO_ACTIVE) + { + if (call_info->state == 0) + { + judge_data.result = 0; + } + + judge_data.flag = CALL_STATE_CHANGE_TO_ACTIVE; + } + + else if (judge_data.expect == CALL_REMOTE_HANGUP) + { + if (call_info->disconnect_reason == + CALL_DISCONNECT_REASON_REMOTE_HANGUP) + { + judge_data.result = 0; + } + + judge_data.flag = CALL_REMOTE_HANGUP; + } + + else if (judge_data.expect == NEW_CALL_INCOMING || + judge_data.expect == NEW_CALL_WAITING || + judge_data.expect == INCOMING_CALL_WITH_NETWORK_NAME) + { + char *call_id = call_info->call_id; + strncpy(test_case_data.call_id, call_id, strlen(call_id)); + test_case_data.call_id[strlen(call_id)] = '\0'; + + if (judge_data.expect == INCOMING_CALL_WITH_NETWORK_NAME) + { + char *network_name = call_info->name; + strncpy(test_case_data.network_name, network_name, + strlen(network_name)); + test_case_data.network_name[strlen(network_name)] = '\0'; + judge_data.result = 0; + judge_data.flag = INCOMING_CALL_WITH_NETWORK_NAME; + } + + else + { + if (judge_data.expect == NEW_CALL_INCOMING && + call_info->state == 4) + { + judge_data.result = 0; + judge_data.flag = NEW_CALL_INCOMING; + } + + else if (judge_data.expect == NEW_CALL_WAITING && + call_info->state == 5) + { + judge_data.result = 0; + judge_data.flag = NEW_CALL_WAITING; + } + } + } + + else if (judge_data.expect == HANGUP_DUE_TO_NETWORK_EXCEPTION) + { + if (call_info->disconnect_reason == + CALL_DISCONNECT_REASON_NETWORK_HANGUP) + { + judge_data.result = 0; + } + + judge_data.flag = judge_data.expect; + } + + else if (judge_data.expect == CALL_STATE_CHANGE_TO_HOLD) + { + if (call_info->state == 1) + { + judge_data.result = 0; + } + + judge_data.flag = judge_data.expect; + } +} + +static void tele_call_ecc_list_async_fun(tapi_async_result *result) +{ + int status = result->status; + int list_length = result->arg2; + ecc_info *ret = result->data; + + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "status : %d\n", status); + syslog(LOG_DEBUG, "list length: %d\n", list_length); + + if (result->status == 0) + { + for (int i = 0; i < list_length; i++) + { + syslog(LOG_DEBUG, "ecc number : %s,%u,%u \n", ret[i].ecc_num, + ret[i].category, ret[i].condition); + } + } +} + +static void tele_call_manager_call_async_fun(tapi_async_result *result) +{ + tapi_call_info *call_info; + + syslog(LOG_DEBUG, "%s : %d\n", __func__, result->status); + if (result->status != OK) + { + syslog(LOG_ERR, "async result error in %s", __func__); + return; + } + + if (result->msg_id == MSG_CALL_ADD_MESSAGE_IND) + { + call_info = (tapi_call_info *)result->data; + + syslog(LOG_DEBUG, "call added call_id : %s\n", call_info->call_id); + syslog(LOG_DEBUG, "call state: %d \n", call_info->state); + syslog(LOG_DEBUG, "call IncomingLine: %s \n", + call_info->incoming_line); + syslog(LOG_DEBUG, "call Name: %s \n", call_info->name); + syslog(LOG_DEBUG, "call StartTime: %s \n", call_info->start_time); + syslog(LOG_DEBUG, "call Multiparty: %d \n", call_info->multiparty); + syslog(LOG_DEBUG, "call RemoteHeld: %d \n", + call_info->remote_held); + syslog(LOG_DEBUG, "call RemoteMultiparty: %d \n", + call_info->remote_multiparty); + syslog(LOG_DEBUG, "call Information: %s \n", call_info->info); + syslog(LOG_DEBUG, "call Icon: %d \n", call_info->icon); + syslog(LOG_DEBUG, "call Emergency: %d \n\n", + call_info->is_emergency_number); + } + + else if (result->msg_id == MSG_CALL_REMOVE_MESSAGE_IND) + { + syslog(LOG_DEBUG, "call removed call_id : %s\n", + (char *)result->data); + } + + else if (result->msg_id == MSG_CALL_RING_BACK_TONE_IND) + { + syslog(LOG_DEBUG, "ring back tone status : %d\n", result->arg2); + } + + else if (result->msg_id == MSG_CALL_FORWARDED_MESSAGE_IND) + { + syslog(LOG_DEBUG, "call Forwarded: %s\n", (char *)result->data); + } + + else if (result->msg_id == MSG_CALL_BARRING_ACTIVE_MESSAGE_IND) + { + syslog(LOG_DEBUG, "call BarringActive: %s\n", + (char *)result->data); + } + + else if (result->msg_id == MSG_DEFAULT_VOICECALL_SLOT_CHANGE_IND) + { + if (judge_data.expect == MSG_DEFAULT_VOICECALL_SLOT_CHANGE_IND) + { + syslog(LOG_DEBUG, "default voicecall slot: %d\n", + result->arg2); + judge_data.result = OK; + global_data.default_voicecall_slot = result->arg2; + judge_data.flag = MSG_DEFAULT_VOICECALL_SLOT_CHANGE_IND; + } + } +} + +int tapi_call_listen_call_test(int slot_id) +{ + global_data.call_state_watch_id = -1; + global_data.call_state_watch_id = tapi_call_register_call_state_change( + get_tapi_ctx(), slot_id, NULL, call_state_change_cb); + + if (global_data.call_state_watch_id < 0) + { + syslog(LOG_ERR, "%s, call state change registered fail, ret: %d", + __func__, global_data.call_state_watch_id); + return -1; + } + + global_data.call_emergencylist_change_watch_id = -1; + global_data.call_emergencylist_change_watch_id = + tapi_call_register_emergency_list_change( + get_tapi_ctx(), slot_id, NULL, tele_call_ecc_list_async_fun); + + if (global_data.call_emergencylist_change_watch_id < 0) + { + syslog(LOG_ERR, + "%s, emergency list change registered fail, ret: %d", + __func__, global_data.call_emergencylist_change_watch_id); + return -1; + } + + global_data.call_ring_back_tone_change_watch_id = -1; + global_data.call_ring_back_tone_change_watch_id = + tapi_call_register_ringback_tone_change( + get_tapi_ctx(), slot_id, NULL, + tele_call_manager_call_async_fun); + + if (global_data.call_ring_back_tone_change_watch_id < 0) + { + syslog(LOG_ERR, "%s, ring back change registered fail, ret: %d", + __func__, global_data.call_ring_back_tone_change_watch_id); + return -1; + } + + global_data.call_slot_change_watch_id = -1; + global_data.call_slot_change_watch_id = + tapi_call_register_default_voicecall_slot_change( + get_tapi_ctx(), NULL, tele_call_manager_call_async_fun); + if (global_data.call_slot_change_watch_id < 0) + { + syslog(LOG_ERR, + "%s, voicecall slot change registered fail, ret: %d", + __func__, global_data.call_slot_change_watch_id); + return -1; + } + + return 0; +} + +static void tele_call_async_fun(tapi_async_result *result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) + { + syslog(LOG_DEBUG, "%s msg id : %d result err, return.\n", __func__, + result->msg_id); + return; + } + + int event = result->msg_id; + int status = result->status; + + switch (event) + { + case EVENT_REQUEST_DIAL_DONE: + syslog(LOG_DEBUG, "%s: EVENT_REQUEST_DIAL_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_REQUEST_DIAL_DONE) + { + judge_data.result = status; + char *call_id = (char *)result->data; + strncpy(test_case_data.call_id, call_id, strlen(call_id)); + test_case_data.call_id[strlen(call_id)] = '\0'; + judge_data.flag = EVENT_REQUEST_DIAL_DONE; + } + break; + case EVENT_REQUEST_START_DTMF_DONE: + syslog(LOG_DEBUG, "%s: EVENT_REQUEST_START_DTMF_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_REQUEST_START_DTMF_DONE) + { + judge_data.result = status; + judge_data.flag = EVENT_REQUEST_START_DTMF_DONE; + } + break; + case EVENT_REQUEST_STOP_DTMF_DONE: + syslog(LOG_DEBUG, "%s: EVENT_REQUEST_STOP_DTMF_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_REQUEST_STOP_DTMF_DONE) + { + judge_data.result = status; + judge_data.flag = EVENT_REQUEST_STOP_DTMF_DONE; + } + break; + default: + break; + } +} + +static void ss_signal_change(tapi_async_result *result) +{ + tapi_call_barring_info *cb_value; + int signal = result->msg_id; + int slot_id = result->arg1; + + switch (signal) + { + case MSG_CALL_BARRING_PROPERTY_CHANGE_IND: + cb_value = result->data; + syslog(LOG_DEBUG, + "call barring service %s changed to %s in slot[%d] \n", + cb_value->service_type, cb_value->value, slot_id); + break; + case MSG_USSD_PROPERTY_CHANGE_IND: + syslog(LOG_DEBUG, "ussd state changed to %s in slot[%d] \n", + (char *)result->data, slot_id); + break; + case MSG_USSD_NOTIFICATION_RECEIVED_IND: + syslog(LOG_DEBUG, + "ussd notification message %s received in slot[%d] \n", + (char *)result->data, slot_id); + break; + case MSG_USSD_REQUEST_RECEIVED_IND: + syslog(LOG_DEBUG, + "ussd request message %s received in slot[%d] \n", + (char *)result->data, slot_id); + break; + default: + break; + } +} + +int tapi_ss_listen_test(int slot_id) +{ + global_data.ss_call_barring_watch_id = -1; + global_data.ss_call_barring_watch_id = tapi_ss_register( + get_tapi_ctx(), slot_id, 47, NULL, ss_signal_change); + + if (global_data.ss_call_barring_watch_id < 0) + { + syslog(LOG_ERR, "%s, slot_id: %d, watch_id < 0\n", __func__, + slot_id); + return -1; + } + + global_data.ss_ussd_property_change_watch_id = -1; + global_data.ss_ussd_property_change_watch_id = tapi_ss_register( + get_tapi_ctx(), slot_id, 50, NULL, ss_signal_change); + + if (global_data.ss_ussd_property_change_watch_id < 0) + { + syslog(LOG_ERR, "%s, slot_id: %d, watch_id < 0\n", __func__, + slot_id); + return -1; + } + + global_data.ss_ussd_notification_received_watch_id = -1; + global_data.ss_ussd_notification_received_watch_id = tapi_ss_register( + get_tapi_ctx(), slot_id, 48, NULL, ss_signal_change); + + if (global_data.ss_ussd_notification_received_watch_id < 0) + { + syslog(LOG_ERR, "%s, slot_id: %d, watch_id < 0\n", __func__, + slot_id); + return -1; + } + + global_data.ss_ussd_request_received_watch_id = -1; + global_data.ss_ussd_request_received_watch_id = tapi_ss_register( + get_tapi_ctx(), slot_id, 49, NULL, ss_signal_change); + + if (global_data.ss_ussd_request_received_watch_id < 0) + { + syslog(LOG_ERR, "%s, slot_id: %d, watch_id < 0\n", __func__, + slot_id); + return -1; + } + + return 0; +} + +int tapi_ss_unlisten_test(void) +{ + if (global_data.ss_call_barring_watch_id < 0 || + global_data.ss_ussd_notification_received_watch_id < 0 || + global_data.ss_ussd_property_change_watch_id < 0 || + global_data.ss_ussd_request_received_watch_id < 0) + return -1; + + int ret = -1; + int res = 0; + ret = tapi_ss_unregister(get_tapi_ctx(), + global_data.ss_call_barring_watch_id); + if (ret) + { + syslog(LOG_ERR, + "unregister ss call barring change fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_ss_unregister( + get_tapi_ctx(), + global_data.ss_ussd_notification_received_watch_id); + if (ret) + { + syslog(LOG_ERR, + "unregister ss ussd notification received change fail in " + "%s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_ss_unregister(get_tapi_ctx(), + global_data.ss_ussd_property_change_watch_id); + if (ret) + { + syslog(LOG_ERR, + "unregister ss ussd property change fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_ss_unregister( + get_tapi_ctx(), global_data.ss_ussd_request_received_watch_id); + if (ret) + { + syslog(LOG_ERR, + "unregister ss ussd request received change fail in %s, " + "ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_listen_error_code_test(int slot_id) +{ + int ret1 = tapi_ss_register(get_tapi_ctx(), slot_id, 46, NULL, + ss_signal_change); + + int ret2 = tapi_ss_register(get_tapi_ctx(), slot_id, 52, NULL, + ss_signal_change); + + return ret1 >= 0 || ret2 >= 0; +} + +int tapi_call_dial_test(int slot_id, char *phone_number, + int hide_caller_id) +{ + int res = 0; + test_case_data_init(); + judge_data_init(); + judge_data.expect = EVENT_REQUEST_DIAL_DONE; + int ret = tapi_call_dial(get_tapi_ctx(), slot_id, phone_number, + hide_caller_id, EVENT_REQUEST_DIAL_DONE, + tele_call_async_fun); + + if (ret) + { + syslog(LOG_ERR, "tapi_call_dial_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_DEBUG, "tapi_call_dial_test is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_call_hanup_current_call_test(int slot_id) +{ + syslog(LOG_DEBUG, "%s called, current call id: %s\n", __func__, + test_case_data.call_id); + + if (test_case_data.call_id[0] == 0) + { + syslog(LOG_DEBUG, "no call to hanup\n"); + return -1; + } + + int res = 0; + judge_data_init(); + judge_data.expect = CALL_LOCAL_HANGUP; + int ret = tapi_call_hangup_by_id(get_tapi_ctx(), slot_id, + test_case_data.call_id); + + if (ret) + { + syslog(LOG_ERR, + "tapi_call_hanup_current_call_test execute fail in %s, " + "ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_DEBUG, + "tapi_call_hanup_current_call_test is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_call_unlisten_call_test(void) +{ + int ret = -1; + int res = 0; + ret = tapi_unregister(get_tapi_ctx(), global_data.call_state_watch_id); + if (ret) + { + syslog(LOG_ERR, "unregister call state change fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_unregister(get_tapi_ctx(), + global_data.call_emergencylist_change_watch_id); + if (ret) + { + syslog(LOG_ERR, + "unregister emergency list change fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_unregister(get_tapi_ctx(), + global_data.call_ring_back_tone_change_watch_id); + if (ret) + { + syslog(LOG_ERR, + "unregister ring back tone change fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +static void call_list_query_complete(tapi_async_result *result) +{ + tapi_call_info *call_info; + + syslog(LOG_DEBUG, "%s : \n", __func__); + if (result->status != OK) + return; + + syslog(LOG_DEBUG, "call count: %d \n\n", result->arg2); + if (judge_data.expect == GET_ALL_CALLS) + { + judge_data.result = 0; + test_case_data.call_count = result->arg2; + judge_data.flag = judge_data.expect; + } + else if (judge_data.expect == GET_TWO_CALL_STATES) + { + judge_data.result = 0; + test_case_data.two_call_state_sum = 0; + judge_data.flag = judge_data.expect; + } + + call_info = result->data; + + for (int i = 0; i < result->arg2; i++) + { + test_case_data.two_call_state_sum += call_info[i].state; + + if (judge_data.expect == GET_HOLD_CALL_ID) + { + if (call_info[i].state == 1) + { + char *hold_call_id = call_info[i].call_id; + strncpy(test_case_data.hold_call_id, hold_call_id, + strlen(hold_call_id)); + test_case_data.hold_call_id[strlen(hold_call_id)] = '\0'; + judge_data.result = 0; + judge_data.flag = judge_data.expect; + } + } + + if (judge_data.expect == GET_CURRENT_CALL_STATE) + { + test_case_data.current_call_state = call_info[i].state; + judge_data.result = 0; + judge_data.flag = judge_data.expect; + } + + syslog(LOG_DEBUG, "call id: %s \n", call_info[i].call_id); + syslog(LOG_DEBUG, "call state: %d \n", call_info[i].state); + syslog(LOG_DEBUG, "call IncomingLine: %s \n", + call_info[i].incoming_line); + syslog(LOG_DEBUG, "call Name: %s \n", call_info[i].name); + syslog(LOG_DEBUG, "call StartTime: %s \n", + call_info[i].start_time); + syslog(LOG_DEBUG, "call Multiparty: %d \n", + call_info[i].multiparty); + syslog(LOG_DEBUG, "call RemoteHeld: %d \n", + call_info[i].remote_held); + syslog(LOG_DEBUG, "call RemoteMultiparty: %d \n", + call_info[i].remote_multiparty); + syslog(LOG_DEBUG, "call Information: %s \n", call_info[i].info); + syslog(LOG_DEBUG, "call Icon: %d \n", call_info[i].icon); + syslog(LOG_DEBUG, "call Emergency: %d \n\n", + call_info[i].is_emergency_number); + } +} + +int tapi_get_call_count(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = GET_ALL_CALLS; + test_case_data.call_count = 0; + int ret = tapi_call_get_all_calls(get_tapi_ctx(), slot_id, 0, + call_list_query_complete); + + if (ret) + { + syslog(LOG_ERR, "tapi_get_call_count execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_DEBUG, "tapi_get_call_count is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + return test_case_data.call_count; + +on_exit: + return res; +} + +static int tapi_get_two_call_state(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = GET_TWO_CALL_STATES; + test_case_data.two_call_state_sum = -22; + int ret = tapi_call_get_all_calls(get_tapi_ctx(), slot_id, 0, + call_list_query_complete); + + if (ret) + { + syslog(LOG_ERR, + "tapi_get_two_call_state execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_DEBUG, "tapi_get_two_call_state is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + return test_case_data.two_call_state_sum; + +on_exit: + return res; +} + +static char *get_hold_call_id(int slot_id) +{ + judge_data_init(); + judge_data.expect = GET_HOLD_CALL_ID; + int ret = tapi_call_get_all_calls(get_tapi_ctx(), slot_id, 0, + call_list_query_complete); + + if (ret) + { + syslog(LOG_ERR, "get_hold_call_id execute fail in %s, ret: %d", + __func__, ret); + goto on_exit; + } + + if (judge()) + { + syslog(LOG_DEBUG, "get_hold_call_id is not executed in %s", + __func__); + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + goto on_exit; + } + + return test_case_data.hold_call_id; + +on_exit: + return NULL; +} + +static int get_current_call_state_test(int slot_id) +{ + int res = 0; + test_case_data.current_call_state = -2; + judge_data_init(); + judge_data.expect = GET_CURRENT_CALL_STATE; + int ret = tapi_call_get_all_calls(get_tapi_ctx(), slot_id, 0, + call_list_query_complete); + + if (ret) + { + syslog(LOG_ERR, + "get_current_call_state_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_DEBUG, + "get_current_call_state_test is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + return test_case_data.current_call_state; + +on_exit: + return res; +} + +int tapi_call_hangup_all_test(int slot_id) +{ + int ret = tapi_call_hangup_all_calls(get_tapi_ctx(), slot_id); + syslog(LOG_DEBUG, "%s, slotId : %d ret : %d \n", __func__, slot_id, + ret); + + return ret; +} + +int tapi_call_dial_using_phone_number_with_area_code_test(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, "02510086", 0); + syslog(LOG_DEBUG, "%s, slotId : %d ret : %d \n", __func__, slot_id, + ret); + return ret; +} + +int tapi_call_dial_using_phone_number_with_pause_code_test(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, "10086,001", 0); + return ret; +} + +int tapi_call_dial_using_phone_number_with_wait_code_test(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, "10086;001", 0); + return ret; +} + +int tapi_call_dial_using_phone_number_with_numerous_code_test( + int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, "10086,001;001", 0); + return ret; +} + +int tapi_call_load_ecc_list_test(int slot_id) +{ + ecc_info out[MAX_ECC_LIST_SIZE]; + int size = tapi_call_get_ecc_list(get_tapi_ctx(), slot_id, out); + + if (size <= 0) + return -1; + + int ret = 0; + syslog(LOG_INFO, "ecc list: \n"); + + for (int i = 0; i < size; i++) + { + syslog(LOG_DEBUG, "ecc number : %s,%u,%u \n", out[i].ecc_num, + out[i].category, out[i].condition); + } + + char *correct_ecc_list_with_sim_card[] = + { + "110", "119", "120", "118", "999", "000", "08", "911", "112" + }; + + char *correct_ecc_list_without_sim_card[] = + { + "119", "118", "999", "110", "08", "000" + }; + + char *error_ecc_list[] = + { + "0", "07", "234" + }; + + bool has_sim_card = false; + tapi_sim_has_icc_card(get_tapi_ctx(), 0, &has_sim_card); + + if (has_sim_card) + { + for (int i = 0; + i < sizeof(correct_ecc_list_with_sim_card) / sizeof(char *); + i++) + { + if (tapi_call_is_emergency_number( + get_tapi_ctx(), correct_ecc_list_with_sim_card[i]) == + -1) + { + syslog(LOG_ERR, "%s is not in ecc list\n", + correct_ecc_list_with_sim_card[i]); + ret |= -1; + } + } + } + else + { + for (int i = 0; i < sizeof(correct_ecc_list_without_sim_card) / + sizeof(char *); + i++) + { + if (tapi_call_is_emergency_number( + get_tapi_ctx(), + correct_ecc_list_without_sim_card[i]) == -1) + { + syslog(LOG_ERR, "%s is not in ecc list\n", + correct_ecc_list_without_sim_card[i]); + ret |= -1; + } + } + } + + for (int i = 0; i < sizeof(error_ecc_list) / sizeof(char *); i++) + { + if (tapi_call_is_emergency_number(get_tapi_ctx(), + error_ecc_list[i]) != -1) + { + syslog(LOG_ERR, "%s is not emergency number\n", + error_ecc_list[i]); + ret |= -1; + } + } + + return ret; +} + +int tapi_call_set_default_voicecall_slot_test(int slot_id) +{ + int res = 0; + judge_data_init(); + global_data.default_voicecall_slot = -100; + judge_data.expect = MSG_DEFAULT_VOICECALL_SLOT_CHANGE_IND; + + int ret = tapi_call_set_default_slot(get_tapi_ctx(), slot_id); + if (ret) + { + syslog(LOG_ERR, "tapi_call_set_default_slot execute fail, ret: %d", + ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, + "tele_call_manager_call_async_fun was not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (global_data.default_voicecall_slot != slot_id) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_call_get_default_voicecall_slot_test(int expect_res) +{ + int result = -1; + int ret = tapi_call_get_default_slot(get_tapi_ctx(), &result); + syslog(LOG_DEBUG, "%s, ret: %d, voicecall_slot: %d", __func__, ret, + result); + + return ret || expect_res != result; +} + +int tapi_call_answer_call_test(int slot_id, char *call_id) +{ + if (test_case_data.call_id[0] == 0) + { + syslog(LOG_ERR, "current call id is NULL\n"); + return -1; + } + + int res = 0; + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret = tapi_call_answer_by_id(get_tapi_ctx(), slot_id, call_id); + + if (ret) + { + syslog(LOG_ERR, + "tapi_call_answer_call_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_DEBUG, + "tapi_call_answer_call_test is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int call_dial_after_caller_reject(int slot_id) +{ + int ret1; + int ret2; + int ret3; + int ret4; + int ret5; + ret1 = ret2 = ret3 = ret4 = ret5 = -1; + + for (int i = 0; i < 5; ++i) + { + ret1 = tapi_call_listen_call_test(slot_id); + ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + int integer_call_id = atoi(test_case_data.call_id + 16); + hangup_remote_call(integer_call_id); + + if (judge() || judge_data.result || ret1 || ret2) + goto error; + + ret3 = tapi_call_dial_test(slot_id, phone_num, 0); + ret4 = tapi_call_hanup_current_call_test(slot_id); + ret5 = tapi_call_unlisten_call_test(); + + if ((ret3 || ret4 || ret5) != 0) + { + goto error; + } + } + + return 0; + +error: + if (tapi_get_call_count(slot_id)) + { + tapi_call_hangup_all_test(slot_id); + } + + return -1; +} + +int call_hangup_after_caller_answer(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + if ((judge() || ret1 || ret2 || judge_data.result) != 0) + goto error; + + int ret4 = tapi_call_hanup_current_call_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + if ((ret4 || ret5) != 0) + goto error; + + return 0; + +error: + if (tapi_get_call_count(slot_id)) + { + tapi_call_hangup_all_test(slot_id); + } + + return -1; +} + +int call_dial_active_and_hangup_by_caller(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + if ((judge() || ret1 || ret2 || judge_data.result) != 0) + goto error; + + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + int integer_call_id = atoi(test_case_data.call_id + 16); + hangup_remote_call(integer_call_id); + + if (judge()) + return -1; + + int ret3 = tapi_call_unlisten_call_test(); + if ((judge_data.result || ret3) != 0) + goto error; + + return 0; + +error: + if (tapi_get_call_count(slot_id)) + { + tapi_call_hangup_all_test(slot_id); + } + + return -1; +} + +int call_dial_caller_reject_and_incoming(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + int integer_call_id = atoi(test_case_data.call_id + 16); + hangup_remote_call(integer_call_id); + + if ((judge() || ret1 || ret2 || judge_data.result) != 0) + goto error; + + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + incoming_call("10010"); + + if (judge() || judge_data.result) + goto error; + + int ret3 = tapi_call_hanup_current_call_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + if ((ret3 || ret4) != 0) + goto error; + + return 0; + +error: + if (tapi_get_call_count(slot_id)) + { + tapi_call_hangup_all_test(slot_id); + } + + return -1; +} + +int call_dial_caller_reject_and_dial_another(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + int integer_call_id = atoi(test_case_data.call_id + 16); + hangup_remote_call(integer_call_id); + + if ((judge() || ret1 || ret2 || judge_data.result) != 0) + goto error; + + int ret3 = tapi_call_dial_test(slot_id, "10001", 0); + int ret4 = tapi_call_hanup_current_call_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + if ((ret3 || ret4 || ret5) != 0) + goto error; + + return 0; + +error: + if (tapi_get_call_count(slot_id)) + { + tapi_call_hangup_all_test(slot_id); + } + + return -1; +} + +int call_hangup_between_dialing_and_answering(int slot_id) +{ + int res = 0; + int ret = tapi_call_dial_test(slot_id, phone_num, 0); + if (ret) + { + syslog(LOG_ERR, "tapi_call_dial_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_call_hanup_current_call_test(slot_id); + if (ret) + { + syslog(LOG_ERR, + "tapi_call_hanup_current_call_test execute fail in %s, " + "ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int call_clear_voicecall_slot_set(void) +{ + int res = 0; + judge_data_init(); + judge_data.expect = MSG_DEFAULT_VOICECALL_SLOT_CHANGE_IND; + global_data.default_voicecall_slot = -100; + int ret = tapi_call_set_default_voicecall_slot_test(-1); + + if (ret) + { + syslog(LOG_ERR, + "tapi_call_set_default_voicecall_slot_test execute fail, " + "ret: %d", + ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, + "tele_call_manager_call_async_fun was not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (global_data.default_voicecall_slot != -1) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +/* todo */ + +int call_dial_to_phone_in_call(int slot_id) +{ + /* todo: caller in process */ + + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + sleep(5); + int ret3 = tapi_call_hanup_current_call_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret1 || ret2 || ret3 || ret4; +} + +/* todo */ + +int call_dial_to_phone_out_of_service(int slot_id) +{ + /* todo: caller out of service */ + + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + sleep(5); + int ret3 = tapi_call_hanup_current_call_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret1 || ret2 || ret3 || ret4; +} + +/* todo */ + +int call_dial_without_sim_card(int slot_id) +{ + /* todo: pull out the sim card */ + + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + sleep(5); + int ret3 = tapi_call_hanup_current_call_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret1 || ret2 || ret3 || ret4; +} + +/* todo */ + +int call_dial_ecc_number_without_sim_card(int slot_id) +{ + /* todo: pull out the sim card */ + + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, "911", 0); + sleep(5); + int ret3 = tapi_call_hanup_current_call_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret1 || ret2 || ret3 || ret4; +} + +/* todo */ + +int call_dial_to_empty_number(int slot_id) +{ + char *empty_phone_number = "123456"; + + /* todo: 123456 is empty phone number */ + + int ret1 = tapi_call_listen_call_test(slot_id); + + if (ret1 != 0) + return -1; + + int ret2 = tapi_call_dial_test(slot_id, empty_phone_number, 0); + + if (ret2 == 0) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + return tapi_call_unlisten_call_test(); +} + +int tapi_dial_number(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, phone_num, 0); + syslog(LOG_DEBUG, "%s, slotId : %d ret : %d \n", __func__, slot_id, + ret); + return ret; +} + +int tapi_dial_ecc_number(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, "911", 0); + syslog(LOG_DEBUG, "%s, ret: %d", __func__, ret); + return ret; +} + +int tapi_dial_with_long_phone_number(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, "167101398140", 0); + syslog(LOG_DEBUG, "%s, slotId : %d ret : %d \n", __func__, slot_id, + ret); + return ret; +} + +int tapi_dial_with_short_phone_number(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, "11", 0); + syslog(LOG_DEBUG, "%s, slotId : %d ret : %d \n", __func__, slot_id, + ret); + return ret; +} + +int tapi_dial_with_enable_hide_callerid(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, phone_num, 1); + syslog(LOG_DEBUG, "%s, slotId : %d ret : %d \n", __func__, slot_id, + ret); + return ret; +} + +int tapi_dial_with_disabled_hide_callerid(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, phone_num, 2); + syslog(LOG_DEBUG, "%s, slotId : %d ret : %d \n", __func__, slot_id, + ret); + return ret; +} + +int tapi_dial_with_default_hide_callerid(int slot_id) +{ + int ret = tapi_call_dial_test(slot_id, phone_num, 0); + syslog(LOG_DEBUG, "%s, slotId : %d ret : %d \n", __func__, slot_id, + ret); + return ret; +} + +int tapi_start_dtmf_test(int slot_id) +{ + int ret = tapi_call_start_dtmf(get_tapi_ctx(), slot_id, '0', + EVENT_REQUEST_START_DTMF_DONE, + tele_call_async_fun); + syslog(LOG_DEBUG, "%s, ret: %d", __func__, ret); + return ret; +} + +int tapi_stop_dtmf_test(int slot_id) +{ + int ret = tapi_call_stop_dtmf(get_tapi_ctx(), slot_id, + EVENT_REQUEST_STOP_DTMF_DONE, + tele_call_async_fun); + syslog(LOG_DEBUG, "%s, ret: %d", __func__, ret); + return ret; +} + +/* todo: unsolicited message error, need gaojiawei fix */ + +int call_incoming_and_hangup_by_dialer_before_answer(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + incoming_call("10010"); + + if ((judge() || ret1 || judge_data.result) != 0) + goto error; + + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + int integer_call_id = atoi(test_case_data.call_id + 16); + hangup_remote_call(integer_call_id); + + if (judge() != 0) + goto error; + + int ret2 = tapi_call_unlisten_call_test(); + + if ((ret2 || judge_data.result) != 0) + goto error; + + return 0; + +error: + if (tapi_get_call_count(slot_id)) + { + tapi_call_hangup_all_test(slot_id); + } + + return -1; +} + +int call_incoming_and_hangup_by_dialer_before_answer_numerous( + int slot_id) +{ + for (int i = 0; i < 5; i++) + { + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call from different phone number */ + + if (judge() != 0) + return -1; + + if ((ret1 || judge_data.result) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + /* todo: dialer hangup */ + + if (judge() != 0) + return -1; + + int ret2 = tapi_call_unlisten_call_test(); + + if ((ret2 || judge_data.result) != 0) + return -1; + } + + return 0; +} + +int call_incoming_answer_and_hangup(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + if (incoming_call("101") < 0) + return -1; + + if ((judge() || ret1 || judge_data.result) != 0) + return -1; + + sleep(2); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(2); + int ret3 = tapi_call_hanup_current_call_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret1 || ret2 || ret3 || ret4; +} + +/* todo */ + +int call_incoming_answer_and_hangup_by_dialer(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if (judge() != 0) + return -1; + + if ((ret1 || judge_data.result) != 0) + return -1; + + sleep(10); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + /* todo: dialer hangup */ + + if (judge() != 0) + return -1; + + int ret3 = tapi_call_unlisten_call_test(); + + if ((ret2 || ret3 || judge_data.result) != 0) + return -1; + + return 0; +} + +/* todo */ + +int call_display_the_network_of_incoming_call(int slot_id, + char *network_name) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = INCOMING_CALL_WITH_NETWORK_NAME; + + /* todo: incoming call with network name */ + + if (judge() != 0) + return -1; + + int ret2 = strncmp(network_name, test_case_data.network_name, + strlen(test_case_data.network_name) + 1); + + if ((ret1 || ret2 || judge_data.result) != 0) + return -1; + + if (test_case_data.call_id[0] != '\0') + { + sleep(5); + int ret3 = tapi_call_hanup_current_call_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + if ((ret3 || ret4) != 0) + return -1; + } + + return tapi_call_unlisten_call_test(); +} + +/* todo */ + +int call_display_the_network_of_incoming_call_in_call_process( + int slot_id, char *network_name) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((judge() || ret1 || judge_data.result) != 0) + return -1; + + sleep(10); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(10); + judge_data_init(); + test_case_data_init(); + judge_data.expect = INCOMING_CALL_WITH_NETWORK_NAME; + + /* todo: incoming call with network name */ + + if ((judge() || ret2 || judge_data.result) != 0) + return -1; + + int ret3 = strncmp(network_name, test_case_data.network_name, + strlen(test_case_data.network_name) + 1); + + if (ret3 != 0) + return -1; + + if (tapi_get_call_count(slot_id) != 0) + { + sleep(5); + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + if ((ret4 || ret5) != 0) + return -1; + } + + return tapi_call_unlisten_call_test(); +} + +/* todo */ + +int call_dial_active_hangup_due_to_dialer_network_exception(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + sleep(5); + + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + /* todo: caller answer */ + + if ((judge() || ret1 || ret2 || judge_data.result) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = HANGUP_DUE_TO_NETWORK_EXCEPTION; + + /* todo: hangup due to dialer network exception */ + + if ((judge() || judge_data.result) != 0) + { + if (tapi_get_call_count(slot_id) != 0) + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + + return -1; + } + + return tapi_call_unlisten_call_test(); +} + +/* todo */ + +int call_dial_active_hangup_due_to_caller_network_exception(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + sleep(5); + + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + /* todo: caller answer */ + + if ((judge() || ret1 || ret2 || judge_data.result) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = HANGUP_DUE_TO_NETWORK_EXCEPTION; + + /* todo: hangup due to caller network exception */ + + if ((judge() || judge_data.result) != 0) + { + if (tapi_get_call_count(slot_id) != 0) + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + + return -1; + } + + return tapi_call_unlisten_call_test(); +} + +/* todo 30 */ + +int call_check_status_in_dialing(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + sleep(5); + + int call_state = get_current_call_state_test(slot_id); + + if ((ret1 || ret2) != 0 || call_state != CALL_STATUS_DIALING) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +/* todo 31 */ + +int call_dial_and_check_status_in_call_process(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + /* todo: caller answer */ + + if ((ret1 || ret2 || judge() || judge_data.result) != 0) + return -1; + + sleep(5); + int call_state = get_current_call_state_test(slot_id); + + if (call_state != CALL_STATUS_ACTIVE) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +/* todo 32 */ + +int call_incoming_answer_and_check_status_in_call_process(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(10); + int call_state = get_current_call_state_test(slot_id); + + if (ret2 || call_state != CALL_STATUS_ACTIVE) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +/* todo 33 */ + +int call_check_status_in_incoming(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + int call_state = get_current_call_state_test(slot_id); + + if (call_state != CALL_STATUS_INCOMING) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret2 = tapi_call_hangup_all_test(slot_id); + int ret3 = tapi_call_unlisten_call_test(); + + return ret2 || ret3; +} + +/* todo 34 */ + +int call_incoming_answer_caller_hold_and_check_status(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + sleep(10); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(10); + int ret3 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + sleep(10); + int call_state = get_current_call_state_test(slot_id); + + if ((ret2 || ret3) != 0 || call_state != CALL_STATUS_HELD) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +/* todo: 35 */ + +int call_incoming_answer_dialer_hold_and_check_status(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + sleep(10); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(10); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + + /* todo: dialer hold */ + + sleep(10); + int call_state = get_current_call_state_test(slot_id); + + if (ret2 != 0 || call_state != CALL_STATUS_HELD) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +/* todo: 36 */ + +int call_check_call_status_in_multi_call(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + sleep(5); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(10); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + /* todo: another incoming call */ + + if ((judge() || judge_data.result || ret2) != 0) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret3 = tapi_call_hold_and_answer(get_tapi_ctx(), slot_id); + + if ((judge() || ret3 || judge_data.result) != 0) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + if (tapi_get_call_count(slot_id) != 2 || + tapi_get_two_call_state(slot_id) != 1) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +/* todo: 37 */ + +int call_check_call_status_in_call_waiting_with_multi_call(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + sleep(5); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(10); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + /* todo: another incoming call */ + + if ((ret2 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_get_call_count(slot_id) != 2 || + tapi_get_two_call_state(slot_id) != 5) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +/* todo: 38 */ + +int call_check_call_status_in_dialing_with_multi_call(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + sleep(5); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(10); + int ret3 = tapi_call_dial_test(slot_id, phone_num, 0); + + if ((ret2 || ret3 || judge()) != 0) + return -1; + + sleep(5); + + if (tapi_get_call_count(slot_id) != 2 || + tapi_get_two_call_state(slot_id) != 3) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +/* todo: 39 */ + +int call_hold_old_call_incoming_new_call_and_check_status(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + sleep(5); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + sleep(10); + + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret3 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((ret2 || ret3 || judge() || judge_data.result) != 0) + return -1; + + judge_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + /* todo: another incoming call */ + + if ((judge() || judge_data.result) != 0) + return -1; + + sleep(10); + if (tapi_get_call_count(slot_id) != 2 || + tapi_get_two_call_state(slot_id) != 5) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +/* todo: 42 */ + +int call_incoming_hangup_first_answer_second(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((judge() || ret1 || judge_data.result) != 0) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + char old_call_id[101]; + strncpy(old_call_id, test_case_data.call_id, + strlen(test_case_data.call_id) + 1); + + sleep(5); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + /* todo: incoming another call */ + + if ((judge() || judge_data.result) != 0) + return -1; + + char new_call_id[101]; + strncpy(new_call_id, test_case_data.call_id, + strlen(test_case_data.call_id) + 1); + + judge_data_init(); + judge_data.expect = CALL_LOCAL_HANGUP; + int ret2 = + tapi_call_hangup_by_id(get_tapi_ctx(), slot_id, old_call_id); + + if ((judge() || ret2 || judge_data.result) != 0) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, new_call_id) != 0) + return -1; + + sleep(5); + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +/* todo: 43 */ + +int call_release_and_answer(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(5); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + /* todo: incoming another call */ + + if (judge() != 0 || judge_data.result != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret2 = tapi_call_release_and_answer(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret2) != 0) + return -1; + + sleep(5); + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +/* todo: 44 */ + +int call_incoming_hold_and_recover_by_dialer(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + sleep(5); + + if ((judge() || ret1 || judge_data.result) != 0) + return -1; + + sleep(5); + int ret2 = tapi_call_answer_call_test(slot_id, test_case_data.call_id); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + + /* todo: dialer hold */ + + if ((ret2 || judge() || judge_data.result) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + /* todo: dialer active */ + + if (judge() != 0 || judge_data.result != 0) + return -1; + + sleep(5); + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +/* todo: 45 */ + +int call_dialer_hold_recover_and_hold_by_caller(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + /* todo: caller answer */ + + if ((judge() || ret1 || ret2 || judge_data.result) != 0) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret3 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((ret3 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret4 = tapi_call_unhold_call(get_tapi_ctx(), slot_id); + + if ((ret4 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + + /* todo: caller hold */ + + if ((judge() || judge_data.result) != 0) + return -1; + + int ret5 = tapi_call_hangup_all_test(slot_id); + int ret6 = tapi_call_unlisten_call_test(); + + return ret5 || ret6; +} + +/* todo: 47 */ + +int call_incoming_hold_and_recover_by_caller(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id)) + return -1; + sleep(5); + + for (int i = 0; i < 3; i++) + { + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret2 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((ret2 || judge() || judge_data.result) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret3 = tapi_call_unhold_call(get_tapi_ctx(), slot_id); + + if ((ret3 || judge() || judge_data.result) != 0) + return -1; + } + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +/* todo: 48 */ + +int call_hold_and_hangup(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret2 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret2) != 0) + return -1; + + sleep(5); + int ret3 = tapi_call_hanup_current_call_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +/* todo: 49 */ + +int call_swap_dial_reject_swap(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret2 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret2) != 0) + return -1; + + sleep(5); + if (tapi_call_dial_test(slot_id, phone_num, 0)) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + /* todo: caller reject */ + + if ((judge() || judge_data.result) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret3 = tapi_call_unhold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret3) != 0) + return -1; + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +/* todo: 50 */ + +int call_hold_incoming_answer_hangup_second_recover_first(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret2 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret2) != 0) + return -1; + + sleep(5); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + /* todo: incoming another call */ + + if (judge() != 0 || judge_data.result != 0) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(10); + + if (tapi_call_hanup_current_call_test(slot_id) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret3 = tapi_call_unhold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret3) != 0) + return -1; + + sleep(5); + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +/* todo: 51 */ + +int call_incoming_second_call_swap_answer_hangup_swap(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + /* todo: incoming another call */ + + if (judge() != 0 || judge_data.result != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret2 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret2) != 0) + return -1; + + sleep(5); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(10); + + if (tapi_call_hanup_current_call_test(slot_id) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret3 = tapi_call_unhold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret3) != 0) + return -1; + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +/* todo: 52 */ + +int call_hold_current_call_and_reject_new_incoming(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(10); + + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret2 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret2) != 0) + return -1; + + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + /* todo: incoming another call */ + + if (judge() != 0 || judge_data.result != 0) + return -1; + + sleep(10); + + if (tapi_call_hanup_current_call_test(slot_id) != 0) + return -1; + + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret3 = tapi_call_unhold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret3) != 0) + return -1; + + sleep(5); + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +/* todo: 53 */ + +int call_incoming_and_hangup_new_call(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(10); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + /* todo: incoming new call */ + + if (judge() != 0 || judge_data.result != 0) + return -1; + + sleep(10); + + if (tapi_call_hanup_current_call_test(slot_id) != 0) + return -1; + + sleep(10); + + if (tapi_get_call_count(slot_id) != 1) + return -1; + + int ret2 = tapi_call_hangup_all_test(slot_id); + int ret3 = tapi_call_unlisten_call_test(); + + return ret2 || ret3; +} + +/* todo: 54 */ + +int call_hold_first_call_and_answer_second_call(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(10); + + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + /* todo: incoming new call */ + + if (judge() != 0 || judge_data.result != 0) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret2 = tapi_call_hold_and_answer(get_tapi_ctx(), slot_id); + int ret3 = tapi_get_two_call_state(slot_id); + + if ((judge() || judge_data.result || ret2 || ret3) != 0) + return -1; + + if (tapi_get_call_count(slot_id) != 2 || + tapi_get_two_call_state(slot_id) != 1) + return -1; + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +/* todo: 55 */ + +int call_dial_second_call_active_and_hangup_by_dialer(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(10); + + if (tapi_call_dial_test(slot_id, phone_num, 0)) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + /* todo: caller answer */ + + if ((judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_call_hanup_current_call_test(slot_id) != 0) + return -1; + + sleep(10); + if (tapi_get_call_count(slot_id) != 1 || + get_current_call_state_test(slot_id) != CALL_STATUS_ACTIVE) + return -1; + + int ret2 = tapi_call_hangup_all_test(slot_id); + int ret3 = tapi_call_unlisten_call_test(); + + return ret2 || ret3; +} + +/* todo: 56 */ + +int call_dial_second_call_and_hangup_by_caller_before_answering( + int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if (judge() != 0 || judge_data.result != 0 || ret1) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(10); + if (tapi_call_dial_test(slot_id, phone_num, 0)) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + /* todo caller reject */ + + if ((judge() || judge_data.result) != 0) + return -1; + + sleep(5); + + if (tapi_get_call_count(slot_id) != 1 || + get_current_call_state_test(slot_id) != CALL_STATUS_ACTIVE) + return -1; + + int ret2 = tapi_call_hangup_all_test(slot_id); + int ret3 = tapi_call_unlisten_call_test(); + + return ret2 || ret3; +} + +/* todo: 57 */ + +int call_dial_second_call_active_and_hangup_by_caller(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + + sleep(10); + + if (tapi_call_dial_test(slot_id, phone_num, 0)) + return -1; + + sleep(10); + + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + /* todo: caller answer */ + + if (judge() || judge_data.result) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_REMOTE_HANGUP; + + /* todo: caller hangup */ + + if (judge() || judge_data.result) + return -1; + + sleep(10); + if (tapi_get_call_count(slot_id) != 1) + return -1; + + sleep(5); + int ret2 = tapi_call_hangup_all_test(slot_id); + int ret3 = tapi_call_unlisten_call_test(); + + return ret2 || ret3; +} + +/* todo: 58 */ + +int call_hangup_hold_call_in_two_calls(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id)) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret2 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((judge() || judge_data.result || ret2) != 0) + return -1; + + sleep(5); + if (tapi_call_dial_test(slot_id, phone_num, 0)) + return -1; + sleep(5); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + + /* todo caller answer */ + + if ((judge() || judge_data.result) != 0) + return -1; + + sleep(5); + if (tapi_get_call_count(slot_id) != 2) + return -1; + char *hold_call_id = get_hold_call_id(slot_id); + + if (hold_call_id == NULL) + return -1; + + judge_data_init(); + judge_data.expect = CALL_LOCAL_HANGUP; + int ret3 = + tapi_call_hangup_by_id(get_tapi_ctx(), slot_id, hold_call_id); + + if ((judge() || judge_data.result || ret3) != 0) + return -1; + + sleep(10); + if (tapi_get_call_count(slot_id) != 1) + return -1; + + sleep(5); + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +/* todo: 59 */ + +int call_swap_in_two_calling(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id)) + return -1; + + sleep(10); + judge_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + /* todo: incoming another call */ + + if ((judge() || judge_data.result) != 0) + return -1; + + sleep(10); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id)) + return -1; + sleep(10); + + if (tapi_get_call_count(slot_id) != 2 || + tapi_get_two_call_state(slot_id) != 1) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_HOLD; + int ret2 = tapi_call_hold_call(get_tapi_ctx(), slot_id); + + if ((ret2 || judge() || judge_data.result) != 0) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + if (tapi_get_call_count(slot_id) != 2 || + tapi_get_two_call_state(slot_id) != 1) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + char old_call_id[101]; + char *call_id = get_hold_call_id(slot_id); + + if (call_id == NULL) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + strncpy(old_call_id, call_id, strlen(call_id) + 1); + + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret3 = tapi_call_unhold_call(get_tapi_ctx(), slot_id); + + if ((ret3 || judge() || judge_data.result) != 0) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + call_id = get_hold_call_id(slot_id); + + if (call_id == NULL) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + if (tapi_get_call_count(slot_id) != 2 || + tapi_get_two_call_state(slot_id) != 1) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + if (strncmp(old_call_id, call_id, strlen(call_id) + 1) == 0) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +/* todo: 60 */ + +int call_hangup_current_call_and_recover_hold_call(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + sleep(10); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + /* todo: incoming another call */ + + if ((judge() || judge_data.result) != 0) + return -1; + + sleep(10); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + sleep(10); + + if (tapi_get_call_count(slot_id) != 2 || + tapi_get_two_call_state(slot_id) != 1) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret2 = tapi_call_hanup_current_call_test(slot_id); + judge_data_init(); + judge_data.expect = CALL_STATE_CHANGE_TO_ACTIVE; + int ret3 = tapi_call_unhold_call(get_tapi_ctx(), slot_id); + + if ((ret2 || ret3 || judge() || judge_data.result) != 0) + return -1; + + int ret4 = tapi_call_hangup_all_test(slot_id); + int ret5 = tapi_call_unlisten_call_test(); + + return ret4 || ret5; +} + +/* todo: 61 */ + +int call_hangup_all_call_in_two_calling(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + sleep(10); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + /* todo: incoming another call */ + + if ((judge() || judge_data.result) != 0) + return -1; + sleep(10); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + sleep(10); + + if (tapi_get_call_count(slot_id) != 2 || + tapi_get_two_call_state(slot_id) != 1) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret2 = tapi_call_hangup_all_test(slot_id); + int ret3 = tapi_call_unlisten_call_test(); + + return ret2 || ret3; +} + +/* todo: 62 */ + +int incoming_new_call_in_calling_and_hangup_all_call(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + sleep(10); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + /* todo: incoming another call */ + + if ((judge() || judge_data.result) != 0) + return -1; + sleep(10); + if (tapi_get_call_count(slot_id) != 2 || + tapi_get_two_call_state(slot_id) != 5) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret2 = tapi_call_hangup_all_test(slot_id); + int ret3 = tapi_call_unlisten_call_test(); + + return ret2 || ret3; +} + +/* todo: 63 */ + +int call_dial_third_call(int slot_id) +{ + int ret1 = tapi_call_listen_call_test(slot_id); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_INCOMING; + + /* todo: incoming call */ + + if ((ret1 || judge() || judge_data.result) != 0) + return -1; + + sleep(10); + + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id) != 0) + return -1; + sleep(10); + judge_data_init(); + test_case_data_init(); + judge_data.expect = NEW_CALL_WAITING; + + /* todo: incoming another call */ + + if ((judge() || judge_data.result) != 0) + return -1; + sleep(10); + if (tapi_call_answer_call_test(slot_id, test_case_data.call_id)) + return -1; + sleep(10); + + if (tapi_get_call_count(slot_id) != 2 || + tapi_get_two_call_state(slot_id) != 1) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret2 = tapi_call_dial_test(slot_id, phone_num, 0); + + if (!ret2) + { + tapi_call_hangup_all_test(slot_id); + tapi_call_unlisten_call_test(); + return -1; + } + + int ret3 = tapi_call_hangup_all_test(slot_id); + int ret4 = tapi_call_unlisten_call_test(); + + return ret3 || ret4; +} + +/* 67 */ + +int call_listen_and_unlisten_ss(int slot_id) +{ + int ret1 = tapi_ss_listen_test(slot_id); + int ret2 = tapi_ss_unlisten_test(); + + return ret1 || ret2; +} + +/* 68 */ + +int call_listen_error_ss_code(int slot_id) +{ + return tapi_ss_listen_error_code_test(slot_id); +} + +void set_callback_data(int expect) +{ + judge_data_init(); + judge_data.expect = expect; +} + +int judge_callback_result(void) +{ + if ((judge() || judge_data.result) != 0) + return -1; + + return 0; +} + +void incoming_first_call(void) +{ + test_case_data_init(); + set_callback_data(NEW_CALL_INCOMING); +} + +void incoming_another_call(void) +{ + test_case_data_init(); + set_callback_data(NEW_CALL_WAITING); +} diff --git a/testing/testsuites/kernel/telephony/telephony_call_test.h b/testing/testsuites/kernel/telephony/telephony_call_test.h new file mode 100644 index 000000000..263b21131 --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_call_test.h @@ -0,0 +1,140 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_call_test.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 TELEPHONY_CALL_TEST_H_ +#define TELEPHONY_CALL_TEST_H_ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "telephony_test.h" +#include + +#define CALL_LOCAL_HANGUP 0x01 +#define CALL_STATE_CHANGE_TO_ACTIVE 0x02 +#define CALL_REMOTE_HANGUP 0x03 +#define NEW_CALL_INCOMING 0x04 +#define INCOMING_CALL_WITH_NETWORK_NAME 0x05 +#define HANGUP_DUE_TO_NETWORK_EXCEPTION 0x06 +#define CALL_STATE_CHANGE_TO_HOLD 0x07 +#define GET_ALL_CALLS 0x08 +#define GET_TWO_CALL_STATES 0x09 +#define GET_HOLD_CALL_ID 0x10 +#define GET_CURRENT_CALL_STATE 0x11 +#define NEW_CALL_WAITING 0x12 +#define NEW_CALL_DIALING 0x13 +#define EVENT_REQUEST_START_DTMF_DONE 0x14 +#define EVENT_REQUEST_STOP_DTMF_DONE 0x15 + +int tapi_call_listen_call_test(int slot_id); +int tapi_call_dial_test(int slot_id, char *phone_number, + int hide_caller_id); +int tapi_call_hanup_current_call_test(int slot_id); +int tapi_call_unlisten_call_test(void); +int tapi_call_dial_using_phone_number_with_area_code_test(int slot_id); +int tapi_call_dial_using_phone_number_with_pause_code_test(int slot_id); +int tapi_call_dial_using_phone_number_with_wait_code_test(int slot_id); +int tapi_call_dial_using_phone_number_with_numerous_code_test( + int slot_id); +int tapi_dial_number(int slot_id); +int tapi_dial_ecc_number(int slot_id); +int tapi_dial_with_enable_hide_callerid(int slot_id); +int tapi_dial_with_disabled_hide_callerid(int slot_id); +int tapi_dial_with_default_hide_callerid(int slot_id); +int tapi_dial_with_long_phone_number(int slot_id); +int tapi_dial_with_short_phone_number(int slot_id); +int tapi_start_dtmf_test(int slot_id); +int tapi_stop_dtmf_test(int slot_id); +int tapi_call_load_ecc_list_test(int slot_id); +int tapi_call_get_call_test(int slot_id); +int tapi_call_answer_call_test(int slot_id, char *call_id); +int tapi_ss_listen_test(int slot_id); +int tapi_ss_unlisten_test(void); +int tapi_ss_listen_error_code_test(int slot_id); +void set_callback_data(int expect); +int judge_callback_result(void); +void incoming_first_call(void); +void incoming_another_call(void); +int call_hangup_between_dialing_and_answering(int slot_id); +int call_dial_with_area_code(int slot_id); +int call_dial_after_caller_reject(int slot_id); +int call_hangup_after_caller_answer(int slot_id); +int call_dial_active_and_hangup_by_caller(int slot_id); +int call_dial_caller_reject_and_incoming(int slot_id); +int call_dial_caller_reject_and_dial_another(int slot_id); +int call_incoming_answer_and_hangup_by_dialer(int slot_id); +int call_dial_to_phone_in_call(int slot_id); +int call_dial_to_phone_out_of_service(int slot_id); +int call_dial_without_sim_card(int slot_id); +int call_dial_ecc_number_without_sim_card(int slot_id); +int call_incoming_and_hangup_by_dialer_before_answer(int slot_id); +int call_incoming_and_hangup_by_dialer_before_answer_numerous( + int slot_id); +int call_display_the_network_of_incoming_call(int slot_id, + char *network_name); +int call_dial_active_hangup_due_to_dialer_network_exception(int slot_id); +int call_dial_active_hangup_due_to_caller_network_exception(int slot_id); +int call_incoming_hangup_first_answer_second(int slot_id); +int call_incoming_hold_and_recover_by_dialer(int slot_id); +int call_dialer_hold_recover_and_hold_by_caller(int slot_id); +int call_incoming_hold_and_recover_by_caller(int slot_id); +int call_swap_dial_reject_swap(int slot_id); +int call_release_and_answer(int slot_id); +int call_hold_and_hangup(int slot_id); +int call_hold_incoming_hangup_second_recover_first(int slot_id); +int call_hold_incoming_answer_hangup_second_recover_first(int slot_id); +int call_incoming_second_call_swap_answer_hangup_swap(int slot_id); +int call_hold_current_call_and_reject_new_incoming(int slot_id); +int call_incoming_and_hangup_new_call(int slot_id); +int call_hold_first_call_and_answer_second_call(int slot_id); +int call_dial_second_call_active_and_hangup_by_dialer(int slot_id); +int call_dial_second_call_and_hangup_by_caller_before_answering( + int slot_id); +int call_dial_second_call_active_and_hangup_by_caller(int slot_id); +int call_hangup_hold_call_in_two_calls(int slot_id); +int call_dial_to_empty_number(int slot_id); +int call_incoming_answer_and_hangup(int slot_id); +int call_display_the_network_of_incoming_call_in_call_process( + int slot_id, char *network_name); +int call_check_status_in_dialing(int slot_id); +int call_dial_and_check_status_in_call_process(int slot_id); +int call_check_status_in_incoming(int slot_id); +int call_incoming_answer_and_check_status_in_call_process(int slot_id); +int call_incoming_answer_caller_hold_and_check_status(int slot_id); +int call_incoming_answer_dialer_hold_and_check_status(int slot_id); +int call_check_call_status_in_multi_call(int slot_id); +int call_check_call_status_in_call_waiting_with_multi_call(int slot_id); +int call_check_call_status_in_dialing_with_multi_call(int slot); +int call_hold_old_call_incoming_new_call_and_check_status(int slot_id); +int call_swap_in_two_calling(int slot_id); +int call_hangup_current_call_and_recover_hold_call(int slot_id); +int call_hangup_all_call_in_two_calling(int slot_id); +int incoming_new_call_in_calling_and_hangup_all_call(int slot_id); +int call_dial_third_call(int slot_id); +int call_incoming_third_call(int slot_id); +int call_listen_and_unlisten_ss(int slot_id); +int call_listen_error_ss_code(int slot_id); +int tapi_call_hangup_all_test(int slot_id); +int tapi_get_call_count(int slot_id); +int tapi_call_set_default_voicecall_slot_test(int slot_id); +int tapi_call_get_default_voicecall_slot_test(int expect_res); +int call_clear_voicecall_slot_set(void); +#endif \ No newline at end of file diff --git a/testing/testsuites/kernel/telephony/telephony_common_test.c b/testing/testsuites/kernel/telephony/telephony_common_test.c new file mode 100644 index 000000000..2a6a10e73 --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_common_test.c @@ -0,0 +1,696 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_common_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 "telephony_common_test.h" +#include +#include +#include + +#define DATA_INIT_VALUE -100 +#define HANDLE_REPEAT_TIME 1 +#define HANDLE_REPEAT_COUNT 10 + +#define MAX_MODEM_WATCH_COUNT 4 +#define MSG_DATA_IND_START MSG_DATA_ENABLED_CHANGE_IND +#define MSG_NETWORK_IND_START MSG_NETWORK_STATE_CHANGE_IND +#define MSG_MODEM_IND_START MSG_RADIO_STATE_CHANGE_IND + +static struct +{ + int radio_state_watch_id; + int phone_state_watch_id; + int modem_restart_ind_watch_id; + int oem_hook_raw_watch_id; + int modem_state; +} modem_data; + +extern struct judge_type judge_data; + +static void radio_signal_change(tapi_async_result *result); + +static void tele_call_async_fun(tapi_async_result *result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) + { + syslog(LOG_DEBUG, "%s msg id : %d result err, return.\n", __func__, + result->msg_id); + return; + } + + int event = result->msg_id; + int status = result->status; + + switch (event) + { + case EVENT_MODEM_ACTIVITY_INFO_QUERY_DONE: + syslog(LOG_DEBUG, + "%s: EVENT_MODEM_ACTIVITY_INFO_QUERY_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_MODEM_ACTIVITY_INFO_QUERY_DONE) + { + judge_data.result = status; + judge_data.flag = EVENT_MODEM_ACTIVITY_INFO_QUERY_DONE; + } + + break; + case EVENT_MODEM_ENABLE_DONE: + syslog(LOG_DEBUG, "%s: EVENT_MODEM_ENABLE_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_MODEM_ENABLE_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_MODEM_ENABLE_DONE; + } + + break; + case EVENT_RADIO_STATE_SET_DONE: + syslog(LOG_DEBUG, "%s: EVENT_RADIO_STATE_SET_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_RADIO_STATE_SET_DONE) + { + judge_data.result = status; + judge_data.flag = EVENT_RADIO_STATE_SET_DONE; + } + + break; + case EVENT_OEM_RIL_REQUEST_RAW_DONE: + syslog(LOG_DEBUG, + "%s: EVENT_OEM_RIL_REQUEST_RAW_DONE status: %d\n", __func__, + result->status); + if (judge_data.expect == EVENT_OEM_RIL_REQUEST_RAW_DONE) + { + judge_data.result = status; + judge_data.flag = EVENT_OEM_RIL_REQUEST_RAW_DONE; + } + + break; + case EVENT_OEM_RIL_REQUEST_STRINGS_DONE: + syslog(LOG_DEBUG, + "%s: EVENT_OEM_RIL_REQUEST_STRINGS_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_OEM_RIL_REQUEST_STRINGS_DONE) + { + judge_data.result = status; + judge_data.flag = EVENT_OEM_RIL_REQUEST_STRINGS_DONE; + } + + break; + case EVENT_MODEM_STATUS_QUERY_DONE: + syslog(LOG_DEBUG, "%s: EVENT_MODEM_STATUS_QUERY_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_MODEM_STATUS_QUERY_DONE) + { + judge_data.result = status; + judge_data.flag = EVENT_MODEM_STATUS_QUERY_DONE; + modem_data.modem_state = result->arg2; + } + + break; + case EVENT_RAT_MODE_SET_DONE: + syslog(LOG_DEBUG, "%s: EVENT_RAT_MODE_SET_DONE status: %d\n", + __func__, result->status); + if (judge_data.expect == EVENT_RAT_MODE_SET_DONE) + { + judge_data.result = status; + judge_data.flag = EVENT_RAT_MODE_SET_DONE; + } + + break; + default: + break; + } +} + +int tapi_get_imei_test(int slot_id) +{ + char *imei = NULL; + + int ret = tapi_get_imei(get_tapi_ctx(), slot_id, &imei); + syslog(LOG_DEBUG, "%s, slotId : %d imei : %s \n", __func__, slot_id, + imei); + + return ret; +} + +int tapi_get_modem_revision_test(int slot_id) +{ + char *version = NULL; + + int ret = tapi_get_modem_revision(get_tapi_ctx(), slot_id, &version); + syslog(LOG_DEBUG, "%s, slotId : %d version : %s \n", __func__, slot_id, + version); + + return ret || (!version); +} + +int tapi_get_pref_net_mode_test(int slot_id, tapi_pref_net_mode *value) +{ + int ret = tapi_get_pref_net_mode(get_tapi_ctx(), slot_id, value); + syslog(LOG_DEBUG, "%s, slotId : %d value :%d \n", __func__, slot_id, + *value); + return ret; +} + +int tapi_set_radio_power_test(int slot_id, bool target_state) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_RADIO_STATE_SET_DONE; + + int ret = tapi_set_radio_power(get_tapi_ctx(), slot_id, + EVENT_RADIO_STATE_SET_DONE, + target_state, tele_call_async_fun); + + if (ret) + { + syslog(LOG_ERR, + "tapi_set_radio_power_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_DEBUG, + "tapi_set_radio_power_test is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_get_radio_power_test(int slot_id, bool *value) +{ + int ret = tapi_get_radio_power(get_tapi_ctx(), slot_id, value); + syslog(LOG_DEBUG, "%s, slotId : %d value : %d \n", __func__, slot_id, + *value); + return ret; +} + +int tapi_modem_register_test(int slot_id) +{ + modem_data.radio_state_watch_id = -1; + modem_data.radio_state_watch_id = + tapi_register(get_tapi_ctx(), slot_id, MSG_RADIO_STATE_CHANGE_IND, + NULL, radio_signal_change); + if (modem_data.radio_state_watch_id < 0) + { + syslog(LOG_ERR, "%s, radio state change registered fail, ret: %d", + __func__, modem_data.radio_state_watch_id); + return -1; + } + + modem_data.phone_state_watch_id = -1; + modem_data.phone_state_watch_id = + tapi_register(get_tapi_ctx(), slot_id, MSG_PHONE_STATE_CHANGE_IND, + NULL, radio_signal_change); + if (modem_data.phone_state_watch_id < 0) + { + syslog(LOG_ERR, "%s, phone state change registered fail, ret: %d", + __func__, modem_data.phone_state_watch_id); + return -1; + } + + modem_data.modem_restart_ind_watch_id = -1; + modem_data.modem_restart_ind_watch_id = + tapi_register(get_tapi_ctx(), slot_id, MSG_MODEM_RESTART_IND, NULL, + radio_signal_change); + if (modem_data.modem_restart_ind_watch_id < 0) + { + syslog(LOG_ERR, "%s, modem restart ind registered fail, ret: %d", + __func__, modem_data.modem_restart_ind_watch_id); + return -1; + } + + modem_data.oem_hook_raw_watch_id = -1; + modem_data.oem_hook_raw_watch_id = + tapi_register(get_tapi_ctx(), slot_id, MSG_OEM_HOOK_RAW_IND, NULL, + radio_signal_change); + if (modem_data.oem_hook_raw_watch_id < 0) + { + syslog(LOG_ERR, "%s, oem hook raw registered fail, ret: %d", + __func__, modem_data.oem_hook_raw_watch_id); + return -1; + } + + return 0; +} + +int tapi_modem_unregister_test(void) +{ + int ret = -1; + int res = 0; + ret = tapi_unregister(get_tapi_ctx(), modem_data.radio_state_watch_id); + if (ret) + { + syslog(LOG_ERR, + "unregister radio state change fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_unregister(get_tapi_ctx(), modem_data.phone_state_watch_id); + if (ret) + { + syslog(LOG_ERR, + "unregister phone state change fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_unregister(get_tapi_ctx(), + modem_data.modem_restart_ind_watch_id); + if (ret) + { + syslog(LOG_ERR, + "unregister modem restart change fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = + tapi_unregister(get_tapi_ctx(), modem_data.oem_hook_raw_watch_id); + if (ret) + { + syslog(LOG_ERR, "unregister oem hook raw fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +static int hex_string_to_byte_array(char *hex_str, + unsigned char *byte_arr, int arr_len) +{ + char *str; + int len; + int i; + int j; + + if (hex_str == NULL) + return -EINVAL; + + len = strlen(hex_str); + if (!len || (len % 2) != 0 || len > arr_len * 2) + return -EINVAL; + + str = strdup(hex_str); + + for (i = 0, j = 0; i < len; i += 2, j++) + { + /* uppercase char 'a' ~ 'f' */ + + if (str[i] >= 'a' && str[i] <= 'f') + str[i] = str[i] & ~0x20; + + if (str[i + 1] >= 'a' && str[i + 1] <= 'f') + str[i + 1] = str[i + 1] & ~0x20; + + /* convert the first character to decimal. */ + + if (str[i] >= 'A' && str[i] <= 'F') + byte_arr[j] = (str[i] - 'A' + 10) << 4; + else if (str[i] >= '0' && str[i] <= '9') + byte_arr[j] = (str[i] & ~0x30) << 4; + else + return -EINVAL; + + /* convert the second character to decimal */ + + /* and combine with the previous decimal. */ + + if (str[i + 1] >= 'A' && str[i + 1] <= 'F') + byte_arr[j] |= (str[i + 1] - 'A' + 10); + else if (str[i + 1] >= '0' && str[i + 1] <= '9') + byte_arr[j] |= (str[i + 1] & ~0x30); + else + return -EINVAL; + } + + free(str); + return 0; +} + +int tapi_invoke_oem_ril_request_raw_test(int slot_id, char *oem_req, + int length) +{ + int res = 0; + unsigned char req_data[MAX_INPUT_ARGS_LEN]; + hex_string_to_byte_array(oem_req, req_data, MAX_INPUT_ARGS_LEN); + judge_data_init(); + judge_data.expect = EVENT_OEM_RIL_REQUEST_RAW_DONE; + + int ret = tapi_invoke_oem_ril_request_raw( + get_tapi_ctx(), slot_id, EVENT_OEM_RIL_REQUEST_RAW_DONE, req_data, + length, tele_call_async_fun); + + if (ret) + { + syslog(LOG_ERR, + "tapi_invoke_oem_ril_request_raw_test execute fail in %s, " + "ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog( + LOG_DEBUG, + "tapi_invoke_oem_ril_request_raw_test is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_invoke_oem_ril_request_strings_test(int slot_id, char *req_data, + int length) +{ + char *result; + char *ptr = NULL; + + /* FIXME: oem_req should be inited */ + + char *oem_req[MAX_OEM_RIL_RESP_STRINGS_LENTH] = + { + 0 + }; + + int count = 0; + int res = 0; + result = strtok_r(req_data, "|", &ptr); + while (result != NULL) + { + if (count < length) + oem_req[count] = result; + + count++; + result = strtok_r(NULL, "|", &ptr); + } + + judge_data_init(); + judge_data.expect = EVENT_OEM_RIL_REQUEST_STRINGS_DONE; + + int ret = tapi_invoke_oem_ril_request_strings( + get_tapi_ctx(), slot_id, EVENT_OEM_RIL_REQUEST_STRINGS_DONE, + oem_req, length, tele_call_async_fun); + + if (ret) + { + syslog(LOG_ERR, + "tapi_invoke_oem_ril_request_strings_test execute fail in " + "%s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_DEBUG, + "tapi_invoke_oem_ril_request_strings_test is not executed " + "in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_get_modem_activity_info_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_MODEM_ACTIVITY_INFO_QUERY_DONE; + + int ret = tapi_get_modem_activity_info( + get_tapi_ctx(), slot_id, EVENT_MODEM_ACTIVITY_INFO_QUERY_DONE, + tele_call_async_fun); + + if (ret) + { + syslog(LOG_ERR, + "tapi_get_modem_activity_info_test execute fail in %s, " + "ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_DEBUG, + "tapi_get_modem_activity_info_test is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_enable_modem_test(int slot_id, int target_state) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_MODEM_ENABLE_DONE; + + int ret = + tapi_enable_modem(get_tapi_ctx(), slot_id, EVENT_MODEM_ENABLE_DONE, + target_state, tele_call_async_fun); + + if (ret) + { + syslog(LOG_ERR, + "tapi_enable_modem_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_DEBUG, "tapi_enable_modem_test is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_get_modem_status_test(int slot_id, int *state) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_MODEM_STATUS_QUERY_DONE; + modem_data.modem_state = -1; + + int ret = tapi_get_modem_status(get_tapi_ctx(), slot_id, + EVENT_MODEM_STATUS_QUERY_DONE, + tele_call_async_fun); + + if (ret) + { + syslog(LOG_ERR, + "tapi_get_modem_enable_status_test execute fail in %s, " + "ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_DEBUG, + "tapi_get_modem_enable_status_test is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + if (modem_data.modem_state != *state) + { + syslog(LOG_ERR, "modem_data.modem_state is invalid in %s", + __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_set_pref_net_mode_test(int slot_id, + tapi_pref_net_mode target_state) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_RAT_MODE_SET_DONE; + + int ret = tapi_set_pref_net_mode(get_tapi_ctx(), slot_id, + EVENT_RAT_MODE_SET_DONE, target_state, + tele_call_async_fun); + + if (ret) + { + syslog(LOG_ERR, + "tapi_set_pref_net_mode_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_DEBUG, + "tapi_set_pref_net_mode_test is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static void radio_signal_change(tapi_async_result *result) +{ + int signal = result->msg_id; + int slot_id = result->arg1; + int param = result->arg2; + + switch (signal) + { + case MSG_RADIO_STATE_CHANGE_IND: + syslog(LOG_DEBUG, "radio state changed to %d in slot[%d] \n", + param, slot_id); + if (judge_data.expect == MSG_RADIO_STATE_CHANGE_IND) + { + judge_data.result = OK; + } + break; + case MSG_PHONE_STATE_CHANGE_IND: + syslog(LOG_DEBUG, "phone state changed to %d in slot[%d] \n", + param, slot_id); + if (judge_data.expect == MSG_PHONE_STATE_CHANGE_IND) + { + judge_data.result = OK; + } + break; + case MSG_MODEM_RESTART_IND: + syslog(LOG_DEBUG, "modem restart in slot[%d] \n", slot_id); + if (judge_data.expect == MSG_MODEM_RESTART_IND) + { + judge_data.result = OK; + } + break; + case MSG_OEM_HOOK_RAW_IND: + syslog(LOG_DEBUG, "oem hook raw in slot[%d] \n", slot_id); + if (judge_data.expect == MSG_OEM_HOOK_RAW_IND) + { + judge_data.result = OK; + } + break; + default: + break; + } +} diff --git a/testing/testsuites/kernel/telephony/telephony_common_test.h b/testing/testsuites/kernel/telephony/telephony_common_test.h new file mode 100644 index 000000000..be550675a --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_common_test.h @@ -0,0 +1,48 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_common_test.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 TELEPHONY_COMMON_TEST_H_ +#define TELEPHONY_COMMON_TEST_H_ +#define MAX_INPUT_ARGS_LEN 128 + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "telephony_test.h" + +int tapi_get_imei_test(int slot_id); +int tapi_get_modem_revision_test(int slot_id); +int tapi_get_modem_activity_info_test(int slot_id); +int tapi_get_pref_net_mode_test(int slot_id, tapi_pref_net_mode *value); +int tapi_set_radio_power_test(int slot_id, bool target_state); +int tapi_get_radio_power_test(int slot_id, bool *value); +int tapi_modem_register_test(int slot_id); +int tapi_modem_unregister_test(void); +int tapi_invoke_oem_ril_request_raw_test(int slot_id, char *oem_req, + int length); +int tapi_invoke_oem_ril_request_strings_test(int slot_id, char *req_data, + int length); +int tapi_enable_modem_test(int slot_id, int target_state); +int tapi_get_modem_status_test(int slot_id, int *state); +int tapi_set_pref_net_mode_test(int slot_id, + tapi_pref_net_mode target_state); + +#endif \ No newline at end of file diff --git a/testing/testsuites/kernel/telephony/telephony_data_test.c b/testing/testsuites/kernel/telephony/telephony_data_test.c new file mode 100644 index 000000000..a11d2e35b --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_data_test.c @@ -0,0 +1,971 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_data_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 "telephony_data_test.h" + +extern struct judge_type judge_data; +static struct +{ + int data_enabled_watch_id; + int data_connection_state_change_watch_id; + int data_on; + int connection_state; +} global_data; + +static void data_event_response(tapi_async_result *result); +static void data_signal_change(tapi_async_result *result); + +int tapi_data_listen_data_test(int slot_id) +{ + global_data.data_enabled_watch_id = -1; + global_data.data_enabled_watch_id = tapi_data_register( + get_tapi_ctx(), slot_id, MSG_DATA_ENABLED_CHANGE_IND, NULL, + data_signal_change); + + if (global_data.data_enabled_watch_id < 0) + { + syslog(LOG_ERR, "%s, slot_id: %d, target_state: %d, watch_id: %d", + __func__, slot_id, MSG_DATA_ENABLED_CHANGE_IND, + global_data.data_enabled_watch_id); + return -1; + } + + global_data.data_connection_state_change_watch_id = -1; + global_data.data_connection_state_change_watch_id = tapi_data_register( + get_tapi_ctx(), slot_id, MSG_DATA_CONNECTION_STATE_CHANGE_IND, + NULL, data_signal_change); + if (global_data.data_connection_state_change_watch_id < 0) + { + syslog(LOG_DEBUG, + "%s, slot_id: %d, target_state: %d, watch_id: %d", __func__, + slot_id, MSG_DATA_CONNECTION_STATE_CHANGE_IND, + global_data.data_connection_state_change_watch_id); + return -1; + } + + return 0; +} + +int tapi_data_unlisten_data_test(void) +{ + int ret = -1; + int res = 0; + syslog(LOG_INFO, + "data enabled watch id: %d, data connection state change watch " + "id: %d", + global_data.data_enabled_watch_id, + global_data.data_connection_state_change_watch_id); + ret = tapi_data_unregister(get_tapi_ctx(), + global_data.data_enabled_watch_id); + if (ret) + { + syslog(LOG_ERR, + "unregister data enable change fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_data_unregister( + get_tapi_ctx(), global_data.data_connection_state_change_watch_id); + if (ret) + { + syslog( + LOG_ERR, + "unregister data connection state change fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_data_load_apn_contexts_test(int slot_id) +{ + int ret = -1; + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_APN_LOADED_DONE; + ret = tapi_data_load_apn_contexts(get_tapi_ctx(), slot_id, + EVENT_APN_LOADED_DONE, + data_event_response); + + if (ret) + { + syslog( + LOG_ERR, + "tapi_data_load_apn_contexts_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "data_event_response called by %s is not execute", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_data_save_apn_context_test(char *slot_id, char *type, + char *name, char *apn, char *proto, + char *auth) +{ + int ret = -1; + int res = 0; + tapi_data_context *apn_context; + judge_data_init(); + judge_data.expect = EVENT_APN_ADD_DONE; + apn_context = malloc(sizeof(tapi_data_context)); + if (apn_context == NULL) + { + syslog(LOG_DEBUG, "apn_contex is null in %s", __func__); + return -EINVAL; + } + + apn_context->type = atoi(type); + apn_context->protocol = atoi(proto); + apn_context->auth_method = atoi(auth); + + if (strlen(name) <= MAX_APN_DOMAIN_LENGTH) + strcpy(apn_context->name, name); + + if (strlen(apn) <= MAX_APN_DOMAIN_LENGTH) + strcpy(apn_context->accesspointname, apn); + + strcpy(apn_context->username, ""); + strcpy(apn_context->password, ""); + + ret = tapi_data_add_apn_context(get_tapi_ctx(), atoi(slot_id), + EVENT_APN_ADD_DONE, apn_context, + data_event_response); + free(apn_context); + if (ret) + { + syslog(LOG_ERR, + "tapi_data_add_apn_context execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_DEBUG, "data_event_response is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_data_edit_apn_context_test(char *slot_id, char *id, char *type, + char *name, char *apn, char *proto, + char *auth) +{ + int ret = -1; + tapi_data_context *apn_context; + judge_data_init(); + judge_data.expect = EVENT_APN_EDIT_DONE; + apn_context = malloc(sizeof(tapi_data_context)); + if (apn_context == NULL) + { + syslog(LOG_ERR, "apn_context is null in %s", __func__); + return -EINVAL; + } + + apn_context->id = id; + apn_context->type = atoi(type); + apn_context->protocol = atoi(proto); + apn_context->auth_method = atoi(auth); + + if (strlen(name) <= MAX_APN_DOMAIN_LENGTH) + strcpy(apn_context->name, name); + + if (strlen(apn) <= MAX_APN_DOMAIN_LENGTH) + strcpy(apn_context->accesspointname, apn); + + strcpy(apn_context->username, ""); + strcpy(apn_context->password, ""); + + ret = tapi_data_edit_apn_context(get_tapi_ctx(), atoi(slot_id), + EVENT_APN_EDIT_DONE, apn_context, + data_event_response); + free(apn_context); + judge(); + + return ret || judge_data.result || + (judge_data.expect != judge_data.flag); +} + +int tapi_data_remove_apn_context_test(char *slot_id, char *id) +{ + int ret = -1; + int res = 0; + tapi_data_context *apn; + judge_data_init(); + judge_data.expect = EVENT_APN_REMOVAL_DONE; + + apn = malloc(sizeof(tapi_data_context)); + if (apn == NULL) + { + syslog(LOG_ERR, "apn is null in %s", __func__); + return ret; + } + + apn->id = id; + ret = tapi_data_remove_apn_context(get_tapi_ctx(), atoi(slot_id), + EVENT_APN_REMOVAL_DONE, apn, + data_event_response); + free(apn); + if (ret) + { + syslog(LOG_ERR, + "tapi_data_remove_apn_context execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "data_event_response is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_DEBUG, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_data_reset_apn_contexts_test(char *slot_id) +{ + int ret = -1; + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_APN_RESTORE_DONE; + + ret = tapi_data_reset_apn_contexts(get_tapi_ctx(), atoi(slot_id), + EVENT_APN_RESTORE_DONE, + data_event_response); + if (ret) + { + syslog(LOG_ERR, "tapi_data_reset_apn_contexts execute fail in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "data_event_response is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_data_request_network_test(int slot_id, char *target_state) +{ + int res = 0; + judge_data_init(); + judge_data.expect = MSG_DATA_CONNECTION_STATE_CHANGE_IND; + global_data.connection_state = -100; + + int ret = + tapi_data_request_network(get_tapi_ctx(), slot_id, target_state); + if (ret) + { + syslog(LOG_ERR, + "tapi_data_request_network execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, + "the callback function of request_network is not executed " + "in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.connection_state != 1) + { + syslog(LOG_ERR, "connection state is error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_data_release_network_test(int slot_id, char *target_state) +{ + int res = 0; + judge_data_init(); + judge_data.expect = MSG_DATA_CONNECTION_STATE_CHANGE_IND; + global_data.connection_state = -100; + int ret = + tapi_data_release_network(get_tapi_ctx(), slot_id, target_state); + if (ret) + { + syslog(LOG_ERR, + "tapi_data_release_network execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, + "the callback function of release_network is not executed " + "in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.connection_state != 0) + { + syslog(LOG_ERR, "connection state is error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_data_enable_test(int state) +{ + int res = 0; + judge_data_init(); + judge_data.expect = MSG_DATA_ENABLED_CHANGE_IND; + global_data.data_on = -1; + int ret = tapi_data_enable_data(get_tapi_ctx(), state); + if (ret) + { + syslog(LOG_ERR, + "tapi_data_enable_data execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog( + LOG_ERR, + "the callback function of data_enable is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result in %s is invalid", __func__); + res = -1; + goto on_exit; + } + + if (global_data.data_on != state) + { + syslog(LOG_ERR, "data status is error"); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +/* is - data - on */ + +int tapi_data_get_enabled_test(bool *result) +{ + int ret = tapi_data_get_enabled(get_tapi_ctx(), result); + bool flag = *result; + syslog(LOG_DEBUG, "ret: %d, result: %d", ret, (int)flag); + + return ret; +} + +int tapi_data_is_ps_attached_test(int slot_id) +{ + bool result = false; + int ret = tapi_data_is_registered(get_tapi_ctx(), slot_id, &result); + return ret || !result; +} + +int tapi_data_get_network_type_test(int slot_id) +{ + tapi_network_type result = NETWORK_TYPE_UNKNOWN; + int ret = tapi_data_get_network_type(get_tapi_ctx(), slot_id, &result); + return ret || result != NETWORK_TYPE_LTE; +} + +int tapi_data_enable_roaming_test(int state) +{ + int ret = tapi_data_enable_roaming(get_tapi_ctx(), state); + return ret; +} + +bool tapi_data_get_roaming_enabled_test(bool *result) +{ + int ret = tapi_data_get_roaming_enabled(get_tapi_ctx(), result); + return ret; +} + +int tapi_data_set_preferred_apn_test(int slot_id, char *apn_id) +{ + tapi_data_context *apn = malloc(sizeof(tapi_data_context)); + if (apn == NULL) + { + syslog(LOG_ERR, "apn is null in %s", __func__); + return -1; + } + + apn->id = apn_id; + int ret = tapi_data_set_preferred_apn(get_tapi_ctx(), slot_id, apn); + free(apn); + return ret; +} + +int tapi_data_get_preferred_apn_test(int slot_id) +{ + sleep(2); + char *apn = NULL; + int ret = tapi_data_get_preferred_apn(get_tapi_ctx(), slot_id, &apn); + syslog(LOG_DEBUG, "%s: %s", __func__, apn); + + return ret || strcmp(apn, "/ril_0/context1") != 0; +} + +int tapi_data_set_default_data_slot_test(int slot_id) +{ + int ret = tapi_data_set_default_slot(get_tapi_ctx(), slot_id); + return ret; +} + +int tapi_data_get_default_data_slot_test(void) +{ + int result = -1; + int ret = tapi_data_get_default_slot(get_tapi_ctx(), &result); + return ret || result != 0; +} + +int tapi_data_set_data_allow_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_DATA_ALLOWED_DONE; + int ret = tapi_data_set_data_allow(get_tapi_ctx(), slot_id, + EVENT_DATA_ALLOWED_DONE, 1, + data_event_response); + if (ret) + { + syslog(LOG_ERR, + "tapi_data_set_data_allow execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "data_event_response is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_data_send_screen_stat_test(int slot_id) +{ + int ret = tapi_set_fast_dormancy(get_tapi_ctx(), slot_id, + EVENT_REQUEST_SCREEN_STATE_DONE, 1, + data_event_response); + sleep(4); + + return ret; +} + +int tapi_data_get_data_call_list_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_DATA_CALL_LIST_QUERY_DONE; + + int ret = tapi_data_get_data_connection_list( + get_tapi_ctx(), slot_id, EVENT_DATA_CALL_LIST_QUERY_DONE, + data_event_response); + if (ret) + { + syslog(LOG_DEBUG, + "tapi_data_get_data_connection_list execute fail in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "data_event_response in %s is not executed", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_DEBUG, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +static void data_event_response(tapi_async_result *result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) + { + syslog(LOG_DEBUG, "%s msg id : %d result err, return.\n", __func__, + result->msg_id); + return; + } + + int event = result->msg_id; + int status = result->status; + + switch (event) + { + case EVENT_APN_LOADED_DONE: + if (judge_data.expect == EVENT_APN_LOADED_DONE) + { + judge_data.result = status; + judge_data.flag = EVENT_APN_LOADED_DONE; + } + + break; + case EVENT_APN_ADD_DONE: + if (judge_data.expect == EVENT_APN_ADD_DONE) + { + judge_data.result = status; + judge_data.flag = EVENT_APN_ADD_DONE; + } + + break; + case EVENT_APN_EDIT_DONE: + if (judge_data.expect == EVENT_APN_EDIT_DONE) + { + judge_data.result = status; + judge_data.flag = EVENT_APN_EDIT_DONE; + } + + break; + case EVENT_APN_REMOVAL_DONE: + if (judge_data.expect == EVENT_APN_REMOVAL_DONE) + { + judge_data.result = status; + judge_data.flag = EVENT_APN_REMOVAL_DONE; + } + + break; + case EVENT_APN_RESTORE_DONE: + if (judge_data.expect == EVENT_APN_RESTORE_DONE) + { + judge_data.result = status; + judge_data.flag = EVENT_APN_RESTORE_DONE; + } + + break; + case EVENT_DATA_ALLOWED_DONE: + if (judge_data.expect == EVENT_DATA_ALLOWED_DONE) + { + judge_data.result = status; + judge_data.flag = EVENT_DATA_ALLOWED_DONE; + } + + case EVENT_REQUEST_SCREEN_STATE_DONE: + if (judge_data.expect == EVENT_REQUEST_SCREEN_STATE_DONE) + { + judge_data.result = status; + judge_data.flag = EVENT_REQUEST_SCREEN_STATE_DONE; + } + + break; + case EVENT_DATA_CALL_LIST_QUERY_DONE: + if (judge_data.expect == EVENT_DATA_CALL_LIST_QUERY_DONE) + { + judge_data.result = status; + judge_data.flag = EVENT_DATA_CALL_LIST_QUERY_DONE; + } + + default: + break; + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static void data_signal_change(tapi_async_result *result) +{ + tapi_data_context *dc; + tapi_ipv4_settings *ipv4; + tapi_ipv6_settings *ipv6; + int signal = result->msg_id; + int slot_id = result->arg1; + int param = result->arg2; + + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) + { + syslog(LOG_DEBUG, "%s msg id : %d result err, return.\n", __func__, + result->msg_id); + return; + } + + switch (signal) + { + case MSG_DATA_REGISTRATION_STATE_CHANGE_IND: + syslog(LOG_DEBUG, + "data registration state changed to %d in slot[%d] \n", + param, slot_id); + if (judge_data.expect == MSG_DATA_REGISTRATION_STATE_CHANGE_IND) + { + judge_data.result = OK; + judge_data.flag = MSG_DATA_REGISTRATION_STATE_CHANGE_IND; + } + + break; + case MSG_DATA_NETWORK_TYPE_CHANGE_IND: + syslog(LOG_DEBUG, "data network type changed to %d in slot[%d] \n", + param, slot_id); + if (judge_data.expect == MSG_DATA_NETWORK_TYPE_CHANGE_IND) + { + judge_data.result = OK; + judge_data.flag = MSG_DATA_NETWORK_TYPE_CHANGE_IND; + } + + break; + case MSG_DEFAULT_DATA_SLOT_CHANGE_IND: + syslog(LOG_DEBUG, "data slot changed to slot[%d] \n", param); + if (judge_data.expect == MSG_DEFAULT_DATA_SLOT_CHANGE_IND) + { + judge_data.result = OK; + judge_data.flag = MSG_DEFAULT_DATA_SLOT_CHANGE_IND; + } + + break; + case MSG_DATA_ENABLED_CHANGE_IND: + if (judge_data.expect == MSG_DATA_ENABLED_CHANGE_IND) + { + syslog(LOG_DEBUG, "data switch changed to %d in slot[%d] \n", + param, slot_id); + judge_data.result = 0; + global_data.data_on = param; + judge_data.flag = MSG_DATA_ENABLED_CHANGE_IND; + } + + break; + case MSG_DATA_CONNECTION_STATE_CHANGE_IND: + if (judge_data.expect == MSG_DATA_CONNECTION_STATE_CHANGE_IND) + { + dc = result->data; + if (dc != NULL) + { + syslog(LOG_DEBUG, "id (apn_path) = %s \n", dc->id); + syslog(LOG_DEBUG, "type = %s \n", + tapi_utils_apn_type_to_string(dc->type)); + syslog(LOG_DEBUG, "active = %d \n", dc->active); + global_data.connection_state = dc->active; + if (dc->ip_settings != NULL) + { + ipv4 = dc->ip_settings->ipv4; + if (ipv4 != NULL) + { + syslog(LOG_DEBUG, + "ipv4-interface = %s; ip = %s; gateway = " + "%s; dns[0] = %s; \n", + ipv4->interface, ipv4->ip, ipv4->gateway, + ipv4->dns[0]); + } + + ipv6 = dc->ip_settings->ipv6; + if (ipv6 != NULL) + { + syslog(LOG_DEBUG, + "ipv6-interface = %s; ip = %s; gateway = " + "%s; dns[0] = %s; \n", + ipv6->interface, ipv6->ip, ipv6->gateway, + ipv6->dns[0]); + } + } + } + + judge_data.result = 0; + judge_data.flag = MSG_DATA_CONNECTION_STATE_CHANGE_IND; + } + + break; + default: + break; + } +} + +int data_enabled_test(int slot_id) +{ + int ret = tapi_data_enable_test(1); + syslog(LOG_DEBUG, "%s, ret: %d", __func__, ret); + + return ret; +} + +int data_disabled_test(int slot_id) +{ + int ret = tapi_data_enable_test(0); + syslog(LOG_DEBUG, "%s, ret: %d", __func__, ret); + + return ret; +} + +int data_release_network_test(int slot_id) +{ + int ret = tapi_data_release_network_test(slot_id, "internet"); + syslog(LOG_DEBUG, "%s, slot_id: %d, ret: %d", __func__, slot_id, ret); + + return ret; +} + +int data_request_network_test(int slot_id) +{ + int ret = tapi_data_request_network_test(slot_id, "internet"); + syslog(LOG_DEBUG, "%s, slot_id: %d, ret: %d", __func__, slot_id, ret); + + return ret; +} + +int data_request_ims(int slot_id) +{ + int ret = tapi_data_request_network_test(slot_id, "ims"); + syslog(LOG_DEBUG, "%s, slot_id: %d, ret: %d", __func__, slot_id, ret); + + return ret; +} + +int data_release_ims(int slot_id) +{ + int ret = tapi_data_release_network_test(slot_id, "ims"); + syslog(LOG_DEBUG, "%s, slot_id: %d, ret: %d", __func__, slot_id, ret); + + return ret; +} + +int data_get_call_list(int slot_id) +{ + int ret = -1; + int res = 0; + + ret = tapi_data_enable_test(1); + if (ret) + { + syslog(LOG_ERR, "enable data failed in %s, ret: %d", __func__, + ret); + res = -1; + goto on_exit; + } + + ret = tapi_data_get_data_call_list_test(slot_id); + if (ret) + { + syslog(LOG_ERR, "get data call list failed in %s", __func__); + res = -1; + goto on_exit; + } + + ret = tapi_data_enable_test(0); + if (ret) + { + syslog(LOG_ERR, "disable data failed in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int data_enable_roaming_test(void) +{ + bool result = false; + int ret = -1; + int res = 0; + ret = tapi_data_enable_roaming_test(true); + if (ret) + { + syslog(LOG_ERR, "enable data roaming failed"); + res = -1; + goto on_exit; + } + + sleep(3); + ret = tapi_data_get_roaming_enabled_test(&result); + if (ret) + { + syslog(LOG_ERR, "get data roaming failed in %s", __func__); + res = -1; + goto on_exit; + } + + if (!result) + { + syslog(LOG_ERR, "data roaming state is error in %s, state: %d", + __func__, (int)result); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int data_disable_roaming_test(void) +{ + bool result = true; + int ret = -1; + int res = 0; + ret = tapi_data_enable_roaming_test(false); + if (ret) + { + syslog(LOG_ERR, "disable data roaming failed in %s", __func__); + res = -1; + goto on_exit; + } + + sleep(3); + ret = tapi_data_get_roaming_enabled_test(&result); + if (ret) + { + syslog(LOG_ERR, "get data roaming failed in %s", __func__); + res = -1; + goto on_exit; + } + + if (result) + { + syslog(LOG_ERR, "data roaming state is error in %s, state: %d", + __func__, (int)result); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} diff --git a/testing/testsuites/kernel/telephony/telephony_data_test.h b/testing/testsuites/kernel/telephony/telephony_data_test.h new file mode 100644 index 000000000..e8203c9fc --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_data_test.h @@ -0,0 +1,66 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_data_test.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 TELEPHONY_DATA_TEST_H_ +#define TELEPHONY_DATA_TEST_H_ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "telephony_test.h" + +int tapi_data_listen_data_test(int slot_id); +int tapi_data_unlisten_data_test(void); +int tapi_data_enable_test(int state); +int tapi_data_load_apn_contexts_test(int slot_id); +int tapi_data_save_apn_context_test(char *slot_id, char *type, + char *name, char *apn, char *proto, + char *auth); +int tapi_data_edit_apn_context_test(char *slot_id, char *id, char *type, + char *name, char *apn, char *proto, + char *auth); +int tapi_data_remove_apn_context_test(char *slot_id, char *id); +int tapi_data_reset_apn_contexts_test(char *slot_id); +int tapi_data_request_network_test(int slot_id, char *target_state); +int tapi_data_release_network_test(int slot_id, char *target_state); +int tapi_data_enable_roaming_test(int); +bool tapi_data_get_roaming_enabled_test(bool *result); +int tapi_data_get_enabled_test(bool *result); +int tapi_data_is_ps_attached_test(int slot_id); +int tapi_data_get_network_type_test(int slot_id); +int tapi_data_set_preferred_apn_test(int slot_id, char *apn_id); +int tapi_data_get_preferred_apn_test(int slot_id); +int tapi_data_set_default_data_slot_test(int slot_id); +int tapi_data_get_default_data_slot_test(void); +int tapi_data_set_data_allow_test(int slot_id); +int tapi_data_send_screen_stat_test(int slot_id); +int tapi_data_get_data_call_list_test(int slot_id); +int data_enabled_test(int slot_id); +int data_disabled_test(int slot_id); +int data_release_network_test(int slot_id); +int data_request_network_test(int slot_id); +int data_request_ims(int slot_id); +int data_release_ims(int slot_id); +int data_get_call_list(int slot_id); +int data_enable_roaming_test(void); +int data_disable_roaming_test(void); + +#endif /* TELEPHONY_DATA_TEST_H_ */ diff --git a/testing/testsuites/kernel/telephony/telephony_ims_test.c b/testing/testsuites/kernel/telephony/telephony_ims_test.c new file mode 100644 index 000000000..1c204d068 --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_ims_test.c @@ -0,0 +1,197 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_ims_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 "telephony_ims_test.h" + +static void tele_ims_async_fun(tapi_async_result *result); +extern struct judge_type judge_data; + +static struct +{ + int ims_enabled; + int ims_reg_watch_id; +} global_data; + +int tapi_ims_listen_ims_test(int slot_id) +{ + global_data.ims_reg_watch_id = -1; + global_data.ims_reg_watch_id = tapi_ims_register_registration_change( + get_tapi_ctx(), slot_id, NULL, tele_ims_async_fun); + + if (global_data.ims_reg_watch_id < 0) + { + syslog(LOG_ERR, "%s, slot_id: %d, watch_id < 0\n", __func__, + slot_id); + return -1; + } + + return 0; +} + +int tapi_ims_turn_on_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = IMS_REG; + global_data.ims_enabled = -1; + int ret = tapi_ims_turn_on(get_tapi_ctx(), slot_id); + if (ret) + { + syslog(LOG_ERR, "tapi_ims_turn_on execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "the callback function is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.ims_enabled != 1) + { + syslog(LOG_ERR, "ims enabled is error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ims_turn_off_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = IMS_REG; + global_data.ims_enabled = -1; + int ret = tapi_ims_turn_off(get_tapi_ctx(), slot_id); + if (ret) + { + syslog(LOG_ERR, "tapi_ims_turn_off execute fail in %s", __func__); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "the callback function is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.ims_enabled != 0) + { + syslog(LOG_ERR, "ims enabled is error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ims_get_registration_test(int slot_id) +{ + tapi_ims_registration_info info; + memset(&info, 0, sizeof(info)); + int ret = tapi_ims_get_registration(get_tapi_ctx(), slot_id, &info); + syslog(LOG_ERR, "%s, slot_id: %d, reg_info: %d", __func__, slot_id, + info.reg_info); + + return ret || !info.reg_info; +} + +int tapi_ims_set_service_status_test(int slot_id, int status) +{ + int res = 0; + int ret = tapi_ims_set_service_status(get_tapi_ctx(), slot_id, status); + if (ret) + { + syslog(LOG_ERR, + "tapi_ims_set_service_status execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static void tele_ims_async_fun(tapi_async_result *result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + switch (result->arg1) + { + case IMS_REG: + if (judge_data.expect == IMS_REG) + { + syslog(LOG_DEBUG, "IMS_REG change : %d", result->arg2); + judge_data.result = 0; + global_data.ims_enabled = result->arg2; + judge_data.flag = IMS_REG; + } + break; + break; + default: + break; + } +} + +int tapi_ims_get_enabled_test(int slot_id) +{ + bool result = false; + int ret = tapi_ims_get_enabled(get_tapi_ctx(), slot_id, &result); + syslog(LOG_DEBUG, "%s, slot_id: %d, ims_enable: %d", __func__, slot_id, + result); + + return ret || !result; +} diff --git a/testing/testsuites/kernel/telephony/telephony_ims_test.h b/testing/testsuites/kernel/telephony/telephony_ims_test.h new file mode 100644 index 000000000..cf7046ee6 --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_ims_test.h @@ -0,0 +1,37 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_ims_test.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 TELEPHONY_IMS_TEST_H_ +#define TELEPHONY_IMS_TEST_H_ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "telephony_test.h" + +int tapi_ims_listen_ims_test(int slot_id); +int tapi_ims_turn_on_test(int slot_id); +int tapi_ims_turn_off_test(int slot_id); +int tapi_ims_get_registration_test(int slot_id); +int tapi_ims_get_enabled_test(int slot_id); +int tapi_ims_set_service_status_test(int slot_id, int status); + +#endif \ No newline at end of file diff --git a/testing/testsuites/kernel/telephony/telephony_network_test.c b/testing/testsuites/kernel/telephony/telephony_network_test.c new file mode 100644 index 000000000..cbc95a046 --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_network_test.c @@ -0,0 +1,470 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_network_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 "telephony_network_test.h" +#include + +extern struct judge_type judge_data; + +static struct +{ + int network_count; + int reg_state; + int serving_cell_reg; +} global_data; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static void network_event_callback(tapi_async_result *result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) + { + syslog(LOG_DEBUG, "%s msg id : %d result err, return.\n", __func__, + result->msg_id); + return; + } + + tapi_operator_info **operator_list; + tapi_operator_info *operator_info; + tapi_registration_info *info; + tapi_cell_identity **cell_list; + tapi_cell_identity *cell; + int msg; + int index; + + msg = result->msg_id; + + switch (msg) + { + case EVENT_NETWORK_SCAN_DONE: + if (judge_data.expect == EVENT_NETWORK_SCAN_DONE) + { + index = result->arg2; + operator_list = result->data; + + while (--index >= 0) + { + operator_info = *operator_list++; + syslog(LOG_DEBUG, + "id : %s, name : %s, status : %d, mcc : %s, mnc : " + "%s \n", + operator_info->id, operator_info->name, + operator_info->status, operator_info->mcc, + operator_info->mnc); + } + + judge_data.result = 0; + global_data.network_count = result->arg2; + judge_data.flag = EVENT_NETWORK_SCAN_DONE; + } + + break; + case EVENT_REGISTER_AUTO_DONE: + if (judge_data.expect == EVENT_REGISTER_AUTO_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_REGISTER_AUTO_DONE; + } + + break; + case EVENT_REGISTER_MANUAL_DONE: + if (judge_data.expect == EVENT_REGISTER_MANUAL_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_REGISTER_MANUAL_DONE; + } + + break; + case EVENT_QUERY_REGISTRATION_INFO_DONE: + if (judge_data.expect == EVENT_QUERY_REGISTRATION_INFO_DONE) + { + info = result->data; + syslog(LOG_DEBUG, "%s : \n", __func__); + if (info == NULL) + { + judge_data.result = -1; + judge_data.flag = EVENT_QUERY_REGISTRATION_INFO_DONE; + return; + } + + syslog( + LOG_DEBUG, + "reg_state = %d operator_name = %s mcc = %s mnc = %s \n", + info->reg_state, info->operator_name, info->mcc, + info->mnc); + + judge_data.result = 0; + global_data.reg_state = info->reg_state; + judge_data.flag = EVENT_QUERY_REGISTRATION_INFO_DONE; + } + + break; + case EVENT_QUERY_SERVING_CELL_DONE: + if (judge_data.expect == EVENT_QUERY_SERVING_CELL_DONE) + { + index = result->arg2; + cell_list = result->data; + + while (--index >= 0) + { + cell = *cell_list++; + syslog(LOG_DEBUG, + "ci : %d, mcc : %s, mnc : %s, registered : %d, " + "type : %d, \n", + cell->ci, cell->mcc_str, cell->mnc_str, + cell->registered, cell->type); + if (cell->registered == 1) + { + global_data.serving_cell_reg = 1; + } + } + + judge_data.result = 0; + judge_data.flag = EVENT_QUERY_SERVING_CELL_DONE; + } + + break; + case EVENT_QUERY_NEIGHBOURING_CELL_DONE: + if (judge_data.expect == EVENT_QUERY_NEIGHBOURING_CELL_DONE) + { + index = result->arg2; + cell_list = result->data; + + while (--index >= 0) + { + cell = *cell_list++; + syslog(LOG_DEBUG, + "ci : %d, mcc : %s, mnc : %s, registered : %d, " + "type : %d, \n", + cell->ci, cell->mcc_str, cell->mnc_str, + cell->registered, cell->type); + } + + judge_data.result = 0; + judge_data.flag = EVENT_QUERY_NEIGHBOURING_CELL_DONE; + } + + break; + default: + break; + } +} + +int tapi_net_select_auto_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_REGISTER_AUTO_DONE; + int ret = tapi_network_select_auto(get_tapi_ctx(), slot_id, + EVENT_REGISTER_AUTO_DONE, + network_event_callback); + if (ret) + { + syslog(LOG_ERR, + "tapi_network_select_auto execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "network_event_callback is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_net_select_manual_test(int slot_id, char *mcc, char *mnc, + char *tech) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_REGISTER_MANUAL_DONE; + tapi_operator_info *network_info = malloc(sizeof(tapi_operator_info)); + if (network_info == NULL) + { + syslog(LOG_ERR, "tapi_operator_info is null in %s", __func__); + return -ENOMEM; + } + + snprintf(network_info->mcc, sizeof(network_info->mcc), "%s", mcc); + snprintf(network_info->mnc, sizeof(network_info->mnc), "%s", mnc); + snprintf(network_info->technology, sizeof(network_info->technology), + "%s", tech); + + int ret = tapi_network_select_manual( + get_tapi_ctx(), slot_id, EVENT_REGISTER_MANUAL_DONE, network_info, + network_event_callback); + free(network_info); + if (ret) + { + syslog(LOG_ERR, + "tapi_network_select_manual execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "network_event_callback is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_net_scan_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_NETWORK_SCAN_DONE; + global_data.network_count = -1; + + int ret = + tapi_network_scan(get_tapi_ctx(), slot_id, EVENT_NETWORK_SCAN_DONE, + network_event_callback); + if (ret) + { + syslog(LOG_ERR, "tapi_network_scan execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "network_event_callback is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is error in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.network_count <= 0) + { + syslog(LOG_ERR, "network scan error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_net_registration_info_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_QUERY_REGISTRATION_INFO_DONE; + global_data.reg_state = -1; + int ret = tapi_network_get_registration_info( + get_tapi_ctx(), slot_id, EVENT_QUERY_REGISTRATION_INFO_DONE, + network_event_callback); + if (ret) + { + syslog(LOG_ERR, + "tapi_network_get_registration_info execute fail in %s, " + "ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "network_event_callback is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is error in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.reg_state != 1) + { + syslog(LOG_ERR, "reg state is error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_net_get_serving_cellinfos_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_QUERY_SERVING_CELL_DONE; + global_data.serving_cell_reg = -1; + int ret = tapi_network_get_serving_cellinfos( + get_tapi_ctx(), slot_id, EVENT_QUERY_SERVING_CELL_DONE, + network_event_callback); + if (ret) + { + syslog(LOG_ERR, + "tapi_network_get_serving_cellinfos execute fail in %s, " + "ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "network_event_callback is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.serving_cell_reg != 1) + { + syslog(LOG_ERR, "serving cell reg is error in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_net_get_neighbouring_cellinfos_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_QUERY_NEIGHBOURING_CELL_DONE; + int ret = tapi_network_get_neighbouring_cellinfos( + get_tapi_ctx(), slot_id, EVENT_QUERY_NEIGHBOURING_CELL_DONE, + network_event_callback); + if (ret) + { + syslog(LOG_ERR, + "tapi_network_get_neighbouring_cellinfos execute fail in " + "%s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "network_event_callback is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_net_get_operator_name_test(int slot_id) +{ + char *operator_name = NULL; + int ret = tapi_network_get_display_name(get_tapi_ctx(), slot_id, + &operator_name); + syslog(LOG_DEBUG, "%s, slotId : %d value :%s \n", __func__, slot_id, + operator_name); + + return ret || operator_name == NULL; +} + +int tapi_net_query_signalstrength_test(int slot_id) +{ + tapi_signal_strength ss; + memset(&ss, 0, sizeof(ss)); + int ret = + tapi_network_get_signalstrength(get_tapi_ctx(), slot_id, &ss); + syslog(LOG_DEBUG, "%s, slotId : %d RSRP value :%d \n", __func__, + slot_id, ss.rsrp); + + return ret || !ss.rsrp; +} + +int tapi_net_get_voice_registered_test(int slot_id) +{ + bool result = false; + int ret = + tapi_network_is_voice_registered(get_tapi_ctx(), slot_id, &result); + syslog(LOG_DEBUG, "%s, slot_id: %d, voice_reg: %d", __func__, slot_id, + (int)result); + + return ret || !result; +} diff --git a/testing/testsuites/kernel/telephony/telephony_network_test.h b/testing/testsuites/kernel/telephony/telephony_network_test.h new file mode 100644 index 000000000..31f481a24 --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_network_test.h @@ -0,0 +1,43 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_network_test.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 TELEPHONY_NETWORK_TEST_H_ +#define TELEPHONY_NETWORK_TEST_H_ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "telephony_test.h" + +int tapi_net_select_auto_test(int slot_id); +int tapi_net_select_manual_test(int slot_id, char *mcc, char *mnc, + char *tech); +int tapi_net_scan_test(int slot_id); +int tapi_net_registration_info_test(int slot_id); +int tapi_net_get_serving_cellinfos_test(int slot_id); +int tapi_net_get_neighbouring_cellinfos_test(int slot_id); +int tapi_net_get_voice_networktype_test(int slot_id, + tapi_network_type *type); +int tapi_net_get_operator_name_test(int slot_id); +int tapi_net_query_signalstrength_test(int slot_id); +int tapi_net_get_voice_registered_test(int slot_id); + +#endif /* TELEPHONY_NETWORK_TEST_H_ */ diff --git a/testing/testsuites/kernel/telephony/telephony_sim_test.c b/testing/testsuites/kernel/telephony/telephony_sim_test.c new file mode 100644 index 000000000..ec22153e7 --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_sim_test.c @@ -0,0 +1,1200 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_sim_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 "telephony_sim_test.h" + +extern struct judge_type judge_data; + +static struct +{ + int sim_state_change_watch_id; + int sim_uicc_app_enabled_change_watch_id; + int current_channel_session_id; +} global_data; + +static void global_data_init(void) +{ + global_data.sim_state_change_watch_id = -1; + global_data.sim_uicc_app_enabled_change_watch_id = -1; +} + +int tapi_sim_has_icc_card_test(int slot_id) +{ + bool result = false; + int ret = tapi_sim_has_icc_card(get_tapi_ctx(), slot_id, &result); + syslog(LOG_DEBUG, "%s, ret: %d, slot_id: %d, result: %d\n", __func__, + ret, slot_id, result); + + return ret || (!result); +} + +int tapi_sim_multi_has_icc_card_test(int slot_id) +{ + int ret = -1; + for (int i = 0; i < TEST_COUNT; ++i) + { + if ((ret = tapi_sim_has_icc_card_test(slot_id)) != 0) + { + return ret; + } + } + + return ret; +} + +int tapi_sim_get_sim_operator_test(int slot_id, const char *expect_res) +{ + char operator[MAX_MCC_LENGTH + MAX_MNC_LENGTH + 1]; + memset(operator, 0, sizeof(operator)); + int ret = tapi_sim_get_sim_operator( + get_tapi_ctx(), 0, + (MAX_MCC_LENGTH + MAX_MNC_LENGTH + 1), operator); + syslog(LOG_DEBUG, "%s, ret: %d, slot_id: %d, operator: %s\n", __func__, + ret, slot_id, operator); + + return ret || (operator[0] == 0) || strcmp(expect_res, operator); +} + +int tapi_sim_multi_get_sim_operator(int slot_id, const char *expect_res) +{ + int ret = -1; + for (int i = 0; i < TEST_COUNT; ++i) + { + if ((ret = tapi_sim_get_sim_operator_test(slot_id, expect_res)) != + 0) + { + return ret; + } + } + + return ret; +} + +int tapi_sim_get_sim_operator_name_test(int slot_id, + const char *expect_res) +{ + char *spn = NULL; + int ret = + tapi_sim_get_sim_operator_name(get_tapi_ctx(), slot_id, &spn); + syslog(LOG_DEBUG, "%s, ret: %d, slot_id: %d, spn: %s\n", __func__, ret, + slot_id, spn); + + return ret || (spn == NULL) || strcmp(expect_res, spn); +} + +int tapi_sim_get_sim_operator_name_numerous(int slot_id, + const char *expect_res) +{ + int ret = -1; + for (int i = 0; i < TEST_COUNT; ++i) + { + if ((ret = tapi_sim_get_sim_operator_name_test(slot_id, + expect_res)) != 0) + { + goto on_exit; + } + } + +on_exit: + return ret; +} + +int tapi_sim_get_sim_subscriber_id_test(int slot_id, + const char *expect_res) +{ + char *result = NULL; + int ret = tapi_sim_get_subscriber_id(get_tapi_ctx(), slot_id, &result); + syslog(LOG_DEBUG, "%s, ret: %d, slot_id: %d, subscriber_id: %s\n", + __func__, ret, slot_id, result); + + return ret || (!result) || strcmp(result, expect_res); +} + +int tapi_sim_multi_get_sim_subscriber_id_test(int slot_id, + const char *expect_res) +{ + int ret = -1; + for (int i = 0; i < TEST_COUNT; ++i) + { + if ((ret = tapi_sim_get_sim_subscriber_id_test(slot_id, + expect_res)) != 0) + { + return ret; + } + } + + return ret; +} + +int tapi_sim_get_sim_iccid_test(int slot_id, const char *expect_res) +{ + char *iccid = NULL; + int ret = tapi_sim_get_sim_iccid(get_tapi_ctx(), slot_id, &iccid); + syslog(LOG_DEBUG, "%s, ret: %d, slot_id: %d, iccid: %s\n", __func__, + ret, slot_id, iccid); + + return ret || iccid == NULL || strcmp(expect_res, iccid); +} + +int tapi_sim_multi_get_sim_iccid_test(int slot_id, + const char *expect_res) +{ + int ret = -1; + for (int i = 0; i < TEST_COUNT; ++i) + { + if ((ret = tapi_sim_get_sim_iccid_test(slot_id, expect_res)) != 0) + { + return ret; + } + } + + return ret; +} + +int tapi_sim_get_ef_msisdn_test(int slot_id, const char *expect_res) +{ + char *number = NULL; + int ret = tapi_get_msisdn_number(get_tapi_ctx(), slot_id, &number); + syslog(LOG_DEBUG, "%s, ret: %d, slotId : %d number : %s \n", __func__, + ret, slot_id, number); + + return ret || number == NULL || strcmp(expect_res, number); +} + +int tapi_sim_multi_get_ef_msisdn_test(int slot_id, + const char *expect_res) +{ + int ret = -1; + for (int i = 0; i < TEST_COUNT; ++i) + { + if ((ret = tapi_sim_get_ef_msisdn_test(slot_id, expect_res)) != 0) + { + return ret; + } + } + + return ret; +} + +int tapi_sim_get_state_test(int slot_id) +{ + int state = 0; + int ret = tapi_sim_get_sim_state(get_tapi_ctx(), slot_id, &state); + syslog(LOG_DEBUG, "%s, ret: %d, slotId : %d sim_state : %s \n", + __func__, ret, slot_id, + tapi_sim_state_to_string((tapi_sim_state)state)); + + return ret || state != 3; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static void tele_sim_async_fun(tapi_async_result *result) +{ + sim_lock_state *sim_lock = NULL; + sim_state_result *ss; + unsigned char *apdu_data; + int i; + + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) + { + syslog(LOG_DEBUG, "%s msg id : %d result err, return.\n", __func__, + result->msg_id); + return; + } + + if (result->msg_id == EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE || + result->msg_id == EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE) + { + apdu_data = (unsigned char *)result->data; + for (i = 0; i < result->arg2; i++) + syslog(LOG_DEBUG, "apdu data %d : %d ", i, apdu_data[i]); + + if (judge_data.expect == EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE; + } + else if (judge_data.expect == + EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE; + } + } + else if (result->msg_id == EVENT_OPEN_LOGICAL_CHANNEL_DONE) + { + syslog(LOG_DEBUG, "open logical channel respond session id : %d\n", + result->arg2); + global_data.current_channel_session_id = result->arg2; + + if (judge_data.expect == EVENT_OPEN_LOGICAL_CHANNEL_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_OPEN_LOGICAL_CHANNEL_DONE; + } + } + else if (result->msg_id == MSG_SIM_STATE_CHANGE_IND) + { + ss = result->data; + if (ss != NULL) + { + syslog(LOG_DEBUG, "response strings name : %s\n", ss->name); + if (strcmp(ss->name, "Present") == 0) + { + syslog(LOG_DEBUG, "response is sim present : %d\n", + ss->value); + } + else if (strcmp(ss->name, "PinRequired") == 0) + { + syslog(LOG_DEBUG, "response pin required type : %s\n", + (char *)ss->data); + } + else if (strcmp(ss->name, "LockedPins") == 0) + { + sim_lock = ss->data; + if (sim_lock != NULL) + { + for (i = 0; i < result->arg2; ++i) + { + syslog(LOG_DEBUG, + "response locked pins type : %s\n", + sim_lock->sim_pwd_type[i]); + } + } + } + else if (strcmp(ss->name, "Retries") == 0) + { + sim_lock = ss->data; + if (sim_lock != NULL) + { + for (i = 0; i < result->arg2; ++i) + { + syslog(LOG_DEBUG, + "response locked pins type : %s\n", + sim_lock->sim_pwd_type[i]); + syslog(LOG_DEBUG, + "response locked pins retries : %d\n", + sim_lock->retry_count[i]); + } + } + } + } + } + else if (result->msg_id == EVENT_CLOSE_LOGICAL_CHANNEL_DONE) + { + if (judge_data.expect == EVENT_CLOSE_LOGICAL_CHANNEL_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_CLOSE_LOGICAL_CHANNEL_DONE; + } + } + else if (result->msg_id == EVENT_UICC_ENABLEMENT_SET_DONE) + { + if (judge_data.expect == EVENT_UICC_ENABLEMENT_SET_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_UICC_ENABLEMENT_SET_DONE; + } + } + else if (result->msg_id == EVENT_ENTER_SIM_PIN_DONE) + { + if (judge_data.expect == EVENT_ENTER_SIM_PIN_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_ENTER_SIM_PIN_DONE; + } + } + else if (result->msg_id == EVENT_CHANGE_SIM_PIN_DONE) + { + if (judge_data.expect == EVENT_CHANGE_SIM_PIN_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_CHANGE_SIM_PIN_DONE; + } + } + else if (result->msg_id == EVENT_LOCK_SIM_PIN_DONE) + { + if (judge_data.expect == EVENT_LOCK_SIM_PIN_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_LOCK_SIM_PIN_DONE; + } + } + else if (result->msg_id == EVENT_UNLOCK_SIM_PIN_DONE) + { + if (judge_data.expect == EVENT_UNLOCK_SIM_PIN_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_UNLOCK_SIM_PIN_DONE; + } + } +} + +int tapi_sim_listen_sim_test(int slot_id, int event_id) +{ + global_data_init(); + + if (event_id != MSG_SIM_STATE_CHANGE_IND && + event_id != MSG_SIM_UICC_APP_ENABLED_CHANGE_IND) + { + syslog(LOG_ERR, "event id error\n"); + return -1; + } + + if (event_id == MSG_SIM_STATE_CHANGE_IND) + { + global_data.sim_state_change_watch_id = tapi_sim_register( + get_tapi_ctx(), slot_id, event_id, NULL, tele_sim_async_fun); + + if (global_data.sim_state_change_watch_id < 0) + { + syslog(LOG_ERR, + "%s, slot_id: %d, MSG_SIM_STATE_CHANGE_IND, watch id < " + "0\n", + __func__, slot_id); + return -1; + } + } + else + { + global_data.sim_uicc_app_enabled_change_watch_id = + tapi_sim_register(get_tapi_ctx(), slot_id, event_id, NULL, + tele_sim_async_fun); + + if (global_data.sim_uicc_app_enabled_change_watch_id < 0) + { + syslog(LOG_ERR, + "%s, slot_id: %d, MSG_SIM_UICC_APP_ENABLED_CHANGE_IND, " + "watch id < 0\n", + __func__, slot_id); + return -1; + } + } + + return 0; +} + +int tapi_sim_unlisten_sim_test(int slot_id, int watch_id) +{ + if (watch_id == -1 || + (watch_id != global_data.sim_state_change_watch_id && + watch_id != global_data.sim_uicc_app_enabled_change_watch_id)) + { + syslog(LOG_ERR, "watch id error\n"); + return -1; + } + + int ret = tapi_sim_unregister(get_tapi_ctx(), watch_id); + + if (ret == 0) + { + if (watch_id == global_data.sim_state_change_watch_id) + { + global_data.sim_state_change_watch_id = -1; + } + else + { + global_data.sim_uicc_app_enabled_change_watch_id = -1; + } + } + + return ret; +} + +int tapi_open_logical_channel_test(int slot_id) +{ + judge_data_init(); + judge_data.expect = EVENT_OPEN_LOGICAL_CHANNEL_DONE; + unsigned char aid[] = "A0000000871002FF86FFFF89FFFFFFFF"; + int res = 0; + global_data.current_channel_session_id = -1; + + int ret = tapi_sim_open_logical_channel( + get_tapi_ctx(), slot_id, EVENT_OPEN_LOGICAL_CHANNEL_DONE, aid, 16, + tele_sim_async_fun); + + if (ret) + { + syslog(LOG_ERR, + "tapi_sim_open_logical_channel execute fail, ret: %d", ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + if (global_data.current_channel_session_id == -1) + { + syslog(LOG_ERR, "session id is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_close_logical_channel_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_CLOSE_LOGICAL_CHANNEL_DONE; + + if (global_data.current_channel_session_id == -1) + { + syslog(LOG_ERR, "session id is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + int ret = tapi_sim_close_logical_channel( + get_tapi_ctx(), slot_id, EVENT_CLOSE_LOGICAL_CHANNEL_DONE, + global_data.current_channel_session_id, tele_sim_async_fun); + + if (ret) + { + syslog(LOG_ERR, + "tapi_sim_close_logical_channel execute fail, ret: %d", + ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + global_data.current_channel_session_id = -1; + return res; +} + +static int hex_string_to_byte_array(char *hex_str, + unsigned char *byte_arr, int arr_len) +{ + char *str; + int len; + int i; + int j; + int ret = -EINVAL; + + if (hex_str == NULL) + return ret; + + len = strlen(hex_str); + if (!len || (len % 2) != 0 || len > arr_len * 2) + return ret; + + str = strdup(hex_str); + if (str == NULL) + return ret; + + for (i = 0, j = 0; i < len; i += 2, j++) + { + /* uppercase char 'a' ~ 'f' */ + + if (str[i] >= 'a' && str[i] <= 'f') + str[i] = str[i] & ~0x20; + + if (str[i + 1] >= 'a' && str[i + 1] <= 'f') + str[i + 1] = str[i + 1] & ~0x20; + + /* convert the first character to decimal. */ + + if (str[i] >= 'A' && str[i] <= 'F') + byte_arr[j] = (str[i] - 'A' + 10) << 4; + else if (str[i] >= '0' && str[i] <= '9') + byte_arr[j] = (str[i] & ~0x30) << 4; + else + goto out; + + /* convert the second character to decimal + * and combine with the previous decimal. + */ + + if (str[i + 1] >= 'A' && str[i + 1] <= 'F') + byte_arr[j] |= (str[i + 1] - 'A' + 10); + else if (str[i + 1] >= '0' && str[i + 1] <= '9') + byte_arr[j] |= (str[i + 1] & ~0x30); + else + goto out; + } + + ret = 0; +out: + free(str); + + return ret; +} + +int tapi_transmit_apdu_basic_channel_test(int slot_id) +{ + char data[] = "A0B000010473656E669000"; + int res = 0; + unsigned char pdu[128]; + judge_data_init(); + judge_data.expect = EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE; + int len = strlen(data) / 2; + + if (hex_string_to_byte_array(data, pdu, 128) != 0) + { + syslog(LOG_ERR, "hex_string_to_byte_array execute fail"); + res = -1; + goto on_exit; + } + + int ret = tapi_sim_transmit_apdu_basic_channel( + get_tapi_ctx(), slot_id, EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, + pdu, len, tele_sim_async_fun); + + if (ret) + { + syslog( + LOG_ERR, + "tapi_sim_transmit_apdu_basic_channel execute fail, ret: %d", + ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_transmit_apdu_logical_channel_test(int slot_id) +{ + int res = 0; + + if (global_data.current_channel_session_id == -1) + { + syslog(LOG_ERR, "session is invalid in %s", __func__); + res = -1; + goto on_exit; + } + + unsigned char pdu[128]; + char data[] = "FFF2000000"; + int len = strlen(data) / 2; + + if (hex_string_to_byte_array(data, pdu, 128) != 0) + { + syslog(LOG_ERR, "hex_string_to_byte_array execute fail in %s", + __func__); + res = -1; + goto on_exit; + } + + judge_data_init(); + judge_data.expect = EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE; + + int ret = tapi_sim_transmit_apdu_logical_channel( + get_tapi_ctx(), slot_id, EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, + global_data.current_channel_session_id, pdu, len, + tele_sim_async_fun); + + if (ret) + { + syslog( + LOG_ERR, + "tapi_sim_transmit_apdu_logical_channel execute fail, ret: %d", + ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int sim_open_close_logical_channel_numerous(int slot_id) +{ + for (int i = 0; i < 10; i++) + { + if (tapi_open_logical_channel_test(slot_id)) + return -1; + + if (tapi_close_logical_channel_test(slot_id)) + return -1; + } + + return 0; +} + +int sim_transmit_apdu_by_logical_channel(int slot_id) +{ + int ret = -1; + int res = 0; + ret = tapi_open_logical_channel_test(slot_id); + if (ret) + { + syslog(LOG_ERR, + "tapi_open_logical_channel_test execute fail in %s", + __func__); + res = -1; + goto on_exit; + } + + ret = tapi_transmit_apdu_logical_channel_test(slot_id); + if (ret) + { + syslog( + LOG_ERR, + "tapi_transmit_apdu_logical_channel_test execute fail in %s", + __func__); + res = -1; + goto on_exit; + } + + ret = tapi_close_logical_channel_test(slot_id); + if (ret) + { + syslog(LOG_ERR, + "tapi_close_logical_channel_test execute fail in %s", + __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_sim_set_uicc_enablement_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_UICC_ENABLEMENT_SET_DONE; + + int ret = tapi_sim_set_uicc_enablement(get_tapi_ctx(), slot_id, + EVENT_UICC_ENABLEMENT_SET_DONE, + 1, tele_sim_async_fun); + + if (ret) + { + syslog(LOG_ERR, + "tapi_sim_set_uicc_enablement execute fail, ret: %d", ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_sim_get_uicc_enablement_test(int slot_id) +{ + tapi_sim_uicc_app_state state = SIM_UICC_APP_UNKNOWN; + int ret = + tapi_sim_get_uicc_enablement(get_tapi_ctx(), slot_id, &state); + syslog(LOG_DEBUG, "%s, ret: %d, state: %d", __func__, ret, (int)state); + + return ret || state != SIM_UICC_APP_ACTIVE; +} + +int tapi_sim_enter_pin_test(int slot_id) +{ + judge_data_init(); + judge_data.expect = EVENT_ENTER_SIM_PIN_DONE; + int res = 0; + + int ret = tapi_sim_enter_pin(get_tapi_ctx(), slot_id, + EVENT_ENTER_SIM_PIN_DONE, "pin2", "1234", + tele_sim_async_fun); + + if (ret) + { + syslog(LOG_DEBUG, "tapi_sim_enter_pin execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_sim_change_pin_test(int slot_id, char *old_pin, char *new_pin) +{ + syslog(LOG_DEBUG, "%s, old_pin: %s, new_pin: %s", __func__, old_pin, + new_pin); + judge_data_init(); + judge_data.expect = EVENT_CHANGE_SIM_PIN_DONE; + int res = 0; + + int ret = tapi_sim_change_pin(get_tapi_ctx(), slot_id, + EVENT_CHANGE_SIM_PIN_DONE, "pin2", + old_pin, new_pin, tele_sim_async_fun); + + if (ret) + { + syslog(LOG_ERR, "tapi_sim_change_pin execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int sim_change_pin_test(int slot_id) +{ + int ret = -1; + int res = 0; + ret = tapi_sim_change_pin_test(slot_id, "1234", "2345"); + if (ret) + { + syslog(LOG_DEBUG, "change pin from \"1234\" to \"2345\" fail"); + res = -1; + goto on_exit; + } + + ret = tapi_sim_change_pin_test(slot_id, "2345", "1234"); + if (ret) + { + syslog(LOG_DEBUG, "change pin from \"2345\" to \"1234\" fail"); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_sim_lock_pin_test(int slot_id) +{ + judge_data_init(); + judge_data.expect = EVENT_LOCK_SIM_PIN_DONE; + int res = 0; + + int ret = + tapi_sim_lock_pin(get_tapi_ctx(), slot_id, EVENT_LOCK_SIM_PIN_DONE, + "pin", "1234", tele_sim_async_fun); + + if (ret) + { + syslog(LOG_ERR, "tapi_sim_lock_pin execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_sim_unlock_pin_test(int slot_id) +{ + judge_data_init(); + judge_data.expect = EVENT_UNLOCK_SIM_PIN_DONE; + int res = 0; + + int ret = tapi_sim_unlock_pin(get_tapi_ctx(), slot_id, + EVENT_UNLOCK_SIM_PIN_DONE, "pin", "1234", + tele_sim_async_fun); + + if (ret) + { + syslog(LOG_ERR, "tapi_sim_unlock_pin execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_sim_async_fun was not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +static void tele_phonebook_async_fun(tapi_async_result *result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->msg_id == EVENT_LOAD_ADN_ENTRIES_DONE) + { + syslog(LOG_DEBUG, "adn entries : %s\n", (char *)result->data); + if (judge_data.expect == EVENT_LOAD_ADN_ENTRIES_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_LOAD_ADN_ENTRIES_DONE; + } + } + else if (result->msg_id == EVENT_LOAD_FDN_ENTRIES_DONE) + { + if (judge_data.expect == EVENT_LOAD_FDN_ENTRIES_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_LOAD_FDN_ENTRIES_DONE; + } + } + else if (result->msg_id == EVENT_INSERT_FDN_ENTRIES_DONE) + { + if (judge_data.expect == EVENT_INSERT_FDN_ENTRIES_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_INSERT_FDN_ENTRIES_DONE; + } + } + else if (result->msg_id == EVENT_UPDATE_FDN_ENTRIES_DONE) + { + if (judge_data.expect == EVENT_UPDATE_FDN_ENTRIES_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_UPDATE_FDN_ENTRIES_DONE; + } + } + else if (result->msg_id == EVENT_DELETE_FDN_ENTRIES_DONE) + { + if (judge_data.expect == EVENT_DELETE_FDN_ENTRIES_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_DELETE_FDN_ENTRIES_DONE; + } + } +} + +int tapi_phonebook_load_adn_entries_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_LOAD_ADN_ENTRIES_DONE; + int ret = tapi_phonebook_load_adn_entries(get_tapi_ctx(), slot_id, + EVENT_LOAD_ADN_ENTRIES_DONE, + tele_phonebook_async_fun); + if (ret) + { + syslog( + LOG_ERR, + "tapi_phonebook_load_adn_entries execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_phonebook_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_phonebook_load_fdn_entries_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_LOAD_FDN_ENTRIES_DONE; + int ret = tapi_phonebook_load_fdn_entries(get_tapi_ctx(), slot_id, + EVENT_LOAD_FDN_ENTRIES_DONE, + tele_phonebook_async_fun); + if (ret) + { + syslog( + LOG_DEBUG, + "tapi_phonebook_load_fdn_entries execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_phonebook_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_phonebook_insert_fdn_entry_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_INSERT_FDN_ENTRIES_DONE; + int ret = tapi_phonebook_insert_fdn_entry( + get_tapi_ctx(), slot_id, EVENT_INSERT_FDN_ENTRIES_DONE, "cmcc", + "10086", "1234", tele_phonebook_async_fun); + if (ret) + { + syslog( + LOG_ERR, + "tapi_phonebook_insert_fdn_entry execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_DEBUG, "tele_phonebook_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_phonebook_update_fdn_entry_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_UPDATE_FDN_ENTRIES_DONE; + int ret = tapi_phonebook_update_fdn_entry( + get_tapi_ctx(), 0, EVENT_UPDATE_FDN_ENTRIES_DONE, 1, "cmcc", + "1008601", "1234", tele_phonebook_async_fun); + if (ret) + { + syslog( + LOG_ERR, + "tapi_phonebook_update_fdn_entry execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_phonebook_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_phonebook_delete_fdn_entry_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_DELETE_FDN_ENTRIES_DONE; + int ret = tapi_phonebook_delete_fdn_entry( + get_tapi_ctx(), 0, EVENT_DELETE_FDN_ENTRIES_DONE, 1, "1234", + tele_phonebook_async_fun); + if (ret) + { + syslog( + LOG_ERR, + "tapi_phonebook_delete_fdn_entry execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_phonebook_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} diff --git a/testing/testsuites/kernel/telephony/telephony_sim_test.h b/testing/testsuites/kernel/telephony/telephony_sim_test.h new file mode 100644 index 000000000..8d4a78337 --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_sim_test.h @@ -0,0 +1,70 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_sim_test.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 TELEPHONY_SIM_TEST_H_ +#define TELEPHONY_SIM_TEST_H_ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "telephony_test.h" +#define TEST_COUNT 10 + +int tapi_sim_has_icc_card_test(int slot_id); +int tapi_sim_multi_has_icc_card_test(int slot_id); +int tapi_sim_get_sim_operator_test(int slot_id, const char *expect_res); +int tapi_sim_multi_get_sim_operator(int slot_id, const char *expect_res); +int tapi_sim_get_sim_operator_name_test(int slot_id, + const char *expect_res); +int tapi_sim_get_sim_operator_name_numerous(int slot_id, + const char *expect_res); +int tapi_sim_get_sim_subscriber_id_test(int slot_id, + const char *expect_res); +int tapi_sim_multi_get_sim_subscriber_id_test(int slot_id, + const char *expect_res); +int tapi_sim_get_sim_iccid_test(int slot_id, const char *expect_res); +int tapi_sim_multi_get_sim_iccid_test(int slot_id, + const char *expect_res); +int tapi_sim_get_ef_msisdn_test(int slot_id, const char *expect_res); +int tapi_sim_multi_get_ef_msisdn_test(int slot_id, + const char *expect_res); +int tapi_sim_listen_sim_test(int slot_id, int event_id); +int tapi_sim_unlisten_sim_test(int slot_id, int watch_id); +int tapi_open_logical_channel_test(int slot_id); +int tapi_close_logical_channel_test(int slot_id); +int tapi_transmit_apdu_basic_channel_test(int slot_id); +int tapi_sim_get_state_test(int slot_id); +int tapi_sim_set_uicc_enablement_test(int slot_id); +int tapi_sim_get_uicc_enablement_test(int slot_id); +int tapi_sim_enter_pin_test(int slot_id); +int tapi_sim_change_pin_test(int slot_id, char *old_pin, char *new_pin); +int tapi_sim_lock_pin_test(int slot_id); +int tapi_sim_unlock_pin_test(int slot_id); +int tapi_phonebook_load_adn_entries_test(int slot_id); +int tapi_phonebook_load_fdn_entries_test(int slot_id); +int tapi_phonebook_insert_fdn_entry_test(int slot_id); +int tapi_phonebook_update_fdn_entry_test(int slot_id); +int tapi_phonebook_delete_fdn_entry_test(int slot_id); +int sim_open_close_logical_channel_numerous(int slot_id); +int tapi_transmit_apdu_logical_channel_test(int slot_id); +int sim_transmit_apdu_by_logical_channel(int slot_id); +int sim_change_pin_test(int slot_id); + +#endif \ No newline at end of file diff --git a/testing/testsuites/kernel/telephony/telephony_sms_test.c b/testing/testsuites/kernel/telephony/telephony_sms_test.c new file mode 100644 index 000000000..19d7ec177 --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_sms_test.c @@ -0,0 +1,257 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_sms_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 "telephony_sms_test.h" +#include "telephony_call_test.h" +#include "telephony_common_test.h" +#include "telephony_ims_test.h" +#include + +extern struct judge_type judge_data; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static void tele_sms_event_response(tapi_async_result *result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) + { + syslog(LOG_DEBUG, "%s msg id: %d result err, return.\n", __func__, + result->msg_id); + return; + } + + judge_data.result = 0; + + if (result->msg_id == EVENT_SEND_MESSAGE_DONE) + { + syslog(LOG_DEBUG, "send message successed, uuid : %s\n", + (char *)result->data); + judge_data.flag = EVENT_SEND_MESSAGE_DONE; + } + else if (result->msg_id == EVENT_SEND_DATA_MESSAGE_DONE) + { + syslog(LOG_DEBUG, "send data message successed"); + judge_data.flag = EVENT_SEND_DATA_MESSAGE_DONE; + } +} + +int sms_send_message_test(tapi_context context, int slot_id, + char *number, char *text) +{ + if (context == NULL || number == NULL || text == NULL) + { + syslog(LOG_ERR, "%s, number: %s, text: %s", __func__, number, + text); + return -EINVAL; + } + + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_SEND_MESSAGE_DONE; + + int ret = tapi_sms_send_message(context, slot_id, 0, number, text, + EVENT_SEND_MESSAGE_DONE, + tele_sms_event_response); + if (ret) + { + syslog(LOG_ERR, + "tapi_sms_send_message execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_sms_event_response is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int sms_set_service_center_number_test(int slot_id) +{ + int ret = tapi_sms_set_service_center_address(get_tapi_ctx(), slot_id, + "10086"); + syslog(LOG_DEBUG, "%s, slot_id: %d, ret: %d", __func__, slot_id, ret); + + return ret; +} + +int sms_check_service_center_number_test(int slot_id) +{ + char *smsc_addr_rtn = NULL; + int ret = tapi_sms_get_service_center_address(get_tapi_ctx(), slot_id, + &smsc_addr_rtn); + syslog(LOG_DEBUG, "%s, slot_id: %d, ret: %d, smsc_addr_rtn: %s", + __func__, slot_id, ret, smsc_addr_rtn); + + return ret || strcmp(smsc_addr_rtn, "10086") != 0; +} + +int sms_send_data_message_test(int slot_id, char *to, int port, + char *text) +{ + if (to == NULL) + { + syslog(LOG_ERR, "to is null in %s", __func__); + return -EINVAL; + } + + if (text == NULL) + { + syslog(LOG_ERR, "text is null in %s", __func__); + return -EINVAL; + } + + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_SEND_DATA_MESSAGE_DONE; + int ret = tapi_sms_send_data_message( + get_tapi_ctx(), slot_id, 0, to, port, text, + EVENT_SEND_DATA_MESSAGE_DONE, tele_sms_event_response); + if (ret) + { + syslog(LOG_ERR, + "tapi_sms_send_data_message execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_sms_event_response is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int sms_send_message_in_dialing(int slot_id, char *to, char *text) +{ + int ret = -1; + int res = 0; + + ret = tapi_call_dial_test(slot_id, to, 0); + if (ret) + { + syslog(LOG_ERR, "tapi_call_dial_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = sms_send_message_test(get_tapi_ctx(), slot_id, to, text); + if (ret) + { + syslog(LOG_ERR, + "sms_send_message_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_call_hanup_current_call_test(slot_id); + if (ret) + { + syslog(LOG_ERR, + "tapi_call_hanup_current_call_test execute fail in %s, " + "ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int sms_send_data_message_in_dialing(int slot_id, char *to, char *text, + int port) +{ + int ret = -1; + int res = 0; + + ret = tapi_call_dial_test(slot_id, to, 0); + if (ret) + { + syslog(LOG_ERR, "tapi_call_dial_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = sms_send_data_message_test(slot_id, to, port, text); + if (ret) + { + syslog(LOG_ERR, + "sms_send_data_message_test execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + ret = tapi_call_hanup_current_call_test(slot_id); + if (ret) + { + syslog(LOG_ERR, + "tapi_call_hanup_current_call_test execute fail in %s, " + "ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} diff --git a/testing/testsuites/kernel/telephony/telephony_sms_test.h b/testing/testsuites/kernel/telephony/telephony_sms_test.h new file mode 100644 index 000000000..759a2481b --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_sms_test.h @@ -0,0 +1,40 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_sms_test.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 TELEPHONY_SMS_TEST_H_ +#define TELEPHONY_SMS_TEST_H_ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "telephony_test.h" + +int sms_send_message_test(tapi_context context, int slot_id, + char *number, char *text); +int sms_set_service_center_number_test(int slot_id); +int sms_check_service_center_number_test(int slot_id); +int sms_send_data_message_test(int slot_id, char *to, int port, + char *text); +int sms_send_message_in_dialing(int slot_id, char *to, char *text); +int sms_send_data_message_in_dialing(int slot_id, char *to, char *text, + int port); + +#endif /* TELEPHONY_SMS_TEST_H_ */ diff --git a/testing/testsuites/kernel/telephony/telephony_ss_test.c b/testing/testsuites/kernel/telephony/telephony_ss_test.c new file mode 100644 index 000000000..0825b9c5e --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_ss_test.c @@ -0,0 +1,779 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_ss_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 "telephony_ss_test.h" + +extern struct judge_type judge_data; + +static struct +{ + int call_barring_property_change_watch_id; + int ussd_property_change_watch_id; + int ussd_notification_received_watch_id; + int ussd_request_received_watch_id; + char cf_number[64]; + int fdn_enable; + int cf_type; + int cw; +} global_data; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static void ss_signal_change(tapi_async_result *result) +{ + tapi_call_barring_info *cb_value; + int signal = result->msg_id; + int slot_id = result->arg1; + + switch (signal) + { + case MSG_CALL_BARRING_PROPERTY_CHANGE_IND: + cb_value = result->data; + syslog(LOG_DEBUG, + "call barring service %s changed to %s in slot[%d] \n", + cb_value->service_type, cb_value->value, slot_id); + break; + case MSG_USSD_PROPERTY_CHANGE_IND: + syslog(LOG_DEBUG, "ussd state changed to %s in slot[%d] \n", + (char *)result->data, slot_id); + break; + case MSG_USSD_NOTIFICATION_RECEIVED_IND: + syslog(LOG_DEBUG, + "ussd notification message %s received in slot[%d] \n", + (char *)result->data, slot_id); + break; + case MSG_USSD_REQUEST_RECEIVED_IND: + syslog(LOG_DEBUG, + "ussd request message %s received in slot[%d] \n", + (char *)result->data, slot_id); + break; + default: + break; + } +} + +int tapi_listen_ss_test(int slot_id) +{ + global_data.call_barring_property_change_watch_id = -1; + global_data.call_barring_property_change_watch_id = tapi_ss_register( + get_tapi_ctx(), slot_id, MSG_CALL_BARRING_PROPERTY_CHANGE_IND, + NULL, ss_signal_change); + if (global_data.call_barring_property_change_watch_id < 0) + { + syslog(LOG_ERR, + "call barring property change register fail, ret: %d", + global_data.call_barring_property_change_watch_id); + return -1; + } + + global_data.ussd_property_change_watch_id = -1; + global_data.ussd_property_change_watch_id = tapi_ss_register( + get_tapi_ctx(), slot_id, MSG_USSD_PROPERTY_CHANGE_IND, NULL, + ss_signal_change); + if (global_data.ussd_property_change_watch_id < 0) + { + syslog(LOG_ERR, "ussd property change register fail, ret: %d", + global_data.ussd_property_change_watch_id); + return -1; + } + + global_data.ussd_notification_received_watch_id = -1; + global_data.ussd_notification_received_watch_id = tapi_ss_register( + get_tapi_ctx(), slot_id, MSG_USSD_NOTIFICATION_RECEIVED_IND, NULL, + ss_signal_change); + if (global_data.ussd_notification_received_watch_id < 0) + { + syslog(LOG_DEBUG, + "ussd notification received register fail, ret: %d", + global_data.ussd_notification_received_watch_id); + return -1; + } + + global_data.ussd_request_received_watch_id = -1; + global_data.ussd_request_received_watch_id = tapi_ss_register( + get_tapi_ctx(), slot_id, MSG_USSD_REQUEST_RECEIVED_IND, NULL, + ss_signal_change); + if (global_data.ussd_request_received_watch_id < 0) + { + syslog(LOG_ERR, "ussd request received register fail, ret: %d", + global_data.ussd_request_received_watch_id); + return -1; + } + + return 0; +} + +int tapi_unlisten_ss_test(void) +{ + int ret; + if (global_data.call_barring_property_change_watch_id < 0 || + global_data.ussd_property_change_watch_id < 0 || + global_data.ussd_notification_received_watch_id < 0 || + global_data.ussd_request_received_watch_id < 0) + { + return -1; + } + + ret = -1; + ret = tapi_ss_unregister( + get_tapi_ctx(), global_data.call_barring_property_change_watch_id); + if (ret < 0) + { + syslog(LOG_DEBUG, + "call barring property change unregister fail, ret: %d", + ret); + return -1; + } + + ret = -1; + ret = tapi_ss_unregister(get_tapi_ctx(), + global_data.ussd_property_change_watch_id); + if (ret < 0) + { + syslog(LOG_ERR, "ussd property change unregister fail, ret: %d", + ret); + return -1; + } + + ret = -1; + ret = tapi_ss_unregister( + get_tapi_ctx(), global_data.ussd_notification_received_watch_id); + if (ret < 0) + { + syslog(LOG_DEBUG, + "ussd notification received unregister fail, ret: %d", ret); + return -1; + } + + ret = -1; + ret = tapi_ss_unregister(get_tapi_ctx(), + global_data.ussd_request_received_watch_id); + if (ret < 0) + { + syslog(LOG_ERR, "ussd request received unregister fail, ret: %d", + ret); + return -1; + } + + return 0; +} + +static void tele_ss_async_fun(tapi_async_result *result) +{ + syslog(LOG_DEBUG, "%s : \n", __func__); + syslog(LOG_DEBUG, "result->msg_id : %d\n", result->msg_id); + syslog(LOG_DEBUG, "result->status : %d\n", result->status); + syslog(LOG_DEBUG, "result->arg1 : %d\n", result->arg1); + syslog(LOG_DEBUG, "result->arg2 : %d\n", result->arg2); + + if (result->status != OK) + { + syslog(LOG_DEBUG, "%s msg id : %d result err, return.\n", __func__, + result->msg_id); + return; + } + + if (result->msg_id == EVENT_QUERY_ALL_CALL_BARRING_DONE) + { + if (judge_data.expect == EVENT_QUERY_ALL_CALL_BARRING_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_QUERY_ALL_CALL_BARRING_DONE; + } + } + + else if (result->msg_id == EVENT_REQUEST_CALL_BARRING_DONE) + { + if (judge_data.expect == EVENT_REQUEST_CALL_BARRING_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_REQUEST_CALL_BARRING_DONE; + } + } + + else if (result->msg_id == EVENT_CALL_BARRING_PASSWD_CHANGE_DONE) + { + if (judge_data.expect == EVENT_CALL_BARRING_PASSWD_CHANGE_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_CALL_BARRING_PASSWD_CHANGE_DONE; + } + } + + else if (result->msg_id == EVENT_DISABLE_ALL_INCOMING_DONE) + { + if (judge_data.expect == EVENT_DISABLE_ALL_INCOMING_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_DISABLE_ALL_INCOMING_DONE; + } + } + + else if (result->msg_id == EVENT_DISABLE_ALL_OUTGOING_DONE) + { + if (judge_data.expect == EVENT_DISABLE_ALL_OUTGOING_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_DISABLE_ALL_OUTGOING_DONE; + } + } + + else if (result->msg_id == EVENT_DISABLE_ALL_CALL_BARRINGS_DONE) + { + if (judge_data.expect == EVENT_DISABLE_ALL_CALL_BARRINGS_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_DISABLE_ALL_CALL_BARRINGS_DONE; + } + } + + else if (result->msg_id == EVENT_REQUEST_CALL_FORWARDING_DONE) + { + if (judge_data.expect == EVENT_REQUEST_CALL_FORWARDING_DONE) + { + if (result->arg1 == global_data.cf_type && result->arg2 == 1) + { + judge_data.result = 0; + judge_data.flag = EVENT_REQUEST_CALL_FORWARDING_DONE; + } + } + } + + else if (result->msg_id == EVENT_QUERY_CALL_FORWARDING_DONE) + { + tapi_call_forward_info *cf_info = result->data; + if (judge_data.expect == EVENT_QUERY_CALL_FORWARDING_DONE) + { + if (result->arg1 == global_data.cf_type && cf_info != NULL && + !strcmp(global_data.cf_number, + cf_info->phone_number.number)) + { + judge_data.result = 0; + judge_data.flag = EVENT_QUERY_CALL_FORWARDING_DONE; + } + } + } + + else if (result->msg_id == EVENT_REQUEST_CALL_WAITING_DONE) + { + if (judge_data.expect == EVENT_REQUEST_CALL_WAITING_DONE) + { + if (result->arg2 == global_data.cw) + { + judge_data.result = 0; + judge_data.flag = EVENT_REQUEST_CALL_WAITING_DONE; + } + } + } + + else if (result->msg_id == EVENT_QUERY_CALL_WAITING_DONE) + { + if (judge_data.expect == EVENT_QUERY_CALL_WAITING_DONE) + { + if (result->arg2 == global_data.cw) + { + judge_data.result = 0; + judge_data.flag = EVENT_QUERY_CALL_WAITING_DONE; + } + } + } + + else if (result->msg_id == EVENT_ENABLE_FDN_DONE) + { + if (judge_data.expect == EVENT_ENABLE_FDN_DONE) + { + judge_data.result = 0; + judge_data.flag = EVENT_ENABLE_FDN_DONE; + } + } + + else if (result->msg_id == EVENT_QUERY_FDN_DONE) + { + if (judge_data.expect == EVENT_QUERY_FDN_DONE) + { + if (result->arg2 == global_data.fdn_enable) + { + judge_data.result = 0; + judge_data.flag = EVENT_QUERY_FDN_DONE; + } + } + } +} + +int tapi_ss_request_call_barring_test(int slot_id) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_QUERY_ALL_CALL_BARRING_DONE; + int ret = tapi_ss_request_call_barring( + get_tapi_ctx(), slot_id, EVENT_QUERY_ALL_CALL_BARRING_DONE, + tele_ss_async_fun); + if (ret) + { + syslog(LOG_ERR, + "tapi_ss_request_call_barring execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_set_call_barring_option_test(int slot_id, char *facility, + char *pin2) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_REQUEST_CALL_BARRING_DONE; + int ret = tapi_ss_set_call_barring_option( + get_tapi_ctx(), slot_id, EVENT_REQUEST_CALL_BARRING_DONE, "AI", + "1234", tele_ss_async_fun); + if (ret) + { + syslog( + LOG_ERR, + "tapi_ss_set_call_barring_option execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_get_call_barring_option_test(int slot_id, char *key, + char *expect) +{ + char *result = NULL; + int ret = tapi_ss_get_call_barring_option(get_tapi_ctx(), slot_id, key, + &result); + syslog(LOG_INFO, "%s, ret: %d, result: %s", __func__, ret, result); + return ret || result == NULL || strcmp(expect, result); +} + +int tapi_ss_change_call_barring_password_test(int slot_id, + char *old_passwd, + char *new_passwd) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_CALL_BARRING_PASSWD_CHANGE_DONE; + int ret = tapi_ss_change_call_barring_password( + get_tapi_ctx(), slot_id, EVENT_CALL_BARRING_PASSWD_CHANGE_DONE, + old_passwd, new_passwd, tele_ss_async_fun); + if (ret) + { + syslog(LOG_ERR, + "tapi_ss_change_call_barring_password execute fail in %s, " + "ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_disable_all_incoming_test(int slot_id, char *passwd) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_DISABLE_ALL_INCOMING_DONE; + int ret = tapi_ss_disable_all_incoming(get_tapi_ctx(), slot_id, + EVENT_DISABLE_ALL_INCOMING_DONE, + passwd, tele_ss_async_fun); + if (ret) + { + syslog(LOG_ERR, + "tapi_ss_disable_all_incoming execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_disable_all_outgoing_test(int slot_id, char *passwd) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_DISABLE_ALL_OUTGOING_DONE; + int ret = tapi_ss_disable_all_outgoing(get_tapi_ctx(), slot_id, + EVENT_DISABLE_ALL_OUTGOING_DONE, + passwd, tele_ss_async_fun); + if (ret) + { + syslog(LOG_ERR, + "tapi_ss_disable_all_outgoing execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_disable_all_call_barrings_test(int slot_id, char *passwd) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_DISABLE_ALL_CALL_BARRINGS_DONE; + int ret = tapi_ss_disable_all_call_barrings( + get_tapi_ctx(), slot_id, EVENT_DISABLE_ALL_CALL_BARRINGS_DONE, + passwd, tele_ss_async_fun); + if (ret) + { + syslog(LOG_ERR, + "tapi_ss_disable_all_call_barrings execute fail in %s, " + "ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_set_call_forwarding_option_test(int slot_id, int cf_type, + char *number) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_REQUEST_CALL_FORWARDING_DONE; + memset(global_data.cf_number, 0, sizeof(global_data.cf_number)); + strcpy(global_data.cf_number, number); + global_data.cf_type = cf_type; + int ret = tapi_ss_set_call_forwarding_option( + get_tapi_ctx(), slot_id, EVENT_REQUEST_CALL_FORWARDING_DONE, + cf_type, BEARER_CLASS_VOICE, number, tele_ss_async_fun); + + if (ret) + { + syslog(LOG_ERR, + "tapi_ss_set_call_forwarding_option execute fail in %s, " + "ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_get_call_forwarding_option_test(int slot_id, int cf_type) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_QUERY_CALL_FORWARDING_DONE; + global_data.cf_type = cf_type; + int ret = tapi_ss_query_call_forwarding_option( + get_tapi_ctx(), slot_id, EVENT_QUERY_CALL_FORWARDING_DONE, cf_type, + BEARER_CLASS_VOICE, tele_ss_async_fun); + if (ret) + { + syslog(LOG_ERR, + "tapi_ss_query_call_forwarding_option execute fail in %s, " + "ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_set_call_waiting_test(int slot_id, bool enable) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_REQUEST_CALL_WAITING_DONE; + global_data.cw = (int)enable; + int ret = tapi_ss_set_call_waiting(get_tapi_ctx(), slot_id, + EVENT_REQUEST_CALL_WAITING_DONE, + enable, tele_ss_async_fun); + if (ret) + { + syslog(LOG_ERR, + "tapi_ss_set_call_waiting execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_get_call_waiting_test(int slot_id, bool expect) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_QUERY_CALL_WAITING_DONE; + global_data.cw = (int)expect; + int ret = tapi_ss_get_call_waiting(get_tapi_ctx(), slot_id, + EVENT_QUERY_CALL_WAITING_DONE, + tele_ss_async_fun); + if (ret) + { + syslog(LOG_ERR, + "tapi_ss_get_call_waiting execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_enable_fdn_test(int slot_id, bool enable, char *passwd) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_ENABLE_FDN_DONE; + int ret = + tapi_ss_enable_fdn(get_tapi_ctx(), slot_id, EVENT_ENABLE_FDN_DONE, + enable, passwd, tele_ss_async_fun); + if (ret) + { + syslog(LOG_ERR, "tapi_ss_enable_fdn execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} + +int tapi_ss_query_fdn_test(int slot_id, bool expect) +{ + int res = 0; + judge_data_init(); + judge_data.expect = EVENT_QUERY_FDN_DONE; + global_data.fdn_enable = (int)expect; + int ret = tapi_ss_query_fdn(get_tapi_ctx(), slot_id, + EVENT_QUERY_FDN_DONE, tele_ss_async_fun); + if (ret) + { + syslog(LOG_ERR, "tapi_ss_query_fdn execute fail in %s, ret: %d", + __func__, ret); + res = -1; + goto on_exit; + } + + if (judge()) + { + syslog(LOG_ERR, "tele_ss_async_fun is not executed in %s", + __func__); + res = -1; + goto on_exit; + } + + if (judge_data.result) + { + syslog(LOG_ERR, "async result is invalid in %s", __func__); + res = -1; + goto on_exit; + } + +on_exit: + return res; +} diff --git a/testing/testsuites/kernel/telephony/telephony_ss_test.h b/testing/testsuites/kernel/telephony/telephony_ss_test.h new file mode 100644 index 000000000..36eba526e --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_ss_test.h @@ -0,0 +1,50 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_ss_test.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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#ifndef TELEPHONY_SS_TEST_H_ +#define TELEPHONY_SS_TEST_H_ + +#include "telephony_test.h" + +int tapi_listen_ss_test(int slot_id); +int tapi_unlisten_ss_test(void); +int tapi_ss_request_call_barring_test(int slot_id); +int tapi_ss_set_call_barring_option_test(int slot_id, char *facility, + char *pin2); +int tapi_ss_get_call_barring_option_test(int slot_id, char *key, + char *expect); +int tapi_ss_change_call_barring_password_test(int slot_id, + char *old_passwd, + char *new_passwd); +int tapi_ss_disable_all_incoming_test(int slot_id, char *passwd); +int tapi_ss_disable_all_outgoing_test(int slot_id, char *passwd); +int tapi_ss_disable_all_call_barrings_test(int slot_id, char *passwd); +int tapi_ss_set_call_forwarding_option_test(int slot_id, int cf_type, + char *number); +int tapi_ss_get_call_forwarding_option_test(int slot_id, int cf_type); +int tapi_ss_set_call_waiting_test(int slot_id, bool enable); +int tapi_ss_get_call_waiting_test(int slot_id, bool expect); +int tapi_ss_enable_fdn_test(int slot_id, bool enable, char *passwd); +int tapi_ss_query_fdn_test(int slot_id, bool expect); + +#endif /* TELEPHONY_SS_TEST_H_ */ diff --git a/testing/testsuites/kernel/telephony/telephony_test.h b/testing/testsuites/kernel/telephony/telephony_test.h new file mode 100644 index 000000000..50d6c1b7e --- /dev/null +++ b/testing/testsuites/kernel/telephony/telephony_test.h @@ -0,0 +1,138 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/telephony/telephony_test.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 TELEPHONY_TEST_H_ +#define TELEPHONY_TEST_H_ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define context tapi_test_context + +/* Generic Callback Event */ + +#define EVENT_MODEM_LIST_QUERY_DONE 0x1001 +#define EVENT_RADIO_STATE_SET_DONE 0x1002 +#define EVENT_RAT_MODE_SET_DONE 0x1003 +#define EVENT_MODEM_ACTIVITY_INFO_QUERY_DONE 0x1004 +#define EVENT_MODEM_ENABLE_DONE 0x1005 +#define EVENT_MODEM_STATUS_QUERY_DONE 0x1006 +#define EVENT_OEM_RIL_REQUEST_RAW_DONE 0x1007 +#define EVENT_OEM_RIL_REQUEST_STRINGS_DONE 0x1008 + +/* Data Callback Event */ + +#define EVENT_APN_LOADED_DONE 0x1009 +#define EVENT_APN_ADD_DONE 0x1010 +#define EVENT_APN_EDIT_DONE 0x101A +#define EVENT_APN_REMOVAL_DONE 0x101B +#define EVENT_APN_RESTORE_DONE 0x101C +#define EVENT_DATA_ALLOWED_DONE 0x101D +#define EVENT_DATA_CALL_LIST_QUERY_DONE 0x101E +#define EVENT_REQUEST_SCREEN_STATE_DONE 0x101F + +/* SIM Callback Event */ + +#define EVENT_CHANGE_SIM_PIN_DONE 0x21 +#define EVENT_ENTER_SIM_PIN_DONE 0x22 +#define EVENT_RESET_SIM_PIN_DONE 0x23 +#define EVENT_LOCK_SIM_PIN_DONE 0x24 +#define EVENT_UNLOCK_SIM_PIN_DONE 0x25 +#define EVENT_OPEN_LOGICAL_CHANNEL_DONE 0x26 +#define EVENT_CLOSE_LOGICAL_CHANNEL_DONE 0x27 +#define EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE 0x28 +#define EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE 0x29 +#define EVENT_UICC_ENABLEMENT_SET_DONE 0x2A + +/* Network Callback Event */ + +#define EVENT_NETWORK_SCAN_DONE 0x31 +#define EVENT_REGISTER_AUTO_DONE 0x32 +#define EVENT_REGISTER_MANUAL_DONE 0x33 +#define EVENT_QUERY_REGISTRATION_INFO_DONE 0x34 +#define EVENT_QUERY_SERVING_CELL_DONE 0x35 +#define EVENT_QUERY_NEIGHBOURING_CELL_DONE 0x36 +#define EVENT_NETWORK_SET_CELL_INFO_LIST_RATE_DONE 0x37 + +/* SS Callback Event */ + +#define EVENT_REQUEST_CALL_BARRING_DONE 0x41 +#define EVENT_CALL_BARRING_PASSWD_CHANGE_DONE 0x42 +#define EVENT_DISABLE_ALL_CALL_BARRINGS_DONE 0x43 +#define EVENT_DISABLE_ALL_INCOMING_DONE 0x44 +#define EVENT_DISABLE_ALL_OUTGOING_DONE 0x45 +#define EVENT_REQUEST_CALL_FORWARDING_DONE 0x46 +#define EVENT_DISABLE_CALL_FORWARDING_DONE 0x47 +#define EVENT_CANCEL_USSD_DONE 0x48 +#define EVENT_REQUEST_CALL_WAITING_DONE 0x49 +#define EVENT_SEND_USSD_DONE 0x4A +#define EVENT_INITIATE_SERVICE_DONE 0x4B +#define EVENT_ENABLE_FDN_DONE 0x4C +#define EVENT_QUERY_FDN_DONE 0x4D +#define EVENT_REQUEST_CLIR_DONE 0x4E +#define EVENT_QUERY_ALL_CALL_BARRING_DONE 0x4F +#define EVENT_QUERY_ALL_CALL_FORWARDING_DONE 0x50 +#define EVENT_QUERY_ALL_CALL_SETTING_DONE 0x51 +#define EVENT_QUERY_CALL_FORWARDING_DONE 0x52 +#define EVENT_QUERY_CALL_WAITING_DONE 0x53 + +/* PhoneBook Callback Event */ + +#define EVENT_LOAD_ADN_ENTRIES_DONE 0x61 +#define EVENT_LOAD_FDN_ENTRIES_DONE 0x62 +#define EVENT_INSERT_FDN_ENTRIES_DONE 0x63 +#define EVENT_UPDATE_FDN_ENTRIES_DONE 0x64 +#define EVENT_DELETE_FDN_ENTRIES_DONE 0x65 + +/* Call CallBack Event */ + +#define EVENT_REQUEST_DIAL_DONE 0x71 + +/* Sms CallBack Event */ + +#define EVENT_SEND_MESSAGE_DONE 0x81 +#define EVENT_SEND_DATA_MESSAGE_DONE 0x82 + +#define TIMEOUT 15 +#define INVALID_VALUE -1 + +tapi_context get_tapi_ctx(void); +int judge(void); +void judge_data_init(void); + +struct judge_type +{ + int flag; + int expect; + int result; +}; + +#endif /* TELEPHONY_TEST_H_ */ diff --git a/testing/testsuites/kernel/time/cases/clock_test_clock01.c b/testing/testsuites/kernel/time/cases/clock_test_clock01.c new file mode 100644 index 000000000..a0cedb891 --- /dev/null +++ b/testing/testsuites/kernel/time/cases/clock_test_clock01.c @@ -0,0 +1,96 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/time/cases/clock_test_clock01.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 +#include +#include +#include +#include "TimeTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_clock_test_clock01 + ****************************************************************************/ + +void test_nuttx_clock_test_clock01(FAR void **state) +{ + clockid_t clk = CLOCK_REALTIME; + struct timespec res; + struct timespec tp; + struct timespec oldtp; + int ret; + int passflag = 0; + + /* get clock resolution */ + + ret = clock_getres(clk, &res); + assert_int_equal(ret, 0); + + /* get current real time */ + + ret = clock_gettime(clk, &oldtp); + syslog(LOG_INFO, "The current real time: sec is %lld, nsec is %ld\n", + (long long)oldtp.tv_sec, oldtp.tv_nsec); + assert_int_equal(ret, 0); + + syslog(LOG_INFO, "sleep 2 seconds\n"); + sleep(2); + + /* 2, use for testing clock setting */ + + tp.tv_sec = oldtp.tv_sec + 2; + tp.tv_nsec = oldtp.tv_nsec; + + /* set real time */ + + ret = clock_settime(clk, &tp); + syslog(LOG_INFO, "Setting time: sec is %lld, nsec is %ld\n", + (long long)tp.tv_sec, tp.tv_nsec); + assert_int_equal(ret, 0); + + syslog(LOG_INFO, "get real time clock again\n"); + + /* get current real time again */ + + ret = clock_gettime(clk, &tp); + syslog(LOG_INFO, + "Obtaining the current time after setting: sec = %lld, nsec = " + "%ld\n", + (long long)tp.tv_sec, tp.tv_nsec); + passflag = (tp.tv_sec >= 2 + oldtp.tv_sec) && + (tp.tv_sec <= + 2 + oldtp.tv_sec + 1); /* 2, use for testing clock setting */ + + assert_int_equal(ret, 0); + assert_int_equal(passflag, 1); +} diff --git a/testing/testsuites/kernel/time/cases/clock_test_clock02.c b/testing/testsuites/kernel/time/cases/clock_test_clock02.c new file mode 100644 index 000000000..ebf355227 --- /dev/null +++ b/testing/testsuites/kernel/time/cases/clock_test_clock02.c @@ -0,0 +1,57 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/time/cases/clock_test_clock02.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 +#include +#include +#include +#include +#include "TimeTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_clock_test_clock02 + ****************************************************************************/ + +void test_nuttx_clock_test_clock02(FAR void **state) +{ + int ret; + struct timespec ts; + errno = 0; + + /* check param invalid */ + + ret = clock_gettime((clockid_t)-2050, &ts); /* 2050, clock id. */ + assert_int_equal(ret, -1); + assert_int_equal(errno, EINVAL); +} diff --git a/testing/testsuites/kernel/time/cases/clock_test_smoke.c b/testing/testsuites/kernel/time/cases/clock_test_smoke.c new file mode 100644 index 000000000..7de690d72 --- /dev/null +++ b/testing/testsuites/kernel/time/cases/clock_test_smoke.c @@ -0,0 +1,106 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/time/cases/clock_test_smoke.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 +#include +#include +#include +#include "TimeTest.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_clock_test_smoke01 + ****************************************************************************/ + +void test_nuttx_clock_test_smoke01(FAR void **state) +{ + clockid_t clk = CLOCK_REALTIME; + struct timespec res = + { + 0, 0 + }; + + struct timespec setts = + { + 0, 0 + }; + + struct timespec oldtp = + { + 0, 0 + }; + + struct timespec ts = + { + 0, 0 + }; + + int ret; + int passflag = 0; + + /* get clock resolution */ + + ret = clock_getres(clk, &res); + assert_int_equal(ret, 0); + + /* get clock realtime */ + + ret = clock_gettime(clk, &oldtp); + syslog(LOG_INFO, + "the clock current time: %lld second, %ld nanosecond\n", + (long long)oldtp.tv_sec, oldtp.tv_nsec); + assert_int_equal(ret, 0); + + /* set clock realtime */ + + setts.tv_sec = oldtp.tv_sec + 1; + setts.tv_nsec = oldtp.tv_nsec; + syslog(LOG_INFO, + "the clock setting time: %lld second, %ld nanosecond\n", + (long long)setts.tv_sec, setts.tv_nsec); + ret = clock_settime(CLOCK_REALTIME, &setts); + assert_int_equal(ret, 0); + + ret = clock_gettime(clk, &ts); + syslog(LOG_INFO, + "obtaining the current time after setting: %lld second, %ld " + "nanosecond\n", + (long long)ts.tv_sec, ts.tv_nsec); + + passflag = + (ts.tv_sec >= setts.tv_sec) && + (ts.tv_sec <= + setts.tv_sec + 1); /* 1, means obtaining time's errno is 1 second. */ + assert_int_equal(ret, 0); + assert_int_equal(passflag, 1); +} diff --git a/testing/testsuites/kernel/time/cases/clock_test_timer01.c b/testing/testsuites/kernel/time/cases/clock_test_timer01.c new file mode 100644 index 000000000..5146db372 --- /dev/null +++ b/testing/testsuites/kernel/time/cases/clock_test_timer01.c @@ -0,0 +1,183 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/time/cases/clock_test_timer01.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 +#include +#include +#include +#include +#include +#include +#include "TimeTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define SIG SIGALRM +#define CLOCKID CLOCK_REALTIME + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static int test_timer01_g_sighdlcnt = 0; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sighandler01 + ****************************************************************************/ + +static void sighandler01(int sig) +{ + test_timer01_g_sighdlcnt++; + syslog(LOG_INFO, "signo = %d test_timer01_g_sighdlcnt = %d\n", sig, + test_timer01_g_sighdlcnt); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_clock_test_timer01 + ****************************************************************************/ + +void test_nuttx_clock_test_timer01(FAR void **state) +{ + int interval = 3; /* 3, seconds */ + timer_t timerid01; + timer_t timerid02; + struct sigevent sev; + struct itimerspec its; + sigset_t mask; + struct sigaction sa; + int ret; + + sa.sa_flags = 0; + sa.sa_handler = sighandler01; + sigemptyset(&sa.sa_mask); + ret = sigaction(SIG, &sa, NULL); + syslog(LOG_INFO, "sigaction %d: %d", SIG, ret); + assert_int_equal(ret, 0); + + /* Block timer signal */ + + sigemptyset(&mask); + sigaddset(&mask, SIG); + ret = sigprocmask(SIG_BLOCK, &mask, NULL); + syslog(LOG_INFO, "sigprocmask setmask %d: %d", SIG, ret); + assert_int_equal(ret, 0); + + /* Create the timer */ + + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = SIG; + sev.sigev_value.sival_ptr = &timerid01; + ret = timer_create(CLOCKID, &sev, &timerid01); + syslog(LOG_INFO, "timer_create %p: %d", timerid01, ret); + assert_int_equal(ret, 0); + + /* Start the timer */ + + its.it_value.tv_sec = 0; + its.it_value.tv_nsec = 900000000; /* 900000000, 0.9s */ + its.it_interval.tv_sec = its.it_value.tv_sec; + its.it_interval.tv_nsec = its.it_value.tv_nsec; + + ret = timer_settime(timerid01, 0, &its, NULL); + syslog(LOG_INFO, "timer_settime %p: %d", timerid01, ret); + assert_int_equal(ret, 0); + + /* Test of evp is NULL */ + + ret = timer_create(CLOCKID, NULL, &timerid02); + syslog(LOG_INFO, "timer_settime %p: %d", timerid02, ret); + assert_int_equal(ret, 0); + + its.it_value.tv_sec = 1; + its.it_value.tv_nsec = 0; + its.it_interval.tv_sec = its.it_value.tv_sec; + its.it_interval.tv_nsec = its.it_value.tv_nsec; + + ret = timer_settime(timerid02, 0, &its, NULL); + syslog(LOG_INFO, "timer_settime %p: %d", timerid02, ret); + assert_int_equal(ret, 0); + + sleep(6); + + /* Sleep for a while */ + + syslog(LOG_INFO, "sleep %ds", interval); + + /* timer signal is blocked, + * this sleep should not be interrupted + */ + + sleep(interval); + + /* Get the timer's time */ + + ret = timer_gettime(timerid01, &its); + syslog(LOG_INFO, "timer_gettime %p: %d", timerid01, ret); + assert_int_equal(ret, 0); /* get time success */ + + syslog(LOG_INFO, "unblock signal %d", SIG); + + /* Unlock the timer signal */ + + ret = sigprocmask(SIG_UNBLOCK, &mask, NULL); + syslog(LOG_INFO, "sigprocmask unblock %d: %d", SIG, ret); + assert_int_equal(ret, 0); + + interval = 1; + syslog(LOG_INFO, "sleep another %ds", interval); + sleep(interval); /* this sleep may be interrupted by the timer */ + syslog(LOG_INFO, "sleep time over, test_timer01_g_sighdlcnt = %d", + test_timer01_g_sighdlcnt); + + syslog(LOG_INFO, "sleep another %ds", interval); + sleep(interval); /* this sleep may be interrupted by the timer */ + syslog(LOG_INFO, "sleep time over, test_timer01_g_sighdlcnt = %d", + test_timer01_g_sighdlcnt); + + ret = timer_delete(timerid01); + syslog(LOG_INFO, "timer_delete %p %d", timerid01, ret); + assert_int_equal(ret, 0); + + ret = timer_delete(timerid02); + syslog(LOG_INFO, "timer_delete %p %d", timerid02, ret); + assert_int_equal(ret, 0); + + assert_int_not_equal(test_timer01_g_sighdlcnt, 0); +} diff --git a/testing/testsuites/kernel/time/cases/clock_test_timer03.c b/testing/testsuites/kernel/time/cases/clock_test_timer03.c new file mode 100644 index 000000000..66ba27100 --- /dev/null +++ b/testing/testsuites/kernel/time/cases/clock_test_timer03.c @@ -0,0 +1,136 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/time/cases/clock_test_timer03.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 +#include +#include +#include +#include +#include +#include +#include +#include "TimeTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define SIG SIGALRM +#define CLOCKID CLOCK_REALTIME + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_clock_test_timer03 + ****************************************************************************/ + +void test_nuttx_clock_test_timer03(FAR void **state) +{ + int ret = 0; + int sig = 0; + int failed = 0; + timer_t timerid; + sigset_t set; + sigset_t oldset; + struct sigevent sev; + + ret = sigemptyset(&set); + assert_int_equal(ret, 0); + + ret = sigaddset(&set, SIG); + assert_int_equal(ret, 0); + + ret = sigprocmask(SIG_BLOCK, &set, &oldset); + assert_int_equal(ret, 0); + + /* Create the timer */ + + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = SIG; + sev.sigev_value.sival_ptr = &timerid; + ret = timer_create(CLOCKID, &sev, &timerid); + syslog(LOG_INFO, "timer_create %p: %d", timerid, ret); + assert_int_equal(ret, 0); + + struct timespec testcases[] = + { + {0, 30000000}, + {1, 0}, + {1, 5000}, + }; + + struct timespec zero = + { + 0, 0 + }; + + for (int i = 0; i < sizeof(testcases) / sizeof(testcases[0]); ++i) + { + struct timespec start; + struct timespec end; + struct itimerspec its; + int64_t expected, escaped; + + its.it_interval = zero; + its.it_value = testcases[i]; + + ret = clock_gettime(CLOCKID, &start); + assert_int_equal(ret, 0); + + ret = timer_settime(timerid, 0, &its, NULL); + assert_int_equal(ret, 0); + + ret = sigwait(&set, &sig); + assert_int_equal(ret, 0); + + ret = clock_gettime(CLOCKID, &end); + assert_int_equal(ret, 0); + + expected = + its.it_value.tv_sec * (int64_t)(1e9) + its.it_value.tv_nsec; + escaped = end.tv_sec * (int64_t)(1e9) + end.tv_nsec - + start.tv_sec * (int64_t)(1e9) - start.tv_nsec; + + failed += (escaped < expected || + (escaped - expected) >= 20000000); /* 20000000, 2 ticks. */ + syslog(LOG_INFO, "expected = %lld escaped = %lld failed = %d", + expected, escaped, failed); + } + + ret = timer_delete(timerid); + assert_int_equal(ret, 0); + + ret = sigprocmask(SIG_SETMASK, &oldset, NULL); + assert_int_equal(ret, 0); + + assert_int_equal(failed, 0); +} diff --git a/testing/testsuites/kernel/time/cases/clock_test_timer04.c b/testing/testsuites/kernel/time/cases/clock_test_timer04.c new file mode 100644 index 000000000..a93202ea9 --- /dev/null +++ b/testing/testsuites/kernel/time/cases/clock_test_timer04.c @@ -0,0 +1,160 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/time/cases/clock_test_timer04.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 +#include +#include +#include +#include +#include +#include +#include +#include "TimeTest.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* signo should be in the range SIGRTMIN to SIGRTMAX when SA_SIGINFO flag + * is set. + */ + +#define SIG SIGRTMIN +#define CLOCKID CLOCK_REALTIME + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static int test_timer04_g_handlerflag; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sighandler + ****************************************************************************/ + +static void sighandler(int sig, siginfo_t *si, void *uc) +{ + if (si == NULL) + { + syslog(LOG_ERR, "sig %d, si %p, uc %p\n", sig, si, uc); + return; + } + + test_timer04_g_handlerflag++; + syslog(LOG_INFO, "sig %d, si %p, uc %p\n", sig, si, uc); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_clock_test_timer04 + ****************************************************************************/ + +void test_nuttx_clock_test_timer04(FAR void **state) +{ + int interval = 3; /* 3 seconds */ + timer_t timerid; + struct sigevent sev; + struct itimerspec its; + sigset_t mask; + struct sigaction sa; + int ret; + + /* Install handler for timer signal. */ + + sa.sa_flags = SA_SIGINFO; + sa.sa_sigaction = sighandler; + sigemptyset(&sa.sa_mask); + ret = sigaction(SIG, &sa, NULL); + syslog(LOG_INFO, "sigaction %d: %d", SIG, ret); + assert_int_equal(ret, 0); + + /* Block timer signal */ + + sigemptyset(&mask); + sigaddset(&mask, SIG); + ret = sigprocmask(SIG_BLOCK, &mask, NULL); + syslog(LOG_INFO, "sigaction %d: %d", SIG, ret); + assert_int_equal(ret, 0); + + /* Create the timer */ + + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = SIG; + sev.sigev_value.sival_ptr = &timerid; + ret = timer_create(CLOCKID, &sev, &timerid); + syslog(LOG_INFO, "timer_create %p: %d", timerid, ret); + assert_int_equal(ret, 0); + + /* Start the timer */ + + its.it_value.tv_sec = 0; + its.it_value.tv_nsec = 990000000; /* 990000000, 0.99s */ + its.it_interval.tv_sec = its.it_value.tv_sec; + its.it_interval.tv_nsec = its.it_value.tv_nsec; + + ret = timer_settime(timerid, 0, &its, NULL); + syslog(LOG_INFO, "timer_create %p: %d", timerid, ret); + assert_int_equal(ret, 0); + + /* Sleep for a while */ + + syslog(LOG_INFO, "sleep %ds", interval); + sleep(interval); /* should not be interrupted */ + + /* Get the timer's time */ + + ret = timer_gettime(timerid, &its); + syslog(LOG_INFO, "timer_gettime %p: %d", timerid, ret); + assert_int_equal(ret, 0); + + /* Unlock the timer signal */ + + ret = sigprocmask(SIG_UNBLOCK, &mask, NULL); + syslog(LOG_INFO, "sigprocmask unblock %d: %d", SIG, ret); + assert_int_equal(ret, 0); + + syslog(LOG_INFO, "sleep another %ds", interval); + sleep(interval); /* should be interrupted */ + syslog(LOG_INFO, "sleep time over, g_handlerflag = %d", + test_timer04_g_handlerflag); + + ret = timer_delete(timerid); + syslog(LOG_INFO, "timer_delete %p %d", timerid, ret); + assert_int_equal(ret, 0); + + assert_int_not_equal(test_timer04_g_handlerflag, 0); +} diff --git a/testing/testsuites/kernel/time/cases/clock_test_timer05.c b/testing/testsuites/kernel/time/cases/clock_test_timer05.c new file mode 100644 index 000000000..a0754a26c --- /dev/null +++ b/testing/testsuites/kernel/time/cases/clock_test_timer05.c @@ -0,0 +1,155 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/time/cases/clock_test_timer05.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 +#include +#include +#include +#include +#include +#include +#include +#include "TimeTest.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static int test_timer05_g_sighdlcnt01; +static int test_timer05_g_sighdlcnt02; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tempsighandler + ****************************************************************************/ + +static void tempsighandler(union sigval v) +{ + syslog(LOG_INFO, "This is tempsighandler ...\r\n"); + (*(void (*)(void))(v.sival_ptr))(); +} + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tempsighandler01 + ****************************************************************************/ + +static void tempsighandler01(void) +{ + test_timer05_g_sighdlcnt01++; +} + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tempsighandler02 + ****************************************************************************/ + +static void tempsighandler02(void) +{ + test_timer05_g_sighdlcnt02++; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: test_nuttx_clock_test_timer05 + ****************************************************************************/ + +void test_nuttx_clock_test_timer05(FAR void **state) +{ + timer_t timerid01; + timer_t timerid02; + struct sigevent sev; + struct itimerspec its; + int ret; + char *p = NULL; + + p = memset(&sev, 0, sizeof(struct sigevent)); + assert_non_null(p); + sev.sigev_notify = SIGEV_THREAD; + sev.sigev_notify_function = tempsighandler; + sev.sigev_value.sival_ptr = (void *)tempsighandler01; + + /* Start the timer */ + + its.it_value.tv_sec = 3; /* 3, timer time 3 seconds. */ + its.it_value.tv_nsec = 0; + its.it_interval.tv_sec = its.it_value.tv_sec; + its.it_interval.tv_nsec = its.it_value.tv_nsec; + ret = timer_create(CLOCK_REALTIME, &sev, &timerid01); + syslog(LOG_INFO, "timer_settime %p: %d", timerid01, ret); + assert_int_equal(ret, 0); + + ret = timer_settime(timerid01, 0, &its, NULL); + syslog(LOG_INFO, "timer_create %p: %d", timerid01, ret); + assert_int_equal(ret, 0); + + its.it_value.tv_sec = 4; /* 4, timer time 4 seconds. */ + its.it_value.tv_nsec = 0; + its.it_interval.tv_sec = its.it_value.tv_sec; + its.it_interval.tv_nsec = its.it_value.tv_nsec; + + sev.sigev_value.sival_ptr = (void *)tempsighandler02; + ret = timer_create(CLOCK_REALTIME, &sev, &timerid02); + syslog(LOG_INFO, "timer_settime %p: %d", timerid02, ret); + assert_int_equal(ret, 0); + + ret = timer_settime(timerid02, 0, &its, NULL); + syslog(LOG_INFO, "timer_settime %p: %d", timerid02, ret); + assert_int_equal(ret, 0); + + its.it_value.tv_sec = 5; /* 5, timer time 5 seconds. */ + its.it_value.tv_nsec = 0; + its.it_interval.tv_sec = its.it_value.tv_sec; + its.it_interval.tv_nsec = its.it_value.tv_nsec; + + sleep(20); /* 20, sleep seconds for timer. */ + ret = timer_delete(timerid01); + syslog(LOG_INFO, "timer_delete %p %d", timerid01, ret); + assert_int_equal(ret, 0); + + ret = timer_delete(timerid02); + syslog(LOG_INFO, "timer_delete %p %d", timerid02, ret); + assert_int_equal(ret, 0); + + assert_int_not_equal(test_timer05_g_sighdlcnt01, 0); + assert_int_not_equal(test_timer05_g_sighdlcnt02, 0); +} diff --git a/testing/testsuites/kernel/time/cmocka_time_test.c b/testing/testsuites/kernel/time/cmocka_time_test.c new file mode 100644 index 000000000..4d36dcd76 --- /dev/null +++ b/testing/testsuites/kernel/time/cmocka_time_test.c @@ -0,0 +1,60 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/time/cmocka_time_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 "TimeTest.h" +#include + +/**************************************************************************** + * Name: cmocka_time_test_main + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +int main(int argc, char *argv[]) +{ + /* Add Test Cases */ + + const struct CMUnitTest nuttx_time_test_suites[] = + { + cmocka_unit_test(test_nuttx_clock_test_smoke01), + cmocka_unit_test(test_nuttx_clock_test_timer01), + cmocka_unit_test(test_nuttx_clock_test_timer03), + cmocka_unit_test(test_nuttx_clock_test_timer04), + cmocka_unit_test(test_nuttx_clock_test_timer05), + cmocka_unit_test(test_nuttx_clock_test_clock01), + cmocka_unit_test(test_nuttx_clock_test_clock02), + }; + + /* Run Test cases */ + + cmocka_run_group_tests(nuttx_time_test_suites, NULL, NULL); + return 0; +} diff --git a/testing/testsuites/kernel/time/include/TimeTest.h b/testing/testsuites/kernel/time/include/TimeTest.h new file mode 100644 index 000000000..79d259375 --- /dev/null +++ b/testing/testsuites/kernel/time/include/TimeTest.h @@ -0,0 +1,72 @@ +/**************************************************************************** + * apps/testing/testsuites/kernel/time/include/TimeTest.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 TIME_CLOCK_LT_CLOCK_TEST_H_ +#define TIME_CLOCK_LT_CLOCK_TEST_H_ +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define CLOCK_RES_SEC 0 +#define CLOCK_RES_NSEC 1000 +#define CLOCK_COARSE_RES_SEC 0 +#define CLOCK_COARSE_RES_NSEC 1000000 +#define CLOCK_GET_CPU_CLOCKID(pid) ((-(pid) - 1) * 8U + 2) + +/* cases/clock_test_smoke.c *************************************************/ + +void test_nuttx_clock_test_smoke01(FAR void **state); + +/* cases/clock_test_timer01.c ***********************************************/ + +void test_nuttx_clock_test_timer01(FAR void **state); + +/* cases/clock_test_timer03.c ***********************************************/ + +void test_nuttx_clock_test_timer03(FAR void **state); + +/* cases/clock_test_timer04.c ***********************************************/ + +void test_nuttx_clock_test_timer04(FAR void **state); + +/* cases/clock_test_timer05.c ***********************************************/ + +void test_nuttx_clock_test_timer05(FAR void **state); + +/* cases/clock_test_clock01.c ***********************************************/ + +void test_nuttx_clock_test_clock01(FAR void **state); + +/* cases/clock_test_clock02.c ***********************************************/ + +void test_nuttx_clock_test_clock02(FAR void **state); + +#endif /* TIME_CLOCK_LT_CLOCK_TEST_H_ */