FastLED 3.9.15
Loading...
Searching...
No Matches
test_helpers.cpp
Go to the documentation of this file.
1// examples/SIMD/test_helpers.cpp
2//
3// Helper function implementations for SIMD testing
4
5#include "test_helpers.h"
6#include "fl/log/log.h"
7
8namespace simd_test {
9
10// ============================================================================
11// Array Comparison Functions
12// ============================================================================
13
14bool compare_u8_arrays(const uint8_t* a, const uint8_t* b, size_t count) {
15 for (size_t i = 0; i < count; i++) {
16 if (a[i] != b[i]) {
17 return false;
18 }
19 }
20 return true;
21}
22
23bool compare_f32_arrays(const float* a, const float* b, size_t count, float epsilon) {
24 for (size_t i = 0; i < count; i++) {
25 float diff = a[i] - b[i];
26 if (diff < 0.0f) diff = -diff;
27 if (diff > epsilon) {
28 return false;
29 }
30 }
31 return true;
32}
33
34// ============================================================================
35// Test Execution Functions
36// ============================================================================
37
38void print_test_result(const TestResult& result) {
39 fl::sstream ss;
40 if (result.passed) {
41 ss << " ✓ PASS: " << result.test_name;
42 FL_PRINT(ss.str());
43 } else {
44 ss << " ✗ FAIL: " << result.test_name;
45 FL_PRINT(ss.str());
46 if (result.error_msg) {
47 fl::sstream err;
48 err << " ERROR: " << result.error_msg;
49 FL_ERROR(err.str().c_str());
50 }
51 }
52}
53
54// ============================================================================
55// Summary and Reporting Functions
56// ============================================================================
57
60 fl::sstream ss;
61
62 ss << "\n╔════════════════════════════════════════════════════════════════╗\n";
63 ss << "║ SIMD TEST SUMMARY ║\n";
64 ss << "╚════════════════════════════════════════════════════════════════╝\n";
65 FL_PRINT(ss.str());
66
67 ss.clear();
68 ss << "Total Tests: " << total_tests << "\n";
69 ss << "Passed: " << passed_tests << " ("
70 << (total_tests > 0 ? (passed_tests * 100 / total_tests) : 0) << "%)\n";
71 ss << "Failed: " << failed_tests << " ("
72 << (total_tests > 0 ? (failed_tests * 100 / total_tests) : 0) << "%)";
73 FL_PRINT(ss.str());
74
75 if (failed_tests > 0) {
76 FL_PRINT("\nFailed Tests:");
77 for (size_t i = 0; i < test_results.size(); i++) {
78 if (!test_results[i].passed) {
79 fl::sstream fail_ss;
80 fail_ss << " - " << test_results[i].test_name;
81 if (test_results[i].error_msg) {
82 fail_ss << ": " << test_results[i].error_msg;
83 }
84 FL_PRINT(fail_ss.str());
85 }
86 }
87 }
88}
89
91 fl::sstream ss;
92 ss << "\n";
93 if (failed_tests == 0) {
94 ss << "╔════════════════════════════════════════════════════════════════╗\n";
95 ss << "║ ✓ ALL TESTS PASSED ║\n";
96 ss << "╚════════════════════════════════════════════════════════════════╝";
97 } else {
98 ss << "╔════════════════════════════════════════════════════════════════╗\n";
99 ss << "║ ✗ TESTS FAILED ║\n";
100 ss << "╚════════════════════════════════════════════════════════════════╝";
101 }
102 FL_PRINT(ss.str());
103}
104
105} // namespace simd_test
int passed_tests
Definition SIMD.ino:75
int failed_tests
Definition SIMD.ino:76
int total_tests
Definition SIMD.ino:74
fl::vector< TestResult > test_results
Definition SIMD.ino:71
const char * c_str() const FL_NOEXCEPT
string str() const FL_NOEXCEPT
Definition strstream.h:43
void clear() FL_NOEXCEPT
Definition strstream.h:358
#define FL_ERROR(X)
Definition log.h:219
#define FL_PRINT(X)
Print without prefix (like FL_WARN but without "WARN: " prefix) Uses sstream for dynamic formatting (...
Definition log.h:457
Centralized logging categories for FastLED hardware interfaces and subsystems.
void print_test_result(const TestResult &result)
Print test result to serial.
void print_final_banner(int failed_tests)
Print final result banner (PASS/FAIL)
bool compare_u8_arrays(const uint8_t *a, const uint8_t *b, size_t count)
Compare two uint8_t arrays element-wise.
void print_summary(const fl::vector< TestResult > &test_results, int total_tests, int passed_tests, int failed_tests)
Print summary table of all test results.
bool compare_f32_arrays(const float *a, const float *b, size_t count, float epsilon)
Compare two float arrays element-wise with epsilon tolerance.
Stores the result of a single SIMD test.
Definition test_result.h:10