int tc_libcxx_strings_string_assign_size_char(void) { { typedef std::string S; TC_ASSERT_FUNC((test(S(), 0, 'a', S()))); TC_ASSERT_FUNC((test(S(), 1, 'a', S(1, 'a')))); TC_ASSERT_FUNC((test(S(), 10, 'a', S(10, 'a')))); TC_ASSERT_FUNC((test(S(), 100, 'a', S(100, 'a')))); TC_ASSERT_FUNC((test(S("12345"), 0, 'a', S()))); TC_ASSERT_FUNC((test(S("12345"), 1, 'a', S(1, 'a')))); TC_ASSERT_FUNC((test(S("12345"), 10, 'a', S(10, 'a')))); TC_ASSERT_FUNC((test(S("12345678901234567890"), 0, 'a', S()))); TC_ASSERT_FUNC((test(S("12345678901234567890"), 1, 'a', S(1, 'a')))); TC_ASSERT_FUNC((test(S("12345678901234567890"), 10, 'a', S(10, 'a')))); } TC_SUCCESS_RESULT(); return 0; }
int tc_libcxx_containers_unord_map_types(void) { { typedef std::unordered_map<char, short> C; static_assert((std::is_same<C::key_type, char>::value), ""); static_assert((std::is_same<C::mapped_type, short>::value), ""); static_assert((std::is_same<C::hasher, std::hash<C::key_type> >::value), ""); static_assert((std::is_same<C::key_equal, std::equal_to<C::key_type> >::value), ""); static_assert((std::is_same<C::allocator_type, std::allocator<C::value_type> >::value), ""); static_assert((std::is_same<C::value_type, std::pair<const C::key_type, C::mapped_type> >::value), ""); static_assert((std::is_same<C::reference, C::value_type&>::value), ""); static_assert((std::is_same<C::const_reference, const C::value_type&>::value), ""); static_assert((std::is_same<C::pointer, C::value_type*>::value), ""); static_assert((std::is_same<C::const_pointer, const C::value_type*>::value), ""); static_assert((std::is_same<C::size_type, std::size_t>::value), ""); static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); } TC_SUCCESS_RESULT(); return 0; }
/** * @fn :tc_libc_misc_crc16part * @brief :Continue CRC calculation on a part of the buffer. * @scenario :Continue CRC calculation on a part of the buffer. * @API's covered :crc16part * @Preconditions :None * @Postconditions :None * @Return :void */ static void tc_libc_misc_crc16part(void) { uint16_t ret_chk; uint8_t src_arr[1] = { VAL_100 }; uint16_t crc_16val = 0; size_t length = 1; /* Return value should be 100 as calculated by crc16part */ ret_chk = crc16part(src_arr, length, crc_16val); TC_ASSERT_EQ("crc16part", ret_chk, VAL_100); /* Return value should be 65380 as calculated by crc16part */ crc_16val = VAL_255; ret_chk = crc16part(src_arr, length, crc_16val); TC_ASSERT_EQ("crc16part", ret_chk, VAL_65380); TC_SUCCESS_RESULT(); }
int tc_libcxx_strings_string_erase_iter(void) { { typedef std::string S; TC_ASSERT_FUNC((test(S("abcde"), 0, S("bcde")))); TC_ASSERT_FUNC((test(S("abcde"), 1, S("acde")))); TC_ASSERT_FUNC((test(S("abcde"), 2, S("abde")))); TC_ASSERT_FUNC((test(S("abcde"), 4, S("abcd")))); TC_ASSERT_FUNC((test(S("abcdefghij"), 0, S("bcdefghij")))); TC_ASSERT_FUNC((test(S("abcdefghij"), 1, S("acdefghij")))); TC_ASSERT_FUNC((test(S("abcdefghij"), 5, S("abcdeghij")))); TC_ASSERT_FUNC((test(S("abcdefghij"), 9, S("abcdefghi")))); TC_ASSERT_FUNC((test(S("abcdefghijklmnopqrst"), 0, S("bcdefghijklmnopqrst")))); TC_ASSERT_FUNC((test(S("abcdefghijklmnopqrst"), 1, S("acdefghijklmnopqrst")))); TC_ASSERT_FUNC((test(S("abcdefghijklmnopqrst"), 10, S("abcdefghijlmnopqrst")))); TC_ASSERT_FUNC((test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs")))); } TC_SUCCESS_RESULT(); return 0; }
int tc_libcxx_strings_string_cons_pointer_alloc(void) { { typedef test_allocator<char> A; TC_ASSERT_FUNC((test(""))); TC_ASSERT_FUNC((test("", A(2)))); TC_ASSERT_FUNC((test("1"))); TC_ASSERT_FUNC((test("1", A(2)))); TC_ASSERT_FUNC((test("1234567980"))); TC_ASSERT_FUNC((test("1234567980", A(2)))); TC_ASSERT_FUNC((test("123456798012345679801234567980123456798012345679801234567980"))); TC_ASSERT_FUNC((test("123456798012345679801234567980123456798012345679801234567980", A(2)))); } TC_SUCCESS_RESULT(); return 0; }
void itc_mqtt_connect_disconnect_p(void) { int res; g_mqtt_client_handle = mqtt_init_client(&g_mqtt_client_config); TC_ASSERT_NEQ("mqtt_init_client", g_mqtt_client_handle, NULL); // MQTT Connect res = mqtt_connect(g_mqtt_client_handle, CONFIG_ITC_MQTT_BROKER_ADDR, CONFIG_ITC_MQTT_BROKER_PORT, 0); TC_ASSERT_EQ("mqtt_connect", res, 0); ITC_MQTT_WAIT_SIGNAL; //MQTT Disconnect res = mqtt_disconnect(g_mqtt_client_handle); TC_ASSERT_EQ("mqtt_disconnect", res, 0); ITC_MQTT_WAIT_SIGNAL; res = mqtt_deinit_client(g_mqtt_client_handle); TC_ASSERT_EQ("mqtt_deinit_client", res, 0); TC_SUCCESS_RESULT(); }
/** * @fn :tc_pthread_pthread_kill * @brief :send a signal to a thread * @Scenario :The pthread_kill() function sends the signal sig to thread, a thread * in the same process as the caller. The signal is asynchronously * directed to thread. * API's covered :pthread_kill, pthread_join * Preconditions :none * Postconditions :none * @return :void */ static void tc_pthread_pthread_kill(void) { int ret_chk; g_bpthreadcallback = false; ret_chk = pthread_create(&g_thread1, NULL, thread_kill_func_callback, NULL); if (ret_chk != OK) { tckndbg("ERROR pthread_create FAIL\n"); pthread_detach(g_thread1); } sleep(SEC_2); ret_chk = pthread_kill(g_thread1, SIGUSR1); sleep(SEC_1); TC_ASSERT_EQ_CLEANUP("pthread_kill", ret_chk, OK, pthread_detach(g_thread1)); TC_ASSERT_EQ_CLEANUP("pthread_kill", g_bpthreadcallback, true, pthread_detach(g_thread1)); pthread_join(g_thread1, NULL); TC_SUCCESS_RESULT(); }
/** * @testcase :itc_net_listen_p_different_socket * @brief :listen for socket connections and limit the queue of incoming connections * @scenario :create socket, bind it and then listen * @apicovered :listen() * @precondition :open socket * @postcondition :close socket */ static void itc_net_listen_p_different_socket(void) { struct sockaddr_in sa; struct sockaddr_in saddr; int socket_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); TC_ASSERT_GEQ("socket", socket_fd, CONFIG_NFILE_DESCRIPTORS); int fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); TC_ASSERT_GEQ("socket", fd, CONFIG_NFILE_DESCRIPTORS); memset(&sa, 0, sizeof sa); memset(&saddr, 0, sizeof saddr); sa.sin_family = AF_INET; sa.sin_port = htons(ADDR_PORT); sa.sin_addr.s_addr = htonl(INADDR_ANY); saddr.sin_family = AF_INET; saddr.sin_port = htons(SOCK_PORT); saddr.sin_addr.s_addr = htonl(INADDR_ANY); int ret = bind(socket_fd, (struct sockaddr *)&sa, sizeof(sa)); TC_ASSERT_EQ_CLEANUP("bind", ret, 0, close(socket_fd); close(fd)); ret = bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)); TC_ASSERT_EQ_CLEANUP("bind", ret, 0, close(socket_fd); close(fd)); ret = listen(socket_fd, BACK_LOG); TC_ASSERT_EQ_CLEANUP("listen", ret, 0, close(socket_fd); close(fd)); ret = listen(fd, BACK_LOG); TC_ASSERT_EQ_CLEANUP("listen", ret, 0, close(socket_fd); close(fd)); ret = close(socket_fd); TC_ASSERT_EQ_CLEANUP("close", ret, 0, close(fd)); ret = close(fd); TC_ASSERT_EQ("close", ret, 0); TC_SUCCESS_RESULT(); }
/** * @fn : tc_libc_spawn_add_file_action * @brief : Add the file action * @scenario : Add the file action to the end for the file action list * @API's covered : posix_spawn_file_actions_init, posix_spawn_file_actions_addopen, add_file_action * @Preconditions : posix_spawn_file_actions_init,posix_spawn_file_actions_addopen * @Postconditions : posix_spawn_file_actions_destroy * @Return : void */ static void tc_libc_spawn_add_file_action(void) { const char szfilepath[] = "./testdata.txt"; posix_spawn_file_actions_t st_fileactions; struct spawn_open_file_action_s *entry1; struct spawn_open_file_action_s *entry2; size_t length; size_t alloc_num; int ret_chk = ERROR; ret_chk = posix_spawn_file_actions_init(&st_fileactions); TC_ASSERT_EQ("posix_spawn_file_actions_init", ret_chk, OK); ret_chk = posix_spawn_file_actions_addopen(&st_fileactions, 1, szfilepath, O_WRONLY, 0644); TC_ASSERT_EQ("posix_spawn_file_actions_addopen", ret_chk, OK); length = strlen(szfilepath); alloc_num = SIZEOF_OPEN_FILE_ACTION_S(length); /* Allocate the action list entry of this size */ entry1 = (struct spawn_open_file_action_s *)zalloc(alloc_num); TC_ASSERT_NOT_NULL("zalloc", entry1); /* And add it to the file action list */ add_file_action(st_fileactions, (struct spawn_general_file_action_s *)entry1); entry2 = (struct spawn_open_file_action_s *)zalloc(alloc_num); TC_ASSERT_NOT_NULL("zalloc", entry2); /* And add it to the file action list */ add_file_action(st_fileactions, (struct spawn_general_file_action_s *)entry2); TC_ASSERT_EQ("add_file_action", entry1->flink, (struct spawn_general_file_action_s *)entry2); ret_chk = posix_spawn_file_actions_destroy(&st_fileactions); TC_ASSERT_EQ("posix_spawn_file_actions_destroy", ret_chk, OK); TC_SUCCESS_RESULT(); }
/** * @fn :tc_pthread_pthread_create_exit_join * @brief :creates a new thread with a specified attributes and \ * terminates execution of a thread started with pthread_create. * @Scenario :creates a new thread with a specified attributes and \ * terminates execution of a thread started with pthread_create. * API's covered :pthread_create, pthread_exit, pthread_join * Preconditions :none * Postconditions :none * @return :void */ static void tc_pthread_pthread_create_exit_join(void) { int ret_chk; pthread_t pthread; void *p_value = 0; isemaphore = ERROR; ret_chk = pthread_create(&pthread, NULL, task_exit, NULL); TC_ASSERT_EQ("pthread create", ret_chk, OK); /* To make sure thread is created before we join it */ while (isemaphore == INTHREAD) { sleep(SEC_1); } ret_chk = pthread_join(pthread, &p_value); TC_ASSERT_EQ("pthread_join", ret_chk, OK); TC_ASSERT_EQ("pthread_join", p_value, RETURN_PTHREAD_JOIN); TC_SUCCESS_RESULT(); }
static void tc_pthread_pthread_equal(void) { int ret_chk; pthread_t first_th; pthread_t second_th; bool check_same; ret_chk = pthread_create(&first_th, NULL, do_nothing_thread, NULL); TC_ASSERT_EQ("pthread_create", ret_chk, OK); ret_chk = pthread_create(&second_th, NULL, do_nothing_thread, NULL); TC_ASSERT_EQ("pthread_create", ret_chk, OK); pthread_join(first_th, NULL); pthread_join(second_th, NULL); check_same = pthread_equal(first_th, second_th); TC_ASSERT_EQ("pthread_equal", check_same, false); TC_SUCCESS_RESULT(); }
/** * @testcase :itc_net_inet_ntop_n * @brief :function converts the network address structure src * in the af address family into a character string* * @scenario :passing invalid args to inet_ntop * @apicovered :inet_ntop() * @precondition :None * @postcondition :None */ static void itc_net_inet_ntop_n(void) { struct in_addr in_addr; char dst[INET_ADDRSTRLEN]; const char *ret; in_addr.s_addr = 0x17071994; #ifdef CONFIG_NET_IPv4 ret = inet_ntop(AF_INET, &in_addr, dst, 7); TC_ASSERT_EQ("inet_ntop", ret, NULL); #endif #ifdef CONFIG_NET_IPv6 ret = inet_ntop(AF_INET6, &in_addr, dst, 7); TC_ASSERT_EQ("inet_ntop", ret, NULL); #endif ret = inet_ntop(33, &in_addr, dst, INET_ADDRSTRLEN); TC_ASSERT_EQ("inet_ntop", ret, NULL); TC_SUCCESS_RESULT(); }
/** * @fn :tc_pthread_pthread_cancel_setcancelstate * @brief :set cancelability state and type and sends a cancellation request to a thread * @Scenario :The pthread_setcancelstate() sets the cancelability state of the calling * thread to the value given in state. The pthread_cancel() function sends a cancellation request to the thread thread. * Whether and when the target thread reacts to the cancellation request depends * on two attributes that are under the control of that thread: * its cancelability state and type * API's covered :pthread_setcancelstate, pthread_cancel * Preconditions :none * Postconditions :none * @return :void */ static void tc_pthread_pthread_cancel_setcancelstate(void) { int ret_chk; g_bpthreadcallback = false; ret_chk = pthread_create(&g_thread1, NULL, cancel_state_func, NULL); TC_ASSERT_EQ_CLEANUP("pthread_create", ret_chk, OK, pthread_detach(g_thread1)); sleep(SEC_1); /* this cancel request goes to pending if cancel is disabled */ ret_chk = pthread_cancel(g_thread1); TC_ASSERT_EQ_CLEANUP("pthread_cancel", ret_chk, OK, pthread_detach(g_thread1)); sleep(SEC_3); TC_ASSERT("pthread_cancel", g_bpthreadcallback); ret_chk = pthread_detach(g_thread1); TC_ASSERT_EQ("pthread_detach", ret_chk, OK); TC_SUCCESS_RESULT(); }
/** * @testcase itc_systemio_iotbus_uart_set_mode_p * @brief sets byte size, parity bit and stop bits * @scenario sets byte size, parity bit and stop bits * @apicovered iotbus_uart_set_mode * @precondition initializes uart_context * @postcondition closes uart_context */ void itc_systemio_iotbus_uart_set_mode_p(void) { int i_bytesize = 8; int i_stop_bits = 1; int ret = IOTBUS_ERROR_NONE; int mode[] = { IOTBUS_UART_PARITY_NONE, IOTBUS_UART_PARITY_EVEN, IOTBUS_UART_PARITY_ODD }; int i_modes = sizeof(mode) / sizeof(int); int index = 0; iotbus_uart_context_h h_uart = iotbus_uart_init(DEVPATH); TC_ASSERT_NEQ("iotbus_uart_init", h_uart, NULL); for (index = 0; index < i_modes; index++) { ret = iotbus_uart_set_mode(h_uart, i_bytesize, mode[index], i_stop_bits); TC_ASSERT_EQ_CLEANUP("iotbus_uart_set_mode", ret, IOTBUS_ERROR_NONE, iotbus_uart_stop(h_uart)); } ret = iotbus_uart_stop(h_uart); TC_ASSERT_EQ("iotbus_uart_stop", ret, IOTBUS_ERROR_NONE); TC_SUCCESS_RESULT(); }
int tc_libcxx_thread_thread_lock_unique_cons_mutex_adopt_lock(void) { { typedef std::mutex M; M m; m.lock(); std::unique_lock<M> lk(m, std::adopt_lock); TC_ASSERT_EXPR(lk.mutex() == std::addressof(m)); TC_ASSERT_EXPR(lk.owns_lock() == true); } { typedef nasty_mutex M; M m; m.lock(); std::unique_lock<M> lk(m, std::adopt_lock); TC_ASSERT_EXPR(lk.mutex() == std::addressof(m)); TC_ASSERT_EXPR(lk.owns_lock() == true); } TC_SUCCESS_RESULT(); return 0; }
/** * @fn : tc_libc_spawn_posix_spawn_file_actions_dump * @brief : Dump the file action whose address is passed * @scenario : Dump the file action whose address is passed * @API's covered : posix_spawn_file_actions_init, posix_spawn_file_actions_addopen, posix_spawn_file_actions_dump, posix_spawn_file_actions_destroy * @Preconditions : posix_spawn_file_actions_init, posix_spawn_file_actions_addopen * @Postconditions : posix_spawn_file_actions_destroy * @Return : void */ static void tc_libc_spawn_posix_spawn_file_actions_dump(void) { const char szfilepath[] = "./testdata.txt"; posix_spawn_file_actions_t st_fileactions; int ret_chk = ERROR; ret_chk = posix_spawn_file_actions_init(&st_fileactions); TC_ASSERT_EQ("posix_spawn_file_actions_init", ret_chk, OK); ret_chk = posix_spawn_file_actions_addopen(&st_fileactions, 1, szfilepath, O_WRONLY, 0644); TC_ASSERT_EQ("posix_spawn_file_actions_addopen", ret_chk, OK); /* posix_spawn_file_actions_dump returns (void) */ posix_spawn_file_actions_dump(&st_fileactions); ret_chk = posix_spawn_file_actions_destroy(&st_fileactions); TC_ASSERT_EQ("posix_spawn_file_actions_destroy", ret_chk, OK); TC_SUCCESS_RESULT(); }
static void tc_pthread_pthread_sem_take_give(void) { int ret_chk; int get_value; sem_t sem; sem_init(&sem, 0, VAL_THREE); ret_chk = pthread_sem_take(&sem, false); TC_ASSERT_EQ("pthread_sem_take", ret_chk, OK); sem_getvalue(&sem, &get_value); TC_ASSERT_EQ("sem_getvalue", get_value, VAL_TWO); ret_chk = pthread_sem_give(&sem); TC_ASSERT_EQ("pthread_sem_give", ret_chk, OK); sem_getvalue(&sem, &get_value); TC_ASSERT_EQ("sem_getvalue", get_value, VAL_THREE); TC_SUCCESS_RESULT(); }
/** * @testcase itc_wifimanager_average_stoping_ap * @brief to check average time taken while deinit wifi * @scenario to check average time taken while deinit wifi * @apicovered wifi_manager_init, wifi_manager_set_mode, wifi_manager_connect_ap, wifi_manager_disconnect_ap, wifi_manager_deinit * @precondition none * @postcondition none */ static void itc_wifimanager_average_stoping_ap(void) { int i = 0; double average = 0.0f; struct timeval start_t; struct timeval end_t; wifi_manager_result_e ret = WIFI_MANAGER_FAIL; wifi_manager_ap_config_s config; config.ssid_length = strlen(TEST_SSID); config.passphrase_length = strlen(TEST_PASSWORD); strncpy(config.ssid, TEST_SSID, config.ssid_length + 1); strncpy(config.passphrase, TEST_PASSWORD, config.passphrase_length + 1); config.ap_auth_type = (wifi_manager_ap_auth_type_e)TEST_AUTH_TYPE; config.ap_crypto_type = (wifi_manager_ap_crypto_type_e)TEST_CRYPTO_TYPE; printf("AP config: %s(%d), %s(%d), %d %d\n", config.ssid, config.ssid_length, config.passphrase, \ config.passphrase_length, config.ap_auth_type, config.ap_crypto_type); for (i = 1; i <= LOOP_SIZE; i++) { ret = wifi_manager_init(&wifi_callbacks); TC_ASSERT_EQ("wifi_manager_init", ret, WIFI_MANAGER_SUCCESS); ret = wifi_manager_connect_ap(&config); TC_ASSERT_EQ_CLEANUP("wifi_manager_connect_ap", ret, WIFI_MANAGER_SUCCESS, wifi_manager_deinit()); WIFITEST_WAIT; ret = wifi_manager_disconnect_ap(); TC_ASSERT_EQ_CLEANUP("wifi_manager_disconnect_ap", ret, WIFI_MANAGER_SUCCESS, wifi_manager_deinit()); WIFITEST_WAIT; gettimeofday(&start_t, NULL); ret = wifi_manager_deinit(); TC_ASSERT_EQ("wifi_manager_deinit", ret, WIFI_MANAGER_SUCCESS); gettimeofday(&end_t, NULL); average += diff_time(&start_t, &end_t); } printf("\n[Average wifi deinitialization time: %.2f ms]\n", average / (LOOP_SIZE * 1000)); TC_SUCCESS_RESULT(); }
int tc_libcxx_algorithms_alg_min_max_minmax_init_list_comp(void) { TC_ASSERT_EXPR((std::minmax({1, 2, 3}, std::greater<int>()) == std::pair<int, int>(3, 1))); TC_ASSERT_EXPR((std::minmax({1, 3, 2}, std::greater<int>()) == std::pair<int, int>(3, 1))); TC_ASSERT_EXPR((std::minmax({2, 1, 3}, std::greater<int>()) == std::pair<int, int>(3, 1))); TC_ASSERT_EXPR((std::minmax({2, 3, 1}, std::greater<int>()) == std::pair<int, int>(3, 1))); TC_ASSERT_EXPR((std::minmax({3, 1, 2}, std::greater<int>()) == std::pair<int, int>(3, 1))); TC_ASSERT_EXPR((std::minmax({3, 2, 1}, std::greater<int>()) == std::pair<int, int>(3, 1))); TC_ASSERT_EXPR((std::minmax({1, 2, 3}, all_equal ) == std::pair<int, int>(1, 3))); binary_counting_predicate<std::greater<int>, int, int> pred ((std::greater<int>())); TC_ASSERT_EXPR((std::minmax({1, 2, 2, 3, 3, 3, 5, 5, 5, 5, 5, 3}, std::ref(pred)) == std::pair<int, int>(5, 1))); TC_ASSERT_EXPR(pred.count() <= 18); // size == 12 TC_ASSERT_FUNC((test_all_equal({0}))); TC_ASSERT_FUNC((test_all_equal({0,1}))); TC_ASSERT_FUNC((test_all_equal({0,1,2}))); TC_ASSERT_FUNC((test_all_equal({0,1,2,3}))); TC_ASSERT_FUNC((test_all_equal({0,1,2,3,4}))); TC_ASSERT_FUNC((test_all_equal({0,1,2,3,4,5}))); TC_ASSERT_FUNC((test_all_equal({0,1,2,3,4,5,6}))); TC_ASSERT_FUNC((test_all_equal({0,1,2,3,4,5,6,7}))); TC_ASSERT_FUNC((test_all_equal({0,1,2,3,4,5,6,7,8}))); TC_ASSERT_FUNC((test_all_equal({0,1,2,3,4,5,6,7,8,9}))); TC_ASSERT_FUNC((test_all_equal({0,1,2,3,4,5,6,7,8,9,10}))); TC_ASSERT_FUNC((test_all_equal({0,1,2,3,4,5,6,7,8,9,10,11}))); #if TEST_STD_VER >= 14 { static_assert((std::minmax({1, 2, 3}, std::greater<int>()) == std::pair<int, int>(3, 1)), ""); static_assert((std::minmax({1, 3, 2}, std::greater<int>()) == std::pair<int, int>(3, 1)), ""); static_assert((std::minmax({2, 1, 3}, std::greater<int>()) == std::pair<int, int>(3, 1)), ""); static_assert((std::minmax({2, 3, 1}, std::greater<int>()) == std::pair<int, int>(3, 1)), ""); static_assert((std::minmax({3, 1, 2}, std::greater<int>()) == std::pair<int, int>(3, 1)), ""); static_assert((std::minmax({3, 2, 1}, std::greater<int>()) == std::pair<int, int>(3, 1)), ""); } #endif TC_SUCCESS_RESULT(); return 0; }
int tc_libcxx_strings_string_assign_string_size_size(void) { { typedef std::string S; TC_ASSERT_FUNC((test(S(), S(), 0, 0, S()))); TC_ASSERT_FUNC((test(S(), S(), 1, 0, S()))); TC_ASSERT_FUNC((test(S(), S("12345"), 0, 3, S("123")))); TC_ASSERT_FUNC((test(S(), S("12345"), 1, 4, S("2345")))); TC_ASSERT_FUNC((test(S(), S("12345"), 3, 15, S("45")))); TC_ASSERT_FUNC((test(S(), S("12345"), 5, 15, S("")))); TC_ASSERT_FUNC((test(S(), S("12345"), 6, 15, S("not happening")))); TC_ASSERT_FUNC((test(S(), S("12345678901234567890"), 0, 0, S()))); TC_ASSERT_FUNC((test(S(), S("12345678901234567890"), 1, 1, S("2")))); TC_ASSERT_FUNC((test(S(), S("12345678901234567890"), 2, 3, S("345")))); TC_ASSERT_FUNC((test(S(), S("12345678901234567890"), 12, 13, S("34567890")))); TC_ASSERT_FUNC((test(S(), S("12345678901234567890"), 21, 13, S("not happening")))); TC_ASSERT_FUNC((test(S("12345"), S(), 0, 0, S()))); TC_ASSERT_FUNC((test(S("12345"), S("12345"), 2, 2, S("34")))); TC_ASSERT_FUNC((test(S("12345"), S("1234567890"), 0, 100, S("1234567890")))); TC_ASSERT_FUNC((test(S("12345678901234567890"), S(), 0, 0, S()))); TC_ASSERT_FUNC((test(S("12345678901234567890"), S("12345"), 1, 3, S("234")))); test(S("12345678901234567890"), S("12345678901234567890"), 5, 10, S("6789012345")); } { typedef std::string S; TC_ASSERT_FUNC((test_npos(S(), S(), 0, S()))); TC_ASSERT_FUNC((test_npos(S(), S(), 1, S()))); TC_ASSERT_FUNC((test_npos(S(), S("12345"), 0, S("12345")))); TC_ASSERT_FUNC((test_npos(S(), S("12345"), 1, S("2345")))); TC_ASSERT_FUNC((test_npos(S(), S("12345"), 3, S("45")))); TC_ASSERT_FUNC((test_npos(S(), S("12345"), 5, S("")))); TC_ASSERT_FUNC((test_npos(S(), S("12345"), 6, S("not happening")))); } TC_SUCCESS_RESULT(); return 0; }
void itc_mqtt_publish_p(void) { int res; g_mqtt_client_handle = mqtt_init_client(&g_mqtt_client_config); TC_ASSERT_NEQ("mqtt_init_client", g_mqtt_client_handle, NULL); res = mqtt_connect(g_mqtt_client_handle, CONFIG_ITC_MQTT_BROKER_ADDR, CONFIG_ITC_MQTT_BROKER_PORT, 0); TC_ASSERT_EQ_CLEANUP("mqtt_connect", res, 0, mqtt_deinit_client(g_mqtt_client_handle)); ITC_MQTT_WAIT_SIGNAL; res = mqtt_publish(g_mqtt_client_handle, ITC_MQTT_TOPIC, g_mqtt_msg, sizeof(g_mqtt_msg), 0, 0); TC_ASSERT_EQ_CLEANUP("mqtt_publish", res, 0, mqtt_disconnect(g_mqtt_client_handle); mqtt_deinit_client(g_mqtt_client_handle)); ITC_MQTT_WAIT_SIGNAL; res = mqtt_disconnect(g_mqtt_client_handle); TC_ASSERT_EQ_CLEANUP("mqtt_disconnect", res, 0, mqtt_deinit_client(g_mqtt_client_handle)); ITC_MQTT_WAIT_SIGNAL; res = mqtt_deinit_client(g_mqtt_client_handle); TC_ASSERT_EQ("mqtt_deinit_client", res, 0); TC_SUCCESS_RESULT(); }
/** * @fn :tc_driver_adc_read * @brief :Test the adc driver read * @scenario :Test the adc driver read * API's covered :read, ioctl * Preconditions :none * Postconditions :none * @return :void */ static void tc_driver_adc_read(void) { int fd = 0; int ret = 0; char buf[5]; int i; fd = open("/dev/adc0", O_RDONLY); TC_ASSERT_GT("adc_open", fd, 0); ret = ioctl(fd, ANIOC_TRIGGER, 0); TC_ASSERT_GEQ_CLEANUP("adc_ioctl", ret, 0, close(fd)); for (i = 0; i < 6; i++) { ret = read(fd, buf, i); TC_ASSERT_GEQ_CLEANUP("adc_read", ret, 0, close(fd)); } close(fd); TC_SUCCESS_RESULT(); }
int tc_libcxx_strings_string_op___string_pointer(void) { typedef std::string S; TC_ASSERT_FUNC((test(S(""), "", false))); TC_ASSERT_FUNC((test(S(""), "abcde", true))); TC_ASSERT_FUNC((test(S(""), "abcdefghij", true))); TC_ASSERT_FUNC((test(S(""), "abcdefghijklmnopqrst", true))); TC_ASSERT_FUNC((test(S("abcde"), "", true))); TC_ASSERT_FUNC((test(S("abcde"), "abcde", false))); TC_ASSERT_FUNC((test(S("abcde"), "abcdefghij", true))); TC_ASSERT_FUNC((test(S("abcde"), "abcdefghijklmnopqrst", true))); TC_ASSERT_FUNC((test(S("abcdefghij"), "", true))); TC_ASSERT_FUNC((test(S("abcdefghij"), "abcde", true))); TC_ASSERT_FUNC((test(S("abcdefghij"), "abcdefghij", false))); TC_ASSERT_FUNC((test(S("abcdefghij"), "abcdefghijklmnopqrst", true))); TC_ASSERT_FUNC((test(S("abcdefghijklmnopqrst"), "", true))); TC_ASSERT_FUNC((test(S("abcdefghijklmnopqrst"), "abcde", true))); TC_ASSERT_FUNC((test(S("abcdefghijklmnopqrst"), "abcdefghij", true))); TC_ASSERT_FUNC((test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", false))); TC_SUCCESS_RESULT(); return 0; }
int tc_libcxx_containers_multimap_size(void) { { typedef std::multimap<int, double> M; M m; TC_ASSERT_EXPR(m.size() == 0); m.insert(M::value_type(2, 1.5)); TC_ASSERT_EXPR(m.size() == 1); m.insert(M::value_type(1, 1.5)); TC_ASSERT_EXPR(m.size() == 2); m.insert(M::value_type(3, 1.5)); TC_ASSERT_EXPR(m.size() == 3); m.erase(m.begin()); TC_ASSERT_EXPR(m.size() == 2); m.erase(m.begin()); TC_ASSERT_EXPR(m.size() == 1); m.erase(m.begin()); TC_ASSERT_EXPR(m.size() == 0); } TC_SUCCESS_RESULT(); return 0; }
static void itc_wifimanager_get_connected_config_p(void) { wifi_manager_result_e nRet = WIFI_MANAGER_FAIL; wifi_manager_ap_config_s apconfig; nRet = wifi_manager_get_connected_config(&apconfig); if (nRet == WIFI_MANAGER_SUCCESS) { printf("====================================\n"); printf("SSID: %s\n", apconfig.ssid); printf("SECURITY TYPE: %d\n", apconfig.ap_auth_type); printf("CYPTO TYPE: %d\n", apconfig.ap_crypto_type); printf("====================================\n"); } if (((strncmp(apconfig.ssid, TEST_SSID, strnlen(TEST_SSID)) != 0)) || (apconfig.ap_auth_type != TEST_AUTH_TYPE) || (apconfig.ap_crypto_type != TEST_CRYPTO_TYPE)) { printf("\nConfig Mismatch nRet = %d \n", nRet); return; } TC_ASSERT_EQ("wifi_manager_get_connected_config", nRet, WIFI_MANAGER_SUCCESS); TC_SUCCESS_RESULT(); }
/** * @fn :tc_pthread_pthread_cond_signal_wait * @brief :The pthread_cond_signal function wakes up at least one thread that is currently waiting on the \ * condition variable specified by cond. If no threads are currently blocked on the condition variable, this call has no effect. * @Scenario :pthread_cond_signal() Signal Condition to One Waiting Thread. * API's covered :pthread_cond_signal, pthread_cond_wait * Preconditions :none * Postconditions :none * @return :void */ static void tc_pthread_pthread_cond_signal_wait(void) { pthread_t pthread_waiter; int ret_chk = ERROR; g_cond_sig_val = VAL_ONE; ret_chk = pthread_mutex_init(&g_mutex, NULL); TC_ASSERT_EQ("pthread_mutex_init", ret_chk, OK); ret_chk = pthread_cond_init(&g_cond, NULL); TC_ASSERT_EQ("pthread_cond_init", ret_chk, OK); ret_chk = pthread_mutex_lock(&g_mutex); TC_ASSERT_EQ("pthread_mutex_lock", ret_chk, OK); ret_chk = pthread_create(&pthread_waiter, NULL, thread_cond_signal, NULL); TC_ASSERT_EQ("pthread_create", ret_chk, OK); TC_ASSERT_EQ("pthread_mutex_lock", g_cond_sig_val, VAL_ONE); ret_chk = pthread_mutex_unlock(&g_mutex); TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK); sleep(SEC_1); TC_ASSERT_EQ("pthread_cond_signal_wait", g_cond_sig_val, VAL_TWO); ret_chk = pthread_cond_signal(&g_cond); TC_ASSERT_EQ("pthread_cond_signal", ret_chk, OK); sleep(SEC_1); TC_ASSERT_EQ("pthread_cond_signal", g_cond_sig_val, VAL_THREE); pthread_cancel(pthread_waiter); pthread_join(pthread_waiter, NULL); TC_SUCCESS_RESULT(); }
static void tc_pthread_pthread_detach(void) { int ret_chk; pthread_t new_th; /* Create the thread */ ret_chk = pthread_create(&new_th, NULL, do_nothing_thread, NULL); TC_ASSERT_EQ("pthread_create", ret_chk, OK); /* Wait 'till the thread returns. * The thread could have ended by the time we try to join, so * don't worry about it, just so long as other errors don't * occur. The point is to make sure the thread has ended execution. */ ret_chk = pthread_join(new_th, NULL); TC_ASSERT_NEQ("pthread_join", ret_chk, EDEADLK); /* Detach the non-existant thread. */ ret_chk = pthread_detach(new_th); TC_ASSERT_NEQ("pthread_detach", ret_chk, OK); TC_SUCCESS_RESULT(); }
int tc_libcxx_containers_unord_map_modifiers_erase_const_iter(void) { { typedef std::unordered_map<int, std::string> C; typedef std::pair<int, std::string> P; P a[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; C c(a, a + sizeof(a)/sizeof(a[0])); C::const_iterator i = c.find(2); c.erase(i); TC_ASSERT_EXPR(c.size() == 3); TC_ASSERT_EXPR(c.at(1) == "one"); TC_ASSERT_EXPR(c.at(3) == "three"); TC_ASSERT_EXPR(c.at(4) == "four"); } #if TEST_STD_VER >= 14 { // This is LWG #2059 typedef TemplateConstructor T; typedef std::unordered_map<T, int, Hash> C; typedef C::iterator I; C m; T a{0}; I it = m.find(a); if (it != m.end()) m.erase(it); } #endif TC_SUCCESS_RESULT(); return 0; }
/** * @fn :tc_pthread_pthread_set_getspecific * @brief :thread-specific data management * @Scenario :The pthread_getspecific() function shall return the value currently bound * to the specified key on behalf of the calling thread. * The pthread_setspecific() function shall associate a thread-specific value * with a key obtained via a previous call to pthread_key_create(). * API's covered :pthread_setspecific, pthread_getspecific, pthread_key_create * Preconditions :pthread_key_create * Postconditions :none * @return :void */ static void tc_pthread_pthread_key_create_set_getspecific(void) { int ret_chk; g_bpthreadcallback = false; g_tlskey = 0; /* Cannot create keys more than PTHREAD_KEYS_MAX, Not able to delete key */ ret_chk = pthread_key_create(&g_tlskey, NULL); TC_ASSERT_EQ("pthread_key_create", ret_chk, OK); sleep(SEC_2); ret_chk = pthread_create(&g_thread1, NULL, func_set_get_callback, NULL); TC_ASSERT_EQ_CLEANUP("pthread_create", ret_chk, OK, pthread_detach(g_thread1)); ret_chk = pthread_join(g_thread1, NULL); TC_ASSERT_EQ_CLEANUP("pthread_join", ret_chk, OK, pthread_detach(g_thread1)); TC_ASSERT_EQ("pthread_join", g_bpthreadcallback, true); TC_SUCCESS_RESULT(); }
int tc_libcxx_containers_vector_cons_dtor_noexcept(void) { { typedef std::vector<MoveOnly> C; static_assert(std::is_nothrow_destructible<C>::value, ""); } { typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C; static_assert(std::is_nothrow_destructible<C>::value, ""); } { typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C; static_assert(std::is_nothrow_destructible<C>::value, ""); } #if defined(_LIBCPP_VERSION) { typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C; static_assert(!std::is_nothrow_destructible<C>::value, ""); } #endif // _LIBCPP_VERSION TC_SUCCESS_RESULT(); return 0; }