Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quickchecking a nasty foreign function in Haskell(GHC)

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?

like image 243
aleator Avatar asked Aug 08 '14 10:08

aleator


1 Answers

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.

like image 82
Joachim Breitner Avatar answered Sep 17 '22 14:09

Joachim Breitner