Difference between revisions of "STRIDE Extensions for Visual Studio"

From STRIDE Wiki
Jump to: navigation, search
(Prerequisites)
 
(37 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
== Introduction ==  
 
== Introduction ==  
If you are using the STRIDE Framework for Windows, an alternative to the [[Building_an_Off-Target_Test_App | standard method]] of building test apps (using ''make'') is to use the STRIDE Extensions for Visual Studio and integrate directly into your existing Visual Studio C/C++ project.
+
The Stride Extensions for Visual Studio can be used to integrate directly into your existing Visual Studio C/C++ project.
  
 
== Prerequisites ==
 
== Prerequisites ==
 
* Visual Studio 2008 or later (an express distribution is fine)
 
* Visual Studio 2008 or later (an express distribution is fine)
* a recent version of the STRIDE Framework [[Desktop_Installation#Windows_Installation|installed]] including a recent version of Perl
+
* a recent version of the Stride installed
* a static library version of the runtime built using the source files included in the [[Windows_SDK | Windows SDK]]:
+
* a static library version of the runtime built using the source files included in the [[Windows_SDK | Windows SDK]]
 +
** to build the library open a [http://msdn.microsoft.com/en-us/library/ms235639(v=vs.100).aspx Visual Studio Command Prompt] and do as follows:
 
<pre>
 
<pre>
 
> md %STRIDE_DIR%\SDK\Windows\lib
 
> md %STRIDE_DIR%\SDK\Windows\lib
 
> cd %STRIDE_DIR%\SDK\Windows\src
 
> cd %STRIDE_DIR%\SDK\Windows\src
 
> ..\bin\make clean
 
> ..\bin\make clean
> ..\bin\make
+
> ..\bin\make RTSINGLEPROC=0
 
> copy %STRIDE_DIR%\SDK\Windows\out\lib\stride-x86-Windows_NT.lib %STRIDE_DIR%\SDK\Windows\lib\stride.lib
 
> copy %STRIDE_DIR%\SDK\Windows\out\lib\stride-x86-Windows_NT.lib %STRIDE_DIR%\SDK\Windows\lib\stride.lib
 
> ..\bin\make clean
 
> ..\bin\make clean
> ..\bin\make DEBUG=1
+
> ..\bin\make RTSINGLEPROC=0 DEBUG=1
 
> copy %STRIDE_DIR%\SDK\Windows\out\lib\stride-x86-Windows_NT-d.lib %STRIDE_DIR%\SDK\Windows\lib\stride-d.lib
 
> copy %STRIDE_DIR%\SDK\Windows\out\lib\stride-x86-Windows_NT-d.lib %STRIDE_DIR%\SDK\Windows\lib\stride-d.lib
 
</pre>
 
</pre>
* existing C/C++ Visual Studio project (you can easily create a new one, e.g. "Win32 Console Application", by using the project wizard provided with Visual Studio)
+
* an existing C/C++ Visual Studio project  
 +
** or you can easily create a new one, e.g. "Win32 Console Application", by using the project wizard provided within Visual Studio.
  
 
== Installation ==
 
== Installation ==
STRIDE Extensions need to be added to any project that is to generate harnessing code (i.e. a project that includes header files with one or more [http://www.stridewiki.com/index.php?title=Test_Unit_Pragmas scl pragmas].)
+
STRIDE Extensions need to be added to any project that is to generate ''intercept module''.  
  
=== Visual Studio 2010 ===
+
=== Visual Studio 2010 (or newer) ===
* Right click on the project in the '''Solution Exporer''' window and choose '''Build Customizations…''' from the menu that is displayed.  
+
* Right click on the project in the '''Solution Explorer''' window and choose '''Build Customizations…''' from the menu that is displayed.  
* In the dialog that is then displayed, click '''Find Existing…''' and select '''$(STRIDE_DIR)\SDK\Windows\settigns\stride.targets''' (if asked, say “No” to adding to standard “Build Customizations Search Path”)
+
* In the dialog that is displayed, click '''Find Existing…''' and select '''$(STRIDE_DIR)\SDK\Windows\settings\stride.targets''' (if asked, say “No” to adding to standard “Build Customizations Search Path”)
 
* Make sure the check box next to '''stride''' is ''enabled''.
 
* Make sure the check box next to '''stride''' is ''enabled''.
  
 
=== Visual Studio 2008 ===
 
=== Visual Studio 2008 ===
<u>''NOTE:''</u> ''Due to limitations in Visual Studio 2008 the STRIDE integration is much more complicated compared to version 2010. We strongly recommend you to upgrade to Visual Studio 2010.''
+
<u>''NOTE:''</u> ''Due to limitations in Visual Studio 2008 the STRIDE integration is much more complicated compared to new versions. We recommend upgrading to Visual Studio 2010 or newer.''
  
* Right click on the project in the '''Solution Exporer''' window and choose '''Build Custom Build Rules...''' from the menu that is displayed.  
+
* Right click on the project in the '''Solution Explorer''' window and choose '''Build Custom Build Rules...''' from the menu that is displayed.  
* In the dialog that is then displayed, click '''Find Existing…''' and select '''$(STRIDE_DIR)\SDK\Windows\settigns\stride.rules''' (if asked, say “No” to adding to standard “Rule Files Search Path”)
+
* In the dialog that is displayed, click '''Find Existing…''' and select '''$(STRIDE_DIR)\SDK\Windows\settings\stride.rules''' (if asked, say “No” to adding to standard “Rule Files Search Path”)
 
* Make sure the check box next to '''STRIDE Rules''' is ''enabled''.
 
* Make sure the check box next to '''STRIDE Rules''' is ''enabled''.
  
 
== Configuration ==
 
== Configuration ==
The STRIDE Extensions execute a set of pre-build steps on your header files that generate test harnessing code that is later compiled in your application. In a matter for that to properly work your header files' and global project settings need to be adjusted.  
+
The STRIDE Extensions execute a set of pre-build steps on your header files that generate test harnessing code that is later compiled in your application. To support the pre-build steps your global project settings require updating.  
  
=== Sort Out Header Files ===
+
=== Project Properties ===
Every header file in the project that has one or more "scl pragmas" will cause harnessing code to be generated if it is input to the STRIDE. (Other header files can be harmlessly input to the STRIDE, but this will only have the effect of longer compile times.)
+
Adjust your project properties to compile and link with the STRIDE Runtime and generated test harnessing code.  
 
 
For each header file to be used as input to the STRIDE rules:
 
* Right click on the header file in the '''Solution Exporer''' window and choose '''Properties''' from the menu that is displayed.
 
* From the properties dialog, select '''Configuration Properties | General''' from the tree view in the left pane.
 
* From the right pane, set the '''Item Type''' property to '''STRIDE Compile-Instrument'''.
 
 
 
If there are any header files that contain no "scl pragmas", then we recommend disabling the build step for these files. This could be done in the last step from above by setting the '''Item Type''' to '''C/C++ header''' or by setting '''Exclude From Build''' property to '''Yes'''.
 
 
 
<u>''NOTE:''</u> ''As you add more header source files to the project, they will be automatically processed by STRIDE unless you explicitly disable that as specified above.''
 
 
 
=== Adjust Project Properties ===
 
Adjust your project properties to compile and link with the STRIDE Runtime and generated test harness.  
 
  
 
<u>''NOTE:''</u> ''Make sure to apply the following changes to all project's configurations (e.g. Debug, Release).''
 
<u>''NOTE:''</u> ''Make sure to apply the following changes to all project's configurations (e.g. Debug, Release).''
  
 
==== C/C++ Properties ====
 
==== C/C++ Properties ====
* Right click on the project in the '''Solution Exporer''' window and choose '''Properties''' from the menu that is displayed.  
+
* Right click on the project in the '''Solution Explorer''' window and choose '''Properties''' from the menu that is displayed.  
 
* From the properties dialog, select '''Configuration Properties | C/C++ | General''' from the tree view in the left pane.  
 
* From the properties dialog, select '''Configuration Properties | C/C++ | General''' from the tree view in the left pane.  
 
* From the right pane, add to '''Additional Include Directories''' the following:
 
* From the right pane, add to '''Additional Include Directories''' the following:
Line 72: Line 62:
  
 
==== Linker Properties ====
 
==== Linker Properties ====
* Right click on the project in the '''Solution Exporer''' window and choose '''Properties''' from the menu that is displayed.  
+
* Right click on the project in the '''Solution Explorer''' window and choose '''Properties''' from the menu that is displayed.  
 
* From the properties dialog, select '''Configuration Properties | Linker | General''' from the tree view in the left pane.  
 
* From the properties dialog, select '''Configuration Properties | Linker | General''' from the tree view in the left pane.  
 
* From the right pane, add to '''Additional Library Directories''' the following:
 
* From the right pane, add to '''Additional Library Directories''' the following:
 +
;If you built stride.lib from the makefile in the SDK
 
<pre>
 
<pre>
 
$(STRIDE_DIR)\SDK\Windows\lib
 
$(STRIDE_DIR)\SDK\Windows\lib
 
</pre>
 
</pre>
 +
 
* Select '''Configuration Properties | Linker | Input''' from the tree view in the left pane.  
 
* Select '''Configuration Properties | Linker | Input''' from the tree view in the left pane.  
 
* From the right pane, add to '''Additional Dependencies''' the following:
 
* From the right pane, add to '''Additional Dependencies''' the following:
 
<pre>
 
<pre>
stride.lib (or stride-d.lib for Debug)
+
stride.lib
 
ws2_32.lib
 
ws2_32.lib
 
</pre>
 
</pre>
 +
<u>''NOTE:''</u> ''For Debug configuration please specify "stride-d.lib".''
 +
 +
=== Sort Out Header Files ===
 +
Every header file in the project that has [[Test Pragmas]] will cause harnessing code to be generated when processed by the STRIDE compiler. (Other non-stride header files can also be processed by the STRIDE compiler, but this only results in longer compile times.)
 +
 +
For each header file to be used as input to the STRIDE rules:
 +
* Right click on the header file in the '''Solution Explorer''' window and choose '''Properties''' from the menu that is displayed.
 +
* From the properties dialog, select '''Configuration Properties | General''' from the tree view in the left pane.
 +
* From the right pane, set the '''Item Type''' property to '''STRIDE Compile-Instrument'''.
 +
 +
If there are any header files that contain no test code declarations, then we recommend disabling the build step for these files. This could be done in the last step from above by setting the '''Item Type''' to '''C/C++ header''' or by setting '''Exclude From Build''' property to '''Yes'''. Remember as you add more header source files to the project, they will be automatically processed by STRIDE unless you explicitly disable.
 +
 +
=== STRIDE Compile-Instrument Properties ===
 +
 +
==== Visual Studio 2010 (or newer) ====
  
==== STRIDE Compile-Instrument Properties ====
 
===== Visual Studio 2010 =====
 
 
The default settings are usually sufficient so you don't need to make any changes.
 
The default settings are usually sufficient so you don't need to make any changes.
  
 
When you build your project, notice that:
 
When you build your project, notice that:
* The STRIDE buiild tools automatically run and generate STRIDE database (.sidb) and intercept module (IM) source files. By default, these use '''$(TargetName)''' as their base names, and the files are written to the '''$(ProjectDir)''' directory.
+
* The STRIDE build tools automatically run and generate a STRIDE database (.sidb) file and intercept module (IM) source files. By default the names are derived from '''$(TargetName)''', and the associated files are written to the '''$(ProjectDir)''' directory.
 
* The IM source, ''$(TargetName)IM.cpp'', is automatically compiled and linked along with your other project sources.
 
* The IM source, ''$(TargetName)IM.cpp'', is automatically compiled and linked along with your other project sources.
 +
 +
If you desire to change the ''Database Name'' and/or the ''Intercept Module Name'' use the following steps:
 +
* Right click on the project in the '''Solution Explorer''' window and choose '''Properties''' from the menu that is displayed.
 +
* From the properties dialog, select '''Configuration Properties | STRIDE Compile-Instrument'''
 +
* Update '''Database Name''' and/or the '''Intercept Module Name''' right pane values as desired.
 +
 +
<u>''NOTE:''</u> ''If you do not see '''STRIDE Compile-Instrument''' try [[#Sort_Out_Header_Files | adding a header file]] to your project.''
  
 
The default harness generation assumes STUB settings for all captured functions. If you require different settings for any of your interfaces, you should create a text file containing the [[S2sinstrument#Options|additional settings]] and specify it as follows:
 
The default harness generation assumes STUB settings for all captured functions. If you require different settings for any of your interfaces, you should create a text file containing the [[S2sinstrument#Options|additional settings]] and specify it as follows:
Line 101: Line 113:
 
</pre>
 
</pre>
  
===== Visual Studio 2008 =====
+
==== Visual Studio 2008 ====
 
* Right click on the project in the '''Solution Exporer''' window and choose '''Properties''' from the menu that is displayed.  
 
* Right click on the project in the '''Solution Exporer''' window and choose '''Properties''' from the menu that is displayed.  
 
* From the properties dialog, select '''Configuration Properties | STRIDE Compile-Instrument | Compile''' from the tree view in the left pane.  
 
* From the properties dialog, select '''Configuration Properties | STRIDE Compile-Instrument | Compile''' from the tree view in the left pane.  
Line 113: Line 125:
 
* From the '''$(ProjectDir)''' directory add the generated IM source file - '''strideIM.cpp''', '''strideIM.h''' and '''strideIMEntry.h''' - to your project.  
 
* From the '''$(ProjectDir)''' directory add the generated IM source file - '''strideIM.cpp''', '''strideIM.h''' and '''strideIMEntry.h''' - to your project.  
 
** For '''strideIM.cpp''' make sure to set its '''Create/Use Precompiled Header''' property to '''Not Using...'''.
 
** For '''strideIM.cpp''' make sure to set its '''Create/Use Precompiled Header''' property to '''Not Using...'''.
** For '''strideIM.h''' and '''strideIMEntry.h''' make sure to set their '''Excluded From Build''' property to '''Yes''' as specified [STRIDE_Extensions_for_Visual_Studio#Sort_Out_Header_Files|above]].
+
** For '''strideIM.h''' and '''strideIMEntry.h''' make sure to set their '''Excluded From Build''' property to '''Yes''' as specified [[#Sort_Out_Header_Files|above]].
 
* Rebuild your project and resolve any compiler errors/warnings.
 
* Rebuild your project and resolve any compiler errors/warnings.
  
Line 126: Line 138:
 
<u>''NOTE:''</u> ''As you add sources, you will likely also need to add Additional Includes and Preprocessor Defines to the project's STRIDE Compile-Instrument settings in order to successfully build.''
 
<u>''NOTE:''</u> ''As you add sources, you will likely also need to add Additional Includes and Preprocessor Defines to the project's STRIDE Compile-Instrument settings in order to successfully build.''
  
=== Update Your Startup ===
+
== Update Your Startup ==
Update your application's main function to initialize the STRIDE subsystem as described in [[Windows_SDK#Target_Integration | this article]]. You can use the provided <tt>$(STRIDE_DIR)\SDK\Windows\src\TestApp.c</tt> as a reference.
 
  
[[Category: Installation]]
+
Update your application's main function to initialize the STRIDE subsystem as described in [[Windows_SDK#Target_Integration | this article]]. <u>''Note''</u> ''that the sample code assumes you have generated your Intercept Module with a name of '''myintercept'''. Make sure to replace any reference to that token in the code to the name you  [[#STRIDE_Compile-Instrument_Properties | chose above]].''

Latest revision as of 13:32, 7 January 2016

Introduction

The Stride Extensions for Visual Studio can be used to integrate directly into your existing Visual Studio C/C++ project.

Prerequisites

  • Visual Studio 2008 or later (an express distribution is fine)
  • a recent version of the Stride installed
  • a static library version of the runtime built using the source files included in the Windows SDK
> md %STRIDE_DIR%\SDK\Windows\lib
> cd %STRIDE_DIR%\SDK\Windows\src
> ..\bin\make clean
> ..\bin\make RTSINGLEPROC=0
> copy %STRIDE_DIR%\SDK\Windows\out\lib\stride-x86-Windows_NT.lib %STRIDE_DIR%\SDK\Windows\lib\stride.lib
> ..\bin\make clean
> ..\bin\make RTSINGLEPROC=0 DEBUG=1
> copy %STRIDE_DIR%\SDK\Windows\out\lib\stride-x86-Windows_NT-d.lib %STRIDE_DIR%\SDK\Windows\lib\stride-d.lib
  • an existing C/C++ Visual Studio project
    • or you can easily create a new one, e.g. "Win32 Console Application", by using the project wizard provided within Visual Studio.

Installation

STRIDE Extensions need to be added to any project that is to generate intercept module.

Visual Studio 2010 (or newer)

  • Right click on the project in the Solution Explorer window and choose Build Customizations… from the menu that is displayed.
  • In the dialog that is displayed, click Find Existing… and select $(STRIDE_DIR)\SDK\Windows\settings\stride.targets (if asked, say “No” to adding to standard “Build Customizations Search Path”)
  • Make sure the check box next to stride is enabled.

Visual Studio 2008

NOTE: Due to limitations in Visual Studio 2008 the STRIDE integration is much more complicated compared to new versions. We recommend upgrading to Visual Studio 2010 or newer.

  • Right click on the project in the Solution Explorer window and choose Build Custom Build Rules... from the menu that is displayed.
  • In the dialog that is displayed, click Find Existing… and select $(STRIDE_DIR)\SDK\Windows\settings\stride.rules (if asked, say “No” to adding to standard “Rule Files Search Path”)
  • Make sure the check box next to STRIDE Rules is enabled.

Configuration

The STRIDE Extensions execute a set of pre-build steps on your header files that generate test harnessing code that is later compiled in your application. To support the pre-build steps your global project settings require updating.

Project Properties

Adjust your project properties to compile and link with the STRIDE Runtime and generated test harnessing code.

NOTE: Make sure to apply the following changes to all project's configurations (e.g. Debug, Release).

C/C++ Properties

  • Right click on the project in the Solution Explorer window and choose Properties from the menu that is displayed.
  • From the properties dialog, select Configuration Properties | C/C++ | General from the tree view in the left pane.
  • From the right pane, add to Additional Include Directories the following:
$(STRIDE_DIR)\SDK\Runtime
$(STRIDE_DIR)\SDK\Windows\src
  • Select Configuration Properties | C/C++ | Preprocessor from the tree view in the left pane.
  • From the right pane, add to Preprocessor Definitions the following:
STRIDE_ENABLED
STRIDE_STATIC
srCOMPLEX_TARGET
  • Select Configuration Properties | C/C++ | Code Generation from the tree view in the left pane.
  • From the right pane, set Runtime Library to Multi-threaded DLL (/MD) (or Multi-threaded Debug DLL (/MDd) for Debug configuration).

Linker Properties

  • Right click on the project in the Solution Explorer window and choose Properties from the menu that is displayed.
  • From the properties dialog, select Configuration Properties | Linker | General from the tree view in the left pane.
  • From the right pane, add to Additional Library Directories the following:
If you built stride.lib from the makefile in the SDK
$(STRIDE_DIR)\SDK\Windows\lib
  • Select Configuration Properties | Linker | Input from the tree view in the left pane.
  • From the right pane, add to Additional Dependencies the following:
stride.lib
ws2_32.lib

NOTE: For Debug configuration please specify "stride-d.lib".

Sort Out Header Files

Every header file in the project that has Test Pragmas will cause harnessing code to be generated when processed by the STRIDE compiler. (Other non-stride header files can also be processed by the STRIDE compiler, but this only results in longer compile times.)

For each header file to be used as input to the STRIDE rules:

  • Right click on the header file in the Solution Explorer window and choose Properties from the menu that is displayed.
  • From the properties dialog, select Configuration Properties | General from the tree view in the left pane.
  • From the right pane, set the Item Type property to STRIDE Compile-Instrument.

If there are any header files that contain no test code declarations, then we recommend disabling the build step for these files. This could be done in the last step from above by setting the Item Type to C/C++ header or by setting Exclude From Build property to Yes. Remember as you add more header source files to the project, they will be automatically processed by STRIDE unless you explicitly disable.

STRIDE Compile-Instrument Properties

Visual Studio 2010 (or newer)

The default settings are usually sufficient so you don't need to make any changes.

When you build your project, notice that:

  • The STRIDE build tools automatically run and generate a STRIDE database (.sidb) file and intercept module (IM) source files. By default the names are derived from $(TargetName), and the associated files are written to the $(ProjectDir) directory.
  • The IM source, $(TargetName)IM.cpp, is automatically compiled and linked along with your other project sources.

If you desire to change the Database Name and/or the Intercept Module Name use the following steps:

  • Right click on the project in the Solution Explorer window and choose Properties from the menu that is displayed.
  • From the properties dialog, select Configuration Properties | STRIDE Compile-Instrument
  • Update Database Name and/or the Intercept Module Name right pane values as desired.

NOTE: If you do not see STRIDE Compile-Instrument try adding a header file to your project.

The default harness generation assumes STUB settings for all captured functions. If you require different settings for any of your interfaces, you should create a text file containing the additional settings and specify it as follows:

  • Right click on the project in the Solution Exporer window and choose Properties from the menu that is displayed.
  • From the properties dialog, select Configuration Properties | STRIDE Compile-Instrument | Command Line from the tree view in the left pane.
  • From the right pane, add to Additional Options property in the right pane.
--intercept_options_file="path\to\my\file.s2instrument"

Visual Studio 2008

  • Right click on the project in the Solution Exporer window and choose Properties from the menu that is displayed.
  • From the properties dialog, select Configuration Properties | STRIDE Compile-Instrument | Compile from the tree view in the left pane.
  • From the right pane, add to Compile Options Files the following:
$(STRIDE_DIR)\SDK\Windows\settings\stride.s2scompile
  • From the right pane, update Include Directories to be exactly the same the one specified in Additional Include Directories in Configuration Properties | C/C++ | General section.
  • From the right pane, update Preprocessor Definitions to be exactly the same the one specified in Preprocessor Definitions in Configuration Properties | C/C++ | Preprocessor section.
  • Build your project once to generate the STRIDE database (.sidb) and intercept module (IM) source files. Notice, that you will get linker errors during this build since you have not yet added the generated IM source to the project.
  • From the $(ProjectDir) directory add the generated IM source file - strideIM.cpp, strideIM.h and strideIMEntry.h - to your project.
    • For strideIM.cpp make sure to set its Create/Use Precompiled Header property to Not Using....
    • For strideIM.h and strideIMEntry.h make sure to set their Excluded From Build property to Yes as specified above.
  • Rebuild your project and resolve any compiler errors/warnings.

The default harness generation assumes STUB settings for all captured functions. If you require different settings for any of your interfaces, you should create a text file containing the additional settings and specify it as follows:

  • Right click on the project in the Solution Exporer window and choose Properties from the menu that is displayed.
  • From the properties dialog, select Configuration Properties | STRIDE Compile-Instrument | Instrument from the tree view in the left pane.
  • From the right pane, add to Intercept Options File property in the right pane.
path\to\my\file.s2instrument

NOTE: As you add sources, you will likely also need to add Additional Includes and Preprocessor Defines to the project's STRIDE Compile-Instrument settings in order to successfully build.

Update Your Startup

Update your application's main function to initialize the STRIDE subsystem as described in this article. Note that the sample code assumes you have generated your Intercept Module with a name of myintercept. Make sure to replace any reference to that token in the code to the name you chose above.