Skip to content

Commit

Permalink
Regenerate C/Rust tests (#964)
Browse files Browse the repository at this point in the history
  • Loading branch information
woodfell committed Apr 27, 2021
1 parent 4ec3a55 commit 4a1fd9b
Show file tree
Hide file tree
Showing 165 changed files with 31,880 additions and 19,601 deletions.
268 changes: 164 additions & 104 deletions c/test/auto_check_sbp_acquisition_1.c

Large diffs are not rendered by default.

172 changes: 86 additions & 86 deletions c/test/auto_check_sbp_acquisition_2.c

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
*/

// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/test_bootload.yaml by generate.py. Do not modify by hand!
// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderHandshakeResp.yaml by generate.py. Do not modify by hand!

#include <check.h>
#include <stdio.h> // for debugging
Expand Down Expand Up @@ -96,7 +96,7 @@ static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], u1
last_frame.context = context;
}

START_TEST( test_auto_check_sbp_bootload_40 )
START_TEST( test_auto_check_sbp_bootload_4 )
{
static sbp_msg_callbacks_node_t n;
static sbp_msg_callbacks_node_t n2;
Expand Down Expand Up @@ -296,11 +296,11 @@ START_TEST( test_auto_check_sbp_bootload_40 )
}
END_TEST

Suite* auto_check_sbp_bootload_40_suite(void)
Suite* auto_check_sbp_bootload_4_suite(void)
{
Suite *s = suite_create("SBP generated test suite: auto_check_sbp_bootload_40");
TCase *tc_acq = tcase_create("Automated_Suite_auto_check_sbp_bootload_40");
tcase_add_test(tc_acq, test_auto_check_sbp_bootload_40);
Suite *s = suite_create("SBP generated test suite: auto_check_sbp_bootload_4");
TCase *tc_acq = tcase_create("Automated_Suite_auto_check_sbp_bootload_4");
tcase_add_test(tc_acq, test_auto_check_sbp_bootload_4);
suite_add_tcase(s, tc_acq);
return s;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
*/

// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/test_ext_events.yaml by generate.py. Do not modify by hand!
// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/ext_events/test_MsgExtEvent.yaml by generate.py. Do not modify by hand!

#include <check.h>
#include <stdio.h> // for debugging
Expand Down Expand Up @@ -96,7 +96,7 @@ static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], u1
last_frame.context = context;
}

START_TEST( test_auto_check_sbp_ext_events_41 )
START_TEST( test_auto_check_sbp_ext_events_5 )
{
static sbp_msg_callbacks_node_t n;
static sbp_msg_callbacks_node_t n2;
Expand Down Expand Up @@ -193,11 +193,11 @@ START_TEST( test_auto_check_sbp_ext_events_41 )
}
END_TEST

Suite* auto_check_sbp_ext_events_41_suite(void)
Suite* auto_check_sbp_ext_events_5_suite(void)
{
Suite *s = suite_create("SBP generated test suite: auto_check_sbp_ext_events_41");
TCase *tc_acq = tcase_create("Automated_Suite_auto_check_sbp_ext_events_41");
tcase_add_test(tc_acq, test_auto_check_sbp_ext_events_41);
Suite *s = suite_create("SBP generated test suite: auto_check_sbp_ext_events_5");
TCase *tc_acq = tcase_create("Automated_Suite_auto_check_sbp_ext_events_5");
tcase_add_test(tc_acq, test_auto_check_sbp_ext_events_5);
suite_add_tcase(s, tc_acq);
return s;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
*/

// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/navigation/test_MsgAgeCorrections.yaml by generate.py. Do not modify by hand!
// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/imu/test_MsgImuAux.yaml by generate.py. Do not modify by hand!

#include <check.h>
#include <stdio.h> // for debugging
#include <stdlib.h> // for malloc
#include <sbp.h>
#include <navigation.h>
#include <imu.h>

static struct {
u32 n_callbacks_logged;
Expand Down Expand Up @@ -96,7 +96,7 @@ static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], u1
last_frame.context = context;
}

