This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 0f74de57cfb0811d1b8887d3a229b66ecc1d532d
Author: yinshengkai <[email protected]>
AuthorDate: Wed Mar 27 21:24:24 2024 +0800

    system/gcov: supports generating device-side code coverage
    
    Signed-off-by: yinshengkai <[email protected]>
---
 system/gcov/gcov.c | 36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/system/gcov/gcov.c b/system/gcov/gcov.c
index bf4dbf549..9506cadb1 100644
--- a/system/gcov/gcov.c
+++ b/system/gcov/gcov.c
@@ -23,6 +23,7 @@
  ****************************************************************************/
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 
 /****************************************************************************
@@ -35,11 +36,13 @@
 
 static void show_usage(FAR const char *progname)
 {
-  printf("\nUsage: %s [-d] [-r] [-h]\n", progname);
+  printf("\nUsage: %s [-d path] [-t strip] [-r] [-h]\n", progname);
   printf("\nWhere:\n");
-  printf("  -d dump the coverage.\n");
+  printf("  -d dump the coverage, path is the path to the coverage file\n");
+  printf("  -t strip the path prefix number\n");
   printf("  -r reset the coverage\n");
   printf("  -h show this text and exits.\n");
+  exit(EXIT_FAILURE);
 }
 
 /****************************************************************************
@@ -49,12 +52,31 @@ static void show_usage(FAR const char *progname)
 void __gcov_dump(void);
 void __gcov_reset(void);
 
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void gcov_dump(FAR const char * path, FAR const char *strip)
+{
+  if (path == NULL || access(path, F_OK) != 0 || atoi(strip) <= 0)
+    {
+      fprintf(stderr, "ERROR: Invalid parameter\n");
+      return;
+    }
+
+  setenv("GCOV_PREFIX_STRIP", strip, 1);
+  setenv("GCOV_PREFIX", path, 1);
+  __gcov_dump();
+}
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
 int main(int argc, FAR char *argv[])
 {
+  FAR const char *strip = "99";
+  FAR const char *path;
   int option;
 
   if (argc < 2)
@@ -62,12 +84,17 @@ int main(int argc, FAR char *argv[])
       show_usage(argv[0]);
     }
 
-  while ((option = getopt(argc, argv, "drh")) != ERROR)
+  while ((option = getopt(argc, argv, "d:t:rh")) != ERROR)
     {
       switch (option)
         {
           case 'd':
-            __gcov_dump();
+            path = optarg;
+            break;
+
+          case 't':
+            strip = optarg;
+
             break;
 
           case 'r':
@@ -83,5 +110,6 @@ int main(int argc, FAR char *argv[])
         }
     }
 
+  gcov_dump(path, strip);
   return 0;
 }

Reply via email to