<div dir="ltr"><br>Porting UART test from ltp-ddt back to ltp. only test 115200 UART_RATE.<br><br>[TODO] support more rate, and add test HWFLOW function test.<br><br>Signed-off-by: Orson Zhai <<a href="mailto:orson@gmail.com">orson@gmail.com</a>><br>Signed-off-by: Cixi Geng <<a href="mailto:gengcixi@gmail.com">gengcixi@gmail.com</a>><div>Signed-off-by: Carlos Hernandez <<a href="mailto:ceh@ti.com">ceh@ti.com</a>><br>---<br> runtest/kernel_ddt                            |   1 +<br> testcases/kernel/device-drivers/Makefile      |   1 +<br> testcases/kernel/device-drivers/uart/Makefile |  22 ++++<br> .../kernel/device-drivers/uart/serialcheck.sh | 111 ++++++++++++++++++<br> 4 files changed, 135 insertions(+)<br> create mode 100644 runtest/kernel_ddt<br> create mode 100644 testcases/kernel/device-drivers/uart/Makefile<br> create mode 100755 testcases/kernel/device-drivers/uart/serialcheck.sh<br><br>diff --git a/runtest/kernel_ddt b/runtest/kernel_ddt<br>new file mode 100644<br>index 000000000..30e9a0269<br>--- /dev/null<br>+++ b/runtest/kernel_ddt<br>@@ -0,0 +1 @@<br>+uart serialcheck.sh<br>diff --git a/testcases/kernel/device-drivers/Makefile b/testcases/kernel/device-drivers/Makefile<br>index 55e0d25a0..a214f211b 100644<br>--- a/testcases/kernel/device-drivers/Makefile<br>+++ b/testcases/kernel/device-drivers/Makefile<br>@@ -27,6 +27,7 @@ SUBDIRS            := acpi \<br>               rtc \<br>               tbio \<br>              uaccess \<br>+                   uart \<br>              zram<br> <br> include $(top_srcdir)/include/mk/<a href="http://generic_trunk_target.mk">generic_trunk_target.mk</a><br>diff --git a/testcases/kernel/device-drivers/uart/Makefile b/testcases/kernel/device-drivers/uart/Makefile<br>new file mode 100644<br>index 000000000..0d73f6635<br>--- /dev/null<br>+++ b/testcases/kernel/device-drivers/uart/Makefile<br>@@ -0,0 +1,22 @@<br>+# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.<br>+#<br>+# This program is free software; you can redistribute it and/or<br>+# modify it under the terms of the GNU General Public License as<br>+# published by the Free Software Foundation; either version 2 of<br>+# the License, or (at your option) any later version.<br>+#<br>+# This program is distributed in the hope that it would be useful,<br>+# but WITHOUT ANY WARRANTY; without even the implied warranty of<br>+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>+# GNU General Public License for more details.<br>+#<br>+# You should have received a copy of the GNU General Public License<br>+# along with this program; if not, write the Free Software Foundation,<br>+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA<br>+<br>+top_srcdir ?= ../../../..<br>+include $(top_srcdir)/include/mk/<a href="http://testcases.mk">testcases.mk</a><br>+<br>+INSTALL_TARGETS             := *.sh<br>+<br>+include $(top_srcdir)/include/mk/<a href="http://generic_leaf_target.mk">generic_leaf_target.mk</a><br>diff --git a/testcases/kernel/device-drivers/uart/serialcheck.sh b/testcases/kernel/device-drivers/uart/serialcheck.sh<br>new file mode 100755<br>index 000000000..f4cf13e02<br>--- /dev/null<br>+++ b/testcases/kernel/device-drivers/uart/serialcheck.sh<br>@@ -0,0 +1,111 @@<br>+#!/bin/sh<br>+###############################################################################<br>+#<br>+# Copyright (C) 2015 Texas Instruments Incorporated - <a href="http://www.ti.com/">http://www.ti.com/</a><br>+# Copyright (C) 2019, Unisoc Communications Inc.<br>+#<br>+# This program is free software; you can redistribute it and/or<br>+# modify it under the terms of the GNU General Public License as<br>+# published by the Free Software Foundation version 2.<br>+#<br>+# This program is distributed "as is" WITHOUT ANY WARRANTY of any<br>+# kind, whether express or implied; without even the implied warranty<br>+# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>+# GNU General Public License for more details.<br>+#<br>+###############################################################################<br>+<br>+# @desc Test UART ports using git://<a href="http://git.breakpoint.cc/bigeasy/serialcheck.git">git.breakpoint.cc/bigeasy/serialcheck.git</a><br>+<br>+#### Functions definitions ####<br>+usage()<br>+{<br>+    echo "usage: ./${0##*/} [-r UART_RATE] [-l LOOPS] [-x to enable HW flow control]"<br>+    exit 1<br>+}<br>+<br>+# Default values<br>+: ${UART_RATE:=115200}<br>+: ${UART_LOOPS:=5}<br>+: ${UART_HWFLOW:=0}<br>+<br>+PORTS_TO_TEST=();<br>+UART_PORTS=();<br>+ARRAY=(`find /sys/class/tty/*/uartclk`);<br>+<br>+check_requirements()<br>+{<br>+   which serialcheck<br>+    ret=$?<br>+       if [ $ret -eq 0 ];then<br>+               tst_res TINFO "serialcheck command is in system,continue to test"<br>+  else<br>+         tst_brk TCONF "test failed for lack of requirement,returned is $ret"<br>+       fi<br>+<br>+}<br>+<br>+create_test_file()<br>+{<br>+    temp_test_file=`mktemp`<br>+    dd if=/dev/urandom of=$temp_test_file count=1 bs=$((UART_RATE / 2))<br>+}<br>+<br>+get_uart_ports()<br>+{<br>+for i in ${ARRAY[@]}; do<br>+    PORT=/dev/`echo $i | cut -d'/' -f 5`<br>+    # Activate port in case it will be initialized only when startup<br>+    echo "DDT TESTING" > $PORT 2>/dev/null<br>+    if [ `cat $i` -ne 0 ]; then<br>+        UART_PORTS=("${UART_PORTS[@]}" "$PORT")<br>+    fi<br>+done<br>+}<br>+<br>+filter_out_used_ports()<br>+{<br>+ which lsof<br>+   ret=$?<br>+       if [ $ret -eq 0 ];then<br>+               tst_res TINFO "lsof command exist, filter out used ports";<br>+ else<br>+         tst_brk TCONF "test failed for lack of requirement,returned is $ret"<br>+       fi<br>+<br>+    for i in ${UART_PORTS[@]}; do<br>+        lsof | grep $i &> /dev/null || PORTS_TO_TEST=("${PORTS_TO_TEST[@]}" $i)<br>+    done<br>+}<br>+<br>+run_serial_test()<br>+{<br>+       create_test_file<br>+    for i in ${PORTS_TO_TEST[@]}; do<br>+        if [ $UART_HWFLOW -eq 0 ]; then<br>+            { sleep 1; serialcheck -b $UART_RATE -d $i -f $temp_test_file -l $UART_LOOPS -m t -k; }&<br>+            PID=$!<br>+            serialcheck -b $UART_RATE -d $i -f $temp_test_file -l $UART_LOOPS -m r -k || { kill -- -$PID 2>/dev/null; tst_res TFAIL "TEST FAILED"; }<br>+        else<br>+            { sleep 1; serialcheck -b $UART_RATE -d $i -f $temp_test_file -l $UART_LOOPS -m t -h; } &<br>+            PID=$!<br>+            serialcheck -b $UART_RATE -d $i -f $temp_test_file -l $UART_LOOPS -m r -h || { kill -- -$PID 2>/dev/null; tst_res TFAIL "TEST FAILED"; }<br>+        fi<br>+    done<br>+    rm $temp_test_file<br>+     tst_res TPASS "uart test passed"<br>+}<br>+<br>+<br>+TST_TESTFUNC=do_test<br>+. tst_test.sh<br>+<br>+do_test()<br>+{<br>+       check_requirements<br>+   get_uart_ports<br>+       filter_out_used_ports<br>+        run_serial_test<br>+}<br>+<br>+tst_run<br>-- <br>2.17.1<br><br></div></div>