Tuesday, 2 June 2015

WEEK 1: ESTABLISHING A TESTING FRAMEWORK !

Okay I accidentally labelled my previous post to be the work of week 1&2 which was supposed to be the community bonding.


SUMMARY(for you lazy fucks out there :P)

  • Zeroed to one testing framework which is super awesome - "ctypes". Smooth and sexy.
  • Way ahead(by 2 weeks) of timeline. Take a look at my proposal.
  • Looking forward to completing the main project in 3 weeks from now and then help with the plasma project and the fitting project.

LONG STORY

As I had mentioned in my previous blogpost I have restructured the C files and the mentor liked it. Early of this week it got merged. Now the task was to test the C files so that the can be called from the root of TARDIS with python setup.py test.

So basically the idea was to be able to call the C functions in python and test them. This isn't a good idea because it involves rewriting all the functions with wrappers in cython or some such glue and then again test. OVERKILL !
OR we could write the tests in C and then write wrappers for them in python. This is okay, because you have a standalone C library for Montecarlo and also callable from python.

But I ended up doing something much better. I found this amazing library in python called ctypes. I knew it earlier but just din't realise how powerful it was until I incorporated it in this amazing way. Checkout my pull request.

What it lets you do is, you can basically use any compiled C library(.so files and etc) as DLLs into python and use their modules. All this with one single line.

from ctypes import CDLL

tests = CDLL(test_path)
tests.test_rpacket_get_nu(double_value)

So this will run the function test_rpacket_get_nu in a C file(library) located at the test path.
The C function look somewhat like this:

bool test_rpacket_get_nu(double value){ rpacket_t * rp = (rpacket_t *) malloc(sizeof(rpacket_t)); rpacket_set_nu(rp, value); if( value != rpacket_get_nu(rp) ){ return false; } return true; }



So I have written the tests for Montecarlo as I would have written for any C library and then called all those functions from python.

In this PR I tested several simple getters and setters using this method. I hope to get my pull request merged in a day or two(if I stop blogging and start coding :P) and then work on with other functions which are not so easy to test(even in pure C) All in all Montecarlo testing should be done in a week and a half or so.

No comments:

Post a Comment