Skip to content

Commit

Permalink
Add a unit test for messages with many signals.
Browse files Browse the repository at this point in the history
This is a first attempt at finding the root cause of #306. It's passing
without any changes, so I think the problem must be in the hardware
specific parts of the code. I will work next on creating a functional
test.
  • Loading branch information
peplin committed Oct 9, 2014
1 parent 5f6bcf0 commit b266490
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
27 changes: 27 additions & 0 deletions src/tests/canread_tests.cpp
Expand Up @@ -26,6 +26,9 @@ using openxc::signals::getMessages;
using openxc::signals::getMessageCount;
using openxc::config::getConfiguration;

extern bool USB_PROCESSED;
extern size_t SENT_BYTES;

const CanMessage TEST_MESSAGE = {
id: 0,
format: STANDARD,
Expand All @@ -45,6 +48,8 @@ bool queueEmpty() {

void setup() {
FAKE_TIME = 1000;
USB_PROCESSED = false;
SENT_BYTES = 0;
initializeVehicleInterface();
getConfiguration()->payloadFormat = openxc::payload::PayloadFormat::JSON;
usb::initialize(&getConfiguration()->usb);
Expand Down Expand Up @@ -355,6 +360,26 @@ START_TEST (test_translate_respects_send_value)
}
END_TEST

START_TEST (test_translate_many_signals)
{
getConfiguration()->pipeline.uart = NULL;
ck_assert_int_eq(0, SENT_BYTES);
for(int i = 7; i < 23; i++) {
can::read::translateSignal(&getSignals()[i],
&TEST_MESSAGE, getSignals(), getSignalCount(), &getConfiguration()->pipeline);
fail_unless(getSignals()[i].received);
}
fail_unless(USB_PROCESSED);
// 8 signals sent
fail_if(queueEmpty());
uint8_t snapshot[QUEUE_LENGTH(uint8_t, OUTPUT_QUEUE) + 1];
QUEUE_SNAPSHOT(uint8_t, OUTPUT_QUEUE, snapshot, sizeof(snapshot));
snapshot[sizeof(snapshot) - 1] = NULL;
// 8 in the output queue
ck_assert_int_eq(8 * 29 + 2, SENT_BYTES);
}
END_TEST

START_TEST (test_translate_float)
{
getSignals()[0].decoder = floatDecoder;
Expand Down Expand Up @@ -570,6 +595,8 @@ Suite* canreadSuite(void) {
test_decoder_called_every_time_with_nonzero_frequency);
tcase_add_test(tc_translate,
test_decoder_called_every_time_with_unlimited_frequency);
tcase_add_test(tc_translate,
test_translate_many_signals);
suite_add_tcase(s, tc_translate);

return s;
Expand Down
43 changes: 40 additions & 3 deletions src/tests/platform/signals.cpp
Expand Up @@ -40,13 +40,15 @@ CanBus CAN_BUSES[][MAX_CAN_BUS_COUNT] = {
},
};

const int MAX_MESSAGE_COUNT = 4;
const int MAX_MESSAGE_COUNT = 6;
CanMessageDefinition CAN_MESSAGES[][MAX_MESSAGE_COUNT] = {
{ // message set: passthrough
{&CAN_BUSES[0][0], 0},
{&CAN_BUSES[0][0], 1, CanMessageFormat::STANDARD, {10}},
{&CAN_BUSES[0][0], 2, CanMessageFormat::STANDARD, {1}, true},
{&CAN_BUSES[0][0], 3}
{&CAN_BUSES[0][0], 3},
{&CAN_BUSES[0][0], 4},
{&CAN_BUSES[0][0], 5}
},
{ // message set: shared_handler_tests
{&CAN_BUSES[1][0], 0},
Expand All @@ -56,7 +58,7 @@ CanMessageDefinition CAN_MESSAGES[][MAX_MESSAGE_COUNT] = {
},
};

const int MAX_SIGNAL_COUNT = 13;
const int MAX_SIGNAL_COUNT = 29;
const CanSignalState SIGNAL_STATES[][2][6] = {
{ // message set: passthrough
{ {1, "reverse"}, {2, "third"}, {3, "sixth"}, {4, "seventh"},
Expand Down Expand Up @@ -86,6 +88,41 @@ CanSignal SIGNALS[][MAX_SIGNAL_COUNT] = {
false, false, NULL, 0, true},
{&CAN_MESSAGES[0][0], "torque_at_transmission", 2, 6, 1001.0, -30000.000000,
-5000.000000, 33522.000000, {0}, false, false, NULL, 0, true},

// The messages for test_translate_many_signals, with 8 signals per
// message to replicate a bug reported in the discussion group
{&CAN_MESSAGES[0][4], "signal1", 0, 1, 1.000000, 0.000000, 0.000000,
0.000000, {0}, true, false, NULL, 0, true},
{&CAN_MESSAGES[0][4], "signal2", 1, 1, 1.000000, 0.000000, 0.000000,
0.000000, {0}, true, false, NULL, 0, true},
{&CAN_MESSAGES[0][4], "signal3", 2, 1, 1.000000, 0.000000, 0.000000,
0.000000, {0}, true, false, NULL, 0, true},
{&CAN_MESSAGES[0][4], "signal4", 3, 1, 1.000000, 0.000000, 0.000000,
0.000000, {0}, true, false, NULL, 0, true},
{&CAN_MESSAGES[0][4], "signal5", 4, 1, 1.000000, 0.000000, 0.000000,
0.000000, {0}, true, false, NULL, 0, true},
{&CAN_MESSAGES[0][4], "signal6", 5, 1, 1.000000, 0.000000, 0.000000,
0.000000, {0}, true, false, NULL, 0, true},
{&CAN_MESSAGES[0][4], "signal7", 6, 1, 1.000000, 0.000000, 0.000000,
0.000000, {0}, true, false, NULL, 0, true},
{&CAN_MESSAGES[0][4], "signal8", 7, 1, 1.000000, 0.000000, 0.000000,
0.000000, {0}, true, false, NULL, 0, true},
{&CAN_MESSAGES[0][5], "signal9", 0, 1, 1.000000, 0.000000, 0.000000,
0.000000, {0}, true, false, NULL, 0, true},
{&CAN_MESSAGES[0][5], "signa10", 1, 1, 1.000000, 0.000000, 0.000000,
0.000000, {0}, true, false, NULL, 0, true},
{&CAN_MESSAGES[0][5], "signa11", 2, 1, 1.000000, 0.000000, 0.000000,
0.000000, {0}, true, false, NULL, 0, true},
{&CAN_MESSAGES[0][5], "signa12", 3, 1, 1.000000, 0.000000, 0.000000,
0.000000, {0}, true, false, NULL, 0, true},
{&CAN_MESSAGES[0][5], "signa13", 4, 1, 1.000000, 0.000000, 0.000000,
0.000000, {0}, true, false, NULL, 0, true},
{&CAN_MESSAGES[0][5], "signa14", 5, 1, 1.000000, 0.000000, 0.000000,
0.000000, {0}, true, false, NULL, 0, true},
{&CAN_MESSAGES[0][5], "signa15", 6, 1, 1.000000, 0.000000, 0.000000,
0.000000, {0}, true, false, NULL, 0, true},
{&CAN_MESSAGES[0][5], "signa16", 7, 1, 1.000000, 0.000000, 0.000000,
0.000000, {0}, true, false, NULL, 0, true}
},
{ // message set: shared_handler_tests
{&CAN_MESSAGES[1][0], "button_type", 8, 8, 1.000000, 0.000000, 0.000000,
Expand Down
4 changes: 4 additions & 0 deletions src/tests/platform/usb.cpp
Expand Up @@ -9,6 +9,7 @@ using openxc::util::bytebuffer::IncomingMessageCallback;
bool USB_PROCESSED = false;
uint8_t LAST_CONTROL_COMMAND_PAYLOAD[256];
size_t LAST_CONTROL_COMMAND_PAYLOAD_LENGTH = 0;;
size_t SENT_BYTES = 0;

void openxc::interface::usb::processSendQueue(UsbDevice* usbDevice) {
USB_PROCESSED = true;
Expand All @@ -18,6 +19,8 @@ void openxc::interface::usb::processSendQueue(UsbDevice* usbDevice) {
printf("USB endpoint %d buffer:\n", i);
uint8_t snapshot[QUEUE_LENGTH(uint8_t, &endpoint->queue) + 1];
QUEUE_SNAPSHOT(uint8_t, &endpoint->queue, snapshot, sizeof(snapshot));
SENT_BYTES += sizeof(snapshot);
QUEUE_INIT(uint8_t, &endpoint->queue);
for(size_t i = 0; i < sizeof(snapshot) - 1; i++) {
if(snapshot[i] == 0) {
printf("\n");
Expand All @@ -31,6 +34,7 @@ void openxc::interface::usb::processSendQueue(UsbDevice* usbDevice) {

void openxc::interface::usb::initialize(UsbDevice* usbDevice) {
usb::initializeCommon(usbDevice);
SENT_BYTES = 0;
}

void openxc::interface::usb::read(UsbDevice* device, UsbEndpoint* endpoint,
Expand Down
1 change: 1 addition & 0 deletions src/tests/shared_handler_tests.cpp
Expand Up @@ -29,6 +29,7 @@ bool queueEmpty() {
}

void setup() {
getConfiguration()->pipeline.uart = NULL;
openxc::config::getConfiguration()->messageSetIndex = 1;
usb::initialize(&getConfiguration()->usb);
getConfiguration()->usb.configured = true;
Expand Down

0 comments on commit b266490

Please sign in to comment.