From 97a889e429d82d44ab0ec4f1dabcd6b98a60bfe0 Mon Sep 17 00:00:00 2001 From: Joseph Mirabel <jmirabel@laas.fr> Date: Fri, 15 Nov 2019 17:27:53 +0100 Subject: [PATCH] [Test] Reduce execution time of unit tests in debug mode. --- test/collision.cpp | 11 +++++++++++ test/distance.cpp | 10 ++++++++-- test/frontlist.cpp | 8 +++++--- test/obb.cpp | 7 +++++++ test/octree.cpp | 7 +++++++ test/profiling.cpp | 4 ++++ test/utility.cpp | 9 +++++++++ test/utility.h | 3 +++ 8 files changed, 54 insertions(+), 5 deletions(-) diff --git a/test/collision.cpp b/test/collision.cpp index 655ab790..da4655f6 100644 --- a/test/collision.cpp +++ b/test/collision.cpp @@ -63,6 +63,7 @@ #include "fcl_resources/config.h" using namespace hpp::fcl; +namespace utf = boost::unit_test::framework; int num_max_contacts = std::numeric_limits<int>::max(); @@ -587,7 +588,12 @@ BOOST_AUTO_TEST_CASE(mesh_mesh) { std::vector<Transform3f> transforms; FCL_REAL extents[] = {-3000, -3000, 0, 3000, 3000, 3000}; +#ifndef NDEBUG // if debug mode + std::size_t n = 1; +#else std::size_t n = 10; +#endif + n = getNbRun(utf::master_test_suite().argc, utf::master_test_suite().argv, n); generateRandomTransforms(extents, transforms, n); @@ -609,7 +615,12 @@ BOOST_AUTO_TEST_CASE(mesh_mesh_benchmark) { std::vector<Transform3f> transforms; FCL_REAL extents[] = {-3000, -3000, 0, 3000, 3000, 3000}; +#ifndef NDEBUG + std::size_t n = 0; +#else std::size_t n = 10; +#endif + n = getNbRun(utf::master_test_suite().argc, utf::master_test_suite().argv, n); generateRandomTransforms(extents, transforms, n); diff --git a/test/distance.cpp b/test/distance.cpp index dc4c2489..f575a49a 100644 --- a/test/distance.cpp +++ b/test/distance.cpp @@ -51,6 +51,7 @@ #include "fcl_resources/config.h" using namespace hpp::fcl; +namespace utf = boost::unit_test::framework; bool verbose = false; FCL_REAL DELTA = 0.001; @@ -96,7 +97,12 @@ BOOST_AUTO_TEST_CASE(mesh_distance) std::vector<Transform3f> transforms; // t0 FCL_REAL extents[] = {-3000, -3000, 0, 3000, 3000, 3000}; +#ifndef NDEBUG // if debug mode + std::size_t n = 1; +#else std::size_t n = 10; +#endif + n = getNbRun(utf::master_test_suite().argc, utf::master_test_suite().argv, n); generateRandomTransforms(extents, transforms, n); @@ -323,8 +329,8 @@ BOOST_AUTO_TEST_CASE(mesh_distance) } - std::cout << "distance timing: " << dis_time << " sec" << std::endl; - std::cout << "collision timing: " << col_time << " sec" << std::endl; + BOOST_TEST_MESSAGE("distance timing: " << dis_time << " sec"); + BOOST_TEST_MESSAGE("collision timing: " << col_time << " sec"); } template<typename BV, typename TraversalNode> diff --git a/test/frontlist.cpp b/test/frontlist.cpp index 9762d69b..6862d883 100644 --- a/test/frontlist.cpp +++ b/test/frontlist.cpp @@ -51,6 +51,7 @@ #include <boost/filesystem.hpp> using namespace hpp::fcl; +namespace utf = boost::unit_test::framework; template<typename BV> bool collide_front_list_Test(const Transform3f& tf1, const Transform3f& tf2, @@ -84,11 +85,12 @@ BOOST_AUTO_TEST_CASE(front_list) std::vector<Transform3f> transforms2; // t1 FCL_REAL extents[] = {-3000, -3000, 0, 3000, 3000, 3000}; FCL_REAL delta_trans[] = {1, 1, 1}; -#ifdef NDEBUG - std::size_t n = 20; +#ifndef NDEBUG // if debug mode + std::size_t n = 2; #else - std::size_t n = 5; + std::size_t n = 20; #endif + n = getNbRun(utf::master_test_suite().argc, utf::master_test_suite().argv, n); bool verbose = false; generateRandomTransforms(extents, delta_trans, 0.005 * 2 * 3.1415, transforms, transforms2, n); diff --git a/test/obb.cpp b/test/obb.cpp index fb4bd9a5..9b27360a 100644 --- a/test/obb.cpp +++ b/test/obb.cpp @@ -45,6 +45,7 @@ #include "../src/BV/OBB.h" #include "../src/distance_func_matrix.h" +#include "utility.h" using namespace hpp::fcl; @@ -1331,9 +1332,15 @@ std::size_t obb_overlap_and_lower_bound_distance(std::ostream* output) Vec3f T; CollisionRequest request; +#ifndef NDEBUG // if debug mode + static const size_t nbRandomOBB = 10; + static const size_t nbTransformPerOBB = 10; + static const size_t nbRunForTimeMeas = 10; +#else static const size_t nbRandomOBB = 100; static const size_t nbTransformPerOBB = 100; static const size_t nbRunForTimeMeas = 1000; +#endif static const FCL_REAL extentNorm = 1.; if (output != NULL) *output << BenchmarkResult::headers << '\n'; diff --git a/test/octree.cpp b/test/octree.cpp index 5632a496..135f19c0 100644 --- a/test/octree.cpp +++ b/test/octree.cpp @@ -49,6 +49,8 @@ #include "utility.h" #include "fcl_resources/config.h" +namespace utf = boost::unit_test::framework; + using hpp::fcl::Vec3f; using hpp::fcl::Triangle; using hpp::fcl::OBBRSS; @@ -136,7 +138,12 @@ BOOST_AUTO_TEST_CASE (OCTREE) std::vector<Transform3f> transforms; FCL_REAL extents[] = {-2000, -2000, 0, 2000, 2000, 2000}; +#ifndef NDEBUG // if debug mode + std::size_t N = 100; +#else std::size_t N = 10000; +#endif + N = hpp::fcl::getNbRun(utf::master_test_suite().argc, utf::master_test_suite().argv, N); generateRandomTransforms(extents, transforms, 2*N); diff --git a/test/profiling.cpp b/test/profiling.cpp index 2e96e4c8..16623c79 100644 --- a/test/profiling.cpp +++ b/test/profiling.cpp @@ -120,7 +120,11 @@ void printResults (const Geometry& g1, const Geometry& g2, const Results& rs) std::cout << g1.type << sep << g2.type << sep << mean << sep << std::sqrt(var) << sep << rs.times.minCoeff() << sep << rs.times.maxCoeff() << std::endl; } +#ifndef NDEBUG // if debug mode +int Ntransform = 1; +#else int Ntransform = 100; +#endif FCL_REAL limit = 20; bool verbose = false; diff --git a/test/utility.cpp b/test/utility.cpp index a107faf8..ca0debf7 100644 --- a/test/utility.cpp +++ b/test/utility.cpp @@ -444,6 +444,15 @@ std::ostream& operator<< (std::ostream& os, const Transform3f& tf) << " ]" ; } +std::size_t getNbRun (const int& argc, char const* const* argv, std::size_t defaultValue) +{ + for (int i = 0; i < argc; ++i) + if (strcmp(argv[i], "--nb-run") == 0) + if (i+1 != argc) + return (std::size_t)strtol(argv[i+1], NULL, 10); + return defaultValue; +} + } } // namespace hpp diff --git a/test/utility.h b/test/utility.h index dcefa684..97b3b335 100644 --- a/test/utility.h +++ b/test/utility.h @@ -178,6 +178,9 @@ Quaternion3f makeQuat(FCL_REAL w, FCL_REAL x, FCL_REAL y, FCL_REAL z); std::ostream& operator<< (std::ostream& os, const Transform3f& tf); +/// Get the argument --nb-run from argv +std::size_t getNbRun (const int& argc, char const* const* argv, std::size_t defaultValue); + } } // namespace hpp -- GitLab