Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions testing/drivers/drivertest/drivertest_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down
Loading