Running Tests (old): Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
m (Marku moved page Running Tests to Running Tests (old))
 
(43 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Target-based [[Test Units]] are controlled by a host computer, physically connected to the target via a configurable communication channel (TCP/IP or serial port). This article describes some common usage patterns and presents several examples.
STRIDE Framework tests (script and native target implementations) are controlled by a host computer, physically connected to the target via a configurable communication channel (TCP/IP or serial port). This article describes some common usage patterns and presents several examples.


== Prerequisites ==
== Prerequisites ==
In order to run target-based [[Test Units]], the following prerequisites are required.


=== Host ===
=== Host ===
* [[Package_Installation#Host_Tools|Stride Host Tools]] installed on the host computer; specifically, the [[Stride Executable|stride]] application.
Tests are initiated on the host by running the program [[Stride Executable|stride]] on the host computer (installed as part of STRIDE [[Desktop Installation]]). See the linked article for reference information.
 
In order for [[Stride Executable|stride]] to run your tests, the STRIDE database (.sidb) file that was produced as part of the target build must be accessible to the program via the host filesystem. This is trivial to accomplish when the target is built on the host computer (as when building and running tests off-target) or when the host and target computers are running the same operating system and are connected via LAN. But for dissimilar operating systems, you will need to mount the target filesystem on the host computer. (Many of our customers use [http://en.wikipedia.org/wiki/Samba_(software) Samba] to accomplish this.)


=== Target ===
=== Target ===
* Target transport configured
* Target transport configured
** TCP/IP over port 8000 is the default target transport. To apply other configurations, see [[Target_Integration#The_Host_Transport| Host Transport]]
* Target built with STRIDE library and some STRIDE source instrumentation (detials can be found [[Integration Overview|here]]). If any native test units have been written, these must be included in the build also.
* Target built with STRIDE library built in and one or more test cases
* Target app running <ref>If target is multi-process, both the target and the STRIDE I/O daemon process must be started.</ref>
* Target app running <ref>If target is multi-process, both the target and the STRIDE I/O daemon process must be started.</ref>


== Preparing to Run Your Tests ==
== Running Tests ==
Tests are executed on the target by running the program [[Stride Executable|stride]] on the host computer. See the linked article for reference information.
The following command line illustrates how to run some STRIDE tests without publishing results to [[STRIDE Test Space]].
 
We assume the following:
* We are testing against a target build that contains the following native code test units: myTest1, myTest2 and myTest3.
* I also want to run host based tests implemented in a perl test module, myScriptTests.pm.
* The target device is running, and is available on the LAN via TCP/IP at 192.168.0.53
 
The command line to run the desired tests would be: 
<pre>
stride --run "myTest1;myTest2;myTest3" --run myScriptTests.pm --database "/my/path/targetApp.sidb" --device TCP:192.168.0.53:8000
</pre>
 
A couple of things to note:
* If you are running tests of a shared location and others may be running tests using the same referenced database, you should specify a unique output file location (via the -o option) to prevent overwriting the output file.
* If you will be running many tests against a specific database and/or device, consider setting [[Stride_Executable#Environment_Variables|environment variables]] to the corresponding values, or put command line options into an options file (via the -O option).
* You can refer to the device address using a DNS name if desired (e.g. TCP:testcomputer:8000)
 
=== Running All Tests ===
By default, stride will not run any tests if <tt>--run</tt> options are not specified. A simple way to run ''all'' target based test units (tests implemented in native code on the device) is to specify the wildcard parameter to stride - specifically:
 
stride --database TestApp.sidb --device TCP:128.0.0.1:8000 --run "*"
 
This will cause all test units that have been captured in the STRIDE database to be executed.
 
There is no way to run ''all'' perl test modules since we don't capture information about these in the STRIDE database. However, if you organize your test modules in a directory hierarchy, the [[Stride_Runner|runner]] provides a convenient syntax for executing all test modules in a directory - for example:


In all cases,
stride --database TestApp.sidb --device TCP:128.0.0.1:8000 --run "path/to/my_directory"
* The stride executable must be able to read the STRIDE database (.sidb) file that corresponds to the target build


By default, tests are run in the order in which their corresponding SCL pragmas were seen by the [[s2scompile|STRIDE compiler]] (This can be overridden; see below.)
will recursively search ''my_directory'' for script test modules (identified by file extension) and execute each as it is found.


= Examples =
=== Running A Subset of Tests ===
The stride test runner allows you to specify a subset of the test units in an existing target build.


== Running STRIDE Diagnostics ==
For example, assume that you have an .sidb file produced from your target build that has many test units defined. You want to run only three of the test units to reproduce a bug, say. We'll assume that the test units you want to run are named ''MyTest1'', ''MyTest2'', and ''MyTest3''. Further, we'll assume that the environment variable <tt>[[Stride_Runner#Environment_Variables|STRIDE_DEVICE]]</tt> is set to reflect your device parameters so that the <tt>--device </tt> argument can be omitted.
S2 Technologies supplies a set of diagnostic tests that can be used to verify correct operation.


By building in the files srdiag.h and srdiag.c (located in the SDK/Runtime directory of each SDK) to your target application, these tests become available.
The following command line will run the three tests in the order shown, putting their results into the root test suite.


Assuming that:
stride --database TestApp.sidb --run /{MyTest1;MyTest2;MyTest3}
* your STRIDE database is named TestApp.sidb and resides in the current directory, and
* the corresponding target application is running on the host computer
the command line to run diagnostic tests is:


stride --database TestApp.sidb --device TCP:localhost:8000 --diagnostics
Or, if your test results are to be published in the root suite, you can use this simplified syntax:


=== Console Output ===
stride --database TestApp.sidb MyTest1 MyTest2 MyTest3
Information is written to the console while the test progresses (note that the link tests can take ~30 seconds), and a results summary is written at the conclusion of the test.


<pre>
You can automate the running of a subset of test units who's names match a text pattern using the stride runner's [[Listing Test Units]] capability and a small perl script as shown below.
Loading database...
 
Connecting to device...
<source lang="perl">
Diagnosing target application...
while( <> ) {
  runtime version: 4.1.01
    if( /myPrefix_*/) {
  link
        print "-r $_";
  payload fragmentation
    }
  runtime configuration
}
  stub-proxy deadlock
</source>
  target characteristics
Summary: 64 passed, 0 failed, 0 in progress, 0 not in use.
Disconnecting from device...
Saving result file...
</pre>


=== Detailed Output ===
The perl script reads from stdin and attempts to match the line to the regular expression <tt>myPrefix_</tt>. If a match is detected, the line is written to stdout prefixed with <tt>-r </tt>,
Detailed results output are also created and written to the local disk.


Since we did not specify an output file to stride above, the xml output is written by default to the directory containing the designated STRIDE database. The name of the file is taken from the database file name with the .sidb replaced by .xml.
If you save the perl script to a file named myTests.pl, you can automate the running of tests that match your prefix as follows:


Additionally, a companion .xsl file is downloaded and written alongside the xml file if you are connected to the Internet. If you open the xml file in a browser, the xsl stylesheet will be automatically applied to render html to the browser.
stride --list --database TestApp.sidb | perl myTests.pl > tests.txt
stride --database TestApp.sidb --options_file tests.txt


== Desktop Test Development ==
== Publishing Test Results ==
Useful for 'pre-flight' desktop testing as well as target debugging, the following command line runs the target tests without publishing results to [[STRIDE Test Space]].


We assume the following:
=== Saving Results to the Local Disk ===
* We are testing against a target build that contains Test Units that I don't want to run. (Perhaps they test code that I am not responsible for.)
When [[Stride Executable|stride]] is executed to run tests, the following files are written to the current directory. By default, they are named after the specified database. You can specify a different name and location by using the -o option when you run stride. If these files already exist, they are overwritten.
* The target device is running, and is available on the LAN via TCP/IP at 192.168.0.53
* I want to run only Test Units named myTest1, myTest2, and myTest3


The command line to run the desired tests would be: 
; ''[database_name]''.xml
: Raw xml test output.
; ''[database_name]''.xsl
: Stylesheet to format the xml file for viewing in a web browser. (''This file is automatically downloaded only if you are connected to the Internet''.)


stride -r "myTest1,myTest2,myTest3" --database "/my/path/targetApp.sidb" --device TCP:192.168.0.53:8000
=== Displaying Local Results Data ===
If you open the xml file in a browser, the xsl stylesheet (if present) will be automatically applied to the xml so that the data is rendered in html within the browser.


A couple of things to note:
If you are using '''Google Chrome''' please see [[Browser Compatibility]].
* If others may be running tests using referenced database, you should specify a unique output file location (via the -o option) to prevent overwriting the output file at the default location.
* If you will be running many tests against a specific database and/or device, consider setting [[Stride_Executable#Environment_Variables|environment variables]] to the corresponding values, or put command line options into an options file (via the -O option).
* You can refer to the device address using a DNS name if desired (e.g. TCP:testcomputer:8000)


== Desktop Testing with Publication to Test Space ==
=== Publishing Results to STRIDE Test Space ===
[[Stride Executable|stride]] can also be instructed to upload test results to [[STRIDE Test Space]].
=== Example: Desktop Testing with Publication to Test Space ===
This example demonstrates the running of specified target tests followed by publication of the results to [[STRIDE Test Space]].
This example demonstrates the running of specified target tests followed by publication of the results to [[STRIDE Test Space]].


Line 87: Line 101:
--database "/my/path/targetApp.sidb"
--database "/my/path/targetApp.sidb"
--device TCP:192.168.0.53:8000
--device TCP:192.168.0.53:8000
-r /(myTest1,myTest2, myTest3)
--run "/{myTest1;myTest2; myTest3}"
-u
--upload
--testspace https://mycompany.stridetestspace.com@username:password
--testspace username:password@mycompany.stridetestspace.com
--project "Super Repeater"
--project "Super Repeater"
--space "Input Processor"
--space "Input Processor"
-o myoutputfile.xml
--output myoutputfile.xml
</pre>
</pre>


The command line is then:
The command line is then:
  stride -O "myOptions.txt"
  stride --options_file "myOptions.txt"
 
'''Note:''' In order for publishing to succeed, the username/password must be correct and the project and space must already exist. If you are using TestSpace for the first time, you should check with your administrator about how to create projects and spaces.
 
== Publishing Pre-Existing Test Report Files ==
Stride.exe can be used to upload to Test Space one or more pre-existing report files only (without running tests).
 
To accomplish this specify the publishing-related parameters but do not specify the <tt>--device</tt> parameter or any <tt>--run</tt> parameters when you run stride. The file to be uploaded is specified by the <tt>--output</tt> parameter.
 
If you want aggregate more than one .xml file to a single Test Space result set, run stride once for each file to be uploaded, specifying the <tt>--upload</tt> parameter accordingly.
 
Note that stride will use any environment variables that are in effect, so if you have a non-empty value set for <tt>STRIDE_DEVICE</tt> it must be set to empty in your terminal session before upload-only will be performed. Similarly, environment variables STRIDE_TESTSPACE_URL, STRIDE_TESTSPACE_PROJECT, and STRIDE_TESTSPACE_SPACE will be used if non-empty. (These can be overridden on the command line.)
 
===Examples===
;Upload a single report file
<pre>
stride --testspace <nowiki>user:pwd@s2technologies.stridetestspace.com</nowiki> --project Sandbox --space "Tim Space" --name RSName --upload --output test.xml
</pre>
 
;Upload multiple report files to a single result set
:Run stride once for each file to be aggregated. Note argument to <tt>--upload</tt> parameter.
 
<pre>
stride --testspace <nowiki>user:pwd@s2technologies.stridetestspace.com</nowiki> --project Sandbox --space "Tim Space" --name RSName --upload start --output test1.xml
 
stride --testspace <nowiki>user:pwd@s2technologies.stridetestspace.com</nowiki> --project Sandbox --space "Tim Space" --name RSName --upload add --output test2.xml
 
stride --testspace <nowiki>user:pwd@s2technologies.stridetestspace.com</nowiki> --project Sandbox --space "Tim Space" --name RSName --upload add --output test3.xml
 
stride --testspace <nowiki>user:pwd@s2technologies.stridetestspace.com</nowiki> --project Sandbox --space "Tim Space" --name RSName --upload finish --output test4.xml
</pre>


== Continuous Integration Testing ==
==Other Resources==
A technique to organize tests into suites is shown [[Organizing Tests into Suites|here]].


TBD
For full details on stride command line parameters, please see [[STRIDE Runner]].


<hr/>
== Notes ==
=== Notes ===
<references/>
<references/>


[[Category:Test Units]]
[[Category:Running Tests]]

Latest revision as of 19:33, 6 July 2015

STRIDE Framework tests (script and native target implementations) are controlled by a host computer, physically connected to the target via a configurable communication channel (TCP/IP or serial port). This article describes some common usage patterns and presents several examples.

Prerequisites

Host

Tests are initiated on the host by running the program stride on the host computer (installed as part of STRIDE Desktop Installation). See the linked article for reference information.

In order for stride to run your tests, the STRIDE database (.sidb) file that was produced as part of the target build must be accessible to the program via the host filesystem. This is trivial to accomplish when the target is built on the host computer (as when building and running tests off-target) or when the host and target computers are running the same operating system and are connected via LAN. But for dissimilar operating systems, you will need to mount the target filesystem on the host computer. (Many of our customers use Samba to accomplish this.)

Target

  • Target transport configured
  • Target built with STRIDE library and some STRIDE source instrumentation (detials can be found here). If any native test units have been written, these must be included in the build also.
  • Target app running [1]

Running Tests

The following command line illustrates how to run some STRIDE tests without publishing results to STRIDE Test Space.

We assume the following:

  • We are testing against a target build that contains the following native code test units: myTest1, myTest2 and myTest3.
  • I also want to run host based tests implemented in a perl test module, myScriptTests.pm.
  • The target device is running, and is available on the LAN via TCP/IP at 192.168.0.53

The command line to run the desired tests would be:

stride --run "myTest1;myTest2;myTest3" --run myScriptTests.pm --database "/my/path/targetApp.sidb" --device TCP:192.168.0.53:8000

A couple of things to note:

  • If you are running tests of a shared location and others may be running tests using the same referenced database, you should specify a unique output file location (via the -o option) to prevent overwriting the output file.
  • If you will be running many tests against a specific database and/or device, consider setting environment variables to the corresponding values, or put command line options into an options file (via the -O option).
  • You can refer to the device address using a DNS name if desired (e.g. TCP:testcomputer:8000)

Running All Tests

By default, stride will not run any tests if --run options are not specified. A simple way to run all target based test units (tests implemented in native code on the device) is to specify the wildcard parameter to stride - specifically:

stride --database TestApp.sidb --device TCP:128.0.0.1:8000 --run "*"

This will cause all test units that have been captured in the STRIDE database to be executed.

There is no way to run all perl test modules since we don't capture information about these in the STRIDE database. However, if you organize your test modules in a directory hierarchy, the runner provides a convenient syntax for executing all test modules in a directory - for example:

stride --database TestApp.sidb --device TCP:128.0.0.1:8000 --run "path/to/my_directory"

will recursively search my_directory for script test modules (identified by file extension) and execute each as it is found.

Running A Subset of Tests

The stride test runner allows you to specify a subset of the test units in an existing target build.

For example, assume that you have an .sidb file produced from your target build that has many test units defined. You want to run only three of the test units to reproduce a bug, say. We'll assume that the test units you want to run are named MyTest1, MyTest2, and MyTest3. Further, we'll assume that the environment variable STRIDE_DEVICE is set to reflect your device parameters so that the --device argument can be omitted.

The following command line will run the three tests in the order shown, putting their results into the root test suite.

stride --database TestApp.sidb --run /{MyTest1;MyTest2;MyTest3}

Or, if your test results are to be published in the root suite, you can use this simplified syntax:

stride --database TestApp.sidb MyTest1 MyTest2 MyTest3

You can automate the running of a subset of test units who's names match a text pattern using the stride runner's Listing Test Units capability and a small perl script as shown below.

while( <> ) {
    if( /myPrefix_*/) {
        print "-r $_";
    }
}

The perl script reads from stdin and attempts to match the line to the regular expression myPrefix_. If a match is detected, the line is written to stdout prefixed with -r ,

If you save the perl script to a file named myTests.pl, you can automate the running of tests that match your prefix as follows:

stride --list --database TestApp.sidb | perl myTests.pl > tests.txt
stride --database TestApp.sidb --options_file tests.txt

Publishing Test Results

Saving Results to the Local Disk

When stride is executed to run tests, the following files are written to the current directory. By default, they are named after the specified database. You can specify a different name and location by using the -o option when you run stride. If these files already exist, they are overwritten.

[database_name].xml
Raw xml test output.
[database_name].xsl
Stylesheet to format the xml file for viewing in a web browser. (This file is automatically downloaded only if you are connected to the Internet.)

Displaying Local Results Data

If you open the xml file in a browser, the xsl stylesheet (if present) will be automatically applied to the xml so that the data is rendered in html within the browser.

If you are using Google Chrome please see Browser Compatibility.

Publishing Results to STRIDE Test Space

stride can also be instructed to upload test results to STRIDE Test Space.

Example: Desktop Testing with Publication to Test Space

This example demonstrates the running of specified target tests followed by publication of the results to STRIDE Test Space.

Here, we create an options file since the command line is getting very long. (We could put several of these option values in environment variables instead if desired.)

The option file is named myOptions.txt, is located in the current directory and contains the following text:

--database "/my/path/targetApp.sidb"
--device TCP:192.168.0.53:8000
--run "/{myTest1;myTest2; myTest3}"
--upload
--testspace username:password@mycompany.stridetestspace.com
--project "Super Repeater"
--space "Input Processor"
--output myoutputfile.xml

The command line is then:

stride --options_file "myOptions.txt"

Note: In order for publishing to succeed, the username/password must be correct and the project and space must already exist. If you are using TestSpace for the first time, you should check with your administrator about how to create projects and spaces.

Publishing Pre-Existing Test Report Files

Stride.exe can be used to upload to Test Space one or more pre-existing report files only (without running tests).

To accomplish this specify the publishing-related parameters but do not specify the --device parameter or any --run parameters when you run stride. The file to be uploaded is specified by the --output parameter.

If you want aggregate more than one .xml file to a single Test Space result set, run stride once for each file to be uploaded, specifying the --upload parameter accordingly.

Note that stride will use any environment variables that are in effect, so if you have a non-empty value set for STRIDE_DEVICE it must be set to empty in your terminal session before upload-only will be performed. Similarly, environment variables STRIDE_TESTSPACE_URL, STRIDE_TESTSPACE_PROJECT, and STRIDE_TESTSPACE_SPACE will be used if non-empty. (These can be overridden on the command line.)

Examples

Upload a single report file
stride --testspace user:pwd@s2technologies.stridetestspace.com --project Sandbox --space "Tim Space" --name RSName --upload --output test.xml
Upload multiple report files to a single result set
Run stride once for each file to be aggregated. Note argument to --upload parameter.
stride --testspace user:pwd@s2technologies.stridetestspace.com --project Sandbox --space "Tim Space" --name RSName --upload start --output test1.xml

stride --testspace user:pwd@s2technologies.stridetestspace.com --project Sandbox --space "Tim Space" --name RSName --upload add --output test2.xml

stride --testspace user:pwd@s2technologies.stridetestspace.com --project Sandbox --space "Tim Space" --name RSName --upload add --output test3.xml

stride --testspace user:pwd@s2technologies.stridetestspace.com --project Sandbox --space "Tim Space" --name RSName --upload finish --output test4.xml

Other Resources

A technique to organize tests into suites is shown here.

For full details on stride command line parameters, please see STRIDE Runner.

Notes

  1. If target is multi-process, both the target and the STRIDE I/O daemon process must be started.