1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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>
106
107#define v1printk(a...) do { \
108 if (verbose) \
109 printk(KERN_INFO a); \
110 } while (0)
111#define v2printk(a...) do { \
112 if (verbose > 1) \
113 printk(KERN_INFO a); \
114 touch_nmi_watchdog(); \
115 } while (0)
116#define eprintk(a...) do { \
117 printk(KERN_ERR a); \
118 WARN_ON(1); \
119 } while (0)
120#define MAX_CONFIG_LEN 40
121
122static struct kgdb_io kgdbts_io_ops;
123static char get_buf[BUFMAX];
124static int get_buf_cnt;
125static char put_buf[BUFMAX];
126static int put_buf_cnt;
127static char scratch_buf[BUFMAX];
128static int verbose;
129static int repeat_test;
130static int test_complete;
131static int send_ack;
132static int final_ack;
133static int force_hwbrks;
134static int hwbreaks_ok;
135static int hw_break_val;
136static int hw_break_val2;
137static int cont_instead_of_sstep;
138static unsigned long cont_thread_id;
139static unsigned long sstep_thread_id;
140#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || defined(CONFIG_SPARC)
141static int arch_needs_sstep_emulation = 1;
142#else
143static int arch_needs_sstep_emulation;
144#endif
145static unsigned long cont_addr;
146static unsigned long sstep_addr;
147static int restart_from_top_after_write;
148static int sstep_state;
149
150
151static unsigned long kgdbts_gdb_regs[(NUMREGBYTES +
152 sizeof(unsigned long) - 1) /
153 sizeof(unsigned long)];
154static struct pt_regs kgdbts_regs;
155
156
157static int configured = -1;
158
159#ifdef CONFIG_KGDB_TESTS_BOOT_STRING
160static char config[MAX_CONFIG_LEN] = CONFIG_KGDB_TESTS_BOOT_STRING;
161#else
162static char config[MAX_CONFIG_LEN];
163#endif
164static struct kparam_string kps = {
165 .string = config,
166 .maxlen = MAX_CONFIG_LEN,
167};
168
169static void fill_get_buf(char *buf);
170
171struct test_struct {
172 char *get;
173 char *put;
174 void (*get_handler)(char *);
175 int (*put_handler)(char *, char *);
176};
177
178struct test_state {
179 char *name;
180 struct test_struct *tst;
181 int idx;
182 int (*run_test) (int, int);
183 int (*validate_put) (char *);
184};
185
186static struct test_state ts;
187
188static int kgdbts_unreg_thread(void *ptr)
189{
190
191
192
193 while (!final_ack)
194 msleep_interruptible(1500);
195
196 msleep_interruptible(1000);
197 if (configured)
198 kgdb_unregister_io_module(&kgdbts_io_ops);
199 configured = 0;
200
201 return 0;
202}
203
204
205
206
207static noinline void kgdbts_break_test(void)
208{
209 v2printk("kgdbts: breakpoint complete\n");
210}
211
212
213static unsigned long lookup_addr(char *arg)
214{
215 unsigned long addr = 0;
216
217 if (!strcmp(arg, "kgdbts_break_test"))
218 addr = (unsigned long)kgdbts_break_test;
219 else if (!strcmp(arg, "sys_open"))
220 addr = (unsigned long)do_sys_open;
221 else if (!strcmp(arg, "do_fork"))
222 addr = (unsigned long)do_fork;
223 else if (!strcmp(arg, "hw_break_val"))
224 addr = (unsigned long)&hw_break_val;
225 return addr;
226}
227
228static void break_helper(char *bp_type, char *arg, unsigned long vaddr)
229{
230 unsigned long addr;
231
232 if (arg)
233 addr = lookup_addr(arg);
234 else
235 addr = vaddr;
236
237 sprintf(scratch_buf, "%s,%lx,%i", bp_type, addr,
238 BREAK_INSTR_SIZE);
239 fill_get_buf(scratch_buf);
240}
241
242static void sw_break(char *arg)
243{
244 break_helper(force_hwbrks ? "Z1" : "Z0", arg, 0);
245}
246
247static void sw_rem_break(char *arg)
248{
249 break_helper(force_hwbrks ? "z1" : "z0", arg, 0);
250}
251
252static void hw_break(char *arg)
253{
254 break_helper("Z1", arg, 0);
255}
256
257static void hw_rem_break(char *arg)
258{
259 break_helper("z1", arg, 0);
260}
261
262static void hw_write_break(char *arg)
263{
264 break_helper("Z2", arg, 0);
265}
266
267static void hw_rem_write_break(char *arg)
268{
269 break_helper("z2", arg, 0);
270}
271
272static void hw_access_break(char *arg)
273{
274 break_helper("Z4", arg, 0);
275}
276
277static void hw_rem_access_break(char *arg)
278{
279 break_helper("z4", arg, 0);
280}
281
282static void hw_break_val_access(void)
283{
284 hw_break_val2 = hw_break_val;
285}
286
287static void hw_break_val_write(void)
288{
289 hw_break_val++;
290}
291
292static int get_thread_id_continue(char *put_str, char *arg)
293{
294 char *ptr = &put_str[11];
295
296 if (put_str[1] != 'T' || put_str[2] != '0')
297 return 1;
298 kgdb_hex2long(&ptr, &cont_thread_id);
299 return 0;
300}
301
302static int check_and_rewind_pc(char *put_str, char *arg)
303{
304 unsigned long addr = lookup_addr(arg);
305 unsigned long ip;
306 int offset = 0;
307
308 kgdb_hex2mem(&put_str[1], (char *)kgdbts_gdb_regs,
309 NUMREGBYTES);
310 gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs);
311 ip = instruction_pointer(&kgdbts_regs);
312 v2printk("Stopped at IP: %lx\n", ip);
313#ifdef GDB_ADJUSTS_BREAK_OFFSET
314
315 if (addr + BREAK_INSTR_SIZE == ip)
316 offset = -BREAK_INSTR_SIZE;
317#endif
318
319 if (arch_needs_sstep_emulation && sstep_addr &&
320 ip + offset == sstep_addr &&
321 ((!strcmp(arg, "sys_open") || !strcmp(arg, "do_fork")))) {
322
323 v2printk("Emul: rewind hit single step bp\n");
324 restart_from_top_after_write = 1;
325 } else if (strcmp(arg, "silent") && ip + offset != addr) {
326 eprintk("kgdbts: BP mismatch %lx expected %lx\n",
327 ip + offset, addr);
328 return 1;
329 }
330
331 ip += offset;
332 cont_addr = ip;
333#ifdef GDB_ADJUSTS_BREAK_OFFSET
334 instruction_pointer_set(&kgdbts_regs, ip);
335#endif
336 return 0;
337}
338
339static int check_single_step(char *put_str, char *arg)
340{
341 unsigned long addr = lookup_addr(arg);
342 static int matched_id;
343
344
345
346
347
348 kgdb_hex2mem(&put_str[1], (char *)kgdbts_gdb_regs,
349 NUMREGBYTES);
350 gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs);
351 v2printk("Singlestep stopped at IP: %lx\n",
352 instruction_pointer(&kgdbts_regs));
353
354 if (sstep_thread_id != cont_thread_id) {
355
356
357
358
359
360 v2printk("ThrID does not match: %lx\n", cont_thread_id);
361 if (arch_needs_sstep_emulation) {
362 if (matched_id &&
363 instruction_pointer(&kgdbts_regs) != addr)
364 goto continue_test;
365 matched_id++;
366 ts.idx -= 2;
367 sstep_state = 0;
368 return 0;
369 }
370 cont_instead_of_sstep = 1;
371 ts.idx -= 4;
372 return 0;
373 }
374continue_test:
375 matched_id = 0;
376 if (instruction_pointer(&kgdbts_regs) == addr) {
377 eprintk("kgdbts: SingleStep failed at %lx\n",
378 instruction_pointer(&kgdbts_regs));
379 return 1;
380 }
381
382 return 0;
383}
384
385static void write_regs(char *arg)
386{
387 memset(scratch_buf, 0, sizeof(scratch_buf));
388 scratch_buf[0] = 'G';
389 pt_regs_to_gdb_regs(kgdbts_gdb_regs, &kgdbts_regs);
390 kgdb_mem2hex((char *)kgdbts_gdb_regs, &scratch_buf[1], NUMREGBYTES);
391 fill_get_buf(scratch_buf);
392}
393
394static void skip_back_repeat_test(char *arg)
395{
396 int go_back = simple_strtol(arg, NULL, 10);
397
398 repeat_test--;
399 if (repeat_test <= 0)
400 ts.idx++;
401 else
402 ts.idx -= go_back;
403 fill_get_buf(ts.tst[ts.idx].get);
404}
405
406static int got_break(char *put_str, char *arg)
407{
408 test_complete = 1;
409 if (!strncmp(put_str+1, arg, 2)) {
410 if (!strncmp(arg, "T0", 2))
411 test_complete = 2;
412 return 0;
413 }
414 return 1;
415}
416
417static void get_cont_catch(char *arg)
418{
419
420 fill_get_buf("D");
421}
422
423static int put_cont_catch(char *put_str, char *arg)
424{
425
426 v2printk("kgdbts: cleanup task: %lx\n", sstep_thread_id);
427 ts.idx--;
428 return 0;
429}
430
431static int emul_reset(char *put_str, char *arg)
432{
433 if (strncmp(put_str, "$OK", 3))
434 return 1;
435 if (restart_from_top_after_write) {
436 restart_from_top_after_write = 0;
437 ts.idx = -1;
438 }
439 return 0;
440}
441
442static void emul_sstep_get(char *arg)
443{
444 if (!arch_needs_sstep_emulation) {
445 if (cont_instead_of_sstep) {
446 cont_instead_of_sstep = 0;
447 fill_get_buf("c");
448 } else {
449 fill_get_buf(arg);
450 }
451 return;
452 }
453 switch (sstep_state) {
454 case 0:
455 v2printk("Emulate single step\n");
456
457 fill_get_buf("g");
458 break;
459 case 1:
460
461 break_helper("Z0", NULL, sstep_addr);
462 break;
463 case 2:
464
465 fill_get_buf("c");
466 break;
467 case 3:
468
469 break_helper("z0", NULL, sstep_addr);
470 break;
471 default:
472 eprintk("kgdbts: ERROR failed sstep get emulation\n");
473 }
474 sstep_state++;
475}
476
477static int emul_sstep_put(char *put_str, char *arg)
478{
479 if (!arch_needs_sstep_emulation) {
480 char *ptr = &put_str[11];
481 if (put_str[1] != 'T' || put_str[2] != '0')
482 return 1;
483 kgdb_hex2long(&ptr, &sstep_thread_id);
484 return 0;
485 }
486 switch (sstep_state) {
487 case 1:
488
489 kgdb_hex2mem(&put_str[1], (char *)kgdbts_gdb_regs,
490 NUMREGBYTES);
491 gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs);
492 v2printk("Stopped at IP: %lx\n",
493 instruction_pointer(&kgdbts_regs));
494
495 sstep_addr = cont_addr + BREAK_INSTR_SIZE;
496 break;
497 case 2:
498 if (strncmp(put_str, "$OK", 3)) {
499 eprintk("kgdbts: failed sstep break set\n");
500 return 1;
501 }
502 break;
503 case 3:
504 if (strncmp(put_str, "$T0", 3)) {
505 eprintk("kgdbts: failed continue sstep\n");
506 return 1;
507 } else {
508 char *ptr = &put_str[11];
509 kgdb_hex2long(&ptr, &sstep_thread_id);
510 }
511 break;
512 case 4:
513 if (strncmp(put_str, "$OK", 3)) {
514 eprintk("kgdbts: failed sstep break unset\n");
515 return 1;
516 }
517
518 sstep_state = 0;
519 return 0;
520 default:
521 eprintk("kgdbts: ERROR failed sstep put emulation\n");
522 }
523
524
525 ts.idx--;
526 return 0;
527}
528
529static int final_ack_set(char *put_str, char *arg)
530{
531 if (strncmp(put_str+1, arg, 2))
532 return 1;
533 final_ack = 1;
534 return 0;
535}
536
537
538
539
540static struct test_struct plant_and_detach_test[] = {
541 { "?", "S0*" },
542 { "kgdbts_break_test", "OK", sw_break, },
543 { "D", "OK" },
544 { "", "" },
545};
546
547
548
549
550
551static struct test_struct sw_breakpoint_test[] = {
552 { "?", "S0*" },
553 { "kgdbts_break_test", "OK", sw_break, },
554 { "c", "T0*", },
555 { "g", "kgdbts_break_test", NULL, check_and_rewind_pc },
556 { "write", "OK", write_regs },
557 { "kgdbts_break_test", "OK", sw_rem_break },
558 { "D", "OK" },
559 { "D", "OK", NULL, got_break },
560 { "", "" },
561};
562
563
564
565
566
567static struct test_struct bad_read_test[] = {
568 { "?", "S0*" },
569 { "m0,1", "E*" },
570 { "m0,2", "E*" },
571 { "m0,3", "E*" },
572 { "m0,4", "E*" },
573 { "m0,5", "E*" },
574 { "m0,6", "E*" },
575 { "m0,7", "E*" },
576 { "m0,8", "E*" },
577 { "D", "OK" },
578 { "", "" },
579};
580
581
582
583
584
585static struct test_struct singlestep_break_test[] = {
586 { "?", "S0*" },
587 { "kgdbts_break_test", "OK", sw_break, },
588 { "c", "T0*", NULL, get_thread_id_continue },
589 { "kgdbts_break_test", "OK", sw_rem_break },
590 { "g", "kgdbts_break_test", NULL, check_and_rewind_pc },
591 { "write", "OK", write_regs },
592 { "s", "T0*", emul_sstep_get, emul_sstep_put },
593 { "g", "kgdbts_break_test", NULL, check_single_step },
594 { "kgdbts_break_test", "OK", sw_break, },
595 { "c", "T0*", },
596 { "g", "kgdbts_break_test", NULL, check_and_rewind_pc },
597 { "write", "OK", write_regs },
598 { "D", "OK" },
599 { "", "" },
600};
601
602
603
604
605
606static struct test_struct do_fork_test[] = {
607 { "?", "S0*" },
608 { "do_fork", "OK", sw_break, },
609 { "c", "T0*", NULL, get_thread_id_continue },
610 { "do_fork", "OK", sw_rem_break },
611 { "g", "do_fork", NULL, check_and_rewind_pc },
612 { "write", "OK", write_regs, emul_reset },
613 { "s", "T0*", emul_sstep_get, emul_sstep_put },
614 { "g", "do_fork", NULL, check_single_step },
615 { "do_fork", "OK", sw_break, },
616 { "7", "T0*", skip_back_repeat_test },
617 { "D", "OK", NULL, final_ack_set },
618 { "", "", get_cont_catch, put_cont_catch },
619};
620
621
622
623
624static struct test_struct sys_open_test[] = {
625 { "?", "S0*" },
626 { "sys_open", "OK", sw_break, },
627 { "c", "T0*", NULL, get_thread_id_continue },
628 { "sys_open", "OK", sw_rem_break },
629 { "g", "sys_open", NULL, check_and_rewind_pc },
630 { "write", "OK", write_regs, emul_reset },
631 { "s", "T0*", emul_sstep_get, emul_sstep_put },
632 { "g", "sys_open", NULL, check_single_step },
633 { "sys_open", "OK", sw_break, },
634 { "7", "T0*", skip_back_repeat_test },
635 { "D", "OK", NULL, final_ack_set },
636 { "", "", get_cont_catch, put_cont_catch },
637};
638
639
640
641
642static struct test_struct hw_breakpoint_test[] = {
643 { "?", "S0*" },
644 { "kgdbts_break_test", "OK", hw_break, },
645 { "c", "T0*", },
646 { "g", "kgdbts_break_test", NULL, check_and_rewind_pc },
647 { "write", "OK", write_regs },
648 { "kgdbts_break_test", "OK", hw_rem_break },
649 { "D", "OK" },
650 { "D", "OK", NULL, got_break },
651 { "", "" },
652};
653
654
655
656
657static struct test_struct hw_write_break_test[] = {
658 { "?", "S0*" },
659 { "hw_break_val", "OK", hw_write_break, },
660 { "c", "T0*", NULL, got_break },
661 { "g", "silent", NULL, check_and_rewind_pc },
662 { "write", "OK", write_regs },
663 { "hw_break_val", "OK", hw_rem_write_break },
664 { "D", "OK" },
665 { "D", "OK", NULL, got_break },
666 { "", "" },
667};
668
669
670
671
672static struct test_struct hw_access_break_test[] = {
673 { "?", "S0*" },
674 { "hw_break_val", "OK", hw_access_break, },
675 { "c", "T0*", NULL, got_break },
676 { "g", "silent", NULL, check_and_rewind_pc },
677 { "write", "OK", write_regs },
678 { "hw_break_val", "OK", hw_rem_access_break },
679 { "D", "OK" },
680 { "D", "OK", NULL, got_break },
681 { "", "" },
682};
683
684
685
686
687static struct test_struct nmi_sleep_test[] = {
688 { "?", "S0*" },
689 { "c", "T0*", NULL, got_break },
690 { "D", "OK" },
691 { "D", "OK", NULL, got_break },
692 { "", "" },
693};
694
695static void fill_get_buf(char *buf)
696{
697 unsigned char checksum = 0;
698 int count = 0;
699 char ch;
700
701 strcpy(get_buf, "$");
702 strcat(get_buf, buf);
703 while ((ch = buf[count])) {
704 checksum += ch;
705 count++;
706 }
707 strcat(get_buf, "#");
708 get_buf[count + 2] = hex_asc_hi(checksum);
709 get_buf[count + 3] = hex_asc_lo(checksum);
710 get_buf[count + 4] = '\0';
711 v2printk("get%i: %s\n", ts.idx, get_buf);
712}
713
714static int validate_simple_test(char *put_str)
715{
716 char *chk_str;
717
718 if (ts.tst[ts.idx].put_handler)
719 return ts.tst[ts.idx].put_handler(put_str,
720 ts.tst[ts.idx].put);
721
722 chk_str = ts.tst[ts.idx].put;
723 if (*put_str == '$')
724 put_str++;
725
726 while (*chk_str != '\0' && *put_str != '\0') {
727
728
729
730 if (*put_str == '#' || *chk_str == '*')
731 return 0;
732 if (*put_str != *chk_str)
733 return 1;
734
735 chk_str++;
736 put_str++;
737 }
738 if (*chk_str == '\0' && (*put_str == '\0' || *put_str == '#'))
739 return 0;
740
741 return 1;
742}
743
744static int run_simple_test(int is_get_char, int chr)
745{
746 int ret = 0;
747 if (is_get_char) {
748
749
750
751 if (send_ack) {
752 send_ack = 0;
753 return '+';
754 }
755
756
757
758 if (get_buf_cnt == 0) {
759 if (ts.tst[ts.idx].get_handler)
760 ts.tst[ts.idx].get_handler(ts.tst[ts.idx].get);
761 else
762 fill_get_buf(ts.tst[ts.idx].get);
763 }
764
765 if (get_buf[get_buf_cnt] == '\0') {
766 eprintk("kgdbts: ERROR GET: EOB on '%s' at %i\n",
767 ts.name, ts.idx);
768 get_buf_cnt = 0;
769 fill_get_buf("D");
770 }
771 ret = get_buf[get_buf_cnt];
772 get_buf_cnt++;
773 return ret;
774 }
775
776
777
778
779 if (ts.tst[ts.idx].get[0] == '\0' && ts.tst[ts.idx].put[0] == '\0' &&
780 !ts.tst[ts.idx].get_handler) {
781 eprintk("kgdbts: ERROR: beyond end of test on"
782 " '%s' line %i\n", ts.name, ts.idx);
783 return 0;
784 }
785
786 if (put_buf_cnt >= BUFMAX) {
787 eprintk("kgdbts: ERROR: put buffer overflow on"
788 " '%s' line %i\n", ts.name, ts.idx);
789 put_buf_cnt = 0;
790 return 0;
791 }
792
793 if (put_buf_cnt == 0 && chr != '$')
794 return 0;
795
796 put_buf[put_buf_cnt] = chr;
797 put_buf_cnt++;
798
799
800 if (put_buf_cnt > 3 && put_buf[put_buf_cnt - 3] == '#') {
801 if (put_buf_cnt >= BUFMAX) {
802 eprintk("kgdbts: ERROR: put buffer overflow on"
803 " '%s' line %i\n", ts.name, ts.idx);
804 put_buf_cnt = 0;
805 return 0;
806 }
807 put_buf[put_buf_cnt] = '\0';
808 v2printk("put%i: %s\n", ts.idx, put_buf);
809
810 if (ts.validate_put && ts.validate_put(put_buf)) {
811 eprintk("kgdbts: ERROR PUT: end of test "
812 "buffer on '%s' line %i expected %s got %s\n",
813 ts.name, ts.idx, ts.tst[ts.idx].put, put_buf);
814 }
815 ts.idx++;
816 put_buf_cnt = 0;
817 get_buf_cnt = 0;
818 send_ack = 1;
819 }
820 return 0;
821}
822
823static void init_simple_test(void)
824{
825 memset(&ts, 0, sizeof(ts));
826 ts.run_test = run_simple_test;
827 ts.validate_put = validate_simple_test;
828}
829
830static void run_plant_and_detach_test(int is_early)
831{
832 char before[BREAK_INSTR_SIZE];
833 char after[BREAK_INSTR_SIZE];
834
835 probe_kernel_read(before, (char *)kgdbts_break_test,
836 BREAK_INSTR_SIZE);
837 init_simple_test();
838 ts.tst = plant_and_detach_test;
839 ts.name = "plant_and_detach_test";
840
841 if (!is_early)
842 kgdb_breakpoint();
843 probe_kernel_read(after, (char *)kgdbts_break_test,
844 BREAK_INSTR_SIZE);
845 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
846 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
847 panic("kgdb memory corruption");
848 }
849
850
851 if (!is_early)
852 kgdbts_break_test();
853}
854
855static void run_breakpoint_test(int is_hw_breakpoint)
856{
857 test_complete = 0;
858 init_simple_test();
859 if (is_hw_breakpoint) {
860 ts.tst = hw_breakpoint_test;
861 ts.name = "hw_breakpoint_test";
862 } else {
863 ts.tst = sw_breakpoint_test;
864 ts.name = "sw_breakpoint_test";
865 }
866
867 kgdb_breakpoint();
868
869 kgdbts_break_test();
870 kgdb_breakpoint();
871
872 if (test_complete)
873 return;
874
875 eprintk("kgdbts: ERROR %s test failed\n", ts.name);
876 if (is_hw_breakpoint)
877 hwbreaks_ok = 0;
878}
879
880static void run_hw_break_test(int is_write_test)
881{
882 test_complete = 0;
883 init_simple_test();
884 if (is_write_test) {
885 ts.tst = hw_write_break_test;
886 ts.name = "hw_write_break_test";
887 } else {
888 ts.tst = hw_access_break_test;
889 ts.name = "hw_access_break_test";
890 }
891
892 kgdb_breakpoint();
893 hw_break_val_access();
894 if (is_write_test) {
895 if (test_complete == 2) {
896 eprintk("kgdbts: ERROR %s broke on access\n",
897 ts.name);
898 hwbreaks_ok = 0;
899 }
900 hw_break_val_write();
901 }
902 kgdb_breakpoint();
903
904 if (test_complete == 1)
905 return;
906
907 eprintk("kgdbts: ERROR %s test failed\n", ts.name);
908 hwbreaks_ok = 0;
909}
910
911static void run_nmi_sleep_test(int nmi_sleep)
912{
913 unsigned long flags;
914
915 init_simple_test();
916 ts.tst = nmi_sleep_test;
917 ts.name = "nmi_sleep_test";
918
919 kgdb_breakpoint();
920 local_irq_save(flags);
921 mdelay(nmi_sleep*1000);
922 touch_nmi_watchdog();
923 local_irq_restore(flags);
924 if (test_complete != 2)
925 eprintk("kgdbts: ERROR nmi_test did not hit nmi\n");
926 kgdb_breakpoint();
927 if (test_complete == 1)
928 return;
929
930 eprintk("kgdbts: ERROR %s test failed\n", ts.name);
931}
932
933static void run_bad_read_test(void)
934{
935 init_simple_test();
936 ts.tst = bad_read_test;
937 ts.name = "bad_read_test";
938
939 kgdb_breakpoint();
940}
941
942static void run_do_fork_test(void)
943{
944 init_simple_test();
945 ts.tst = do_fork_test;
946 ts.name = "do_fork_test";
947
948 kgdb_breakpoint();
949}
950
951static void run_sys_open_test(void)
952{
953 init_simple_test();
954 ts.tst = sys_open_test;
955 ts.name = "sys_open_test";
956
957 kgdb_breakpoint();
958}
959
960static void run_singlestep_break_test(void)
961{
962 init_simple_test();
963 ts.tst = singlestep_break_test;
964 ts.name = "singlestep_breakpoint_test";
965
966 kgdb_breakpoint();
967 kgdbts_break_test();
968 kgdbts_break_test();
969}
970
971static void kgdbts_run_tests(void)
972{
973 char *ptr;
974 int fork_test = 0;
975 int do_sys_open_test = 0;
976 int sstep_test = 1000;
977 int nmi_sleep = 0;
978 int i;
979
980 ptr = strchr(config, 'F');
981 if (ptr)
982 fork_test = simple_strtol(ptr + 1, NULL, 10);
983 ptr = strchr(config, 'S');
984 if (ptr)
985 do_sys_open_test = simple_strtol(ptr + 1, NULL, 10);
986 ptr = strchr(config, 'N');
987 if (ptr)
988 nmi_sleep = simple_strtol(ptr+1, NULL, 10);
989 ptr = strchr(config, 'I');
990 if (ptr)
991 sstep_test = simple_strtol(ptr+1, NULL, 10);
992
993
994 if (arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT) {
995 hwbreaks_ok = 1;
996 v1printk("kgdbts:RUN hw breakpoint test\n");
997 run_breakpoint_test(1);
998 v1printk("kgdbts:RUN hw write breakpoint test\n");
999 run_hw_break_test(1);
1000 v1printk("kgdbts:RUN access write breakpoint test\n");
1001 run_hw_break_test(0);
1002 }
1003
1004
1005 v1printk("kgdbts:RUN plant and detach test\n");
1006 run_plant_and_detach_test(0);
1007 v1printk("kgdbts:RUN sw breakpoint test\n");
1008 run_breakpoint_test(0);
1009 v1printk("kgdbts:RUN bad memory access test\n");
1010 run_bad_read_test();
1011 v1printk("kgdbts:RUN singlestep test %i iterations\n", sstep_test);
1012 for (i = 0; i < sstep_test; i++) {
1013 run_singlestep_break_test();
1014 if (i % 100 == 0)
1015 v1printk("kgdbts:RUN singlestep [%i/%i]\n",
1016 i, sstep_test);
1017 }
1018
1019
1020
1021 if (nmi_sleep) {
1022 v1printk("kgdbts:RUN NMI sleep %i seconds test\n", nmi_sleep);
1023 run_nmi_sleep_test(nmi_sleep);
1024 }
1025
1026
1027
1028
1029
1030 if (fork_test) {
1031 repeat_test = fork_test;
1032 printk(KERN_INFO "kgdbts:RUN do_fork for %i breakpoints\n",
1033 repeat_test);
1034 kthread_run(kgdbts_unreg_thread, NULL, "kgdbts_unreg");
1035 run_do_fork_test();
1036 return;
1037 }
1038
1039
1040
1041
1042
1043 if (do_sys_open_test) {
1044 repeat_test = do_sys_open_test;
1045 printk(KERN_INFO "kgdbts:RUN sys_open for %i breakpoints\n",
1046 repeat_test);
1047 kthread_run(kgdbts_unreg_thread, NULL, "kgdbts_unreg");
1048 run_sys_open_test();
1049 return;
1050 }
1051
1052 kgdb_unregister_io_module(&kgdbts_io_ops);
1053 configured = 0;
1054}
1055
1056static int kgdbts_option_setup(char *opt)
1057{
1058 if (strlen(opt) >= MAX_CONFIG_LEN) {
1059 printk(KERN_ERR "kgdbts: config string too long\n");
1060 return -ENOSPC;
1061 }
1062 strcpy(config, opt);
1063
1064 verbose = 0;
1065 if (strstr(config, "V1"))
1066 verbose = 1;
1067 if (strstr(config, "V2"))
1068 verbose = 2;
1069
1070 return 0;
1071}
1072
1073__setup("kgdbts=", kgdbts_option_setup);
1074
1075static int configure_kgdbts(void)
1076{
1077 int err = 0;
1078
1079 if (!strlen(config) || isspace(config[0]))
1080 goto noconfig;
1081 err = kgdbts_option_setup(config);
1082 if (err)
1083 goto noconfig;
1084
1085 final_ack = 0;
1086 run_plant_and_detach_test(1);
1087
1088 err = kgdb_register_io_module(&kgdbts_io_ops);
1089 if (err) {
1090 configured = 0;
1091 return err;
1092 }
1093 configured = 1;
1094 kgdbts_run_tests();
1095
1096 return err;
1097
1098noconfig:
1099 config[0] = 0;
1100 configured = 0;
1101
1102 return err;
1103}
1104
1105static int __init init_kgdbts(void)
1106{
1107
1108 if (configured == 1)
1109 return 0;
1110
1111 return configure_kgdbts();
1112}
1113
1114static int kgdbts_get_char(void)
1115{
1116 int val = 0;
1117
1118 if (ts.run_test)
1119 val = ts.run_test(1, 0);
1120
1121 return val;
1122}
1123
1124static void kgdbts_put_char(u8 chr)
1125{
1126 if (ts.run_test)
1127 ts.run_test(0, chr);
1128}
1129
1130static int param_set_kgdbts_var(const char *kmessage, struct kernel_param *kp)
1131{
1132 int len = strlen(kmessage);
1133
1134 if (len >= MAX_CONFIG_LEN) {
1135 printk(KERN_ERR "kgdbts: config string too long\n");
1136 return -ENOSPC;
1137 }
1138
1139
1140 if (configured < 0) {
1141 strcpy(config, kmessage);
1142 return 0;
1143 }
1144
1145 if (configured == 1) {
1146 printk(KERN_ERR "kgdbts: ERROR: Already configured and running.\n");
1147 return -EBUSY;
1148 }
1149
1150 strcpy(config, kmessage);
1151
1152 if (config[len - 1] == '\n')
1153 config[len - 1] = '\0';
1154
1155
1156 return configure_kgdbts();
1157}
1158
1159static void kgdbts_pre_exp_handler(void)
1160{
1161
1162 if (!kgdb_connected)
1163 try_module_get(THIS_MODULE);
1164}
1165
1166static void kgdbts_post_exp_handler(void)
1167{
1168
1169 if (!kgdb_connected)
1170 module_put(THIS_MODULE);
1171}
1172
1173static struct kgdb_io kgdbts_io_ops = {
1174 .name = "kgdbts",
1175 .read_char = kgdbts_get_char,
1176 .write_char = kgdbts_put_char,
1177 .pre_exception = kgdbts_pre_exp_handler,
1178 .post_exception = kgdbts_post_exp_handler,
1179};
1180
1181module_init(init_kgdbts);
1182module_param_call(kgdbts, param_set_kgdbts_var, param_get_string, &kps, 0644);
1183MODULE_PARM_DESC(kgdbts, "<A|V1|V2>[F#|S#][N#]");
1184MODULE_DESCRIPTION("KGDB Test Suite");
1185MODULE_LICENSE("GPL");
1186MODULE_AUTHOR("Wind River Systems, Inc.");
1187
1188