Create test for thread creation on WindowsBRL-CAD
Status: ClosedTime to complete: 48 hrs Mentors: SeanTags: C, testing, multithreading, windows

This is a follow-on of a previous GCI task:

  • http://www.google-melange.com/gci/task/view/google/gci2012/8030203

Your task is to test whether that thread creation actually works correctly.  Write a small test program that calls bu_parallel() and calls a function N times.

You can submit this as a partial unit test for parallel.c by adding a new test file similar to several other existing files.  You can write the test on any platform, but ideally you'll have access to a clean Windows build so that you can specifically test the new Windows thread creation.

Code:

  • src/libbu/tests/CMakeLists.txt
  • src/libbu/tests/test_parallel.c  -- you write this, test bu_parallel()

 

Uploaded Work
File name/URLFile sizeDate submitted
parallel-test.patch1.9 KBJanuary 08 2013 17:28 UTC
parallel-test.patch2.1 KBJanuary 08 2013 17:44 UTC
parallel-test.patch2.1 KBJanuary 09 2013 03:49 UTC
parallel-sans-arg.patch1.9 KBJanuary 09 2013 03:49 UTC
parallel-test.patch3.5 KBJanuary 09 2013 11:04 UTC
Comments
Skriptkidon January 8 2013 12:02 UTCTask Claimed

I would like to work on this task.

Erik on January 8 2013 14:37 UTCTask Assigned

This task has been assigned to Skriptkid. You have 48 hours to complete this task, good luck!

Skriptkidon January 8 2013 15:04 UTCTest

The test files are run when "make test" is run right? And in Windows, if ALL_BUILD is used to build BRL-CAD, is "test" also run?

Skriptkidon January 8 2013 15:55 UTCFunction

"that calls bu_parallel() and calls a function N times." Create a function in the test file and call it through bu_parallel?

Skriptkidon January 8 2013 17:28 UTCReady for review

The work on this task is ready to be reviewed.

Sean on January 8 2013 18:51 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Skriptkidon January 8 2013 18:56 UTCWork

What's the needed work?

Sean on January 8 2013 19:29 UTCfew minor issues

Noticed a few minor issues:



  • file header has wrong file name

  • paren in wrong after the if(argc... line

  • should be spaces after if ( and for (

  • what's the reason for argv[1]?  It obviously runs bu_parallel() N times, but what for?

  • you don't test any other values of argv[2]

  • you should make sure argc is sufficient before accesing argv[1] and argv[2] respectively

Skriptkidon January 9 2013 03:49 UTCFixed

First three were issues, which are now corrected, but 4 and 5 are there intentionally. argv[1] is the number of times bu_parallel is run("N") and argv[2] is the no. of CPUs available(which is also the number of threads created by parallel, unless that many are not available.) Both of these are passed through CMakeLists.txt in addtest(... ... N no-of-CPUs.) If you're saying this is not needed, I'l upload two versions, one with arguments being passed and the other without. The no of CPUs have to be passed since bu_parallel takes (void *func)(int ncpu, genptr arg) Also, the no of argc is being tested. (if (argc 3)) If some changes still need to be made, I'll do it.

Skriptkidon January 9 2013 03:50 UTCReady for review

The work on this task is ready to be reviewed.

Sean on January 9 2013 05:19 UTCnot what I was saying

I wasn't saying that passing N and no-of-CPUs  aren't needed.  I was asking *why* are you running bu_parallel N times?


I was also asking why you only test no-of-CPUs=1?  Why not also test 2, 10, 42...


You're not really testing bu_parallel() very well to only test creation of 1 parallel context.

Sean on January 9 2013 05:19 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Skriptkidon January 9 2013 10:49 UTCMisunderstanding

There's probably a misunderstanding on my part. The task description says "that calls bu_parallel and calls a function N times." What does this mean? What I've understood is that you need to pass a test function to bu_parallel and run it N times, which is why I've put bu_parallel in a loop that runs N times and calls bu_parallel each time, passing the test function to it. 


The CPUs part, I had forgotten. I'll add some more tests. Any specific number required?

Skriptkidon January 9 2013 11:06 UTCReady for review

The work on this task is ready to be reviewed.

Skriptkidon January 9 2013 11:07 UTCNew test

The latest patch has some more(25 more) tests. I haven't fixed the "N times" part yet, because I'm waiting for someone to answer that.

Sean on January 9 2013 20:29 UTCTask Closed

Congratulations, this task has been completed successfully.

Sean on January 9 2013 20:37 UTCunnecessary tests

I think there is some misunderstanding on your part of what bu_parallel() does.  All of the additional tests you added are rather unnecessary (unhelpful even) and I think just reinforce the misunderstanding for what the two parameters you've defined actually do.  Calling bu_parallel() just one time runs a function X times in parallel.  So in actuality, you only needed to have your test program call bu_parallel once.  It's okay to re-run it in a loop but from a testing perspective, you have to think about what it's testing and hoping to catch.


On that point, your test should have included some means to verify that bu_parallel() actually ran a function X times but I let it pass since you got enough scaffolding in place for us to make that edit.  You run it and print a message, but don't actually have the program test anything (beyond it compiles and didn't crash).  A human becomes the tester, needing to read the print statements and discern if anything is wrong.  Still, easy to fix.


Thanks for your efforts.  Again, it's a good stub to get us started (and why it's worth closing).  You've put good work in spite of the misunderstanding. ;)