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
50 * I## = Run the single step test ## iterations
52 * NOTE: that the do_fork and sys_open tests are mutually exclusive.
54 * To invoke the kgdb test suite from boot you use a kernel start
55 * argument as follows:
57 * Or if you wanted to perform the NMI test for 6 seconds and do_fork
58 * test for 100 forks, you could use:
59 * kgdbts=V1N6F100 kgdbwait
61 * The test suite can also be invoked at run time with:
62 * echo kgdbts=V1N6F100 > /sys/module/kgdbts/parameters/kgdbts
63 * Or as another example:
64 * echo kgdbts=V2 > /sys/module/kgdbts/parameters/kgdbts
66 * When developing a new kgdb arch specific implementation or
67 * using these tests for the purpose of regression testing,
68 * several invocations are required.
70 * 1) Boot with the test suite enabled by using the kernel arguments
71 * "kgdbts=V1F100 kgdbwait"
72 * ## If kgdb arch specific implementation has NMI use
75 * 2) After the system boot run the basic test.
76 * echo kgdbts=V1 > /sys/module/kgdbts/parameters/kgdbts
78 * 3) Run the concurrency tests. It is best to use n+1
79 * while loops where n is the number of cpus you have
80 * in your system. The example below uses only two
83 * ## This tests break points on sys_open
84 * while [ 1 ] ; do find / > /dev/null 2>&1 ; done &
85 * while [ 1 ] ; do find / > /dev/null 2>&1 ; done &
86 * echo kgdbts=V1S10000 > /sys/module/kgdbts/parameters/kgdbts
87 * fg # and hit control-c
88 * fg # and hit control-c
89 * ## This tests break points on do_fork
90 * while [ 1 ] ; do date > /dev/null ; done &
91 * while [ 1 ] ; do date > /dev/null ; done &
92 * echo kgdbts=V1F1000 > /sys/module/kgdbts/parameters/kgdbts
93 * fg # and hit control-c
97 #include <linux/kernel.h>
98 #include <linux/kgdb.h>
99 #include <linux/ctype.h>
100 #include <linux/uaccess.h>
101 #include <linux/syscalls.h>
102 #include <linux/nmi.h>
103 #include <linux/delay.h>
104 #include <linux/kthread.h>
105 #include <linux/module.h>
107 #define v1printk(a...) do { \
109 printk(KERN_INFO a); \
111 #define v2printk(a...) do { \
113 printk(KERN_INFO a); \
114 touch_nmi_watchdog(); \
116 #define eprintk(a...) do { \
117 printk(KERN_ERR a); \
120 #define MAX_CONFIG_LEN 40
122 static struct kgdb_io kgdbts_io_ops
;
123 static char get_buf
[BUFMAX
];
124 static int get_buf_cnt
;
125 static char put_buf
[BUFMAX
];
126 static int put_buf_cnt
;
127 static char scratch_buf
[BUFMAX
];
129 static int repeat_test
;
130 static int test_complete
;
132 static int final_ack
;
133 static int force_hwbrks
;
134 static int hwbreaks_ok
;
135 static int hw_break_val
;
136 static int hw_break_val2
;
137 static int cont_instead_of_sstep
;
138 static unsigned long cont_thread_id
;
139 static unsigned long sstep_thread_id
;
140 #if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || defined(CONFIG_SPARC)
141 static int arch_needs_sstep_emulation
= 1;
143 static int arch_needs_sstep_emulation
;
145 static unsigned long sstep_addr
;
146 static int sstep_state
;
148 /* Storage for the registers, in GDB format. */
149 static unsigned long kgdbts_gdb_regs
[(NUMREGBYTES
+
150 sizeof(unsigned long) - 1) /
151 sizeof(unsigned long)];
152 static struct pt_regs kgdbts_regs
;
154 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
155 static int configured
= -1;
157 #ifdef CONFIG_KGDB_TESTS_BOOT_STRING
158 static char config
[MAX_CONFIG_LEN
] = CONFIG_KGDB_TESTS_BOOT_STRING
;
160 static char config
[MAX_CONFIG_LEN
];
162 static struct kparam_string kps
= {
164 .maxlen
= MAX_CONFIG_LEN
,
167 static void fill_get_buf(char *buf
);
172 void (*get_handler
)(char *);
173 int (*put_handler
)(char *, char *);
178 struct test_struct
*tst
;
180 int (*run_test
) (int, int);
181 int (*validate_put
) (char *);
184 static struct test_state ts
;
186 static int kgdbts_unreg_thread(void *ptr
)
188 /* Wait until the tests are complete and then ungresiter the I/O
192 msleep_interruptible(1500);
195 kgdb_unregister_io_module(&kgdbts_io_ops
);
201 /* This is noinline such that it can be used for a single location to
204 static noinline
void kgdbts_break_test(void)
206 v2printk("kgdbts: breakpoint complete\n");
209 /* Lookup symbol info in the kernel */
210 static unsigned long lookup_addr(char *arg
)
212 unsigned long addr
= 0;
214 if (!strcmp(arg
, "kgdbts_break_test"))
215 addr
= (unsigned long)kgdbts_break_test
;
216 else if (!strcmp(arg
, "sys_open"))
217 addr
= (unsigned long)do_sys_open
;
218 else if (!strcmp(arg
, "do_fork"))
219 addr
= (unsigned long)do_fork
;
220 else if (!strcmp(arg
, "hw_break_val"))
221 addr
= (unsigned long)&hw_break_val
;
225 static void break_helper(char *bp_type
, char *arg
, unsigned long vaddr
)
230 addr
= lookup_addr(arg
);
234 sprintf(scratch_buf
, "%s,%lx,%i", bp_type
, addr
,
236 fill_get_buf(scratch_buf
);
239 static void sw_break(char *arg
)
241 break_helper(force_hwbrks
? "Z1" : "Z0", arg
, 0);
244 static void sw_rem_break(char *arg
)
246 break_helper(force_hwbrks
? "z1" : "z0", arg
, 0);
249 static void hw_break(char *arg
)
251 break_helper("Z1", arg
, 0);
254 static void hw_rem_break(char *arg
)
256 break_helper("z1", arg
, 0);
259 static void hw_write_break(char *arg
)
261 break_helper("Z2", arg
, 0);
264 static void hw_rem_write_break(char *arg
)
266 break_helper("z2", arg
, 0);
269 static void hw_access_break(char *arg
)
271 break_helper("Z4", arg
, 0);
274 static void hw_rem_access_break(char *arg
)
276 break_helper("z4", arg
, 0);
279 static void hw_break_val_access(void)
281 hw_break_val2
= hw_break_val
;
284 static void hw_break_val_write(void)
289 static int get_thread_id_continue(char *put_str
, char *arg
)
291 char *ptr
= &put_str
[11];
293 if (put_str
[1] != 'T' || put_str
[2] != '0')
295 kgdb_hex2long(&ptr
, &cont_thread_id
);
299 static int check_and_rewind_pc(char *put_str
, char *arg
)
301 unsigned long addr
= lookup_addr(arg
);
305 kgdb_hex2mem(&put_str
[1], (char *)kgdbts_gdb_regs
,
307 gdb_regs_to_pt_regs(kgdbts_gdb_regs
, &kgdbts_regs
);
308 ip
= instruction_pointer(&kgdbts_regs
);
309 v2printk("Stopped at IP: %lx\n", ip
);
310 #ifdef GDB_ADJUSTS_BREAK_OFFSET
311 /* On some arches, a breakpoint stop requires it to be decremented */
312 if (addr
+ BREAK_INSTR_SIZE
== ip
)
313 offset
= -BREAK_INSTR_SIZE
;
315 if (strcmp(arg
, "silent") && ip
+ offset
!= addr
) {
316 eprintk("kgdbts: BP mismatch %lx expected %lx\n",
320 /* Readjust the instruction pointer if needed */
322 #ifdef GDB_ADJUSTS_BREAK_OFFSET
323 instruction_pointer_set(&kgdbts_regs
, ip
);
328 static int check_single_step(char *put_str
, char *arg
)
330 unsigned long addr
= lookup_addr(arg
);
332 * From an arch indepent point of view the instruction pointer
333 * should be on a different instruction
335 kgdb_hex2mem(&put_str
[1], (char *)kgdbts_gdb_regs
,
337 gdb_regs_to_pt_regs(kgdbts_gdb_regs
, &kgdbts_regs
);
338 v2printk("Singlestep stopped at IP: %lx\n",
339 instruction_pointer(&kgdbts_regs
));
341 if (sstep_thread_id
!= cont_thread_id
&& !arch_needs_sstep_emulation
) {
343 * Ensure we stopped in the same thread id as before, else the
344 * debugger should continue until the original thread that was
345 * single stepped is scheduled again, emulating gdb's behavior.
347 v2printk("ThrID does not match: %lx\n", cont_thread_id
);
348 cont_instead_of_sstep
= 1;
352 if (instruction_pointer(&kgdbts_regs
) == addr
) {
353 eprintk("kgdbts: SingleStep failed at %lx\n",
354 instruction_pointer(&kgdbts_regs
));
361 static void write_regs(char *arg
)
363 memset(scratch_buf
, 0, sizeof(scratch_buf
));
364 scratch_buf
[0] = 'G';
365 pt_regs_to_gdb_regs(kgdbts_gdb_regs
, &kgdbts_regs
);
366 kgdb_mem2hex((char *)kgdbts_gdb_regs
, &scratch_buf
[1], NUMREGBYTES
);
367 fill_get_buf(scratch_buf
);
370 static void skip_back_repeat_test(char *arg
)
372 int go_back
= simple_strtol(arg
, NULL
, 10);
375 if (repeat_test
<= 0)
379 fill_get_buf(ts
.tst
[ts
.idx
].get
);
382 static int got_break(char *put_str
, char *arg
)
385 if (!strncmp(put_str
+1, arg
, 2)) {
386 if (!strncmp(arg
, "T0", 2))
393 static void emul_sstep_get(char *arg
)
395 if (!arch_needs_sstep_emulation
) {
396 if (cont_instead_of_sstep
) {
397 cont_instead_of_sstep
= 0;
404 switch (sstep_state
) {
406 v2printk("Emulate single step\n");
407 /* Start by looking at the current PC */
412 break_helper("Z0", NULL
, sstep_addr
);
419 /* Clear breakpoint */
420 break_helper("z0", NULL
, sstep_addr
);
423 eprintk("kgdbts: ERROR failed sstep get emulation\n");
428 static int emul_sstep_put(char *put_str
, char *arg
)
430 if (!arch_needs_sstep_emulation
) {
431 char *ptr
= &put_str
[11];
432 if (put_str
[1] != 'T' || put_str
[2] != '0')
434 kgdb_hex2long(&ptr
, &sstep_thread_id
);
437 switch (sstep_state
) {
439 /* validate the "g" packet to get the IP */
440 kgdb_hex2mem(&put_str
[1], (char *)kgdbts_gdb_regs
,
442 gdb_regs_to_pt_regs(kgdbts_gdb_regs
, &kgdbts_regs
);
443 v2printk("Stopped at IP: %lx\n",
444 instruction_pointer(&kgdbts_regs
));
445 /* Want to stop at IP + break instruction size by default */
446 sstep_addr
= instruction_pointer(&kgdbts_regs
) +
450 if (strncmp(put_str
, "$OK", 3)) {
451 eprintk("kgdbts: failed sstep break set\n");
456 if (strncmp(put_str
, "$T0", 3)) {
457 eprintk("kgdbts: failed continue sstep\n");
462 if (strncmp(put_str
, "$OK", 3)) {
463 eprintk("kgdbts: failed sstep break unset\n");
466 /* Single step is complete so continue on! */
470 eprintk("kgdbts: ERROR failed sstep put emulation\n");
473 /* Continue on the same test line until emulation is complete */
478 static int final_ack_set(char *put_str
, char *arg
)
480 if (strncmp(put_str
+1, arg
, 2))
486 * Test to plant a breakpoint and detach, which should clear out the
487 * breakpoint and restore the original instruction.
489 static struct test_struct plant_and_detach_test
[] = {
490 { "?", "S0*" }, /* Clear break points */
491 { "kgdbts_break_test", "OK", sw_break
, }, /* set sw breakpoint */
492 { "D", "OK" }, /* Detach */
497 * Simple test to write in a software breakpoint, check for the
498 * correct stop location and detach.
500 static struct test_struct sw_breakpoint_test
[] = {
501 { "?", "S0*" }, /* Clear break points */
502 { "kgdbts_break_test", "OK", sw_break
, }, /* set sw breakpoint */
503 { "c", "T0*", }, /* Continue */
504 { "g", "kgdbts_break_test", NULL
, check_and_rewind_pc
},
505 { "write", "OK", write_regs
},
506 { "kgdbts_break_test", "OK", sw_rem_break
}, /*remove breakpoint */
507 { "D", "OK" }, /* Detach */
508 { "D", "OK", NULL
, got_break
}, /* On success we made it here */
513 * Test a known bad memory read location to test the fault handler and
514 * read bytes 1-8 at the bad address
516 static struct test_struct bad_read_test
[] = {
517 { "?", "S0*" }, /* Clear break points */
518 { "m0,1", "E*" }, /* read 1 byte at address 1 */
519 { "m0,2", "E*" }, /* read 1 byte at address 2 */
520 { "m0,3", "E*" }, /* read 1 byte at address 3 */
521 { "m0,4", "E*" }, /* read 1 byte at address 4 */
522 { "m0,5", "E*" }, /* read 1 byte at address 5 */
523 { "m0,6", "E*" }, /* read 1 byte at address 6 */
524 { "m0,7", "E*" }, /* read 1 byte at address 7 */
525 { "m0,8", "E*" }, /* read 1 byte at address 8 */
526 { "D", "OK" }, /* Detach which removes all breakpoints and continues */
531 * Test for hitting a breakpoint, remove it, single step, plant it
534 static struct test_struct singlestep_break_test
[] = {
535 { "?", "S0*" }, /* Clear break points */
536 { "kgdbts_break_test", "OK", sw_break
, }, /* set sw breakpoint */
537 { "c", "T0*", NULL
, get_thread_id_continue
}, /* Continue */
538 { "kgdbts_break_test", "OK", sw_rem_break
}, /*remove breakpoint */
539 { "g", "kgdbts_break_test", NULL
, check_and_rewind_pc
},
540 { "write", "OK", write_regs
}, /* Write registers */
541 { "s", "T0*", emul_sstep_get
, emul_sstep_put
}, /* Single step */
542 { "g", "kgdbts_break_test", NULL
, check_single_step
},
543 { "kgdbts_break_test", "OK", sw_break
, }, /* set sw breakpoint */
544 { "c", "T0*", }, /* Continue */
545 { "g", "kgdbts_break_test", NULL
, check_and_rewind_pc
},
546 { "write", "OK", write_regs
}, /* Write registers */
547 { "D", "OK" }, /* Remove all breakpoints and continues */
552 * Test for hitting a breakpoint at do_fork for what ever the number
553 * of iterations required by the variable repeat_test.
555 static struct test_struct do_fork_test
[] = {
556 { "?", "S0*" }, /* Clear break points */
557 { "do_fork", "OK", sw_break
, }, /* set sw breakpoint */
558 { "c", "T0*", NULL
, get_thread_id_continue
}, /* Continue */
559 { "do_fork", "OK", sw_rem_break
}, /*remove breakpoint */
560 { "g", "do_fork", NULL
, check_and_rewind_pc
}, /* check location */
561 { "write", "OK", write_regs
}, /* Write registers */
562 { "s", "T0*", emul_sstep_get
, emul_sstep_put
}, /* Single step */
563 { "g", "do_fork", NULL
, check_single_step
},
564 { "do_fork", "OK", sw_break
, }, /* set sw breakpoint */
565 { "7", "T0*", skip_back_repeat_test
}, /* Loop based on repeat_test */
566 { "D", "OK", NULL
, final_ack_set
}, /* detach and unregister I/O */
570 /* Test for hitting a breakpoint at sys_open for what ever the number
571 * of iterations required by the variable repeat_test.
573 static struct test_struct sys_open_test
[] = {
574 { "?", "S0*" }, /* Clear break points */
575 { "sys_open", "OK", sw_break
, }, /* set sw breakpoint */
576 { "c", "T0*", NULL
, get_thread_id_continue
}, /* Continue */
577 { "sys_open", "OK", sw_rem_break
}, /*remove breakpoint */
578 { "g", "sys_open", NULL
, check_and_rewind_pc
}, /* check location */
579 { "write", "OK", write_regs
}, /* Write registers */
580 { "s", "T0*", emul_sstep_get
, emul_sstep_put
}, /* Single step */
581 { "g", "sys_open", NULL
, check_single_step
},
582 { "sys_open", "OK", sw_break
, }, /* set sw breakpoint */
583 { "7", "T0*", skip_back_repeat_test
}, /* Loop based on repeat_test */
584 { "D", "OK", NULL
, final_ack_set
}, /* detach and unregister I/O */
589 * Test for hitting a simple hw breakpoint
591 static struct test_struct hw_breakpoint_test
[] = {
592 { "?", "S0*" }, /* Clear break points */
593 { "kgdbts_break_test", "OK", hw_break
, }, /* set hw breakpoint */
594 { "c", "T0*", }, /* Continue */
595 { "g", "kgdbts_break_test", NULL
, check_and_rewind_pc
},
596 { "write", "OK", write_regs
},
597 { "kgdbts_break_test", "OK", hw_rem_break
}, /*remove breakpoint */
598 { "D", "OK" }, /* Detach */
599 { "D", "OK", NULL
, got_break
}, /* On success we made it here */
604 * Test for hitting a hw write breakpoint
606 static struct test_struct hw_write_break_test
[] = {
607 { "?", "S0*" }, /* Clear break points */
608 { "hw_break_val", "OK", hw_write_break
, }, /* set hw breakpoint */
609 { "c", "T0*", NULL
, got_break
}, /* Continue */
610 { "g", "silent", NULL
, check_and_rewind_pc
},
611 { "write", "OK", write_regs
},
612 { "hw_break_val", "OK", hw_rem_write_break
}, /*remove breakpoint */
613 { "D", "OK" }, /* Detach */
614 { "D", "OK", NULL
, got_break
}, /* On success we made it here */
619 * Test for hitting a hw access breakpoint
621 static struct test_struct hw_access_break_test
[] = {
622 { "?", "S0*" }, /* Clear break points */
623 { "hw_break_val", "OK", hw_access_break
, }, /* set hw breakpoint */
624 { "c", "T0*", NULL
, got_break
}, /* Continue */
625 { "g", "silent", NULL
, check_and_rewind_pc
},
626 { "write", "OK", write_regs
},
627 { "hw_break_val", "OK", hw_rem_access_break
}, /*remove breakpoint */
628 { "D", "OK" }, /* Detach */
629 { "D", "OK", NULL
, got_break
}, /* On success we made it here */
634 * Test for hitting a hw access breakpoint
636 static struct test_struct nmi_sleep_test
[] = {
637 { "?", "S0*" }, /* Clear break points */
638 { "c", "T0*", NULL
, got_break
}, /* Continue */
639 { "D", "OK" }, /* Detach */
640 { "D", "OK", NULL
, got_break
}, /* On success we made it here */
644 static void fill_get_buf(char *buf
)
646 unsigned char checksum
= 0;
650 strcpy(get_buf
, "$");
651 strcat(get_buf
, buf
);
652 while ((ch
= buf
[count
])) {
656 strcat(get_buf
, "#");
657 get_buf
[count
+ 2] = hex_asc_hi(checksum
);
658 get_buf
[count
+ 3] = hex_asc_lo(checksum
);
659 get_buf
[count
+ 4] = '\0';
660 v2printk("get%i: %s\n", ts
.idx
, get_buf
);
663 static int validate_simple_test(char *put_str
)
667 if (ts
.tst
[ts
.idx
].put_handler
)
668 return ts
.tst
[ts
.idx
].put_handler(put_str
,
671 chk_str
= ts
.tst
[ts
.idx
].put
;
675 while (*chk_str
!= '\0' && *put_str
!= '\0') {
676 /* If someone does a * to match the rest of the string, allow
677 * it, or stop if the received string is complete.
679 if (*put_str
== '#' || *chk_str
== '*')
681 if (*put_str
!= *chk_str
)
687 if (*chk_str
== '\0' && (*put_str
== '\0' || *put_str
== '#'))
693 static int run_simple_test(int is_get_char
, int chr
)
697 /* Send an ACK on the get if a prior put completed and set the
704 /* On the first get char, fill the transmit buffer and then
705 * take from the get_string.
707 if (get_buf_cnt
== 0) {
708 if (ts
.tst
[ts
.idx
].get_handler
)
709 ts
.tst
[ts
.idx
].get_handler(ts
.tst
[ts
.idx
].get
);
711 fill_get_buf(ts
.tst
[ts
.idx
].get
);
714 if (get_buf
[get_buf_cnt
] == '\0') {
715 eprintk("kgdbts: ERROR GET: EOB on '%s' at %i\n",
720 ret
= get_buf
[get_buf_cnt
];
725 /* This callback is a put char which is when kgdb sends data to
728 if (ts
.tst
[ts
.idx
].get
[0] == '\0' &&
729 ts
.tst
[ts
.idx
].put
[0] == '\0') {
730 eprintk("kgdbts: ERROR: beyond end of test on"
731 " '%s' line %i\n", ts
.name
, ts
.idx
);
735 if (put_buf_cnt
>= BUFMAX
) {
736 eprintk("kgdbts: ERROR: put buffer overflow on"
737 " '%s' line %i\n", ts
.name
, ts
.idx
);
741 /* Ignore everything until the first valid packet start '$' */
742 if (put_buf_cnt
== 0 && chr
!= '$')
745 put_buf
[put_buf_cnt
] = chr
;
748 /* End of packet == #XX so look for the '#' */
749 if (put_buf_cnt
> 3 && put_buf
[put_buf_cnt
- 3] == '#') {
750 if (put_buf_cnt
>= BUFMAX
) {
751 eprintk("kgdbts: ERROR: put buffer overflow on"
752 " '%s' line %i\n", ts
.name
, ts
.idx
);
756 put_buf
[put_buf_cnt
] = '\0';
757 v2printk("put%i: %s\n", ts
.idx
, put_buf
);
758 /* Trigger check here */
759 if (ts
.validate_put
&& ts
.validate_put(put_buf
)) {
760 eprintk("kgdbts: ERROR PUT: end of test "
761 "buffer on '%s' line %i expected %s got %s\n",
762 ts
.name
, ts
.idx
, ts
.tst
[ts
.idx
].put
, put_buf
);
772 static void init_simple_test(void)
774 memset(&ts
, 0, sizeof(ts
));
775 ts
.run_test
= run_simple_test
;
776 ts
.validate_put
= validate_simple_test
;
779 static void run_plant_and_detach_test(int is_early
)
781 char before
[BREAK_INSTR_SIZE
];
782 char after
[BREAK_INSTR_SIZE
];
784 probe_kernel_read(before
, (char *)kgdbts_break_test
,
787 ts
.tst
= plant_and_detach_test
;
788 ts
.name
= "plant_and_detach_test";
789 /* Activate test with initial breakpoint */
792 probe_kernel_read(after
, (char *)kgdbts_break_test
,
794 if (memcmp(before
, after
, BREAK_INSTR_SIZE
)) {
795 printk(KERN_CRIT
"kgdbts: ERROR kgdb corrupted memory\n");
796 panic("kgdb memory corruption");
799 /* complete the detach test */
804 static void run_breakpoint_test(int is_hw_breakpoint
)
808 if (is_hw_breakpoint
) {
809 ts
.tst
= hw_breakpoint_test
;
810 ts
.name
= "hw_breakpoint_test";
812 ts
.tst
= sw_breakpoint_test
;
813 ts
.name
= "sw_breakpoint_test";
815 /* Activate test with initial breakpoint */
817 /* run code with the break point in it */
824 eprintk("kgdbts: ERROR %s test failed\n", ts
.name
);
825 if (is_hw_breakpoint
)
829 static void run_hw_break_test(int is_write_test
)
834 ts
.tst
= hw_write_break_test
;
835 ts
.name
= "hw_write_break_test";
837 ts
.tst
= hw_access_break_test
;
838 ts
.name
= "hw_access_break_test";
840 /* Activate test with initial breakpoint */
842 hw_break_val_access();
844 if (test_complete
== 2) {
845 eprintk("kgdbts: ERROR %s broke on access\n",
849 hw_break_val_write();
853 if (test_complete
== 1)
856 eprintk("kgdbts: ERROR %s test failed\n", ts
.name
);
860 static void run_nmi_sleep_test(int nmi_sleep
)
865 ts
.tst
= nmi_sleep_test
;
866 ts
.name
= "nmi_sleep_test";
867 /* Activate test with initial breakpoint */
869 local_irq_save(flags
);
870 mdelay(nmi_sleep
*1000);
871 touch_nmi_watchdog();
872 local_irq_restore(flags
);
873 if (test_complete
!= 2)
874 eprintk("kgdbts: ERROR nmi_test did not hit nmi\n");
876 if (test_complete
== 1)
879 eprintk("kgdbts: ERROR %s test failed\n", ts
.name
);
882 static void run_bad_read_test(void)
885 ts
.tst
= bad_read_test
;
886 ts
.name
= "bad_read_test";
887 /* Activate test with initial breakpoint */
891 static void run_do_fork_test(void)
894 ts
.tst
= do_fork_test
;
895 ts
.name
= "do_fork_test";
896 /* Activate test with initial breakpoint */
900 static void run_sys_open_test(void)
903 ts
.tst
= sys_open_test
;
904 ts
.name
= "sys_open_test";
905 /* Activate test with initial breakpoint */
909 static void run_singlestep_break_test(void)
912 ts
.tst
= singlestep_break_test
;
913 ts
.name
= "singlestep_breakpoint_test";
914 /* Activate test with initial breakpoint */
920 static void test_debug_rodata(void)
922 #ifdef CONFIG_DEBUG_RODATA
923 /* Until there is an api to write to read-only text segments, use
924 * HW breakpoints for the remainder of any tests, else print a
925 * failure message if hw breakpoints do not work.
927 if (!(arch_kgdb_ops
.flags
& KGDB_HW_BREAKPOINT
&& hwbreaks_ok
)) {
928 eprintk("kgdbts: HW breakpoints BROKEN, ending tests\n");
932 v1printk("kgdbts:Using HW breakpoints for SW breakpoint tests\n");
933 #endif /* CONFIG_DEBUG_RODATA */
936 static void kgdbts_run_tests(void)
940 int do_sys_open_test
= 0;
941 int sstep_test
= 1000;
945 ptr
= strchr(config
, 'F');
947 fork_test
= simple_strtol(ptr
+ 1, NULL
, 10);
948 ptr
= strchr(config
, 'S');
950 do_sys_open_test
= simple_strtol(ptr
+ 1, NULL
, 10);
951 ptr
= strchr(config
, 'N');
953 nmi_sleep
= simple_strtol(ptr
+1, NULL
, 10);
954 ptr
= strchr(config
, 'I');
956 sstep_test
= simple_strtol(ptr
+1, NULL
, 10);
958 /* All HW break point tests */
959 if (arch_kgdb_ops
.flags
& KGDB_HW_BREAKPOINT
) {
961 v1printk("kgdbts:RUN hw breakpoint test\n");
962 run_breakpoint_test(1);
963 v1printk("kgdbts:RUN hw write breakpoint test\n");
964 run_hw_break_test(1);
965 v1printk("kgdbts:RUN access write breakpoint test\n");
966 run_hw_break_test(0);
970 /* required internal KGDB tests */
971 v1printk("kgdbts:RUN plant and detach test\n");
972 run_plant_and_detach_test(0);
973 v1printk("kgdbts:RUN sw breakpoint test\n");
974 run_breakpoint_test(0);
975 v1printk("kgdbts:RUN bad memory access test\n");
977 v1printk("kgdbts:RUN singlestep test %i iterations\n", sstep_test
);
978 for (i
= 0; i
< sstep_test
; i
++) {
979 run_singlestep_break_test();
981 v1printk("kgdbts:RUN singlestep [%i/%i]\n",
985 /* ===Optional tests=== */
988 v1printk("kgdbts:RUN NMI sleep %i seconds test\n", nmi_sleep
);
989 run_nmi_sleep_test(nmi_sleep
);
992 /* If the do_fork test is run it will be the last test that is
993 * executed because a kernel thread will be spawned at the very
994 * end to unregister the debug hooks.
997 repeat_test
= fork_test
;
998 printk(KERN_INFO
"kgdbts:RUN do_fork for %i breakpoints\n",
1000 kthread_run(kgdbts_unreg_thread
, NULL
, "kgdbts_unreg");
1005 /* If the sys_open test is run it will be the last test that is
1006 * executed because a kernel thread will be spawned at the very
1007 * end to unregister the debug hooks.
1009 if (do_sys_open_test
) {
1010 repeat_test
= do_sys_open_test
;
1011 printk(KERN_INFO
"kgdbts:RUN sys_open for %i breakpoints\n",
1013 kthread_run(kgdbts_unreg_thread
, NULL
, "kgdbts_unreg");
1014 run_sys_open_test();
1017 /* Shutdown and unregister */
1018 kgdb_unregister_io_module(&kgdbts_io_ops
);
1022 static int kgdbts_option_setup(char *opt
)
1024 if (strlen(opt
) >= MAX_CONFIG_LEN
) {
1025 printk(KERN_ERR
"kgdbts: config string too long\n");
1028 strcpy(config
, opt
);
1031 if (strstr(config
, "V1"))
1033 if (strstr(config
, "V2"))
1039 __setup("kgdbts=", kgdbts_option_setup
);
1041 static int configure_kgdbts(void)
1045 if (!strlen(config
) || isspace(config
[0]))
1047 err
= kgdbts_option_setup(config
);
1052 run_plant_and_detach_test(1);
1054 err
= kgdb_register_io_module(&kgdbts_io_ops
);
1071 static int __init
init_kgdbts(void)
1073 /* Already configured? */
1074 if (configured
== 1)
1077 return configure_kgdbts();
1080 static int kgdbts_get_char(void)
1085 val
= ts
.run_test(1, 0);
1090 static void kgdbts_put_char(u8 chr
)
1093 ts
.run_test(0, chr
);
1096 static int param_set_kgdbts_var(const char *kmessage
, struct kernel_param
*kp
)
1098 int len
= strlen(kmessage
);
1100 if (len
>= MAX_CONFIG_LEN
) {
1101 printk(KERN_ERR
"kgdbts: config string too long\n");
1105 /* Only copy in the string if the init function has not run yet */
1106 if (configured
< 0) {
1107 strcpy(config
, kmessage
);
1111 if (configured
== 1) {
1112 printk(KERN_ERR
"kgdbts: ERROR: Already configured and running.\n");
1116 strcpy(config
, kmessage
);
1117 /* Chop out \n char as a result of echo */
1118 if (config
[len
- 1] == '\n')
1119 config
[len
- 1] = '\0';
1121 /* Go and configure with the new params. */
1122 return configure_kgdbts();
1125 static void kgdbts_pre_exp_handler(void)
1127 /* Increment the module count when the debugger is active */
1128 if (!kgdb_connected
)
1129 try_module_get(THIS_MODULE
);
1132 static void kgdbts_post_exp_handler(void)
1134 /* decrement the module count when the debugger detaches */
1135 if (!kgdb_connected
)
1136 module_put(THIS_MODULE
);
1139 static struct kgdb_io kgdbts_io_ops
= {
1141 .read_char
= kgdbts_get_char
,
1142 .write_char
= kgdbts_put_char
,
1143 .pre_exception
= kgdbts_pre_exp_handler
,
1144 .post_exception
= kgdbts_post_exp_handler
,
1147 module_init(init_kgdbts
);
1148 module_param_call(kgdbts
, param_set_kgdbts_var
, param_get_string
, &kps
, 0644);
1149 MODULE_PARM_DESC(kgdbts
, "<A|V1|V2>[F#|S#][N#]");
1150 MODULE_DESCRIPTION("KGDB Test Suite");
1151 MODULE_LICENSE("GPL");
1152 MODULE_AUTHOR("Wind River Systems, Inc.");