{"id":4256,"date":"2020-01-23T10:01:28","date_gmt":"2020-01-23T08:01:28","guid":{"rendered":"https:\/\/zen-cori.138-201-132-86.plesk.page\/?p=4256"},"modified":"2022-10-11T11:50:19","modified_gmt":"2022-10-11T09:50:19","slug":"3-challenges-in-setting-up-a-test-project-for-handwritten-c-code","status":"publish","type":"post","link":"https:\/\/www.btc-embedded.com\/zh-hans\/3-challenges-in-setting-up-a-test-project-for-handwritten-c-code\/","title":{"rendered":"3 Challenges in Setting up a Test Project for Handwritten C-Code"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"4256\" class=\"elementor elementor-4256\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-3b5f0493 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"3b5f0493\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-559a247a\" data-id=\"559a247a\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-d83c847 elementor-widget elementor-widget-text-editor\" data-id=\"d83c847\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Despite the growing trend of Model-based software development (MBD) in automotive, an important part of the embedded software is still developed as handwritten code. People often move to MBD for new projects or when new complex functions are introduce. Several factors explain the remaining hand-code part such as: existing legacy code proven in use, experienced hand coding engineers present in the companies, big challenges to<span style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform ); background-color: var( --e-global-color-8c64e01 );\">\u00a0reverse-engineer handwritten code into models<\/span><span style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform ); background-color: var( --e-global-color-8c64e01 );\">, and of course low-level software which are difficult to develop with MBD.\u00a0<\/span><span style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform ); background-color: var( --e-global-color-8c64e01 );\">Although, writing embedded code in C is as old as the language itself, the verification process is constantly looking for improvements. On the process side, new safety standards like\u00a0<\/span><a style=\"font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform );\" href=\"https:\/\/www.iso.org\/standard\/68388.html\" target=\"_blank\" rel=\"noopener\">ISO 26262<\/a><span style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform ); background-color: var( --e-global-color-8c64e01 );\">\u00a0requires a\u00a0<\/span><a href=\"https:\/\/www.btc-embedded.com\/when-and-how-to-qualify-tools-according-to-iso-26262\/\" target=\"_blank\" rel=\"noopener\">qualified verification tool for ASIL rated software<\/a><span style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform ); background-color: var( --e-global-color-8c64e01 );\">\u00a0and for the daily work, engineers look for solutions\u00a0<\/span><span style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform ); background-color: var( --e-global-color-8c64e01 );\">with less manual effort\u00a0<\/span><span style=\"background-color: var( --e-global-color-8c64e01 ); color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform );\">for unit testing C code.\u00a0<\/span><\/p><p><span style=\"background-color: var( --e-global-color-8c64e01 ); color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform );\">Compared to MBD, handwritten code has a very low degree of abstraction. It\u2019s often difficult to identify which function to test and which variable to access in a bunch of source files. It\u2019s even harder to isolate the function for testing when it has many dependencies. In this context, we identify three main challenges:<\/span><\/p><ol><li>The recurrent need to create stub code for external variables and functions<\/li><li>The extraction of an architecture view of the test interfaces of each function<\/li><li>The creation of the test harness to write, execute and evaluate test cases<\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7c099a8 elementor-widget elementor-widget-heading\" data-id=\"7c099a8\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">1 - Stubbing <\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a1ff07f elementor-widget elementor-widget-text-editor\" data-id=\"a1ff07f\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Software units have inter-dependencies through the data they exchange and sometimes extra-dependencies with sub-components like library functions, services or hardware routines, plus\u00a0 the architecture is often distributed in several files. To perform unit test, the unit has to be &#8220;isolated&#8221; from the rest<span style=\"color: var( --e-global-color-text ); letter-spacing: 0px; background-color: var( --e-global-color-8c64e01 );\">\u00a0and this process sometimes requires <\/span><span style=\"color: var( --e-global-color-text ); letter-spacing: 0px; background-color: var( --e-global-color-8c64e01 );\">to create stub code for the variables and functions owned by other units.<\/span><\/p><p><b>How easy it is to create stubs?\u00a0<\/b><\/p><p>Let\u2019s compare two types of software architectures:<b><br \/><\/b><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-ff5eb11 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"ff5eb11\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-b2010cd\" data-id=\"b2010cd\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-e9e1ace elementor-widget elementor-widget-text-editor\" data-id=\"e9e1ace\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><b>a.<\/b> A cluttered software architecture where the frontier between the software and the hardware layers cannot be well identified (e.g. direct call of low level hardware routines within the software units) nor the frontier between the software units (e.g. unit owning variables accessed by other units)<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-baec2de\" data-id=\"baec2de\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-8a61f1d elementor-widget elementor-widget-image\" data-id=\"8a61f1d\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"250\" height=\"143\" src=\"https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2020\/01\/01-software-hardware-250x143-b62.png\" class=\"attachment-large size-large wp-image-8061\" alt=\"\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-050f1fb elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"050f1fb\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-79c7e1a\" data-id=\"79c7e1a\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-a317b1a elementor-widget elementor-widget-text-editor\" data-id=\"a317b1a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><b>b.<\/b> In opposite, a structured software architecture where the software units are separated and communicate through well-defined interface variables not owned by the units themselves and where a middle abstraction layer creates the interface between the software and the hardware<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-089198e\" data-id=\"089198e\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-7ee616a elementor-widget elementor-widget-image\" data-id=\"7ee616a\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"350\" height=\"147\" src=\"https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2020\/01\/02-stack-350x147-d8f.png\" class=\"attachment-large size-large wp-image-8062\" alt=\"\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<div class=\"elementor-element elementor-element-0c9822b elementor-widget elementor-widget-text-editor\" data-id=\"0c9822b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>With <b>option a<\/b>, the access to hardware functions within the unit makes it almost impossible to test the unit without the hardware. Units owning the definition of interface variables create cascaded dependencies which requires to carry several files when testing other units. Such architecture style increases the stubbing effort as it\u2019s difficult to find the cutting layer from where files, variables and functions can be stubbed.<\/p><p><b>Option b<\/b> in contrary, enables to develop and test the units\u00a0<span style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform ); background-color: var( --e-global-color-8c64e01 );\">individually<\/span><span style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform ); background-color: var( --e-global-color-8c64e01 );\">\u00a0and significantly reduces the stubbing effort. For example, if the interface layer is not yet or only partially developed, the missing interface variables (external to the units) can easily be stubbed in a temporary file without altering the production code.<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-934b48a elementor-widget elementor-widget-text-editor\" data-id=\"934b48a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>In a distributed development process, software units are developed by several teams in parallels and some parts of the architecture are only available at the final integration phase. Therefore, stub code is often needed. An appropriate software architecture such as <b>option b<\/b> helps to reduce the stubbing effort for more efficiency.<\/p><p>Nevertheless, the stubbing process itself can have some complexity depending on the data to be stubbed. Here are some examples:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c10a0d4 elementor-widget elementor-widget-image\" data-id=\"c10a0d4\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"800\" height=\"630\" src=\"https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2022\/05\/Blog_3challenges_Tab1.png\" class=\"attachment-large size-large wp-image-8087\" alt=\"\" srcset=\"https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2022\/05\/Blog_3challenges_Tab1.png 3272w, https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2022\/05\/Blog_3challenges_Tab1-768x604.png 768w, https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2022\/05\/Blog_3challenges_Tab1-1536x1209.png 1536w, https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2022\/05\/Blog_3challenges_Tab1-2048x1612.png 2048w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-db3cc27 elementor-widget elementor-widget-text-editor\" data-id=\"db3cc27\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Stubbing effort while unit testing C code<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6cdaf06 elementor-widget elementor-widget-text-editor\" data-id=\"6cdaf06\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>To conclude, once stubbing is possible, it can be handled through an automated process assisted by tool. The correctness and accuracy of the stub code depends on the tools capability to identify the inter-dependencies within the set of source files. With\u00a0<a href=\"https:\/\/www.btc-embedded.com\/btc-embeddedplatform\/\" target=\"_blank\" rel=\"noopener\">BTC EmbeddedPlatform<\/a>\u00a0for instance, the stubbing feature proceeds through\u00a0an exhaustive parsing of the c-code to detect undefined variables and functions and offer to create stub code from a simple push button. This includes stub code for variables, arrays, pointer initialization, function pointers and complex data such as nested structures.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8f3060b elementor-widget elementor-widget-heading\" data-id=\"8f3060b\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">2 - Architecture definition <\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6ec190f elementor-widget elementor-widget-text-editor\" data-id=\"6ec190f\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>For the next step, let\u2019s assume we have a software unit with a self-contained set of source files (including potential stub code) and ready for testing. Before starting, two questions pop up:<\/p><ol><li>What are the input and output variables of the unit and how to access them?<\/li><li>Are there any sub-functions within the unit we should also consider during testing?<\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-da6f93a elementor-widget elementor-widget-heading\" data-id=\"da6f93a\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Interface variables<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fa217fc elementor-widget elementor-widget-text-editor\" data-id=\"fa217fc\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>In model-based development, the interface variables of the software unit are omnipresent as given by the model structure (e.g. ports of a subsystem) but in handwritten code the information is not easy to find. The interface variables can be function arguments, global variables, getter\/setter functions, macros, elements of composite data like structures or a mix of all these. They can be defined in any file and at any line of the code. Reading the code to find interface information is not realistic. Instead, test engineers should use an automated solution to extract the information as form of an abstract architecture view (a kind of box with Inputs\/Outputs). No matter which variable construct the function uses as interface, the abstract view of the test interfaces helps the tester to know which variables stimulate the function and which ones can be evaluated. In general, the software units have four types of interfaces:<\/p><ol><li>Input variables: signal received by the unit under test (produced by another unit)<\/li><li>Output variables: signal produced by the unit under test<\/li><li>Calibration variables: variables used for software configuration<\/li><li>Measurement variables: variables inside the unit allowing to measure inner operation results usually for debugging purpose. During unit test they are treated similar as outputs.<\/li><\/ol><div>\u00a0<\/div><p>In the following examples, we see various definition of function interfaces. For the test engineer, the abstract architecture view (in the right-hand column) is more self-explaining then the code itself.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-65b120e elementor-widget elementor-widget-image\" data-id=\"65b120e\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"566\" src=\"https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2022\/10\/AbstractView1.png\" class=\"attachment-large size-large wp-image-12050\" alt=\"unit-testing-c-code-abstractionexamples1\" srcset=\"https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2022\/10\/AbstractView1.png 1370w, https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2022\/10\/AbstractView1-768x543.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5dfd4bc elementor-widget elementor-widget-image\" data-id=\"5dfd4bc\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"575\" src=\"https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2022\/10\/AbstractView2.png\" class=\"attachment-large size-large wp-image-12053\" alt=\"unit-testing-c-code-abstractionexamples2\" srcset=\"https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2022\/10\/AbstractView2.png 1361w, https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2022\/10\/AbstractView2-768x552.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7303e71 elementor-widget elementor-widget-heading\" data-id=\"7303e71\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Function hierarchy<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-79c29f9 elementor-widget elementor-widget-text-editor\" data-id=\"79c29f9\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Complex or large software units are often split into smaller functions. The goal is to group functional operations into sub parts to break down the complexity. This can be a design choice of the developer, or a constraint derived from the software requirements (e.g. pre or post processing of data, reusable operations, etc.). It helps to develop the function step by step and to test functions with relatively small sizes and then proceed hierarchically towards the highest level. In addition, the hierarchical testing eases the debugging tasks as errors can be narrowed down to a small area of the unit.<\/p><p>Just as for the interface variables, it can be difficult to find the function hierarchy by just looking at the c code. An abstract architecture view (extracted automatically like a call graph) is much easier to read and understand.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1f423fe elementor-widget elementor-widget-image\" data-id=\"1f423fe\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"439\" src=\"https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2022\/10\/HiearchicalFunctions.png\" class=\"attachment-large size-large wp-image-12047\" alt=\"unit-testing-c-code-callgraph\" srcset=\"https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2022\/10\/HiearchicalFunctions.png 1361w, https:\/\/www.btc-embedded.com\/wp-content\/uploads\/2022\/10\/HiearchicalFunctions-768x422.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ef2476b elementor-widget elementor-widget-text-editor\" data-id=\"ef2476b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>With\u00a0<a href=\"https:\/\/www.btc-embedded.com\/btc-embeddedplatform\/\" target=\"_blank\" rel=\"noopener\">BTC EmbeddedPlatform<\/a>, an automatic analysis of the source code can find all functions and the hierarchical calls between them. This is presented in a call graph where the test engineer can choose which function to test. In addition, the interface variables of each function are analyzed automatically and made accessible in the test cases. The user can adjust the analyzed\u00a0interface definition or overwrite it from external data base describing the I\/Os of the function.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-46ac4dd elementor-widget elementor-widget-heading\" data-id=\"46ac4dd\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">3 - Test Harness<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-190a8e8 elementor-widget elementor-widget-text-editor\" data-id=\"190a8e8\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>The test harness is the executable part of a test tool that connects the function-under-test, the test cases, the compiler, and further methods (or tools) to evaluate the test results.<\/p><p>Often, unit testing of C code uses handwritten code to test handwritten code. This is possible with many testing frameworks including standard Integrated Development Environment (IDE) such as Microsoft Visual Studio or Eclipse. However, setting up an IDE test project can be time consuming and error prone.\u00a0<span style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform ); background-color: var( --e-global-color-8c64e01 );\">The abstraction view of the function-under-test is missing, and the test engineer must manually find the functions and interface variables to access.\u00a0<\/span><span style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform ); background-color: var( --e-global-color-8c64e01 );\">The convenience for writing and evaluating the test cases in IDEs is very low compared to a graphical user interface, plus many other aspects such as test management, coverage analysis, traceability with the requirements require to integrate with third party tools or plugins.\u00a0<\/span><\/p><p>Ideally and among other features,\u00a0<span style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform ); background-color: var( --e-global-color-8c64e01 );\">an efficient test harness should be able to automatically handle variable scaling (e.g. fixed-point datatype) to support test values written in the physical domain. It should enable mathematical signals creation including time dimension and the definition of tolerances and more complex verdict mechanism to evaluate the test results, and finally, it should be able to execute several test cases automatically to calculate an aggregated result.<\/span><\/p><p>As the manual approach to create a test harness is error-prone, any mistake can have a direct impact on the test result. Therefore, we recommend using professional tool to test\u00a0complex and safety critical functions. The professional test tool would typically be able to automatically create the test harness from an abstract architecture definition and prepare the test interfaces for a ready-to-use project. This can considerably speed up the test process and improve the quality of the testing activities.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9a9f5a0 elementor-widget elementor-widget-heading\" data-id=\"9a9f5a0\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Conclusion: Abstraction and automation are testers\u2019 best friends<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-be1858c elementor-widget elementor-widget-text-editor\" data-id=\"be1858c\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Unit testing C code is possible with several IDEs including open source tools but for complex software functions, testing goes beyond a simple gathering and compilation of source files. An efficient testing process needs a \u201cwell\u201d defined software architecture combined with maximum automation and sufficient abstraction for the test authoring. Automatic stubbing is a handy feature to manage external dependencies. An abstract architecture view of the functions and interfaces offers a \u201csystem\u201d view which helps to connect the function-under-test, the software requirements and the test cases. The automatic creation of the test harness, without user interaction, is the highest added value feature for a test engineer. Once available, test cases can be\u00a0<span style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform ); background-color: var( --e-global-color-8c64e01 );\">immediately\u00a0<\/span><span style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform ); background-color: var( --e-global-color-8c64e01 );\">created and executed. In addition, we should not ignore other aspects such as test management, coverage measurement, reporting and debugging required to address modern software development. At BTC, we try to solve these challenges with our integrated test tool\u00a0<\/span><a style=\"font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform );\" href=\"https:\/\/www.btc-embedded.com\/btc-embeddedplatform\/\" target=\"_blank\" rel=\"noopener\">BTC EmbeddedPlatform<\/a><span style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: var( --e-global-typography-text-font-size ); font-style: var( --e-global-typography-text-font-style ); font-weight: var( --e-global-typography-text-font-weight ); letter-spacing: var( --e-global-typography-text-letter-spacing ); text-transform: var( --e-global-typography-text-text-transform ); background-color: var( --e-global-color-8c64e01 );\">.<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Despite the growing trend of Model-based software devel [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":9059,"comment_status":"open","ping_status":"closed","sticky":false,"template":"elementor_theme","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[62],"product":[],"use_cases":[],"class_list":["post-4256","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-handcode"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.btc-embedded.com\/zh-hans\/wp-json\/wp\/v2\/posts\/4256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.btc-embedded.com\/zh-hans\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.btc-embedded.com\/zh-hans\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.btc-embedded.com\/zh-hans\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.btc-embedded.com\/zh-hans\/wp-json\/wp\/v2\/comments?post=4256"}],"version-history":[{"count":0,"href":"https:\/\/www.btc-embedded.com\/zh-hans\/wp-json\/wp\/v2\/posts\/4256\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.btc-embedded.com\/zh-hans\/wp-json\/wp\/v2\/media\/9059"}],"wp:attachment":[{"href":"https:\/\/www.btc-embedded.com\/zh-hans\/wp-json\/wp\/v2\/media?parent=4256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.btc-embedded.com\/zh-hans\/wp-json\/wp\/v2\/categories?post=4256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.btc-embedded.com\/zh-hans\/wp-json\/wp\/v2\/tags?post=4256"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/www.btc-embedded.com\/zh-hans\/wp-json\/wp\/v2\/product?post=4256"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.btc-embedded.com\/zh-hans\/wp-json\/wp\/v2\/use_cases?post=4256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}