|
| |||||||||||||||||||
Chapter 16 Reactis for C PluginThe base Reactis product treats S-Functions and Stateflow custom C code as black boxes. Models containing such C code can be processed, but the C source code is inaccessible. Hence, there is no way to perform basic debugging operations such as single-stepping, viewing variable values, setting breakpoints, or browsing the source code during simulation. Furthermore, targets cannot be created within the C source code when generating tests. Reactis for C Plugin integrates seamlessly with Reactis to offer white-box testing and validation of the C-code portions of models (S-Functions and C code called from Stateflow). Together, Reactis and Reactis for C Plugin automate the generation of test data from, and validation of models constructed with Simulink, Stateflow, and C code. A separate license is required to use the Reactis for C Plugin. If your organization does not yet own such a license please contact sales@reactive-systems.com to inquire about purchase options or to obtain a demo license for the product. Reactis for C Plugin requires base Reactis to run. 16.1 Quick Start
16.2 Configuring Reactis for CFigure 16.1 shows the Reactis for C Plugin tab of the Reactis settings dialog. Within this menu, the behavior of Reactis for C Plugin can be configured. The purpose of each menu item is as follows:
16.3 S-Function C CodeSimulink does not require you to specify the C source files that implement an S-Function; instead only a name is given. For white-box testing, Reactis for C Plugin requires the C source files that implement an S-Function as well as the source files for any libraries referenced by the S-Function. Since the .mdl file does not include this information, Reactis for C Plugin has a mechanism for listing the C source files which comprise an S-Function. This mechanism is described in the rest of this section. The collection of C source files that implement an S-Function is specified using a Reactis Make File (.rsm file), which is created and modified by the simple editor shown in Figure 16.2. An .rsm file is created to specify how Reactis for C Plugin should compile the S-Function. Additionally, a separate .rsm file is constructed for each library referenced by the S-Function. The .rsm files for the S-Function and any libraries referenced by the S-Function are defined in the same way. In the following discussion we denote the library compiled from an .rsm file as the library under construction (LUC). The following sections appear within the .rsm file editor window:
16.3.1 PathnamesThe path to each source file or library
can be either relative or
absolute. The location of a source file whose
path is relative is determined by appending the relative path
to the directory containing the .rsm file. For example,
if the .rsm file 16.3.2 S-Function RequirementsAll source code (for both an S-Function and any referenced libraries) must be available. In addition, all code must satisfy the requirements listed in Section 14.2.1. 16.4 Stateflow Custom C Code
Reactis for C Plugin will automatically determine which C source files are called from Stateflow. This is possible because Stateflow requires you to specify the C source files in the Target Options dialog 1 and stores the names of the files in the .mdl file for a model. Reactis for C Plugin automatically processes any custom C code files. User input is only required in cases where custom C code links to external libraries. When a model is opened, the C files called from Stateflow will be listed at the bottom of the Reactis hierarchy panel in the C Libraries section, subsection Stateflow User Sources. This is illustrated in Figure 16.3. In this case, Reactis for C Plugin has determined that the file ctest10_code.c is called from Stateflow and has added it to the tree of model components, along with the library ctest10_code_lib.a. Note the error icon next to ctest10_code_lib.a. This icon indicates that user input is required to tell Reactis for C Plugin what sources belong to the library.
After selecting ctest10_code_lib.a, the message shown in Figure 16.4 is displayed. This message indicates that it will be necessary to create an .rsm file because the .mdl file does not list the sources used to build ctest10_code_lib.a. To specify the sources, right-click on the library model component (in this case ctest10_code_lib.a) and select Assign RSM File. A dialog window similar to the one in Figure 16.5 will appear. The process of creating the .rsm file is nearly the same as the process for creating S-Function .rsm files discussed in section 16.3. The only two differences are (1) that the editor window does not contain a library section, and (2) there is no coverage selection dialog. No coverage selection dialog is presented because coverage data in custom C code called from Stateflow is always collected cumulatively. 16.4.1 Stateflow Custom Code RequirementsReactis for C Plugin supports analysis of Stateflow custom code for which all C source code is available. The source files need not necessarily reside in the same directory as the model. Reactis will automatically search the directories in the Reactis path if a custom code source file or library is not found in the model directory. This behavior emulates the behavior of MATLAB . Regardless of what directory a library is found in, the .rsm file editor will start in the model directory when assigning the .rsm file associated with the library. If the .rsm file does not yet exist, the file system tree displayed as part of the open dialog window can be used to select a directory other than the model directory in which to create the .rsm file. For example, it could be desirable to create the .rsm file for a library which shared between models in the directory containing the source files used to build the library. 16.5 C Code Tab in the Info File EditorAccess to Reactis for C parameters is available from the Info File Editor. The C code tab displays a list of locations in the current model that reference C code (S-Functions and Stateflow custom code). This tab also gives the you ability to configure associated .rsm files. Each of the window items labeled in Figure 16.6 is interpreted and used as follows:
By right-clicking on a row of this dialog, you can bring up a menu to add, edit, or remove .rsm files. These functions are the same the ones presented when you right-click on an .rsm file in the model hierarchy panel. Double-clicking on any line with a named S-Function will cause the Reactis main window to jump to that location in the model hierarchy, and briefly highlight that system. Double-clicking on a line whose location is ’global’ will only highlight the C code library in the hierarchy panel. Clicking on each column heading will sort the rows alphabetically according to that column. In the example, some S-Function name and .rsm file columns have "n/a" (not applicable) in various locations. As explained in 16.4, code referenced from Stateflow does not have an associated S-Function, nor is an .rsm file required. Libraries that are referenced from Stateflow or S-Functions require an .rsm file, but do not have separate S-Functions. 16.6 C Code Coverage CriteriaReactis uses a number of different coverage criteria to measure how thoroughly a test or set of tests exercises a model. In general, coverage criteria record how many of a given class of coverage targets (model features such as Stateflow states, C program statements, etc.) have been executed at least once. Coverage criteria may be visualized using Simulator and are central to test generation and model validation using Tester and Validator. Chapter 6 describes the coverage criteria that are tracked within the Simulink and Stateflow portions of models. Those criteria include some which are specific to Simulink, some which appear only in Stateflow, and others which are generic and can appear in either Simulink or Stateflow. Three of the generic criteria are also tracked by the C code portions of models by Reactis for C Plugin. These are decision coverage, condition coverage, and modified condition / decision coverage (MC/DC). Reactis for C Plugin uses precise criteria to determine which elements of C a program are decisions and which are conditions. A decision is any boolean-valued expression used to determine which execution path to follow. Conditions represent the atomic (i.e. smallest) boolean expressions within decisions. Specifically, decisions within a program are identified as follows:
Note that the argument expression of a Decision coverage tracks whether each decision in a program has evaluated to both true and false. Condition coverage tracks whether each condition in a program has evaluated to both true and false. For the definition of MC/DC coverage, please see Chapter 6. Finally, in addition to the generic coverage criteria discussed above, Reactis for C Plugin also tracks statement coverage, which records for each statement in a C program, whether or not the statement has been executed at least once. 16.6.1 Tracking Coverage in C CodeWhen Coverage -> Show Details in Simulator is selected, unexercised coverage targets in C code are reported visually as shown in Figure 16.7. Any unexecuted C statement is rendered in red. If a decision has not evaluated to true it has a thin red overline. If a decision has not evaluated to false it has a thin red underline. If a condition has not evaluated to true it has a thick red overline. If a condition has not evaluated to false it has a thick red underline. If a decision has not met the MC/DC criteria, then the text of the decision is displayed in red. The MC/DC-related coverage details associated with a decision (Figure 16.8) may be displayed by right clicking on the decision and selecting View Coverage Details. For a description of this dialog, please see Chapter 6. Lines containing unexercised targets are distinguished by a a thin red bar which is drawn just to the right of the line number of that line. 16.7 C Code in the Main Reactis WindowAs shown in Figure 16.9, an .rsm file may be assigned, edited, or removed by right-clicking on the S-Function in the main panel when Simulator is disabled. After an .rsm file is assigned, the C source files for an S-Function are listed in the hierarchy panel and RSM appears in the upper right corner of the S-Function in the main panel. Figure 16.10 shows that a C file may be displayed in the main panel by clicking on the filename in the hierarchy panel. Line numbers and the grid may be turned on or off from the Reactis for C tab of the Settings dialog.
16.8 C Code and Reactis SimulatorWhen Reactis for C Plugin is enabled, Simulator seamlessly steps into Stateflow C code and S-Functions that have .rsm files assigned. The Simulator controls in the tool bar work in the same way within C code as they do for the Simulink and Stateflow portions of models. Five additional buttons are available to step through C source code. The behavior of those five and the Step Into button (also available when stepping through Simulink / Stateflow) is described below:
Other buttons continue to operate the same as when not using the Reactis for C Plugin.
For example, the step button (
As shown in Figure 16.11, a breakpoint may be toggled on lines within a C file which contain an executable C statement by double-clicking just to the right of the line number, or by right-clicking to the right of the line number and selecting Toggle Breakpoint. When trying to set a breakpoint in C code on a line that does not contain an executable statement, Reactis remaps the breakpoint to a different line according to the following rules:
Note that the following are not executable statements:
When execution reaches a line containing a breakpoint, execution will he paused before the line is executed. While paused, hovering over many identifiers in the source code will cause information about the identifier to be displayed. The information displayed depends on the type of the identifier:
For a description of how Simulator visually presents coverage information please see Section 16.6.1. The sizes and alignments of the common built-in C types under Reactis for C Plugin are listed in Table 16.1. These match the behavior of GCC (GNU C Compiler) and most other x86 C compilers. Integers are stored using a little endian byte order (the least-significant byte is stored first).
16.9 C Code and Reactis TesterWhen Reactis for C Plugin is enabled, Tester automatically tries to exercise the coverage targets (described in Section 16.6) in Stateflow custom C code and S-Functions that have .rsm files assigned. The launch dialog includes a check-box to enable or disable C statement coverage. 16.10 C Code and Reactis ValidatorReactis Validator can check requirements on top-level S-Function inputs and outputs. To do so, Validator objectives are inserted within the subsystem which contains the S-Function. Reactis for C Plugin does not currently support the insertion of Validator objectives within the C code. 16.11 Integer OverflowsThe C-plugin supports detection and flagging of overflows during operations on integer values. This feature can be turned on or off by changing the value of the On integer overflow configuration parameter, as discussed in Section 16.2. When On integer overflow is set to Wrap Over, the C-plugin emulates the behavior of typical hardware, in which the most significant bits of a value which is too large are dropped until the value is small enough to be represented. The result of an unsigned wrapped-over overflow is typically equal to the large result modulo 2n, where n is the width (in bits) of the container type. When signed values overflow, the sign bit may
change, producing results much smaller or larger than if no
overflow occurred. For example, in most 32-bit environments, adding the
maximum signed int value ( When On integer overflow is set to Error, the C-plugin will stop execution and display an error dialog window whenever an integer computation overflows. When a signed integer addition, subtraction, multiplication or left shift operation is performed, the result is considered to have overflowed when it is too large or too small to be represented. Note that according to the C language specification,
no overflow occurs during unsigned computations. Instead, the result
is computed by wrapping over the large value, using the modulo approach
mentioned in the previous paragraph.
This has the effect of truncating (in binary) the larger value.
For example, assigning the value When a value of one integer type is converted to a value of a different integer type, an overflow can only occur when the destination type is signed. This means that the statements
will not produce an overflow. Instead,
then an overflow will occur, because the value of
The values The C-plugin uses C99 rules for determining the signedness of expressions,
which affects when overflows may occur.
For integer constants, the type of the constant is determined by radix of
the constant and the presence of a
The C99 rules for evaluating integer expressions state that values of any type smaller
than When two integer values are combined in a binary expression, the width and signedness of the result are determined by two rules:
Operator arguments are converted to the result type before
the expression is evaluated. This means that the expression
16.12 Memory ErrorsWhenever a pointer is used to access memory, Reactis for C Plugin performs a safety check to ensure that pointer is valid. There are two steps in the validity check:
Note that it is possible that a program which appears to function correctly actually contains a memory error. For example, a function that sums an array may have an error in the iteration termination condition which causes the function to read 1 element past the end of the array. If the element which follows the end of the array happens to always be zero, this error may have never been detected. At some point the future, a change to the program may cause the invalid memory access to return a non-zero value. Even worse, there may be rare runtime conditions under which the memory access returns a non-zero value, causing intermittent program malfunctions which are difficult to reproduce and diagnose. Hence it is best to detect and fix such errors even though they may not seem to be presently causing a problem. 16.12.1 Invalid Pointer CreationReactis for C Plugin can produce an error or warning whenever a pointer expression produces an invalid pointer. This can help determine the source of a memory error. However, there are cases where invalid pointers are produced which are never dereferenced, such as the following program fragment:
During the last iteration of the above loop, the pointers 16.13 Other Runtime ErrorsIn addition to memory errors and overflows, the Reactis for C Plugin also detects the errors listed below. The C standard states that the results of these operations are undefined.
16.14 Unsupported C FeaturesReactis for C Plugin supports a very large subset of the C99 standard. The following features, however, are not currently supported:
The following restrictions apply to white-box analysis of S-Functions:
In Stateflow custom C code, pointers to functions are not currently supported. The following runtime library functions are currently unimplemented: complex.h cabsf cargf cimagf crealf cabs carg cimag creal cabsl cargl cimagl creall cacosf cacoshf casinf casinhf catanf catanhf ccosf ccoshf cexpf clogf conjf cpowf cprojf csinf csinhf csqrtf ctanf ctanhf cacos cacosh casin casinh catan catanh ccos ccosh cexp clog conj cpow cproj csin csinh csqrt ctan ctanh cacosl cacoshl casinl casinhl catanl catanhl ccosl ccoshl cexpl clogl conjl cpowl cprojl csinl csinhl csqrtl ctanl ctanhl dlfcn.h dlopen dlsym dlclose dlerror fcntl.h creat fcntl open close read write lseek unlink math.h asinh asinhf asinhl acosh acoshf acoshl atanh tanhf atanhl erf erff erfl erfc erfcf erfcl fam fmaf faml hypot hypotf hypotl lgamma lgammaf lgammal tgamma tgammaf tgammal expm1 expm1f exp1ml ilogb ilogbf ilogbl log1p log1pf log1pl rint rintf rintl setjmp.h sigsetjmp siglongjmp signal.h raise stdio.h freopen fseek ftell rewind fgetpos fsetpos ungetc fscanf scanf vfprintf vfscanf vscanf vsscanf fread fwrite feof ferror clearerr rename remove tmpfile tmpname stdlib.h atexit system execl execlp execle execv execvp execve bsearch qsort unistd.h access alarm brk chdir chroot chown close confstr crypt ctermid cuserid dup dup2 encrypt fchown fchdir fdatasync fork fpathconf fsync ftruncate getcwd getdtablesize getegid geteuid getgid getgroups gethostid getlogin getlogin_r getpagesize getpass getpgid getpgrp getpid getppid getsid getuid getwd isatty lchown link lockf lseek nice pathconf pause pipe pread pthread_atfork pwrite read readlink rmdir sbrk setgid setpgid setpgrp setregid setreuid setsid setuid sleep swab symlink sync sysconf tcgetpgrp tcsetpgrp truncate ttyname ttyname_r ualarm unlink usleep vfork write utime.h utime wchar.h wcscat wcsncat wcscmp wcsncmp wcscpy wcsncpy wcslen wcschr wcsrchr wcsspn wcscspn wcspbrk wcstok wcsstr wcscoll wcsxfrm wmemchr wmemcmp wmemcpy wmemmove wmemset fwide fgetwc getwc getwchar ungetwc fgetws fwscanf wscanf swscanf fputwc putwc putwchar fputws fwprintf wprintf swprintf vfwprintf vswprintf vwprintf vfwscanf vswscanf vwscanf wctype.h mbrlen btowc mbrtowc wctob wcrtomb mbsinit iswalnum iswalpha iswcntrl iswdigit iswxdigit iswgraph iswpunct iswprint iswlower iswupper iswspace towlower towupper wctype iswctype wctrans towctrans 16.15 Supported C library functionsThe following C library functions are currently provided by Reactis for C Plugin. assert.h assert ctype.h isalnum isalpha isascii iscntrl iscsym iscsymf isdigit isxdigit isprint isgraph ispunct islower isupper isspace isblank toint tolower toupper errno.h strerror fenv.h fegetround fesetround math.h acos sqrt sin cos tan asin acos atan atan2 exp exp2 pow ln log log2 log10 sinh cosh tanh acosf sqrtf sinf cosf tanf asinf acosf atanf atan2f expf exp2f powf lnf logf log2f log10f sinhf coshf tanhf acosl sqrtl sinl cosl tanl asinl acosl atanl atan2l expl exp2l powl lnl logl log2l log10l sinhl coshl tanhl memory.h bcopy memccpy setjmp.h longjmp setjmp stdarg.h va_start va_arg va_copy va_end stddef.h offsetof stdlib.h malloc calloc realloc free abs labs llabs div ldiv lldiv atof atoi atol atoll strtof strtod strtold strtol strtoll strtoul strtoull exit _Exit abort getenv bsearch qsotr mblen mbtowc mbstowcs wcstombs rand srand string.h memchr memcmp memcpy memmove memset strlen strchr strcpy strncpy strcat strncat strcmp strncmp strspn strcspn strpbrk strtok strcoll strxfrm strdup strndup tgmath.h sin cos tan sinh cosh tanh asin acos atan exp exp2 sqrt cbrt ln log log2 erf erfc lgamma tgamma expm1 ilogb log1p fabs ceil floor nearbyint rint lrint round lround trunc atan2 pow copysign fdim hypot fmin fmax fmod remainder nextafter nexttoward frexp ldexp modf scalbn scalbnln remquo
| |||||||||||||||||||