Browse Source

Improved float tests

sbg
Lorenz Meier 13 years ago
parent
commit
d92cdc7cfa
  1. 2
      apps/px4/tests/Makefile
  2. 73
      apps/px4/tests/test_float.c
  3. 28
      apps/px4/tests/tests_main.c

2
apps/px4/tests/Makefile

@ -37,6 +37,6 @@
APPNAME = tests APPNAME = tests
PRIORITY = SCHED_PRIORITY_DEFAULT PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 4096 STACKSIZE = 8096
include $(APPDIR)/mk/app.mk include $(APPDIR)/mk/app.mk

73
apps/px4/tests/test_float.c

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* px4/sensors/test_gpio.c
* *
* Copyright (C) 2012 PX4 Development Team. All rights reserved. * Copyright (C) 2012 PX4 Development Team. All rights reserved.
* Author: @author Lorenz Meier <lm@inf.ethz.ch>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -13,7 +13,7 @@
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* 3. Neither the name NuttX nor the names of its contributors may be * 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software * used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
@ -32,64 +32,25 @@
* *
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /**
* Included Files * @file tests_float.c
****************************************************************************/ * Floating point tests
*/
#include <nuttx/config.h> #include <nuttx/config.h>
#include <sys/types.h> #include <sys/types.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <debug.h> #include <debug.h>
#include <arch/board/board.h> #include <arch/board/board.h>
#include <arch/board/drv_led.h> #include <arch/board/drv_led.h>
#include "tests.h" #include "tests.h"
#include <math.h> #include <math.h>
#include <float.h> #include <float.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: test_led
****************************************************************************/
typedef union { typedef union {
float f; float f;
double d; double d;
@ -187,15 +148,25 @@ int test_float(int argc, char *argv[])
float atan2f_ones = atan2(1.0f, 1.0f); float atan2f_ones = atan2(1.0f, 1.0f);
if (fabs(atan2f_ones - 0.785398163397448278999490867136f) < FLT_EPSILON) { if (fabsf(atan2f_ones - 0.785398163397448278999490867136f) < FLT_EPSILON) {
printf("\t success: atan2f(1.0f, 1.0f) == 0.78539f\n"); printf("\t success: atan2f(1.0f, 1.0f) == 0.78539f\n");
} else { } else {
printf("\t FAIL: atan2f(1.0f, 1.0f) != 0.78539f, result: %f\n", atan2f_ones); printf("\t FAIL: atan2f(1.0f, 1.0f) != 0.78539f, result: %8.4f\n", atan2f_ones);
ret = -4; ret = -4;
} }
printf("\t testing printing: printf(0.553415f): %f\n", 0.553415f); char sbuf[30];
sprintf(sbuf, "%8.4f", 0.553415f);
if (sbuf[0] == ' ' && sbuf[1] == ' ' && sbuf[2] == '0' &&
sbuf[3] == '.' && sbuf[4] == '5' && sbuf[5] == '5'
&& sbuf[6] == '3' && sbuf[7] == '4' && sbuf[8] == '\0') {
printf("\t success: printf(\"%8.4f\", 0.553415f) == %8.4f\n", 0.553415f);
} else {
printf("\t FAIL: printf(\"%8.4f\", 0.553415f) != \" 0.5534\", result: %s\n", sbuf);
ret = -5;
}
@ -259,14 +230,14 @@ int test_float(int argc, char *argv[])
ret = -7; ret = -7;
} }
printf("\t testing printing: printf(0.553415): %f\n", 0.553415); printf("\t testing printing: printf(0.553415): %8.4f\n", 0.553415);
printf("\t testing pow() with magic value\n"); printf("\t testing pow() with magic value\n");
printf("\t (44330.0 * (1.0 - pow((96286LL / 101325.0), 0.190295)));\n"); printf("\t (44330.0 * (1.0 - pow((96286LL / 101325.0), 0.190295)));\n");
fflush(stdout); fflush(stdout);
usleep(20000); usleep(20000);
double powres = (44330.0 * (1.0 - pow((96286LL / 101325.0), 0.190295))); double powres = (44330.0 * (1.0 - pow((96286LL / 101325.0), 0.190295)));
printf("\t success: result: %f\n", (float)powres); printf("\t success: result: %8.4f\n", (double)powres);
if (ret == 0) { if (ret == 0) {

28
apps/px4/tests/tests_main.c

@ -112,14 +112,6 @@ struct {
{NULL, NULL, 0, 0} {NULL, NULL, 0, 0}
}; };
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
static int static int
test_help(int argc, char *argv[]) test_help(int argc, char *argv[])
{ {
@ -198,7 +190,7 @@ test_all(int argc, char *argv[])
/* Print failed tests */ /* Print failed tests */
if (failcount > 0) printf(" Failed tests:\n\n"); if (failcount > 0) printf(" Failed tests:\n\n");
int k; unsigned int k;
for (k = 0; k < i; k++) { for (k = 0; k < i; k++) {
if ((tests[k].passed == 0) && !(tests[k].options & OPT_NOALLTEST)) { if ((tests[k].passed == 0) && !(tests[k].options & OPT_NOALLTEST)) {
@ -239,9 +231,11 @@ test_perf(int argc, char *argv[])
perf_free(cc); perf_free(cc);
perf_free(ec); perf_free(ec);
return OK;
} }
test_jig(int argc, char *argv[]) int test_jig(int argc, char *argv[])
{ {
unsigned i; unsigned i;
char *args[2] = {"jig", NULL}; char *args[2] = {"jig", NULL};
@ -297,7 +291,7 @@ test_jig(int argc, char *argv[])
/* Print failed tests */ /* Print failed tests */
if (failcount > 0) printf(" Failed tests:\n\n"); if (failcount > 0) printf(" Failed tests:\n\n");
int k; unsigned int k;
for (k = 0; k < i; k++) for (k = 0; k < i; k++)
{ {
if ((tests[k].passed == 0) && !(tests[k].options & OPT_NOJIGTEST)) if ((tests[k].passed == 0) && !(tests[k].options & OPT_NOJIGTEST))
@ -310,17 +304,11 @@ test_jig(int argc, char *argv[])
return 0; return 0;
} }
/****************************************************************************
* Public Functions
****************************************************************************/
__EXPORT int tests_main(int argc, char *argv[]); __EXPORT int tests_main(int argc, char *argv[]);
/**************************************************************************** /**
* Name: tests_main * Executes system tests.
****************************************************************************/ */
int tests_main(int argc, char *argv[]) int tests_main(int argc, char *argv[])
{ {
unsigned i; unsigned i;

Loading…
Cancel
Save