START_TEST( test_auto_check_sbp_navigation_3 )
START_TEST( test_auto_check_sbp_imu_6 )
{
static sbp_msg_callbacks_node_t n;
static sbp_msg_callbacks_node_t n2;
Expand All @@ -119,21 +119,22 @@ START_TEST( test_auto_check_sbp_navigation_3 )

logging_reset();

sbp_register_callback(&sbp_state, 0x210, &msg_callback, &DUMMY_MEMORY_FOR_CALLBACKS, &n);
sbp_register_frame_callback(&sbp_state, 0x210, &frame_callback, &DUMMY_MEMORY_FOR_CALLBACKS, &n2);
sbp_register_callback(&sbp_state, 0x901, &msg_callback, &DUMMY_MEMORY_FOR_CALLBACKS, &n);
sbp_register_frame_callback(&sbp_state, 0x901, &frame_callback, &DUMMY_MEMORY_FOR_CALLBACKS, &n2);

u8 encoded_frame[] = {85,16,2,66,0,6,100,0,0,0,30,0,233,202, };
u8 encoded_frame[] = {85,1,9,52,18,4,1,244,10,66,200,252, };

dummy_reset();

u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN];
memset(test_msg_storage, 0, sizeof(test_msg_storage));
u8 test_msg_len = 0;
msg_age_corrections_t* test_msg = ( msg_age_corrections_t* )test_msg_storage;
msg_imu_aux_t* test_msg = ( msg_imu_aux_t* )test_msg_storage;
test_msg_len = sizeof(*test_msg);
test_msg->age = 30;
test_msg->tow = 100;
sbp_send_message(&sbp_state, 0x210, 66, test_msg_len, test_msg_storage, &dummy_write);
test_msg->imu_conf = 66;
test_msg->imu_type = 1;
test_msg->temp = 2804;
sbp_send_message(&sbp_state, 0x901, 4660, test_msg_len, test_msg_storage, &dummy_write);

ck_assert_msg(test_msg_len == sizeof(encoded_frame) - 8,
"Test message has not been generated correctly, or the encoded frame from the spec is badly defined. Check your test spec");
Expand All @@ -150,7 +151,7 @@ START_TEST( test_auto_check_sbp_navigation_3 )

ck_assert_msg(last_msg.n_callbacks_logged == 1,
"msg_callback: one callback should have been logged");
ck_assert_msg(last_msg.sender_id == 66,
ck_assert_msg(last_msg.sender_id == 4660,
"msg_callback: sender_id decoded incorrectly");
ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8,
"msg_callback: len decoded incorrectly");
Expand All @@ -162,9 +163,9 @@ START_TEST( test_auto_check_sbp_navigation_3 )

ck_assert_msg(last_frame.n_callbacks_logged == 1,
"frame_callback: one callback should have been logged");
ck_assert_msg(last_frame.sender_id == 66,
ck_assert_msg(last_frame.sender_id == 4660,
"frame_callback: sender_id decoded incorrectly");
ck_assert_msg(last_frame.msg_type == 0x210,
ck_assert_msg(last_frame.msg_type == 0x901,
"frame_callback: msg_type decoded incorrectly");
ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8,
"frame_callback: msg_len decoded incorrectly");
Expand All @@ -178,20 +179,21 @@ START_TEST( test_auto_check_sbp_navigation_3 )
"frame_callback: context pointer incorrectly passed");

// Cast to expected message type - the +6 byte offset is where the payload starts
msg_age_corrections_t* check_msg = ( msg_age_corrections_t *)((void *)last_msg.msg);
msg_imu_aux_t* check_msg = ( msg_imu_aux_t *)((void *)last_msg.msg);
// Run tests against fields
ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used");
ck_assert_msg(check_msg->age == 30, "incorrect value for age, expected 30, is %d", check_msg->age);
ck_assert_msg(check_msg->tow == 100, "incorrect value for tow, expected 100, is %d", check_msg->tow);
ck_assert_msg(check_msg->imu_conf == 66, "incorrect value for imu_conf, expected 66, is %d", check_msg->imu_conf);
ck_assert_msg(check_msg->imu_type == 1, "incorrect value for imu_type, expected 1, is %d", check_msg->imu_type);
ck_assert_msg(check_msg->temp == 2804, "incorrect value for temp, expected 2804, is %d", check_msg->temp);
}
}
END_TEST

