diff options
author | Chris Johns <chrisj@rtems.org> | 2016-11-25 15:13:36 +1100 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2016-11-29 08:50:40 +1100 |
commit | a0d4e9933c57693f99203da358bb8aaa8a5d50d9 (patch) | |
tree | d17a98faf93185d2baa18fba6ee97b0e2916b2e4 /testsuites/libtests | |
parent | arm/zynq: Wait for the UART TX FIFO to empty on reset. (diff) | |
download | rtems-a0d4e9933c57693f99203da358bb8aaa8a5d50d9.tar.bz2 |
cpukit: Add libdebugger, a remote debugger agent for GDB.
Diffstat (limited to 'testsuites/libtests')
-rw-r--r-- | testsuites/libtests/Makefile.am | 4 | ||||
-rw-r--r-- | testsuites/libtests/configure.ac | 12 | ||||
-rw-r--r-- | testsuites/libtests/debugger01/Makefile.am | 21 | ||||
-rw-r--r-- | testsuites/libtests/debugger01/debugger01.doc | 18 | ||||
-rw-r--r-- | testsuites/libtests/debugger01/debugger01.scn | 188 | ||||
-rw-r--r-- | testsuites/libtests/debugger01/init.c | 53 | ||||
-rw-r--r-- | testsuites/libtests/debugger01/remote.c | 321 | ||||
-rw-r--r-- | testsuites/libtests/debugger01/system.h | 37 |
8 files changed, 654 insertions, 0 deletions
diff --git a/testsuites/libtests/Makefile.am b/testsuites/libtests/Makefile.am index c00916a143..9ff4394f9e 100644 --- a/testsuites/libtests/Makefile.am +++ b/testsuites/libtests/Makefile.am @@ -53,5 +53,9 @@ _SUBDIRS += dl04 dl05 endif endif +if DEBUGGERTESTS +_SUBDIRS += debugger01 +endif + include $(top_srcdir)/../automake/test-subdirs.am include $(top_srcdir)/../automake/local.am diff --git a/testsuites/libtests/configure.ac b/testsuites/libtests/configure.ac index 430c509640..8e74b3e979 100644 --- a/testsuites/libtests/configure.ac +++ b/testsuites/libtests/configure.ac @@ -80,6 +80,17 @@ AS_IF([test x"$TEST_LIBDL" = x"yes"],[ AM_CONDITIONAL(DLTESTS,[test x"$TEST_LIBDL" = x"yes"]) +# Must match the list in cpukit. +AC_MSG_CHECKING([whether CPU supports libdebugger]) +case $RTEMS_CPU in + arm | i386) + TEST_LIBDEBUGGER=yes ;; + *) + TEST_LIBDEBUGGER=no ;; +esac +AC_MSG_RESULT([$TEST_LIBDEBUGGER]) +AM_CONDITIONAL(DEBUGGERTESTS,[test x"$TEST_LIBDEBUGGER" = x"yes"]) + # Explicitly list all Makefiles here AC_CONFIG_FILES([Makefile networking01/Makefile @@ -169,5 +180,6 @@ math/Makefile mathf/Makefile mathl/Makefile complex/Makefile +debugger01/Makefile ]) AC_OUTPUT diff --git a/testsuites/libtests/debugger01/Makefile.am b/testsuites/libtests/debugger01/Makefile.am new file mode 100644 index 0000000000..d0bf0f8c14 --- /dev/null +++ b/testsuites/libtests/debugger01/Makefile.am @@ -0,0 +1,21 @@ + +rtems_tests_PROGRAMS = debugger01 +debugger01_SOURCES = init.c remote.c system.h + +dist_rtems_tests_DATA = debugger01.scn + +include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg +include $(top_srcdir)/../automake/compile.am +include $(top_srcdir)/../automake/leaf.am + + +AM_CPPFLAGS += -I$(top_srcdir)/../support/include + +LINK_OBJS = $(debugger01_OBJECTS) +LINK_LIBS = $(debugger01_LDLIBS) + +debugger01$(EXEEXT): $(debugger01_OBJECTS) $(debugger01_DEPENDENCIES) + @rm -f debugger01$(EXEEXT) + $(make-exe) + +include $(top_srcdir)/../automake/local.am diff --git a/testsuites/libtests/debugger01/debugger01.doc b/testsuites/libtests/debugger01/debugger01.doc new file mode 100644 index 0000000000..2cdd48bf4d --- /dev/null +++ b/testsuites/libtests/debugger01/debugger01.doc @@ -0,0 +1,18 @@ +# Copyright (c) 2016 Chris Johns <chrisj@rtems.org> +# +# The license and distribution terms for this file may be +# found in the file LICENSE in this distribution or at +# http://www.rtems.org/license/LICENSE. +# + +This file describes the directives and concepts tested by this test set. + +test set name: debugger01 + +directives: + + rtems_debugger_start + +concepts: + ++ Starts a debugging session with the test remote backend. diff --git a/testsuites/libtests/debugger01/debugger01.scn b/testsuites/libtests/debugger01/debugger01.scn new file mode 100644 index 0000000000..7d221fd98b --- /dev/null +++ b/testsuites/libtests/debugger01/debugger01.scn @@ -0,0 +1,188 @@ + +*** BEGIN OF TEST DEBUGGER01 *** +error: rtems-db: remote not found: test +error: rtems-db: test remote: begin +rtems-db: remote-debug is on +rtems-db: remote running +rtems-db: test remote: isconnected: not-connected +error: rtems-db: test remote: connect +rtems-db: remote running +rtems-db: arm debug: (v3.0) ARMv7 [v7, all CP14 registers] breakpoints:5 +watchpoints:3 +rtems-db: sys: : suspending +rtems-db: sys: thd: 0a010001: signal: 0 +rtems-db: test remote: isconnected: connected + remote: rx: message=0 length=1 + remote: rx: + +rtems-db: get: 1: + [[ACK?]] + remote: rx: message=1 length=5 + remote: rx: xxxxx + remote: rx: message=2 length=5 + remote: rx: $x#aa +rtems-db: get: 5: xxxxx [[junk dropped]] +rtems-db: get: : $x#aa [[invalid checksum]] +rtems-db: put: 1: - + remote: tx: message=0 length=1 + remote: tx: - + remote: rx: message=3 length=141 + remote: rx: $qSupported:multiprocess+;swbreak+;hwbreak+;qRelocInsn+;fork-events+;vfork-events+;exec-events+;vContSupported+;QThreadEvents+;no-resumed+#df +rtems-db: get: 141: [[junk dropped]] +rtems-db: get: : $qSupported:multiprocess+;swbreak+;hwbreak+;qRelocInsn+;fork-events+;vfork-events+;exec-events+;vContSupported+;QThreadEvents+;no-resumed+#df +rtems-db: put: 1: + + remote: tx: message=1 length=1 + remote: tx: + +rtems-db: put: 167: $qSupported:PacketSize=4096;QNonStop-;multiprocess+;swbreak+;hwbreak-;qRelocInsn-;fork-events-;vfork-events-;exec-events-;vContSupported+;QThreadEvents-;no-resumed+#b3 + remote: tx: message=2 length=167 + remote: tx: $qSupported:PacketSize=4096;QNonStop-;multiprocess+;swbreak+;hwbreak-;qRelocInsn-;fork-events-;vfork-events-;exec-events-;vContSupported+;QThreadEvents-;no-resumed+#b3 +rtems-db: test remote: isconnected: connected + remote: rx: message=4 length=19 + remote: rx: $vMustReplyEmpty#3a +rtems-db: get: 19: $vMustReplyEmpty#3a +rtems-db: put: 1: + + remote: tx: message=3 length=1 + remote: tx: + +rtems-db: put: 4: $#00 + remote: tx: message=4 length=4 + remote: tx: $#00 +rtems-db: test remote: isconnected: connected + remote: rx: message=5 length=1 + remote: rx: + +rtems-db: get: 1: + [[ACK]] + remote: rx: message=6 length=10 + remote: rx: $Hgp0.0#ad +rtems-db: get: 10: $Hgp0.0#ad +rtems-db: put: 1: + + remote: tx: message=5 length=1 + remote: tx: + +rtems-db: put: 6: $OK#9a + remote: tx: message=6 length=6 + remote: tx: $OK#9a +rtems-db: test remote: isconnected: connected + remote: rx: message=7 length=1 + remote: rx: + +rtems-db: get: 1: + [[ACK]] + remote: rx: message=8 length=12 + remote: rx: $qTStatus#49 +rtems-db: get: 12: $qTStatus#49 +rtems-db: put: 1: + + remote: tx: message=7 length=1 + remote: tx: + +rtems-db: put: 4: $#00 + remote: tx: message=8 length=4 + remote: tx: $#00 +rtems-db: test remote: isconnected: connected + remote: rx: message=9 length=1 + remote: rx: + +rtems-db: get: 1: + [[ACK]] + remote: rx: message=10 length=5 + remote: rx: $?#3f +rtems-db: get: 5: $?#3f +rtems-db: put: 1: + + remote: tx: message=9 length=1 + remote: tx: + +rtems-db: put: 26: $T00thread:p1.0a010001;#23 + remote: tx: message=10 length=26 + remote: tx: $T00thread:p1.0a010001;#23 +rtems-db: test remote: isconnected: connected + remote: rx: message=11 length=1 + remote: rx: + +rtems-db: get: 1: + [[ACK]] + remote: rx: message=12 length=16 + remote: rx: $qfThreadInfo#bb +rtems-db: get: 16: $qfThreadInfo#bb +rtems-db: put: 1: + + remote: tx: message=11 length=1 + remote: tx: + +rtems-db: put: 16: $mp1.0a010001#ef + remote: tx: message=12 length=2 + remote: tx: $mp1.0a010001#ef +rtems-db: test remote: isconnected: connected + remote: rx: message=13 length=1 + remote: rx: + +rtems-db: get: 1: + [[ACK]] + remote: rx: message=14 length=16 + remote: rx: $qsThreadInfo#c8 +rtems-db: get: 16: $qsThreadInfo#c8 +rtems-db: put: 1: + + remote: tx: message=13 length=1 + remote: tx: + +rtems-db: put: 5: $l#6c + remote: tx: message=14 length=5 + remote: tx: $l#6c +rtems-db: test remote: isconnected: connected + remote: rx: message=15 length=1 + remote: rx: - +rtems-db: get: 1: - [[NACK]] +rtems-db: put: 5: $l#6c + remote: tx: message=15 length=5 + remote: tx: $l#6c + remote: rx: message=16 length=1 + remote: rx: + +rtems-db: get: 1: + [[ACK]] + remote: rx: message=17 length=15 + remote: rx: $qAttached:1#fa +rtems-db: get: 15: $qAttached:1#fa +rtems-db: put: 1: + + remote: tx: message=16 length=1 + remote: tx: + +rtems-db: put: 5: $1#31 + remote: tx: message=17 length=5 + remote: tx: $1#31 +rtems-db: test remote: isconnected: connected + remote: rx: message=18 length=1 + remote: rx: + +rtems-db: get: 1: + [[ACK]] + remote: rx: message=19 length=8 + remote: rx: $Hc-1#09 +rtems-db: get: 8: $Hc-1#09 +rtems-db: put: 1: + + remote: tx: message=18 length=1 + remote: tx: + +rtems-db: put: 6: $OK#9a + remote: tx: message=19 length=6 + remote: tx: $OK#9a +rtems-db: test remote: isconnected: connected + remote: rx: message=20 length=1 + remote: rx: + +rtems-db: get: 1: + [[ACK]] + remote: rx: message=21 length=12 + remote: rx: $qOffsets#4b +rtems-db: get: 12: $qOffsets#4b +rtems-db: put: 1: + + remote: tx: message=20 length=1 + remote: tx: + +rtems-db: put: 4: $#00 + remote: tx: message=21 length=4 + remote: tx: $#00 +rtems-db: test remote: isconnected: connected + remote: rx: message=22 length=1 + remote: rx: + +rtems-db: get: 1: + [[ACK]] + remote: rx: message=23 length=6 + remote: rx: $g#67+ +rtems-db: get: 6: $g#67 +rtems-db: put: 1: + + remote: tx: message=22 length=1 + remote: tx: + ++ [[extra data: 0x2b]]rtems-db: put: 212: $cc381200cc381200cc381200cc3812004c162000a83f2000704520004c16200040362000481620000000000020ee1100cc38120028a2200089dc100089dc1000cc381200cc381200cc381200cc381200cc381200cc381200cc381200cc381200cc381200cc381200#95 + remote: tx: message=23 length=2 + remote: tx: $cc381200cc381200cc381200cc3812004c162000a83f2000704520004c16200040362000481620000000000020ee1100cc38120028a2200089dc100089dc1000cc381200cc381200cc381200cc381200cc381200cc381200cc381200cc381200cc3812g00cc381200#95 +rtems-db: test remote: isconnected: connected + remote: rx: message=24 length=7 + remote: rx: $D;1#b0 +rtems-db: get: 7: $D;1#b0 +rtems-db: put: 1: + + remote: tx: message=24 length=1 + remote: tx: + +rtems-db: put: 6: $OK#9a + remote: tx: message=25 length=6 + remote: tx: $OK#9a +rtems-db: test remote: isconnected: connected +rtems-db: test remote: disconnect host +rtems-db: test remote: isconnected: not-connected +rtems-db: events running +rtems-db: events finishing +rtems-db: sys: : resuming +rtems-db: test remote: isconnected: not-connected +rtems-db: test remote: isconnected: not-connected +*** END OF TEST DEBUGGER01 *** diff --git a/testsuites/libtests/debugger01/init.c b/testsuites/libtests/debugger01/init.c new file mode 100644 index 0000000000..e243d424a5 --- /dev/null +++ b/testsuites/libtests/debugger01/init.c @@ -0,0 +1,53 @@ +/* + * Debugger test. + * + * Copyright (c) 2016 Chris Johns (chrisj@rtems.org) + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#define CONFIGURE_INIT +#include "system.h" + +#include "tmacros.h" + +#include <rtems/rtems-debugger.h> + +#include "system.h" + +static void test(void) +{ + rtems_printer printer; + + rtems_print_printer_fprintf(&printer, stdout); + rtems_test_assert(rtems_debugger_start("test", "something", + 3, 10, &printer) < 0); + rtems_test_assert(rtems_debugger_register_test_remote() == 0); + rtems_test_assert(rtems_debugger_start("test", "something", + 3, 10, &printer) == 0); + rtems_debugger_set_verbose(true); + rtems_test_assert(rtems_debugger_remote_debug(true) == 0); + + /* + * This thread is suspended when the debugger is active until the debugger + * disconnects. + */ + sleep(1); +} + +const char rtems_test_name[] = "DEBUGGER01"; + +rtems_task Init(rtems_task_argument argument) +{ + TEST_BEGIN(); + + test(); + + TEST_END(); +} diff --git a/testsuites/libtests/debugger01/remote.c b/testsuites/libtests/debugger01/remote.c new file mode 100644 index 0000000000..1c8c4d09be --- /dev/null +++ b/testsuites/libtests/debugger01/remote.c @@ -0,0 +1,321 @@ +/* + * Debugger test remote. + * + * Copyright (c) 2016 Chris Johns (chrisj@rtems.org) + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include "tmacros.h" + +#include <errno.h> +#include <stdlib.h> +#include <unistd.h> + +#include <rtems/rtems-debugger.h> +#include <rtems/debugger/rtems-debugger-server.h> +#include <rtems/debugger/rtems-debugger-remote.h> + +#include "system.h" + +/** + * Remote data. + */ +typedef struct +{ + int connect_count; + bool connected; + size_t out; + size_t in; +} rtems_debugger_remote_test; + +static const char* out[] = +{ + "+", + "xxxxx", + "$x#aa", + + "$qSupported:multiprocess+;swbreak+;hwbreak+;qRelocInsn+;fork-events+;" + "vfork-events+;exec-events+;vContSupported+;QThreadEvents+;no-resumed+#df", + + "$vMustReplyEmpty#3a", + "+", + + "$Hgp0.0#ad", + "+", + + "$qTStatus#49", + "+", + + "$?#3f", + "+", + + "$qfThreadInfo#bb", + "+", + + "$qsThreadInfo#c8", + "-", + "+", + + "$qAttached:1#fa", + "+", + + "$Hc-1#09", + "+", + + "$qOffsets#4b", + "+", + + "$g#67" + "+", + + "$D;1#b0", + "+" +}; + +static const char* in[] = +{ + /* 0 */ + "-", + + /* 1 */ + "+", + "$qSupported:PacketSize=4096;QNonStop-;multiprocess+;swbreak+;hwbreak-;" + "qRelocInsn-;fork-events-;vfork-events-;exec-events-;vContSupported+;" + "QThreadEvents-;no-resumed+#b3", + + /* 3 */ + "+", + "$#00", + + /* 5 */ + "+", + "$OK#9a", + + /* 7 */ + "+", + "$#00", + + /* 9 */ + "+", + "$T00thread:p1.0a010001;#23", + + /* 11 */ + "+", + "**", + + /* 13 */ + "+", + "$l#6c", + "$l#6c", + + /* 16 */ + "+", + "$1#31", + + /* 18 */ + "+", + "$OK#9a", + + /* 20 */ + "+", + "$#00", + + /* 22 */ + "+", + "**", + + "+", + "$OK#9a" +}; + +static int +test_remote_begin(rtems_debugger_remote* remote, const char* device) +{ + rtems_debugger_remote_test* test; + + rtems_debugger_printf("error: rtems-db: test remote: begin\n"); + + rtems_debugger_lock(); + + /* + * Check the device. + */ + rtems_test_assert(strcmp(device, "something") == 0); + + test = malloc(sizeof(rtems_debugger_remote_test)); + rtems_test_assert(test != NULL); + + remote->data = test; + + test->connect_count = 0; + test->connected = false; + test->out = 0; + test->in = 0; + + rtems_debugger_unlock(); + + return 0; +} + +static int +test_remote_end(rtems_debugger_remote* remote) +{ + rtems_debugger_remote_test* test; + + rtems_debugger_printf("error: rtems-db: test remote: end\n"); + + rtems_debugger_lock(); + + rtems_test_assert(remote != NULL); + rtems_test_assert(remote->data != NULL); + test = (rtems_debugger_remote_test*) remote->data; + + test->connected = false; + + free(test); + + rtems_debugger_unlock(); + + return 0; +} + +static int +test_remote_connect(rtems_debugger_remote* remote) +{ + rtems_debugger_remote_test* test; + + rtems_test_assert(remote != NULL); + rtems_test_assert(remote->data != NULL); + test = (rtems_debugger_remote_test*) remote->data; + + if (test->connect_count > 0) { + rtems_event_set out = 0; + rtems_test_assert(rtems_event_receive(RTEMS_EVENT_1, + RTEMS_EVENT_ALL | RTEMS_WAIT, + RTEMS_NO_TIMEOUT, + &out) == RTEMS_SUCCESSFUL); + } + + rtems_debugger_printf("error: rtems-db: test remote: connect\n"); + + ++test->connect_count; + test->connected = true; + test->out = 0; + test->in = 0; + + return 0; +} + +static int +test_remote_disconnect(rtems_debugger_remote* remote) +{ + rtems_debugger_remote_test* test; + + rtems_test_assert(remote != NULL); + rtems_test_assert(remote->data != NULL); + test = (rtems_debugger_remote_test*) remote->data; + + rtems_debugger_printf("rtems-db: test remote: disconnect host\n"); + + rtems_debugger_lock(); + + rtems_test_assert(test->connected == true); + + test->connected = false; + + rtems_debugger_unlock(); + + return 0; +} + +static bool +test_remote_isconnected(rtems_debugger_remote* remote) +{ + rtems_debugger_remote_test* test; + bool isconnected; + rtems_test_assert(remote != NULL); + rtems_test_assert(remote->data != NULL); + test = (rtems_debugger_remote_test*) remote->data; + isconnected = test != NULL && test->connected; + rtems_debugger_printf("rtems-db: test remote: isconnected: %s\n", + isconnected ? "connected" : "not-connected"); + return isconnected; +} + +static void +test_remote_print(const char* label, const char* buf, size_t size) +{ + printf(" remote: %s: ", label); + while (size-- > 0) { + printf("%c", *buf++); + } + printf("\n"); +} + +static ssize_t +test_remote_receive(rtems_debugger_remote* remote, + void* buf, + size_t nbytes) +{ + rtems_debugger_remote_test* test; + size_t len; + rtems_test_assert(remote != NULL); + rtems_test_assert(remote->data != NULL); + test = (rtems_debugger_remote_test*) remote->data; + rtems_test_assert(test->out < RTEMS_DEBUGGER_NUMOF(out)); + len = strlen(out[test->out]); + printf(" remote: rx: message=%zu length=%zu\n", test->out, len); + test_remote_print("rx", out[test->out], len); + rtems_test_assert(len < nbytes); + memcpy(buf, out[test->out++], len); + return len; +} + +static ssize_t +test_remote_send(rtems_debugger_remote* remote, + const void* buf, + size_t nbytes) +{ + rtems_debugger_remote_test* test; + size_t len; + bool no_match; + rtems_test_assert(remote != NULL); + rtems_test_assert(remote->data != NULL); + test = (rtems_debugger_remote_test*) remote->data; + rtems_test_assert(test->in < RTEMS_DEBUGGER_NUMOF(in)); + len = strlen(in[test->in]); + no_match = len == 2 && strcmp(in[test->in], "**") == 0; + printf(" remote: tx: message=%zu length=%zu\n", test->in, len); + if (!no_match) + rtems_test_assert(len == nbytes); + test_remote_print("tx", buf, nbytes); + if (!no_match) + rtems_test_assert(memcmp(buf, in[test->in], nbytes) == 0); + test->in++; + return nbytes; +} + +static rtems_debugger_remote remote_test = +{ + .name = "test", + .begin = test_remote_begin, + .end = test_remote_end, + .connect = test_remote_connect, + .disconnect = test_remote_disconnect, + .isconnected = test_remote_isconnected, + .read = test_remote_receive, + .write = test_remote_send +}; + +int +rtems_debugger_register_test_remote(void) +{ + return rtems_debugger_remote_register(&remote_test); +} diff --git a/testsuites/libtests/debugger01/system.h b/testsuites/libtests/debugger01/system.h new file mode 100644 index 0000000000..c38283c33f --- /dev/null +++ b/testsuites/libtests/debugger01/system.h @@ -0,0 +1,37 @@ +/* system.h + * + * This include file contains information that is included in every + * function in the test set. + * + * COPYRIGHT (c) 1989-1999. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include <bsp.h> +#include <tmacros.h> + +/* functions */ + +rtems_task Init(rtems_task_argument argument); + +int rtems_debugger_register_test_remote(void); +void test_wake(void); + +/* configuration information */ + +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER + +#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 +#define CONFIGURE_MAXIMUM_TASKS 10 +#define CONFIGURE_MAXIMUM_SEMAPHORES 10 + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#include <rtems/confdefs.h> + +/* end of include file */ |