OpenTTCN/Developer corner/Parameterizing individual test cases with module parameters
From OpenTTCN
Home | Developer's corner | Knowledge base | Working documents | Documentation | OpenTTCN IDE | Tutorials | Training | How do I | Frequently asked questions | Technical support |
Parameterizing individual test cases with module parameters
Starting from OpenTTCN Tester for TTCN-3 4.0beta2.1 it is possible to configure test cases in a more fine-grain fashion by overriding individual values of module parameters stored in the parameter repository from the command line using tester run command and --modulepar option.
From the adapter side this requires usage of otGetModuleParameterEffectiveValue() SDK function defined in tci_ext.h and implemented in TCI-CD SDK library.
This facilitates test execution automation and helps creating more versatile shell scripts controlling test execution.
This also allows creating more generic and more powerful adapters that can be parameterized dynamically on a case-by-case basic.
Preparing example
Assume we have two test cases in which the same adapter needs to be used in different modes. For example, test case TC_L2_MS_BV_01 containing valid behaviour uses normal mode of the adapter and sends frames to SUT IP address 192.168.3.1, while TC_L2_MS_BI_01 containing invalid behaviour uses test loop mode of the adapter emulating lower layers of the protocol and sends frames to SUT IP address 192.168.3.2.
Here is how we can make it all in several simple steps.
First we define two new PIXIT parameters in our test suite by adding the following code to a TTCN-3 module containing list of test suite parameters (.ttcn file):
modulepar boolean TSPX_ADAPTER_TEST_LOOP_MODE; modulepar charstring TSPX_SUT_IP_ADDRESS;
Next we assign their default values in the parameter file (.par file):
modulepar boolean TSPX_ADAPTER_TEST_LOOP_MODE := false; modulepar charstring TSPX_SUT_IP_ADDRESS := "127.0.0.1";
Then we add code to the adapter that reads effective values of these module parameters from the current testing session. The best place where to put this code is triExecuteTestCase() hook:
#include <tri/tri.h>
#include <tci/tci.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
extern bool _adapterInTestLoopMode; // global variable defined elsewhere
extern std::string _sutIpAddr; // global variable defined elsewhere
TriStatus triExecuteTestCase(
const TriTestCaseId* testCaseId,
const TriPortIdList* tsiPortList)
{
// Handle TSPX_ADAPTER_TEST_LOOP_MODE module parameter:
TciValue parVal = otGetModuleParameterEffectiveValue("TSPX_ADAPTER_TEST_LOOP_MODE");
if (!parVal)
{
std::cout << "triExecuteTestCase(): Cannot retrieve TSPX_ADAPTER_TEST_LOOP_MODE." << std::endl;
return TRI_ERROR;
}
char* s = otStringifyTciValue(parVal, 0);
_adapterInTestLoopMode = strcmp(s, "true") ? false : true;
setAdapterMode(_adapterInTestLoopMode); // define your own function content elsewhere
free(s);
otReleaseTciValue(parVal);
// Handle TSPX_SUT_IP_ADDRESS module parameter:
parVal = otGetModuleParameterEffectiveValue("TSPX_SUT_IP_ADDRESS");
if (!parVal)
{
std::cout << "triExecuteTestCase(): Cannot retrieve TSPX_SUT_IP_ADDRESS." << std::endl;
return TRI_ERROR;
}
s = otStringifyTciValue(parVal, 0);
std::string ipAddr = s;
ipAddr = ipAddr.substr(1, ipAddr.size() - 2); // strip enclosing double quotes
_sutIpAddr = ipAddr;
free(s);
otReleaseTciValue(parVal);
return TRI_OK;
}
Running example
Now it is easy to run both test cases without the need to reconfigure the adapter or do anything of this kind.
Run tester run command with --modulepar option from the command line or prepare this kind of a shell script (session L2PROTO):
#!/bin/sh tester run --modulepar TSPX_ADAPTER_TEST_LOOP_MODE=false --modulepar TSPX_SUT_IP_ADDRESS="192.168.3.1" L2PROTO TC_L2_MS_BV_01 tester run --modulepar TSPX_ADAPTER_TEST_LOOP_MODE=true --modulepar TSPX_SUT_IP_ADDRESS="192.168.3.2" L2PROTO TC_L2_MS_BI_01
