Using Test Script Services from an External C or C++ Program

prevnext

Connecting to a TestManager Listener Port


Rational does not provide a built-in test script type for C or C++ test scripts. You can, however, directly call the test script services documented in Chapter 3 from a C or C++ program and run the program from TestManager as a Command Line test script. TestManager displays the test results if you:

An example follows. The lines that attach to a TestManager listener port are shown in bold. If you saved this program to a file named emulmany.c, here's how you would compile and link the program:

cl /I "%ratl_rthome%\rtsdk\c\include" /c emulmany.c
link /out:emulmany.exe emulmany.obj 
"%ratl_rthome%\rtsdk\c\lib\rttssremote.lib"

To run the program, follow the instructions in Running a Test Script with the Command Line Adapter. Alternatively, to be able to access C or C++ test scripts for viewing or editing as well as for execution from TestManager's File pull-down menu selections, you can create a new test script type for your C or C++ test scripts: see Adding a Command Line Test Script Type.


Example: Attaching to a TestManager Listener Port


* This program demonstrates how to use the Test Script Services 
(TSS)
 * from a C program.
 *
 * The program is designed to run as a command line script under 
TestManager.

#include <stdlib.h>
#include <stdio.h>
#include "rttss.h"

char    emul_logmsg[512];

typedef struct info {
    char *host;
    u16 port;
    s32 vtid;
} info_t;

int
uniform_delay(int mindly,
              int maxdly,
              int pctpass) {
    s32 dly;
    s32 pass;

    dly = TSSUniform(mindly, maxdly);
    pass = TSSUniform(1,100) < pctpass;
    sprintf(emul_logmsg, "uniform_delay(%d, %d, %d) delayed %d and 
%s.",
            mindly, maxdly, pctpass, dly,
            pass ? "passed" : "failed");
    TSSDelay(dly);
    return pass;
}


int main(int argc, char *argv[]) {
    s32 rc;
    s32 pass;
    EvarValue evalue;
    int i;
    char *s;
    info_t      thinfo;                 /* Parent program host/port     
*/


    /* Get connect info from the environment. */

    if (s = getenv("RTTSS_HOST"))
	 thinfo.host = s;
    else {
	 fprintf(stderr, "Environment variable RTTSS_HOST is not 
defined\n");
	 exit(1);
    }
    thinfo.port = 0;
    if (s = getenv("RTTSS_PORT"))
	 thinfo.port = (u16) strtoul(s, NULL, 10);
    thinfo.vtid = 0;
    if (s = getenv("RTTSS_VTID"))
	 thinfo.vtid = strtol(s, NULL, 10);

    if ((rc = TSSConnect(thinfo.host, thinfo.port, thinfo.vtid)) != 
TSS_OK) {
        fprintf(stderr, "TSSConnect failed\n");
        exit(-1);
    }


    evalue.envStr = "NEGEXP";
    TSSEnvironmentOp(EVAR_Think_dist, EVOP_set, &evalue);
    evalue.envInt = 100;
    TSSEnvironmentOp(EVAR_Think_dly_scale, EVOP_set, &evalue);
    evalue.envInt = 3000;
    TSSEnvironmentOp(EVAR_Think_avg, EVOP_set, &evalue);

    for (i = 0; i < 1; i++) {
        TSSCommandStart("step001", "step001", MST_DELAY);
        pass = uniform_delay(10, 100, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step001 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step002", "step002", MST_DELAY);
        pass = uniform_delay(100, 200, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step002 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step003", "step003", MST_DELAY);
        pass = uniform_delay(200, 300, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step003 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step004", "step004", MST_DELAY);
        pass = uniform_delay(300, 400, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step004 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step005", "step005", MST_DELAY);
        pass = uniform_delay(400, 500, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step005 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step006", "step006", MST_DELAY);
        pass = uniform_delay(500, 600, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step006 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step007", "step007", MST_DELAY);
        pass = uniform_delay(600, 700, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step007 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step008", "step008", MST_DELAY);
        pass = uniform_delay(700, 800, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step008 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step009", "step009", MST_DELAY);
        pass = uniform_delay(800, 900, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step009 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step010", "step010", MST_DELAY);
        pass = uniform_delay(900, 1000, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step010 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step011", "step011", MST_DELAY);
        pass = uniform_delay(1000, 1100, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step011 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step012", "step012", MST_DELAY);
        pass = uniform_delay(1100, 1200, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step012 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step013", "step013", MST_DELAY);
        pass = uniform_delay(1200, 1300, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step013 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step014", "step014", MST_DELAY);
        pass = uniform_delay(1300, 1400, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step014 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step015", "step015", MST_DELAY);
        pass = uniform_delay(1400, 1500, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step015 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step016", "step016", MST_DELAY);
        pass = uniform_delay(1500, 1600, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step016 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step017", "step017", MST_DELAY);
        pass = uniform_delay(1600, 1700, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step017 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step018", "step018", MST_DELAY);
        pass = uniform_delay(1700, 1800, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step018 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step019", "step019", MST_DELAY);
        pass = uniform_delay(1800, 1900, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step019 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step020", "step020", MST_DELAY);
        pass = uniform_delay(1900, 2000, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step020 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step021", "step021", MST_DELAY);
        pass = uniform_delay(2000, 3000, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step021 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step022", "step022", MST_DELAY);
        pass = uniform_delay(3000, 4000, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step022 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step023", "step023", MST_DELAY);
        pass = uniform_delay(4000, 5000, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step023 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step024", "step024", MST_DELAY);
        pass = uniform_delay(5000, 6000, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step024 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step025", "step025", MST_DELAY);
        pass = uniform_delay(6000, 7000, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step025 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step026", "step026", MST_DELAY);
        pass = uniform_delay(7000, 8000, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step026 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);

        TSSCommandStart("step027", "step027", MST_DELAY);
        pass = uniform_delay(8000, 9000, 90);
        TSSCommandEnd(pass ? TSS_LOG_RESULT_PASS : 
TSS_LOG_RESULT_FAIL,
                      "step027 failed",
                      0,
                      0,
                      emul_logmsg,
                      0,
                      NULL);
    }
}

prevnext


Rational TestManager Extensibility Reference Rational Software Corporation
Copyright (c) 2003, Rational Software Corporation http://www.rational.com
support@rational.com
info@rational.com