Chapter 3: I only deploy on Fridays

OK, you now have:
Actually, you haven't done anything to assess or improve the quality. Does this CTF work? We actually have no idea. We have no data to suggest it does other than the fact that something was created by our ctf build step. Let's get a little test focused for a minute here.
You may be familiar with the unit test framework built in MATLAB. The astute observer noticed that tests were run as part of the build that produced the toolbox. Unit tests were written against the code, and integration tests ran against the toolbox package to ensure everything was packaged up correctly.
You haven't changed any code of the toolbox, so there shouldn't be a need to write any unit tests. However you have produced a new environment in which the code will run, namely on a production server. You need to have evidence that this deployment will work in production and produce correct results.
With the MATLAB Test product, you can now write equivalence tests to confirm that transformations that occur for Coder and Compiler products produces equivalent results as the tried and tested algorithm in MATLAB. For this workshop, we have written this test for you. Navigate to the integTests/equivalence folder and open MPSEquivalenceTest.m
openFile integTests/equivalence/MPSEquivalenceTest.m
Observe this test does the following:
showCode integTests/equivalence/MPSEquivalenceTest.m 1
1 classdef MPSEquivalenceTest < matlabtest.compiler.TestCase
showCode integTests/equivalence/MPSEquivalenceTest.m 27:30
27 % Load the results built in a prior build step 28 disp("Load the build results from the ""ctf"" task") 29 loadedData = load(resultsFile); 30 buildResults = loadedData.buildResults;
showCode integTests/equivalence/MPSEquivalenceTest.m 32:36
32 % Execute the runtime inputs (damping) on the server 33 disp("Executing design on a local Production Server") 34 design.k = 5e5; 35 design.c = damping; 36 executionResults = testCase.execute(buildResults,{design},"simulateSystem");
showCode integTests/equivalence/MPSEquivalenceTest.m 38:40
38 % Verify server execution is equivalent to the local results 39 disp("Verifying results match MATLAB results") 40 testCase.verifyExecutionMatchesMATLAB(executionResults);
Alright, now let's add this to our build and run it! Open your buildfile and uncomment lines 88 to 96:
openFile buildfile.m 90
showCode buildfile.m 90:98
90 %% Integration tests - back-to-back equivalence tests for the production server archive 91 plan("ctfIntegTest") = TestTask("integTests/equivalence",SourceFiles=["code","pcode"], ... 92 Description="Run integration tests against CTF archive.", ... 93 Dependencies="ctf"); 94 95 96 %% Create the deploy task - does nothing but depends on other tasks 97 plan("deploy") = matlab.buildtool.Task(Dependencies="ctfIntegTest", ... 98 Description="Produce and test a ctf archive to deploy to a MATLAB Production Server");
Here we add a new ctfIntegTests task to the build, and define the outputs of the ctf task we created last time to the Inputs of our new test task. Also we add a new deploy task that simply depends on our new test task. This means that to deploy we not only need to create the ctf, we also need to test against it. Let's now run the build, including our new equivalence tests:
buildtool deploy
** Starting lint Analysis Summary: Total Files: 21 Errors: 0 (Threshold: 0) Warnings: 3 (Threshold: Inf) Results: SARIF: results\win64\code-issues.sarif ** Finished lint ** Starting setupCompiler MEX configured to use 'Microsoft Visual C++ 2022 (C)' for C language compilation. To choose a different language, execute one from the following: mex -setup C++ mex -setup FORTRAN Compiler is detected and properly setup. ** Finished setupCompiler ** Starting mex_convec Building with 'Microsoft Visual C++ 2022 (C)'. MEX completed successfully. ** Finished mex_convec ** Starting mex_yprime Building with 'Microsoft Visual C++ 2022'. MEX completed successfully. ** Finished mex_yprime ** Starting mex ** Finished mex ** Starting test .....
.
. Generating test report. Please wait. Preparing content for the test report.
Adding content to the test report. Writing test report to file. Test report has been saved to: D:\a\Mass-Spring-Damper-PFT-2024\Mass-Spring-Damper-PFT-2024\results\win64\test-results.html MATLAB code coverage report has been saved to: D:\a\Mass-Spring-Damper-PFT-2024\Mass-Spring-Damper-PFT-2024\results\win64\coverage\index.html Test Summary: Total Tests: 7 Passed: 7 Failed: 0 Incomplete: 0 Duration: 2.6631 seconds testing time. Test Results: HTML: results\win64\test-results.html Code Coverage: HTML: results\win64\coverage\index.html ** Finished test ** Starting ctf ** Finished ctf ** Starting ctfIntegTest Load the build results from the "ctf" task Executing design on a local Production Server Verifying results match MATLAB results .Load the build results from the "ctf" task Executing design on a local Production Server Verifying results match MATLAB results .Load the build results from the "ctf" task Executing design on a local Production Server Verifying results match MATLAB results . Test Summary: Total Tests: 3 Passed: 3 Failed: 0 Incomplete: 0 Duration: 25.7766 seconds testing time. ** Finished ctfIntegTest ** Starting deploy ** Finished deploy
open Chapter_4

Preface & TOC | Chapter 4