Re: [PATCH 5/5] binman: test: add code coverage for nxp_imx93cst etype
Simon Glass <[email protected]>
| Newsgroups | org.u-boot-project.lists.u-boot |
|---|---|
| Message-ID | <CAFLszTh6MDfPM75QgLBvwu34cpJ7aeBJZxHXN0uexUFyoDLphA@mail.gmail.com> |
Hi Jérémie, On 2026-08-14T17:07:09, Jérémie Dautheribes <[email protected]> wrote: > binman: test: add code coverage for nxp_imx93cst etype > > Add test methods to cover all code paths of the nxp_imx93cst etype, > reusing the pattern of the nxp_imx8mcst as done in commit 0cab35362d77 > ("binman: test: Fix code coverage for iMX8 and cst bintool") by Simon > Glass. > > This brings nxp_imx93cst to 100% coverage. > > Signed-off-by: Jérémie Dautheribes (Schneider Electric) <[email protected]> > > tools/binman/ftest.py | 78 ++++++++++++++++++++++ > tools/binman/test/vendor/nxp_imx93_csf.dts | 18 +++++ > .../binman/test/vendor/nxp_imx93_csf_imagename.dts | 24 +++++++ > 3 files changed, 120 insertions(+) > + def testNxpImx93cstELE(self): > + """Test CST signing with an i.MX93 SPL container including the ELE > + FW""" Please keep the docstring on a single line to match the imx8 tests just above. It fits within 80 columns as e.g. "Test CST signing where the SPL container starts with the ELE FW". > + def testNxpImx93cstSigned(self): > + """Test CST-signing-success path with mocked cst invocation""" > + spl_data = bytearray(64) > + spl_data[3] = nxp_imx93cst.CONTAINER_HDR_TAG > + spl_data[12:14] = struct.pack('<H', 0x90) > + spl_data[40:44] = struct.pack('<I', 0x123) > + self._MakeInputFile('imx93-container.bin', bytes(spl_data)) > + > + # Mock run_cmd() so that when cst is invoked, it creates a fake > + # output blob and returns success, thus covering the signing path > + original = bintool.Bintool.run_cmd > + > + def fake_cst_run_cmd(self_tool, *args, binary=False): > + if self_tool.name == 'cst': > + arg_list = list(args) > + if '-o' in arg_list: > + idx = arg_list.index('-o') > + tools.write_file(arg_list[idx + 1], b'\x00' * 32) > + return 'fake cst output' > + return original(self_tool, *args, binary=binary) > + > + with unittest.mock.patch.object(bintool.Bintool, 'run_cmd', > + new=fake_cst_run_cmd): > + data = self._DoReadFile('vendor/nxp_imx93_csf.dts') data is never used - drop the assignment (as testNxpImx8mCSTSigned does), or add an assertion on the returned bytes so the signing path is actually validated rather than only executed. A quick assertEqual on the length (spl_data plus fake 32-byte blob) would give real coverage rather than only line coverage. > + def testNxpImx93cstUnknownTag(self): > + """Test CST with unknown input tag passes data through""" > + # Trigger the pass-through path using an input without the AHAB > + # container tag > + data = b'\x00' * 64 > + self._MakeInputFile('imx93-container.bin', data) > + self._DoTestFile('vendor/nxp_imx93_csf.dts', > + force_missing_bintools='cst') Since the pass-through branch returns early before cst is invoked, please assert the produced image equals the 64 zero bytes - that way the test actually proves the pass-through behaviour rather than only that no exception is raised. Regards, Simon