|
![]() |
Using expect-lite as a TCL Libraryexpect-lite can now can run in two modes: standalone, and library-mode. In library-mode expect-lite be used within a TCL (Tool Command Language) program.What this means is that expect-lite can be called programmatically from TCL, allowing the integration of the ease of expect-lite scripting with a more complex TCL-based regression system. An example TCL program, test_el_lib.tcl, using library-mode is included in the tarball. In keeping with the principle of 'keeping it simple', the goal is allow expect-lite scripts to be used unchanged, or with minimal changes, in a native TCL environment. Important differences from standalone mode are described below. The expect-lite library seeks to leverage the ease of expect-lite scripting with easy integration into a more complex TCL environment. Applications Programmers Interface (API)As part of playing well with other TCL software, a majority of expect-lite has been encapsulated in a TCL namespace, expectlite (TCL does not permit dash in a namespace name). This prevents procedure- (or functions) and variable-name collisions with other TCL code.The API includes the following functions, listed in typical order of use:
Details & examples of the APIIncluded in the expect-lite tarball is the file test_el_lib.tcl. The example program, is a hybrid script, part TCL, and part expect-lite. The API functions are listed below in more detail, and are listed without the namespace name: expectlite for brevity._el_init_libraryUsed to initialize the expect-lite library, loads the expect library, and optionally can take a list of expect-lite constants (read-only variables) as name value pairs in the form of var=value, and expect-lite directives.Example: _el_init_library "*EXP_INFO IP=10.5.5.5 *DEBUG" _el_import_session_idsThe TCL program may have previously created expect sessions which would be used in the expect-lite script. Session names are imported into the expect-lite *FORK sessions, and the expect-lite script will have access to use the session names defined by the program.Since TCL can not pass arrays, the array of sessions is passed as a list (via [array get session]). Example: # create spawn sessions and set prompt to identify the session _el_import_constAs mentioned earlier, it is possible to pass expect-lite constants and directives via _el_init_library call. However that can only be called once. It may be more desirable to create a loop where TCL variables are imported into expect-lite. The _el_import_const function that does this can be called many times.Example: _el_import_const "DUT=mydut *NOFAIL" _el_buffer
This function is used to read a file into expect-lite's private command
buffer space. In the included example test_el_lib.tcl, the TCL file itself is
read into _el_buffer. Since any line that does not begin with
expect-lite's punctuation characters is ignored, all the TCL in the
test program will be ignored. |