From 2a9aa338ce4bccc8b2e4484a532d0bc05ae1b917 Mon Sep 17 00:00:00 2001 From: buxiasen Date: Tue, 22 Oct 2024 19:44:36 +0800 Subject: [PATCH] drivertest_uart: uart device open should use cfmakeraw to ensure raw. reference: https://www.man7.org/linux/man-pages/man3/termios.3.html Signed-off-by: buxiasen --- testing/drivers/drivertest/drivertest_uart.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/testing/drivers/drivertest/drivertest_uart.c b/testing/drivers/drivertest/drivertest_uart.c index fb19a980e42..24714386194 100644 --- a/testing/drivers/drivertest/drivertest_uart.c +++ b/testing/drivers/drivertest/drivertest_uart.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -70,6 +71,7 @@ struct test_confs_s struct test_state_s { FAR const char *dev_path; + struct termios devtio; /* Original serial port setting */ FAR char *buffer; int fd; }; @@ -170,6 +172,8 @@ static int setup(FAR void **state) { FAR struct test_confs_s *confs = (FAR struct test_confs_s *)*state; FAR struct test_state_s *test_state = malloc(sizeof(struct test_state_s)); + struct termios ti; + int ret = 0; assert_true(test_state != NULL); test_state->dev_path = confs->dev_path; @@ -180,6 +184,16 @@ static int setup(FAR void **state) test_state->fd = open(test_state->dev_path, O_RDWR); assert_true(test_state->fd > 0); + ret = tcgetattr(test_state->fd, &ti); + assert_int_equal(ret, OK); + + /* Backup and enable data to be processed as raw input */ + + memcpy(&test_state->devtio, &ti, sizeof(struct termios)); + cfmakeraw(&ti); + ret = tcsetattr(test_state->fd, TCSANOW, &ti); + assert_int_equal(ret, OK); + *state = test_state; return 0; } @@ -191,6 +205,12 @@ static int setup(FAR void **state) static int teardown(FAR void **state) { FAR struct test_state_s *test_state = (FAR struct test_state_s *)*state; + int ret = 0; + + /* Retrieve termios updated flags */ + + ret = tcsetattr(test_state->fd, TCSANOW, &test_state->devtio); + assert_int_equal(ret, OK); free(test_state->buffer); assert_int_equal(close(test_state->fd), 0);