Studio:Integrating the Intercept Module (IM)

From STRIDE Wiki
Revision as of 19:54, 20 June 2007 by Billp (talk | contribs) (IM Files and how they are used)
Jump to: navigation, search

IM Files and how they are used

The Intercept Module is generated by STRIDE Studio for the specific set of function interfaces you select. Three files are created, differing only by their ending:

  • The Intercept Module source file (IM.c / IM.cpp)
This file contains the code that allows the remoting of functions so that they can be accessed by the Target and Host.
  • The Delegate Mangling header file (IM.h)
This file must be included in all of your C files that are using Delegates (Dynamic or Tracing). It contains macros that will mangle the appropriate function names so that they can be intercepted and routed through the IM. When used, it must be the last file #include'd in the source. Also, it is only required if the C file uses Delegates. Stubs and Proxy functions do not require this file.
  • The IM Entry point header file (IMEntry.h)
This file contains the prototypes for the external entry points into the IM. It is needed only by the function that starts the IM Stub Read Thread.

These filenames are all prepended by the name you give the IM when it is generated. For example, if you call the IM "MyProject", then the resulting filenames will be "MyProjectIM.c", "MyProjectIM.h", and "MyProjectIMEntry.h".

Adding the IM files to the build

IM Resource Requirements

  • Stack size
  • Threads

Configuring and generating an Intercept Module

You can either generate the IM via STRIDE Studio’s Intercept Module Wizard, or you can utilize scripts to automatically configure and generate the IM files. These files will contain Studio-based configuration definitions. In addition, the script used for configuration will denote in which context the IM runtime functions are to be executed.

The script can execute automatically so that the Intercept Module is built as part of the test automation framework, as shown in the following example. The IM generation script should open a Studio workspace, optionally compile the workspace and save the database (if needed), then configure and create the IM as shown in the following Perl example:

 # Compile and save the workspace database
 $main::studio->Workspace->CompileAll();
 $main::studio->Workspace->Save();
 
 # Intercept Module (IM) name and path constants
 my $IM_FILE_NAME = "stride";
 my $IM_LOCATION_PATH = $main::studio->Workspace->Path;
 
 # Create a reference to the workspace IM object
 my $IM = $main::studio->Workspace->Intercept;
 
 # Local variables
 my ($i, $fx);
 
 # Reset all of the IM configuration settings to off and
 # reset the delegate group Id's to their default name.
 $IM->Reset();
  
 # Setup the IM name and path
 $IM->{Name} = $IM_FILE_NAME;
 $IM->{Path} = $IM_LOCATION_PATH;
  
 # For each interface in the IM collection
 for ($i=0; $i < $IM->Count(); $i++)
 {
     # reference the ith interface;
     $fx = $IM->Item($i);
  
     $fx->{Stub} = 1;               # configure as stub
                                    # and delegate
     $fx->Delegate->{Owner} = 1;    # mangle from owner's perspective
     $fx->Delegate->{Explicit} = 1; # implicit name mangling
     $fx->Delegate->{Dynamic} = 1;  # enable dynamic interception
 }                                 
  
 # Create IM files.
 $IM->Create();

The resulting Intercept Module file is then compiled and built with the rest of your target code.

Starting the IMStubRead thread