Google Test is a unit testing framework, yes. I'm using it in a rather simple way, and on a small part of my codebase -- for now. Here's an example test function I've used just to test my compile/link/runtime of the libppmac bits (breaking several Test-Driven Development "rules"):
TEST(SHM_Test, SetAndClearMotor1ServoCtrl) {
ASSERT_THAT(InitLibrary(), Eq(0)); // gplib init must return 0 to proceed
struct SHM *pshm = GetSharedMemPtr(); // get pointer to SHM
pshm->Motor[1].ServoCtrl = 1; // set ServoCtrl to 1
ASSERT_THAT(pshm->Motor[1].ServoCtrl, Eq(1)); // Check that the value is now 1
pshm->Motor[1].ServoCtrl = 0; // set ServoCtrl to 0
ASSERT_THAT(pshm->Motor[1].ServoCtrl, Eq(0)); // Check that the value is now 0
CloseLibrary(); // clean up in gplib
}
Here's the main() function which is used to run the tests:
// includes , , , ...
int main(int argc, char **argv) {
std::chrono::time_point time_point;
time_point = std::chrono::system_clock::now();
std::time_t ttp = std::chrono::system_clock::to_time_t(time_point);
std::cout << "Start time: " << std::ctime(&ttp) << "\n";
::testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();
time_point = std::chrono::system_clock::now();
ttp = std::chrono::system_clock::to_time_t(time_point);
std::cout << "End time: " << std::ctime(&ttp) << "\n";
return 0;
}
And the output from running it (with one other test defined):
./shmtest.out
Start time: Tue Sep 29 01:05:59 2015
[==========] Running 2 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 2 tests from SHM_Test
[ RUN ] SHM_Test.SetAndClearMotor1ServoCtrl
[ OK ] SHM_Test.SetAndClearMotor1ServoCtrl (22 ms)
[ RUN ] SHM_Test.ReadsMotor1ActPos
-- Motor[1] Position: 3963
[ OK ] SHM_Test.ReadsMotor1ActPos (21 ms)
[----------] 2 tests from SHM_Test (46 ms total)
[----------] Global test environment tear-down
[==========] 2 tests from 1 test case ran. (51 ms total)
[ PASSED ] 2 tests.
End time: Tue Sep 29 01:05:59 2015
There was quite a bit of muddling to get here, and some things I still don't completely understand (all the xenomai stuff as a start). Note also I'm not cross-compiling here, everything is being built directly on the PMAC Debian Sid chroot. This should be easy to improve, using schroot and debootstrap on a Debian/Ubuntu workstation with crossbuild-essential-powerpc. Compiling on the PMAC is sloooow.
Also note the tests above take >20ms each to run. That time includes Google Test creating a new thread, running InitLibrary, running the tests, and then CloseLibrary. I will be doing performance testing and figuring out where the slowdowns are in my actual application classes. If it takes that long to InitLibrary, that will certainly help determine how and when I use the shared memory!
- Luke