Suite* auto_check_sbp_navigation_3_suite(void)
Suite* auto_check_sbp_imu_6_suite(void)
{
Suite *s = suite_create("SBP generated test suite: auto_check_sbp_navigation_3");
TCase *tc_acq = tcase_create("Automated_Suite_auto_check_sbp_navigation_3");
tcase_add_test(tc_acq, test_auto_check_sbp_navigation_3);
Suite *s = suite_create("SBP generated test suite: auto_check_sbp_imu_6");
TCase *tc_acq = tcase_create("Automated_Suite_auto_check_sbp_imu_6");
tcase_add_test(tc_acq, test_auto_check_sbp_imu_6);
suite_add_tcase(s, tc_acq);
return s;
}
209 changes: 209 additions & 0 deletions c/test/auto_check_sbp_imu_7.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
/*
* Copyright (C) 2015-2018 Swift Navigation Inc.
* Contact: https://support.swiftnav.com
*
* This source is subject to the license found in the file 'LICENSE' which must
* be be distributed together with this source. All other rights reserved.
*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
*/

// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/imu/test_MsgImuRaw.yaml by generate.py. Do not modify by hand!

#include <check.h>
#include <stdio.h> // for debugging
#include <stdlib.h> // for malloc
#include <sbp.h>
#include <imu.h>

static struct {
u32 n_callbacks_logged;
u16 sender_id;
u8 len;
u8 msg[SBP_MAX_PAYLOAD_LEN];
void *context;
} last_msg;

static struct {
u32 n_callbacks_logged;
u16 sender_id;
u16 msg_type;
u8 msg_len;
u8 msg[SBP_MAX_PAYLOAD_LEN];
u16 frame_len;
u8 frame[SBP_MAX_FRAME_LEN];
void *context;
} last_frame;

static u32 dummy_wr = 0;
static u32 dummy_rd = 0;
static u8 dummy_buff[1024];
static void* last_io_context;

static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef;
static int DUMMY_MEMORY_FOR_IO = 0xdead0000;

static void dummy_reset()
{
dummy_rd = dummy_wr = 0;
memset(dummy_buff, 0, sizeof(dummy_buff));
}

static s32 dummy_write(u8 *buff, u32 n, void* context)
{
last_io_context = context;
u32 real_n = n;//(dummy_n > n) ? n : dummy_n;
memcpy(dummy_buff + dummy_wr, buff, real_n);
dummy_wr += real_n;
return real_n;
}

static s32 dummy_read(u8 *buff, u32 n, void* context)
{
last_io_context = context;
u32 real_n = n;//(dummy_n > n) ? n : dummy_n;
memcpy(buff, dummy_buff + dummy_rd, real_n);
dummy_rd += real_n;
return real_n;
}

static void logging_reset()
{
memset(&last_msg, 0, sizeof(last_msg));
memset(&last_frame, 0, sizeof(last_frame));
}

static void msg_callback(u16 sender_id, u8 len, u8 msg[], void* context)
{
last_msg.n_callbacks_logged++;
last_msg.sender_id = sender_id;
last_msg.len = len;
last_msg.context = context;
memcpy(last_msg.msg, msg, len);
}

static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], u16 frame_len, u8 frame[], void *context)
{
last_frame.n_callbacks_logged++;
last_frame.sender_id = sender_id;
last_frame.msg_type = msg_type;
last_frame.msg_len = msg_len;
memcpy(last_frame.msg, msg, msg_len);
last_frame.frame_len = frame_len;
memcpy(last_frame.frame, frame, frame_len);
last_frame.context = context;
}

