Building an Off-Target Test App: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
 
(40 intermediate revisions by 4 users not shown)
Line 1: Line 1:
== Introduction ==
== Prerequisite ==
This article guides you through building a test application ('''TestApp''') for the purpose of running sample code using the STRIDE [[Installation_Overview#Off-Target_Environment | Off-Target Environment]].  
This article guides you through building a test application ('''TestApp''') for the purpose of running sample code using the [[STRIDE Off-Target Environment]].  


It requires an installation of the STRIDE Framework package. If not installed, please see [[Desktop Installation]] for more information.
It requires an installation of the STRIDE Framework desktop package. If not installed, please see [[Desktop Installation]] for more information.  
 
== Host Toolchain ==
Please verify that your Host system contains one of the following compilers:
* For Windows Microsoft Visual Studio 2005 or later is required. If you don't already have Visual Studio, the free [http://en.wikipedia.org/wiki/Microsoft_Visual_Studio_Express Visual C++ Express] can be used (download [http://www.microsoft.com/express/download/#webInstall here]).
* For Linux the [http://en.wikipedia.org/wiki/GNU_Compiler_Collection GNU Compiler Collection] (included by default in almost all Linux distros) is required.


It also requires that your desktop contains one of the following '''compilers''':
* For Windows, Microsoft Visual Studio 2008 or later is required. If you don't already have Visual Studio, the free [http://en.wikipedia.org/wiki/Microsoft_Visual_Studio_Express Visual C++ Express] can be used (download [http://www.microsoft.com/express/download/#webInstall here]). <i>In case you have [http://www.cygwin.com Cygwin] installed, the [http://en.wikipedia.org/wiki/GNU_Compiler_Collection GNU Compiler Collection] could be used as an alternative.</i>
* For Linux and FreeBSD, the [http://en.wikipedia.org/wiki/GNU_Compiler_Collection GNU Compiler Collection] (included by default in almost all distros) is required.


== Building a TestApp ==
== Building a TestApp ==


=== SDK Makefile ===
=== SDK Makefile ===
The SDK Makefile is set up so that all <tt>.c</tt> <tt>.cpp</tt> and <tt>.h</tt> files found in the directory <tt>SDK/Windows/sample_src</tt> are included in the compile and link of the '''testapp''' target.
The SDK Makefile is set up so that all <tt>.c</tt> <tt>.cpp</tt> and <tt>.h</tt> files found in the directory <tt>SDK\Windows\sample_src</tt> (or <tt>SDK/Posix/sample_src</tt> for Linux) are included in the compile and link of the '''testapp''' target.


Further--as a pre-compilation step--any <tt>.h</tt> files found in <tt>sample_src</tt> are submitted to the [[STRIDE Build Tools]]. This will result in  
Further--as a pre-compilation step--any <tt>.h</tt> files found in <tt>sample_src</tt> are submitted to the [[STRIDE Build Tools]]. This will result in  
Line 23: Line 21:
=== Build Steps ===
=== Build Steps ===
To begin, be sure that TestApp is not running then perform the following steps:
To begin, be sure that TestApp is not running then perform the following steps:
 
 
====Linux====
NOTE: ''If you experience any build problem please make sure to read [[Troubleshooting Build Problems]] for possible resolution.''
 
====Linux/FreeBSD====
<ol>
<ol>
<li>Build the test app
<li>Build the test app
<source lang="bash">
<source lang="bash">
cd $STRIDE_DIR/SDK/Linux/src
cd $STRIDE_DIR/SDK/Posix/src
make testapp
make testapp
</source>
</source>
</li>
</li>
<li>The file <tt>$STRIDE_DIR/SDK/Linux/out/bin/TestApp</tt> will be produced
<li>Note that the following artifacts are produced by the build:
</li>
 
<li>Note also that the STRIDE database file <tt>$STRIDE_DIR/SDK/Linux/out/TestApp.sidb</tt> is also produced
;<tt>$STRIDE_DIR/SDK/Posix/out/bin/TestApp</tt>
: the test application
;<tt>$STRIDE_DIR/SDK/Posix/out/TestApp.sidb</tt>
: the STRIDE interface database file which contains metadata describing the interfaces remoted by the test app (along with other data)
</li>
</li>
</ol>
</ol>


====Windows====
====Windows====
NOTE: ''If you have [http://en.wikipedia.org/wiki/Cygwin Cygwin] installed and its <tt>bin</tt>  directory is on your path, see [[Troubleshooting Build Problems]].''
NOTE: ''In case you have [http://www.cygwin.com Cygwin] and [http://en.wikipedia.org/wiki/GNU_Compiler_Collection GNU Compiler Collection] installed and prefer to use it, please follow the build steps for Linux (see previous section) and ignore the one in here.''
 
<ol>
<ol>
<li>If using Microsoft Visual Studio, open a Visual Studio command prompt<ref>To open a Visual Studio Command prompt: Click the Start button, point to All Programs, Microsoft Visual Studio 200X, Visual Studio Tools, and then click Visual Studio 200X Command Prompt.</ref> to ensure that the compiler and linker are on your PATH.
<li>If using Microsoft Visual Studio, open a [http://msdn.microsoft.com/en-us/library/ms235639(v=vs.100).aspx Visual Studio Command Prompt] to ensure that the compiler and linker are on your PATH.
</li>
</li>
<li>Build the test app using the supplied GNU make. (You will get Makefile errors if you use the default make.)
<li>Build the test app using the supplied GNU make. (You will get Makefile errors if you use the default make.)
Line 49: Line 51:
..\bin\make testapp
..\bin\make testapp
</source>
</source>
</li>
<li>Note that the following artifacts are produced by the build:
<li>The file <tt>%STRIDE_DIR%\SDK\Windows\out\bin\TestApp.exe</tt> will be produced
 
</li>
;<tt>%STRIDE_DIR%\SDK\Windows\out\bin\TestApp.exe</tt>
<li>Note that the STRIDE database file <tt>%STRIDE_DIR%\SDK\Windows\out\TestApp.sidb</tt> is also produced
: the test application
;<tt>%STRIDE_DIR%\SDK\Windows\out\TestApp.sidb</tt>
: the STRIDE interface database file which contains metadata describing the interfaces remoted by the test app (along with other data)
</li>
</li>
</ol>
</ol>


'''Note:''' If you prefer to use Visual Studio to build/debug/run your testapp, we provide instructions [[Using_STRIDE_Rules_for_Visual_Studio|here]] about how to accomplish this.
NOTE: ''If you prefer to use Visual Studio to build/debug/run your testapp, we provide instructions [[STRIDE_Extensions_for_Visual_Studio|here]] about how to accomplish this.''


== Diagnostics ==
== Diagnostics ==
The test app we just built does not have any user tests in it. At this point it provides a starting point for test that we will subsequently add.


A set of diagnostic tests are always built into the generated TestApp executable. If desired (we recommend you to do so) you could run them by doing the following:
However, a set of diagnostic tests that verify operation of the STRIDE runtime itself are always built into the generated TestApp executable. If desired (we recommend you to do so) you could run them by doing the following:


<ol>
<ol>
<li>Invoke the TestApp. In order to see TestApp's output, we recommend that you manually open a new console (or Windows equivalent):  
<li>Invoke the TestApp. In order to see TestApp's output, we recommend that you manually run in a console window (or Windows equivalent):  
;Linux
;Linux
<source lang="bash">
<source lang="bash">
$STRIDE_DIR/SDK/Linux/out/bin/TestApp
$STRIDE_DIR/SDK/Posix/out/bin/TestApp
</source>
</source>
;Windows
;Windows
Line 78: Line 83:
--------------------------------------------------
--------------------------------------------------
STRIDE Test Console Application.
STRIDE Test Console Application.
Enter 'Q' to Quit.
Enter 'Ctrl+C' to Quit.
--------------------------------------------------
--------------------------------------------------
Listening on TCP port 8000
starting up...
starting up...
Listening on TCP port 8000
"_srThread" thread started.
"_srThread" thread started.
"stride" thread started.
"stride" thread started.
</pre>
</pre>
</li>
</li>
<li>From a console window, invoke <tt>[[STRIDE_Runner|stride]]</tt> as follows, to verify connectivity with the target app (or Windows equivalent):
<li>From a second console window, invoke <tt>[[STRIDE_Runner|stride]]</tt> as follows, to verify connectivity with the test app and STRIDE runtime operation:
<br/>
<br/>
;Linux
;Linux
<source lang="bash">
<source lang="bash">
stride --diagnostics --database=$STRIDE_DIR/SDK/Linux/out/TestApp.sidb --device=TCP:localhost:8000 --run="*"
stride --diagnostics --database="$STRIDE_DIR/SDK/Posix/out/TestApp.sidb" --device=TCP:localhost:8000 --run="*"
</source>
</source>
;Windows
;Windows
<source lang="dos">
<source lang="dos">
stride --diagnostics --database=%STRIDE_DIR%\SDK\Windows\out\TestApp.sidb --device=TCP:localhost:8000 --run="*"
stride --diagnostics --database="%STRIDE_DIR%\SDK\Windows\out\TestApp.sidb" --device=TCP:localhost:8000 --run="*"
</source>
</source>


Line 103: Line 108:
Loading database...
Loading database...
Connecting to device...
Connecting to device...
   runtime version: 4.3.0x
   runtime version: 5.x.yy
Executing diagnostics...
Executing diagnostics...
   test unit "Link"
   test unit "Link"
Line 127: Line 132:
</ol>
</ol>


== Samples ==


== TestIntro Sample ==
The initial desktop installation of STRIDE does not set up any source code (with the exception of a set of system diagnostic tests) for automatic inclusion in a test application. The [[Desktop Installation | desktop framework]] distribution, however, comes with a set of [[Samples_Overview | Samples]].


The initial desktop installation of STRIDE does not set up any source code (with the exception of a set of system diagnostic tests) for automatic inclusion in a test application. The [[Desktop Installation | desktop framework]] distribution, however, comes with a set of [[Samples_Overview | Samples]].  
To demonstrate how to build a sample, will will add the [[Test Intro Sample]] that provide an overview of STRIDE testing techniques. For an overview from a C++ perspective, please see [[Test Intro Cpp Sample]].
 
The following steps are applicable for '''all''' [[Samples_Overview | Samples]].


In this step, will will add a set of sample tests that provide an overview of STRIDE testing techniques. The [[Test Intro Sample]] tests are described in the linked article. For an overview from a C++ perspective, please see [[Test Intro Cpp Sample]].
To begin, be sure that TestApp is not running, then copy the <tt>.c</tt> and <tt>.h</tt> files found in <tt>Samples/test_in_c_cpp/TestIntro</tt> to <tt>SDK/Windows/sample_src</tt> (or <tt>SDK/Posix/sample_src</tt> for Linux).


To begin, be sure that TestApp is not running, then copy the <tt>.c</tt> and <tt>.h</tt> files found in <tt>Samples/test_in_c_cpp/TestIntro</tt> to <tt>SDK/Windows/sample_src</tt> (or <tt>SDK/Linux/sample_src</tt> for Linux).  
'''''Note:''' Only files in the sample_src directory will be picked up by the makefile. Files in any subdirectories will be igored.
''


Once the files have been copied to <tt>sample_src</tt>, simply build TestApp as described above. Note if you had previous copied other sample source to this directory, you should decide whether to remove those files first. When you complete the test app build, any source that is in this directory at the time of build will be included in the test app.
Once the files have been copied to <tt>sample_src</tt>, simply build TestApp as described above. Note if you had previously copied other sample source to this directory, you should decide whether to remove those files first. When you complete the test app build, any source that is in this directory at the time of build will be included in the test app.


=== Running the Tests ===
=== Running the Tests ===
Line 153: Line 162:
A couple of things to note:
A couple of things to note:
* If you setup an [[STRIDE_Runner#Environment_Variables | environment variable]] for the '''device''' option than it is not required in the option file. Note: Command line options override environment variables.   
* If you setup an [[STRIDE_Runner#Environment_Variables | environment variable]] for the '''device''' option than it is not required in the option file. Note: Command line options override environment variables.   
* You may want to create a text file named ''RunTestIntro.txt'' in the <tt>SDK\Windows</tt> (or <tt>SDK/Linux</tt> for Linux) directory as an option file to submit to <tt>stride</tt>.
* You may want to create a text file named ''RunTestIntro.txt'' in the <tt>SDK\Windows</tt> (or <tt>SDK/Posix</tt> for Linux) directory as an option file to submit to <tt>stride</tt>.
* ''stride --help'' provides [[STRIDE_Runner#Options | options information]]
* ''stride --help'' provides [[STRIDE_Runner#Options | options information]]


If you haven't done so already, start <tt>TestApp</tt> running in a separate console window.
If you haven't done so already, start <tt>TestApp</tt> running in a separate console window.


Now run stride as follows (starting from the <tt>SDK\Windows</tt> or <tt>SDK/Linux</tt> directory):
Now run stride as follows (starting from the <tt>SDK\Windows</tt> or <tt>SDK/Posix</tt> directory):


<source lang="bash">
<source lang="bash">
stride -O RunTestIntro.txt --run="*"
stride --options_file RunTestIntro.txt --run="*"
</source>
</source>


Line 187: Line 196:


=== Interpreting Results ===
=== Interpreting Results ===
If you're interested in the details of the tests, please see to the test documentation contained in the test report. Open <tt>TestApp.xml</tt> in your browser; this file is created in the directory from which you ran <tt>stride</tt>. If you were connected to the Internet when you ran the tests, the TestApp.xsl file is also generated in the directory. By opening TestApp.xml in a web browser, the xsl is automatically applied to create html in the browser.
Open '''TestApp.html''' in your browser; this file is created in the directory from which you ran '''stride''' (or the directory via the <tt>--output</tt> command line option).  
 
If you're interested in the details of the tests, please see to the test documentation contained in the test report.


==Notes==
==Notes==

Latest revision as of 19:00, 8 September 2015

Prerequisite

This article guides you through building a test application (TestApp) for the purpose of running sample code using the STRIDE Off-Target Environment.

It requires an installation of the STRIDE Framework desktop package. If not installed, please see Desktop Installation for more information.

It also requires that your desktop contains one of the following compilers:

Building a TestApp

SDK Makefile

The SDK Makefile is set up so that all .c .cpp and .h files found in the directory SDK\Windows\sample_src (or SDK/Posix/sample_src for Linux) are included in the compile and link of the testapp target.

Further--as a pre-compilation step--any .h files found in sample_src are submitted to the STRIDE Build Tools. This will result in

  • the detection of test pragmas used to declare Test Units in these .h files
  • the detection of function pragmas used to declare remoting of functions also found in .h files
  • the inclusion of metadata into the sidb file created
  • the generation of an Intercept Module required for executing tests

Build Steps

To begin, be sure that TestApp is not running then perform the following steps:

NOTE: If you experience any build problem please make sure to read Troubleshooting Build Problems for possible resolution.

Linux/FreeBSD

  1. Build the test app
    cd $STRIDE_DIR/SDK/Posix/src
    make testapp
    
  2. Note that the following artifacts are produced by the build:
    $STRIDE_DIR/SDK/Posix/out/bin/TestApp
    the test application
    $STRIDE_DIR/SDK/Posix/out/TestApp.sidb
    the STRIDE interface database file which contains metadata describing the interfaces remoted by the test app (along with other data)

Windows

NOTE: In case you have Cygwin and GNU Compiler Collection installed and prefer to use it, please follow the build steps for Linux (see previous section) and ignore the one in here.

  1. If using Microsoft Visual Studio, open a Visual Studio Command Prompt to ensure that the compiler and linker are on your PATH.
  2. Build the test app using the supplied GNU make. (You will get Makefile errors if you use the default make.)
    cd %STRIDE_DIR%\SDK\Windows\src
    ..\bin\make testapp
    
  3. Note that the following artifacts are produced by the build:
    %STRIDE_DIR%\SDK\Windows\out\bin\TestApp.exe
    the test application
    %STRIDE_DIR%\SDK\Windows\out\TestApp.sidb
    the STRIDE interface database file which contains metadata describing the interfaces remoted by the test app (along with other data)

NOTE: If you prefer to use Visual Studio to build/debug/run your testapp, we provide instructions here about how to accomplish this.

Diagnostics

The test app we just built does not have any user tests in it. At this point it provides a starting point for test that we will subsequently add.

However, a set of diagnostic tests that verify operation of the STRIDE runtime itself are always built into the generated TestApp executable. If desired (we recommend you to do so) you could run them by doing the following:

  1. Invoke the TestApp. In order to see TestApp's output, we recommend that you manually run in a console window (or Windows equivalent):
    Linux
    $STRIDE_DIR/SDK/Posix/out/bin/TestApp
    
    Windows
    %STRIDE_DIR%\SDK\Windows\out\bin\TestApp
    

    (...or launch from the file explorer)

  2. Note TestApp's output upon startup.
    --------------------------------------------------
    STRIDE Test Console Application.
    Enter 'Ctrl+C' to Quit.
    --------------------------------------------------
    Listening on TCP port 8000
    starting up...
    "_srThread" thread started.
    "stride" thread started.
    
  3. From a second console window, invoke stride as follows, to verify connectivity with the test app and STRIDE runtime operation:
    Linux
    stride --diagnostics --database="$STRIDE_DIR/SDK/Posix/out/TestApp.sidb" --device=TCP:localhost:8000 --run="*"
    
    Windows
    stride --diagnostics --database="%STRIDE_DIR%\SDK\Windows\out\TestApp.sidb" --device=TCP:localhost:8000 --run="*"
    

    As the tests run you will see output in both the TestApp (target) and stride (host) console windows.

    The host console window output is shown here:

    Loading database...
    Connecting to device...
      runtime version: 5.x.yy 
    Executing diagnostics...
      test unit "Link"
        Loopback ............
        Payload Fragmentation
        Stub-Proxy Deadlock
        Target Characteristics
        > 4 passed, 0 failed, 0 in progress, 0 not in use.
      test unit "Stat"
        > 2 passed, 0 failed, 0 in progress, 0 not in use.
      test unit "Time"
        > 2 passed, 0 failed, 0 in progress, 0 not in use.
      --------------------------------------------------------------------- 
      Summary: 8 passed, 0 failed, 0 in progress, 0 not in use.
    
    Disconnecting from device...
    Saving result file...
    
  4. Note the Summary results shown in the host output; all in use tests should pass.
  5. To exit TestApp, give the target window focus and enter Ctrl-C (or 'q' under Windows).

Samples

The initial desktop installation of STRIDE does not set up any source code (with the exception of a set of system diagnostic tests) for automatic inclusion in a test application. The desktop framework distribution, however, comes with a set of Samples.

To demonstrate how to build a sample, will will add the Test Intro Sample that provide an overview of STRIDE testing techniques. For an overview from a C++ perspective, please see Test Intro Cpp Sample.

The following steps are applicable for all Samples.

To begin, be sure that TestApp is not running, then copy the .c and .h files found in Samples/test_in_c_cpp/TestIntro to SDK/Windows/sample_src (or SDK/Posix/sample_src for Linux).

Note: Only files in the sample_src directory will be picked up by the makefile. Files in any subdirectories will be igored.

Once the files have been copied to sample_src, simply build TestApp as described above. Note if you had previously copied other sample source to this directory, you should decide whether to remove those files first. When you complete the test app build, any source that is in this directory at the time of build will be included in the test app.

Running the Tests

Here we will run all tests in the TestApp.sidb database.[1]

  1. Run the build above TestApp in a console window.
  2. Invoke stride in a separate console window (different from the running TestApp) -- as shown below and verify Summary results.

Here are the command line parameters that we will submit to stride

--database ./out/TestApp.sidb 
--device TCP:localhost:8000

A couple of things to note:

  • If you setup an environment variable for the device option than it is not required in the option file. Note: Command line options override environment variables.
  • You may want to create a text file named RunTestIntro.txt in the SDK\Windows (or SDK/Posix for Linux) directory as an option file to submit to stride.
  • stride --help provides options information

If you haven't done so already, start TestApp running in a separate console window.

Now run stride as follows (starting from the SDK\Windows or SDK/Posix directory):

stride --options_file RunTestIntro.txt --run="*"

The output should look like this:

Loading database...
Connecting to device...
Executing...
  test unit "s2_testintro_flist"
    > 2 passed, 1 failed, 0 in progress, 0 not in use.
  test unit "s2_testintro_cclass"
    > 1 passed, 1 failed, 0 in progress, 0 not in use.
  test unit "s2_testintro_testdoubles"
    > 3 passed, 0 failed, 0 in progress, 0 not in use.
  test unit "s2_testintro_testpoints"
    > 3 passed, 0 failed, 0 in progress, 0 not in use.
  test unit "s2_testintro_parameters"
    > 2 passed, 0 failed, 0 in progress, 0 not in use.
  --------------------------------------------------------------------- 
  Summary: 11 passed, 2 failed, 0 in progress, 0 not in use.

Disconnecting from device...
Saving result file...

Interpreting Results

Open TestApp.html in your browser; this file is created in the directory from which you ran stride (or the directory via the --output command line option).

If you're interested in the details of the tests, please see to the test documentation contained in the test report.

Notes

  1. Note that the S2 diagnostic tests are treated separately, and are not run unless the --diagnostics option is specified to stride.