39 #include <px4_platform_common/px4_config.h> 40 #include <px4_platform_common/posix.h> 42 #include <sys/types.h> 50 #include <arch/board/board.h> 54 #include <semaphore.h> 64 #define NUM_MISSIONS_TEST 50 66 #define DM_MAX_DATA_SIZE sizeof(struct mission_s) 73 PX4_INFO(
"Starting dataman test task %s", argv[1]);
75 int my_id = atoi(argv[1]);
79 PX4_ERR(
"%d read an invalid item failed", my_id);
85 PX4_ERR(
"%d read an invalid index failed", my_id);
90 unsigned hit = 0, miss = 0;
94 memset(buffer, my_id,
sizeof(buffer));
96 unsigned hash = i ^ my_id;
103 PX4_WARN(
"task %d: write failed, index %d, length %d", my_id, hash, len);
107 if (i % (NUM_MISSIONS_TEST / 10) == 0) {
108 PX4_INFO(
"task %d: %.0f%%", my_id, (
double)i * 100.0
f / NUM_MISSIONS_TEST);
111 px4_usleep(rand() & ((64 * 1024) - 1));
118 unsigned hash = i ^ my_id;
123 PX4_WARN(
"task %d: read failed length test, index %d", my_id, hash);
127 if (buffer[0] == my_id) {
131 PX4_WARN(
"task %d: read failed length test, index %d, wanted %d, got %d", my_id, hash, len, len2);
135 if (buffer[1] != i) {
136 PX4_WARN(
"task %d: data verification failed, index %d, wanted %d, got %d", my_id, hash, my_id, buffer[1]);
146 PX4_INFO(
"task %d pass, hit %d, miss %d, io time read %" PRIu64
"ms. write %" PRIu64
"ms.",
147 my_id, hit, miss, (rend - rstart) / NUM_MISSIONS_TEST / 1000, (wend - wstart) / NUM_MISSIONS_TEST / 1000);
148 px4_sem_post(
sems + my_id);
152 PX4_ERR(
"test_dataman FAILED: task %d, buffer %02x %02x %02x %02x %02x %02x",
153 my_id, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]);
154 px4_sem_post(
sems + my_id);
162 unsigned num_tasks = 4;
166 num_tasks = atoi(argv[1]);
169 sems = (px4_sem_t *)malloc(num_tasks *
sizeof(px4_sem_t));
171 PX4_INFO(
"Running %d tasks", num_tasks);
173 for (i = 0; i < num_tasks; i++) {
177 snprintf(a, 16,
"%d", i);
179 char *av[] = {
"tests_dataman", a, NULL};
181 px4_sem_init(
sems + i, 1, 0);
183 px4_sem_setprotocol(
sems, SEM_PRIO_NONE);
186 if ((task = px4_task_spawn_cmd(
"dataman", SCHED_DEFAULT, SCHED_PRIORITY_MAX - 5, 2048,
task_main, av)) <= 0) {
187 PX4_ERR(
"task start failed");
191 for (i = 0; i < num_tasks; i++) {
192 px4_sem_wait(
sems + i);
193 px4_sem_destroy(
sems + i);
198 bool got_error =
false;
200 for (i = 0; i < num_tasks; i++) {
221 if (i >= NUM_MISSIONS_TEST) {
222 PX4_ERR(
"Restart in-flight failed");
231 PX4_ERR(
"Restart power-on failed");
#define NUM_MISSIONS_TEST
int test_dataman(int argc, char *argv[])
LED driver API to control the onboard LED(s) via ioctl() interface.
static int task_main(int argc, char *argv[])
High-resolution timer with callouts and timekeeping.
__EXPORT ssize_t dm_read(dm_item_t item, unsigned index, void *buf, size_t count)
Retrieve from the data manager file.
__EXPORT int dm_restart(dm_reset_reason reason)
Tell the data manager about the type of the last reset.
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
__EXPORT ssize_t dm_write(dm_item_t item, unsigned index, dm_persitence_t persistence, const void *buf, size_t count)
Write to the data manager file.
static bool * task_returned_error
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).