Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce lib-embedded-gcov #1

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from

Conversation

michpappas
Copy link
Member

Port of embedded-gcov[1] for Unikraft.

[1] https://github.com/nasa-jpl/embedded-gcov

@razvand razvand self-assigned this Mar 26, 2023
@razvand razvand added the enhancement New feature or request label Mar 26, 2023
@razvand razvand added this to the v0.13.0 (Atlas) milestone Mar 26, 2023
Makefile.uk Outdated
endif

LIBEMBEDDEDGCOV_CFLAGS-$(CONFIG_LIBEMBEDDEDGCOV_OUTPUT_SERIAL_HEXDUMP) += -DGCOV_OPT_OUTPUT_SERIAL_HEXDUMP
LIBEMBEDDEDGCOV_CFLAGS-$(CONFIG_LIBEMBEDDEDGCOV_OUTPUT_SERIAL_HEXDUMP) += -Dgcov_printf=printf
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gcov_printf function is not only used when the CONFIG_LIBEMBEDDEDGCOV_OUTPUT_SERIAL_HEXDUMP option is set, but also when the GCOV_OPT_PRINT_STATUS option is set. This can be seen in the original embedded-gcov code where the gcov_printf function is used when either of these options is defined. This means that even if the user selects a memory output, they may still want to see console information about the gcov run.

#if defined(GCOV_OPT_PRINT_STATUS) || defined(GCOV_OPT_OUTPUT_SERIAL_HEXDUMP)
    GCOV_PRINT_STR("Gcov End");
    GCOV_PRINT_STR("\n");
#endif
Suggested change
LIBEMBEDDEDGCOV_CFLAGS-$(CONFIG_LIBEMBEDDEDGCOV_OUTPUT_SERIAL_HEXDUMP) += -Dgcov_printf=printf
LIBEMBEDDEDGCOV_CFLAGS-y += -Dgcov_printf=printf

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated 👍🏼

Copy link

@DeliaPavel DeliaPavel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-by: Delia Pavel [email protected]

@razvand
Copy link
Contributor

razvand commented Apr 10, 2023

@michpappas, @Starnox, I get the error below when testing lib-embedded-gcov. I'm running the basic app-helloworld app, and I added the lib-embedded-gcov library to it. Any idea why this is happening?

/media/razvan/c4f6765a-efa5-4ebd-9cf0-7da9908a0189/razvan/unikraft/scripts/workdir/apps/app-helloworld/build/libembeddedgcov/origin/code/gcov_public.c: In function ‘__gcov_call_constructors’:
/media/razvan/c4f6765a-efa5-4ebd-9cf0-7da9908a0189/razvan/unikraft/scripts/workdir/apps/app-helloworld/build/libembeddedgcov/origin/code/gcov_public.c:206:36: error: ‘UINT32’ undeclared (first use in this function); did you mean ‘MIN3’?
         func = (void ( *)(void))(*(UINT32 *)ctor);
                                    ^~~~~~
                                    MIN3
/media/razvan/c4f6765a-efa5-4ebd-9cf0-7da9908a0189/razvan/unikraft/scripts/workdir/apps/app-helloworld/build/libembeddedgcov/origin/code/gcov_public.c:206:36: note: each undeclared identifier is reported only once for each function it appears in
/media/razvan/c4f6765a-efa5-4ebd-9cf0-7da9908a0189/razvan/unikraft/scripts/workdir/apps/app-helloworld/build/libembeddedgcov/origin/code/gcov_public.c:206:44: error: expected expression before ‘)’ token
         func = (void ( *)(void))(*(UINT32 *)ctor);

@razvand
Copy link
Contributor

razvand commented Apr 10, 2023

OK, that error appears when selecting Provide call constructors in make menuconfig. I had selected all items by default. Still, that issue should be solved. Even if all items are selected, there shouldn't be a build error.

Also, I'm running the commands above, and when running the processing scripts, I get:

$ ../../libs/embedded-gcov/scripts/gcov_process.sh build/ serial.log
Capturing coverage data from ../objs/
Found gcov version: 7.5.0
Scanning ../objs/ for .gcno files ...
Found 68 graph files in ../objs/
Processing objs/print.gcno
geninfo: WARNING: /media/razvan/c4f6765a-efa5-4ebd-9cf0-7da9908a0189/razvan/unikraft/scripts/workdir/apps/app-helloworld/build/libembeddedgcov/origin/objs/print.gcno: Overlong record
at end of file!
Processing objs/__secs_to_tm.gcno
geninfo: WARNING: /media/razvan/c4f6765a-efa5-4ebd-9cf0-7da9908a0189/razvan/unikraft/scripts/workdir/apps/app-helloworld/build/libembeddedgcov/origin/objs/__secs_to_tm.gcno: Overlong
record at end of file!
Processing objs/ctx.isr.gcno
geninfo: WARNING: /media/razvan/c4f6765a-efa5-4ebd-9cf0-7da9908a0189/razvan/unikraft/scripts/workdir/apps/app-helloworld/build/libembeddedgcov/origin/objs/ctx.isr.gcno: Overlong record at end of file!
Processing objs/gcov_printf.gcno
geninfo: ERROR: /media/razvan/c4f6765a-efa5-4ebd-9cf0-7da9908a0189/razvan/unikraft/scripts/workdir/apps/app-helloworld/build/libembeddedgcov/origin/objs/gcov_printf.gcno: reached unexpected end of file

