opensim-core icon indicating copy to clipboard operation
opensim-core copied to clipboard

Convert all tests to the `Catch2` framework

Open nickbianco opened this issue 2 years ago • 2 comments

Current testing in OpenSim uses a variety of implementations and code styles. Most of the tests for Moco use Catch2, and since the Moco merge, we've been sporadically converting OpenSim tests to this new framework. This epic proposes that we convert all the OpenSim tests to Catch2 to unify the testing suite, speed up development (i.e., isolating and re-running only failed tests), and make adding new tests easy. This should be a "many hands make light work" approach, where we divide up the tests to be converted across several individual issues that separate members of the dev team can tackle.

Tasks

Phase 1: Convert existing code to minimally use Catch

  • For each .cpp file in the list below:

    • #include <catch2/catch_all.hpp>
    • Minimally convert each test function to use TEST_CASE("test name")
    • Remove existing main function (catch automates calling each case)
    • Put helper functions in an anonymous namespace (namespace {})
    • Check+commit - mention this issue (#3555) in the commit message if you want it to appear in GitHub
    • PR

Phase 2: Update any build/contribution guides to mention the change

  • [ ] Standardize how tests are added via CMake macros (if needed)
  • [ ] Update CONTRIBUTING.MD with guidelines for writing Catch2 tests (and links to Catch2 docs)
  • [ ] Decide if any changes needed for Java/Matlab/Python tests

Phase 3: Improve assertions and test framework usage

  • For each cpp file in the list below:

    • Update assertions to use catch assertions, instead of OpenSim/SimTK assertions (they provide better testing feedback)
    • Parameterize tests etc. where possible using catch's conventions
    • If other testing macros are necessary, consolidate them under Auxiliary or Common (i.e., remove OpenSim/Moco/Test/Testing.h

Phase 1 CPP todo List

  • [x] Actuators\
    • [x] Test\testActuators.cpp - #3684
    • [x] Test\testDeGrooteFregly2016Muscle.cpp
    • [x] Test\testModelProcessor.cpp
    • [x] Test\testMuscleFirstOrderActivationDynamicModel.cpp - #3691
    • [x] Test\testMuscleFixedWidthPennationModel.cpp
    • [x] Test\testMuscles.cpp
    • [x] Test\testSerializableMuscleCurves.cpp
  • [ ] Analyses\
    • [x] Test\testOutputReporter.cpp
  • [ ] Common\ - (@adamkewley : I'll start with this one)
    • [x] Test\testAPDMDataReader.cpp
    • [x] Test\testAssertion.cpp
    • [ ] Test\testC3DFileAdapter.cpp - skip: not built by default
    • [x] Test\testComponentInterface.cpp
    • [x] Test\testDataTable.cpp
    • [x] Test\testFunctionAdapter.cpp
    • [x] Test\testFunctions.cpp
    • [x] Test\testGCVSpline.cpp
    • [x] Test\testLatinHypercubeDesign.cpp
    • [x] Test\testMarkerData.cpp
    • [x] Test\testNCSpline.cpp
    • [x] Test\testPath.cpp
    • [x] Test\testRootSolver.cpp
    • [x] Test\testSerialization.cpp
    • [x] Test\testSmoothSegmentedFunctionFactory.cpp
    • [x] Test\testSTOFileAdapter.cpp
    • [x] Test\testStorage.cpp - #3557
    • [x] Test\testTRCFileAdapter.cpp
    • [x] Test\testXsensDataReader.cpp
  • [x] Moco\
    • [x] Archive\Tests\test2Muscles1DOFDeGrooteFregly2016.cpp - #3562
    • [x] Archive\Tests\test2Muscles2DOFsDeGrooteFregly2016.cpp
    • [x] Archive\Tests\testGait10dof18musc.cpp
    • [x] Archive\Tests\testHangingMassRoundtrip.cpp
    • [x] Archive\Tests\testMultivariatePolynomial.cpp
    • [x] Archive\Tests\testSingleMuscle.cpp
    • [x] Archive\Tests\testSingleMuscleDeGrooteFregly2016.cpp
    • [x] Archive\Tests\testSingleMuscleDeGrooteFregly2016MomentArms.cpp
    • [x] Archive\Tests\testTugOfWarDeGrooteFregly2016.cpp
    • [x] Test\testMocoActuators.cpp - #3558
    • [x] Test\testMocoAnalytic.cpp
    • [x] Test\testMocoConstraints.cpp
    • [x] Test\testMocoContact.cpp
    • [x] Test\testMocoGoals.cpp
    • [x] Test\testMocoImplicit.cpp
    • [x] Test\testMocoInterface.cpp
    • [x] Test\testMocoInverse.cpp
    • [x] Test\testMocoMetabolics.cpp
    • [x] Test\testMocoParameters.cpp
    • [x] Test\testMocoTrack.cpp
  • [ ] Simulation\
    • [x] SimbodyEngine\Test\testConstraints.cpp
    • [x] SimbodyEngine\Test\testJoints.cpp
    • [x] Test\testAssemblySolver.cpp
    • [x] Test\testContactGeometry.cpp
    • [x] Test\testForces.cpp
    • [x] Test\testFrames.cpp
    • [x] Test\testInitState.cpp
    • [x] Test\testInverseKinematicsSolver.cpp
    • [x] Test\testManager.cpp
    • [x] Test\testModelInterface.cpp
    • [x] Test\testMomentArms.cpp
    • [x] Test\testMuscleMetabolicsProbes.cpp
    • [x] Test\testNestedModelComponents.cpp
    • [x] Test\testPoints.cpp
    • [x] Test\testPointToPointSpring.cpp
    • [x] Test\testPrescribedForce.cpp
    • [x] Test\testProbes.cpp
    • [x] Test\testReportersWithModel.cpp
    • [x] Test\testSimulationUtilities.cpp
    • [x] Test\testStatesTrajectory.cpp
    • [x] Test\testTableProcessor.cpp
  • [ ] Tests\
    • [ ] AddComponents\testAddComponents.cpp
    • [ ] Components\testComponents.cpp
    • [ ] ConstantCurvatureExample\testConstantCurvature.cpp
    • [ ] ControllerExample\testControllerExample.cpp
    • [ ] CustomActuatorExample\testCustomActuatorExample.cpp
    • [ ] ExampleMain\testExampleMain.cpp
    • [ ] MuscleExample\testMuscleExample.cpp
    • [ ] OptimizationExample_Arm26\testOptimizationExample.cpp
    • [ ] README\testREADME.cpp
    • [ ] SimpleOptimizationExample\testSimpleOptimizationExample.cpp
    • [ ] testIterators\testIterators.cpp
    • [ ] testMemoryLeaks\testMemoryLeaks.cpp
    • [ ] Wrapping\testWrapCylinder.cpp
    • [x] Wrapping\testWrapping.cpp
    • [ ] Wrapping\testWrappingAlgorithm.cpp
    • [ ] Wrapping\testWrapping_Deprecated.cpp
  • [ ] Tools\
    • [ ] Test\testControllers.cpp
    • [ ] Test\testExternalLoads.cpp
    • [ ] Test\testModelCopy.cpp
    • [ ] Test\testSerializeOpenSimObjects.cpp
    • [ ] Test\testVisualization.cpp
  • [x] Vendors\ - #3580
    • [x] lepton\test\testLepton.cpp
    • [x] tropter\tests\test_analytic_optimal_control_solutions.cpp
    • [x] tropter\tests\test_derivatives.cpp
    • [x] tropter\tests\test_double_pendulum.cpp
    • [x] tropter\tests\test_eigen_adolc_reverse_mode.cpp
    • [x] tropter\tests\test_generic_optimization.cpp
    • [x] tropter\tests\test_optimal_control_initial_guess.cpp
    • [x] tropter\tests\test_parameter_optimization.cpp
    • [x] tropter\tests\test_path_contraints.cpp
    • [x] tropter\tests\test_sliding_mass_minimum_effort.cpp
    • [x] tropter\tests\test_sliding_mass_minimum_time.cpp
    • [x] tropter\tests\test_snopt.cpp

nickbianco avatar Sep 14 '23 15:09 nickbianco

List created with hacky script:

import os
import itertools

srcdir = 'C:\\Users\\adamk\\Desktop\\opensim-core\\OpenSim'

all = []
for root, subdirs, files in os.walk(srcdir):
    for file in files:
        if file.lower().startswith('test') and file.lower().endswith('cpp'):
            p = os.path.relpath(os.path.join(root, file), srcdir)
            all.append(p)

for k, g in itertools.groupby(all, lambda el: el.split(os.path.sep)[0]):
    print(f'- [ ] {k}{os.path.sep}')
    for el in g:
        rest = os.path.sep.join(el.split(os.path.sep)[1:])
        print(f'    - [ ] {rest}')

adamkewley avatar Sep 15 '23 08:09 adamkewley

@adamkewley I added some tests under /Vendors that your script missed.

nickbianco avatar Sep 19 '23 17:09 nickbianco