forked from rusefi/rusefi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_tunerstudio.cpp
86 lines (64 loc) · 2.01 KB
/
test_tunerstudio.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "pch.h"
#include "tunerstudio.h"
#include "tunerstudio_io.h"
static uint8_t st5TestBuffer[16000];
class BufferTsChannel : public TsChannelBase {
public:
BufferTsChannel() : TsChannelBase("Test") { }
void write(const uint8_t* buffer, size_t size, bool /*isLastWriteInTransaction*/) override {
memcpy(&st5TestBuffer[writeIdx], buffer, size);
writeIdx += size;
}
size_t readTimeout(uint8_t* buffer, size_t size, int timeout) override {
// nothing to do here
return size;
}
void reset() {
writeIdx = 0;
}
size_t writeIdx = 0;
};
#define CODE 2
#define PAYLOAD "123"
#define SIZE strlen(PAYLOAD)
static void assertCrcPacket(BufferTsChannel& dut) {
ASSERT_EQ(dut.writeIdx, SIZE + 7);
// todo: proper uint16 comparison
ASSERT_EQ(st5TestBuffer[0], 0);
ASSERT_EQ(st5TestBuffer[1], SIZE + 1);
ASSERT_EQ(st5TestBuffer[2], CODE);
ASSERT_EQ(memcmp(&st5TestBuffer[3], PAYLOAD, SIZE), 0);
// todo: proper uint32 comparison
ASSERT_EQ(st5TestBuffer[6], 252);
ASSERT_EQ(st5TestBuffer[7], 68);
ASSERT_EQ(st5TestBuffer[8], 173);
ASSERT_EQ(st5TestBuffer[9], 87);
}
TEST(binary, testWriteCrc) {
BufferTsChannel test;
// Let it pick which impl (small vs large) to use
test.reset();
test.writeCrcPacket(CODE, (const uint8_t*)PAYLOAD, SIZE);
assertCrcPacket(test);
// Force the large impl
test.reset();
test.writeCrcPacket(CODE, (const uint8_t*)PAYLOAD, SIZE);
assertCrcPacket(test);
// Force the small impl
test.reset();
test.writeCrcPacket(CODE, (const uint8_t*)PAYLOAD, SIZE);
assertCrcPacket(test);
}
TEST(TunerstudioCommands, writeChunkEngineConfig) {
EngineTestHelper eth(TEST_ENGINE);
::testing::NiceMock<MockTsChannel> channel;
uint8_t* configBytes = reinterpret_cast<uint8_t*>(config);
// Contains zero before the write
configBytes[100] = 0;
EXPECT_EQ(configBytes[100], 0);
// two step - writes to the engineConfiguration section require a burn
uint8_t val = 50;
TunerStudio instance;
instance.handleWriteChunkCommand(&channel, TS_CRC, 100, 1, &val);
EXPECT_EQ(configBytes[100], 50);
}