Skip to content

Commit 3010ccc

Browse files
repair tests
1 parent 5a03fbd commit 3010ccc

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

tests/mock_linux_wire.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ extern "C"
7070
std::strncpy(bus->device_path, device_path, LINUX_WIRE_DEVICE_PATH_MAX - 1);
7171
bus->device_path[LINUX_WIRE_DEVICE_PATH_MAX - 1] = '\0';
7272
bus->timeout_us = 0;
73+
bus->log_errors = g_state.logErrors;
7374
g_state.lastDevicePath = device_path;
7475
return 0;
7576
}
@@ -159,9 +160,19 @@ ssize_t lw_ioctl_write(lw_i2c_bus * /*bus*/,
159160
return static_cast<ssize_t>(len);
160161
}
161162

162-
int lw_set_timeout(lw_i2c_bus * /*bus*/, uint32_t timeout_us)
163+
int lw_set_timeout(lw_i2c_bus * /*bus*/, uint32_t timeout_us)
164+
{
165+
(void)timeout_us;
166+
return 0;
167+
}
168+
169+
void lw_set_error_logging(lw_i2c_bus *bus, int enable)
170+
{
171+
g_state.logErrors = enable ? 1 : 0;
172+
if (bus)
163173
{
164-
(void)timeout_us;
165-
return 0;
174+
bus->log_errors = g_state.logErrors;
166175
}
176+
}
177+
167178
} // extern "C"

tests/mock_linux_wire.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct MockLinuxWireState
1515
std::vector<uint8_t> lastWriteBuffer;
1616
bool lastWriteWasIoctl = false;
1717
uint8_t lastWriteSlaveAddr = 0;
18+
int logErrors = 1;
1819
int readCalls = 0;
1920
std::vector<uint8_t> lastReadBuffer;
2021
int ioctlReadCalls = 0;

tests/test_wire.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,23 @@ static void testZeroInternalAddressFallback()
207207
tw.end();
208208
}
209209

210+
static void testErrorLoggingToggle()
211+
{
212+
mockLinuxWireReset();
213+
214+
TwoWire tw;
215+
tw.begin("/dev/i2c-mock");
216+
assert(mockLinuxWireState().logErrors == 1);
217+
218+
tw.setErrorLogging(false);
219+
assert(mockLinuxWireState().logErrors == 0);
220+
221+
tw.setErrorLogging(true);
222+
assert(mockLinuxWireState().logErrors == 1);
223+
224+
tw.end();
225+
}
226+
210227
int main()
211228
{
212229
testPlainReadUsesRead();
@@ -217,6 +234,7 @@ int main()
217234
testTxBufferOverflow();
218235
testFlushOnDifferentAddress();
219236
testZeroInternalAddressFallback();
237+
testErrorLoggingToggle();
220238

221239
std::puts("linux_wire tests passed");
222240
return 0;

0 commit comments

Comments
 (0)