Any clue what might be causing this?

Copy link
Contributor

@razvand razvand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comments.

README.md Outdated

## Collecting Coverage Results

embedded-gcov provides three types of output:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
embedded-gcov provides three types of output:
`lib-embedded-gcov` provides three types of output:

README.md Outdated
The console output then needs to be processed into an lcov report. `lib-embedded-gcov` provides the `gcov_process.sh` script for that, which is essentially a wrapper around the tools provided by `embedded-gcov`.

Before executing the script make sure you have the required dependencies installed, that is:
- dox2unix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- dox2unix
- `dos2unix`

README.md Outdated

Before executing the script make sure you have the required dependencies installed, that is:
- dox2unix
- lcov
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- lcov
- `lcov`

README.md Outdated

With dependencies installed, execute the script as:
```
lib-embedded-gcov/scripts/gcov_process.sh <build_directory> <console_log>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a concrete run sample, it's easier to know what your command should look like.

```

The script will generate an lcov report and provide a link as shown below.
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These three backticks are here by mistake, right?

README.md Outdated

To obtain coverage results via the console you need to dump the console output into a file. With QEMU this is possible by configuring the serial device to log all output into a file:
```
-chardev stdio,id=char0,logfile=serial.log,signal=off -serial chardev:char0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a concrete run sample, it's easier to know what your command should look like.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also mention NOT using -nographic because that clashes with the redirection of standard output.

README.md Outdated

lcov report in file:///home/mpp/devel/unikraft_oss/uk_embedded-gcov/app-helloworld/build/libembeddedgcov/origin/results/html/index.html
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why empty line?

Port of embedded-gcov[1] for Unikraft. This patch only provides
support for serial console output.

[1] https://github.com/nasa-jpl/embedded-gcov

Signed-off-by: Michalis Pappas <[email protected]>
@michpappas michpappas force-pushed the introduce-lib-embedded-gcov branch from e17069f to 81ef7ed Compare May 8, 2023 07:20
@michpappas
Copy link
Member Author

@michpappas, @Starnox, I get the error below when testing lib-embedded-gcov. I'm running the basic app-helloworld app, and I added the lib-embedded-gcov library to it. Any idea why this is happening?

/media/razvan/c4f6765a-efa5-4ebd-9cf0-7da9908a0189/razvan/unikraft/scripts/workdir/apps/app-helloworld/build/libembeddedgcov/origin/code/gcov_public.c: In function ‘__gcov_call_constructors’:
/media/razvan/c4f6765a-efa5-4ebd-9cf0-7da9908a0189/razvan/unikraft/scripts/workdir/apps/app-helloworld/build/libembeddedgcov/origin/code/gcov_public.c:206:36: error: ‘UINT32’ undeclared (first use in this function); did you mean ‘MIN3’?
         func = (void ( *)(void))(*(UINT32 *)ctor);
                                    ^~~~~~
                                    MIN3
/media/razvan/c4f6765a-efa5-4ebd-9cf0-7da9908a0189/razvan/unikraft/scripts/workdir/apps/app-helloworld/build/libembeddedgcov/origin/code/gcov_public.c:206:36: note: each undeclared identifier is reported only once for each function it appears in
/media/razvan/c4f6765a-efa5-4ebd-9cf0-7da9908a0189/razvan/unikraft/scripts/workdir/apps/app-helloworld/build/libembeddedgcov/origin/code/gcov_public.c:206:44: error: expected expression before ‘)’ token
         func = (void ( *)(void))(*(UINT32 *)ctor);

@razvand thanks for that. As you pointed out it happens if you enable CONFIG_LIBEMBEDDEDGCOV_PROVIDE_CALL_CONSTRUCTORS. I had previously come across it and was under the impression that I fixed it. I pushed an additional patch now under patches/.

Please notice that even with that patch the build will fail with:

/usr/bin/ld: /home/mpp/devel/unikraft_oss/uk_embedded-gcov/app-helloworld/build/app-helloworld_kvm-x86_64.o: in function `__gcov_call_constructors':
/home/mpp/devel/unikraft_oss/uk_embedded-gcov/app-helloworld/build/libembeddedgcov/origin/code/gcov_public.c:203: undefined reference to `__ctor_list'
/usr/bin/ld: /home/mpp/devel/unikraft_oss/uk_embedded-gcov/app-helloworld/build/libembeddedgcov/origin/code/gcov_public.c:203: undefined reference to `__ctor_end'
/usr/bin/ld: /home/mpp/devel/unikraft_oss/uk_embedded-gcov/app-helloworld/build/libembeddedgcov/origin/code/gcov_public.c:203: undefined reference to `__ctor_end'
collect2: error: ld returned 1 exit status
make[3]: *** [/home/mpp/devel/unikraft_oss/uk_embedded-gcov/unikraft/plat/kvm/Linker.uk:35: /home/mpp/devel/unikraft_oss/uk_embedded-gcov/app-helloworld/build/app-helloworld_kvm-x86_64.dbg] Error 1

This is normal behavior, as with this option you need to provide __ctors_list and __ctors_end. I updated the help message in the relevant option in KConfig to make it more clear.

@michpappas
Copy link
Member Author

@razvand README.md has now been rewritten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 🏗 In Progress
Development

Successfully merging this pull request may close these issues.

None yet

4 participants