i2c: Document the message size limit
[safe/jmp/linux-2.6] / drivers / misc / kgdbts.c
index 879fcbd..fcb6ec1 100644 (file)
@@ -47,6 +47,7 @@
  *       to test the HW NMI watchdog
  * F## = Break at do_fork for ## iterations
  * S## = Break at sys_open for ## iterations
+ * I## = Run the single step test ## iterations
  *
  * NOTE: that the do_fork and sys_open tests are mutually exclusive.
  *
 #include <linux/nmi.h>
 #include <linux/delay.h>
 #include <linux/kthread.h>
-#include <linux/delay.h>
 
 #define v1printk(a...) do { \
        if (verbose) \
        } while (0)
 #define MAX_CONFIG_LEN         40
 
-static const char hexchars[] = "0123456789abcdef";
 static struct kgdb_io kgdbts_io_ops;
 static char get_buf[BUFMAX];
 static int get_buf_cnt;
@@ -130,6 +129,8 @@ static int repeat_test;
 static int test_complete;
 static int send_ack;
 static int final_ack;
+static int force_hwbrks;
+static int hwbreaks_ok;
 static int hw_break_val;
 static int hw_break_val2;
 #if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || defined(CONFIG_SPARC)
@@ -233,12 +234,12 @@ static void break_helper(char *bp_type, char *arg, unsigned long vaddr)
 
 static void sw_break(char *arg)
 {
-       break_helper("Z0", arg, 0);
+       break_helper(force_hwbrks ? "Z1" : "Z0", arg, 0);
 }
 
 static void sw_rem_break(char *arg)
 {
-       break_helper("z0", arg, 0);
+       break_helper(force_hwbrks ? "z1" : "z0", arg, 0);
 }
 
 static void hw_break(char *arg)
@@ -618,8 +619,8 @@ static void fill_get_buf(char *buf)
                count++;
        }
        strcat(get_buf, "#");
-       get_buf[count + 2] = hexchars[checksum >> 4];
-       get_buf[count + 3] = hexchars[checksum & 0xf];
+       get_buf[count + 2] = hex_asc_hi(checksum);
+       get_buf[count + 3] = hex_asc_lo(checksum);
        get_buf[count + 4] = '\0';
        v2printk("get%i: %s\n", ts.idx, get_buf);
 }
@@ -711,6 +712,12 @@ static int run_simple_test(int is_get_char, int chr)
 
        /* End of packet == #XX so look for the '#' */
        if (put_buf_cnt > 3 && put_buf[put_buf_cnt - 3] == '#') {
+               if (put_buf_cnt >= BUFMAX) {
+                       eprintk("kgdbts: ERROR: put buffer overflow on"
+                               " '%s' line %i\n", ts.name, ts.idx);
+                       put_buf_cnt = 0;
+                       return 0;
+               }
                put_buf[put_buf_cnt] = '\0';
                v2printk("put%i: %s\n", ts.idx, put_buf);
                /* Trigger check here */
@@ -780,6 +787,8 @@ static void run_breakpoint_test(int is_hw_breakpoint)
                return;
 
        eprintk("kgdbts: ERROR %s test failed\n", ts.name);
+       if (is_hw_breakpoint)
+               hwbreaks_ok = 0;
 }
 
 static void run_hw_break_test(int is_write_test)
@@ -797,9 +806,11 @@ static void run_hw_break_test(int is_write_test)
        kgdb_breakpoint();
        hw_break_val_access();
        if (is_write_test) {
-               if (test_complete == 2)
+               if (test_complete == 2) {
                        eprintk("kgdbts: ERROR %s broke on access\n",
                                ts.name);
+                       hwbreaks_ok = 0;
+               }
                hw_break_val_write();
        }
        kgdb_breakpoint();
@@ -808,6 +819,7 @@ static void run_hw_break_test(int is_write_test)
                return;
 
        eprintk("kgdbts: ERROR %s test failed\n", ts.name);
+       hwbreaks_ok = 0;
 }
 
 static void run_nmi_sleep_test(int nmi_sleep)
@@ -875,17 +887,22 @@ static void kgdbts_run_tests(void)
        char *ptr;
        int fork_test = 0;
        int do_sys_open_test = 0;
+       int sstep_test = 1000;
        int nmi_sleep = 0;
+       int i;
 
-       ptr = strstr(config, "F");
+       ptr = strchr(config, 'F');
        if (ptr)
                fork_test = simple_strtol(ptr + 1, NULL, 10);
-       ptr = strstr(config, "S");
+       ptr = strchr(config, 'S');
        if (ptr)
                do_sys_open_test = simple_strtol(ptr + 1, NULL, 10);
-       ptr = strstr(config, "N");
+       ptr = strchr(config, 'N');
        if (ptr)
                nmi_sleep = simple_strtol(ptr+1, NULL, 10);
+       ptr = strchr(config, 'I');
+       if (ptr)
+               sstep_test = simple_strtol(ptr+1, NULL, 10);
 
        /* required internal KGDB tests */
        v1printk("kgdbts:RUN plant and detach test\n");
@@ -894,13 +911,19 @@ static void kgdbts_run_tests(void)
        run_breakpoint_test(0);
        v1printk("kgdbts:RUN bad memory access test\n");
        run_bad_read_test();
-       v1printk("kgdbts:RUN singlestep breakpoint test\n");
-       run_singlestep_break_test();
+       v1printk("kgdbts:RUN singlestep test %i iterations\n", sstep_test);
+       for (i = 0; i < sstep_test; i++) {
+               run_singlestep_break_test();
+               if (i % 100 == 0)
+                       v1printk("kgdbts:RUN singlestep [%i/%i]\n",
+                                i, sstep_test);
+       }
 
        /* ===Optional tests=== */
 
        /* All HW break point tests */
        if (arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT) {
+               hwbreaks_ok = 1;
                v1printk("kgdbts:RUN hw breakpoint test\n");
                run_breakpoint_test(1);
                v1printk("kgdbts:RUN hw write breakpoint test\n");
@@ -914,6 +937,19 @@ static void kgdbts_run_tests(void)
                run_nmi_sleep_test(nmi_sleep);
        }
 
+#ifdef CONFIG_DEBUG_RODATA
+       /* Until there is an api to write to read-only text segments, use
+        * HW breakpoints for the remainder of any tests, else print a
+        * failure message if hw breakpoints do not work.
+        */
+       if (!(arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT && hwbreaks_ok)) {
+               eprintk("kgdbts: HW breakpoints do not work,"
+                       "skipping remaining tests\n");
+               return;
+       }
+       force_hwbrks = 1;
+#endif /* CONFIG_DEBUG_RODATA */
+
        /* If the do_fork test is run it will be the last test that is
         * executed because a kernel thread will be spawned at the very
         * end to unregister the debug hooks.