mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
292 lines
8.6 KiB
Diff
292 lines
8.6 KiB
Diff
From 30484a41cc1ad29344583521ae9478f25206f05d Mon Sep 17 00:00:00 2001
|
|
From: Alexandre Abadie <alexandre.abadie@inria.fr>
|
|
Date: Wed, 27 Jan 2021 13:48:26 +0100
|
|
Subject: [PATCH 2/2] Adapt unittests for RIOT
|
|
|
|
---
|
|
unittests/fix16_exp_unittests.c | 15 ++++++------
|
|
unittests/fix16_macros_unittests.c | 13 +++++-----
|
|
unittests/fix16_str_unittests.c | 13 +++++-----
|
|
unittests/fix16_unittests.c | 39 +++++++++++++++---------------
|
|
unittests/libfixmath-unittests.h | 6 ++++-
|
|
5 files changed, 47 insertions(+), 39 deletions(-)
|
|
|
|
diff --git a/unittests/fix16_exp_unittests.c b/unittests/fix16_exp_unittests.c
|
|
index afb6706..532f918 100644
|
|
--- a/unittests/fix16_exp_unittests.c
|
|
+++ b/unittests/fix16_exp_unittests.c
|
|
@@ -2,11 +2,11 @@
|
|
#include <stdio.h>
|
|
#include <math.h>
|
|
#include <stdbool.h>
|
|
-#include "unittests.h"
|
|
+#include "libfixmath-unittests.h"
|
|
|
|
#define delta(a,b) (((a)>=(b)) ? (a)-(b) : (b)-(a))
|
|
|
|
-int main()
|
|
+int fix16_exp_unittests(void)
|
|
{
|
|
int status = 0;
|
|
{
|
|
@@ -41,7 +41,7 @@ int main()
|
|
count++;
|
|
}
|
|
|
|
- printf("Worst delta %d with input %d\n", max_delta, worst);
|
|
+ printf("Worst delta %ld with input %ld\n", (long)max_delta, (long)worst);
|
|
printf("Average delta %0.2f\n", (float)sum / count);
|
|
|
|
TEST(max_delta < 200);
|
|
@@ -80,7 +80,7 @@ int main()
|
|
count++;
|
|
}
|
|
|
|
- printf("Worst delta %0.4f%% with input %d\n", max_delta, worst);
|
|
+ printf("Worst delta %0.4f%% with input %ld\n", max_delta, (long)worst);
|
|
printf("Average delta %0.4f%%\n", sum / count);
|
|
|
|
TEST(max_delta < 1);
|
|
@@ -111,14 +111,15 @@ int main()
|
|
count++;
|
|
}
|
|
|
|
- printf("Worst delta %d with input %d\n", max_delta, worst);
|
|
+ printf("Worst delta %ld with input %ld\n", (long)max_delta, (long)worst);
|
|
printf("Average delta %0.2f\n", (float)sum / count);
|
|
|
|
TEST(max_delta < 20);
|
|
}
|
|
|
|
- if (status != 0)
|
|
- fprintf(stdout, "\n\nSome tests FAILED!\n");
|
|
+ if (status != 0) {
|
|
+ printf("\n\nSome tests FAILED!\n");
|
|
+ }
|
|
|
|
return status;
|
|
}
|
|
diff --git a/unittests/fix16_macros_unittests.c b/unittests/fix16_macros_unittests.c
|
|
index cdfcfaf..2e7bc5c 100644
|
|
--- a/unittests/fix16_macros_unittests.c
|
|
+++ b/unittests/fix16_macros_unittests.c
|
|
@@ -4,13 +4,13 @@
|
|
#include <stdio.h>
|
|
#include <math.h>
|
|
#include <stdbool.h>
|
|
-#include "unittests.h"
|
|
+#include "libfixmath-unittests.h"
|
|
|
|
#define DO_TEST(i,m) \
|
|
TEST(F16(i ## . ## m) == F16C(i,m)) \
|
|
TEST(F16(i ## . ## m) == fix16_from_dbl(i ## . ## m))
|
|
|
|
-int main()
|
|
+int fix16_macros_unittests(void)
|
|
{
|
|
int status = 0;
|
|
|
|
@@ -101,10 +101,11 @@ int main()
|
|
DO_TEST( -1,07143)
|
|
DO_TEST( -1,07737)
|
|
DO_TEST( -0,22957)
|
|
-
|
|
- if (status != 0)
|
|
- fprintf(stdout, "\n\nSome tests FAILED!\n");
|
|
-
|
|
+
|
|
+ if (status != 0) {
|
|
+ printf("\n\nSome tests FAILED!\n");
|
|
+ }
|
|
+
|
|
return status;
|
|
}
|
|
|
|
diff --git a/unittests/fix16_str_unittests.c b/unittests/fix16_str_unittests.c
|
|
index 46da171..b1f811d 100644
|
|
--- a/unittests/fix16_str_unittests.c
|
|
+++ b/unittests/fix16_str_unittests.c
|
|
@@ -3,9 +3,9 @@
|
|
#include <math.h>
|
|
#include <string.h>
|
|
#include <stdbool.h>
|
|
-#include "unittests.h"
|
|
+#include "libfixmath-unittests.h"
|
|
|
|
-int main()
|
|
+int fix16_str_unittests(void)
|
|
{
|
|
int status = 0;
|
|
|
|
@@ -93,14 +93,14 @@ int main()
|
|
|
|
if (strcmp(goodbuf, testbuf) != 0)
|
|
{
|
|
- printf("Value (fix16_t)%d gave %s, should be %s\n", value, testbuf, goodbuf);
|
|
+ printf("Value (fix16_t)%ld gave %s, should be %s\n", (long)value, testbuf, goodbuf);
|
|
ok = false;
|
|
}
|
|
|
|
fix16_t roundtrip = fix16_from_str(testbuf);
|
|
if (roundtrip != value)
|
|
{
|
|
- printf("Roundtrip failed: (fix16_t)%d -> %s -> (fix16_t)%d\n", value, testbuf, roundtrip);
|
|
+ printf("Roundtrip failed: (fix16_t)%ld -> %s -> (fix16_t)%ld\n", (long)value, testbuf, (long)roundtrip);
|
|
ok = false;
|
|
}
|
|
|
|
@@ -110,8 +110,9 @@ int main()
|
|
TEST(ok);
|
|
}
|
|
|
|
- if (status != 0)
|
|
- fprintf(stdout, "\n\nSome tests FAILED!\n");
|
|
+ if (status != 0) {
|
|
+ printf("\n\nSome tests FAILED!\n");
|
|
+ }
|
|
|
|
return status;
|
|
}
|
|
diff --git a/unittests/fix16_unittests.c b/unittests/fix16_unittests.c
|
|
index 51d8f61..265b637 100644
|
|
--- a/unittests/fix16_unittests.c
|
|
+++ b/unittests/fix16_unittests.c
|
|
@@ -3,7 +3,7 @@
|
|
#include <math.h>
|
|
#include <stdbool.h>
|
|
#include "int64.h"
|
|
-#include "unittests.h"
|
|
+#include "libfixmath-unittests.h"
|
|
|
|
const fix16_t testcases[] = {
|
|
// Small numbers
|
|
@@ -48,7 +48,7 @@ const fix16_t max_delta = 1;
|
|
const fix16_t max_delta = 0;
|
|
#endif
|
|
|
|
-int main()
|
|
+int fix16_unittests(void)
|
|
{
|
|
int status = 0;
|
|
|
|
@@ -102,7 +102,7 @@ int main()
|
|
#ifndef FIXMATH_NO_OVERFLOW
|
|
if (result != fix16_overflow)
|
|
{
|
|
- printf("\n%d * %d overflow not detected!\n", a, b);
|
|
+ printf("\n%ld * %ld overflow not detected!\n", (long)a, (long)b);
|
|
failures++;
|
|
}
|
|
#endif
|
|
@@ -110,8 +110,8 @@ int main()
|
|
continue;
|
|
}
|
|
|
|
- printf("\n%d * %d = %d\n", a, b, result);
|
|
- printf("%f * %f = %d\n", fa, fb, fresult);
|
|
+ printf("\n%ld * %ld = %ld\n", (long)a, (long)b, (long)result);
|
|
+ printf("%f * %f = %ld\n", fa, fb, (long)fresult);
|
|
failures++;
|
|
}
|
|
}
|
|
@@ -177,7 +177,7 @@ int main()
|
|
#ifndef FIXMATH_NO_OVERFLOW
|
|
if (result != fix16_overflow)
|
|
{
|
|
- printf("\n%d / %d overflow not detected!\n", a, b);
|
|
+ printf("\n%ld / %ld overflow not detected!\n", (long)a, (long)b);
|
|
failures++;
|
|
}
|
|
#endif
|
|
@@ -223,7 +223,7 @@ int main()
|
|
#ifndef FIXMATH_NO_OVERFLOW
|
|
if (result != fix16_overflow)
|
|
{
|
|
- printf("\n%d + %d overflow not detected!\n", a, b);
|
|
+ printf("\n%ld + %ld overflow not detected!\n", (long)a, (long)b);
|
|
failures++;
|
|
}
|
|
#endif
|
|
@@ -231,8 +231,8 @@ int main()
|
|
continue;
|
|
}
|
|
|
|
- printf("\n%d + %d = %d\n", a, b, result);
|
|
- printf("%f + %f = %d\n", fa, fb, fresult);
|
|
+ printf("\n%ld + %ld = %ld\n", (long)a, (long)b, (long)result);
|
|
+ printf("%f + %f = %ld\n", fa, fb, (long)fresult);
|
|
failures++;
|
|
}
|
|
}
|
|
@@ -269,16 +269,16 @@ int main()
|
|
#ifndef FIXMATH_NO_OVERFLOW
|
|
if (result != fix16_overflow)
|
|
{
|
|
- printf("\n%d - %d overflow not detected!\n", a, b);
|
|
+ printf("\n%ld - %ld overflow not detected!\n", (long)a, (long)b);
|
|
failures++;
|
|
}
|
|
#endif
|
|
// Legitimate overflow
|
|
continue;
|
|
}
|
|
-
|
|
- printf("\n%d - %d = %d\n", a, b, result);
|
|
- printf("%f - %f = %d\n", fa, fb, fresult);
|
|
+
|
|
+ printf("\n%ld - %ld = %ld\n", (long)a, (long)b, (long)result);
|
|
+ printf("%f - %f = %ld\n", fa, fb, (long)fresult);
|
|
failures++;
|
|
}
|
|
}
|
|
@@ -322,8 +322,8 @@ int main()
|
|
|
|
if (delta(fresult, result) > max_delta)
|
|
{
|
|
- printf("\nfix16_sqrt(%d) = %d\n", a, result);
|
|
- printf("sqrt(%f) = %d\n", fa, fresult);
|
|
+ printf("\nfix16_sqrt(%ld) = %ld\n", (long)a, (long)result);
|
|
+ printf("sqrt(%f) = %ld\n", fa, (long)fresult);
|
|
failures++;
|
|
}
|
|
}
|
|
@@ -383,9 +383,10 @@ int main()
|
|
TEST(fix16_lerp32(fix16_minimum, fix16_maximum, 0xffffffff) == (fix16_maximum - 1));
|
|
TEST(fix16_lerp32(-fix16_maximum, fix16_maximum, 0x80000000) == 0);
|
|
}
|
|
-
|
|
- if (status != 0)
|
|
- fprintf(stdout, "\n\nSome tests FAILED!\n");
|
|
-
|
|
+
|
|
+ if (status != 0) {
|
|
+ printf( "\n\nSome tests FAILED!\n");
|
|
+ }
|
|
+
|
|
return status;
|
|
}
|
|
diff --git a/unittests/libfixmath-unittests.h b/unittests/libfixmath-unittests.h
|
|
index 57ad8f8..cab51ca 100644
|
|
--- a/unittests/libfixmath-unittests.h
|
|
+++ b/unittests/libfixmath-unittests.h
|
|
@@ -7,7 +7,7 @@
|
|
if (!(x)) { \
|
|
fflush(stdout); \
|
|
fflush(stderr); \
|
|
- fprintf(stderr, "\033[31;1mFAILED:\033[22;39m " __FILE__ ":" STR2(__LINE__) " " #x "\n"); \
|
|
+ printf("\033[31;1mFAILED:\033[22;39m " RIOT_FILE_NOPATH ":" STR2(__LINE__) " " #x "\n"); \
|
|
status = 1; \
|
|
} else { \
|
|
fflush(stdout); \
|
|
@@ -15,3 +15,7 @@
|
|
printf("\033[32;1mOK:\033[22;39m " #x "\n"); \
|
|
}
|
|
|
|
+int fix16_exp_unittests(void);
|
|
+int fix16_macros_unittests(void);
|
|
+int fix16_str_unittests(void);
|
|
+int fix16_unittests(void);
|
|
--
|
|
2.27.0
|
|
|