Skip to content

Commit 80cbcf8

Browse files
committed
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]>
1 parent 8841299 commit 80cbcf8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

testing/drivers/drivertest/drivertest_uart.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <stdint.h>
3434
#include <stdlib.h>
3535
#include <string.h>
36+
#include <termios.h>
3637
#include <unistd.h>
3738
#include <sys/ioctl.h>
3839
#include <cmocka.h>
@@ -70,6 +71,7 @@ struct test_confs_s
7071
struct test_state_s
7172
{
7273
FAR const char *dev_path;
74+
struct termios devtio; /* Original serial port setting */
7375
FAR char *buffer;
7476
int fd;
7577
};
@@ -170,6 +172,8 @@ static int setup(FAR void **state)
170172
{
171173
FAR struct test_confs_s *confs = (FAR struct test_confs_s *)*state;
172174
FAR struct test_state_s *test_state = malloc(sizeof(struct test_state_s));
175+
struct termios ti;
176+
int ret = 0;
173177
assert_true(test_state != NULL);
174178

175179
test_state->dev_path = confs->dev_path;
@@ -180,6 +184,16 @@ static int setup(FAR void **state)
180184
test_state->fd = open(test_state->dev_path, O_RDWR);
181185
assert_true(test_state->fd > 0);
182186

187+
ret = tcgetattr(test_state->fd, &ti);
188+
assert_int_equal(ret, OK);
189+
190+
/* Backup and enable data to be processed as raw input */
191+
192+
memcpy(&test_state->devtio, &ti, sizeof(struct termios));
193+
cfmakeraw(&ti);
194+
ret = tcsetattr(test_state->fd, TCSANOW, &ti);
195+
assert_int_equal(ret, OK);
196+
183197
*state = test_state;
184198
return 0;
185199
}
@@ -191,6 +205,12 @@ static int setup(FAR void **state)
191205
static int teardown(FAR void **state)
192206
{
193207
FAR struct test_state_s *test_state = (FAR struct test_state_s *)*state;
208+
int ret = 0;
209+
210+
/* Retrieve termios updated flags */
211+
212+
ret = tcsetattr(test_state->fd, TCSANOW, &test_state->devtio);
213+
assert_int_equal(ret, OK);
194214

195215
free(test_state->buffer);
196216
assert_int_equal(close(test_state->fd), 0);

0 commit comments

Comments
 (0)