Skip to content

Commit

Permalink
testing: Add Serial Error Reporting testing app
Browse files Browse the repository at this point in the history
This commit adds support to Serial Error Reporting using the ioctl
TIOCGICOUNT.

Signed-off-by: Alan C. Assis <[email protected]>
  • Loading branch information
acassis committed Feb 6, 2025
1 parent 5d7ff30 commit 90e0f26
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 0 deletions.
33 changes: 33 additions & 0 deletions testing/drivers/ser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ##############################################################################
# apps/testing/drivers/ser/CMakeLists.txt
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################

if(CONFIG_TESTING_SERIAL)
nuttx_add_application(
NAME
${CONFIG_TESTING_SERIAL_PROGNAME}
PRIORITY
${CONFIG_TESTING_SERIAL_PRIORITY}
STACKSIZE
${CONFIG_TESTING_SERIAL_STACKSIZE}
SRCS
ser.c)
endif()
31 changes: 31 additions & 0 deletions testing/drivers/ser/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

config TESTING_SERIAL
bool "Serial Error Report (ser)"
default n
depends on SERIAL_TIOCGICOUNT
---help---
Enable the serial error reporting test. This test
could report U[S]ART erros like frame, overrun, parity, etc

if TESTING_SERIAL

config TESTING_SERIAL_PROGNAME
string "Program name"
default "ser"
---help---
This is the name of the program that will be used when the NSH ELF
program is installed.

config TESTING_SERIAL_PRIORITY
int "ser utility task priority"
default 100

config TESTING_SERIAL_STACKSIZE
int "ser utility stack size"
default DEFAULT_TASK_STACKSIZE

endif
25 changes: 25 additions & 0 deletions testing/drivers/ser/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
############################################################################
# apps/testing/drivers/ser/Make.defs
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

ifneq ($(CONFIG_TESTING_SERIAL),)
CONFIGURED_APPS += $(APPDIR)/testing/drivers/ser
endif
35 changes: 35 additions & 0 deletions testing/drivers/ser/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
############################################################################
# apps/testing/drivers/ser/Makefile
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

include $(APPDIR)/Make.defs

# ser built-in application info

PROGNAME = $(CONFIG_TESTING_SERIAL_PROGNAME)
PRIORITY = $(CONFIG_TESTING_SERIAL_PRIORITY)
STACKSIZE = $(CONFIG_TESTING_SERIAL_STACKSIZE)

# ser main source

MAINSRC = ser.c

include $(APPDIR)/Application.mk
115 changes: 115 additions & 0 deletions testing/drivers/ser/ser.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/****************************************************************************
* apps/testing/drivers/ser/ser.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <fcntl.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <nuttx/serial/serial.h>

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

/****************************************************************************
* Private Types
****************************************************************************/

/****************************************************************************
* Private Data
****************************************************************************/

/****************************************************************************
* Private Functions
****************************************************************************/

/****************************************************************************
* Public Functions
****************************************************************************/

int main(int argc, FAR char *argv[])
{
struct serial_icounter_s rcount;
struct serial_icounter_s scount;

int fd;
int ret;

fd = open("/dev/ttyS1", O_RDONLY);
if (fd < 0)
{
ret = -ENODEV;
goto out;
}

ret = ioctl(fd, TIOCGICOUNT, &scount);
if (ret < 0)
{
goto out_close;
}

while (1)
{
ret = ioctl(fd, TIOCGICOUNT, &rcount);

if (rcount.frame > scount.frame)
{
printf("ERROR: framing %d\n", rcount.frame - scount.frame);
}

if (rcount.overrun > scount.overrun)
{
printf("ERROR: overrun %d\n", rcount.overrun - scount.overrun);
}

if (rcount.parity > scount.parity)
{
printf("ERROR: parity %d\n", rcount.parity - scount.parity);
}

if (rcount.brk > scount.brk)
{
printf("ERROR: break %d\n", rcount.brk - scount.brk);
}

if (rcount.buf_overrun > scount.buf_overrun)
{
printf("ERROR: buffer overrun %d\n",
rcount.buf_overrun - scount.buf_overrun);
}

scount = rcount;

Check failure on line 106 in testing/drivers/ser/ser.c

View workflow job for this annotation

GitHub Actions / check

Dangling whitespace at the end of line
usleep(1000000);
}

out_close:
close(fd);
out:

return ret;
}

0 comments on commit 90e0f26

Please sign in to comment.