Regression Testing for CLARAty


Regression Testing


Regression Testing Conventions in CLARAty


Example CppUnit Program in CLARAty (Thanks to Anne Wright)

// <sandbox>/src/points/utest_point
#include "claraty/common_defs.h"
#include "claraty/cppunit_defs.h"
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/extensions/HelperMacros.h>
#include "claraty/point_t.h"

// Create a class that contains the suite of tests
class Utest_Point : public CppUnit::TestFixture {

  // Macros expand to code that defines a registerTests() method
  // that registers the specified tests to this suite
  CPPUNIT_TEST_SUITE (Utest_Point);
  CPPUNIT_TEST (test_equality);
  CPPUNIT_TEST (test_math);
  CPPUNIT_TEST (test_failure);
  CPPUNIT_TEST_SUITE_END ();
  
  // Members that can be used throughout tests
  Point<double> _p, _q;

public:
  Utest_Point() : _p(5.3, 6.3, 1.2), _q(1.0, -1.0, 3.0) {
  }

  // Can define a setUp() method to initialize things
  // Will be called automatically
  // Preferable to put code here rather than constructor as CppUnit
  // will check for exceptions
  void setUp() { 
    ... 
  }

  // Can define a tearDown() method to clean up
  // Will be called automatically
  // Preferable to put code here rather than destructor as CppUnit
  // will check for exceptions
  void tearDown() {
    ...
  }

  void test_equality() {
    CPPUNIT_ASSERT( _p == _p );
    CPPUNIT_ASSERT( _p != _q );

    Point<double> pc(_p);
    CPPUNIT_ASSERT( _p == pc );

    Point<double> pe(_p.get_x(), _p.get_y(), _p.get_z());
    CPPUNIT_ASSERT( _p == pe );
    CPPUNIT_ASSERT( pc == pe );
  }    

  void test_math() {
    CPPUNIT_ASSERT(_p+_q == Point<double>(6.3, 5.3, 4.2));
    CPPUNIT_ASSERT(_p-_q == Point<double>(4.3, 7.3, -1.8));
    CPPUNIT_ASSERT(_p+_q == _q+_p);
    CPPUNIT_ASSERT(_p-_q == (_q*-1)+_p);
  }

  void test_failure() {
    CPPUNIT_ASSERT(_p == _q);
  }

};

int 
main(int argc, char** argv)
{
  // Create the test runner
  CppUnit::TextUi::TestRunner runner;
  // Add test suite to runner
  runner.addTest (Utest_Point::suite());

  CPPUNIT_SET_OUTPUT (argc, argv, runner);

  // run the test
  runner.run();

  // check the results
  CppUnit::TestResultCollector& result_collector = runner.result();
  // uncaught exceptions
  int num_errors = result_collector.testErrors();
  // failed tests
  int num_failures = result_collector.testFailures();

  // return the sum of errors and failures
  // 0 means success
  return num_errors + num_failures;
}

Sample Output

# build example CppUnit program
> cd /claraty/src/points
> setenv USE_CPPUNIT 1
> ymk all

# run the test
> ../../bin/Drun ix86-linux-gcc3.2-glibc2.3/utest_point
...F
 
!!!FAILURES!!!
Test Results:
Run:  3   Failures: 1   Errors: 0
 
 
1) test: 11Utest_Point.test_failure (F) line: 41 /home/gaines/projects/nightly_r8_rover/claraty/include/claraty/utest_point.h
 "_p == _q"

# confirm return value 
> echo $?
1

Other Useful CppUnit Features


Getting More Information on CppUnit


Notes on Regression Test Running

For each <arch>
  For each <module>
    cd <module>
    for each <program> in test_*
      number_of_errors = run <arch>/<program>
      log results

Notes

For VxWorks, will use Expect to interact with remote target. (E.g. reboot stack, load code, run test, check result)

Will need to handle programs crashing. E.g., on Linux, if the program seg faults test run is aborted and an error code is returned.

May need to run a watchdog to check for programs that appear to be in an infinite loop (e.g. no test is allowed to run for more than x minutes).


Transition Plan


Author: Dan Gaines
Last modified: Wed Feb 23 10:22:24 PST 2005