/** * @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(); }
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(); }
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(); }
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(); }
static void itc_wifimanager_get_connected_config_n(void) { wifi_manager_result_e nRet = WIFI_MANAGER_FAIL; wifi_manager_ap_config_s apconfig; nRet = unlink("/mnt/wifi_connected.conf"); printf("\nThe return after unlink is =%d \n", nRet); if (nRet != 0) { wifi_manager_deinit(); return; } 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"); } TC_ASSERT_EQ("wifi_manager_get_connected_config", nRet, WIFI_MANAGER_FAIL); TC_SUCCESS_RESULT(); }
/** * @testcase :itc_net_listen_n_after_socket_close * @brief :listen for socket connections and limit the queue of incoming connections * @scenario :create socket, bind, close socket and then listen * @apicovered :listen() * @precondition :open socket, close socket * @postcondition :none */ static void itc_net_listen_n_after_socket_close(void) { struct sockaddr_in sa; int socket_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); TC_ASSERT_GEQ("socket", socket_fd, CONFIG_NFILE_DESCRIPTORS); memset(&sa, 0, sizeof sa); sa.sin_family = AF_INET; sa.sin_port = htons(ADDR_PORT); sa.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)); ret = close(socket_fd); TC_ASSERT_EQ("close", ret, 0); ret = listen(socket_fd, BACK_LOG); TC_ASSERT_NEQ("listen", ret, 0); TC_SUCCESS_RESULT(); }
/** * @testcase itc_systemio_iotbus_uart_write_read_p * @brief write and read data over uart bus * @scenario write and read data over uart bus * @apicovered iotbus_uart_write, iotbus_uart_read * @precondition initializes uart_context * @postcondition closes uart_context */ void itc_systemio_iotbus_uart_write_read_p(void) { int ret = IOTBUS_ERROR_NONE; char sz_input_text[BUF_LEN] = "UART READ/WRITE ITC TESTING!"; char sz_output_text[BUF_LEN]; iotbus_uart_context_h h_uart = iotbus_uart_init(DEVPATH); TC_ASSERT_NEQ("iotbus_uart_init", h_uart, NULL); ret = iotbus_uart_write(h_uart, sz_input_text, sizeof(sz_input_text)); TC_ASSERT_EQ_CLEANUP("iotbus_uart_write", ret < 0, false, iotbus_uart_stop(h_uart)); usleep(MICROSECOND); ret = iotbus_uart_read(h_uart, sz_output_text, sizeof(sz_output_text)); TC_ASSERT_EQ_CLEANUP("iotbus_uart_read", ret < 0, false, iotbus_uart_stop(h_uart)); TC_ASSERT_EQ_CLEANUP("iotbus_uart_read", strcmp(sz_input_text, sz_output_text), 0, iotbus_uart_stop(h_uart)); ret = iotbus_uart_stop(h_uart); TC_ASSERT_EQ("iotbus_uart_stop", ret, IOTBUS_ERROR_NONE); TC_SUCCESS_RESULT(); }
/** * @fn :tc_pthread_pthread_timed_wait * @brief :function shall block on a condition variable. * @Scenario :function is called with mutex locked by the calling thread or undefined behavior results. * API's covered :pthread_create, pthread_join, pthread_mutex_init, pthread_mutex_destroy, pthread_cond_init, pthread_cond_destroy, pthread_cond_timedwait * Preconditions :none * Postconditions :none * @return :void */ static void tc_pthread_pthread_timed_wait(void) { int ret_chk; pthread_t waiter; pthread_attr_t attr; struct sched_param sparam; void *result; int prio_max; /* Initialize the mutex */ g_bpthreadcallback = false; ret_chk = pthread_mutex_init(&g_mutex_timedwait, NULL); TC_ASSERT_EQ("pthread_mutex_init", ret_chk, OK); /* Initialize the condition variable */ ret_chk = pthread_cond_init(&cond, NULL); TC_ASSERT_EQ("pthread_cond_init", ret_chk, OK); /* Start the waiter thread at higher priority */ ret_chk = pthread_attr_init(&attr); TC_ASSERT_EQ("pthread_attr_init", ret_chk, OK); prio_max = sched_get_priority_max(SCHED_FIFO); ret_chk = sched_getparam(getpid(), &sparam); if (ret_chk != OK) { sparam.sched_priority = PTHREAD_DEFAULT_PRIORITY; } sparam.sched_priority = (prio_max + sparam.sched_priority) / 2; ret_chk = pthread_attr_setschedparam(&attr, &sparam); TC_ASSERT_EQ("pthread_attr_setschedparam", ret_chk, OK); ret_chk = pthread_create(&waiter, &attr, thread_waiter, NULL); TC_ASSERT_EQ("pthread_create", ret_chk, OK); TC_ASSERT("pthread_create", g_bpthreadcallback); ret_chk = pthread_join(waiter, &result); TC_ASSERT_EQ("pthread_join", ret_chk, OK); TC_SUCCESS_RESULT(); }
/** * @testcase itc_systemio_iotbus_uart_init_stop_p_multi_handle * @brief initializes and closes uart_context * @scenario initializes and closes uart_context * @apicovered iotbus_uart_init, iotbus_uart_stop * @precondition none * @postcondition none */ static void itc_systemio_iotbus_uart_init_stop_p_multi_handle(void) { int ret = IOTBUS_ERROR_NONE; iotbus_uart_context_h h_uart1 = iotbus_uart_init(DEVPATH); TC_ASSERT_NEQ("iotbus_uart_init1", h_uart1, NULL); iotbus_uart_context_h h_uart2 = iotbus_uart_init(DEVPATH); TC_ASSERT_NEQ_CLEANUP("iotbus_uart_init2", h_uart2, NULL, iotbus_uart_stop(h_uart1)); iotbus_uart_context_h h_uart3 = iotbus_uart_init(DEVPATH); TC_ASSERT_NEQ_CLEANUP("iotbus_uart_init3", h_uart3, NULL, iotbus_uart_stop(h_uart2); iotbus_uart_stop(h_uart1)); ret = iotbus_uart_stop(h_uart3); TC_ASSERT_EQ_CLEANUP("iotbus_uart_stop3", ret, IOTBUS_ERROR_NONE, iotbus_uart_stop(h_uart2); iotbus_uart_stop(h_uart1)); ret = iotbus_uart_stop(h_uart2); TC_ASSERT_EQ_CLEANUP("iotbus_uart_stop2", ret, IOTBUS_ERROR_NONE, iotbus_uart_stop(h_uart1)); ret = iotbus_uart_stop(h_uart1); TC_ASSERT_EQ("iotbus_uart_stop1", ret, IOTBUS_ERROR_NONE); TC_SUCCESS_RESULT(); }
void itc_mqtt_init_deinit_client_n(void) { int res; static mqtt_client_config_t mqtt_client_config = { "", NULL, NULL, 0, 0, 0, 0, on_connect, on_disconnect, on_publish, on_message, on_subscribe, on_unsubscribe }; mqtt_client_t *mqtt_client_handle; mqtt_client_handle = mqtt_init_client(&mqtt_client_config); TC_ASSERT_EQ("mqtt_init_client", mqtt_client_handle, NULL); res = mqtt_deinit_client(mqtt_client_handle); TC_ASSERT_NEQ("mqtt_deinit_client", res, 0); TC_SUCCESS_RESULT(); }
static void utc_taskmanager_start_p(void) { int ret; ret = task_manager_start(tm_sample_handle, TM_RESPONSE_WAIT_INF); TC_ASSERT_EQ("task_manager_start", ret, OK); ret = task_manager_start(tm_sample_handle, TM_RESPONSE_WAIT_INF); TC_ASSERT_EQ("task_manager_start", ret, TM_ALREADY_STARTED_APP); ret = task_manager_start(tm_broadcast_handle1, TM_RESPONSE_WAIT_INF); TC_ASSERT_EQ("task_manager_start", ret, OK); ret = task_manager_start(tm_broadcast_handle2, TM_RESPONSE_WAIT_INF); TC_ASSERT_EQ("task_manager_start", ret, OK); ret = task_manager_start(tm_broadcast_handle3, TM_RESPONSE_WAIT_INF); TC_ASSERT_EQ("task_manager_start", ret, OK); ret = task_manager_start(tm_not_builtin_handle, TM_RESPONSE_WAIT_INF); TC_ASSERT_EQ("task_manager_start", ret, OK); TC_SUCCESS_RESULT(); }
/** * @fn :tc_pthread_pthread_cond_broadcast * @brief :broadcast or signal a condition * @Scenario :function shall unblock all threads currently blocked on the specified condition variable cond. * API's covered :pthread_cond_broadcast ,pthread_cond_init , pthread_cond_destroy , pthread_cond_wait * Preconditions :pthread_cond_init * Postconditions :pthread_cond_destroy * @return :void */ static void tc_pthread_pthread_cond_broadcast(void) { int ret_chk; int ipthread_id = 0; pthread_t rgthread[PTHREAD_CNT]; g_barrier_count_in = 0; g_barrier_count_out = 0; g_cnt = 0; 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_CLEANUP("pthread_cond_init", ret_chk, OK, pthread_mutex_destroy(&g_mutex)); for (ipthread_id = 0; ipthread_id < PTHREAD_CNT; ipthread_id++) { ret_chk = pthread_create(&rgthread[ipthread_id], NULL, pthread_wait_callback, NULL); TC_ASSERT_EQ_CLEANUP("pthread_create", ret_chk, OK, goto cleanup_cond); } /* To check all thread block conditional lock */ while (g_barrier_count_in < PTHREAD_CNT) { usleep(SEC_1); } /* To make sure all waiter are currently block on pthread_cond_wait */ ret_chk = pthread_mutex_lock(&g_mutex); TC_ASSERT_EQ_CLEANUP("pthread_mutex_lock", ret_chk, OK, goto cleanup_mutex); ret_chk = pthread_mutex_unlock(&g_mutex); TC_ASSERT_EQ_CLEANUP("pthread_mutex_unlock", ret_chk, OK, goto cleanup_mutex); ret_chk = pthread_cond_broadcast(&g_cond); TC_ASSERT_EQ_CLEANUP("pthread_cond_broadcast", ret_chk, OK, goto cleanup_cond); sleep(SEC_1); TC_ASSERT_GEQ_CLEANUP("pthread_cond_broadcast", g_barrier_count_out, PTHREAD_CNT, goto cleanup_cond); /* Wait till terminate all thread */ for (ipthread_id = 0; ipthread_id < PTHREAD_CNT; ipthread_id++) { ret_chk = pthread_join(rgthread[ipthread_id], NULL); TC_ASSERT_EQ_CLEANUP("pthread_join", ret_chk, OK, goto cleanup_cond); } ret_chk = pthread_cond_destroy(&g_cond); TC_ASSERT_EQ_CLEANUP("pthread_cond_destroy", ret_chk, OK, pthread_mutex_destroy(&g_mutex)); ret_chk = pthread_mutex_destroy(&g_mutex); TC_ASSERT_EQ("pthread_mutex_destroy", ret_chk, OK); TC_SUCCESS_RESULT(); cleanup_mutex: pthread_cond_broadcast(&g_cond); cleanup_cond: for (ipthread_id = 0; ipthread_id < PTHREAD_CNT; ++ipthread_id) { pthread_cancel(rgthread[ipthread_id]); pthread_join(rgthread[ipthread_id], NULL); } pthread_cond_destroy(&g_cond); pthread_mutex_destroy(&g_mutex); }
static void utc_spi_recv_p(void) { int ret = iotbus_spi_recv(spi, rxbuf, 8); TC_ASSERT_EQ("iotbus_spi_recv", ret, IOTBUS_ERROR_NONE); TC_SUCCESS_RESULT(); }
static void utc_spi_recv_n(void) { int ret = iotbus_spi_recv(spi, NULL, -1); TC_ASSERT_EQ("iotbus_spi_recv", ret, IOTBUS_ERROR_INVALID_PARAMETER); TC_SUCCESS_RESULT(); }
static void utc_spi_open_n(void) { iotbus_spi_context_h m_spi = iotbus_spi_open(bus, NULL); TC_ASSERT_EQ("iotbus_spi_open", m_spi, NULL); TC_SUCCESS_RESULT(); }
static void utc_spi_write_p(void) { int ret = iotbus_spi_write(spi, txbuf, 8); TC_ASSERT_EQ("iotbus_spi_write", ret, IOTBUS_ERROR_NONE); TC_SUCCESS_RESULT(); }
static void utc_spi_close_n(void) { int ret = iotbus_spi_close(NULL); TC_ASSERT_EQ("iotbus_spi_close", ret, IOTBUS_ERROR_INVALID_PARAMETER); TC_SUCCESS_RESULT(); }
/** * @testcase itc_wifimanager_success_ratio_ap * @brief to check success ratio of operations(init, join, leave, deinit) * @scenario check success ratio of operations(init, join, leave, deinit) * @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_success_ratio_ap(void) { float init_cnt = 0.0f; float s_init_cnt = 0.0f; float join_cnt = 0.0f; float s_join_cnt = 0.0f; float leave_cnt = 0.0f; float s_leave_cnt = 0.0f; float deinit_cnt = 0.0f; float s_deinit_cnt = 0.0f; int i = 0; 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 = 0; i < LOOP_SIZE; i++) { init_cnt++; ret = wifi_manager_init(&wifi_callbacks); if (ret == WIFI_MANAGER_SUCCESS) { s_init_cnt++; } else { continue; } join_cnt++; ret = wifi_manager_connect_ap(&config); if (ret == WIFI_MANAGER_SUCCESS) { s_join_cnt++; WIFITEST_WAIT; leave_cnt++; ret = wifi_manager_disconnect_ap(); if (ret == WIFI_MANAGER_SUCCESS) { s_leave_cnt++; WIFITEST_WAIT; } } deinit_cnt++; ret = wifi_manager_deinit(); if (ret == WIFI_MANAGER_SUCCESS) { s_deinit_cnt++; } } printf("\nSuccess Ratio \n"); if (init_cnt > 0) { printf("[Initialization Wifi] Success Ratio = %.2f% \n", (s_init_cnt / init_cnt) * 100); } if (join_cnt > 0) { printf("[Connect Wifi] Success Ratio = %.2f% \n", (s_join_cnt / join_cnt) * 100); } if (leave_cnt > 0) { printf("[Disconnect Wifi] Success Ratio = %.2f% \n", (s_leave_cnt / leave_cnt) * 100); } if (deinit_cnt > 0) { printf("[Deinitization Wifi] Success Ratio = %.2f% \n", (s_deinit_cnt / deinit_cnt) * 100); } TC_ASSERT_EQ("itc_wifimanager_success_ratio_ap", s_init_cnt, init_cnt); TC_ASSERT_EQ("itc_wifimanager_success_ratio_ap", s_join_cnt, join_cnt); TC_ASSERT_EQ("itc_wifimanager_success_ratio_ap", s_leave_cnt, leave_cnt); TC_ASSERT_EQ("itc_wifimanager_success_ratio_ap", s_deinit_cnt, deinit_cnt); TC_SUCCESS_RESULT(); }
/** * @fn :tc_pthread_pthread_mutex_lock_unlock_trylock * @brief :The mutex object referenced by mutex is locked/unlocked by calling * pthread_mutex_lock/pthread_mutex_unlock * @Scenario :The mutex object referenced by mutex is locked/unlocked by calling * pthread_mutex_lock/pthread_mutex_unlock * API's covered :pthread_mutex_lock, pthread_mutex_unlock * Preconditions :pthread_mutex_init * Postconditions :pthread_mutex_destroy * @return :void */ static void tc_pthread_pthread_mutex_lock_unlock_trylock(void) { int ret_chk; pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&g_mutex, NULL); ret_chk = pthread_mutex_lock(&g_mutex); TC_ASSERT_EQ("pthread_mutex_lock", ret_chk, OK); ret_chk = pthread_mutex_trylock(&g_mutex); TC_ASSERT_EQ_CLEANUP("pthread_mutex_trylock", ret_chk, EBUSY, pthread_mutex_unlock(&g_mutex)); ret_chk = pthread_mutex_unlock(&g_mutex); TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK); ret_chk = pthread_mutex_trylock(&g_mutex); TC_ASSERT_EQ("pthread_mutex_trylock", ret_chk, OK); ret_chk = pthread_mutex_unlock(&g_mutex); TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK); pthread_mutex_destroy(&g_mutex); sleep(SEC_2); /* initalize mutex with PTHREAD_MUTEX_RECURSIVE attribute */ pthread_mutex_init(&g_mutex, &attr); ret_chk = pthread_mutex_lock(&g_mutex); TC_ASSERT_EQ("pthread_mutex_lock", ret_chk, OK); ret_chk = pthread_mutex_lock(&g_mutex); TC_ASSERT_EQ("pthread_mutex_lock", ret_chk, OK); ret_chk = pthread_mutex_unlock(&g_mutex); TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK); ret_chk = pthread_mutex_unlock(&g_mutex); TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK); /* mutex_lock mutex_unlock check through multi threads */ g_mutex_cnt = 0; ret_chk = pthread_mutex_init(&g_mutex, NULL); TC_ASSERT_EQ("pthread_mutex_init", ret_chk, OK); ret_chk = pthread_create(&g_thread1, NULL, &thread_mutex, NULL); TC_ASSERT_EQ("pthread_create", ret_chk, OK); ret_chk = pthread_create(&g_thread2, NULL, &thread_mutex, NULL); TC_ASSERT_EQ("pthread_create", ret_chk, OK); pthread_join(g_thread1, NULL); pthread_join(g_thread2, NULL); TC_ASSERT("pthread_mutex_lock_unlock", g_bpthreadcallback); pthread_mutex_destroy(&g_mutex); TC_SUCCESS_RESULT(); }
static void tc_pthread_pthread_mutex_destroy(void) { pthread_mutexattr_t attr; pthread_t pid; int ret_chk; ret_chk = pthread_mutexattr_init(&attr); TC_ASSERT_EQ("pthread_mutexattr_init", ret_chk, OK); ret_chk = pthread_mutex_init(&g_mutex, &attr); TC_ASSERT_EQ("pthread_mutex_init", ret_chk, OK); #ifndef CONFIG_DEBUG /* test NULL case. ASSERT will rise when debug is enabled */ ret_chk = pthread_mutex_destroy(NULL); TC_ASSERT_EQ("pthread_mutex_destroy", ret_chk, EINVAL); #endif /* try pthread_mutex_destroy while mutex is used */ ret_chk = pthread_mutex_lock(&g_mutex); TC_ASSERT_EQ("pthread_mutex_lock", ret_chk, OK); ret_chk = pthread_mutex_destroy(&g_mutex); TC_ASSERT_EQ("pthread_mutex_destroy", ret_chk, EBUSY); ret_chk = pthread_mutex_unlock(&g_mutex); TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK); /* try ptherad_mutex_destroy when dead thread hold mutex */ ret_chk = pthread_create(&pid, NULL, thread_mutex_lock_exit_without_unlock, NULL); TC_ASSERT_EQ("pthread_create", ret_chk, OK); ret_chk = pthread_join(pid, NULL); TC_ASSERT_EQ("pthread_join", ret_chk, OK); ret_chk = pthread_mutex_destroy(&g_mutex); TC_ASSERT_EQ("pthread_mutex_destroy", ret_chk, OK); TC_ASSERT_EQ("pthread_mutex_destroy", g_mutex.pid, -1); /* test revisit case */ ret_chk = pthread_mutex_destroy(&g_mutex); TC_ASSERT_EQ("pthread_mutex_destroy", ret_chk, OK); TC_SUCCESS_RESULT(); }
static void utc_taskmanager_set_stop_cb_p(void) { TC_ASSERT_EQ("task_manager_set_stop_cb", cb_flag, true); TC_SUCCESS_RESULT(); }
static void utc_taskmanager_reply_unicast_p(void) { TC_ASSERT_EQ("task_manager_reply_unicast", cb_flag, true); TC_SUCCESS_RESULT(); }
/** * @testcase itc_systemio_iotbus_uart_set_flow_mode_flush_write_read_p * @brief To check flush/write/read operation with all combination of parity and flow * @scenario uart flush/write/read operation with all combination of parity and flow * @apicovered iotbus_uart_set_flowcontrol, iotbus_uart_set_mode, iotbus_uart_write, iotbus_uart_read, iotbus_uart_flush * @precondition initializes uart_context * @postcondition closes uart_context */ static void itc_systemio_iotbus_uart_set_flow_mode_flush_write_read_p(void) { int i_bytesize = 8; int i_flow_size = 4; int i_stop_bits = 1; int ret = IOTBUS_ERROR_NONE; char sz_input_text[BUF_LEN] = "UART READ/WRITE ITC TESTING!"; char sz_output_text[BUF_LEN]; int mode[] = { IOTBUS_UART_PARITY_NONE, IOTBUS_UART_PARITY_EVEN, IOTBUS_UART_PARITY_ODD }; char *mode_str[3] = { "IOTBUS_UART_PARITY_NONE", "IOTBUS_UART_PARITY_EVEN", "IOTBUS_UART_PARITY_ODD" }; int rtscts[4][2] = { {1, 0}, {0, 1}, {1, 1}, {0, 0} }; int i_modes = sizeof(mode) / sizeof(int); int index = 0; int flow_index = 0; int count_fail_mode = 0; int count_fail_write = 0; int count_fail_read = 0; int count_fail_flush = 0; int count_fail_flowcontrol = 0; iotbus_uart_context_h h_uart = iotbus_uart_init(DEVPATH); TC_ASSERT_NEQ("iotbus_uart_init", h_uart, NULL); for (flow_index = 0; flow_index < i_flow_size; flow_index++) { ret = iotbus_uart_set_flowcontrol(h_uart, rtscts[flow_index][0], rtscts[flow_index][1]); if (ret != IOTBUS_ERROR_NONE) { SYSIO_ITC_PRINT("iotbus_uart_set_flowcontrol failed with xonxoff ::%d, rtscts::%d\n", rtscts[flow_index][0], rtscts[flow_index][1]); count_fail_flowcontrol++; continue; } for (index = 0; index < i_modes; index++) { ret = iotbus_uart_set_mode(h_uart, i_bytesize, mode[index], i_stop_bits); if ((ret != IOTBUS_ERROR_NONE)) { SYSIO_ITC_PRINT("iotbus_uart_set_mode failed with PARITY ::%s, stop_bits::%d, xonxoff::%d, rtscts::%d\n", mode_str[index], i_stop_bits, rtscts[flow_index][0], rtscts[flow_index][1]); count_fail_mode++; continue; } ret = iotbus_uart_flush(h_uart); if ((ret != IOTBUS_ERROR_NONE)) { SYSIO_ITC_PRINT("iotbus_uart_flush failed with PARITY ::%s, stop_bits::%d, xonxoff::%d, rtscts::%d\n", mode_str[index], i_stop_bits, rtscts[flow_index][0], rtscts[flow_index][1]); count_fail_flush++; continue; }; ret = iotbus_uart_write(h_uart, sz_input_text, sizeof(sz_input_text)); if ((ret < 0)) { SYSIO_ITC_PRINT("iotbus_uart_write failed with PARITY ::%s, stop_bits::%d, xonxoff::%d, rtscts::%d\n", mode_str[index], i_stop_bits, rtscts[flow_index][0], rtscts[flow_index][1]); count_fail_write++; continue; } usleep(MICROSECOND); ret = iotbus_uart_read(h_uart, sz_output_text, sizeof(sz_output_text)); if ((ret < 0) || (strcmp(sz_input_text, sz_output_text) != 0)) { SYSIO_ITC_PRINT("iotbus_uart_read failed with PARITY ::%s, stop_bits::%d, xonxoff::%d, rtscts::%d\n", mode_str[index], i_stop_bits, rtscts[flow_index][0], rtscts[flow_index][1]); count_fail_read++; } } } TC_ASSERT_EQ_CLEANUP("iotbus_uart_set_flowcontrol failed count", count_fail_flowcontrol, 0, iotbus_uart_stop(h_uart)); TC_ASSERT_EQ_CLEANUP("iotbus_uart_set_mode failed count", count_fail_mode, 0, iotbus_uart_stop(h_uart)); TC_ASSERT_EQ_CLEANUP("iotbus_uart_flush failed count", count_fail_flush, 0, iotbus_uart_stop(h_uart)); TC_ASSERT_EQ_CLEANUP("iotbus_uart_write failed count", count_fail_write, 0, iotbus_uart_stop(h_uart)); TC_ASSERT_EQ_CLEANUP("iotbus_uart_read failed count", count_fail_read, 0, iotbus_uart_stop(h_uart)); ret = iotbus_uart_stop(h_uart); TC_ASSERT_EQ("iotbus_uart_stop", ret, IOTBUS_ERROR_NONE); TC_SUCCESS_RESULT(); }