Bob
Bob

Reputation: 4980

how to run gcov on bare metal (without file system)

I'm running C++ on Cortex M4 and I want to start doing automated unit tests and coverage.

gcov writes its output files - .gcno, .gcda - on the target which is a no-go because I don't have a filesystem.

QUESTION

Is it possible to "intercept and redirect" these writes to the PC using gdb?

I want to automate these tests via a Python script:

  1. Get unit test from data base
  2. Compile
  3. Transfer to target board
  4. Run
  5. Redirect results to PC

Upvotes: 2

Views: 1944

Answers (2)

Strooom
Strooom

Reputation: 3

You can try a technique called semihosting : the file I/O is then being redirected over the debug probe to the host computer.

Upvotes: 0

Alceste_
Alceste_

Reputation: 614

So, I didn't know gcov, thank you.

A quick look at man gcov showed that I had it on my system and that the following option exists:

-t, --stdout Output to stdout instead of a file

I haven't done python in a while, but you should be able to create a memory-only file, and, supposing the opened file handle is 8, use:

gcov -t [whatever you are doing] >&8

The -t argument tells gcov to print to the standard output instead of writing to a file, and >&8 overwrites stdout (as seen by the executed program) to be file handle 8 instead of 1 (on most unix/posix/whateveryoucallit, anyway).

That is of course in bash, which you can either invoke from python, or transcode to however you achieve this in python.

I haven't got to try it, so if it helps (or if it doesn't) make sure to leave a mark to help future readers.

Upvotes: 0

Related Questions