0

I am testing a library that monitors USB stick and allows listening to plugin/plugout events. The target system runs a custom Linux version and debugging is a pain on this system

So, for quick analysis of what is going, I very often use printf messages.

For unit testing of the library, I have started using Catch and I generate test reports using JUint reporter.

Problem: If I insert aprintf message for analysis, it gets added to the xml report generated by Catch.

My question: Is there a way to separate printf messages and the report generated by Catch?

Thanks.

UPDATE: I want to avoid writing to a file, because I've had problems with it when there are errors and the program crashes before the file is completely written to.

3 Answers3

1

Not really familiar with Catch, but an obvious solution is to print to a non-standard location. So, e.g., fopen a log file and fprintf there instead of to standard output.

Also, quite unrelated to your question, but may help you with your problem, you can use gdbserver to debug on the platform. Just search for "gdbserver remote debugging" for instructions on how to do that.

Edited to add: If you're worried that the file will get truncated in case of a crash, just replace "printf" with a wrapper that also does fflush.

Shachar Shemesh
  • 8,193
  • 6
  • 25
  • 57
  • I have restated my question to reflect what I am exactly looking for. And regarding use of file, I thought about this method and I will indeed do this if it turns out that there is no other easy solution. – Bilal Chughtai Sep 29 '17 at 14:17
1

There is an another way.

You could print your debug messages to stderr instead of stdout using fprintf like this:

fprintf(stderr, "%d\n", c);

Since Catch's report is written to stdout you can then dismiss your output using redirection, e.g. on Linux systems:

./a.out -r junit 2> /dev/null
Daniel Trugman
  • 8,186
  • 20
  • 41
  • I tried this out, but Catch also captures std-err. The debug messages get added to a special tag in XML named "system-err" or "system-out". – Bilal Chughtai Oct 01 '17 at 12:20
  • Are you sure this is not as a result of your configuration? I'm doing this exact thing and it works for me... – Daniel Trugman Oct 01 '17 at 12:29
  • Okay it worked now. I didn't try redirection as I don't understand how it can effects catch's output file. That's confusing for me. But your solution has worked. Thank you! – Bilal Chughtai Oct 02 '17 at 13:44
0

If you are ok with writing the output to file, there is an easy solution. Use the -o option to change where Catch places its output.

You can either use it as -o report.xml to have the output be placed in a file called report.xml, or you can use a special file called %debug. When passed %debug as the output file, Catch attempts to write to whatever debugging facility it knows for given platform, which is stderr for Android.

Xarn
  • 3,460
  • 1
  • 21
  • 43