Code coverage using openmsx

By ricbit

Champion (438)

ricbit's picture

05-08-2017, 18:44

Just sharing a nice idea I had today:

I wanted to make my json parsing library as bug-free as possible, for that reason I wrote a comprehensive set of unit tests for it. However I wasn't sure if I covered all use cases, so I made a small code coverage tool using openmsx.

The idea is to set watchpoints and log all addresses being executed, then a python script combines the log with the .lst file generated by sjasmplus to provide a visualization of the code. Here's the output:

http://www.ilafox.com.br/ricbit/coverage_error.html

As you can see, this uncovered a bug! When I optimized the code by size, I wrongly put an INC on D00C, but it was supposed to be a DEC. On the turboR this didn't triggered a bug, because by coincidence the register A was non-zero when USR was called. But it could break in other machines. The coverage tool pointed correctly that D02E was never executed, and I was able to fix the bug :)

The tool is available as coverage.tcl and coverage.py on the msxjson repository, very simple:

https://github.com/ricbit/msxjson

Login or register to post comments

By ricbit

Champion (438)

ricbit's picture

05-08-2017, 18:47

Also, it would be nice if $wp_last_address was documented on the openmsx manual. I had to dig the source code to find it. Very useful when you're watching a range, such as {0xD000 0xD400}, to know which address actually triggered the breakpoint.

By wouter_

Champion (508)

wouter_'s picture

05-08-2017, 21:50

Very nice. I always love it when openmsx scripting is used in (for me) unexpected ways.

And yes, some of this stuff could be documented better. I'll add some more documentation on watchpoints. Let us know which other parts need more documentation. (Or send us documentation patches.)