Search code examples
testingcaplcanoe

Which is the correct code structure to be followed for getting the best output using TestModules in Canoe?


I am using CANoe 10.0 to do some Diagnostic testing and I have to generate reports for the tests. So, I am using Test Setup to create my test cases using CAPL. I know that the test starts from the function "MainTest". After this, I don't know how to structure my test case and which functions to use to get the correct format in the report. For example, I want to send a Diagnostic request and expecting a particular response. I want to be able to show in the report, the sending of the message, what response was received and what response was expected. Based on this, the verdict should be displayed.


Solution

  • Below you can find simple example. More examples and another use cases you can find in CANoe 'Help' and "Sample Configurations" provided by Vector.Before first try please remember to add CDD file which will allow you to import diagnostics services to CANoe environment(Ive used example Vector CDD).

    void MainTest()
    {
    TestModuleTitle ("ECU DIAGNOSTICS TEST");
    TestModuleDescription ("Basic Diagnostics Test");
    
    TestGroupBegin("ECU Extended session", "ReadPartNubmers");
    ExtendedDiagnosticSession_Start();
    //testcase 
    //testcase 
    //...
    //testcase n
    TestGroupEnd();
    
    TestGroupBegin("ECU Identification", "ReadPartNubmers");
    ReadSerialPartNumber();
    //testcase eg  ReadSerialPartNumber()... 
    //testcase 
    //...
    //testcase 
    TestGroupEnd();  
    }
    
    testcase  ReadSerialPartNumber()
    {
    diagRequest ABS_ESP.Serial_Number_Read req; //Service from CDD
    
    TestCaseTitle("TEST 1 ReadPartNumber", "Read Serial Part Number");
    
    diagSendRequest(req);
    
    if (TestWaitForDiagResponse(req, 2000)== 1)
    {
      testReportWriteDiagResponse(req);
    
      if(DiagGetLastResponseCode(req) == -1) // Positive response
      {
        byte DataBuffer[50];
    
        diagGetRespParameterRaw(req,"SerialNumber",DataBuffer,20);// get data from response
    
          if(DataBuffer[0] == 0xAA)//dummy response verification
          {
             TestStepPass("Serial Number is correct");
          }
          else
          {
             TestStepFail("Wrong Part number ");
          }
      }
      else if(DiagGetLastResponseCode(req) > 0)//Negative response 
      {
        TestStepFail("Negative response received");
      }
    
    }
    else
    {
      TestStepFail("No answer from ECU!");
    }
    }
    
    testcase ExtendedDiagnosticSession_Start()
    {
      diagRequest ABS_ESP.ExtendedDiagnosticSession_Start req; //Service from CDD, 
    
     TestCaseTitle("Test no 1", "Set Extended session");
    
    diagSendRequest(req);
    
    if (TestWaitForDiagResponse(req, 2000)== 1)
    {
      testReportWriteDiagResponse(req);
    
      if(DiagGetLastResponseCode(req) == -1) // Positive response
      {
    
       TestStepPass("Positive");
    
      }
      else if(DiagGetLastResponseCode(req) > 0)//Negative response 
      {
    
        TestStepFail("ExtendedDiagnosticSession","Negative response received");
      }
    
    }
    else
    {
      TestStepFail("ExtendedDiagnosticSession","No answer from ECU!");
    }
    
    }