Bump clang version to 18 (#14116)
[betaflight.git] / src / test / unit / motor_output_unittest.cc
blobbf45d12457d3bd4d75140e90f1a28f4421010856
1 /*
2 * This file is part of Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include <stdint.h>
22 #include <iostream>
24 extern "C" {
25 #include "drivers/dshot.h"
26 #include "build/atomic.h"
29 #include "unittest_macros.h"
30 #include "gtest/gtest.h"
32 extern "C" {
34 bool featureIsEnabled(uint8_t f);
35 float scaleRangef(float a, float b, float c, float d, float e);
37 // Mocking functions
39 bool featureIsEnabled(uint8_t f)
41 UNUSED(f);
42 return true;
45 float scaleRangef(float a, float b, float c, float d, float e)
47 UNUSED(a);
48 UNUSED(b);
49 UNUSED(c);
50 UNUSED(d);
51 UNUSED(e);
52 return 0;
57 // Tests
59 TEST(MotorOutputUnittest, TestFixMotorOutputReordering)
61 const unsigned size = 8;
63 uint8_t a1_initial[size] = {0, 1, 2, 3, 4, 5, 6, 7};
64 uint8_t a1_expected[size] = {0, 1, 2, 3, 4, 5, 6, 7};
65 validateAndfixMotorOutputReordering(a1_initial, size);
66 EXPECT_TRUE( 0 == memcmp(a1_expected, a1_initial, sizeof(a1_expected)));
68 uint8_t a2_initial[size] = {3, 2, 1, 4, 5, 6, 7, 0};
69 uint8_t a2_expected[size] = {3, 2, 1, 4, 5, 6, 7, 0};
70 validateAndfixMotorOutputReordering(a2_initial, size);
71 EXPECT_TRUE( 0 == memcmp(a2_expected, a2_initial, sizeof(a2_expected)));
73 uint8_t a3_initial[size] = {3, 2, 1, 100, 5, 6, 7, 0};
74 uint8_t a3_expected[size] = {0, 1, 2, 3, 4, 5, 6, 7};
75 validateAndfixMotorOutputReordering(a3_initial, size);
76 EXPECT_TRUE( 0 == memcmp(a3_expected, a3_initial, sizeof(a3_expected)));
78 uint8_t a4_initial[size] = {3, 2, 1, 100, 5, 6, 200, 0};
79 uint8_t a4_expected[size] = {0, 1, 2, 3, 4, 5, 6, 7};
80 validateAndfixMotorOutputReordering(a4_initial, size);
81 EXPECT_TRUE( 0 == memcmp(a4_expected, a4_initial, sizeof(a4_expected)));
83 uint8_t a5_initial[size] = {0, 0, 0, 0, 0, 0, 0, 0};
84 uint8_t a5_expected[size] = {0, 1, 2, 3, 4, 5, 6, 7};
85 validateAndfixMotorOutputReordering(a5_initial, size);
86 EXPECT_TRUE( 0 == memcmp(a5_expected, a5_initial, sizeof(a5_expected)));
88 uint8_t a6_initial[size] = {0, 0, 0, 1, 0, 99, 0, 0};
89 uint8_t a6_expected[size] = {0, 1, 2, 3, 4, 5, 6, 7};
90 validateAndfixMotorOutputReordering(a6_initial, size);
91 EXPECT_TRUE( 0 == memcmp(a6_expected, a6_initial, sizeof(a5_expected)));
93 uint8_t a7_initial[size] = {1, 5, 3, 4, 5, 6, 7, 0};
94 uint8_t a7_expected[size] = {0, 1, 2, 3, 4, 5, 6, 7};
95 validateAndfixMotorOutputReordering(a7_initial, size);
96 EXPECT_TRUE( 0 == memcmp(a7_expected, a7_initial, sizeof(a7_expected)));
98 uint8_t a8_initial[size] = {1, 5, 1, 5, 3, 3, 3, 3};
99 uint8_t a8_expected[size] = {0, 1, 2, 3, 4, 5, 6, 7};
100 validateAndfixMotorOutputReordering(a8_initial, size);
101 EXPECT_TRUE( 0 == memcmp(a8_expected, a8_initial, sizeof(a8_expected)));
103 uint8_t a9_initial[size] = {7, 6, 5, 4, 3, 2, 1, 0};
104 uint8_t a9_expected[size] = {7, 6, 5, 4, 3, 2, 1, 0};
105 validateAndfixMotorOutputReordering(a9_initial, size);
106 EXPECT_TRUE( 0 == memcmp(a9_expected, a9_initial, sizeof(a9_expected)));