Sharing Test Step Data
You can share data between test steps to improve the test step
granularity. The following are the two ways to share data:
-
Using persistant data members in the server through accessor
functions to share data between test steps in a common thread:
LOAD_SUITE
stores the shared data in the CTestServer
derived class, and instantiate its test steps with a reference to their parent
class. For example:
CTestStep* CSampleServer::CreateTestStep(const TDesC& aStepName)
{
CTestStep* testStep = NULL;
// Test step name constant in the test step header file
// Created "just in time"
// Just one created here but create as many as required.
if(aStepName == KSampleStep1)
testStep = new CSampleStep1(*this); // Reference to parent
return testStep;
}
If the parent class provides accessor methods to its data, then this
data is accessible to the child test step. However, the test server must be
loaded with:
LOAD_SUITE SampleServer –SharedData
The default mode of operation in LOAD_SUITE allows scripts to run tests in
CONCURRENT mode. This involves multiple
test steps running concurrently with each test step running in its own new
thread instance with its own heap. In this mode of operation, it is not
possible to share the data stored in the server. If the SharedData
flag is set when a server is loaded, successive test steps are run in a reused
thread with the main server's heap. This means that CONCURRENT
mode is disabled for that server session.
-
Using shared memory to share data between test steps running in
separate threads: SHARED_DATA
is a global heap memory object that
can be used to share the text data between threads. This requires an initial
SHARED_DATA command to be used within the
script file. For example:
SHARED_DATA <FullIniFilePath\xxxFile.ini> <SectionName>
xxxFile.ini
is a user defined .ini
file. It
must contain the specified section name. The section should contain key-value
pairs to store the shared data. For example:
shared_data_num = 2 //Two shared objects
shared_name_1 = SharedData // Name of the first shared object
shared_name_2 = SharedData1 // Name of the second shared object
The first key holds the number of shared objects that needs to be
allocated. This is followed by a numbered entry for each of these objects. The
value for these keys is the name of the individual heap object allocated in the
heap to store the data.
When the script is executed, the objects are readily shared and
accessed in test codes through a set of functions available in
CTestStep
. The following example shows some shared data being read
and written using these functions.
TVerdict CSampleStep1::doTestStepL()
{
TBuf<256> txtReadData(KNull); // Initialise a buffer
_LIT(KSharedDataName,"SharedData"); // Shared data name provided in ini file
// Data is read into the buffer
TRAPD(err,ReadSharedDataL(KSharedDataName, txtReadData));
_LIT(KWriteData, “Green pastures?”); // Data to be written for sharing
TPtrC txtWriteData;
txtWriteData.Set(KWriteData); // Copy the literal to a text buffer
// Data copied to shared location
WriteSharedDataL(KSharedDataName, txtWriteData, ESetText);
}
Note: The flag ESetText
overwrites the text in
the shared location. Alternatively, EAppendText
can be used, to
append the new text to the current data.