From 55d06241b35505f371aa1d41a4332cdf1edc9cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Tue, 23 Jun 2020 08:51:32 +0200 Subject: [PATCH] fix unit tests: do not stub pthread_cond_wait and fix the tests instead. Some unit tests depend on pthread_cond_wait to work as expected. --- .../posix/src/px4/common/test_stubs/CMakeLists.txt | 1 - .../src/px4/common/test_stubs/stub_parameter.cpp | 11 ----------- .../posix/src/px4/common/test_stubs/stub_parameter.h | 8 -------- src/lib/avoidance/ObstacleAvoidanceTest.cpp | 1 + .../collision_prevention/CollisionPreventionTest.cpp | 1 + src/lib/parameters/ParameterTest.cpp | 1 + 6 files changed, 3 insertions(+), 20 deletions(-) delete mode 100644 platforms/posix/src/px4/common/test_stubs/stub_parameter.cpp delete mode 100644 platforms/posix/src/px4/common/test_stubs/stub_parameter.h diff --git a/platforms/posix/src/px4/common/test_stubs/CMakeLists.txt b/platforms/posix/src/px4/common/test_stubs/CMakeLists.txt index 8b8c0ad9b7..1a3335a05c 100644 --- a/platforms/posix/src/px4/common/test_stubs/CMakeLists.txt +++ b/platforms/posix/src/px4/common/test_stubs/CMakeLists.txt @@ -33,7 +33,6 @@ set(SRCS stub_daemon.cpp - stub_parameter.cpp ) px4_add_library(test_stubs ${SRCS}) diff --git a/platforms/posix/src/px4/common/test_stubs/stub_parameter.cpp b/platforms/posix/src/px4/common/test_stubs/stub_parameter.cpp deleted file mode 100644 index 769d8d8010..0000000000 --- a/platforms/posix/src/px4/common/test_stubs/stub_parameter.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "stub_parameter.h" - - - -extern "C" { - /* This function blocks forever in tests, so override it with a version that can be customized */ - int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) - { - return stub_pthread_cond_wait_callback(cond, mutex); - } -} diff --git a/platforms/posix/src/px4/common/test_stubs/stub_parameter.h b/platforms/posix/src/px4/common/test_stubs/stub_parameter.h deleted file mode 100644 index 57a709b547..0000000000 --- a/platforms/posix/src/px4/common/test_stubs/stub_parameter.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include - -#include - -std::function stub_pthread_cond_wait_callback = -[](pthread_cond_t *, pthread_mutex_t *) {return 0;}; diff --git a/src/lib/avoidance/ObstacleAvoidanceTest.cpp b/src/lib/avoidance/ObstacleAvoidanceTest.cpp index 20ff48f89a..d9c0b52e40 100644 --- a/src/lib/avoidance/ObstacleAvoidanceTest.cpp +++ b/src/lib/avoidance/ObstacleAvoidanceTest.cpp @@ -49,6 +49,7 @@ public: void SetUp() override { + param_control_autosave(false); param_reset_all(); pos_sp = Vector3f(1.f, 1.2f, 0.1f); vel_sp = Vector3f(0.3f, 0.4f, 0.1f); diff --git a/src/lib/collision_prevention/CollisionPreventionTest.cpp b/src/lib/collision_prevention/CollisionPreventionTest.cpp index d8aeb1e776..9de0a208aa 100644 --- a/src/lib/collision_prevention/CollisionPreventionTest.cpp +++ b/src/lib/collision_prevention/CollisionPreventionTest.cpp @@ -42,6 +42,7 @@ class CollisionPreventionTest : public ::testing::Test public: void SetUp() override { + param_control_autosave(false); param_reset_all(); } }; diff --git a/src/lib/parameters/ParameterTest.cpp b/src/lib/parameters/ParameterTest.cpp index 4e5ff3231e..b0e04923e9 100644 --- a/src/lib/parameters/ParameterTest.cpp +++ b/src/lib/parameters/ParameterTest.cpp @@ -43,6 +43,7 @@ class ParameterTest : public ::testing::Test public: void SetUp() override { + param_control_autosave(false); param_reset_all(); } };