Linux: added HRT test, moved tests to linux/tests

Also fixed naming of mavlink files for NuttX build.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
Mark Charlebois
2015-03-14 17:54:37 -07:00
parent 99399115f2
commit ac0df5c61d
26 changed files with 1924 additions and 24 deletions
+3 -2
View File
@@ -54,6 +54,7 @@ MODULES += lib/conversion
# Linux port
#
MODULES += platforms/linux/px4_layer
MODULES += platforms/linux/hello
MODULES += platforms/linux/vcdev_test
MODULES += platforms/linux/tests/hello
MODULES += platforms/linux/tests/vcdev_test
MODULES += platforms/linux/tests/hrt_test
File diff suppressed because it is too large Load Diff
+5 -1
View File
@@ -38,8 +38,12 @@
MODULE_COMMAND = mavlink_tests
SRCS = mavlink_tests.cpp \
mavlink_ftp_test.cpp \
../mavlink_ftp.cpp \
../mavlink.c
ifeq ($(PX4_TARGET_NUTTX),nuttx)
SRCS += ../mavlink_ftp_nuttx.cpp
else
SRCS += ../mavlink_ftp_linux.cpp
endif
INCLUDE_DIRS += $(MAVLINK_SRC)/include/mavlink
+5 -4
View File
@@ -36,16 +36,17 @@
#
MODULE_COMMAND = mavlink
ifeq ($(PX$_TARGET_OS),nuttx)
ifeq ($(PX4_TARGET_OS),nuttx)
SRCS += mavlink_main_nuttx.cpp \
mavlink_ftp_nuttx.cpp
mavlink_ftp_nuttx.cpp \
mavlink_receiver_nuttx.cpp
else
SRCS += mavlink_main_linux.cpp \
mavlink_ftp_linux.cpp
mavlink_ftp_linux.cpp \
mavlink_receiver_linux.cpp
endif
SRCS += mavlink.c \
mavlink_receiver.cpp \
mavlink_mission.cpp \
mavlink_parameters.cpp \
mavlink_orb_subscription.cpp \
+5 -3
View File
@@ -197,7 +197,7 @@ ORBDevNode::ORBDevNode(const struct orb_metadata *meta, const char *name, const
_priority(priority)
{
// enable debug() calls
_debug_enabled = true;
//_debug_enabled = true;
}
ORBDevNode::~ORBDevNode()
@@ -702,7 +702,7 @@ namespace
ORBDevMaster *g_dev;
bool pubsubtest_passed = false;
bool pubsubtest_print = false;
bool pubsubtest_print = true;
int pubsubtest_res = PX4_OK;
struct orb_test {
@@ -818,7 +818,8 @@ int pubsublatency_main(void)
if (pubsubtest_print) {
char fname[32];
sprintf(fname, "/fs/microsd/timings%u.txt", timingsgroup);
//sprintf(fname, "/fs/microsd/timings%u.txt", timingsgroup);
sprintf(fname, "/tmp/timings%u.txt", timingsgroup);
FILE *f = fopen(fname, "w");
if (f == NULL) {
warnx("Error opening file!\n");
@@ -971,6 +972,7 @@ test()
template<typename S> int
latency_test(orb_id_t T, bool print)
{
test_note("---------------- LATENCY TEST ------------------");
S t;
t.val = 308;
t.time = hrt_absolute_time();
+7 -5
View File
@@ -78,11 +78,6 @@ hrt_abstime ts_to_abstime(struct timespec *ts)
return result;
}
/*
* Convert absolute time to a timespec.
*/
void abstime_to_ts(struct timespec *ts, hrt_abstime abstime);
/*
* Compute the delta between a timestamp taken in the past
* and now.
@@ -289,3 +284,10 @@ void hrt_call_at(struct hrt_call *entry, hrt_abstime calltime, hrt_callout callo
hrt_call_internal(entry, calltime, 0, callout, arg);
}
#if 0
/*
* Convert absolute time to a timespec.
*/
void abstime_to_ts(struct timespec *ts, hrt_abstime abstime);
#endif
@@ -96,7 +96,9 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
unsigned long structsize;
char * p = (char *)argv;
px4_task_t task;
pthread_t task;
pthread_attr_t attr;
struct sched_param param;
// Calculate argc
while (p != (char *)0) {
@@ -125,14 +127,36 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
// Must add NULL at end of argv
taskdata->argv[argc] = (char *)0;
//printf("Called px4_task_spawn_cmd\n");
// FIXME - add handling for scheduler and priority
rv = pthread_create (&task, NULL, (void *)&entry_adapter, (void *) taskdata);
if (rv != 0)
{
rv = pthread_attr_init(&attr);
if (rv != 0) {
printf("px4_task_spawn_cmd: failed to init thread attrs\n");
return (rv < 0) ? rv : -rv;
}
rv = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
if (rv != 0) {
printf("px4_task_spawn_cmd: failed to set inherit sched\n");
return (rv < 0) ? rv : -rv;
}
rv = pthread_attr_setschedpolicy(&attr, scheduler);
if (rv != 0) {
printf("px4_task_spawn_cmd: failed to set sched policy\n");
return (rv < 0) ? rv : -rv;
}
param.sched_priority = priority;
rv = pthread_attr_setschedparam(&attr, &param);
if (rv != 0) {
printf("px4_task_spawn_cmd: failed to set sched param\n");
return (rv < 0) ? rv : -rv;
}
rv = pthread_create (&task, &attr, (void *)&entry_adapter, (void *) taskdata);
if (rv != 0) {
printf("px4_task_spawn_cmd: failed to create thread\n");
return (rv < 0) ? rv : -rv;
}
//printf("pthread_create task=%d rv=%d\n",(int)task, rv);
for (i=0; i<PX4_MAX_TASKS; ++i) {
@@ -0,0 +1,66 @@
/****************************************************************************
*
* Copyright (C) 2015 Mark Charlebois. 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.
*
****************************************************************************/
/**
* @file hrt_test.cpp
* Test High Resolution Timers in Linux
*
* @author Mark Charlebois <charlebm@gmail.com>
*/
#include <drivers/drv_hrt.h>
#include "hrt_test.h"
#include <unistd.h>
#include <stdio.h>
px4::AppState HRTTest::appState;
int HRTTest::main()
{
appState.setRunning(true);
hrt_abstime t = hrt_absolute_time();
usleep(1000000);
hrt_abstime elt = hrt_elapsed_time(&t);
printf("Elapsed time %llu in 1 sec (usleep)\n", elt);
printf("Start time %llu\n", t);
t = hrt_absolute_time();
sleep(1);
elt = hrt_elapsed_time(&t);
printf("Elapsed time %llu in 1 sec (sleep)\n", elt);
printf("Start time %llu\n", t);
return 0;
}
@@ -0,0 +1,53 @@
/****************************************************************************
*
* Copyright (C) 2015 Mark Charlebois. 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.
*
****************************************************************************/
/**
* @file hrt_test.h
* Example app for Linux
*
* @author Mark Charlebois <charlebm@gmail.com>
*/
#pragma once
#include <px4_app.h>
class HRTTest {
public:
HRTTest() {};
~HRTTest() {};
int main();
static px4::AppState appState; /* track requests to terminate app */
};
@@ -0,0 +1,55 @@
/****************************************************************************
*
* Copyright (C) 2015 Mark Charlebois. 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.
*
****************************************************************************/
/**
* @file hello_main.cpp
* Example for Linux
*
* @author Mark Charlebois <charlebm@gmail.com>
*/
#include <px4_middleware.h>
#include <px4_app.h>
#include "hrt_test.h"
#include <stdio.h>
int PX4_MAIN(int argc, char **argv)
{
px4::init(argc, argv, "hello");
printf("hello\n");
HRTTest test;
test.main();
printf("goodbye\n");
return 0;
}
@@ -0,0 +1,92 @@
/****************************************************************************
*
* Copyright (C) 2015 Mark Charlebois. 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.
*
****************************************************************************/
/**
* @file hrt_test_start_linux.cpp
*
* @author Mark Charlebois <mcharleb@gmail.com>
*/
#include "hrt_test.h"
#include <px4_app.h>
#include <px4_tasks.h>
#include <stdio.h>
#include <string.h>
#include <sched.h>
static int daemon_task; /* Handle of deamon task / thread */
extern "C" __EXPORT int hrttest_main(int argc, char *argv[]);
int hrttest_main(int argc, char *argv[])
{
if (argc < 2) {
printf("usage: hrttest_main {start|stop|status}\n");
return 1;
}
if (!strcmp(argv[1], "start")) {
if (HRTTest::appState.isRunning()) {
printf("already running\n");
/* this is not an error */
return 0;
}
daemon_task = px4_task_spawn_cmd("hrttest",
SCHED_DEFAULT,
SCHED_PRIORITY_MAX - 5,
2000,
PX4_MAIN,
(argv) ? (char* const*)&argv[2] : (char* const*)NULL);
return 0;
}
if (!strcmp(argv[1], "stop")) {
HRTTest::appState.requestExit();
return 0;
}
if (!strcmp(argv[1], "status")) {
if (HRTTest::appState.isRunning()) {
printf("is running\n");
} else {
printf("not started\n");
}
return 0;
}
printf("usage: hrttest_main {start|stop|status}\n");
return 1;
}
@@ -0,0 +1,43 @@
############################################################################
#
# Copyright (c) 2014 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.
#
############################################################################
#
# Publisher Example Application
#
MODULE_COMMAND = hrttest
SRCS = hrt_test_main.cpp \
hrt_test_start_linux.cpp \
hrt_test.cpp
+2 -2
View File
@@ -55,8 +55,8 @@
#define PX4_DEVIOCSPUBBLOCK 3
#define PX4_DEVIOCGPUBBLOCK 4
//#define PX4_DEBUG(...)
#define PX4_DEBUG(...) printf(__VA_ARGS__)
#define PX4_DEBUG(...)
//#define PX4_DEBUG(...) printf(__VA_ARGS__)
__BEGIN_DECLS