2 * kgdbts is a test suite for kgdb for the sole purpose of validating
3 * that key pieces of the kgdb internals are working properly such as
4 * HW/SW breakpoints, single stepping, and NMI.
6 * Created by: Jason Wessel <jason.wessel@windriver.com>
8 * Copyright (c) 2008 Wind River Systems, Inc.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 /* Information about the kgdb test suite.
24 * -------------------------------------
26 * The kgdb test suite is designed as a KGDB I/O module which
27 * simulates the communications that a debugger would have with kgdb.
28 * The tests are broken up in to a line by line and referenced here as
29 * a "get" which is kgdb requesting input and "put" which is kgdb
32 * The kgdb suite can be invoked from the kernel command line
33 * arguments system or executed dynamically at run time. The test
34 * suite uses the variable "kgdbts" to obtain the information about
35 * which tests to run and to configure the verbosity level. The
36 * following are the various characters you can use with the kgdbts=
39 * When using the "kgdbts=" you only choose one of the following core
41 * A = Run all the core tests silently
42 * V1 = Run all the core tests with minimal output
43 * V2 = Run all the core tests in debug mode
45 * You can also specify optional tests:
46 * N## = Go to sleep with interrupts of for ## seconds
47 * to test the HW NMI watchdog
48 * F## = Break at do_fork for ## iterations
49 * S## = Break at sys_open for ## iterations
51 * NOTE: that the do_fork and sys_open tests are mutually exclusive.
53 * To invoke the kgdb test suite from boot you use a kernel start
54 * argument as follows:
56 * Or if you wanted to perform the NMI test for 6 seconds and do_fork
57 * test for 100 forks, you could use:
58 * kgdbts=V1N6F100 kgdbwait
60 * The test suite can also be invoked at run time with:
61 * echo kgdbts=V1N6F100 > /sys/module/kgdbts/parameters/kgdbts
62 * Or as another example:
63 * echo kgdbts=V2 > /sys/module/kgdbts/parameters/kgdbts
65 * When developing a new kgdb arch specific implementation or
66 * using these tests for the purpose of regression testing,
67 * several invocations are required.
69 * 1) Boot with the test suite enabled by using the kernel arguments
70 * "kgdbts=V1F100 kgdbwait"
71 * ## If kgdb arch specific implementation has NMI use
74 * 2) After the system boot run the basic test.
75 * echo kgdbts=V1 > /sys/module/kgdbts/parameters/kgdbts
77 * 3) Run the concurrency tests. It is best to use n+1
78 * while loops where n is the number of cpus you have
79 * in your system. The example below uses only two
82 * ## This tests break points on sys_open
83 * while [ 1 ] ; do find / > /dev/null 2>&1 ; done &
84 * while [ 1 ] ; do find / > /dev/null 2>&1 ; done &
85 * echo kgdbts=V1S10000 > /sys/module/kgdbts/parameters/kgdbts
86 * fg # and hit control-c
87 * fg # and hit control-c
88 * ## This tests break points on do_fork
89 * while [ 1 ] ; do date > /dev/null ; done &
90 * while [ 1 ] ; do date > /dev/null ; done &
91 * echo kgdbts=V1F1000 > /sys/module/kgdbts/parameters/kgdbts
92 * fg # and hit control-c
96 #include <linux/kernel.h>
97 #include <linux/kgdb.h>
98 #include <linux/ctype.h>
99 #include <linux/uaccess.h>
100 #include <linux/syscalls.h>
101 #include <linux/nmi.h>
102 #include <linux/delay.h>
103 #include <linux/kthread.h>
104 #include <linux/delay.h>
106 #define v1printk(a...) do { \
108 printk(KERN_INFO a); \
110 #define v2printk(a...) do { \
112 printk(KERN_INFO a); \
113 touch_nmi_watchdog(); \
115 #define MAX_CONFIG_LEN 40
117 static const char hexchars[] = "0123456789abcdef";
118 static struct kgdb_io kgdbts_io_ops;
119 static char get_buf[BUFMAX];
120 static int get_buf_cnt;
121 static char put_buf[BUFMAX];
122 static int put_buf_cnt;
123 static char scratch_buf[BUFMAX];
125 static int repeat_test;
126 static int test_complete;
128 static int final_ack;
129 static int hw_break_val;
130 static int hw_break_val2;
131 #if defined(CONFIG_ARM) || defined(CONFIG_MIPS)
132 static int arch_needs_sstep_emulation = 1;
134 static int arch_needs_sstep_emulation;
136 static unsigned long sstep_addr;
137 static int sstep_state;
139 /* Storage for the registers, in GDB format. */
140 static unsigned long kgdbts_gdb_regs[(NUMREGBYTES +
141 sizeof(unsigned long) - 1) /
142 sizeof(unsigned long)];
143 static struct pt_regs kgdbts_regs;
145 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
146 static int configured = -1;
148 static char config[MAX_CONFIG_LEN];
149 static struct kparam_string kps = {
151 .maxlen = MAX_CONFIG_LEN,
154 static void fill_get_buf(char *buf);
159 void (*get_handler)(char *);
160 int (*put_handler)(char *, char *);
165 struct test_struct *tst;
167 int (*run_test) (int, int);
168 int (*validate_put) (char *);
171 static struct test_state ts;
173 static int kgdbts_unreg_thread(void *ptr)
175 /* Wait until the tests are complete and then ungresiter the I/O
179 msleep_interruptible(1500);
182 kgdb_unregister_io_module(&kgdbts_io_ops);
188 /* This is noinline such that it can be used for a single location to
191 static noinline void kgdbts_break_test(void)
193 v2printk("kgdbts: breakpoint complete\n");
196 /* Lookup symbol info in the kernel */
197 static unsigned long lookup_addr(char *arg)
199 unsigned long addr = 0;
201 if (!strcmp(arg, "kgdbts_break_test"))
202 addr = (unsigned long)kgdbts_break_test;
203 else if (!strcmp(arg, "sys_open"))
204 addr = (unsigned long)sys_open;
205 else if (!strcmp(arg, "do_fork"))
206 addr = (unsigned long)do_fork;
207 else if (!strcmp(arg, "hw_break_val"))
208 addr = (unsigned long)&hw_break_val;
212 static void break_helper(char *bp_type, char *arg, unsigned long vaddr)
217 addr = lookup_addr(arg);
221 sprintf(scratch_buf, "%s,%lx,%i", bp_type, addr,
223 fill_get_buf(scratch_buf);
226 static void sw_break(char *arg)
228 break_helper("Z0", arg, 0);
231 static void sw_rem_break(char *arg)
233 break_helper("z0", arg, 0);
236 static void hw_break(char *arg)
238 break_helper("Z1", arg, 0);
241 static void hw_rem_break(char *arg)
243 break_helper("z1", arg, 0);
246 static void hw_write_break(char *arg)
248 break_helper("Z2", arg, 0);
251 static void hw_rem_write_break(char *arg)
253 break_helper("z2", arg, 0);
256 static void hw_access_break(char *arg)
258 break_helper("Z4", arg, 0);
261 static void hw_rem_access_break(char *arg)
263 break_helper("z4", arg, 0);
266 static void hw_break_val_access(void)
268 hw_break_val2 = hw_break_val;
271 static void hw_break_val_write(void)
276 static int check_and_rewind_pc(char *put_str, char *arg)
278 unsigned long addr = lookup_addr(arg);
281 kgdb_hex2mem(&put_str[1], (char *)kgdbts_gdb_regs,
283 gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs);
284 v2printk("Stopped at IP: %lx\n", instruction_pointer(&kgdbts_regs));
286 /* On x86 a breakpoint stop requires it to be decremented */
287 if (addr + 1 == kgdbts_regs.ip)
290 if (strcmp(arg, "silent") &&
291 instruction_pointer(&kgdbts_regs) + offset != addr) {
292 printk(KERN_ERR "kgdbts: BP mismatch %lx expected %lx\n",
293 instruction_pointer(&kgdbts_regs) + offset, addr);
297 /* On x86 adjust the instruction pointer if needed */
298 kgdbts_regs.ip += offset;
303 static int check_single_step(char *put_str, char *arg)
305 unsigned long addr = lookup_addr(arg);
307 * From an arch indepent point of view the instruction pointer
308 * should be on a different instruction
310 kgdb_hex2mem(&put_str[1], (char *)kgdbts_gdb_regs,
312 gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs);
313 v2printk("Singlestep stopped at IP: %lx\n",
314 instruction_pointer(&kgdbts_regs));
315 if (instruction_pointer(&kgdbts_regs) == addr) {
316 printk(KERN_ERR "kgdbts: SingleStep failed at %lx\n",
317 instruction_pointer(&kgdbts_regs));
324 static void write_regs(char *arg)
326 memset(scratch_buf, 0, sizeof(scratch_buf));
327 scratch_buf[0] = 'G';
328 pt_regs_to_gdb_regs(kgdbts_gdb_regs, &kgdbts_regs);
329 kgdb_mem2hex((char *)kgdbts_gdb_regs, &scratch_buf[1], NUMREGBYTES);
330 fill_get_buf(scratch_buf);
333 static void skip_back_repeat_test(char *arg)
335 int go_back = simple_strtol(arg, NULL, 10);
338 if (repeat_test <= 0)
342 fill_get_buf(ts.tst[ts.idx].get);
345 static int got_break(char *put_str, char *arg)
348 if (!strncmp(put_str+1, arg, 2)) {
349 if (!strncmp(arg, "T0", 2))
356 static void emul_sstep_get(char *arg)
358 if (!arch_needs_sstep_emulation) {
362 switch (sstep_state) {
364 v2printk("Emulate single step\n");
365 /* Start by looking at the current PC */
370 break_helper("Z0", 0, sstep_addr);
377 /* Clear breakpoint */
378 break_helper("z0", 0, sstep_addr);
381 printk(KERN_ERR "kgdbts: ERROR failed sstep get emulation\n");
386 static int emul_sstep_put(char *put_str, char *arg)
388 if (!arch_needs_sstep_emulation) {
389 if (!strncmp(put_str+1, arg, 2))
393 switch (sstep_state) {
395 /* validate the "g" packet to get the IP */
396 kgdb_hex2mem(&put_str[1], (char *)kgdbts_gdb_regs,
398 gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs);
399 v2printk("Stopped at IP: %lx\n",
400 instruction_pointer(&kgdbts_regs));
401 /* Want to stop at IP + break instruction size by default */
402 sstep_addr = instruction_pointer(&kgdbts_regs) +
406 if (strncmp(put_str, "$OK", 3)) {
407 printk(KERN_ERR "kgdbts: failed sstep break set\n");
412 if (strncmp(put_str, "$T0", 3)) {
413 printk(KERN_ERR "kgdbts: failed continue sstep\n");
418 if (strncmp(put_str, "$OK", 3)) {
419 printk(KERN_ERR "kgdbts: failed sstep break unset\n");
422 /* Single step is complete so continue on! */
426 printk(KERN_ERR "kgdbts: ERROR failed sstep put emulation\n");
429 /* Continue on the same test line until emulation is complete */
434 static int final_ack_set(char *put_str, char *arg)
436 if (strncmp(put_str+1, arg, 2))
442 * Test to plant a breakpoint and detach, which should clear out the
443 * breakpoint and restore the original instruction.
445 static struct test_struct plant_and_detach_test[] = {
446 { "?", "S0*" }, /* Clear break points */
447 { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */
448 { "D", "OK" }, /* Detach */
453 * Simple test to write in a software breakpoint, check for the
454 * correct stop location and detach.
456 static struct test_struct sw_breakpoint_test[] = {
457 { "?", "S0*" }, /* Clear break points */
458 { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */
459 { "c", "T0*", }, /* Continue */
460 { "g", "kgdbts_break_test", 0, check_and_rewind_pc },
461 { "write", "OK", write_regs },
462 { "kgdbts_break_test", "OK", sw_rem_break }, /*remove breakpoint */
463 { "D", "OK" }, /* Detach */
464 { "D", "OK", 0, got_break }, /* If the test worked we made it here */
469 * Test a known bad memory read location to test the fault handler and
470 * read bytes 1-8 at the bad address
472 static struct test_struct bad_read_test[] = {
473 { "?", "S0*" }, /* Clear break points */
474 { "m0,1", "E*" }, /* read 1 byte at address 1 */
475 { "m0,2", "E*" }, /* read 1 byte at address 2 */
476 { "m0,3", "E*" }, /* read 1 byte at address 3 */
477 { "m0,4", "E*" }, /* read 1 byte at address 4 */
478 { "m0,5", "E*" }, /* read 1 byte at address 5 */
479 { "m0,6", "E*" }, /* read 1 byte at address 6 */
480 { "m0,7", "E*" }, /* read 1 byte at address 7 */
481 { "m0,8", "E*" }, /* read 1 byte at address 8 */
482 { "D", "OK" }, /* Detach which removes all breakpoints and continues */
487 * Test for hitting a breakpoint, remove it, single step, plant it
490 static struct test_struct singlestep_break_test[] = {
491 { "?", "S0*" }, /* Clear break points */
492 { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */
493 { "c", "T0*", }, /* Continue */
494 { "g", "kgdbts_break_test", 0, check_and_rewind_pc },
495 { "write", "OK", write_regs }, /* Write registers */
496 { "kgdbts_break_test", "OK", sw_rem_break }, /*remove breakpoint */
497 { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */
498 { "g", "kgdbts_break_test", 0, check_single_step },
499 { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */
500 { "c", "T0*", }, /* Continue */
501 { "g", "kgdbts_break_test", 0, check_and_rewind_pc },
502 { "write", "OK", write_regs }, /* Write registers */
503 { "D", "OK" }, /* Remove all breakpoints and continues */
508 * Test for hitting a breakpoint at do_fork for what ever the number
509 * of iterations required by the variable repeat_test.
511 static struct test_struct do_fork_test[] = {
512 { "?", "S0*" }, /* Clear break points */
513 { "do_fork", "OK", sw_break, }, /* set sw breakpoint */
514 { "c", "T0*", }, /* Continue */
515 { "g", "do_fork", 0, check_and_rewind_pc }, /* check location */
516 { "write", "OK", write_regs }, /* Write registers */
517 { "do_fork", "OK", sw_rem_break }, /*remove breakpoint */
518 { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */
519 { "g", "do_fork", 0, check_single_step },
520 { "do_fork", "OK", sw_break, }, /* set sw breakpoint */
521 { "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */
522 { "D", "OK", 0, final_ack_set }, /* detach and unregister I/O */
526 /* Test for hitting a breakpoint at sys_open for what ever the number
527 * of iterations required by the variable repeat_test.
529 static struct test_struct sys_open_test[] = {
530 { "?", "S0*" }, /* Clear break points */
531 { "sys_open", "OK", sw_break, }, /* set sw breakpoint */
532 { "c", "T0*", }, /* Continue */
533 { "g", "sys_open", 0, check_and_rewind_pc }, /* check location */
534 { "write", "OK", write_regs }, /* Write registers */
535 { "sys_open", "OK", sw_rem_break }, /*remove breakpoint */
536 { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */
537 { "g", "sys_open", 0, check_single_step },
538 { "sys_open", "OK", sw_break, }, /* set sw breakpoint */
539 { "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */
540 { "D", "OK", 0, final_ack_set }, /* detach and unregister I/O */
545 * Test for hitting a simple hw breakpoint
547 static struct test_struct hw_breakpoint_test[] = {
548 { "?", "S0*" }, /* Clear break points */
549 { "kgdbts_break_test", "OK", hw_break, }, /* set hw breakpoint */
550 { "c", "T0*", }, /* Continue */
551 { "g", "kgdbts_break_test", 0, check_and_rewind_pc },
552 { "write", "OK", write_regs },
553 { "kgdbts_break_test", "OK", hw_rem_break }, /*remove breakpoint */
554 { "D", "OK" }, /* Detach */
555 { "D", "OK", 0, got_break }, /* If the test worked we made it here */
560 * Test for hitting a hw write breakpoint
562 static struct test_struct hw_write_break_test[] = {
563 { "?", "S0*" }, /* Clear break points */
564 { "hw_break_val", "OK", hw_write_break, }, /* set hw breakpoint */
565 { "c", "T0*", 0, got_break }, /* Continue */
566 { "g", "silent", 0, check_and_rewind_pc },
567 { "write", "OK", write_regs },
568 { "hw_break_val", "OK", hw_rem_write_break }, /*remove breakpoint */
569 { "D", "OK" }, /* Detach */
570 { "D", "OK", 0, got_break }, /* If the test worked we made it here */
575 * Test for hitting a hw access breakpoint
577 static struct test_struct hw_access_break_test[] = {
578 { "?", "S0*" }, /* Clear break points */
579 { "hw_break_val", "OK", hw_access_break, }, /* set hw breakpoint */
580 { "c", "T0*", 0, got_break }, /* Continue */
581 { "g", "silent", 0, check_and_rewind_pc },
582 { "write", "OK", write_regs },
583 { "hw_break_val", "OK", hw_rem_access_break }, /*remove breakpoint */
584 { "D", "OK" }, /* Detach */
585 { "D", "OK", 0, got_break }, /* If the test worked we made it here */
590 * Test for hitting a hw access breakpoint
592 static struct test_struct nmi_sleep_test[] = {
593 { "?", "S0*" }, /* Clear break points */
594 { "c", "T0*", 0, got_break }, /* Continue */
595 { "D", "OK" }, /* Detach */
596 { "D", "OK", 0, got_break }, /* If the test worked we made it here */
600 static void fill_get_buf(char *buf)
602 unsigned char checksum = 0;
606 strcpy(get_buf, "$");
607 strcat(get_buf, buf);
608 while ((ch = buf[count])) {
612 strcat(get_buf, "#");
613 get_buf[count + 2] = hexchars[checksum >> 4];
614 get_buf[count + 3] = hexchars[checksum & 0xf];
615 get_buf[count + 4] = '\0';
616 v2printk("get%i: %s\n", ts.idx, get_buf);
619 static int validate_simple_test(char *put_str)
623 if (ts.tst[ts.idx].put_handler)
624 return ts.tst[ts.idx].put_handler(put_str,
627 chk_str = ts.tst[ts.idx].put;
631 while (*chk_str != '\0' && *put_str != '\0') {
632 /* If someone does a * to match the rest of the string, allow
633 * it, or stop if the recieved string is complete.
635 if (*put_str == '#' || *chk_str == '*')
637 if (*put_str != *chk_str)
643 if (*chk_str == '\0' && (*put_str == '\0' || *put_str == '#'))
649 static int run_simple_test(int is_get_char, int chr)
653 /* Send an ACK on the get if a prior put completed and set the
660 /* On the first get char, fill the transmit buffer and then
661 * take from the get_string.
663 if (get_buf_cnt == 0) {
664 if (ts.tst[ts.idx].get_handler)
665 ts.tst[ts.idx].get_handler(ts.tst[ts.idx].get);
667 fill_get_buf(ts.tst[ts.idx].get);
670 if (get_buf[get_buf_cnt] == '\0') {
672 "kgdbts: ERROR GET: end of buffer on '%s' at %i\n",
677 ret = get_buf[get_buf_cnt];
682 /* This callback is a put char which is when kgdb sends data to
685 if (ts.tst[ts.idx].get[0] == '\0' &&
686 ts.tst[ts.idx].put[0] == '\0') {
687 printk(KERN_ERR "kgdbts: ERROR: beyond end of test on"
688 " '%s' line %i\n", ts.name, ts.idx);
692 if (put_buf_cnt >= BUFMAX) {
693 printk(KERN_ERR "kgdbts: ERROR: put buffer overflow on"
694 " '%s' line %i\n", ts.name, ts.idx);
698 /* Ignore everything until the first valid packet start '$' */
699 if (put_buf_cnt == 0 && chr != '$')
702 put_buf[put_buf_cnt] = chr;
705 /* End of packet == #XX so look for the '#' */
706 if (put_buf_cnt > 3 && put_buf[put_buf_cnt - 3] == '#') {
707 put_buf[put_buf_cnt] = '\0';
708 v2printk("put%i: %s\n", ts.idx, put_buf);
709 /* Trigger check here */
710 if (ts.validate_put && ts.validate_put(put_buf)) {
711 printk(KERN_ERR "kgdbts: ERROR PUT: end of test "
712 "buffer on '%s' line %i expected %s got %s\n",
713 ts.name, ts.idx, ts.tst[ts.idx].put, put_buf);
723 static void init_simple_test(void)
725 memset(&ts, 0, sizeof(ts));
726 ts.run_test = run_simple_test;
727 ts.validate_put = validate_simple_test;
730 static void run_plant_and_detach_test(int is_early)
732 char before[BREAK_INSTR_SIZE];
733 char after[BREAK_INSTR_SIZE];
735 probe_kernel_read(before, (char *)kgdbts_break_test,
738 ts.tst = plant_and_detach_test;
739 ts.name = "plant_and_detach_test";
740 /* Activate test with initial breakpoint */
743 probe_kernel_read(after, (char *)kgdbts_break_test,
745 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
746 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
747 panic("kgdb memory corruption");
750 /* complete the detach test */
755 static void run_breakpoint_test(int is_hw_breakpoint)
759 if (is_hw_breakpoint) {
760 ts.tst = hw_breakpoint_test;
761 ts.name = "hw_breakpoint_test";
763 ts.tst = sw_breakpoint_test;
764 ts.name = "sw_breakpoint_test";
766 /* Activate test with initial breakpoint */
768 /* run code with the break point in it */
775 printk(KERN_ERR "kgdbts: ERROR %s test failed\n", ts.name);
778 static void run_hw_break_test(int is_write_test)
783 ts.tst = hw_write_break_test;
784 ts.name = "hw_write_break_test";
786 ts.tst = hw_access_break_test;
787 ts.name = "hw_access_break_test";
789 /* Activate test with initial breakpoint */
791 hw_break_val_access();
793 if (test_complete == 2)
794 printk(KERN_ERR "kgdbts: ERROR %s broke on access\n",
796 hw_break_val_write();
800 if (test_complete == 1)
803 printk(KERN_ERR "kgdbts: ERROR %s test failed\n", ts.name);
806 static void run_nmi_sleep_test(int nmi_sleep)
811 ts.tst = nmi_sleep_test;
812 ts.name = "nmi_sleep_test";
813 /* Activate test with initial breakpoint */
815 local_irq_save(flags);
816 mdelay(nmi_sleep*1000);
817 touch_nmi_watchdog();
818 local_irq_restore(flags);
819 if (test_complete != 2)
820 printk(KERN_ERR "kgdbts: ERROR nmi_test did not hit nmi\n");
822 if (test_complete == 1)
825 printk(KERN_ERR "kgdbts: ERROR %s test failed\n", ts.name);
828 static void run_bad_read_test(void)
831 ts.tst = bad_read_test;
832 ts.name = "bad_read_test";
833 /* Activate test with initial breakpoint */
837 static void run_do_fork_test(void)
840 ts.tst = do_fork_test;
841 ts.name = "do_fork_test";
842 /* Activate test with initial breakpoint */
846 static void run_sys_open_test(void)
849 ts.tst = sys_open_test;
850 ts.name = "sys_open_test";
851 /* Activate test with initial breakpoint */
855 static void run_singlestep_break_test(void)
858 ts.tst = singlestep_break_test;
859 ts.name = "singlestep_breakpoint_test";
860 /* Activate test with initial breakpoint */
866 static void kgdbts_run_tests(void)
870 int sys_open_test = 0;
873 ptr = strstr(config, "F");
875 fork_test = simple_strtol(ptr+1, NULL, 10);
876 ptr = strstr(config, "S");
878 sys_open_test = simple_strtol(ptr+1, NULL, 10);
879 ptr = strstr(config, "N");
881 nmi_sleep = simple_strtol(ptr+1, NULL, 10);
883 /* required internal KGDB tests */
884 v1printk("kgdbts:RUN plant and detach test\n");
885 run_plant_and_detach_test(0);
886 v1printk("kgdbts:RUN sw breakpoint test\n");
887 run_breakpoint_test(0);
888 v1printk("kgdbts:RUN bad memory access test\n");
890 v1printk("kgdbts:RUN singlestep breakpoint test\n");
891 run_singlestep_break_test();
893 /* ===Optional tests=== */
895 /* All HW break point tests */
896 if (arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT) {
897 v1printk("kgdbts:RUN hw breakpoint test\n");
898 run_breakpoint_test(1);
899 v1printk("kgdbts:RUN hw write breakpoint test\n");
900 run_hw_break_test(1);
901 v1printk("kgdbts:RUN access write breakpoint test\n");
902 run_hw_break_test(0);
906 v1printk("kgdbts:RUN NMI sleep %i seconds test\n", nmi_sleep);
907 run_nmi_sleep_test(nmi_sleep);
910 /* If the do_fork test is run it will be the last test that is
911 * executed because a kernel thread will be spawned at the very
912 * end to unregister the debug hooks.
915 repeat_test = fork_test;
916 printk(KERN_INFO "kgdbts:RUN do_fork for %i breakpoints\n",
918 kthread_run(kgdbts_unreg_thread, 0, "kgdbts_unreg");
923 /* If the sys_open test is run it will be the last test that is
924 * executed because a kernel thread will be spawned at the very
925 * end to unregister the debug hooks.
928 repeat_test = sys_open_test;
929 printk(KERN_INFO "kgdbts:RUN sys_open for %i breakpoints\n",
931 kthread_run(kgdbts_unreg_thread, 0, "kgdbts_unreg");
935 /* Shutdown and unregister */
936 kgdb_unregister_io_module(&kgdbts_io_ops);
940 static int kgdbts_option_setup(char *opt)
942 if (strlen(opt) > MAX_CONFIG_LEN) {
943 printk(KERN_ERR "kgdbts: config string too long\n");
949 if (strstr(config, "V1"))
951 if (strstr(config, "V2"))
957 __setup("kgdbts=", kgdbts_option_setup);
959 static int configure_kgdbts(void)
963 if (!strlen(config) || isspace(config[0]))
965 err = kgdbts_option_setup(config);
970 run_plant_and_detach_test(1);
972 err = kgdb_register_io_module(&kgdbts_io_ops);
989 static int __init init_kgdbts(void)
991 /* Already configured? */
995 return configure_kgdbts();
998 static void cleanup_kgdbts(void)
1000 if (configured == 1)
1001 kgdb_unregister_io_module(&kgdbts_io_ops);
1004 static int kgdbts_get_char(void)
1009 val = ts.run_test(1, 0);
1014 static void kgdbts_put_char(u8 chr)
1017 ts.run_test(0, chr);
1020 static int param_set_kgdbts_var(const char *kmessage, struct kernel_param *kp)
1022 int len = strlen(kmessage);
1024 if (len >= MAX_CONFIG_LEN) {
1025 printk(KERN_ERR "kgdbts: config string too long\n");
1029 /* Only copy in the string if the init function has not run yet */
1030 if (configured < 0) {
1031 strcpy(config, kmessage);
1035 if (kgdb_connected) {
1037 "kgdbts: Cannot reconfigure while KGDB is connected.\n");
1042 strcpy(config, kmessage);
1043 /* Chop out \n char as a result of echo */
1044 if (config[len - 1] == '\n')
1045 config[len - 1] = '\0';
1047 if (configured == 1)
1050 /* Go and configure with the new params. */
1051 return configure_kgdbts();
1054 static void kgdbts_pre_exp_handler(void)
1056 /* Increment the module count when the debugger is active */
1057 if (!kgdb_connected)
1058 try_module_get(THIS_MODULE);
1061 static void kgdbts_post_exp_handler(void)
1063 /* decrement the module count when the debugger detaches */
1064 if (!kgdb_connected)
1065 module_put(THIS_MODULE);
1068 static struct kgdb_io kgdbts_io_ops = {
1070 .read_char = kgdbts_get_char,
1071 .write_char = kgdbts_put_char,
1072 .pre_exception = kgdbts_pre_exp_handler,
1073 .post_exception = kgdbts_post_exp_handler,
1076 module_init(init_kgdbts);
1077 module_exit(cleanup_kgdbts);
1078 module_param_call(kgdbts, param_set_kgdbts_var, param_get_string, &kps, 0644);
1079 MODULE_PARM_DESC(kgdbts, "<A|V1|V2>[F#|S#][N#]");
1080 MODULE_DESCRIPTION("KGDB Test Suite");
1081 MODULE_LICENSE("GPL");
1082 MODULE_AUTHOR("Wind River Systems, Inc.");