mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-15 11:53:34 +08:00
GTest functional tests that include parameters and uORB messaging (#12521)
* Add kdevelop to gitignore * Add test stubs * Rename px4_add_gtest to px4_add_unit_gtest * Add infrastructure to run functional tests * Add example tests with parameters and uorb messages * Fix memory issues in destructors in uORB manager and CDev * Add a more real-world test of the collision prevention
This commit is contained in:
@@ -32,3 +32,7 @@
|
||||
############################################################################
|
||||
|
||||
add_subdirectory(common)
|
||||
|
||||
if (${PX4_PLATFORM} STREQUAL "posix" AND BUILD_TESTING)
|
||||
add_subdirectory(posix/test_stubs)
|
||||
endif()
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "px4_tasks.h" // px4_main_t
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
// Maps an app name to it's function.
|
||||
typedef std::map<std::string, px4_main_t> apps_map_type;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2019 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name PX4 nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
set(SRCS
|
||||
stub_daemon.cpp
|
||||
stub_devmgr.cpp
|
||||
stub_parameter.cpp
|
||||
)
|
||||
|
||||
px4_add_library(test_stubs ${SRCS})
|
||||
message("-- ADDING TEST STUBS")
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "stub_daemon.h"
|
||||
|
||||
|
||||
void init_app_map(apps_map_type &apps) {stub_init_app_map_callback(apps);}
|
||||
|
||||
void list_builtins(apps_map_type &apps) {stub_list_builtins_callback(apps);}
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <platforms/posix/apps.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
std::function<void(apps_map_type &apps)> stub_init_app_map_callback = [](apps_map_type &) {};
|
||||
std::function<void(apps_map_type &apps)> stub_list_builtins_callback = [](apps_map_type &) {};
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "stub_devmgr.h"
|
||||
|
||||
|
||||
namespace DriverFramework
|
||||
{
|
||||
int DevMgr::getNextDeviceName(unsigned int &index, const char **instancename)
|
||||
{
|
||||
return stub_getNextDeviceName_callback(index, instancename);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "DevMgr.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
||||
std::function<int(unsigned int &, const char **)> stub_getNextDeviceName_callback = [](unsigned int &,
|
||||
const char **) {return 0;};
|
||||
@@ -0,0 +1,11 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
std::function<int(pthread_cond_t *, pthread_mutex_t *)> stub_pthread_cond_wait_callback =
|
||||
[](pthread_cond_t *, pthread_mutex_t *) {return 0;};
|
||||
Reference in New Issue
Block a user