STRIDE Extensions for Visual Studio: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
No edit summary
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 project.
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.


== Prerequisites ==
== Prerequisites ==
Line 6: Line 6:
* a recent version of the STRIDE Framework [[Desktop_Installation#Windows_Installation|installed]] including a recent version of Perl
* a recent version of the STRIDE Framework [[Desktop_Installation#Windows_Installation|installed]] including a recent version of Perl
* a static library version of the runtime built using the source files included in the [[Windows_SDK | SDK]]. This is accomplished by just running ''make'' on the makefile that we provide in the <tt>SDK\Windows\src</tt> directory (the default makefile target builds the static runtime library).
* a static library version of the runtime built using the source files included in the [[Windows_SDK | SDK]]. This is accomplished by just running ''make'' on the makefile that we provide in the <tt>SDK\Windows\src</tt> directory (the default makefile target builds the static runtime library).
* existing C/C++ Visual Studio project (you can easily create one by using the project wizard provided with Visual Studio)


== Creating Off-Target Test App Projects  ==
== 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].)


The following instructions describe the steps required to create sandbox target applications on windows. You will likely need additional source code and project settings as required to make your specific application code build.
=== Visual Studio 2010 ===
* Right click on the project in the '''Solution Exporer''' 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”)
* Make sure the check box next to '''stride''' is ''enabled''.


<ol>
=== Visual Studio 2005/2008 ===
<li>Create a new C/C++ Win32 Console application project. All versions of Visual Studio provide a project wizard to do this. If you are given an option to use precompiled headers in the project, select '''No'''.</li>
<u>''NOTE:''</u> ''Due to limitations in Visual Studio 2005/2008 the STRIDE integration is much more complicated compared to version 2010. We strongly recommend you to upgrade to Visual Studio 2010.''
<li>Assign the stride rules file to this project. Select the ''Project'' -> ''Custom Build Rules...'' menu item to launch a dialog to import this rules file located at ''stride\SDK\Windows\settings\stride.rules''. After associating the stride rules file with your project, make sure you also ''enable'' the rule for your project (typically by selecting the check-box next to its name).</li>
<li>Add your application, test and SCL source code to the project.


Any header files that are in the project will be automatically processed by the STRIDE SCL compiler. If there are some header files that contain no SCL statements, then we recommend disabling the build step for these files. This is typically done via the properties dialog for a file by setting the "General" | "Exclude from build" property to "Yes".  
* Right click on the project in the '''Solution Exporer''' 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”)
* Make sure the check box next to '''STRIDE Rules''' is ''enabled''.


In order to get an appropriate ''main'' function, you will also need to add the <tt>stride\SDK\Windows\src\TestApp.c</tt> to the project.</li>
== Configuration ==
<li>Change the C/C++ Properties for the project:
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.
<ul>
 
<li>Disable detection of 64-bit portability issues [typically found in the ''General'' section].</li>
=== Sort Out Header Files ===
<li>set the runtime library to '''Multi-threaded DLL (/MD)''' [typically found in the ''Code Generation'' section].</li>
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.)
<li>Add Additional Include Directories to your project [typically found in the ''General'' section]:
 
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 the stride compiler unless you explicitly specify something else.''
 
=== 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 configurations (e.g., Debug, Release).''
 
