I'd like to use Haskell's quickcheck library test some C code. The easiest way seems to be doing a foreign import
and write a property on top of the resulting haskell function. The problem with this is that if the C code causes a segfault or manages to corrupt memory, my tests either crash without output or do something totally unpredictable.
The second alternative is to make simple executable wrappers over the C-bits and execute them outside the testing process via System.Process
. Needless to say, doing this requires a lot of scaffolding and serializing values, but on the other hand, it can handle segfaults.
Is there any way of making the foreign import
strategy as safe as running an external process?
You could implement the wrapper in your current process, but then use
System.Posix.Process.forkProcess
to run in safely in a process of its own, implementing the necessary communication using Haskell.