Studio:Hello Stride Sample
Introduction
The purpose of this sample is to verify that STRIDE is installed and functioning correctly and the required prerequisites for STRIDE operation are met. The following content relates to the sample files and workspaces installed in %STRIDE_DIR%\Samples\HelloStride. This sample consists of a Visual Studio workspace for building an off-target simulator, sample test unit source code, and a STRIDE workspace for executing the test unit sample.
Prerequisites
Before starting, some prerequisites must be satisfied. For details and instructions, see Host Installation.
Specifically:
- STRIDE must be installed on the Windows PC to be used in the training, and any required licenses must be present.
- Active State Perl must be installed, and additional perl packages must be downloaded and installed. Note: when the sample workspace is executed, a script runs that verifies that the required Perl packages have been installed correctly.
- Microsoft Visual Studio 2005 or a later version must be installed. If you do not currently have any version of Visual Studio, we recommend that you install the current free (as in beer) version of Visual Studio Express.
Getting Started
To begin, open the Visual Studio Solution file in the sample directory. This solution (and corresponding project) were created for Visual Studio 2005. If you have a later version of Visual Studio installed, you should be able to open this solution and it will be automatically upgraded if necessary.
Once you have successfully opened the solution, rebuild it. The build process has custom STRIDE build rules integrated and will produce a STRIDE database, intercept module source files, and an off-target simulator application that incorporates the test unit source.
Once the build is complete, perform the following steps to run the test unit in the workspace:
- launch the off-target simulator, HelloStride.exe. This will run in a standard console window.
- open a command prompt window and change to this sample's directory.
- at the command prompt, run the command TestUnitRun.pl -v. This will execute all of the test units in the workspace and open a browser to display the results.
- quit the HelloStride.exe application by typing 'q' in its console window.
HelloStride Test Unit
Now that you have built the off-target simulator and executed the test unit it contains, you can take time to peruse the source and the corresponding results that was produced. The HelloStride sample defines a test unit, TestHelloStride, as a test function list that combines two simple target functions, tf_HelloStride_Pass and tf_HelloStride_Fail, both of which use STRIDE runtime APIs to set descriptions and add comments for their respective test cases. One of the test functions returns a value indicating a PASS status, and the other returns a FAIL status.
Test Unit Execution
This sample demonstrates two different techniques for executing the sample test unit.
Command Line Execution
Command line execution for test classes is done using the TestUnitRun utility. Here are several examples of specific syntax to execute test classes. All of these commands can be invoked from a standard command shell and the arguments shown assume that the commands are executed with the sample's directory as the starting directory. You must have your HelloStride.exe application running in order for the runner to be able to initiate a connection to the target simulator. In addition, you should verify that your %STRIDE_DIR%\bin\transport.cfg file is using the TCP transport to connect to port 8000 (these are the default settings when the product is installed).
Test unit execution with TestUnitRun.pl
The following command executes all of the test units found in the STRIDE database you have previously generated. For the purpose of this sample, since there is only one database, the -d parameter is not strictly needed, but we show it here for completeness.
TestUnitRun.pl -d HelloStride.sidb
When you run this command, you should see console output like:
Attempting connection using [Sockets (S2)] transport ... Connected to device. Initializing STRIDE database objects... Done. Running Test TestHelloStride... Disconnected from device. Test Results saved to C:\S2\Seaside\Samples\HelloStride\HelloStride.xml Test Report saved to C:\S2\Seaside\Samples\HelloStride\HelloStride.html *************************************************************************** Results Summary *************************************************************************** Passed: 1 Failed: 1 In Progress: 0 Not Applicable: 0 ...in 1 suites. ***************************************************************************
Workspace-Based Execution
We also provide a sample STRIDE workspace that demonstrates the use of script execution within STRIDE Studio. This workspace was created using WorkspaceSetup.pl and the WindowsTestApp framework. The setup and teardown folders provide basic infrastructure scripts that start and stop the simulator application (HelloStride.exe). In addition, the setup folder contains a script (VerifyEnv.pl) that verifies that the required Perl packages have been installed correctly. The script that drives the testing is in the workspace test folder. This folder contains a single script, RunTest.pl, that executes the sample test unit through the STRIDE AutoScript object's TestUnits collection. The script is essentially one line:
ascript.TestUnits.Item("TestHelloStride").Run();
Note that the test folder has the OnRunConnect property checked (to see this, select the folder and look for the property in the Properties panel in Studio.) When this property is true, the connection is established with the target simulator before the contents of the folder are executed. The order of the folders in the workspace here is important - the setup folder executes before the test folder, so the target simulator is started before the connection is established when the test folder runs.
Running the Test
- Run the workspace by clicking on the Run All toolbar button File:RunAll.png
- At the completion of the run, you will see text similar to the following written to the STRIDE Messages window:
Tests Complete *************************************************************************** Results Summary *************************************************************************** Passed: 1 Failed: 1 In Progress: 0 Not Applicable: 0 ...in 2 suites. *************************************************************************** Test Report created file://C:\S2\Seaside\Samples\HelloStride\HelloStride.html
Click on the Test Report hyperlink to display the html report in a web browser.