Runtime Integration: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
 
(58 intermediate revisions by 3 users not shown)
Line 1: Line 1:
==Overview==
==Overview==


This page discusses the first step in an overall STRIDE framework integration. The ultimate goals are to extend your target build process to:
* Incorporate the STRIDE Runtime source files in your target build
* Configure compiler settings
* Add code to target source to start and stop STRIDE runtime threads
* Incorporate the STRIDE Build Tools in your make process as a pre-compilation step


This page discuses the first step in an overall STRIDE integration effort. Here we incorporate the STRIDE runtime in your target application build without tests. In the second and last step, we add the STRIDE [[Build Tools]] to the mix and hook up the test-running harnessing.
Here we incorporate the [[STRIDE Runtime]] in your target application build without tests. In the second and last step, we add the STRIDE [[Build Tools]] to the mix and hook up the test-running harnessing.


After building the target with the STRIDE runtime in place, we will run stride from a remote host computer to verify connectivity and runtime operation.
After building the target with the STRIDE Runtime in place, we will run stride from a remote host computer to verify connectivity and runtime operation.


=== Recommendations ===
=== Recommendations ===
Line 10: Line 15:


=== Integrating STRIDE Into Your Target Build ===
=== Integrating STRIDE Into Your Target Build ===
To add the STRIDE runtime to your build process, the following changes must be made:
To add the STRIDE Runtime to your build process, the following changes must be made:


* Secure a PAL targeted to your target operating system
* Secure a PAL targeted to your target operating system
* Configure the PAL I/O parameters to conform the your target hardware
* Configure the PAL I/O parameters to conform the your target hardware
* Add steps to your target build process to include the STRIDE runtime source files
* Include the STRIDE runtime source files in the software build
* Edit your target application's source code to start the runtime's I/O thread
* Edit your target application's source code to start the runtime and I/O thread(s)


== Securing a PAL ==
== Securing a PAL ==
The Platform Abstraction Layer (PAL) provides the glue between the STRIDE runtime and services offered by your OS. It is the only piece of the runtime that is customized between operating systems.
The [[Platform_Abstraction_Layer|Platform Abstraction Layer (PAL)]] provides the glue between the STRIDE Runtime and services offered by your OS. It is the only piece of the runtime that is customized between operating systems.


