From 8c5fe1bf23d41c0e3cf1c282081ce2b342dd681c Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sat, 5 Dec 2020 00:22:10 -0500 Subject: [PATCH] unit tests in clang #2012 --- unit_tests/main.cpp | 2 +- .../ignition_injection/injection_mode_transition.cpp | 4 ++-- unit_tests/tests/test_cpp_memory_layout.cpp | 12 +++++------- unit_tests/tests/test_gpiochip.cpp | 6 +++--- unit_tests/tests/test_on_demand_parameters.cpp | 4 ++-- unit_tests/tests/test_parameters.h | 2 +- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp index abd8a7d0cc..b3da98bc4b 100644 --- a/unit_tests/main.cpp +++ b/unit_tests/main.cpp @@ -47,7 +47,7 @@ GTEST_API_ int main(int argc, char **argv) { printf("Success 20201203\r\n"); printAllTriggers(); if (focusOnTrigger != TT_UNUSED) { - return; + return -1; } testing::InitGoogleTest(&argc, argv); diff --git a/unit_tests/tests/ignition_injection/injection_mode_transition.cpp b/unit_tests/tests/ignition_injection/injection_mode_transition.cpp index f4aec72a1f..1c1123a74c 100644 --- a/unit_tests/tests/ignition_injection/injection_mode_transition.cpp +++ b/unit_tests/tests/ignition_injection/injection_mode_transition.cpp @@ -69,12 +69,12 @@ TEST(fuelControl, transitionIssue1592) { // Check that the action is correct - we don't care about the timing necessarily auto sched_open = engine->executor.getForUnitTest(0); ASSERT_EQ(sched_open->action.getArgument(), inj2); - ASSERT_EQ(sched_open->action.getCallback(), &turnInjectionPinHigh); + ASSERT_EQ(sched_open->action.getCallback(), (void(*)(void*))turnInjectionPinHigh); auto sched_close = engine->executor.getForUnitTest(1); // Next action should be closing the same injector ASSERT_EQ(sched_close->action.getArgument(), inj2); - ASSERT_EQ(sched_close->action.getCallback(), &turnInjectionPinLow); + ASSERT_EQ(sched_close->action.getCallback(), (void(*)(void*))turnInjectionPinLow); } // Run the engine for some revs diff --git a/unit_tests/tests/test_cpp_memory_layout.cpp b/unit_tests/tests/test_cpp_memory_layout.cpp index fa3bac2994..18efdcbb9d 100644 --- a/unit_tests/tests/test_cpp_memory_layout.cpp +++ b/unit_tests/tests/test_cpp_memory_layout.cpp @@ -50,7 +50,7 @@ TEST(misc, cppPlainStructMemoryLayout) { memcpy(&destimationInt, &c, 4); ASSERT_EQ(540, destimationInt); - ASSERT_EQ(0, (int)&c.field0 - (int)&c); + ASSERT_EQ((uintptr_t)&c.field0, (uintptr_t)&c); } static int valueWePointAt; @@ -58,13 +58,11 @@ static int valueWePointAt; TEST(misc, cppVirtualStructMemoryLayout) { TestChildWithVirtual c; - int * valuePointer = &valueWePointAt; - int pointerSize = sizeof(valuePointer); + int pointerSize = sizeof(int*); // '4' in case of 32 bit target // '8' in case of 64 bit target - // this '8' is totally compiler and platform dependent int MAGIC_VTABLE_SIZE = pointerSize; // validate field initializers just for fun @@ -80,9 +78,9 @@ TEST(misc, cppVirtualStructMemoryLayout) { // static_cast is smart to skip the vtable, we like static_cast TestParent *parent = static_cast(&c); - ASSERT_EQ(0, (int)&c.field0 - (int)parent); + ASSERT_EQ((uintptr_t)&c.field0, (uintptr_t)parent); - ASSERT_EQ(MAGIC_VTABLE_SIZE, (int)&c.field0 - (int)&c); + ASSERT_EQ(MAGIC_VTABLE_SIZE, (uintptr_t)&c.field0 - (uintptr_t)&c); } @@ -96,5 +94,5 @@ TEST(misc, cppPlainExtraFieldsStructMemoryLayout) { // parent fields go first memcpy(&destimationInt, &c, 4); ASSERT_EQ(540, destimationInt); - ASSERT_EQ(0, (int)&c.field0 - (int)&c); + ASSERT_EQ(0, (uintptr_t)&c.field0 - (uintptr_t)&c); } diff --git a/unit_tests/tests/test_gpiochip.cpp b/unit_tests/tests/test_gpiochip.cpp index eaa00411fc..cff4df61d6 100644 --- a/unit_tests/tests/test_gpiochip.cpp +++ b/unit_tests/tests/test_gpiochip.cpp @@ -10,7 +10,7 @@ using ::testing::_; -static int testchip_readPad(void *data, brain_pin_e pin) +static int testchip_readPad(void *data, unsigned int pin) { if (pin & 0x01) return 1; @@ -19,7 +19,7 @@ static int testchip_readPad(void *data, brain_pin_e pin) static int io_state = 0; -static int testchip_writePad(void *data, brain_pin_e pin, int value) +static int testchip_writePad(void *data, unsigned int pin, int value) { if (value) io_state |= (1 << value); @@ -39,7 +39,7 @@ static int testchip_init(void *data) } static int calls_to_failed_chip = 0; -static int testchip_failed_writePad(void *data, brain_pin_e pin, int value) +static int testchip_failed_writePad(void *data, unsigned int pin, int value) { calls_to_failed_chip++; return 0; diff --git a/unit_tests/tests/test_on_demand_parameters.cpp b/unit_tests/tests/test_on_demand_parameters.cpp index 42b264b8c6..77b57d39b8 100644 --- a/unit_tests/tests/test_on_demand_parameters.cpp +++ b/unit_tests/tests/test_on_demand_parameters.cpp @@ -13,9 +13,9 @@ TestParameters* TestParameters::put(string key, float value) { return this; } -float TestParameters::get(string key) const { +float TestParameters::get(string key) { // WAT? 'contains' method only defined in C++20?! - std::unordered_map::const_iterator got = values.find (key); + std::unordered_map::const_iterator got = values.find(key); if (got == values.end()) throw "No value for this key: " + key; return values[key]; diff --git a/unit_tests/tests/test_parameters.h b/unit_tests/tests/test_parameters.h index dd4013a41c..71b854c08b 100644 --- a/unit_tests/tests/test_parameters.h +++ b/unit_tests/tests/test_parameters.h @@ -14,6 +14,6 @@ class TestParameters { public: unordered_map values; TestParameters* put(string key, float value); - float get(string key) const; + float get(string key); };