/** * @testcase itc_systemio_iotbus_uart_write_read_flush_p * @brief write, read, flush data over uart bus * @scenario write, read, flush data over uart bus * @apicovered iotbus_uart_write, iotbus_uart_read, iotbus_uart_flush * @precondition initializes uart_context * @postcondition closes uart_context */ static void itc_systemio_iotbus_uart_write_read_flush_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_flush(h_uart); TC_ASSERT_EQ_CLEANUP("iotbus_uart_flush", 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(); }
/** * @testcase itc_systemio_iotbus_uart_set_mode_flush_write_read_p * @brief To check flush/write/read operation with different parity * @scenario uart flush/write/read operation with different parity * @apicovered 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_mode_flush_write_read_p(void) { int i_bytesize = 8; 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 i_modes = sizeof(mode) / sizeof(int); int index = 0; int count_fail_mode = 0; int count_fail_write = 0; int count_fail_read = 0; int count_fail_flush = 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); if ((ret != IOTBUS_ERROR_NONE)) { SYSIO_ITC_PRINT("iotbus_uart_set_mode failed with PARITY ::%s, stop_bits::%d\n", mode_str[index], i_stop_bits); 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\n", mode_str[index], i_stop_bits); 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\n", mode_str[index], i_stop_bits); 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\n", mode_str[index], i_stop_bits); count_fail_read++; } } 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(); }
/** * @testcase itc_systemio_iotbus_uart_set_flow_write_flush_read_p * @brief flush, write, and read data over uart bus with set flow * @scenario flush, write, and read data over uart bus with set flow * @apicovered iotbus_uart_write, iotbus_uart_read, iotbus_uart_set_flowcontrol, iotbus_uart_flush * @precondition initializes uart_context * @postcondition closes uart_context */ static void itc_systemio_iotbus_uart_set_flow_flush_write_read_p(void) { int i_size = 4; int ret = IOTBUS_ERROR_NONE; char sz_input_text[BUF_LEN] = "UART READ/WRITE ITC TESTING!"; char sz_output_text[BUF_LEN]; int rtscts[4][2] = { {1, 0}, {0, 1}, {1, 1}, {0, 0} }; int index = 0; int count_fail_flowcontrol = 0; int count_fail_write = 0; int count_fail_read = 0; int count_fail_flush = 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_size; index++) { ret = iotbus_uart_set_flowcontrol(h_uart, rtscts[index][0], rtscts[index][1]); if (ret != IOTBUS_ERROR_NONE) { SYSIO_ITC_PRINT("iotbus_uart_set_flowcontrol failed with xonxoff ::%d, rtscts::%d\n", rtscts[index][0], rtscts[index][1]); count_fail_flowcontrol++; continue; } ret = iotbus_uart_flush(h_uart); if (ret != IOTBUS_ERROR_NONE) { SYSIO_ITC_PRINT("iotbus_uart_flush failed with xonxoff ::%d, rtscts::%d\n", rtscts[index][0], rtscts[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 xonxoff ::%d, rtscts::%d\n", rtscts[index][0], rtscts[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 xonxoff ::%d, rtscts::%d\n", rtscts[index][0], rtscts[index][1]); count_fail_read++; } } 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)); TC_ASSERT_EQ_CLEANUP("iotbus_uart_set_flowcontrol failed count", count_fail_flowcontrol, 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(); }
/** * @testcase itc_systemio_iotbus_uart_set_mode_p_all * @brief sets byte size, parity bit and stop bits (all combinations) * @scenario sets byte size, parity bit and stop bits (all combinations) * @apicovered iotbus_uart_set_mode * @precondition initializes uart_context * @postcondition closes uart_context */ static void itc_systemio_iotbus_uart_set_mode_p_all(void) { int i_bytesize = 0; int i_max_bytesize = 10; int i_stop_bits = 0; int i_max_stop_bits = 4; int ret = IOTBUS_ERROR_NONE; int mode[] = { IOTBUS_UART_PARITY_NONE, IOTBUS_UART_PARITY_EVEN, IOTBUS_UART_PARITY_ODD }; char mode_str[3][BUF_LEN] = { "IOTBUS_UART_PARITY_NONE", "IOTBUS_UART_PARITY_EVEN", "IOTBUS_UART_PARITY_ODD" }; int i_modes = sizeof(mode) / sizeof(int); int index = 0; int count_bytesize_fail = 0; int count_stopbit_fail = 0; int count_fail = 0; iotbus_uart_context_h h_uart = iotbus_uart_init(DEVPATH); TC_ASSERT_NEQ("iotbus_uart_init", h_uart, NULL); for (i_bytesize = 0; i_bytesize < i_max_bytesize; ++i_bytesize) { for (i_stop_bits = 0; i_stop_bits < i_max_stop_bits; ++i_stop_bits) { for (index = 0; index < i_modes; index++) { ret = iotbus_uart_set_mode(h_uart, i_bytesize, mode[index], i_stop_bits); if (i_stop_bits < 1 || i_stop_bits > 2) { //checking for invalid parameters (stopbits) if (ret != IOTBUS_ERROR_INVALID_PARAMETER) { SYSIO_ITC_PRINT("iotbus_uart_set_mode failed for stopbits ::%d\n", i_stop_bits); count_stopbit_fail++; } } else if (i_bytesize < 5 || i_bytesize > 8) { //checking with invalid parameters (bytessize) if (ret != IOTBUS_ERROR_INVALID_PARAMETER) { SYSIO_ITC_PRINT("iotbus_uart_set_mode failed for bytesize ::%d\n", i_bytesize); count_bytesize_fail++; } } else { //checking with valid parameters if (ret != IOTBUS_ERROR_NONE) { SYSIO_ITC_PRINT("iotbus_uart_set_mode failed UART_PARITY::%s, bytesize::%d, stopbits::%d \n", mode_str[index], i_bytesize, i_stop_bits); count_fail++; } } } } } TC_ASSERT_EQ_CLEANUP("iotbus_uart_set_mode fail_count with bytesize", count_bytesize_fail, 0, iotbus_uart_stop(h_uart)); TC_ASSERT_EQ_CLEANUP("iotbus_uart_set_mode fail_count with stopbit", count_stopbit_fail, 0, iotbus_uart_stop(h_uart)); TC_ASSERT_EQ_CLEANUP("iotbus_uart_set_mode fail_count", count_fail, 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(); }
/** * @testcase itc_systemio_iotbus_uart_flush_p * @brief flushes uart buffer * @scenario flushes uart buffer * @apicovered iotbus_uart_flush * @precondition initializes uart_context * @postcondition closes uart_context */ void itc_systemio_iotbus_uart_flush_p(void) { int ret = IOTBUS_ERROR_NONE; iotbus_uart_context_h h_uart = iotbus_uart_init(DEVPATH); TC_ASSERT_NEQ("iotbus_uart_init", h_uart, NULL); ret = iotbus_uart_flush(h_uart); TC_ASSERT_EQ_CLEANUP("iotbus_uart_flush", 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(); }
/** * @testcase itc_systemio_iotbus_uart_set_baudrate_p * @brief sets uart baud rate * @scenario sets uart baud rate * @apicovered iotbus_uart_set_baudrate * @precondition initializes uart_context * @postcondition closes uart_context */ void itc_systemio_iotbus_uart_set_baudrate_p(void) { int i_baudrate = 115200; int ret = IOTBUS_ERROR_NONE; iotbus_uart_context_h h_uart = iotbus_uart_init(DEVPATH); TC_ASSERT_NEQ("iotbus_uart_init", h_uart, NULL); ret = iotbus_uart_set_baudrate(h_uart, i_baudrate); TC_ASSERT_EQ_CLEANUP("iotbus_uart_set_baudrate", 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();; }
/** * @testcase itc_systemio_iotbus_uart_set_flowcontrol_p * @brief set flow control settings * @scenario set flow control settings * @apicovered iotbus_uart_set_flowcontrol * @precondition initializes uart_context * @postcondition closes uart_context */ void itc_systemio_iotbus_uart_set_flowcontrol_p(void) { int i_size = 4; int ret = IOTBUS_ERROR_NONE; int rtscts[4][2] = { {1, 0}, {0, 1}, {1, 1}, {0, 0} }; 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_size; index++) { ret = iotbus_uart_set_flowcontrol(h_uart, rtscts[index][0], rtscts[index][1]); TC_ASSERT_EQ_CLEANUP("iotbus_uart_set_flowcontrol", 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(); }
/** * @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(); }
/** * @testcase itc_systemio_iotbus_uart_set_baudrate_n * @brief sets uart baud rate * @scenario sets uart baud rate * @apicovered iotbus_uart_set_baudrate * @precondition initializes uart_context * @postcondition closes uart_context */ static void itc_systemio_iotbus_uart_set_baudrate_n(void) { int i_baudrate = -115200; // invalid baudrate int ret = IOTBUS_ERROR_NONE; iotbus_uart_context_h h_uart = iotbus_uart_init(DEVPATH); TC_ASSERT_NEQ("iotbus_uart_init", h_uart, NULL); ret = iotbus_uart_set_baudrate(h_uart, i_baudrate); TC_ASSERT_EQ_CLEANUP("iotbus_uart_set_baudrate", ret, IOTBUS_ERROR_INVALID_PARAMETER, iotbus_uart_stop(h_uart)); ret = iotbus_uart_stop(h_uart); TC_ASSERT_EQ("iotbus_uart_stop", ret, IOTBUS_ERROR_NONE); 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(); }
/****************************** UART TEST ******************************/ int systemio_test_uart(char *failstr) { int result = SYSIO_RESULT_FAIL; int fail_flag = 0; iotbus_uart_context_h uart; int ret = -1; char *dev_path = "/dev/ttyS1"; uart = iotbus_uart_init(dev_path); if (!uart) { SYSIO_DEBUG("[IOTAPI] iotbus_uart_init() fail \n"); REGISTER_FAIL_REASON("iotbus_uart_init() fail", &fail_flag); goto errout_without_handle; } else { SYSIO_DEBUG("[IOTAPI] iotbus_uart_init() success \n"); } unsigned int baudrate = 115200; ret = iotbus_uart_set_baudrate(uart, baudrate); if (ret < 0) { SYSIO_DEBUG("[IOTAPI] iotbus_uart_set_baudrate(baudrate=%d) fail \n", baudrate); REGISTER_FAIL_REASON("iotbus_uart_set_baudrate() fail", &fail_flag); goto errout_with_handle; } else { SYSIO_DEBUG("[IOTAPI] iotbus_uart_set_baudrate(baudrate=%d) success \n", baudrate); } ret = iotbus_uart_set_mode(uart, 8, IOTBUS_UART_PARITY_NONE, 1); if (ret < 0) { SYSIO_DEBUG("[IOTAPI] iotbus_uart_set_mode(mode=8N1) fail \n"); REGISTER_FAIL_REASON("iotbus_uart_set_mode() fail", &fail_flag); goto errout_with_handle; } else { SYSIO_DEBUG("[IOTAPI] iotbus_uart_set_mode(mode=8N1) success \n"); } ret = iotbus_uart_set_flowcontrol(uart, 1, 1); if (ret < 0) { SYSIO_DEBUG("[IOTAPI] iotbus_uart_set_flowcontrol(1,1) fail \n"); REGISTER_FAIL_REASON("iotbus_uart_set_flowcontrol() fail", &fail_flag); goto errout_with_handle; } else { SYSIO_DEBUG("[IOTAPI] iotbus_uart_set_flowcontrol(1,1) success \n"); } #if 0 char rbuf[20]; ret = iotbus_uart_read(uart, rbuf, sizeof(rbuf)); if (ret < 0) { SYSIO_DEBUG("[IOTAPI] iotbus_uart_read() fail \n"); REGISTER_FAIL_REASON("iotbus_uart_read() fail", &fail_flag); //goto errout_with_handle; } else { SYSIO_DEBUG("[IOTAPI] iotbus_uart_read() success \n"); } #endif char tbuf[32] = "Go Bears!UART WRITE TEST OK!\n"; ret = iotbus_uart_write(uart, tbuf, sizeof(tbuf)); if (ret < 0) { SYSIO_DEBUG("[IOTAPI] iotbus_uart_write() fail \n"); // REGISTER_FAIL_REASON("iotbus_uart_write() fail", &fail_flag); //goto errout_with_handle; } else { SYSIO_DEBUG("[IOTAPI] iotbus_uart_write() success \n"); } ret = iotbus_uart_flush(uart); if (ret < 0) { SYSIO_DEBUG("[IOTAPI] iotbus_uart_flush() fail \n"); // REGISTER_FAIL_REASON("iotbus_uart_flush() fail", &fail_flag); //goto errout_with_handle; } else { SYSIO_DEBUG("[IOTAPI] iotbus_uart_flush() success \n"); } errout_with_handle: ret = iotbus_uart_stop(uart); if (ret < 0) { SYSIO_DEBUG("[IOTAPI] iotbus_uart_stop() fail \n"); REGISTER_FAIL_REASON("iotbus_uart_stop() fail", &fail_flag); } else { SYSIO_DEBUG("[IOTAPI] iotbus_uart_stop() success \n"); } errout_without_handle: /* check if succeed */ if (fail_flag == 0) { result = SYSIO_RESULT_SUCCESS; } return result; }