Fully tested PALs are provided for Linux and Windows, included as <tt>palIO.c</tt> and <tt>palOS.c</tt> in their respective SDKs. Other PALs are also available or under development. Please contact S2 for availability.
Fully tested PALs are provided for Posix and Windows, included as <tt>palcfg.h</tt>, <tt>palIO.c</tt> and <tt>palOS.c</tt> in their respective [[Framework_Setup#SDK|SDK]].  


== Configuring I/O parameters ==
== Configuring PAL I/O parameters ==
If your target will communicate with the host computer via the default of TCP/IP port 8000, you can skip this step.
If your target will communicate with the host computer via the default of TCP/IP port 8000, you can skip this step.


Otherwise, refer to <tt>[[palcfg.h]]</tt> for a list of configuration parameters.
Otherwise, refer to <tt>palcfg.h</tt> that comes with your PAL for a list of configuration parameters.


For complete information, refer to the [[Platform Abstraction Layer|Platform Abstraction Layer]] page and the [[Media:s2sPAL.pdf|PAL Specification]] document.
== Including the STRIDE Runtime ==
The [[STRIDE Runtime]] is distributed in source form. The source files are included with each [[Framework_Setup#SDK|SDK]] under "Runtime" directory. Files in that directories should be included in your target build.


== Including the STRIDE Runtime Sources ==
If you are using an S2-supplied SDK, additional required sources can be found in the SDK's <tt>src</tt> directory:
The STRIDE runtime sources are distributed in source form. The source files are available as a stand-alone package and are also included with each flavor of SDK package.


The runtime sources are supplied in three directories:
* PAL implementation
;GRS
** <tt>palcfg.h</tt>
: [[GRS|Generic RTOS Services]]
** <tt>palIO.c</tt>
;Runtime
** <tt>palOS.c</tt>
: [[Runtime Reference|STRIDE runtime]]
 
;SLAP
* Convenience functions (these wrap low-level PAL/Runtime calls)
: [[SLAP|Simplified Link-layer Application Protocol]]
** <tt>stride.c</tt>
** <tt>stride.h</tt>
 
* Build script
** <tt>Makefile</tt>
 
The build script (Makefile) supplied with an SDK allows building of the runtime source into a library that could then be linked with the target application.
 
=== C/C++ Feature Support ===
By default the C source in the Runtime was written with the presumption that the target C compiler and C Runtime (CRT) library supports '''wchar_t''', '''long long''', '''long double''', '''safe snprintf''', and '''variadic macros'''
 
By default the C++ source in the Runtime was written with the presumption that the target C++ compiler can handle '''namespaces''' and '''exceptions'''.


If you are using an S2-supplied PAL, files in each of these directories should be included in your target build.
If desired the user can specify different configuration by using '''-D''' compiler options:


If you are using an S2-supplied PAL, additional required sources can be found in the SDK's <tt>src</tt> directory:
-DsrCRT_HAS_WCHAR_T=<0|1>
-DsrCRT_HAS_LONG_LONG=<0|1>
-DsrCRT_HAS_LONG_DBL=<0|1>
-DsrCRT_HAS_SNPRINTF=<0|1>
-DsrCRT_HAS_VA_ARGS=<0|1>
-DsrCPP_HAS_NAMESPACE=<0|1>
-DsrCPP_HAS_EXCEPTION=<0|1>


* PAL implementation
where 0=disabled and 1=enabled.
** palcfg.h
** palIO.c
** palOS.c


* Convenience functions (these wrap low-level STRIDE runtime calls)
=== STRIDE Feature Control ===
** stride.c
Any application's source file referencing STRIDE source should be compiled with addition ''STRIDE_ENABLED'' switch (preprocessor directive):
** stride.h
<source lang="bash">
cc -DSTRIDE_ENABLED=1 file.c
</source>


The SDKs inlclude the runtime sources by building them into a library that is then linked with the target application.  
The definition of the <tt>STRIDE_ENABLED</tt> macro controls all STRIDE-related sources and macros. If undefined (or defined as zero), STRIDE-related sources are excluded and STRIDE-related macros are left undefined. This provides a simple means of including and excluding test-related entities in your production build.


== Target Source Changes ==
== Target Source Changes ==
Line 59: Line 80:
Your target source must be edited to include code that initializes and uninitializes the runtime. The code is typically added to your <tt>main()</tt> function, but the only requirement is that the initialization takes place before the host computer connects and the uninitialization occurs before the process terminates.
Your target source must be edited to include code that initializes and uninitializes the runtime. The code is typically added to your <tt>main()</tt> function, but the only requirement is that the initialization takes place before the host computer connects and the uninitialization occurs before the process terminates.


Example startup code:
Please refer to the standard pre-packaged [[Framework_Setup#SDK|SDK]] for examples of a startup sequence. Briefly it should be something like:
 
<source lang="c">
<source lang="c">
#ifdef WIN32
/* STRIDE runtime includes */
#include <windows.h>
#include <stride.h>
#include <tchar.h>
int main(int argc, char **argv)
{
    ...
    /* initialize the STRIDE subsytem using default I/O */
#ifdef __cplusplus
    strideIO_t io = {strideIO_t::strideDEFAULT};
#else
#else
#include <stdlib.h>
    strideIO_t io = {strideDEFAULT};
#include <unistd.h>
#endif
#endif
    if (strideInit(&io) != srTRUE)
        return -1;
    /* start any IM thread */
    ...
    /* target application code here */
    ...
    /* stop all STRIDE threads and uninitialize STRIDE subsystem */
    strideUninit();
    return 0; 
}
</source>
If you implement a custom PAL then here is an example of the startup code using direct PAL and STRIDE Runtime API calls instead of the stride.c/.h wrappers provided by the SDK:
<source lang="c">
/* STRIDE runtime includes */
/* STRIDE runtime includes */
#include <stride.h>
#include <palcfg.h>
#include <sr.h>


int main(int argc, char **argv)
int main(int argc, char **argv)
{
{
  ...
    palDWORD dwRTNID;
 
    ...
 
    /* initialize the PAL handler */
    if (palOSInit() != palTRUE)
        return -1;
 
    /* initialize the PAL IO handler */
    if (palIOInit(PAL_DEFAULT_DEVICE_NAME) != palTRUE)
    {
        palOSUninit();
        return -1;
    }


/* initialize the STRIDE subsytem using default I/O */
    /* initialize STRIDE Runtime */
  strideIO_t io = {strideDEFAULT};
     if (srInit() != srOK)
/* for C++ use
    {
  strideIO_t io = {strideIO_t::strideDEFAULT};
        palIOShutdown();
*/
        srUninit();
      
        palOSUninit();
  if (strideInit(&io) != srTRUE) {
        return -1;
      return -1;
    }
  }


  /* target application code here */
    /* start the Runtime thread first */
  ...
    palDWORD dwRTNID = /* create thread with function srThread() */;
    if (dwRTNID == 0)
    {
        palIOShutdown();
        srUninit();
        palOSUninit();
        return -1;
    }


/* this call blocks until a SIGTERM is received, omit if not needed */
    /* start any IM thread */
  strideExWaitForExit();
    ...


/* terminate all STRIDE threads and uninitialize STRIDE subsystem */
    /* target application code here */
  strideUninit();
    ...
  return 0;   
 
}
    /* stop all IM threads */
    ...
 
    /* stop Runtime thread */
    palNotify(dwRTNID, palSTOP_EVENT);
 
    /* uninitialize STRIDE subsystem */
    palIOShutdown();
    srUninit();
    palOSUninit();
 
    return 0;   
}
</source>
</source>


==Testing the Runtime Integration==
==Testing the Runtime Integration==
Once the instrumented target is successfully built, start the target application. On a separate host computer, connected to the target via TCP/IP (or serial port if so configured), run '''stride''' as follows (substitute the --device option argument as needed):
Once the instrumented target is successfully built, start the target application. On a separate host computer, connected to the target via TCP/IP (or serial port if so configured), run '''[[STRIDE_Runner|stride]]''' as follows (substitute the <tt>--device</tt> option argument as needed):
<ref>If '''stride''' is not already installed, see [[Package_Installation#Host_Tools|Host Tools installation]].</ref>
stride --diagnostics --device TCP:[device_address]:8000


By specifying --diagnostics without also specifying a database, we instruct stride to test for connectivity with the target.
<source lang="bash">
stride --diagnostics --device=<device_address>
</source>
 
By specifying <tt>--diagnostics</tt> without also specifying a database, we instruct stride to test for connectivity with the target.


If all is well, the following will be output to the host window (the reported runtime version may be different than that shown):
If all is well, the following will be output to the host window (the reported runtime version may be different than that shown):
Line 108: Line 189:
<pre>
<pre>
Connecting to device...
Connecting to device...
   runtime version: 4.1.01
   runtime version: 5.x.yy
Disconnecting from device...
Disconnecting from device...
</pre>
</pre>
== Notes ==
<references/>
[[Category:Deployment]]

Latest revision as of 16:28, 7 July 2015

Overview

This page discusses the first step in an overall STRIDE framework integration. The ultimate goals are to extend your target build process to:

  • Incorporate the STRIDE Runtime source files in your target build
  • Configure compiler settings
  • Add code to target source to start and stop STRIDE runtime threads
  • Incorporate the STRIDE Build Tools in your make process as a pre-compilation step

Here we incorporate the STRIDE Runtime in your target application build without tests. In the second and last step, we add the STRIDE Build Tools to the mix and hook up the test-running harnessing.

After building the target with the STRIDE Runtime in place, we will run stride from a remote host computer to verify connectivity and runtime operation.

Recommendations

The STRIDE target environment offers lots of flexibility to accommodate different target scenarios. For an initial target integration, we recommend that you pursue the simplest STRIDE configuration that will yield results. Once this configuration is successfully integrated you can make adjustments as desired.

Integrating STRIDE Into Your Target Build

To add the STRIDE Runtime to your build process, the following changes must be made:

  • Secure a PAL targeted to your target operating system
  • Configure the PAL I/O parameters to conform the your target hardware
  • Include the STRIDE runtime source files in the software build
  • Edit your target application's source code to start the runtime and I/O thread(s)

Securing a PAL

The Platform Abstraction Layer (PAL) provides the glue between the STRIDE Runtime and services offered by your OS. It is the only piece of the runtime that is customized between operating systems.

Fully tested PALs are provided for Posix and Windows, included as palcfg.h, palIO.c and palOS.c in their respective SDK.

Configuring PAL I/O parameters

If your target will communicate with the host computer via the default of TCP/IP port 8000, you can skip this step.

Otherwise, refer to palcfg.h that comes with your PAL for a list of configuration parameters.

Including the STRIDE Runtime

The STRIDE Runtime is distributed in source form. The source files are included with each SDK under "Runtime" directory. Files in that directories should be included in your target build.

If you are using an S2-supplied SDK, additional required sources can be found in the SDK's src directory:

  • PAL implementation
    • palcfg.h
    • palIO.c
    • palOS.c
  • Convenience functions (these wrap low-level PAL/Runtime calls)
    • stride.c
    • stride.h
  • Build script
    • Makefile

The build script (Makefile) supplied with an SDK allows building of the runtime source into a library that could then be linked with the target application.

C/C++ Feature Support

By default the C source in the Runtime was written with the presumption that the target C compiler and C Runtime (CRT) library supports wchar_t, long long, long double, safe snprintf, and variadic macros

By default the C++ source in the Runtime was written with the presumption that the target C++ compiler can handle namespaces and exceptions.

If desired the user can specify different configuration by using -D compiler options:

-DsrCRT_HAS_WCHAR_T=<0|1>
-DsrCRT_HAS_LONG_LONG=<0|1>
-DsrCRT_HAS_LONG_DBL=<0|1>
-DsrCRT_HAS_SNPRINTF=<0|1>
-DsrCRT_HAS_VA_ARGS=<0|1>
-DsrCPP_HAS_NAMESPACE=<0|1> 
-DsrCPP_HAS_EXCEPTION=<0|1>

where 0=disabled and 1=enabled.

STRIDE Feature Control

Any application's source file referencing STRIDE source should be compiled with addition STRIDE_ENABLED switch (preprocessor directive):

cc -DSTRIDE_ENABLED=1 file.c

The definition of the STRIDE_ENABLED macro controls all STRIDE-related sources and macros. If undefined (or defined as zero), STRIDE-related sources are excluded and STRIDE-related macros are left undefined. This provides a simple means of including and excluding test-related entities in your production build.

Target Source Changes

Your target source must be edited to include code that initializes and uninitializes the runtime. The code is typically added to your main() function, but the only requirement is that the initialization takes place before the host computer connects and the uninitialization occurs before the process terminates.

Please refer to the standard pre-packaged SDK for examples of a startup sequence. Briefly it should be something like:

/* STRIDE runtime includes */
#include <stride.h>
 
int main(int argc, char **argv)
{
    ...
 
    /* initialize the STRIDE subsytem using default I/O */
#ifdef __cplusplus
    strideIO_t io = {strideIO_t::strideDEFAULT};
#else
    strideIO_t io = {strideDEFAULT};
#endif
    if (strideInit(&io) != srTRUE)
        return -1;
 
    /* start any IM thread */
    ...

    /* target application code here */
    ...
 
    /* stop all STRIDE threads and uninitialize STRIDE subsystem */
    strideUninit();

    return 0;   
}

If you implement a custom PAL then here is an example of the startup code using direct PAL and STRIDE Runtime API calls instead of the stride.c/.h wrappers provided by the SDK:

/* STRIDE runtime includes */
#include <palcfg.h>
#include <sr.h>

int main(int argc, char **argv)
{
    palDWORD dwRTNID;

    ...

    /* initialize the PAL handler */
    if (palOSInit() != palTRUE) 
        return -1;

    /* initialize the PAL IO handler */
    if (palIOInit(PAL_DEFAULT_DEVICE_NAME) != palTRUE) 
    {
        palOSUninit();
        return -1;
    }

    /* initialize STRIDE Runtime */
    if (srInit() != srOK)
    {
        palIOShutdown();
        srUninit();
        palOSUninit();
        return -1;
    }

    /* start the Runtime thread first */
    palDWORD dwRTNID = /* create thread with function srThread() */;
    if (dwRTNID == 0) 
    {
        palIOShutdown();
        srUninit();
        palOSUninit();
        return -1;
    }

    /* start any IM thread */
    ...

    /* target application code here */
    ...

    /* stop all IM threads */
    ...

    /* stop Runtime thread */
    palNotify(dwRTNID, palSTOP_EVENT);

    /* uninitialize STRIDE subsystem */
    palIOShutdown();
    srUninit();
    palOSUninit();

    return 0;   
}

Testing the Runtime Integration

Once the instrumented target is successfully built, start the target application. On a separate host computer, connected to the target via TCP/IP (or serial port if so configured), run stride as follows (substitute the --device option argument as needed):

stride --diagnostics --device=<device_address>

By specifying --diagnostics without also specifying a database, we instruct stride to test for connectivity with the target.

If all is well, the following will be output to the host window (the reported runtime version may be different than that shown):

Connecting to device...
  runtime version: 5.x.yy
Disconnecting from device...