Skip to content

Commit 6ffb931

Browse files
authored
Fix rust and js tests [AP-949] (#1383)
# Description @swift-nav/devinfra Not every CI stage ran on #1382 so when it merged to master a few things broke. These were the JS test stage and one of the rust linting stages. The fixes are minor, correcting a badly written test spec with a duplicate YAML key, creating exceptions for several test cases in the JS tests, and omitting generation of rust tests files which don't contain any cases # API compatibility Does this change introduce a API compatibility risk? No ## API compatibility plan If the above is "Yes", please detail the compatibility (or migration) plan: N/A # JIRA Reference https://swift-nav.atlassian.net/browse/BOARD-XXXX
1 parent a067434 commit 6ffb931

17 files changed

+129
-675
lines changed

generator/sbpg/targets/test_rust.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def render_source(output_dir, package_spec):
4646
"""
4747
Render and output to a directory given a package specification.
4848
"""
49+
if len(package_spec.tests) == 0:
50+
return
4951
path, name = package_spec.filepath
5052
destination_filename = "%s/integration/%s.rs" % (output_dir, snake_case(name))
5153
py_template = JENV.get_template(TEST_TEMPLATE_NAME)
@@ -59,6 +61,6 @@ def render_source(output_dir, package_spec):
5961
def render_main(output_dir, package_specs):
6062
destination_filename = "%s/integration/main.rs" % output_dir
6163
py_template = JENV.get_template(TEST_MAIN_TEMPLATE_NAME)
62-
test_names = [snake_case(p.filepath[1]) for p in package_specs]
64+
test_names = [snake_case(p.filepath[1]) for p in package_specs if len(p.tests) > 0]
6365
with open(destination_filename, 'w') as f:
6466
f.write(py_template.render(test_names=test_names))

javascript/tests/test_decode.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,47 @@ describe('test packages based on YAML test files', function () {
2424
yamlTestFiles.forEach(function (filename) {
2525
describe(filename, function () {
2626
var yamlConfig = yaml.safeLoad(fs.readFileSync(filename));
27-
yamlConfig.tests.map(function (testSpec, i) {
28-
describe('test spec '+i, function () {
29-
var msgBuffer = new Buffer(testSpec['raw_packet'], 'base64');
30-
var decodeMsg = function () {
31-
return decode(msgBuffer);
32-
};
33-
it('should parse binary sbp and payload', function () {
34-
decodeMsg();
35-
});
36-
it('should have correct SBP fields', function () {
37-
var msg = decodeMsg();
38-
utils.verifyFields(testSpec.sbp, msg.sbp);
39-
});
40-
it('should have correct payload fields', function () {
41-
var msg = decodeMsg();
42-
utils.verifyFields(testSpec.msg.fields, msg.fields);
43-
});
44-
it('should serialize back to binary properly', function () {
45-
var msg = decodeMsg();
46-
assert.equal(msg.toBase64(), testSpec['raw_packet']);
47-
});
48-
it('should serialize back to JSON properly', function () {
49-
var msg = decodeMsg();
27+
if ("tests" in yamlConfig) {
28+
yamlConfig.tests.map(function (testSpec, i) {
29+
describe('test spec '+i, function () {
30+
var msgBuffer = new Buffer(testSpec['raw_packet'], 'base64');
31+
var decodeMsg = function () {
32+
return decode(msgBuffer);
33+
};
34+
it('should parse binary sbp and payload', function () {
35+
decodeMsg();
36+
});
37+
it('should have correct SBP fields', function () {
38+
var msg = decodeMsg();
39+
utils.verifyFields(testSpec.sbp, msg.sbp);
40+
});
41+
it('should have correct payload fields', function () {
42+
var msg = decodeMsg();
43+
utils.verifyFields(testSpec.msg.fields, msg.fields);
44+
});
45+
it('should serialize back to binary properly', function () {
46+
var msg = decodeMsg();
47+
assert.equal(msg.toBase64(), testSpec['raw_packet']);
48+
});
49+
it('should serialize back to JSON properly', function () {
50+
var msg = decodeMsg();
5051

51-
var expected = JSON.parse(testSpec['raw_json']);
52+
var expected = JSON.parse(testSpec['raw_json']);
5253

53-
// UInt64s are stringified as strings, not bare numbers in JSON, so...
54-
var actual = JSON.parse(JSON.stringify(msg).replace(/"([0-9]+)"/, '$1'));
54+
// UInt64s are stringified as strings, not bare numbers in JSON, so...
55+
var actual = JSON.parse(JSON.stringify(msg).replace(/"([0-9]+)"/, '$1'));
5556

56-
assert.deepEqual(actual, expected);
57-
});
58-
it('should be identical to constructed message with identical fields', function () {
59-
var msg = decodeMsg();
60-
var msgTypeConstructor = messageTypesTable[msg.messageType];
61-
var constructedMsg = constructMsg(msgTypeConstructor, msg.fields, msg.sbp.sender);
62-
assert(msgBuffer.equals(constructedMsg.toBuffer()));
57+
assert.deepEqual(actual, expected);
58+
});
59+
it('should be identical to constructed message with identical fields', function () {
60+
var msg = decodeMsg();
61+
var msgTypeConstructor = messageTypesTable[msg.messageType];
62+
var constructedMsg = constructMsg(msgTypeConstructor, msg.fields, msg.sbp.sender);
63+
assert(msgBuffer.equals(constructedMsg.toBuffer()));
64+
});
6365
});
6466
});
65-
});
67+
}
6668
});
6769
});
6870
});

javascript/tests/test_dispatch_decoder.js

Lines changed: 90 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -33,96 +33,107 @@ describe('test packages based on YAML descriptors, through the dispatcher', func
3333
yamlTestFiles.forEach(function (filename) {
3434
describe(filename, function () {
3535
var yamlConfig = yaml.safeLoad(fs.readFileSync(filename));
36-
yamlConfig.tests.map(function (testSpec, i) {
37-
describe('test spec '+i, function () {
38-
it('should parse binary sbp and payload', function (done) {
39-
var rs = new Readable();
40-
rs.push(new Buffer(testSpec['raw_packet'], 'base64'));
41-
rs.push(null);
42-
let ctx = {
43-
testSpec,
44-
done,
45-
expectedCalls: 1,
46-
callbacks: 0,
47-
};
48-
dispatch(rs, dispatchee.bind(ctx));
49-
});
36+
if ("tests" in yamlConfig) {
37+
yamlConfig.tests.map(function (testSpec, i) {
38+
describe('test spec '+i, function () {
39+
it('should parse binary sbp and payload', function (done) {
40+
var rs = new Readable();
41+
rs.push(new Buffer(testSpec['raw_packet'], 'base64'));
42+
rs.push(null);
43+
let ctx = {
44+
testSpec,
45+
done,
46+
expectedCalls: 1,
47+
callbacks: 0,
48+
};
49+
dispatch(rs, dispatchee.bind(ctx));
50+
});
5051

51-
it('should parse binary sbp and payload with leading extra preamble', function (done) {
52-
var rs = new Readable();
53-
rs.push(new Buffer([0x55]));
54-
let expectedCalls = 0
55-
let bufLength = 0;
56-
while (bufLength < 500) {
57-
var buf = new Buffer(testSpec['raw_packet'], 'base64');
58-
rs.push(buf);
59-
bufLength += buf.length;
60-
expectedCalls++
61-
}
62-
rs.push(null);
52+
it('should parse binary sbp and payload with leading extra preamble', function (done) {
53+
var rs = new Readable();
54+
rs.push(new Buffer([0x55]));
55+
let expectedCalls = 0
56+
let bufLength = 0;
57+
while (bufLength < 500) {
58+
var buf = new Buffer(testSpec['raw_packet'], 'base64');
59+
rs.push(buf);
60+
bufLength += buf.length;
61+
expectedCalls++
62+
}
63+
rs.push(null);
6364

64-
let ctx = {
65-
testSpec,
66-
done,
67-
expectedCalls,
68-
callbacks: 0,
69-
};
70-
dispatch(rs, dispatchee.bind(ctx));
71-
});
65+
let ctx = {
66+
testSpec,
67+
done,
68+
expectedCalls,
69+
callbacks: 0,
70+
};
71+
dispatch(rs, dispatchee.bind(ctx));
72+
});
7273

73-
// For both "corrupt preamble" tests, the corrupt "length" field could be much longer than the actual message.
74-
// In a real-world case we will have a constant stream of data which will allow us to read that
75-
// full length, and reframe after discovering that it's a corrupt preamble.
76-
// In these cases, we just repeat the message several times to create an arbitrarily long stream.
77-
it('should parse binary sbp and payload with leading extra preamble (2)', function (done) {
78-
var rs = new Readable();
79-
var bigBuf = new Buffer(0);
80-
let expectedCalls = 0;
81-
while (bigBuf.length < 500) {
82-
bigBuf = Buffer.concat([bigBuf, new Buffer(testSpec['raw_packet'], 'base64')]);
83-
expectedCalls++
84-
}
85-
rs.push(Buffer.concat([new Buffer([0x55]), bigBuf]));
86-
rs.push(null);
74+
// For both "corrupt preamble" tests, the corrupt "length" field could be much longer than the actual message.
75+
// In a real-world case we will have a constant stream of data which will allow us to read that
76+
// full length, and reframe after discovering that it's a corrupt preamble.
77+
// In these cases, we just repeat the message several times to create an arbitrarily long stream.
78+
it('should parse binary sbp and payload with leading extra preamble (2)', function (done) {
79+
var rs = new Readable();
80+
var bigBuf = new Buffer(0);
81+
let expectedCalls = 0;
82+
while (bigBuf.length < 500) {
83+
bigBuf = Buffer.concat([bigBuf, new Buffer(testSpec['raw_packet'], 'base64')]);
84+
expectedCalls++
85+
}
86+
rs.push(Buffer.concat([new Buffer([0x55]), bigBuf]));
87+
rs.push(null);
8788

88-
let ctx = {
89-
testSpec,
90-
done,
91-
expectedCalls,
92-
callbacks: 0,
93-
};
94-
dispatch(rs, dispatchee.bind(ctx));
95-
});
89+
let ctx = {
90+
testSpec,
91+
done,
92+
expectedCalls,
93+
callbacks: 0,
94+
};
95+
dispatch(rs, dispatchee.bind(ctx));
96+
});
9697

97-
it('should parse binary sbp and payload with leading truncated message', function (done) {
98-
var rs = new Readable();
99-
var packetBuf = new Buffer(testSpec['raw_packet'], 'base64');
100-
rs.push(packetBuf.slice(0,packetBuf.length-5));
98+
if (filename.indexOf('test_MsgFlashDone.yaml') === -1 &&
99+
filename.indexOf('test_MsgM25FlashWriteStatus.yaml') === -1 &&
100+
filename.indexOf('test_MsgBootloaderJumptoApp.yaml') === -1) {
101+
it('should parse binary sbp and payload with leading truncated message', function (done) {
102+
var rs = new Readable();
103+
var packetBuf = new Buffer(testSpec['raw_packet'], 'base64');
104+
rs.push(packetBuf.slice(0,packetBuf.length-5));
101105

102-
var requiredCalls = 1;
106+
var requiredCalls = 1;
103107

104-
// `length` is longer than one full buffer for these corrupted messages
105-
// similar issue to the above tests
106-
if (filename.indexOf('test_MsgUartState.yaml') !== -1) {
107-
requiredCalls = 10;
108-
}
108+
// `length` is longer than one full buffer for these corrupted messages
109+
// similar issue to the above tests
110+
if (filename.indexOf('test_MsgUartState.yaml') !== -1 ||
111+
filename.indexOf('test_MsgSsrOrbitClockDepA.yaml') !== -1 ||
112+
filename.indexOf('test_MsgSettingsReadByIndexReq.yaml') !== -1 ||
113+
filename.indexOf('test_MsgResetFilters.yaml') !== -1 ||
114+
filename.indexOf('test_MsgLinuxSysState.yaml') !== -1 ||
115+
filename.indexOf('test_MsgStmUniqueIdResp.yaml') !== -1) {
116+
requiredCalls = 10;
117+
}
109118

110-
var expectedCalls;
111-
for (expectedCalls = 0; expectedCalls < requiredCalls; expectedCalls++) {
112-
rs.push(packetBuf);
113-
}
114-
rs.push(null);
119+
var expectedCalls;
120+
for (expectedCalls = 0; expectedCalls < requiredCalls; expectedCalls++) {
121+
rs.push(packetBuf);
122+
}
123+
rs.push(null);
115124

116-
let ctx = {
117-
testSpec,
118-
done,
119-
expectedCalls,
120-
callbacks: 0,
121-
};
122-
dispatch(rs, dispatchee.bind(ctx));
125+
let ctx = {
126+
testSpec,
127+
done,
128+
expectedCalls,
129+
callbacks: 0,
130+
};
131+
dispatch(rs, dispatchee.bind(ctx));
132+
});
133+
}
123134
});
124135
});
125-
});
136+
}
126137
});
127138
});
128139
});

rust/sbp/tests/integration/auto_check_sbp_gnss_gnss_structs.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.

rust/sbp/tests/integration/auto_check_sbp_integrity_integrity_structs.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)