SimonKagstrom / kcov

Code coverage tool for compiled programs, Python and Bash which uses debugging information to collect and report data without special compilation options
http://simonkagstrom.github.io/kcov/
GNU General Public License v2.0
709 stars 109 forks source link

Improve tests code even more #432

Closed perillo closed 5 months ago

perillo commented 5 months ago

Additional improvements to kcov test suite.

This PR changes a lot of code! I used sed to make the change automatic.

CHANGES

TODO

Additionally tests that should use doCmd:

Possible BUG(?)

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 65.68%. Comparing base (c3b0b2a) to head (9794dd0).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #432 +/- ## ========================================== - Coverage 65.70% 65.68% -0.03% ========================================== Files 58 58 Lines 4514 4514 Branches 4171 4171 ========================================== - Hits 2966 2965 -1 - Misses 1548 1549 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

perillo commented 5 months ago

As I suspected system_mode_can_record_and_report_binary did not failed on Github CI. Probably because the tests are run as root, while on my PC the tests are run as a normal user.

The strange thing is that system_mode_can_record_and_report_binary is incorrect, since it starts the daemon process but does not stop it.

SimonKagstrom commented 5 months ago

Thanks!

As for system-mode, it has really never been properly working anyway. It's sort of meant to be run as root, since the purpose is to collect coverage from all binaries in a system, as a part of the startup of an embedded system. However, it really was never working outside of a proof-of-concept stage, so I think we can simply disable the system mode tests for now.

perillo commented 5 months ago

Thanks for the explanation.

However it is true that before the change introducing subprocess.run, the test worked until the skipTest with normal privilege.

Do you have a preferred channel for communication, like email, forum or github issue? For the following commits I may need your help for some clarification.

SimonKagstrom commented 5 months ago

I'm fine with pr communication!

What I mean is mainly that we can just remove the system mode tests. Maybe also the build of the binary, since it's not really working other than as a toy.

SimonKagstrom commented 5 months ago

Good stuff! The tests feel much more proper now, and not like the plain hacks that they were before :-)

Anyway, I've looked through your changes, and I think they look good! Tell me when you're ready and I'll merge them!

perillo commented 5 months ago

Good stuff! The tests feel much more proper now, and not like the plain hacks that they were before :-)

Anyway, I've looked through your changes, and I think they look good! Tell me when you're ready and I'll merge them!

The PR is ready for merge.

However I would like to update the basic.lookup_binary_in_path test to use doCmd in

noKcovRv, o = self.do(self.sources + "/tests/python/main 5")

I avoided the change since I was not sure of it was a oversight to not set kcovKcov to False.

Additionally, I found that in this pattern

noKcovRv, o = self.doCmd(self.testbuild + "/executable")
rv, o = self.do(self.kcov + " " + self.outbase + "/kcov " + self.testbuild + "/executable", False)

a few tests don't set kcovKcov to True. There are no comments, so I'm not sure if this was the correct way or an oversight.

I checked the code using

> grep -A15 noKcovRv tests/tools/*.py`
perillo commented 5 months ago

I forgot to add a commit.

Fixed a typo in the commit message.

SimonKagstrom commented 5 months ago

Big thanks!

In general, if I remember correctly, the kcovKcov stuff was to avoid running kcov on itself when collecting data for compiled code, where it's not possible to trace kcov itself since it would mean recursive ptrace, which is illegal. Thus, coverage data on kcov itself can be collected when covering bash and python, but not for compiled code.