This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 4ac0b1031 drivertest_uart: uart device open should use cfmakeraw to
ensure raw.
4ac0b1031 is described below
commit 4ac0b10318bbce2732347f37c77f95687748d31b
Author: buxiasen <[email protected]>
AuthorDate: Tue Oct 22 19:44:36 2024 +0800
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 <[email protected]>
---
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 fb19a980e..247143861 100644
--- a/testing/drivers/drivertest/drivertest_uart.c
+++ b/testing/drivers/drivertest/drivertest_uart.c
@@ -33,6 +33,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <termios.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <cmocka.h>
@@ -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);