| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #include "pch.h" | |||
| 2 | #include "rusefi_lua.h" | |||
| 3 | #include "lua_lib.h" | |||
| 4 | ||||
| 5 | /** | |||
| 6 | * MSB bit conversion insanity | |||
| 7 | * data[1] means start offset 7 | |||
| 8 | * data[2] means start offset 15 | |||
| 9 | * data[3] means start offset 23 | |||
| 10 | * data[4] means start offset 31 | |||
| 11 | * data[5] means start offset 39 | |||
| 12 | * data[6] means start offset 47 | |||
| 13 | * data[7] means start offset 55 | |||
| 14 | * data[8] means start offset 63 | |||
| 15 | */ | |||
| 16 | ||||
| 17 | #define ECMEngineStatus "\ndata = { 0x80, 0x20, 0x29, 0x16, 0x0F, 0x40, 0x08, 0x00}\n " | |||
| 18 | ||||
| 19 | 4 | TEST(LuaE38, rpm) { | ||
| 20 | ||||
| 21 | 1 | const char* script = TWO_BYTES_MSB ECMEngineStatus R"( | ||
| 22 | function testFunc() | |||
| 23 | rpm = getTwoBytesMSB(data, 2, 0.25) | |||
| 24 | return rpm | |||
| 25 | end | |||
| 26 | )"; | |||
| 27 |
3/7✓ Branch 3 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 time.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(script).value_or(0), 2629.5); | |
| 28 | 1 | } | ||
| 29 | ||||
| 30 | 4 | TEST(LuaE38, tps) { | ||
| 31 | ||||
| 32 | 1 | const char* script = TWO_BYTES_MSB ECMEngineStatus R"( | ||
| 33 | function testFunc() | |||
| 34 | tps = data[5] * 0.3921 | |||
| 35 | return tps | |||
| 36 | end | |||
| 37 | )"; | |||
| 38 |
3/7✓ Branch 3 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 time.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(script).value_or(0), 5.881); | |
| 39 | 1 | } | ||
| 40 | ||||
| 41 | 4 | TEST(LuaE38, packECMEngineStatus) { | ||
| 42 |
3/7✓ Branch 3 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 time.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_NEAR_M3(testLuaReturnsNumberOrNil( | |
| 43 | TWO_BYTES_MSB ARRAY_EQUALS PRINT_ARRAY R"( | |||
| 44 | tps = 5.881 | |||
| 45 | function testFunc() | |||
| 46 | canEngine = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } | |||
| 47 | canEngine[5] = tps / 0.3921 | |||
| 48 | ||||
| 49 | print(arrayToString(canEngine)) | |||
| 50 | expected = { 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00 } | |||
| 51 | return equals(canEngine, expected) | |||
| 52 | end | |||
| 53 | )" | |||
| 54 | 1 | ).value_or(0), 0); | ||
| 55 | 1 | } | ||
| 56 | ||||
| 57 | #define ECMEngineCoolantTemp "\ndata = { 0x00, 0xCA, 0x69, 0x3F, 0x6A, 0x00, 0x00, 0x00}\n " | |||
| 58 | ||||
| 59 | 4 | TEST(LuaE38, clt) { | ||
| 60 | ||||
| 61 |
3/7✓ Branch 3 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 time.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(TWO_BYTES_MSB ECMEngineCoolantTemp R"( | |
| 62 | function testFunc() | |||
| 63 | clt = data[3] -40 | |||
| 64 | return clt | |||
| 65 | end | |||
| 66 | )" | |||
| 67 | 1 | ).value_or(0), 65); | ||
| 68 | 1 | } | ||
| 69 | ||||
| 70 | 4 | TEST(LuaE38, packECMEngineCoolantTemp) { | ||
| 71 |
3/7✓ Branch 3 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 time.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_NEAR_M3(testLuaReturnsNumberOrNil( | |
| 72 | TWO_BYTES_MSB ARRAY_EQUALS PRINT_ARRAY R"( | |||
| 73 | clt = 65 | |||
| 74 | function testFunc() | |||
| 75 | canEngine = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } | |||
| 76 | canEngine[3] = clt + 40 | |||
| 77 | ||||
| 78 | print(arrayToString(canEngine)) | |||
| 79 | expected = { 0x00, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00 } | |||
| 80 | return equals(canEngine, expected) | |||
| 81 | end | |||
| 82 | )" | |||
| 83 | 1 | ).value_or(0), 0); | ||
| 84 | 1 | } | ||
| 85 |