Skip to content

Commit

Permalink
Merge pull request #4712 from mvieth/improve_tests
Browse files Browse the repository at this point in the history
Fix/enable more output for intermittently failing tests
  • Loading branch information
mvieth committed May 6, 2021
2 parents d0d19b3 + 10190eb commit 1acca4b
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 23 deletions.
9 changes: 7 additions & 2 deletions registration/include/pcl/registration/impl/ia_fpcs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ pcl::registration::FPCSInitialAlignment<PointSource, PointTarget, NormalT, Scala
num_threads(nr_threads_)
{
#ifdef _OPENMP
std::srand(static_cast<unsigned int>(std::time(NULL)) ^ omp_get_thread_num());
const unsigned int seed =
static_cast<unsigned int>(std::time(NULL)) ^ omp_get_thread_num();
std::srand(seed);
PCL_DEBUG("[%s::computeTransformation] Using seed=%u\n", reg_name_.c_str(), seed);
#pragma omp for schedule(dynamic)
#endif
for (int i = 0; i < max_iterations_; i++) {
Expand Down Expand Up @@ -236,7 +239,9 @@ bool
pcl::registration::FPCSInitialAlignment<PointSource, PointTarget, NormalT, Scalar>::
initCompute()
{
std::srand(static_cast<unsigned int>(std::time(nullptr)));
const unsigned int seed = std::time(nullptr);
std::srand(seed);
PCL_DEBUG("[%s::initCompute] Using seed=%u\n", reg_name_.c_str(), seed);

// basic pcl initialization
if (!pcl::PCLBase<PointSource>::initCompute())
Expand Down
3 changes: 3 additions & 0 deletions test/registration/test_kfpcs_ia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ PointCloud<PointXYZI> cloud_source, cloud_target;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TEST (PCL, KFPCSInitialAlignment)
{
const auto previous_verbosity_level = pcl::console::getVerbosityLevel();
pcl::console::setVerbosityLevel(pcl::console::L_VERBOSE);
// create shared pointers
PointCloud<PointXYZI>::Ptr cloud_source_ptr, cloud_target_ptr;
cloud_source_ptr = cloud_source.makeShared ();
Expand Down Expand Up @@ -93,6 +95,7 @@ TEST (PCL, KFPCSInitialAlignment)
EXPECT_EQ (cloud_source_aligned.size (), cloud_source.size ());
EXPECT_NEAR (angle3d, 0.f, max_angle3d);
EXPECT_NEAR (translation3d, 0.f, max_translation3d);
pcl::console::setVerbosityLevel(previous_verbosity_level); // reset verbosity level
}


Expand Down
14 changes: 13 additions & 1 deletion test/sample_consensus/test_sample_consensus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,24 @@ TYPED_TEST(SacTest, InfiniteLoop)
SampleConsensusModelSpherePtr model (new SampleConsensusModelSphere<PointXYZ> (cloud.makeShared ()));
TypeParam sac (model, 0.03);

// This test sometimes fails for LMedS on azure, but always passes when run locally.
// Enable all output for LMedS, so that when it fails next time, we hopefully see why.
// This can be removed again when the failure reason is found and fixed.
int debug_verbosity_level = 0;
const auto previous_verbosity_level = pcl::console::getVerbosityLevel();
if (std::is_same<TypeParam, LeastMedianSquares<PointXYZ>>::value) {
debug_verbosity_level = 2;
pcl::console::setVerbosityLevel(pcl::console::L_VERBOSE);
}

// Set up timed conditions
std::condition_variable cv;
std::mutex mtx;

// Create the RANSAC object
std::thread thread ([&] ()
{
sac.computeModel (0);
sac.computeModel (debug_verbosity_level);

// Notify things are done
std::lock_guard<std::mutex> lock (mtx);
Expand All @@ -135,6 +145,8 @@ TYPED_TEST(SacTest, InfiniteLoop)
// release lock to avoid deadlock
lock.unlock();
thread.join ();

pcl::console::setVerbosityLevel(previous_verbosity_level); // reset verbosity level
}

int
Expand Down
12 changes: 9 additions & 3 deletions test/search/test_octree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ TEST (PCL, Octree_Pointcloud_Nearest_K_Neighbour_Search)
// instantiate point cloud
PointCloud<PointXYZ>::Ptr cloudIn (new PointCloud<PointXYZ> ());

srand (static_cast<unsigned int> (time (nullptr)));
const unsigned int seed = time (nullptr);
srand (seed);
SCOPED_TRACE("seed=" + std::to_string(seed));

std::priority_queue<prioPointQueueEntry, pcl::PointCloud<prioPointQueueEntry>::VectorType> pointCandidates;

Expand Down Expand Up @@ -173,7 +175,9 @@ TEST (PCL, Octree_Pointcloud_Approx_Nearest_Neighbour_Search)
// instantiate point cloud
PointCloud<PointXYZ>::Ptr cloudIn (new PointCloud<PointXYZ> ());

srand (time (NULL));
const unsigned int seed = time (nullptr);
srand (seed);
SCOPED_TRACE("seed=" + std::to_string(seed));

double voxelResolution = 0.1;

Expand Down Expand Up @@ -275,7 +279,9 @@ TEST (PCL, Octree_Pointcloud_Neighbours_Within_Radius_Search)
PointCloud<PointXYZ>::Ptr cloudIn (new PointCloud<PointXYZ> ());
PointCloud<PointXYZ>::Ptr cloudOut (new PointCloud<PointXYZ> ());

srand (static_cast<unsigned int> (time (nullptr)));
const unsigned int seed = time (nullptr);
srand (seed);
SCOPED_TRACE("seed=" + std::to_string(seed));

for (unsigned int test_id = 0; test_id < test_runs; test_id++)
{
Expand Down
8 changes: 6 additions & 2 deletions test/search/test_organized.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ TEST (PCL, Organized_Neighbor_Pointcloud_Nearest_K_Neighbour_Search)
// instantiate point cloud
PointCloud<PointXYZ>::Ptr cloudIn (new PointCloud<PointXYZ> ());

srand (int (time (nullptr)));
const unsigned int seed = time (nullptr);
srand (seed);
SCOPED_TRACE("seed=" + std::to_string(seed));

// create organized search
search::OrganizedNeighbor<PointXYZ> organizedNeighborSearch;
Expand Down Expand Up @@ -180,7 +182,9 @@ TEST (PCL, Organized_Neighbor_Pointcloud_Neighbours_Within_Radius_Search)
{
constexpr unsigned int test_runs = 10;

srand (int (time (nullptr)));
const unsigned int seed = time (nullptr);
srand (seed);
SCOPED_TRACE("seed=" + std::to_string(seed));

search::OrganizedNeighbor<PointXYZ> organizedNeighborSearch;

Expand Down
48 changes: 33 additions & 15 deletions test/search/test_organized_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <vector>
#include <cstdio>
#include <pcl/common/time.h>
#include <pcl/common/geometry.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
Expand All @@ -49,6 +48,16 @@ using namespace pcl;

std::string pcd_filename;

// Here we want a very precise distance function, speed is less important. So we use
// double precision, unlike euclideanDistance() in pcl/common/distances and distance()
// in pcl/common/geometry which use float (single precision) and possibly vectorization
template <typename PointT> inline double
point_distance(const PointT& p1, const PointT& p2)
{
const double x_diff = p1.x - p2.x, y_diff = p1.y - p2.y, z_diff = p1.z - p2.z;
return std::sqrt(x_diff * x_diff + y_diff * y_diff + z_diff * z_diff);
}

// helper class for priority queue
class prioPointQueueEntry
{
Expand Down Expand Up @@ -79,7 +88,9 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Nearest_K_Neighbour_Search)
// instantiate point cloud
PointCloud<PointXYZ>::Ptr cloudIn (new PointCloud<PointXYZ> ());

srand (time (NULL));
const unsigned int seed = time (nullptr);
srand (seed);
SCOPED_TRACE("seed=" + std::to_string(seed));

// create organized search
search::OrganizedNeighbor<PointXYZ> organizedNeighborSearch;
Expand Down Expand Up @@ -135,7 +146,7 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Nearest_K_Neighbour_Search)

for (auto it = cloudIn->begin(); it != cloudIn->end(); ++it)
{
const auto pointDist = geometry::distance(*it, searchPoint);
const auto pointDist = point_distance(*it, searchPoint);
prioPointQueueEntry pointEntry (*it, pointDist, std::distance(cloudIn->begin(), it));
pointCandidates.push (pointEntry);
}
Expand Down Expand Up @@ -174,7 +185,9 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Nearest_K_Neighbour_Search_Kinec

// instantiate point cloud

srand (time (NULL));
const unsigned int seed = time (nullptr);
srand (seed);
SCOPED_TRACE("seed=" + std::to_string(seed));

// create organized search
search::OrganizedNeighbor<PointXYZ> organizedNeighborSearch;
Expand Down Expand Up @@ -226,7 +239,7 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Nearest_K_Neighbour_Search_Kinec
// push all points and their distance to the search point into a priority queue - bruteforce approach.
for (auto it = cloudIn->begin(); it != cloudIn->end(); ++it)
{
const auto pointDist = geometry::distance(*it, searchPoint);
const auto pointDist = point_distance(*it, searchPoint);
prioPointQueueEntry pointEntry (*it, pointDist, std::distance(cloudIn->begin(), it));
pointCandidates.push (pointEntry);
}
Expand All @@ -251,7 +264,9 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search)
{
constexpr unsigned int test_runs = 10;

srand (time (NULL));
const unsigned int seed = time (nullptr);
srand (seed);
SCOPED_TRACE("seed=" + std::to_string(seed));
search::OrganizedNeighbor<PointXYZ> organizedNeighborSearch;

std::vector<int> k_indices;
Expand Down Expand Up @@ -299,7 +314,7 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search)

for (auto it = cloudIn->points.cbegin(); it != cloudIn->points.cend(); ++it)
{
const auto pointDist = geometry::distance(*it, searchPoint);
const auto pointDist = point_distance(*it, searchPoint);

if (pointDist <= searchRadius)
{
Expand All @@ -319,15 +334,15 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search)
// check if result from organized radius search can be also found in bruteforce search
for (const auto it : cloudNWRSearch)
{
auto const pointDist = geometry::distance((*cloudIn)[it], searchPoint);
const auto pointDist = point_distance((*cloudIn)[it], searchPoint);
ASSERT_LE (pointDist, searchRadius);
}


// check if bruteforce result from organized radius search can be also found in bruteforce search
for (const auto it : cloudSearchBruteforce)
{
const auto pointDist = geometry::distance((*cloudIn)[it], searchPoint);
const auto pointDist = point_distance((*cloudIn)[it], searchPoint);
ASSERT_LE (pointDist, searchRadius);
}

Expand All @@ -344,7 +359,8 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search)
TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search_Benchmark_Test)
{
constexpr unsigned int test_runs = 10;
srand (time (NULL));
const unsigned int seed = time (nullptr);
srand (seed);

search::OrganizedNeighbor<PointXYZ> organizedNeighborSearch;

Expand Down Expand Up @@ -396,7 +412,7 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search_

for (auto it = cloudIn->points.cbegin(); it != cloudIn->points.cend(); ++it)
{
const auto pointDist = geometry::distance(*it, searchPoint);
const auto pointDist = point_distance(*it, searchPoint);

if (pointDist <= searchRadius)
{
Expand Down Expand Up @@ -436,7 +452,9 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search_
return;
}
constexpr unsigned int test_runs = 10;
srand (time (NULL));
const unsigned int seed = time (nullptr);
srand (seed);
SCOPED_TRACE("seed=" + std::to_string(seed));

search::OrganizedNeighbor<PointXYZ> organizedNeighborSearch;

Expand Down Expand Up @@ -510,7 +528,7 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search_

for (auto it = cloudIn->points.cbegin(); it != cloudIn->points.cend(); ++it)
{
const auto pointDist = geometry::distance(*it, searchPoint);
const auto pointDist = point_distance(*it, searchPoint);

if (pointDist <= searchRadius)
{
Expand All @@ -522,15 +540,15 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search_
// check if result from organized radius search can be also found in bruteforce search
for (const auto it : cloudNWRSearch)
{
double pointDist = geometry::distance((*cloudIn)[it], searchPoint);
const auto pointDist = point_distance((*cloudIn)[it], searchPoint);
ASSERT_LE (pointDist, searchRadius);
}


// check if bruteforce result from organized radius search can be also found in bruteforce search
for (const auto it : cloudSearchBruteforce)
{
double pointDist = geometry::distance((*cloudIn)[it], searchPoint);
const auto pointDist = point_distance((*cloudIn)[it], searchPoint);
ASSERT_LE (pointDist, searchRadius);
}

Expand Down

0 comments on commit 1acca4b

Please sign in to comment.