START_TEST( test_auto_check_sbp_imu_7 )
{
static sbp_msg_callbacks_node_t n;
static sbp_msg_callbacks_node_t n2;

// State of the SBP message parser.
// Must be statically allocated.
sbp_state_t sbp_state;

//
// Run tests:
//
// Test successful parsing of a message
{
// SBP parser state must be initialized before sbp_process is called.
// We re-initialize before every test so that callbacks for the same message types can be
// allocated multiple times across different tests.
sbp_state_init(&sbp_state);

sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO);

logging_reset();

sbp_register_callback(&sbp_state, 0x900, &msg_callback, &DUMMY_MEMORY_FOR_CALLBACKS, &n);
sbp_register_frame_callback(&sbp_state, 0x900, &frame_callback, &DUMMY_MEMORY_FOR_CALLBACKS, &n2);

u8 encoded_frame[] = {85,0,9,52,18,17,26,1,0,192,206,96,0,223,255,44,16,60,0,208,254,238,255,70,135, };

dummy_reset();

u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN];
memset(test_msg_storage, 0, sizeof(test_msg_storage));
u8 test_msg_len = 0;
msg_imu_raw_t* test_msg = ( msg_imu_raw_t* )test_msg_storage;
test_msg_len = sizeof(*test_msg);
test_msg->acc_x = 96;
test_msg->acc_y = -33;
test_msg->acc_z = 4140;
test_msg->gyr_x = 60;
test_msg->gyr_y = -304;
test_msg->gyr_z = -18;
test_msg->tow = 3221225754;
test_msg->tow_f = 206;
sbp_send_message(&sbp_state, 0x900, 4660, test_msg_len, test_msg_storage, &dummy_write);

ck_assert_msg(test_msg_len == sizeof(encoded_frame) - 8,
"Test message has not been generated correctly, or the encoded frame from the spec is badly defined. Check your test spec");

ck_assert_msg(dummy_wr == sizeof(encoded_frame),
"not enough data was written to dummy_buff");
ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0,
"frame was not encoded properly");

while (dummy_rd < dummy_wr) {
ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK,
"sbp_process threw an error!");
}

ck_assert_msg(last_msg.n_callbacks_logged == 1,
"msg_callback: one callback should have been logged");
ck_assert_msg(last_msg.sender_id == 4660,
"msg_callback: sender_id decoded incorrectly");
ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8,
"msg_callback: len decoded incorrectly");
ck_assert_msg(memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8)
== 0,
"msg_callback: test data decoded incorrectly");
ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS,
"frame_callback: context pointer incorrectly passed");

ck_assert_msg(last_frame.n_callbacks_logged == 1,
"frame_callback: one callback should have been logged");
ck_assert_msg(last_frame.sender_id == 4660,
"frame_callback: sender_id decoded incorrectly");
ck_assert_msg(last_frame.msg_type == 0x900,
"frame_callback: msg_type decoded incorrectly");
ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8,
"frame_callback: msg_len decoded incorrectly");
ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0,
"frame_callback: test data decoded incorrectly");
ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame),
"frame_callback: frame_len decoded incorrectly");
ck_assert_msg(memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0,
"frame_callback: frame decoded incorrectly");
ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS,
"frame_callback: context pointer incorrectly passed");

// Cast to expected message type - the +6 byte offset is where the payload starts
msg_imu_raw_t* check_msg = ( msg_imu_raw_t *)((void *)last_msg.msg);
// Run tests against fields
ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used");
ck_assert_msg(check_msg->acc_x == 96, "incorrect value for acc_x, expected 96, is %d", check_msg->acc_x);
ck_assert_msg(check_msg->acc_y == -33, "incorrect value for acc_y, expected -33, is %d", check_msg->acc_y);
ck_assert_msg(check_msg->acc_z == 4140, "incorrect value for acc_z, expected 4140, is %d", check_msg->acc_z);
ck_assert_msg(check_msg->gyr_x == 60, "incorrect value for gyr_x, expected 60, is %d", check_msg->gyr_x);
ck_assert_msg(check_msg->gyr_y == -304, "incorrect value for gyr_y, expected -304, is %d", check_msg->gyr_y);
ck_assert_msg(check_msg->gyr_z == -18, "incorrect value for gyr_z, expected -18, is %d", check_msg->gyr_z);
ck_assert_msg(check_msg->tow == 3221225754, "incorrect value for tow, expected 3221225754, is %d", check_msg->tow);
ck_assert_msg(check_msg->tow_f == 206, "incorrect value for tow_f, expected 206, is %d", check_msg->tow_f);
}
}
END_TEST

Suite* auto_check_sbp_imu_7_suite(void)
{
Suite *s = suite_create("SBP generated test suite: auto_check_sbp_imu_7");
TCase *tc_acq = tcase_create("Automated_Suite_auto_check_sbp_imu_7");
tcase_add_test(tc_acq, test_auto_check_sbp_imu_7);
suite_add_tcase(s, tc_acq);
return s;
}
Loading

0 comments on commit 4a1fd9b

Please sign in to comment.