testing C code with python

B

Bilgehan.Balban

Hi,

A simple question - Is it common/good practice to test C code using
Python? For example one could wrap individual C functions, and test
each of them using python, maybe not for low-level things but at least
for algorithmic correctness. Anyone effectively doing this as common
practice?

Thanks,
Bahadir
 
P

Peter Hansen

A simple question - Is it common/good practice to test C code using
Python? For example one could wrap individual C functions, and test
each of them using python, maybe not for low-level things but at least
for algorithmic correctness. Anyone effectively doing this as common
practice?

I doubt this is common practice (in general), but at a previous company
we developed a tool that let us write tests in Python, which would then
call into C code which was executing in the form of object code (in an
S19 file) running inside a simulated microcontroller CPU (68HC12) which
was itself implemented in Python.

I realize that doesn't help you, but I just thought I'd mention it,
because it was a heck of a lot of fun writing it. :)

-Peter
 
R

Ruben Charles

Take a look at swig.org

There are some examples for testing C code y python and/or extend
python with C functions.
 
S

Scott David Daniels

A simple question - Is it common/good practice to test C code using
Python?

I certainly do such testing (hand-wrapped, because it doesn't
seem to cost too much time to do so. Usually I develop in Python
and accumulate my tests there, then write the C equivalent, and
move the tests to the C code. I've done this for programs that
were always to have become C programs as well as for those things
I intend to wrap as Python modules.
 
C

christopherlmarshall

I have recently started using tcl to do this with C++ code and will
soon be switching to doing it with python.

I think it is a fantastic way to arrange to test C++ and C code.
Python makes an excellent test-harness, and writing interfaces for
complex units of C++ code to enable them to be tested from Python is an
valuable exercise in itself. It forces you to make your code
inspectable and brings up all sorts of important design issues that
otherwise would never occur to you.

It was a lot of work to get started with this but once you put in the
initial effort, it gets eaiser to maintiain. And the payoff is that it
lets you write regression tests easily so that would be too hard to do
otherwise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,270
Messages
2,571,351
Members
48,036
Latest member
nickwillsonn

Latest Threads

Top