Skip to content

Commit bfba462

Browse files
committed
Adding unit tests for block forwarding issue discovered in #12.
1 parent 2d5ca73 commit bfba462

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

resources/project/Project.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4379,6 +4379,26 @@
43794379
</Category>
43804380
</Info>
43814381
</File>
4382+
<File Location="simulink">
4383+
<DIR_SIGNIFIER Location="1">
4384+
<Info/>
4385+
</DIR_SIGNIFIER>
4386+
<Info/>
4387+
<File Location="mroblocksForwarding.slx">
4388+
<Info>
4389+
<Category UUID="FileClassCategory">
4390+
<Label UUID="design"/>
4391+
</Category>
4392+
</Info>
4393+
</File>
4394+
<File Location="troblocksForwarding.m">
4395+
<Info>
4396+
<Category UUID="FileClassCategory">
4397+
<Label UUID="test"/>
4398+
</Category>
4399+
</Info>
4400+
</File>
4401+
</File>
43824402
</File>
43834403
</File>
43844404
</Files>
88.6 KB
Binary file not shown.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
classdef troblocksForwarding < matlab.unittest.TestCase
2+
%troblocksForwarding Test block forwarding of blocks in roblocks library
3+
% We introduced block forwarding when we introduced the sub-libraries
4+
% generallib, mobilelib, and visualservolib.
5+
6+
% Copyright 2023-2025 Peter Corke, Witold Jachimczyk, Remo Pillat
7+
8+
properties (Constant)
9+
%ModelName - Name of Simulink model containing the old blocks
10+
ModelName = "mroblocksForwarding"
11+
12+
%LibraryName - Main Simulink library for RVC Toolbox
13+
LibraryName = "roblocks"
14+
end
15+
16+
properties
17+
%ForwardingTable - Forwarding table extracted from library
18+
% This will be a Nx3 string array.
19+
ForwardingTable
20+
end
21+
22+
properties (TestParameter)
23+
%BlockNames - Block names to test for forwarding
24+
% Each parameter contains 3 values
25+
% (1) The name of the block in ModelName
26+
% (2) The original block path
27+
% (3) The new, forwarded block path
28+
pBlockName = struct(...
29+
"angdiff", {{"angdiff", "roblocks/angdiff", "generallib/angdiff"}}, ...
30+
"tform2delta", {{"tform2delta", "roblocks/tform2delta", "generallib/tform2delta"}}, ...
31+
"wrapToPi", {{"wrapToPi", "roblocks/wrapToPi", "generallib/wrapToPi"}}, ...
32+
"Quadrotor", {{"Quadrotor", "roblocks/Quadrotor", "mobilelib/Quadrotor"}}, ...
33+
"ControlMixer", {{"Control Mixer 4", "roblocks/Control Mixer 4", "mobilelib/Control Mixer 4"}}, ...
34+
"JointVLoop", {{"Joint vloop", "roblocks/Joint vloop", "mobilelib/Joint vloop"}} ...
35+
)
36+
end
37+
38+
methods(TestClassSetup)
39+
function loadTestModel(testCase)
40+
%loadTestModel Load model with forwarded blocks
41+
42+
% Ensure model loads without any warnings. That's a good
43+
% initial sanity check that the forwarding is working.
44+
testCase.verifyWarningFree(@() load_system(testCase.ModelName));
45+
testCase.addTeardown(@() close_system(testCase.ModelName,0));
46+
end
47+
48+
function storeForwardingTable(testCase)
49+
%storeForwardingTable Extract forwarding table from library and store in class property
50+
51+
load_system(testCase.LibraryName);
52+
testCase.addTeardown(@() close_system(testCase.LibraryName, 0));
53+
54+
% Retrieve the actual forwarding table
55+
actualTableTemp = get_param(testCase.LibraryName, "ForwardingTable");
56+
testCase.assertNotEmpty(actualTableTemp, "Expected forwarding table for library to exist");
57+
58+
for k = 1:numel(actualTableTemp)
59+
while length(actualTableTemp{k})< 3
60+
actualTableTemp{k}(end+1)={''};
61+
end
62+
testCase.ForwardingTable = [testCase.ForwardingTable;string(actualTableTemp{k})];
63+
end
64+
end
65+
end
66+
67+
methods(Test)
68+
function blockForwarding(testCase, pBlockName)
69+
%blockForwarding Verify that block forwarding works correctly
70+
71+
[blockName, oldLibraryPath, newLibraryPath] = pBlockName{:};
72+
73+
% Check that block exists in test model
74+
blockPath = testCase.ModelName + "/" + blockName;
75+
testCase.assertNotEmpty(get_param(blockPath, "BlockType"), "Expected block to exist.");
76+
77+
% Verify that forwarding is set up correctly
78+
fwdRow = find(testCase.ForwardingTable.matches(oldLibraryPath));
79+
testCase.verifyNotEmpty(fwdRow, "No entry for block in forwarding table")
80+
actualLibraryPath = get_param(blockPath, "ReferenceBlock");
81+
testCase.verifyEqual(actualLibraryPath, char(newLibraryPath));
82+
end
83+
end
84+
85+
end

0 commit comments

Comments
 (0)