mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-22 14:53:35 +08:00
systemcmds/tests: split out microbenchmarks and remove obsolete tests
- reorganize Jenkins HIL tests
This commit is contained in:
@@ -32,7 +32,6 @@
|
||||
############################################################################
|
||||
|
||||
set(srcs
|
||||
test_adc.cpp
|
||||
test_atomic_bitset.cpp
|
||||
test_bezierQuad.cpp
|
||||
test_bitset.cpp
|
||||
@@ -47,17 +46,11 @@ set(srcs
|
||||
test_int.cpp
|
||||
test_i2c_spi_cli.cpp
|
||||
test_IntrusiveQueue.cpp
|
||||
test_jig_voltages.cpp
|
||||
test_led.c
|
||||
test_List.cpp
|
||||
test_IntrusiveSortedList.cpp
|
||||
test_mathlib.cpp
|
||||
test_matrix.cpp
|
||||
test_microbench_atomic.cpp
|
||||
test_microbench_hrt.cpp
|
||||
test_microbench_math.cpp
|
||||
test_microbench_matrix.cpp
|
||||
test_microbench_uorb.cpp
|
||||
test_mixer.cpp
|
||||
test_param.c
|
||||
test_parameters.cpp
|
||||
@@ -66,7 +59,6 @@ set(srcs
|
||||
test_ppm_loopback.c
|
||||
test_rc.c
|
||||
test_search_min.cpp
|
||||
test_servo.c
|
||||
test_sleep.c
|
||||
test_uart_baudchange.c
|
||||
test_uart_console.c
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2012 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file test_adc.c
|
||||
* Test for the analog to digital converter.
|
||||
*/
|
||||
|
||||
#include <px4_platform_common/time.h>
|
||||
#include <px4_platform_common/log.h>
|
||||
#include "tests_main.h"
|
||||
#include <drivers/drv_adc.h>
|
||||
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/adc_report.h>
|
||||
|
||||
int test_adc(int argc, char *argv[])
|
||||
{
|
||||
uORB::Subscription _adc_sub{ORB_ID(adc_report)};
|
||||
adc_report_s adc;
|
||||
|
||||
px4_usleep(50000); // sleep 50ms and wait for adc report
|
||||
|
||||
if (_adc_sub.update(&adc)) {
|
||||
PX4_INFO_RAW("DeviceID: %" PRIu32 "\n", adc.device_id);
|
||||
PX4_INFO_RAW("Resolution: %" PRIu32 "\n", adc.resolution);
|
||||
PX4_INFO_RAW("Voltage Reference: %f\n", adc.v_ref);
|
||||
|
||||
for (int i = 0; i < PX4_MAX_ADC_CHANNELS; ++i) {
|
||||
PX4_INFO_RAW("%" PRIu16 ": %" PRIi32 " ", adc.channel_id[i], adc.raw_data[i]);
|
||||
}
|
||||
|
||||
PX4_INFO_RAW("\n");
|
||||
|
||||
PX4_INFO_RAW("\t ADC test successful.\n");
|
||||
|
||||
return OK;
|
||||
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ int check_user_abort(int fd)
|
||||
case 0x1b: // esc
|
||||
case 'c':
|
||||
case 'q': {
|
||||
warnx("Test aborted.");
|
||||
printf("Test aborted.\n");
|
||||
fsync(fd);
|
||||
close(fd);
|
||||
return OK;
|
||||
@@ -90,14 +90,14 @@ int check_user_abort(int fd)
|
||||
int
|
||||
test_file(int argc, char *argv[])
|
||||
{
|
||||
const unsigned iterations = 100;
|
||||
const unsigned alignments = 65;
|
||||
const unsigned iterations = 2;
|
||||
const unsigned alignments = 33;
|
||||
|
||||
/* check if microSD card is mounted */
|
||||
struct stat buffer;
|
||||
|
||||
if (stat(PX4_STORAGEDIR "/", &buffer)) {
|
||||
warnx("no microSD card mounted, aborting file test");
|
||||
printf("no microSD card mounted, aborting file test\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ test_file(int argc, char *argv[])
|
||||
for (unsigned a = 0; a < alignments; a++) {
|
||||
|
||||
printf("\n");
|
||||
warnx("----- alignment test: %u bytes -----", a);
|
||||
printf("----- alignment test: %u bytes -----\n", a);
|
||||
|
||||
uint8_t write_buf[chunk_sizes[c] + alignments] __attribute__((aligned(64)));
|
||||
|
||||
@@ -124,9 +124,9 @@ test_file(int argc, char *argv[])
|
||||
uint8_t read_buf[chunk_sizes[c] + alignments] __attribute__((aligned(64)));
|
||||
hrt_abstime start, end;
|
||||
|
||||
int fd = px4_open(PX4_STORAGEDIR "/testfile", O_TRUNC | O_WRONLY | O_CREAT);
|
||||
int fd = open(PX4_STORAGEDIR "/testfile", O_TRUNC | O_WRONLY | O_CREAT, 0600);
|
||||
|
||||
warnx("testing unaligned writes - please wait..");
|
||||
printf("testing unaligned writes - please wait..\n");
|
||||
|
||||
start = hrt_absolute_time();
|
||||
|
||||
@@ -134,10 +134,10 @@ test_file(int argc, char *argv[])
|
||||
int wret = write(fd, write_buf + a, chunk_sizes[c]);
|
||||
|
||||
if (wret != chunk_sizes[c]) {
|
||||
warn("WRITE ERROR!");
|
||||
PX4_ERR("WRITE ERROR!");
|
||||
|
||||
if ((0x3 & (uintptr_t)(write_buf + a))) {
|
||||
warnx("memory is unaligned, align shift: %d", a);
|
||||
printf("memory is unaligned, align shift: %d\n", a);
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -153,9 +153,9 @@ test_file(int argc, char *argv[])
|
||||
|
||||
end = hrt_absolute_time();
|
||||
|
||||
warnx("write took %" PRIu64 " us", (end - start));
|
||||
printf("write took %" PRIu64 " us\n", (end - start));
|
||||
|
||||
px4_close(fd);
|
||||
close(fd);
|
||||
fd = open(PX4_STORAGEDIR "/testfile", O_RDONLY);
|
||||
|
||||
/* read back data for validation */
|
||||
@@ -163,7 +163,7 @@ test_file(int argc, char *argv[])
|
||||
int rret = read(fd, read_buf, chunk_sizes[c]);
|
||||
|
||||
if (rret != chunk_sizes[c]) {
|
||||
warnx("READ ERROR!");
|
||||
PX4_ERR("READ ERROR!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -172,14 +172,14 @@ test_file(int argc, char *argv[])
|
||||
|
||||
for (int j = 0; j < chunk_sizes[c]; j++) {
|
||||
if (read_buf[j] != write_buf[j + a]) {
|
||||
warnx("COMPARISON ERROR: byte %d, align shift: %d", j, a);
|
||||
PX4_ERR("COMPARISON ERROR: byte %d, align shift: %d", j, a);
|
||||
compare_ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!compare_ok) {
|
||||
warnx("ABORTING FURTHER COMPARISON DUE TO ERROR");
|
||||
PX4_ERR("ABORTING FURTHER COMPARISON DUE TO ERROR");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -195,15 +195,15 @@ test_file(int argc, char *argv[])
|
||||
|
||||
close(fd);
|
||||
int ret = unlink(PX4_STORAGEDIR "/testfile");
|
||||
fd = px4_open(PX4_STORAGEDIR "/testfile", O_TRUNC | O_WRONLY | O_CREAT);
|
||||
fd = open(PX4_STORAGEDIR "/testfile", O_TRUNC | O_WRONLY | O_CREAT, 0600);
|
||||
|
||||
warnx("testing aligned writes - please wait.. (CTRL^C to abort)");
|
||||
printf("testing aligned writes - please wait.. (CTRL^C to abort)\n");
|
||||
|
||||
for (unsigned i = 0; i < iterations; i++) {
|
||||
int wret = write(fd, write_buf, chunk_sizes[c]);
|
||||
|
||||
if (wret != chunk_sizes[c]) {
|
||||
warnx("WRITE ERROR!");
|
||||
PX4_ERR("WRITE ERROR!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -215,9 +215,9 @@ test_file(int argc, char *argv[])
|
||||
|
||||
fsync(fd);
|
||||
|
||||
warnx("reading data aligned..");
|
||||
printf("reading data aligned..\n");
|
||||
|
||||
px4_close(fd);
|
||||
close(fd);
|
||||
fd = open(PX4_STORAGEDIR "/testfile", O_RDONLY);
|
||||
|
||||
bool align_read_ok = true;
|
||||
@@ -227,13 +227,13 @@ test_file(int argc, char *argv[])
|
||||
int rret = read(fd, read_buf, chunk_sizes[c]);
|
||||
|
||||
if (rret != chunk_sizes[c]) {
|
||||
warnx("READ ERROR!");
|
||||
PX4_ERR("READ ERROR!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (int j = 0; j < chunk_sizes[c]; j++) {
|
||||
if (read_buf[j] != write_buf[j]) {
|
||||
warnx("COMPARISON ERROR: byte %d: %u != %u", j, (unsigned int)read_buf[j], (unsigned int)write_buf[j]);
|
||||
PX4_ERR("COMPARISON ERROR: byte %d: %u != %u", j, (unsigned int)read_buf[j], (unsigned int)write_buf[j]);
|
||||
align_read_ok = false;
|
||||
break;
|
||||
}
|
||||
@@ -244,15 +244,15 @@ test_file(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (!align_read_ok) {
|
||||
warnx("ABORTING FURTHER COMPARISON DUE TO ERROR");
|
||||
PX4_ERR("ABORTING FURTHER COMPARISON DUE TO ERROR");
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
warnx("align read result: %s\n", (align_read_ok) ? "OK" : "ERROR");
|
||||
printf("align read result: %s\n", (align_read_ok) ? "OK" : "ERROR");
|
||||
|
||||
warnx("reading data unaligned..");
|
||||
printf("reading data unaligned..\n");
|
||||
|
||||
close(fd);
|
||||
fd = open(PX4_STORAGEDIR "/testfile", O_RDONLY);
|
||||
@@ -267,15 +267,15 @@ test_file(int argc, char *argv[])
|
||||
int rret = read(fd, read_buf + a, chunk_sizes[c]);
|
||||
|
||||
if (rret != chunk_sizes[c]) {
|
||||
warnx("READ ERROR!");
|
||||
PX4_ERR("READ ERROR!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (int j = 0; j < chunk_sizes[c]; j++) {
|
||||
|
||||
if ((read_buf + a)[j] != write_buf[j]) {
|
||||
warnx("COMPARISON ERROR: byte %d, align shift: %d: %u != %u", j, a, (unsigned int)read_buf[j + a],
|
||||
(unsigned int)write_buf[j]);
|
||||
PX4_ERR("COMPARISON ERROR: byte %d, align shift: %d: %u != %u", j, a, (unsigned int)read_buf[j + a],
|
||||
(unsigned int)write_buf[j]);
|
||||
unalign_read_ok = false;
|
||||
unalign_read_err_count++;
|
||||
|
||||
@@ -290,7 +290,7 @@ test_file(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (!unalign_read_ok) {
|
||||
warnx("ABORTING FURTHER COMPARISON DUE TO ERROR");
|
||||
PX4_ERR("ABORTING FURTHER COMPARISON DUE TO ERROR");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ test_file(int argc, char *argv[])
|
||||
close(fd);
|
||||
|
||||
if (ret) {
|
||||
warnx("UNLINKING FILE FAILED");
|
||||
PX4_ERR("UNLINKING FILE FAILED");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -314,16 +314,16 @@ test_file(int argc, char *argv[])
|
||||
if (d) {
|
||||
|
||||
while ((dir = readdir(d)) != NULL) {
|
||||
//printf("%s\n", dir->d_name);
|
||||
printf("%s\n", dir->d_name);
|
||||
}
|
||||
|
||||
closedir(d);
|
||||
|
||||
warnx("directory listing ok (FS mounted and readable)");
|
||||
printf("directory listing ok (FS mounted and readable)\n");
|
||||
|
||||
} else {
|
||||
/* failed opening dir */
|
||||
warnx("FAILED LISTING MICROSD ROOT DIRECTORY");
|
||||
PX4_ERR("FAILED LISTING MICROSD ROOT DIRECTORY");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2012-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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file test_jig_voltages.c
|
||||
* Tests for jig voltages.
|
||||
*/
|
||||
|
||||
#include <px4_platform_common/defines.h>
|
||||
#include <unistd.h>
|
||||
#include "tests_main.h"
|
||||
#include <drivers/drv_adc.h>
|
||||
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/adc_report.h>
|
||||
|
||||
int test_jig_voltages(int argc, char *argv[])
|
||||
{
|
||||
uORB::Subscription _adc_sub{ORB_ID(adc_report)};
|
||||
adc_report_s adc;
|
||||
|
||||
px4_usleep(50000); // sleep 50ms and wait for adc report
|
||||
|
||||
if (_adc_sub.update(&adc)) {
|
||||
PX4_INFO_RAW("DeviceID: %" PRIu32 "\n", adc.device_id);
|
||||
PX4_INFO_RAW("Resolution: %" PRIu32 "\n", adc.resolution);
|
||||
PX4_INFO_RAW("Voltage Reference: %f\n", adc.v_ref);
|
||||
|
||||
unsigned channels = 0;
|
||||
|
||||
for (int i = 0; i < PX4_MAX_ADC_CHANNELS; ++i) {
|
||||
PX4_INFO_RAW("%" PRIu16 ": %" PRIi32 " ", adc.channel_id[i], adc.raw_data[i]);
|
||||
|
||||
if (adc.channel_id[i] != -1) {
|
||||
++channels;
|
||||
}
|
||||
}
|
||||
|
||||
PX4_INFO_RAW("\n");
|
||||
|
||||
PX4_INFO("\t ADC operational.\n");
|
||||
|
||||
/* Expected values */
|
||||
int16_t expected_min[] = {2800, 2800, 1800, 800};
|
||||
int16_t expected_max[] = {3100, 3100, 2100, 1100};
|
||||
const char *check_res[channels];
|
||||
|
||||
if (channels < 4) {
|
||||
PX4_ERR("not all four test channels available, aborting.");
|
||||
return 1;
|
||||
|
||||
} else {
|
||||
int ret = OK;
|
||||
|
||||
/* Check values */
|
||||
check_res[0] = (expected_min[0] < adc.raw_data[0] && expected_max[0] > adc.raw_data[0]) ? "OK" : "FAIL";
|
||||
check_res[1] = (expected_min[1] < adc.raw_data[1] && expected_max[1] > adc.raw_data[1]) ? "OK" : "FAIL";
|
||||
check_res[2] = (expected_min[2] < adc.raw_data[2] && expected_max[2] > adc.raw_data[2]) ? "OK" : "FAIL";
|
||||
check_res[3] = (expected_min[3] < adc.raw_data[3] && expected_max[3] > adc.raw_data[3]) ? "OK" : "FAIL";
|
||||
|
||||
/* Accumulate result */
|
||||
ret += (expected_min[0] > adc.raw_data[0] || expected_max[0] < adc.raw_data[0]) ? 1 : 0;
|
||||
ret += (expected_min[1] > adc.raw_data[1] || expected_max[1] < adc.raw_data[1]) ? 1 : 0;
|
||||
ret += (expected_min[2] > adc.raw_data[2] || expected_max[2] < adc.raw_data[2]) ? 1 : 0;
|
||||
ret += (expected_min[3] > adc.raw_data[3] || expected_max[3] < adc.raw_data[3]) ? 1 : 0;
|
||||
|
||||
PX4_INFO("Sample:");
|
||||
PX4_INFO("channel: %d value: %d (allowed min: %d, allowed max: %d), result: %s",
|
||||
adc.channel_id[0], (int)(adc.raw_data[0]), expected_min[0], expected_max[0], check_res[0]);
|
||||
PX4_INFO("channel: %d value: %d (allowed min: %d, allowed max: %d), result: %s",
|
||||
adc.channel_id[1], (int)(adc.raw_data[1]), expected_min[1], expected_max[1], check_res[1]);
|
||||
PX4_INFO("channel: %d value: %d (allowed min: %d, allowed max: %d), result: %s",
|
||||
adc.channel_id[2], (int)(adc.raw_data[2]), expected_min[2], expected_max[2], check_res[2]);
|
||||
PX4_INFO("channel: %d value: %d (allowed min: %d, allowed max: %d), result: %s",
|
||||
adc.channel_id[3], (int)(adc.raw_data[3]), expected_min[3], expected_max[3], check_res[3]);
|
||||
|
||||
if (ret != OK) {
|
||||
PX4_ERR("\t JIG voltages test FAILED. Some channels where out of allowed range. Check supply voltages.");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
PX4_INFO("JIG voltages test successful.");
|
||||
|
||||
return OK;
|
||||
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -1,320 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2020 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file test_microbench_atomic.cpp
|
||||
* Microbenchmark atomic operations.
|
||||
*/
|
||||
|
||||
#include <unit_test.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <perf/perf_counter.h>
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <px4_platform_common/micro_hal.h>
|
||||
#include <px4_platform_common/atomic.h>
|
||||
|
||||
#ifdef __PX4_NUTTX
|
||||
#include <nuttx/irq.h>
|
||||
#endif
|
||||
|
||||
namespace MicroBenchAtomic
|
||||
{
|
||||
|
||||
#define PERF(name, op, count) do { \
|
||||
px4_usleep(100); \
|
||||
reset(); \
|
||||
perf_counter_t p = perf_alloc(PC_ELAPSED, name); \
|
||||
for (int i = 0; i < count; i++) { \
|
||||
px4_usleep(1); \
|
||||
lock(); \
|
||||
perf_begin(p); \
|
||||
op; \
|
||||
perf_end(p); \
|
||||
unlock(); \
|
||||
reset(); \
|
||||
} \
|
||||
perf_print_counter(p); \
|
||||
perf_free(p); \
|
||||
} while (0)
|
||||
|
||||
class MicroBenchAtomic : public UnitTest
|
||||
{
|
||||
public:
|
||||
bool run_tests() override;
|
||||
|
||||
private:
|
||||
|
||||
bool time_atomic_bool();
|
||||
bool time_atomic_int8();
|
||||
bool time_atomic_int16();
|
||||
bool time_atomic_int32();
|
||||
bool time_atomic_uint32();
|
||||
bool time_atomic_float();
|
||||
bool time_atomic_hrt_abstime();
|
||||
|
||||
void reset();
|
||||
|
||||
void lock()
|
||||
{
|
||||
#ifdef __PX4_NUTTX
|
||||
_flags = px4_enter_critical_section();
|
||||
#endif
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
#ifdef __PX4_NUTTX
|
||||
px4_leave_critical_section(_flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __PX4_NUTTX
|
||||
irqstate_t _flags {};
|
||||
#endif
|
||||
|
||||
px4::atomic<bool> _atomic_bool{false};
|
||||
px4::atomic<bool> _atomic_bool_storage{false};
|
||||
bool _test_load_bool{};
|
||||
|
||||
px4::atomic<int8_t> _atomic_int8{0};
|
||||
px4::atomic<int8_t> _atomic_int8_storage{0};
|
||||
int8_t _test_load_int8{};
|
||||
|
||||
px4::atomic<int16_t> _atomic_int16{0};
|
||||
px4::atomic<int16_t> _atomic_int16_storage{0};
|
||||
int16_t _test_load_int16{};
|
||||
|
||||
px4::atomic<int32_t> _atomic_int32{0};
|
||||
px4::atomic<int32_t> _atomic_int32_storage{0};
|
||||
int32_t _test_load_int32{};
|
||||
|
||||
px4::atomic<uint32_t> _atomic_uint32{0};
|
||||
px4::atomic<uint32_t> _atomic_uint32_storage{0};
|
||||
uint32_t _test_load_uint32{};
|
||||
|
||||
px4::atomic<float> _atomic_float{0};
|
||||
px4::atomic<float> _atomic_float_storage{0};
|
||||
float _test_load_float{};
|
||||
|
||||
px4::atomic<hrt_abstime> _atomic_hrt_abstime{0};
|
||||
px4::atomic<hrt_abstime> _atomic_hrt_abstime_storage{0};
|
||||
hrt_abstime _test_load_hrt_abstime{};
|
||||
};
|
||||
|
||||
bool MicroBenchAtomic::run_tests()
|
||||
{
|
||||
ut_run_test(time_atomic_bool);
|
||||
ut_run_test(time_atomic_int8);
|
||||
ut_run_test(time_atomic_int16);
|
||||
ut_run_test(time_atomic_int32);
|
||||
ut_run_test(time_atomic_uint32);
|
||||
ut_run_test(time_atomic_float);
|
||||
ut_run_test(time_atomic_hrt_abstime);
|
||||
|
||||
return (_tests_failed == 0);
|
||||
}
|
||||
|
||||
void MicroBenchAtomic::reset()
|
||||
{
|
||||
srand(time(nullptr));
|
||||
|
||||
_atomic_bool.store(rand());
|
||||
_atomic_bool_storage.store(rand());
|
||||
_test_load_bool = rand();
|
||||
|
||||
_atomic_int8.store(rand());
|
||||
_atomic_int8_storage.store(rand());
|
||||
_test_load_int8 = rand();
|
||||
|
||||
_atomic_int16.store(rand());
|
||||
_atomic_int16_storage.store(rand());
|
||||
_test_load_int16 = rand();
|
||||
|
||||
_atomic_int32.store(rand());
|
||||
_atomic_int32_storage.store(rand());
|
||||
_test_load_int32 = rand();
|
||||
|
||||
_atomic_uint32.store(rand());
|
||||
_atomic_uint32_storage.store(rand());
|
||||
_test_load_uint32 = rand();
|
||||
|
||||
_atomic_float.store(rand());
|
||||
_atomic_float_storage.store(rand());
|
||||
_test_load_float = rand();
|
||||
}
|
||||
|
||||
ut_declare_test_c(test_microbench_atomic, MicroBenchAtomic)
|
||||
|
||||
bool MicroBenchAtomic::time_atomic_bool()
|
||||
{
|
||||
PERF("atomic bool load", _test_load_bool = _atomic_bool.load(), 100);
|
||||
PERF("atomic bool store", _atomic_bool.store(_test_load_bool), 100);
|
||||
PERF("atomic bool load and store", _atomic_bool_storage.store(_atomic_bool.load()), 100);
|
||||
|
||||
bool expected = true;
|
||||
PERF("atomic bool compare exchange (same)",
|
||||
volatile bool compare_exchange = _atomic_bool.compare_exchange(&expected, true), 100);
|
||||
PERF("atomic bool compare exchange (different)",
|
||||
volatile bool compare_exchange = _atomic_bool.compare_exchange(&expected, false), 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MicroBenchAtomic::time_atomic_int8()
|
||||
{
|
||||
PERF("atomic int8 load", _test_load_int8 = _atomic_int8.load(), 100);
|
||||
PERF("atomic int8 store", _atomic_int8.store(_test_load_int8), 100);
|
||||
PERF("atomic int8 load and store", _atomic_int8_storage.store(_atomic_int8.load()), 100);
|
||||
PERF("atomic int8 fetch add", _test_load_int8 = _atomic_int8.fetch_add(_test_load_int8), 100);
|
||||
PERF("atomic int8 fetch sub", _test_load_int8 = _atomic_int8.fetch_sub(_test_load_int8), 100);
|
||||
PERF("atomic int8 fetch and", _test_load_int8 = _atomic_int8.fetch_and(_test_load_int8), 100);
|
||||
PERF("atomic int8 fetch xor", _test_load_int8 = _atomic_int8.fetch_xor(_test_load_int8), 100);
|
||||
PERF("atomic int8 fetch or", _test_load_int8 = _atomic_int8.fetch_or(_test_load_int8), 100);
|
||||
PERF("atomic int8 fetch nand", _test_load_int8 = _atomic_int8.fetch_nand(_test_load_int8), 100);
|
||||
|
||||
int8_t expected = 42;
|
||||
PERF("atomic int8 compare exchange (same)",
|
||||
volatile bool compare_exchange = _atomic_int8.compare_exchange(&expected, 42), 100);
|
||||
PERF("atomic int8 compare exchange (different)",
|
||||
volatile bool compare_exchange = _atomic_int8.compare_exchange(&expected, 0), 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MicroBenchAtomic::time_atomic_int16()
|
||||
{
|
||||
PERF("atomic int16 load", _test_load_int16 = _atomic_int16.load(), 100);
|
||||
PERF("atomic int16 store", _atomic_int16.store(_test_load_int16), 100);
|
||||
PERF("atomic int16 load and store", _atomic_int16_storage.store(_atomic_int16.load()), 100);
|
||||
PERF("atomic int16 fetch add", _test_load_int16 = _atomic_int16.fetch_add(_test_load_int16), 100);
|
||||
PERF("atomic int16 fetch sub", _test_load_int16 = _atomic_int16.fetch_sub(_test_load_int16), 100);
|
||||
PERF("atomic int16 fetch and", _test_load_int16 = _atomic_int16.fetch_and(_test_load_int16), 100);
|
||||
PERF("atomic int16 fetch xor", _test_load_int16 = _atomic_int16.fetch_xor(_test_load_int16), 100);
|
||||
PERF("atomic int16 fetch or", _test_load_int16 = _atomic_int16.fetch_or(_test_load_int16), 100);
|
||||
PERF("atomic int16 fetch nand", _test_load_int16 = _atomic_int16.fetch_nand(_test_load_int16), 100);
|
||||
|
||||
int16_t expected = 42;
|
||||
PERF("atomic int16 compare exchange (same)",
|
||||
volatile bool compare_exchange = _atomic_int16.compare_exchange(&expected, 42), 100);
|
||||
PERF("atomic int16 compare exchange (different)",
|
||||
volatile bool compare_exchange = _atomic_int16.compare_exchange(&expected, 0), 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MicroBenchAtomic::time_atomic_int32()
|
||||
{
|
||||
PERF("atomic int32 load", _test_load_int32 = _atomic_int32.load(), 100);
|
||||
PERF("atomic int32 store", _atomic_int32.store(_test_load_int32), 100);
|
||||
PERF("atomic int32 load and store", _atomic_int32_storage.store(_atomic_int32.load()), 100);
|
||||
PERF("atomic int32 fetch add", _test_load_int32 = _atomic_int32.fetch_add(_test_load_int32), 100);
|
||||
PERF("atomic int32 fetch sub", _test_load_int32 = _atomic_int32.fetch_sub(_test_load_int32), 100);
|
||||
PERF("atomic int32 fetch and", _test_load_int32 = _atomic_int32.fetch_and(_test_load_int32), 100);
|
||||
PERF("atomic int32 fetch xor", _test_load_int32 = _atomic_int32.fetch_xor(_test_load_int32), 100);
|
||||
PERF("atomic int32 fetch or", _test_load_int32 = _atomic_int32.fetch_or(_test_load_int32), 100);
|
||||
PERF("atomic int32 fetch nand", _test_load_int32 = _atomic_int32.fetch_nand(_test_load_int32), 100);
|
||||
|
||||
int32_t expected = 42;
|
||||
PERF("atomic int32 compare exchange (same)",
|
||||
volatile bool compare_exchange = _atomic_int32.compare_exchange(&expected, 42), 100);
|
||||
PERF("atomic int32 compare exchange (different)",
|
||||
volatile bool compare_exchange = _atomic_int32.compare_exchange(&expected, 0), 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MicroBenchAtomic::time_atomic_uint32()
|
||||
{
|
||||
PERF("atomic uint32 load", _test_load_uint32 = _atomic_uint32.load(), 100);
|
||||
PERF("atomic uint32 store", _atomic_uint32_storage.store(_test_load_uint32), 100);
|
||||
PERF("atomic uint32 load and store", _atomic_uint32_storage.store(_atomic_uint32.load()), 100);
|
||||
PERF("atomic uint32 fetch add", _test_load_uint32 = _atomic_uint32.fetch_add(_test_load_uint32), 100);
|
||||
PERF("atomic uint32 fetch sub", _test_load_uint32 = _atomic_uint32.fetch_sub(_test_load_uint32), 100);
|
||||
PERF("atomic uint32 fetch and", _test_load_uint32 = _atomic_uint32.fetch_and(_test_load_uint32), 100);
|
||||
PERF("atomic uint32 fetch xor", _test_load_uint32 = _atomic_uint32.fetch_xor(_test_load_uint32), 100);
|
||||
PERF("atomic uint32 fetch or", _test_load_uint32 = _atomic_uint32.fetch_or(_test_load_uint32), 100);
|
||||
PERF("atomic uint32 fetch nand", _test_load_uint32 = _atomic_uint32.fetch_nand(_test_load_uint32), 100);
|
||||
|
||||
uint32_t expected = 42;
|
||||
PERF("atomic uint32 compare exchange (same)",
|
||||
volatile bool compare_exchange = _atomic_uint32.compare_exchange(&expected, 42), 100);
|
||||
PERF("atomic uint32 compare exchange (different)",
|
||||
volatile bool compare_exchange = _atomic_uint32.compare_exchange(&expected, 0), 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MicroBenchAtomic::time_atomic_float()
|
||||
{
|
||||
//PERF("atomic float load", volatile float test_load = _atomic_float.load(), 100);
|
||||
PERF("atomic float store", _atomic_float.store(_test_load_float), 100);
|
||||
//PERF("atomic float load and store", _atomic_float_storage.store(_atomic_float.load()), 100);
|
||||
|
||||
float expected = 42;
|
||||
PERF("atomic float compare exchange (same)",
|
||||
volatile bool compare_exchange = _atomic_float.compare_exchange(&expected, 42), 100);
|
||||
PERF("atomic float compare exchange (different)",
|
||||
volatile bool compare_exchange = _atomic_float.compare_exchange(&expected, 0), 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MicroBenchAtomic::time_atomic_hrt_abstime()
|
||||
{
|
||||
ut_compare("atomic hrt_abstime load", _atomic_hrt_abstime.load(), 0);
|
||||
PERF("atomic hrt_abstime load", volatile hrt_abstime test_load = _atomic_hrt_abstime.load(), 100);
|
||||
|
||||
_test_load_hrt_abstime = 1;
|
||||
PERF("atomic hrt_abstime store", _atomic_hrt_abstime.store(_test_load_hrt_abstime), 100);
|
||||
ut_compare("atomic hrt_abstime load", _atomic_hrt_abstime.load(), 1);
|
||||
|
||||
PERF("atomic hrt_abstime load and store", _atomic_hrt_abstime_storage.store(_atomic_hrt_abstime.load()), 100);
|
||||
|
||||
hrt_abstime expected = 12345678;
|
||||
PERF("atomic hrt_abstime compare exchange (same)",
|
||||
volatile bool compare_exchange = _atomic_hrt_abstime.compare_exchange(&expected, 12345678), 100);
|
||||
ut_compare("atomic hrt_abstime load", _atomic_hrt_abstime.compare_exchange(&expected, 12345678) == true, true);
|
||||
|
||||
PERF("atomic hrt_abstime compare exchange (different)",
|
||||
volatile bool compare_exchange = _atomic_hrt_abstime.compare_exchange(&expected, 0), 100);
|
||||
ut_compare("atomic hrt_abstime load", _atomic_hrt_abstime.compare_exchange(&expected, 0) == false, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace MicroBenchAtomic
|
||||
@@ -1,152 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file test_microbench_hrt.cpp
|
||||
* Tests for the microbench high resolution timer.
|
||||
*/
|
||||
|
||||
#include <unit_test.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <perf/perf_counter.h>
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <px4_platform_common/micro_hal.h>
|
||||
|
||||
namespace MicroBenchHRT
|
||||
{
|
||||
|
||||
#ifdef __PX4_NUTTX
|
||||
#include <nuttx/irq.h>
|
||||
static irqstate_t flags;
|
||||
#endif
|
||||
|
||||
void lock()
|
||||
{
|
||||
#ifdef __PX4_NUTTX
|
||||
flags = px4_enter_critical_section();
|
||||
#endif
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
#ifdef __PX4_NUTTX
|
||||
px4_leave_critical_section(flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define PERF(name, op, count) do { \
|
||||
px4_usleep(1000); \
|
||||
reset(); \
|
||||
perf_counter_t p = perf_alloc(PC_ELAPSED, name); \
|
||||
for (int i = 0; i < count; i++) { \
|
||||
px4_usleep(1); \
|
||||
lock(); \
|
||||
perf_begin(p); \
|
||||
op; \
|
||||
perf_end(p); \
|
||||
unlock(); \
|
||||
reset(); \
|
||||
} \
|
||||
perf_print_counter(p); \
|
||||
perf_free(p); \
|
||||
} while (0)
|
||||
|
||||
class MicroBenchHRT : public UnitTest
|
||||
{
|
||||
public:
|
||||
virtual bool run_tests();
|
||||
|
||||
private:
|
||||
|
||||
bool time_px4_hrt();
|
||||
|
||||
void reset();
|
||||
|
||||
void lock()
|
||||
{
|
||||
#ifdef __PX4_NUTTX
|
||||
flags = px4_enter_critical_section();
|
||||
#endif
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
#ifdef __PX4_NUTTX
|
||||
px4_leave_critical_section(flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t u_64;
|
||||
uint64_t u_64_out;
|
||||
};
|
||||
|
||||
bool MicroBenchHRT::run_tests()
|
||||
{
|
||||
ut_run_test(time_px4_hrt);
|
||||
|
||||
return (_tests_failed == 0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T random(T min, T max)
|
||||
{
|
||||
const T scale = rand() / (T) RAND_MAX; /* [0, 1.0] */
|
||||
return min + scale * (max - min); /* [min, max] */
|
||||
}
|
||||
|
||||
void MicroBenchHRT::reset()
|
||||
{
|
||||
srand(time(nullptr));
|
||||
|
||||
// initialize with random data
|
||||
u_64 = rand();
|
||||
u_64_out = rand();
|
||||
}
|
||||
|
||||
ut_declare_test_c(test_microbench_hrt, MicroBenchHRT)
|
||||
|
||||
bool MicroBenchHRT::time_px4_hrt()
|
||||
{
|
||||
PERF("hrt_absolute_time()", u_64_out = hrt_absolute_time(), 1000);
|
||||
PERF("hrt_elapsed_time()", u_64_out = hrt_elapsed_time(&u_64), 1000);
|
||||
PERF("hrt_elapsed_time_atomic()", u_64_out = hrt_elapsed_time_atomic(&u_64), 1000);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace MicroBenchHRT
|
||||
@@ -1,272 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file test_microbench_math.cpp
|
||||
* Tests for the microbench math library.
|
||||
*/
|
||||
|
||||
#include <unit_test.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <perf/perf_counter.h>
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <px4_platform_common/micro_hal.h>
|
||||
|
||||
namespace MicroBenchMath
|
||||
{
|
||||
|
||||
#ifdef __PX4_NUTTX
|
||||
#include <nuttx/irq.h>
|
||||
static irqstate_t flags;
|
||||
#endif
|
||||
|
||||
void lock()
|
||||
{
|
||||
#ifdef __PX4_NUTTX
|
||||
flags = px4_enter_critical_section();
|
||||
#endif
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
#ifdef __PX4_NUTTX
|
||||
px4_leave_critical_section(flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define PERF(name, op, count) do { \
|
||||
px4_usleep(1000); \
|
||||
reset(); \
|
||||
perf_counter_t p = perf_alloc(PC_ELAPSED, name); \
|
||||
for (int i = 0; i < count; i++) { \
|
||||
px4_usleep(1); \
|
||||
lock(); \
|
||||
perf_begin(p); \
|
||||
op; \
|
||||
perf_end(p); \
|
||||
unlock(); \
|
||||
reset(); \
|
||||
} \
|
||||
perf_print_counter(p); \
|
||||
perf_free(p); \
|
||||
} while (0)
|
||||
|
||||
class MicroBenchMath : public UnitTest
|
||||
{
|
||||
public:
|
||||
virtual bool run_tests();
|
||||
|
||||
private:
|
||||
bool time_single_precision_float();
|
||||
bool time_single_precision_float_trig();
|
||||
|
||||
bool time_double_precision_float();
|
||||
bool time_double_precision_float_trig();
|
||||
|
||||
bool time_8bit_integers();
|
||||
bool time_16bit_integers();
|
||||
bool time_32bit_integers();
|
||||
bool time_64bit_integers();
|
||||
|
||||
void reset();
|
||||
|
||||
volatile float f32;
|
||||
volatile float f32_out;
|
||||
|
||||
volatile double f64;
|
||||
volatile double f64_out;
|
||||
|
||||
volatile uint8_t i_8;
|
||||
volatile uint8_t i_8_out;
|
||||
|
||||
volatile uint16_t i_16;
|
||||
volatile uint16_t i_16_out;
|
||||
|
||||
volatile uint32_t i_32;
|
||||
volatile uint32_t i_32_out;
|
||||
|
||||
volatile int64_t i_64;
|
||||
volatile int64_t i_64_out;
|
||||
|
||||
volatile uint64_t u_64;
|
||||
volatile uint64_t u_64_out;
|
||||
};
|
||||
|
||||
bool MicroBenchMath::run_tests()
|
||||
{
|
||||
ut_run_test(time_single_precision_float);
|
||||
ut_run_test(time_single_precision_float_trig);
|
||||
ut_run_test(time_double_precision_float);
|
||||
ut_run_test(time_double_precision_float_trig);
|
||||
ut_run_test(time_8bit_integers);
|
||||
ut_run_test(time_16bit_integers);
|
||||
ut_run_test(time_32bit_integers);
|
||||
ut_run_test(time_64bit_integers);
|
||||
|
||||
return (_tests_failed == 0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T random(T min, T max)
|
||||
{
|
||||
const T scale = rand() / (T) RAND_MAX; /* [0, 1.0] */
|
||||
return min + scale * (max - min); /* [min, max] */
|
||||
}
|
||||
|
||||
void MicroBenchMath::reset()
|
||||
{
|
||||
srand(time(nullptr));
|
||||
|
||||
// initialize with random data
|
||||
f32 = random(-2.0f * M_PI, 2.0f * M_PI); // somewhat representative range for angles in radians
|
||||
f32_out = random(-2.0f * M_PI, 2.0f * M_PI);
|
||||
|
||||
f64 = random(-2.0 * M_PI, 2.0 * M_PI);
|
||||
f64_out = random(-2.0 * M_PI, 2.0 * M_PI);
|
||||
|
||||
i_8 = rand();
|
||||
i_8_out = rand();
|
||||
|
||||
i_16 = rand();
|
||||
i_16_out = rand();
|
||||
|
||||
i_32 = rand();
|
||||
i_32_out = rand();
|
||||
|
||||
i_64 = rand();
|
||||
i_64_out = rand();
|
||||
|
||||
u_64 = rand();
|
||||
u_64_out = rand();
|
||||
}
|
||||
|
||||
ut_declare_test_c(test_microbench_math, MicroBenchMath)
|
||||
|
||||
bool MicroBenchMath::time_single_precision_float()
|
||||
{
|
||||
PERF("float add", f32_out += f32, 100);
|
||||
PERF("float sub", f32_out -= f32, 100);
|
||||
PERF("float mul", f32_out *= f32, 100);
|
||||
PERF("float div", f32_out /= f32, 100);
|
||||
PERF("float sqrt", f32_out = sqrtf(f32), 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MicroBenchMath::time_single_precision_float_trig()
|
||||
{
|
||||
PERF("sinf()", f32_out = sinf(f32), 100);
|
||||
PERF("cosf()", f32_out = cosf(f32), 100);
|
||||
PERF("tanf()", f32_out = tanf(f32), 100);
|
||||
|
||||
PERF("acosf()", f32_out = acosf(f32), 100);
|
||||
PERF("asinf()", f32_out = asinf(f32), 100);
|
||||
PERF("atan2f()", f32_out = atan2f(f32, 2.0f * f32), 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MicroBenchMath::time_double_precision_float()
|
||||
{
|
||||
PERF("double add", f64_out += f64, 100);
|
||||
PERF("double sub", f64_out -= f64, 100);
|
||||
PERF("double mul", f64_out *= f64, 100);
|
||||
PERF("double div", f64_out /= f64, 100);
|
||||
PERF("double sqrt", f64_out = sqrt(f64), 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MicroBenchMath::time_double_precision_float_trig()
|
||||
{
|
||||
PERF("sin()", f64_out = sin(f64), 100);
|
||||
PERF("cos()", f64_out = cos(f64), 100);
|
||||
PERF("tan()", f64_out = tan(f64), 100);
|
||||
|
||||
PERF("acos()", f64_out = acos(f64 * 0.5), 100);
|
||||
PERF("asin()", f64_out = asin(f64 * 0.6), 100);
|
||||
PERF("atan2()", f64_out = atan2(f64 * 0.7, f64 * 0.8), 100);
|
||||
|
||||
PERF("sqrt()", f64_out = sqrt(f64), 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool MicroBenchMath::time_8bit_integers()
|
||||
{
|
||||
PERF("int8 add", i_8_out += i_8, 100);
|
||||
PERF("int8 sub", i_8_out -= i_8, 100);
|
||||
PERF("int8 mul", i_8_out *= i_8, 100);
|
||||
PERF("int8 div", i_8_out /= i_8, 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MicroBenchMath::time_16bit_integers()
|
||||
{
|
||||
PERF("int16 add", i_16_out += i_16, 100);
|
||||
PERF("int16 sub", i_16_out -= i_16, 100);
|
||||
PERF("int16 mul", i_16_out *= i_16, 100);
|
||||
PERF("int16 div", i_16_out /= i_16, 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MicroBenchMath::time_32bit_integers()
|
||||
{
|
||||
PERF("int32 add", i_32_out += i_32, 100);
|
||||
PERF("int32 sub", i_32_out -= i_32, 100);
|
||||
PERF("int32 mul", i_32_out *= i_32, 100);
|
||||
PERF("int32 div", i_32_out /= i_32, 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MicroBenchMath::time_64bit_integers()
|
||||
{
|
||||
PERF("int64 add", i_64_out += i_64, 100);
|
||||
PERF("int64 sub", i_64_out -= i_64, 100);
|
||||
PERF("int64 mul", i_64_out *= i_64, 100);
|
||||
PERF("int64 div", i_64_out /= i_64, 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace MicroBenchMath
|
||||
@@ -1,180 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file test_microbench_matrix.cpp
|
||||
* Tests for the microbench matrix math library.
|
||||
*/
|
||||
|
||||
#include <unit_test.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <perf/perf_counter.h>
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <px4_platform_common/micro_hal.h>
|
||||
|
||||
#include <matrix/math.hpp>
|
||||
|
||||
namespace MicroBenchMatrix
|
||||
{
|
||||
|
||||
#ifdef __PX4_NUTTX
|
||||
#include <nuttx/irq.h>
|
||||
static irqstate_t flags;
|
||||
#endif
|
||||
|
||||
void lock()
|
||||
{
|
||||
#ifdef __PX4_NUTTX
|
||||
flags = px4_enter_critical_section();
|
||||
#endif
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
#ifdef __PX4_NUTTX
|
||||
px4_leave_critical_section(flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define PERF(name, op, count) do { \
|
||||
px4_usleep(1000); \
|
||||
reset(); \
|
||||
perf_counter_t p = perf_alloc(PC_ELAPSED, name); \
|
||||
for (int i = 0; i < count; i++) { \
|
||||
px4_usleep(1); \
|
||||
lock(); \
|
||||
perf_begin(p); \
|
||||
op; \
|
||||
perf_end(p); \
|
||||
unlock(); \
|
||||
reset(); \
|
||||
} \
|
||||
perf_print_counter(p); \
|
||||
perf_free(p); \
|
||||
} while (0)
|
||||
|
||||
class MicroBenchMatrix : public UnitTest
|
||||
{
|
||||
public:
|
||||
virtual bool run_tests();
|
||||
|
||||
private:
|
||||
|
||||
bool time_matrix_euler();
|
||||
bool time_matrix_quaternion();
|
||||
bool time_matrix_dcm();
|
||||
bool time_matrix_pseduo_inverse();
|
||||
|
||||
void reset();
|
||||
|
||||
matrix::Quatf q;
|
||||
matrix::Eulerf e;
|
||||
matrix::Dcmf d;
|
||||
matrix::Matrix<float, 16, 6> A16;
|
||||
matrix::Matrix<float, 6, 16> B16;
|
||||
matrix::Matrix<float, 6, 16> B16_4;
|
||||
};
|
||||
|
||||
bool MicroBenchMatrix::run_tests()
|
||||
{
|
||||
ut_run_test(time_matrix_euler);
|
||||
ut_run_test(time_matrix_quaternion);
|
||||
ut_run_test(time_matrix_dcm);
|
||||
ut_run_test(time_matrix_pseduo_inverse);
|
||||
|
||||
return (_tests_failed == 0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T random(T min, T max)
|
||||
{
|
||||
const T scale = rand() / (T) RAND_MAX; /* [0, 1.0] */
|
||||
return min + scale * (max - min); /* [min, max] */
|
||||
}
|
||||
|
||||
void MicroBenchMatrix::reset()
|
||||
{
|
||||
srand(time(nullptr));
|
||||
|
||||
// initialize with random data
|
||||
q = matrix::Quatf(rand(), rand(), rand(), rand());
|
||||
e = matrix::Eulerf(random(-2.0 * M_PI, 2.0 * M_PI), random(-2.0 * M_PI, 2.0 * M_PI), random(-2.0 * M_PI, 2.0 * M_PI));
|
||||
d = q;
|
||||
|
||||
for (size_t j = 0; j < 6; j++) {
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
B16(j, i) = random(-10.0, 10.0);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
B16_4(j, i) = random(-10.0, 10.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool MicroBenchMatrix::time_matrix_euler()
|
||||
{
|
||||
PERF("matrix Euler from Quaternion", e = q, 100);
|
||||
PERF("matrix Euler from Dcm", e = d, 100);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MicroBenchMatrix::time_matrix_quaternion()
|
||||
{
|
||||
PERF("matrix Quaternion from Euler", q = e, 100);
|
||||
PERF("matrix Quaternion from Dcm", q = d, 100);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MicroBenchMatrix::time_matrix_dcm()
|
||||
{
|
||||
PERF("matrix Dcm from Euler", d = e, 100);
|
||||
PERF("matrix Dcm from Quaternion", d = q, 100);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MicroBenchMatrix::time_matrix_pseduo_inverse()
|
||||
{
|
||||
PERF("matrix 6x16 pseudo inverse (all non-zero columns)", A16 = matrix::geninv(B16), 100);
|
||||
PERF("matrix 6x16 pseudo inverse (4 non-zero columns)", A16 = matrix::geninv(B16_4), 100);
|
||||
return true;
|
||||
}
|
||||
|
||||
ut_declare_test_c(test_microbench_matrix, MicroBenchMatrix)
|
||||
|
||||
} // namespace MicroBenchMatrix
|
||||
@@ -1,252 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file test_microbench_uorb.cpp
|
||||
* Tests for microbench uORB functionality.
|
||||
*/
|
||||
|
||||
#include <unit_test.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <perf/perf_counter.h>
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <px4_platform_common/micro_hal.h>
|
||||
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/sensor_accel.h>
|
||||
#include <uORB/topics/sensor_gyro.h>
|
||||
#include <uORB/topics/sensor_gyro_fifo.h>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
#include <uORB/topics/vehicle_status.h>
|
||||
|
||||
namespace MicroBenchORB
|
||||
{
|
||||
|
||||
#ifdef __PX4_NUTTX
|
||||
#include <nuttx/irq.h>
|
||||
static irqstate_t flags;
|
||||
#endif
|
||||
|
||||
void lock()
|
||||
{
|
||||
#ifdef __PX4_NUTTX
|
||||
flags = px4_enter_critical_section();
|
||||
#endif
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
#ifdef __PX4_NUTTX
|
||||
px4_leave_critical_section(flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define PERF(name, op, count) do { \
|
||||
px4_usleep(1000); \
|
||||
reset(); \
|
||||
perf_counter_t p = perf_alloc(PC_ELAPSED, name); \
|
||||
for (int i = 0; i < count; i++) { \
|
||||
px4_usleep(1); \
|
||||
lock(); \
|
||||
perf_begin(p); \
|
||||
op; \
|
||||
perf_end(p); \
|
||||
unlock(); \
|
||||
reset(); \
|
||||
} \
|
||||
perf_print_counter(p); \
|
||||
perf_free(p); \
|
||||
} while (0)
|
||||
|
||||
class MicroBenchORB : public UnitTest
|
||||
{
|
||||
public:
|
||||
virtual bool run_tests();
|
||||
|
||||
private:
|
||||
|
||||
bool time_px4_uorb();
|
||||
bool time_px4_uorb_direct();
|
||||
|
||||
void reset();
|
||||
|
||||
vehicle_status_s status;
|
||||
vehicle_local_position_s lpos;
|
||||
sensor_gyro_s gyro;
|
||||
sensor_gyro_fifo_s gyro_fifo;
|
||||
};
|
||||
|
||||
bool MicroBenchORB::run_tests()
|
||||
{
|
||||
ut_run_test(time_px4_uorb);
|
||||
ut_run_test(time_px4_uorb_direct);
|
||||
|
||||
return (_tests_failed == 0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T random(T min, T max)
|
||||
{
|
||||
const T scale = rand() / (T) RAND_MAX; /* [0, 1.0] */
|
||||
return min + scale * (max - min); /* [min, max] */
|
||||
}
|
||||
|
||||
void MicroBenchORB::reset()
|
||||
{
|
||||
srand(time(nullptr));
|
||||
|
||||
// initialize with random data
|
||||
status.timestamp = rand();
|
||||
status.mission_failure = rand();
|
||||
|
||||
lpos.timestamp = rand();
|
||||
lpos.dist_bottom_valid = rand();
|
||||
|
||||
gyro.timestamp = rand();
|
||||
|
||||
gyro_fifo.timestamp = rand();
|
||||
}
|
||||
|
||||
ut_declare_test_c(test_microbench_uorb, MicroBenchORB)
|
||||
|
||||
bool MicroBenchORB::time_px4_uorb()
|
||||
{
|
||||
int fd_status = orb_subscribe(ORB_ID(vehicle_status));
|
||||
int fd_lpos = orb_subscribe(ORB_ID(vehicle_local_position));
|
||||
int fd_gyro = orb_subscribe(ORB_ID(sensor_gyro));
|
||||
int fd_gyro_fifo = orb_subscribe(ORB_ID(sensor_gyro_fifo));
|
||||
|
||||
int ret = 0;
|
||||
bool updated = false;
|
||||
uint64_t time = 0;
|
||||
|
||||
PERF("orb_check vehicle_status", ret = orb_check(fd_status, &updated), 100);
|
||||
PERF("orb_copy vehicle_status", ret = orb_copy(ORB_ID(vehicle_status), fd_status, &status), 100);
|
||||
|
||||
printf("\n");
|
||||
|
||||
PERF("orb_check vehicle_local_position", ret = orb_check(fd_lpos, &updated), 100);
|
||||
PERF("orb_copy vehicle_local_position", ret = orb_copy(ORB_ID(vehicle_local_position), fd_lpos, &lpos), 100);
|
||||
|
||||
printf("\n");
|
||||
|
||||
PERF("orb_check sensor_gyro", ret = orb_check(fd_gyro, &updated), 100);
|
||||
PERF("orb_copy sensor_gyro", ret = orb_copy(ORB_ID(sensor_gyro), fd_gyro, &gyro), 100);
|
||||
|
||||
printf("\n");
|
||||
|
||||
PERF("orb_check sensor_gyro_fifo", ret = orb_check(fd_gyro_fifo, &updated), 100);
|
||||
PERF("orb_copy sensor_gyro_fifo", ret = orb_copy(ORB_ID(sensor_gyro_fifo), fd_gyro_fifo, &gyro_fifo), 100);
|
||||
|
||||
printf("\n");
|
||||
|
||||
PERF("orb_exists sensor_accel 0", ret = orb_exists(ORB_ID(sensor_accel), 0), 100);
|
||||
PERF("orb_exists sensor_accel 1", ret = orb_exists(ORB_ID(sensor_accel), 1), 100);
|
||||
PERF("orb_exists sensor_accel 2", ret = orb_exists(ORB_ID(sensor_accel), 2), 100);
|
||||
PERF("orb_exists sensor_accel 3", ret = orb_exists(ORB_ID(sensor_accel), 3), 100);
|
||||
PERF("orb_exists sensor_accel 4", ret = orb_exists(ORB_ID(sensor_accel), 4), 100);
|
||||
PERF("orb_exists sensor_accel 5", ret = orb_exists(ORB_ID(sensor_accel), 5), 100);
|
||||
PERF("orb_exists sensor_accel 6", ret = orb_exists(ORB_ID(sensor_accel), 6), 100);
|
||||
PERF("orb_exists sensor_accel 7", ret = orb_exists(ORB_ID(sensor_accel), 7), 100);
|
||||
PERF("orb_exists sensor_accel 8", ret = orb_exists(ORB_ID(sensor_accel), 8), 100);
|
||||
PERF("orb_exists sensor_accel 9", ret = orb_exists(ORB_ID(sensor_accel), 9), 100);
|
||||
PERF("orb_exists sensor_accel 10", ret = orb_exists(ORB_ID(sensor_accel), 10), 100);
|
||||
|
||||
orb_unsubscribe(fd_status);
|
||||
orb_unsubscribe(fd_lpos);
|
||||
orb_unsubscribe(fd_gyro);
|
||||
orb_unsubscribe(fd_gyro_fifo);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MicroBenchORB::time_px4_uorb_direct()
|
||||
{
|
||||
bool ret = false;
|
||||
bool updated = false;
|
||||
uint64_t time = 0;
|
||||
|
||||
uORB::Subscription vstatus{ORB_ID(vehicle_status)};
|
||||
PERF("uORB::Subscription orb_check vehicle_status", ret = vstatus.updated(), 100);
|
||||
PERF("uORB::Subscription orb_copy vehicle_status", ret = vstatus.copy(&status), 100);
|
||||
|
||||
printf("\n");
|
||||
|
||||
uORB::Subscription local_pos{ORB_ID(vehicle_local_position)};
|
||||
PERF("uORB::Subscription orb_check vehicle_local_position", ret = local_pos.updated(), 100);
|
||||
PERF("uORB::Subscription orb_copy vehicle_local_position", ret = local_pos.copy(&lpos), 100);
|
||||
|
||||
{
|
||||
printf("\n");
|
||||
uORB::Subscription sens_gyro0{ORB_ID(sensor_gyro), 0};
|
||||
PERF("uORB::Subscription orb_check sensor_gyro:0", ret = sens_gyro0.updated(), 100);
|
||||
PERF("uORB::Subscription orb_copy sensor_gyro:0", ret = sens_gyro0.copy(&gyro), 100);
|
||||
}
|
||||
|
||||
{
|
||||
printf("\n");
|
||||
uORB::Subscription sens_gyro1{ORB_ID(sensor_gyro), 1};
|
||||
PERF("uORB::Subscription orb_check sensor_gyro:1", ret = sens_gyro1.updated(), 100);
|
||||
PERF("uORB::Subscription orb_copy sensor_gyro:1", ret = sens_gyro1.copy(&gyro), 100);
|
||||
}
|
||||
|
||||
{
|
||||
printf("\n");
|
||||
uORB::Subscription sens_gyro2{ORB_ID(sensor_gyro), 2};
|
||||
PERF("uORB::Subscription orb_check sensor_gyro:2", ret = sens_gyro2.updated(), 100);
|
||||
PERF("uORB::Subscription orb_copy sensor_gyro:2", ret = sens_gyro2.copy(&gyro), 100);
|
||||
}
|
||||
|
||||
{
|
||||
printf("\n");
|
||||
uORB::Subscription sens_gyro3{ORB_ID(sensor_gyro), 3};
|
||||
PERF("uORB::Subscription orb_check sensor_gyro:3", ret = sens_gyro3.updated(), 100);
|
||||
PERF("uORB::Subscription orb_copy sensor_gyro:3", ret = sens_gyro3.copy(&gyro), 100);
|
||||
}
|
||||
|
||||
{
|
||||
printf("\n");
|
||||
uORB::Subscription sens_gyro_fifo0{ORB_ID(sensor_gyro_fifo), 0};
|
||||
PERF("uORB::Subscription orb_check sensor_gyro_fifo:0", ret = sens_gyro_fifo0.updated(), 100);
|
||||
PERF("uORB::Subscription orb_copy sensor_gyro_fifo:0", ret = sens_gyro_fifo0.copy(&gyro_fifo), 100);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace MicroBenchORB
|
||||
@@ -1,127 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2012-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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file test_servo.c
|
||||
* Tests the servo outputs
|
||||
*/
|
||||
|
||||
#include <px4_platform_common/time.h>
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <drivers/drv_pwm_output.h>
|
||||
#include <systemlib/err.h>
|
||||
|
||||
#include "tests_main.h"
|
||||
|
||||
int test_servo(int argc, char *argv[])
|
||||
{
|
||||
int fd;
|
||||
int result = 0;
|
||||
servo_position_t data[PWM_OUTPUT_MAX_CHANNELS];
|
||||
servo_position_t pos;
|
||||
|
||||
fd = open(PWM_OUTPUT0_DEVICE_PATH, O_RDWR);
|
||||
|
||||
if (fd < 0) {
|
||||
printf("failed opening /dev/pwm_servo\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
result = read(fd, &data, sizeof(data));
|
||||
|
||||
if (result != sizeof(data)) {
|
||||
printf("failed bulk-reading channel values\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
printf("Servo readback, pairs of values should match defaults\n");
|
||||
|
||||
unsigned servo_count;
|
||||
result = ioctl(fd, PWM_SERVO_GET_COUNT, (unsigned long)&servo_count);
|
||||
|
||||
if (result != OK) {
|
||||
warnx("PWM_SERVO_GET_COUNT");
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < servo_count; i++) {
|
||||
result = ioctl(fd, PWM_SERVO_GET(i), (unsigned long)&pos);
|
||||
|
||||
if (result < 0) {
|
||||
printf("failed reading channel %u\n", i);
|
||||
goto out;
|
||||
}
|
||||
|
||||
printf("%u: %u %u\n", i, pos, data[i]);
|
||||
|
||||
}
|
||||
|
||||
/* tell safety that its ok to disable it with the switch */
|
||||
result = ioctl(fd, PWM_SERVO_SET_ARM_OK, 0);
|
||||
|
||||
if (result != OK) {
|
||||
warnx("FAIL: PWM_SERVO_SET_ARM_OK");
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* tell output device that the system is armed (it will output values if safety is off) */
|
||||
result = ioctl(fd, PWM_SERVO_ARM, 0);
|
||||
|
||||
if (result != OK) {
|
||||
warnx("FAIL: PWM_SERVO_ARM");
|
||||
goto out;
|
||||
}
|
||||
|
||||
px4_usleep(5000000);
|
||||
printf("Advancing channel 0 to 1500\n");
|
||||
result = ioctl(fd, PWM_SERVO_SET(0), 1500);
|
||||
printf("Advancing channel 1 to 1800\n");
|
||||
result = ioctl(fd, PWM_SERVO_SET(1), 1800);
|
||||
out:
|
||||
|
||||
if (fd >= 0) {
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -57,7 +57,16 @@ int test_sleep(int argc, char *argv[])
|
||||
fflush(stdout);
|
||||
|
||||
for (unsigned int i = 0; i < nsleeps; i++) {
|
||||
const hrt_abstime time_start = hrt_absolute_time();
|
||||
px4_usleep(100000);
|
||||
const hrt_abstime time_stop = hrt_absolute_time();
|
||||
|
||||
int elapsed = time_stop - time_start;
|
||||
|
||||
if (elapsed < 100000) {
|
||||
PX4_ERR("\t Sleep test failed, only %d us elapsed\n", elapsed);
|
||||
return PX4_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\t Sleep test successful.\n");
|
||||
|
||||
@@ -75,29 +75,25 @@ cycletime(void)
|
||||
|
||||
int test_time(int argc, char *argv[])
|
||||
{
|
||||
hrt_abstime h, c;
|
||||
int lowdelta, maxdelta = 0;
|
||||
int delta, deltadelta;
|
||||
int maxdelta = 0;
|
||||
|
||||
/* enable the cycle counter */
|
||||
(*(unsigned long *)0xe000edfc) |= (1 << 24); /* DEMCR |= DEMCR_TRCENA */
|
||||
(*(unsigned long *)0xe0001000) |= 1; /* DWT_CTRL |= DWT_CYCCNT_ENA */
|
||||
|
||||
/* get an average delta between the two clocks - this should stay roughly the same */
|
||||
delta = 0;
|
||||
int delta = 0;
|
||||
|
||||
for (unsigned i = 0; i < 100; i++) {
|
||||
uint32_t flags = px4_enter_critical_section();
|
||||
|
||||
h = hrt_absolute_time();
|
||||
c = cycletime();
|
||||
|
||||
irqstate_t flags = px4_enter_critical_section();
|
||||
hrt_abstime h = hrt_absolute_time();
|
||||
hrt_abstime c = cycletime();
|
||||
px4_leave_critical_section(flags);
|
||||
|
||||
delta += h - c;
|
||||
}
|
||||
|
||||
lowdelta = abs(delta / 100);
|
||||
int lowdelta = abs(delta / 100);
|
||||
|
||||
/* loop checking the time */
|
||||
for (unsigned i = 0; i < 100; i++) {
|
||||
@@ -106,13 +102,13 @@ int test_time(int argc, char *argv[])
|
||||
|
||||
uint32_t flags = px4_enter_critical_section();
|
||||
|
||||
c = cycletime();
|
||||
h = hrt_absolute_time();
|
||||
hrt_abstime c = cycletime();
|
||||
hrt_abstime h = hrt_absolute_time();
|
||||
|
||||
px4_leave_critical_section(flags);
|
||||
|
||||
delta = h - c;
|
||||
deltadelta = abs(delta - lowdelta);
|
||||
int deltadelta = abs(delta - lowdelta);
|
||||
|
||||
if (deltadelta > maxdelta) {
|
||||
maxdelta = deltadelta;
|
||||
|
||||
@@ -77,7 +77,6 @@ const struct {
|
||||
{"uart_console", test_uart_console, OPT_NOJIGTEST | OPT_NOALLTEST},
|
||||
#endif /* __PX4_NUTTX */
|
||||
|
||||
{"adc", test_adc, OPT_NOJIGTEST},
|
||||
{"atomic_bitset", test_atomic_bitset, 0},
|
||||
{"bezier", test_bezierQuad, 0},
|
||||
{"bitset", test_bitset, 0},
|
||||
@@ -91,17 +90,10 @@ const struct {
|
||||
{"int", test_int, 0},
|
||||
{"i2c_spi_cli", test_i2c_spi_cli, 0},
|
||||
{"IntrusiveQueue", test_IntrusiveQueue, 0},
|
||||
{"jig_voltages", test_jig_voltages, OPT_NOALLTEST},
|
||||
{"IntrusiveSortedList", test_IntrusiveSortedList, 0},
|
||||
{"List", test_List, 0},
|
||||
{"mathlib", test_mathlib, 0},
|
||||
{"matrix", test_matrix, 0},
|
||||
{"microbench_atomic", test_microbench_atomic, 0},
|
||||
{"microbench_hrt", test_microbench_hrt, 0},
|
||||
{"microbench_math", test_microbench_math, 0},
|
||||
{"microbench_matrix", test_microbench_matrix, 0},
|
||||
{"microbench_uorb", test_microbench_uorb, 0},
|
||||
{"mixer", test_mixer, OPT_NOJIGTEST},
|
||||
{"mixer", test_mixer, OPT_NOJIGTEST},
|
||||
{"param", test_param, 0},
|
||||
{"parameters", test_parameters, 0},
|
||||
@@ -110,20 +102,17 @@ const struct {
|
||||
{"ppm_loopback", test_ppm_loopback, OPT_NOALLTEST},
|
||||
{"rc", test_rc, OPT_NOJIGTEST | OPT_NOALLTEST},
|
||||
{"search_min", test_search_min, 0},
|
||||
{"servo", test_servo, OPT_NOJIGTEST | OPT_NOALLTEST},
|
||||
{"sleep", test_sleep, OPT_NOJIGTEST},
|
||||
{"uart_loopback", test_uart_loopback, OPT_NOJIGTEST | OPT_NOALLTEST},
|
||||
{"uart_send", test_uart_send, OPT_NOJIGTEST | OPT_NOALLTEST},
|
||||
{"versioning", test_versioning, 0},
|
||||
{"cli", test_cli, 0},
|
||||
|
||||
{NULL, NULL, 0}
|
||||
};
|
||||
|
||||
#define NTESTS (sizeof(tests) / sizeof(tests[0]))
|
||||
|
||||
static int
|
||||
test_help(int argc, char *argv[])
|
||||
static int test_help(int argc, char *argv[])
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
@@ -136,20 +125,17 @@ test_help(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
test_all(int argc, char *argv[])
|
||||
static int test_all(int argc, char *argv[])
|
||||
{
|
||||
return test_runner(OPT_NOALLTEST);
|
||||
}
|
||||
|
||||
static int
|
||||
test_jig(int argc, char *argv[])
|
||||
static int test_jig(int argc, char *argv[])
|
||||
{
|
||||
return test_runner(OPT_NOJIGTEST);
|
||||
}
|
||||
|
||||
static int
|
||||
test_runner(unsigned option)
|
||||
static int test_runner(unsigned option)
|
||||
{
|
||||
size_t i;
|
||||
char *args[2] = {"all", NULL};
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
extern int test_adc(int argc, char *argv[]);
|
||||
extern int test_atomic_bitset(int argc, char *argv[]);
|
||||
extern int test_bezierQuad(int argc, char *argv[]);
|
||||
extern int test_bitset(int argc, char *argv[]);
|
||||
@@ -58,17 +57,11 @@ extern int test_hrt(int argc, char *argv[]);
|
||||
extern int test_int(int argc, char *argv[]);
|
||||
extern int test_i2c_spi_cli(int argc, char *argv[]);
|
||||
extern int test_IntrusiveQueue(int argc, char *argv[]);
|
||||
extern int test_jig_voltages(int argc, char *argv[]);
|
||||
extern int test_led(int argc, char *argv[]);
|
||||
extern int test_IntrusiveSortedList(int argc, char *argv[]);
|
||||
extern int test_List(int argc, char *argv[]);
|
||||
extern int test_mathlib(int argc, char *argv[]);
|
||||
extern int test_matrix(int argc, char *argv[]);
|
||||
extern int test_microbench_atomic(int argc, char *argv[]);
|
||||
extern int test_microbench_hrt(int argc, char *argv[]);
|
||||
extern int test_microbench_math(int argc, char *argv[]);
|
||||
extern int test_microbench_matrix(int argc, char *argv[]);
|
||||
extern int test_microbench_uorb(int argc, char *argv[]);
|
||||
extern int test_mixer(int argc, char *argv[]);
|
||||
extern int test_mount(int argc, char *argv[]);
|
||||
extern int test_param(int argc, char *argv[]);
|
||||
@@ -78,7 +71,6 @@ extern int test_ppm(int argc, char *argv[]);
|
||||
extern int test_ppm_loopback(int argc, char *argv[]);
|
||||
extern int test_rc(int argc, char *argv[]);
|
||||
extern int test_search_min(int argc, char *argv[]);
|
||||
extern int test_servo(int argc, char *argv[]);
|
||||
extern int test_sleep(int argc, char *argv[]);
|
||||
extern int test_time(int argc, char *argv[]);
|
||||
extern int test_uart_baudchange(int argc, char *argv[]);
|
||||
|
||||
Reference in New Issue
Block a user