Skip to content

Commit 16b3bbf

Browse files
committed
replaced printf with boot_sprintf in autotests to reduce the chance of GDB1 errors
1 parent eb939d0 commit 16b3bbf

File tree

21 files changed

+178
-73
lines changed

21 files changed

+178
-73
lines changed

test/floating_point/complex/src/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <ti/screen.h>
77
#include <ti/getcsc.h>
88
#include <sys/util.h>
9+
#include <ti/sprintf.h>
910

1011
#include <complex.h>
1112

@@ -191,9 +192,11 @@ int main(void) {
191192
os_ClrHome();
192193
size_t fail_index = run_test();
193194
if (fail_index == SIZE_MAX) {
194-
printf("All tests passed");
195+
fputs("All tests passed", stdout);
195196
} else {
196-
printf("Failed test: L%zu\n", fail_index);
197+
char buf[sizeof("Failed test: 16777215\n")];
198+
boot_sprintf(buf, "Failed test: %u\n", fail_index);
199+
fputs(buf, stdout);
197200
}
198201

199202
while (!os_GetCSC());

test/floating_point/float32_classification/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ static test_result fpclassify_test(void) {
136136

137137
int main(void) {
138138
os_ClrHome();
139-
printf("Testing 2^" NUM_TO_STR(test_count) " inputs");
139+
fputs("Testing 2^" NUM_TO_STR(test_count) " inputs", stdout);
140140
test_result ret = fpclassify_test();
141141
os_ClrHome();
142142
if (ret.passed) {
143-
printf("All tests passed");
143+
fputs("All tests passed", stdout);
144144
} else {
145145
printf(
146146
"Failed test:\n0x%08lX\nTruth: %06o_%d\nGuess: %06o_%d",

test/floating_point/float32_frexp/src/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <ti/screen.h>
88
#include <ti/getcsc.h>
99
#include <sys/util.h>
10+
#include <ti/sprintf.h>
1011

1112
#include "f32_frexp_LUT.h"
1213

@@ -48,9 +49,11 @@ int main(void) {
4849
os_ClrHome();
4950
size_t fail_index = run_test();
5051
if (fail_index == SIZE_MAX) {
51-
printf("All tests passed");
52+
fputs("All tests passed", stdout);
5253
} else {
53-
printf("Failed test: %zu", fail_index);
54+
char buf[sizeof("Failed test: 16777215\n")];
55+
boot_sprintf(buf, "Failed test: %u\n", fail_index);
56+
fputs(buf, stdout);
5457
}
5558

5659
while (!os_GetCSC());

test/floating_point/float32_ilogb/src/main.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <ti/screen.h>
88
#include <ti/getcsc.h>
99
#include <sys/util.h>
10+
#include <ti/sprintf.h>
1011

1112
#include "f32_ilogb_LUT.h"
1213

@@ -23,8 +24,9 @@ size_t run_test(void) {
2324
for (size_t i = 0; i < length; i++) {
2425
int result = ilogbf(input[i]);
2526
if (result != output[i]) {
26-
// printf("%3zu: %08lX\n\t%d != %d\n", i, input[i], result, output[i]);
27-
// while (!os_GetCSC());
27+
#if 0
28+
printf("%3zu: %08lX\n\t%d != %d\n", i, input[i], result, output[i]);
29+
#endif
2830
return i;
2931
}
3032
}
@@ -34,13 +36,14 @@ size_t run_test(void) {
3436
}
3537

3638
int main(void) {
37-
3839
os_ClrHome();
3940
size_t fail_index = run_test();
4041
if (fail_index == SIZE_MAX) {
41-
printf("All tests passed");
42+
fputs("All tests passed", stdout);
4243
} else {
43-
printf("Failed test: %zu", fail_index);
44+
char buf[sizeof("Failed test: 16777215\n")];
45+
boot_sprintf(buf, "Failed test: %u\n", fail_index);
46+
fputs(buf, stdout);
4447
}
4548

4649
while (!os_GetCSC());

test/floating_point/float32_ldexp/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int main(void) {
6161
if (fail_index == SIZE_MAX) {
6262
fputs("All tests passed", stdout);
6363
} else {
64-
char buf[sizeof("Failed test: -8388608\n")];
64+
char buf[sizeof("Failed test: 16777215\n")];
6565
boot_sprintf(buf, "Failed test: %u\n", fail_index);
6666
fputs(buf, stdout);
6767
}

test/floating_point/float32_math/src/main.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <ti/screen.h>
77
#include <ti/getcsc.h>
88
#include <sys/util.h>
9+
#include <ti/sprintf.h>
910

1011
#include <bit>
1112
#include <cmath>
@@ -38,7 +39,7 @@ static bool test_result(float guess, float truth) {
3839

3940
#define TEST(guess, truth) if (test_result(guess, truth)) { return __LINE__; }
4041

41-
static size_t run_test(void) {
42+
static int run_test(void) {
4243

4344
TEST(std::exp ( 6.3f), 544.5719101259290330593886677332f);
4445
TEST(std::exp ( -4.2f), 0.014995576820477706211984360229f);
@@ -91,16 +92,22 @@ static size_t run_test(void) {
9192
TEST(std::hypot(1.23f, 4.56f, 7.89f), 9.195575022803087326242198470012610630662f);
9293

9394
/* passed all */
94-
return SIZE_MAX;
95+
return 0;
9596
}
9697

9798
int main(void) {
9899
os_ClrHome();
99-
size_t fail_index = run_test();
100-
if (fail_index == SIZE_MAX) {
101-
printf("All tests passed");
100+
int failed_test = run_test();
101+
if (failed_test != 0) {
102+
char buf[sizeof("Failed test L-8388608\n")];
103+
boot_sprintf(buf, "Failed test L%d\n", failed_test);
104+
fputs(buf, stdout);
105+
#if 0
106+
/* debugging */
107+
printf("ULP: %ld\n", fail_ulp);
108+
#endif
102109
} else {
103-
printf("Failed test: L%zu\nULP: %ld", fail_index, fail_ulp);
110+
fputs("All tests passed", stdout);
104111
}
105112

106113
while (!os_GetCSC());

test/floating_point/float32_modf/src/main.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <ti/screen.h>
88
#include <ti/getcsc.h>
99
#include <sys/util.h>
10+
#include <ti/sprintf.h>
1011

1112
#include "f32_modf_LUT.h"
1213

@@ -36,12 +37,14 @@ size_t run_test(void) {
3637
isnan(frac_part.flt) && isnan(output[i].frac_part.flt) &&
3738
isnan(trunc_part.flt) && isnan(output[i].trunc_part.flt)
3839
)) {
39-
printf(
40-
"I: %08lX T: %zu\nG: %08lX %08lX\nT: %08lX %08lX\n",
41-
input[i].bin, i,
42-
frac_part.bin, trunc_part.bin,
43-
output[i].frac_part.bin, output[i].trunc_part.bin
44-
);
40+
#if 0
41+
printf(
42+
"I: %08lX T: %zu\nG: %08lX %08lX\nT: %08lX %08lX\n",
43+
input[i].bin, i,
44+
frac_part.bin, trunc_part.bin,
45+
output[i].frac_part.bin, output[i].trunc_part.bin
46+
);
47+
#endif
4548
return i;
4649
}
4750
}
@@ -55,9 +58,11 @@ int main(void) {
5558
os_ClrHome();
5659
size_t fail_index = run_test();
5760
if (fail_index == SIZE_MAX) {
58-
printf("All tests passed");
61+
fputs("All tests passed", stdout);
5962
} else {
60-
printf("Failed test: %zu", fail_index);
63+
char buf[sizeof("Failed test: 16777215\n")];
64+
boot_sprintf(buf, "Failed test: %u\n", fail_index);
65+
fputs(buf, stdout);
6166
}
6267

6368
while (!os_GetCSC());

test/floating_point/float32_to_float64/src/main.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <ti/screen.h>
88
#include <ti/getcsc.h>
99
#include <sys/util.h>
10+
#include <ti/sprintf.h>
1011

1112
#include "f32_to_f64_LUT.h"
1213

@@ -30,10 +31,12 @@ size_t run_test(void) {
3031
result.flt = (long double)input[i];
3132
if (result.bin != output[i].bin) {
3233
if (!(isnan(result.flt) && isnan(output[i].flt))) {
33-
printf(
34-
"I: %08lX\nG: %016llX\nT: %016llX\n",
35-
*((const uint32_t*)input + i), result.bin, output[i].bin
36-
);
34+
#if 0
35+
printf(
36+
"I: %08lX\nG: %016llX\nT: %016llX\n",
37+
*((const uint32_t*)input + i), result.bin, output[i].bin
38+
);
39+
#endif
3740
return i;
3841
}
3942
}
@@ -47,9 +50,11 @@ int main(void) {
4750
os_ClrHome();
4851
size_t fail_index = run_test();
4952
if (fail_index == SIZE_MAX) {
50-
printf("All tests passed");
53+
fputs("All tests passed", stdout);
5154
} else {
52-
printf("Failed test: %zu", fail_index);
55+
char buf[sizeof("Failed test: 16777215\n")];
56+
boot_sprintf(buf, "Failed test: %u\n", fail_index);
57+
fputs(buf, stdout);
5358
}
5459

5560
while (!os_GetCSC());

test/floating_point/float32_trunc/src/main.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <ti/screen.h>
88
#include <ti/getcsc.h>
99
#include <sys/util.h>
10+
#include <ti/sprintf.h>
1011

1112
#include "f32_trunc_LUT.h"
1213

@@ -29,12 +30,14 @@ size_t run_test(void) {
2930
F32_pun result;
3031
result.flt = truncf(input[i].flt);
3132
if (result.bin != output[i].bin && !(isnan(result.flt) || isnan(output[i].flt))) {
32-
printf(
33-
"I: %08lX T: %zu\nG: %08lX\nT: %08lX\n",
34-
input[i].bin, i,
35-
result.bin,
36-
output[i].bin
37-
);
33+
#if 0
34+
printf(
35+
"I: %08lX T: %zu\nG: %08lX\nT: %08lX\n",
36+
input[i].bin, i,
37+
result.bin,
38+
output[i].bin
39+
);
40+
#endif
3841
return i;
3942
}
4043
}
@@ -47,9 +50,11 @@ int main(void) {
4750
os_ClrHome();
4851
size_t fail_index = run_test();
4952
if (fail_index == SIZE_MAX) {
50-
printf("All tests passed");
53+
fputs("All tests passed", stdout);
5154
} else {
52-
printf("Failed test: %zu", fail_index);
55+
char buf[sizeof("Failed test: 16777215\n")];
56+
boot_sprintf(buf, "Failed test: %u\n", fail_index);
57+
fputs(buf, stdout);
5358
}
5459

5560
while (!os_GetCSC());

test/floating_point/float64_arithmetic/src/main.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <ti/screen.h>
88
#include <ti/getcsc.h>
99
#include <sys/util.h>
10+
#include <ti/sprintf.h>
1011

1112
#include <bit>
1213
#include <cmath>
@@ -124,14 +125,22 @@ int main(void) {
124125
os_ClrHome();
125126
int comparison_result = comparison_test();
126127
if (comparison_result != 0) {
127-
printf("Failed test L%d\n", comparison_result);
128+
char buf[sizeof("Failed test L-8388608\n")];
129+
boot_sprintf(buf, "Failed test L%d\n", comparison_result);
130+
fputs(buf, stdout);
128131
} else {
129132
int64_t fail_ulp = 0;
130133
size_t fail_index = run_test(&fail_ulp);
131134
if (fail_index == SIZE_MAX) {
132-
printf("All tests passed");
135+
fputs("All tests passed", stdout);
133136
} else {
134-
printf("Failed test: %zu\nULP: %lld", fail_index, fail_ulp);
137+
char buf[sizeof("Failed test: 16777215\n")];
138+
boot_sprintf(buf, "Failed test: %u\n", fail_index);
139+
fputs(buf, stdout);
140+
#if 0
141+
/* debugging */
142+
printf("ULP: %lld\n", fail_ulp);
143+
#endif
135144
}
136145
}
137146
while (!os_GetCSC());

test/floating_point/float64_classification/src/main.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,15 @@ static test_result fpclassify_test(void) {
136136

137137
int main(void) {
138138
os_ClrHome();
139-
printf("Testing 2^" NUM_TO_STR(test_count) " inputs");
139+
fputs("Testing 2^" NUM_TO_STR(test_count) " inputs", stdout);
140140
test_result ret = fpclassify_test();
141141
os_ClrHome();
142142
if (ret.passed) {
143-
printf("All tests passed");
143+
fputs("All tests passed", stdout);
144144
} else {
145-
// just in-case printf does not support long long or uint64_t
146-
const uint32_t* failed_index_split = (const uint32_t*)((const void*)&(ret.failed_index));
147145
printf(
148-
"Failed test:\n0x%08lX%08lX\nTruth: %06o_%d\nGuess: %06o_%d",
149-
failed_index_split[1], failed_index_split[0], ret.truth, ret.truth_fp, ret.guess, ret.guess_fp
146+
"Failed test:\n0x%016llX\nTruth: %06o_%d\nGuess: %06o_%d",
147+
ret.failed_index, ret.truth, ret.truth_fp, ret.guess, ret.guess_fp
150148
);
151149
}
152150

test/floating_point/float64_frexp/src/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <ti/screen.h>
88
#include <ti/getcsc.h>
99
#include <sys/util.h>
10+
#include <ti/sprintf.h>
1011

1112
#include "f64_frexp_LUT.h"
1213

@@ -44,9 +45,11 @@ int main(void) {
4445
os_ClrHome();
4546
size_t fail_index = run_test();
4647
if (fail_index == SIZE_MAX) {
47-
printf("All tests passed");
48+
fputs("All tests passed", stdout);
4849
} else {
49-
printf("Failed test: %zu", fail_index);
50+
char buf[sizeof("Failed test: 16777215\n")];
51+
boot_sprintf(buf, "Failed test: %u\n", fail_index);
52+
fputs(buf, stdout);
5053
}
5154

5255
while (!os_GetCSC());

test/floating_point/float64_from_integer/src/main.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <ti/getcsc.h>
99
#include <sys/util.h>
1010
#include <stdlib.h>
11+
#include <ti/sprintf.h>
1112

1213
#include "f64_from_integer_LUT.h"
1314

@@ -18,13 +19,22 @@ typedef union F64_pun {
1819
uint64_t bin;
1920
} F64_pun;
2021

22+
#define AUTOTEST_DEBUG 0
23+
24+
#ifndef AUTOTEST_DEBUG
25+
#define AUTOTEST_DEBUG 0
26+
#endif
27+
28+
#if AUTOTEST_DEBUG
2129
void print_failed(uint64_t input, uint64_t guess, uint64_t truth) {
2230
printf(
2331
"I: %016llX -->\nG: %016llX !=\nT: %016llX\n",
2432
input, guess, truth
2533
);
2634
}
27-
35+
#else
36+
#define print_failed(...)
37+
#endif
2838

2939
long double CRT_utod(unsigned int);
3040
long double CRT_itod(signed int);
@@ -97,9 +107,12 @@ int main(void) {
97107
const char* failed_func;
98108
size_t fail_index = run_test(&failed_func);
99109
if (fail_index == SIZE_MAX) {
100-
printf("All tests passed");
110+
fputs("All tests passed", stdout);
101111
} else {
102-
printf("Failed test: %zu %s", fail_index, failed_func);
112+
char buf[sizeof("Failed test: 16777215\n")];
113+
boot_sprintf(buf, "Failed test: %u\n", fail_index);
114+
fputs(buf, stdout);
115+
fputs(failed_func, stdout);
103116
}
104117

105118
while (!os_GetCSC());

0 commit comments

Comments
 (0)