C function call and parameter tracking - test case and false data generation

I have a large code base of fairly old code on an embedded system and, unfortunately, there are no automatic test cases / suites. This makes the problem of restructuring and reorganization a dangerous task.

Manually writing test cases is very time-consuming, so I thought it’s possible, for example, to automate at least part of this process by tracking all function calls and writing down input and output values. Then I could use these values ​​in test cases (this would not work for everyone, but at least for some functions). It is probably also possible to create mock functions based on the data collected.

The presence of such tests will result in a reorganization of less hazardous activities.

Are there any solutions that can already do this? What would be the easiest way to make this work if I have to code it myself?

I was thinking about using ctags to find function definitions and wrap them in a function that writes parameter values. Another option might be the gcc compiler plugin.

+8
c unit-testing mocking tracing
source share
1 answer

There is the gcc -finstrument-functions option, the mechanism of which you can use to define your own callbacks for each funtion entry / exit.

Google, and you can find many good examples.

[Edit] With this call to the gcc function, you can only track the on / off of the function, not the parameters. but with some tricks you can also track parameters. (follow the current frame pointer to get the parameter on the stack).

Here is an article on implementation idea:

http://linuxgazette.net/151/melinte.html

Also, depending on your embedded system, on linux, you might try something like ltrace to show options (e.g. strace path). There are many tools that work in tracing functions in user space or in kernelspace on linux, ftrace / ust / ltrace / utrace / strace / systemtap /. In any case, if you do not add a hard debugging code, it is not possible to display the parameters correctly. If you take steps to add I / O debugging information, then this is much simpler.

There is also a similar thread dedicated to this issue.

A tool for tracking local function calls in Linux

+1
source share

All Articles