1

I am attempting to write a python script which runs a .c test suite, and needs to track the number of times a line of code is executed in failing cases. My plan is to start by setting a return value of the individual .c tests to -1 in failing cases, and then eventually implement gcov to find the lines being executed. I am new to python as well as fundamental testing methods, but I am sure there is a simple way to implement this. How would I find the return value or is there a better way to do this?

zdevita
  • 121
  • 6
  • The [`subprocess`](https://docs.python.org/3/library/subprocess.html) module is the way to run new processes. e.g. `subprocess.call()` will return the edit code. – Martin Tournoij Mar 11 '16 at 01:44
  • Possible duplicate of [Calling an external command in Python](http://stackoverflow.com/questions/89228/calling-an-external-command-in-python) – Martin Tournoij Mar 11 '16 at 01:45
  • 1
    There are two ways you could be trying to do this. First, by compiling and linking an *entirely separate* program that is written in 'C'. Second, by compiling C code into a library or shared object and dynamically loading that into Python. To start with, you should probably work on the first model, but if your intention is the second please say so. – aghast Mar 11 '16 at 01:54
  • So using the subprocess.call() will return the return value from the unit test. i.e. err=subprocess.call ( source_file.c ) , then err would equal -1 in a failing case. – zdevita Mar 11 '16 at 01:54
  • The first way seems feasible. I am a little lost on what the separate .c program needs to do or why its necessary. – zdevita Mar 11 '16 at 02:01

0 Answers0