Skip to content

Commit dfbaedd

Browse files
W-M-Rxiaoxiang781216
authored andcommitted
gcov: Refactoring the implementation framework of gcov
All implementations of gcov are sunk to the kernel implementation 1. Support three dump modes: serial port output, single file output, standard output Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
1 parent 25d43c6 commit dfbaedd

File tree

1 file changed

+14
-109
lines changed

1 file changed

+14
-109
lines changed

system/gcov/gcov.c

Lines changed: 14 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* Included Files
2525
****************************************************************************/
2626

27+
#include <fcntl.h>
2728
#include <gcov.h>
2829
#include <stdio.h>
2930
#include <stdlib.h>
@@ -34,17 +35,6 @@
3435
#include <nuttx/crc16.h>
3536
#include <nuttx/streams.h>
3637

37-
/****************************************************************************
38-
* Private Types
39-
****************************************************************************/
40-
41-
struct gcov_arg
42-
{
43-
FAR const char *name;
44-
struct lib_stdoutstream_s stdoutstream;
45-
struct lib_hexdumpstream_s hexstream;
46-
};
47-
4838
/****************************************************************************
4939
* Private Functions
5040
****************************************************************************/
@@ -65,92 +55,6 @@ static void show_usage(FAR const char *progname)
6555
exit(EXIT_FAILURE);
6656
}
6757

68-
/****************************************************************************
69-
* Name: gcov_dump
70-
****************************************************************************/
71-
72-
static void gcov_dump(FAR const char * path, FAR const char *strip)
73-
{
74-
if (path == NULL || access(path, F_OK) != 0 || atoi(strip) < 0)
75-
{
76-
fprintf(stderr, "ERROR: Invalid parameter\n");
77-
return;
78-
}
79-
80-
setenv("GCOV_PREFIX_STRIP", strip, 1);
81-
setenv("GCOV_PREFIX", path, 1);
82-
__gcov_dump();
83-
}
84-
85-
/****************************************************************************
86-
* Name: stdout_dump
87-
****************************************************************************/
88-
89-
#ifndef CONFIG_COVERAGE_TOOLCHAIN
90-
static void stdout_dump(FAR const void *buffer, size_t size,
91-
FAR void *arg)
92-
{
93-
FAR struct gcov_arg *args = (FAR struct gcov_arg *)arg;
94-
uint16_t checksum = 0;
95-
int i;
96-
97-
if (size == 0)
98-
{
99-
return;
100-
}
101-
102-
for (i = 0; i < size; i++)
103-
{
104-
checksum += ((FAR const uint8_t *)buffer)[i];
105-
}
106-
107-
lib_sprintf(&args->stdoutstream.common,
108-
"gcov start filename:%s size: %zuByte\n",
109-
args->name, size);
110-
lib_stream_puts(&args->hexstream, buffer, size);
111-
lib_stream_flush(&args->hexstream);
112-
lib_sprintf(&args->stdoutstream.common,
113-
"gcov end filename:%s checksum: %#0x\n",
114-
args->name, checksum);
115-
lib_stream_flush(&args->stdoutstream);
116-
}
117-
118-
/****************************************************************************
119-
* Name: stdout_filename
120-
****************************************************************************/
121-
122-
static void stdout_filename(const char *name, FAR void *arg)
123-
{
124-
FAR struct gcov_arg *args = (FAR struct gcov_arg *)arg;
125-
args->name = name;
126-
__gcov_filename_to_gcfn(name, NULL, NULL);
127-
}
128-
129-
/****************************************************************************
130-
* Name: gcov_stdout_dump
131-
*
132-
* Description:
133-
* Dump the gcov information of all translation units to stdout.
134-
*
135-
****************************************************************************/
136-
137-
static void gcov_stdout_dump(void)
138-
{
139-
FAR struct gcov_info *info = __gcov_info_start;
140-
FAR struct gcov_info *end = __gcov_info_end;
141-
struct gcov_arg arg;
142-
143-
lib_stdoutstream(&arg.stdoutstream, stdout);
144-
lib_hexdumpstream(&arg.hexstream, &arg.stdoutstream.common);
145-
146-
while (info != end)
147-
{
148-
__gcov_info_to_gcda(info, stdout_filename, stdout_dump, NULL, &arg);
149-
info = info->next;
150-
}
151-
}
152-
#endif
153-
15458
/****************************************************************************
15559
* Public Functions
15660
****************************************************************************/
@@ -159,14 +63,10 @@ int main(int argc, FAR char *argv[])
15963
{
16064
FAR const char *strip = CONFIG_COVERAGE_DEFAULT_PREFIX_STRIP;
16165
FAR const char *path = NULL;
66+
bool onefile = false;
16267
int option;
16368

164-
if (argc < 2)
165-
{
166-
show_usage(argv[0]);
167-
}
168-
169-
while ((option = getopt(argc, argv, "d::t:rh")) != ERROR)
69+
while ((option = getopt(argc, argv, "d::t:orh")) != ERROR)
17070
{
17171
switch (option)
17272
{
@@ -191,17 +91,22 @@ int main(int argc, FAR char *argv[])
19191
}
19292
}
19393

194-
#ifndef CONFIG_COVERAGE_TOOLCHAIN
195-
if (path == NULL)
94+
if (access(path, F_OK) == 0)
95+
{
96+
onefile = true;
97+
}
98+
99+
if (onefile)
196100
{
197-
gcov_stdout_dump();
101+
setenv("GCOV_DUMP_ONEFILE", "1", 1);
198102
}
199103
else
200-
#endif
201104
{
202-
gcov_dump(path, strip);
105+
setenv("GCOV_DUMP_ONEFILE", "0", 1);
203106
}
204107

205-
printf("Gcov dump complete\n");
108+
setenv("GCOV_PREFIX_STRIP", strip, 1);
109+
setenv("GCOV_PREFIX", path, 1);
110+
__gcov_dump();
206111
return 0;
207112
}

0 commit comments

Comments
 (0)