Review Board 2.0.15


RefCount: Add a unit test for reference counting pointers.

Review Request #365 - Created Jan. 3, 2011 and submitted

Information
Gabe Black
gem5
Reviewers
Default
ali, gblack, nate, stever
RefCount: Add a unit test for reference counting pointers.

This test exercises each of the functions in the reference counting pointer
implementation individually (except get()) and verifies they have some
minimially expected behavior. It also checks that reference counted objects
are freed when their usage count goes to 0 in some basic situations,
specifically a pointer being set to NULL and a pointer being deleted.

   
Review request changed
Updated (Jan. 3, 2011, 4:56 a.m.)
Ship it!
Posted (Jan. 3, 2011, 12:33 p.m.)
I have some suggestions, but overall, it looks good.  It would be nice to at least have the return value of the test indicate success or failure as it would be nice to actually include these in the regressions in the future.  Thanks!
src/unittest/refcnttest.cc (Diff revision 2)
 
 
This diff looks overall correct, though the use of assert to do this is a bit odd.  Perhaps replace assert with something more like (though it might not be very meaningful without a description of what you're testing to go with it):

#define test(X) do {
bool test = (X);
cprintf("%-7s (line %3d) %s\n", test ? "SUCCESS" : "FAIL", __LINE__, #X);
if (!test) {
    Debug::break();
    failures++;
}
} while (0)

at the exit of main(), i'd print "total failures" and also do "return !!failures"  "!!x" is equivalent to x ? 1 : 0 or int(bool(x)), if you don't like the shorthand.
Posted (Jan. 4, 2011, 9:02 a.m.)
It's pretty good. I think Nate's suggestion is great and maybe a little comment before each test "// Test setting variable to NULL lowers ref count" would be great.