Unit Testing
Unit Testing
Unit Testing
UNIT TESTING
Prepared By:
Products Group
KPIT
India
1. UNIT TESTING
Unit testing is performed to identify the deviations present in the AUTOSAR BSW modules code
with respect to design. The Unit is the smallest testable part of the software, which is a function
(API). The unit will be tested individually by providing inputs and validating the outputs from that
function. The unit testing activity goes hand by hand with development activity and unit testing will
be performed by developer.
Stub details is available, while generating script in RTRT. Here, stub means function
present in other .c files of same module.
If function call or nested function calls present in the same .c file, RTRT will not provide
any details.
Manual analyzation is required and path of calling function should be covered.
Typecasting related testing are followed in unit testing but not for void.
If RTRT generates a huge executable code, then sometimes it may not be possible to debug due
To test each unit function, a set of input variables are passed on to the testing sub-module and the
result is compared against the expected result after executing the software in a controlled
environment.
Unit test plan approach will be as below:
Stage 1: Create Equivalence sheet & unit test plan with ESDD (HLD+LLD+Flow chart) as inputs.
Stage 2: Update the same unit test plan once the source code is available to achieve 100%
coverage (MCDC, statement, path, loops, boundary values, equivalence class)
Dependency parameter values like global to local variable mapping
(API inputs), Function calls, Global variable updation, Return value, Stub calls
Module testing is used to verify behaviour of the BSW module against functional requirements from
AUTOSAR <MSN> SRS. Test cases are derived for all the functional requirements for BSW module.
Different test groups shall be created based on the features.
Analyze Module SRS and Create test plan covering all requirements with category
“Requirement on Module Behavior”
For each test group, Identify Default conditions and commonly used macros which
shall be used to pass values as argument and verify out parameter
For each test case, provide unique and sequential test case id with proper title.
Provide requirement reference in “Tested functionality” and applicable
configuration set in “Configuration Test Id”
In test description, provide test steps like invocation of module provided APIs, test
APIs and stub functions
In Expected result, verify return value, OUT parameter for the APIs invoked in test
description
Prepare Make environment for the module testing with consideration of compiler
specific Generic header files
Create test application based on the module test plan. Add stub code for
dependent modules. Follow coding guideline while creating test application
Create test configuration for each test group using K-SAR tool
Generate test configuration and build test application using make commands
Create module test report manually as per STR template. If test case is failed or
not tested, then provide proper justification
The test environment consists of the Integrated Development Environment (IDE) for building the BSW that
has to be tested and test setup for x86 or other specified platform.
Build environment for module testing consists make environment which uses Test application, Module
code, module test configuration and test stub code for building complete test group. Test applications are
developed for each test group based on the test plan and stub code shall be created for all the
dependent modules. Sample test application and stub code are provided in the example below. Test
application will invoke functions of Module under test which is provided in the test description column of
test case. Module shall invoke APIs of dependency module, so stub code shall be provided. Test
configuration and Generic header files are included in the module and shall require for building test
application.
Respective make command shall be used to build the test application. Executable shall be generated once
build is successful without any compilation or linking warning. Run executable using debugger and verify
result for all test cases covered in the test group. Create module test report based on the result from all
test groups.
Similarly, test environment for porting shall be provided for respective platform in the porting STR .
2.6 EXAMPLE
Scope of the Test Cases in this section is to check all possible functionalities which could be achieved via a
DiagnosticSessionControl service. The positive and negative response transmission by the DSP layer for
the DiagnosticSessionControl is also tested in this section.
3 UDS_ON_CAN_TXPDUID 2 NA
4 DCM_TPNSDU_LENGTH_2 2 NA
Tested functionality:
2. The sent confirmation function shall do the mode switch of the
ModeDeclarationGroupPrototype DcmDiagnosticSessionControl by
calling
SchM_Switch_Dcm_<vendorApiInfix>_DcmDiagnosticSessionControl()
with the new diagnostic session type (see Dcm778).
{Dcm311b}
Pre-conditions: None
Test description: Expected test result:
1. Dcm_StartOfReception should return
1. Invoke Dcm_StartOfReception
BUFREQ_OK
(PHY_UDS_ON_CAN_RXPDUID,
2. RxBufferSizePtr should be updated with
DCM_TPNSDU_LENGTH_2, &RxBufferSizePtr)
available buffer size as 0x08
2. Invoke Dcm_CopyRxData
(PHY_UDS_ON_CAN_RXPDUID, &PduInfoPtr, 3. Dcm_CopyRxData should return
&RxBufferSizePtr) BUFREQ_OK
4. RxBufferSizePtr should be updated with
Hint: PduInfoPtr.SduLength = 0x02 buffer size as 0x06
PduInfoPtr.SduDataPtr = 0x10, 0x03
3. Invoke Simulate_Dcm_SessionControl() with
NA
SessionLevel as 3 (Extended Session)
5. PduR_DcmTransmit(UDS_ON_CAN_TXPDUI
4. Invoke
D, &PduInfoPtr) should be invoked
Dcm_TpRxIndication(PHY_UDS_ON_CAN_RXPDUI
D, NTFRSLT_OK)
Hint: PduInfoPtr.SduLength = 0x06
6. Dcm_CopyTxData should return
5. Invoke BUFREQ_OK
Dcm_CopyTxData(UDS_ON_CAN_TXPDUID, 7. PduInfoPtr.SduDataPtr should be updated
&PduInfoPtr, NULL_PTR, &TxDataCntPtr) with the values 0x50, 0x03, 0x00, 0x32,
0x00, 0x05
Hint: PduInfoPtr.SduLength = 0x06 {DCM_SRS_006}
8. TxDataCntPtr should be updated with 0x00
9. ComM_DCM_ActiveDiagnostic(0x04) should
be invoked
6. Invoke Dcm_TpTxConfirmation {Dcm167}
(UDS_ON_CAN_TXPDUID, NTFRSLT_OK) 10. SchM_Switch_Dcm_DcmDiagnosticSessionC
ontrol(0x03) should be invoked
{Dcm311b}
11. Dcm_GetSesCtrlType should return E_OK
7. Invoke Dcm_GetSesCtrlType(&SesCtrlValue) 12. SesCtrlValue should be
0x03(EXTENDED_DIAGNOSTIC_SESSION)
Comments: None
Please refer attached test template and guideline documents for more information.
To build above test application, stub shall be provided for the dependent modules. Following example
shows the sample stub file for PduR module.
Test Log shall be stored at separate folder and reference is provided in Test report.
Provide solution to identify and correct test description when there is any change in sequence
diagram when it is provided.
Tool Exe(<Ma>.exe)
Parameter Definition File (Module PDF)
Module Template file(<Ma>.template)
BSW Module Description Template file(<Ma>BSWMDT.arxml)
Generation Tool SRS (GTSRS)
Generation Tool Design(GTSDD)
Module Descrition file(Ma.arxml) and Dependent Module Descrition files(if applicable).
Generation Tool STP(GTSTP)
Common Generation Tool STP
Common Generation Tool Design
Any other pre-configured configuration(if required)
Step 1: Preparation of module generation tool test plan based on the analysis of KPIT Generation
Tool SRS, Parameter Definition File (PDF) and Tool Design.
Step 2: Prepare Test Input folder structure based on the grouping of Tests (e.g. Consistency
checks, Based on each generated files (Com_Cfg_Source)) and Test scripts used for testing
(Option.txt and batch files if required).
Step 3: Prepare Test Configuration as per Test description for every test case identified in step 1
using K-SAR Editor.
Step 4: Generate Module configuration output files based on configuration for each test case in
prepared folder structure as per step 2.
Step 5: Generate Test report using Output comparator or Generation tool test suite.
3.5 EXAMPLE
Test Report
Log will be stored at separate folder and reference is provided in Test report.
Test Report
4. INTEGRATION TESTING
Integration testing focuses on testing interaction across the different layers of AUTOSAR by
integrating BSW modules, RTE, OS and a sample application developed by KPIT, with third party
MCAL drivers on a target microcontroller.
All AUTOSAR requirements cannot be tested at integration level (Eg: requirements related
to file structure).
All AUTOSAR interfaces are not covered.
4.5 EXAMPLE
Test Plan
Configuration
Ecu Level configuration for Above test case are attached (ComM,EcuM)
Swc_Runnable()
{
Rte_Call_RPortUR000_GetCurrentComMode(&ComMode);
if(ComMode == RTE_MODE_ComMMode_COMM_NO_COMMUNICATION)
{
Rte_Call_RPortUR000_RequestComMode(RTE_MODE_ComMMode_COMM_FULL_COMMU
NICATION);
}
Rte_Call_RPortUR000_GetCurrentComMode(&ComMode);
if(ComMode == RTE_MODE_ComMMode_COMM_FULL_COMMUNICATION)
{
Result = Pass;
}
}
Build the stack along with test application.
Execution of test case
Below is the execution flow for above test case. Figure also shows interaction between
various modules interfaces.
Test Report
Note: Fields in ITR documents are still need to be discussed and decided.