diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2012-08-13 21:09:08 +0200 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2012-08-13 21:09:08 +0200 |
commit | d92cdc7cfac667e5926f98d06936bbbff89ccfe9 (patch) | |
tree | 4ac280b55b30bb517673de46d55cb41099d1b1e6 /apps | |
parent | 43019ba618d45c5f2cc064f5dd04ee83bbeea4be (diff) | |
download | px4-firmware-d92cdc7cfac667e5926f98d06936bbbff89ccfe9.tar.gz px4-firmware-d92cdc7cfac667e5926f98d06936bbbff89ccfe9.tar.bz2 px4-firmware-d92cdc7cfac667e5926f98d06936bbbff89ccfe9.zip |
Improved float tests
Diffstat (limited to 'apps')
-rw-r--r-- | apps/px4/tests/Makefile | 2 | ||||
-rw-r--r-- | apps/px4/tests/test_float.c | 73 | ||||
-rw-r--r-- | apps/px4/tests/tests_main.c | 28 |
3 files changed, 31 insertions, 72 deletions
diff --git a/apps/px4/tests/Makefile b/apps/px4/tests/Makefile index 41979f85a..ad8849454 100644 --- a/apps/px4/tests/Makefile +++ b/apps/px4/tests/Makefile @@ -37,6 +37,6 @@ APPNAME = tests PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 4096 +STACKSIZE = 8096 include $(APPDIR)/mk/app.mk diff --git a/apps/px4/tests/test_float.c b/apps/px4/tests/test_float.c index 02e748e70..0439476e6 100644 --- a/apps/px4/tests/test_float.c +++ b/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 * modification, are permitted provided that the following conditions @@ -13,7 +13,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * 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 * without specific prior written permission. * @@ -32,64 +32,25 @@ * ****************************************************************************/ -/**************************************************************************** - * Included Files - ****************************************************************************/ +/** + * @file tests_float.c + * Floating point tests + */ #include <nuttx/config.h> - #include <sys/types.h> - #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <debug.h> - #include <arch/board/board.h> - #include <arch/board/drv_led.h> - #include "tests.h" - #include <math.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 { float f; double d; @@ -187,15 +148,25 @@ int test_float(int argc, char *argv[]) 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"); } 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; } - 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; } - 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 (44330.0 * (1.0 - pow((96286LL / 101325.0), 0.190295)));\n"); fflush(stdout); usleep(20000); 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) { diff --git a/apps/px4/tests/tests_main.c b/apps/px4/tests/tests_main.c index 63af9098d..268e7d5f9 100644 --- a/apps/px4/tests/tests_main.c +++ b/apps/px4/tests/tests_main.c @@ -112,14 +112,6 @@ struct { {NULL, NULL, 0, 0} }; -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - static int test_help(int argc, char *argv[]) { @@ -198,7 +190,7 @@ test_all(int argc, char *argv[]) /* Print failed tests */ if (failcount > 0) printf(" Failed tests:\n\n"); - int k; + unsigned int k; for (k = 0; k < i; k++) { 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(ec); + + return OK; } -test_jig(int argc, char *argv[]) +int test_jig(int argc, char *argv[]) { unsigned i; char *args[2] = {"jig", NULL}; @@ -297,7 +291,7 @@ test_jig(int argc, char *argv[]) /* Print failed tests */ if (failcount > 0) printf(" Failed tests:\n\n"); - int k; + unsigned int k; for (k = 0; k < i; k++) { if ((tests[k].passed == 0) && !(tests[k].options & OPT_NOJIGTEST)) @@ -310,17 +304,11 @@ test_jig(int argc, char *argv[]) return 0; } - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - __EXPORT int tests_main(int argc, char *argv[]); -/**************************************************************************** - * Name: tests_main - ****************************************************************************/ - +/** + * Executes system tests. + */ int tests_main(int argc, char *argv[]) { unsigned i; |