]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sandbox: Add serial test
authorPatrice Chotard <patrice.chotard@st.com>
Fri, 3 Aug 2018 13:07:41 +0000 (15:07 +0200)
committerTom Rini <trini@konsulko.com>
Tue, 11 Sep 2018 00:48:12 +0000 (20:48 -0400)
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/serial/sandbox.c
include/common.h
include/serial.h
test/dm/Makefile
test/dm/serial.c [new file with mode: 0644]

index a60dabe58835648027ed53d29a715431bea753cd..94b4fdfb17148cd4a30a0bf9c5cc56fa09a4de84 100644 (file)
@@ -143,6 +143,19 @@ static int sandbox_serial_getc(struct udevice *dev)
        return result;
 }
 
+static int sandbox_serial_setconfig(struct udevice *dev, uint serial_config)
+{
+       u8 parity = SERIAL_GET_PARITY(serial_config);
+       u8 bits = SERIAL_GET_BITS(serial_config);
+       u8 stop = SERIAL_GET_STOP(serial_config);
+
+       if (bits != SERIAL_8_BITS || stop != SERIAL_ONE_STOP ||
+           parity != SERIAL_PAR_NONE)
+               return -ENOTSUPP; /* not supported in driver*/
+
+       return 0;
+}
+
 static const char * const ansi_colour[] = {
        "black", "red", "green", "yellow", "blue", "megenta", "cyan",
        "white",
@@ -173,6 +186,7 @@ static const struct dm_serial_ops sandbox_serial_ops = {
        .putc = sandbox_serial_putc,
        .pending = sandbox_serial_pending,
        .getc = sandbox_serial_getc,
+       .setconfig = sandbox_serial_setconfig,
 };
 
 static const struct udevice_id sandbox_serial_ids[] = {
index 940161f1758b77cfa31984ed3b65bd28b208b47d..5c952af5e31988f8b86b0c0e067760a0f9ba0595 100644 (file)
@@ -359,6 +359,7 @@ void        serial_putc_raw(const char);
 void   serial_puts   (const char *);
 int    serial_getc   (void);
 int    serial_tstc   (void);
+int    serial_setconfig(uint config);
 
 /* $(CPU)/speed.c */
 int    get_clocks (void);
index ffda48a1410aab62e034faf544b037e296176235..020cd392e888e2c0bdc2e28b025257e489db774a 100644 (file)
@@ -102,6 +102,11 @@ enum serial_stop {
 #define SERIAL_GET_STOP(config) \
        ((config & SERIAL_STOP_MASK) >> SERIAL_STOP_SHIFT)
 
+#define SERIAL_CONFIG(par, bits, stop) \
+                    (par << SERIAL_PAR_SHIFT | \
+                     bits << SERIAL_BITS_SHIFT | \
+                     stop << SERIAL_STOP_SHIFT)
+
 #define SERIAL_DEFAULT_CONFIG  SERIAL_PAR_NONE << SERIAL_PAR_SHIFT | \
                                SERIAL_8_BITS << SERIAL_BITS_SHIFT | \
                                SERIAL_ONE_STOP << SERIAL_STOP_SHIFT
index 67c1fe6d0142dcc7360d50a2da1ffc349cef3e60..3f5a634afd5cf16023ebba51ffb5d4c008e68b1a 100644 (file)
@@ -46,4 +46,5 @@ obj-$(CONFIG_SPMI) += spmi.o
 obj-$(CONFIG_WDT) += wdt.o
 obj-$(CONFIG_AXI) += axi.o
 obj-$(CONFIG_MISC) += misc.o
+obj-$(CONFIG_DM_SERIAL) += serial.o
 endif
diff --git a/test/dm/serial.c b/test/dm/serial.c
new file mode 100644 (file)
index 0000000..5c603e1
--- /dev/null
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018, STMicroelectronics
+ */
+
+#include <common.h>
+#include <serial.h>
+#include <dm.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+static int dm_test_serial(struct unit_test_state *uts)
+{
+       struct udevice *dev_serial;
+
+       ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial",
+                                             &dev_serial));
+
+       ut_assertok(serial_tstc());
+       /*
+        * test with default config which is the only one supported by
+        * sandbox_serial driver
+        */
+       ut_assertok(serial_setconfig(SERIAL_DEFAULT_CONFIG));
+       /*
+        * test with a serial config which is not supported by
+        * sandbox_serial driver: test with wrong parity
+        */
+       ut_asserteq(-ENOTSUPP,
+                   serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_ODD,
+                                                  SERIAL_8_BITS,
+                                                  SERIAL_ONE_STOP)));
+       /*
+        * test with a serial config which is not supported by
+        * sandbox_serial driver: test with wrong bits number
+        */
+       ut_asserteq(-ENOTSUPP,
+                   serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_NONE,
+                                                  SERIAL_6_BITS,
+                                                  SERIAL_ONE_STOP)));
+
+       /*
+        * test with a serial config which is not supported by
+        * sandbox_serial driver: test with wrong stop bits number
+        */
+       ut_asserteq(-ENOTSUPP,
+                   serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_NONE,
+                                                  SERIAL_8_BITS,
+                                                  SERIAL_TWO_STOP)));
+
+       return 0;
+}
+
+DM_TEST(dm_test_serial, DM_TESTF_SCAN_FDT);