==== C/C++ Properties ====
* 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 | C/C++ | General''' from the tree view in the left pane.
* From the right pane, add to '''Additional Include Directories''' the following:
<pre>
<pre>
$(STRIDE_DIR)\SDK\Runtime
$(STRIDE_DIR)\SDK\Runtime
$(STRIDE_DIR)\SDK\Windows\src
$(STRIDE_DIR)\SDK\Windows\src
[path(s) to other application and test source headers]
</pre>
</pre></li>
* Select '''Configuration Properties | C/C++ | Preprocessor''' from the tree view in the left pane.
<li>Add the following to the preprocessor definitions [typically found in the ''Preprocessor'' section]:
* From the right pane, add to '''Preprocessor Definitions''' the following:
<pre>
<pre>
STANDALONE_TESTAPP
STRIDE_ENABLED
STRIDE_ENABLED
STRIDE_STATIC
STRIDE_STATIC
srCOMPLEX_TARGET
</pre>
</pre>
</li>
* Select '''Configuration Properties | C/C++ | Code Generation''' from the tree view in the left pane.
<li>Disable precompiled headers for the project (or selectively disable them for STRIDE-generated files) [typically found in the ''Precompiled Headers'' section].</li>
* From the right pane, set '''Runtime Library''' to '''Multi-threaded DLL (/MD)'''
</ul>
</li>


<li>Change the Linker Properties for the project:
==== Linker Properties ====
<ul>
* Right click on the project in the '''Solution Exporer''' window and choose '''Properties''' from the menu that is displayed.
<li>Add Additional Library Directories [typically found in the ''General'' section]:
* 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:
<pre>
<pre>
$(STRIDE_DIR)\SDK\Windows\out\lib
$(STRIDE_DIR)\SDK\Windows\out\lib
</pre></li>
</pre>
<li>Add Additional (linker) Dependency [typically found in the ''Input'' section]:
* Select '''Configuration Properties | Linker | Input''' from the tree view in the left pane.
* From the right pane, add to '''Additional Dependencies''' the following:
<pre>
<pre>
stride.lib
stride.lib
ws2_32.lib 
ws2_32.lib
winmm.lib
</pre>
</pre></li>
</ul>
</li> 


<li>Set the STRIDE Compile-Instrument properties for the project:
==== STRIDE Compile-Instrument Properties ====
<ul>
===== Visual Studio 2010 =====
<li>Set the '''Compile Options File''' to ''$(STRIDE_DIR)\SDK\Windows\settings\stride.s2scompile''.  This file provides basic options for windows off-target apps.  If you require different or additional parameters to be passed to the STRIDE SCL compiler, then we recommend that you make a local copy of the provided settings file and set this property to your private (and modified) version.  The size and alignment settings in the provided file are correct for standard 32 bit Windows platforms.</li>
The default settings are ususlly sufficient so don't need to make any changes.
<li>The default Intercept 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]] to assign the path to this file for the '''Intercept Options File''' property.</li>
<li>Add directories to the '''Include Directory''' property as needed to allow the STRIDE SCL compiler to process your source code. You can often use the same values here that you have previously set in the C/C++ compiler settings for your project.</li>
<li>Add preprocessor defines to the '''Defines''' property as needed to allow the STRIDE SCL compiler to process your source code. You can often use the same values here that you have previously set in the C/C++ compiler settings for your project.</li>
</ul>
</li>
<li>Repeat steps 4-6 for all project configurations you want to build (e.g., Debug, Release).</li>
<li>Build your project once to generate the STRIDE intercept module source files. You will get linker errors during this build since you have not yet added the generated STRIDE intercept code.</li>
<li>Add the generated source file - '''strideIM.cpp''' - to your project. This file will be located in the $(ProjectDir) directory. If you are using the STRIDE rules file (as described in step 2 above), you also need to add the following generated header files to your project: '''strideIM.h''' and '''strideIMEntry.h'''. Since these header files are generated, we do not want the STRIDE rule to attempt to process them (rather, they are in the project so that Visual Studio can properly calculate dependencies). As such, you should also set the ''Excluded from build'' property on these two header files to '''yes''' (this property is accessible by right clicking on the header file in the solution explorer view and selecting ''Properties'')</li>
<li>Rebuild your project and resolve any compiler errors/warnings.</li>


<u>''NOTE:''</u> As you add more header source files to the project, they will be automatically processed by the stride compiler unless you explicitly exclude them from the build. As you add sources, you will likely also need to add additional include and preprocessor defines to the STRIDE compile-instrument settings in order to successfully build.
===== Visual Studio 2005/2008 =====
</ol>
* 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:
<pre>
$(STRIDE_DIR)\SDK\Windows\settings\stride.s2scompile
</pre>
* 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.
* From the properties dialog, select '''Configuration Properties | STRIDE Compile-Instrument | Instrument''' from the tree view in the left pane.
* 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 add it to '''Intercept Options File''' property in the right pane.
* Build your project once to generate the STRIDE intercept module source files. You will get linker errors during this build since you have not yet added the generated STRIDE intercept code.
* Add the generated source file - '''strideIM.cpp''', '''strideIM.h''' and '''strideIMEntry.h''' - to your project. These files will be located in the '''$(ProjectDir)''' directory. For the two header files, since they are generated, we do not want the STRIDE rule to attempt to process them (rather, they are in the project so that Visual Studio can properly calculate dependencies). As such, you should also set the ''Excluded From Build'' property on these two header files to '''Yes''' (this property is accessible by right clicking on the header file in the '''Solution Explorer''' window and selecting ''Properties'')
* Rebuild your project and resolve any compiler errors/warnings.


<u>''NOTE:''</u> ''As you add sources, you will likely also need to add additional include and preprocessor defines to the STRIDE compile-instrument settings in order to successfully build.''


[[Category: Installation]]
[[Category: Installation]]

Revision as of 00:27, 10 June 2011

Introduction

If you are using the STRIDE Framework for Windows, an alternative to the 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.

Prerequisites

  • Visual Studio 2005 or later (an express distribution is fine)
  • a recent version of the STRIDE Framework installed including a recent version of Perl
  • a static library version of the runtime built using the source files included in the SDK. This is accomplished by just running make on the makefile that we provide in the SDK\Windows\src directory (the default makefile target builds the static runtime library).
  • existing C/C++ Visual Studio project (you can easily create one by using the project wizard provided with Visual Studio)

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 scl pragmas.)

Visual Studio 2010

  • Right click on the project in the Solution Exporer 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”)
  • Make sure the check box next to stride is enabled.

Visual Studio 2005/2008

NOTE: Due to limitations in Visual Studio 2005/2008 the STRIDE integration is much more complicated compared to version 2010. We strongly recommend you to upgrade to Visual Studio 2010.

  • Right click on the project in the Solution Exporer 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”)
  • 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. In a matter for that to properly work your header files and global project settings need to be adjusted.

Sort Out Header Files

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.)

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.

NOTE: As you add more header source files to the project, they will be automatically processed by the stride compiler unless you explicitly specify something else.

Adjust Project Properties

Adjust your project properties to compile and link with the STRIDE Runtime and generated test harness. NOTE: Make sure to apply the following changes to all project configurations (e.g., Debug, Release).

C/C++ Properties

  • 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 | 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)

Linker Properties

  • 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 | Linker | General from the tree view in the left pane.
  • From the right pane, add to Additional Library Directories the following:
$(STRIDE_DIR)\SDK\Windows\out\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

STRIDE Compile-Instrument Properties

Visual Studio 2010

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

Visual Studio 2005/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.
  • From the properties dialog, select Configuration Properties | STRIDE Compile-Instrument | Instrument from the tree view in the left pane.
  • 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 add it to Intercept Options File property in the right pane.
  • Build your project once to generate the STRIDE intercept module source files. You will get linker errors during this build since you have not yet added the generated STRIDE intercept code.
  • Add the generated source file - strideIM.cpp, strideIM.h and strideIMEntry.h - to your project. These files will be located in the $(ProjectDir) directory. For the two header files, since they are generated, we do not want the STRIDE rule to attempt to process them (rather, they are in the project so that Visual Studio can properly calculate dependencies). As such, you should also set the Excluded From Build property on these two header files to Yes (this property is accessible by right clicking on the header file in the Solution Explorer window and selecting Properties)
  • Rebuild your project and resolve any compiler errors/warnings.

NOTE: As you add sources, you will likely also need to add additional include and preprocessor defines to the STRIDE compile-instrument settings in order to successfully build.