Example #1
0
/**
* @testcase         itc_systemio_iotbus_uart_write_read_flush_read_p
* @brief            perform write, read, flush, and read data operations over uart bus
* @scenario         perform write, read, flush, and read data operations 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_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_flush(h_uart);
	TC_ASSERT_EQ_CLEANUP("iotbus_uart_flush", ret, IOTBUS_ERROR_NONE, iotbus_uart_stop(h_uart));

	ret = iotbus_uart_read(h_uart, sz_output_text, sizeof(sz_output_text));
	TC_ASSERT_EQ_CLEANUP("iotbus_uart_read", ret == 0, true, iotbus_uart_stop(h_uart));

	ret = iotbus_uart_stop(h_uart);
	TC_ASSERT_EQ("iotbus_uart_stop", ret, IOTBUS_ERROR_NONE);

	TC_SUCCESS_RESULT();
}
Example #2
0
/**
* @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();
}
Example #3
0
/**
* @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();
}
Example #4
0
/******************************
     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;
}