testing C code with python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bilgehan.Balban@gmail.com

    #1

    testing C code with python

    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

  • Peter Hansen

    #2
    Re: testing C code with python

    Bilgehan.Balban @gmail.com wrote:[color=blue]
    > 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?[/color]

    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

    Comment

    • Ruben Charles

      #3
      Re: testing C code with python

      On 11/10/05, Peter Hansen <peter@engcorp. com> wrote:[color=blue]
      > Bilgehan.Balban @gmail.com wrote:[color=green]
      > > 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?[/color][/color]

      Take a look at swig.org

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

      Comment

      • Scott David Daniels

        #4
        Re: testing C code with python

        >Bilgehan.Balba n@gmail.com wrote:[color=blue]
        > A simple question - Is it common/good practice to test C code using
        > Python?[/color]

        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.

        --
        -Scott David Daniels
        scott.daniels@a cm.org

        Comment

        • christopherlmarshall@yahoo.com

          #5
          Re: testing C code with python

          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.

          Comment

          Working...