]> granicus.if.org Git - esp-idf/commitdiff
unity: add a hook to run test from gdb session
authorIvan Grokhotkov <ivan@espressif.com>
Thu, 6 Dec 2018 11:28:45 +0000 (19:28 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Thu, 6 Dec 2018 11:37:51 +0000 (19:37 +0800)
components/unity/unity_port_esp32.c

index e689d88be9bc7a58084f6bc7e5599eb6134b354c..024dbc7e513ea4b0273fa570793759052bcdb669 100644 (file)
@@ -36,8 +36,25 @@ void unity_flush()
     uart_tx_wait_idle(CONFIG_CONSOLE_UART_NUM);
 }
 
+/* To start a unit test from a GDB session without console input,
+ * - set a break at unity_gets ('hb unity_gets')
+ * - resume the program ('c')
+ * - modify this value to the desired command line ('set {char[64]} unity_input_from_gdb = "5"')
+ * - optionally set a break point in the test being debugged
+ * - resume the program ('c')
+ */
+char unity_input_from_gdb[64];
+
 void unity_gets(char *dst, size_t len)
 {
+    size_t unity_input_from_gdb_len = strlen(unity_input_from_gdb);
+    if (unity_input_from_gdb_len > 0 && unity_input_from_gdb_len < len - 1) {
+        memcpy(dst, unity_input_from_gdb, unity_input_from_gdb_len);
+        dst[unity_input_from_gdb_len] = '\n';
+        dst[unity_input_from_gdb_len + 1] = 0;
+        memset(unity_input_from_gdb, 0, sizeof(unity_input_from_gdb));
+        return;
+    }
     /* UartRxString length argument is uint8_t */
     if (len >= UINT8_MAX) {
         len = UINT8_MAX;