TPF_TESTCASE: Define a test case

This C/C++ macro defines a test case in the automated test framework.

Last updated

Added for PUT15.

Format

maketpf_env += idevops
#include <tpf/c_devops.h>
TPF_TESTCASE(name, description) { code }
name
A non-quoted name that identifies the test case. The name must be unique across all source files within the shared object.
description
A brief description of the test case.
code
The C/C++ code to be processed as part of the test case.

Normal return

None.

Error return

None.

Programming considerations

  • Do not use this macro in production applications.
  • You must define a TPF_TESTSUITE entry in exactly one source file of a C shared object (CSO) that contains test cases.
  • The name and description are included in the list of test cases that is displayed when the ZDEVO INFO command is entered.

Examples

The following example shows the infrastructure for defining a basic test case.

TPF_TESTCASE(name1, “my first test case”)
{
…
TPF_TC_INFO("Hello World");
return;
}

The following example defines a test case that potentially generates an error or informational message and returns.

TPF_TESTCASE(test_gethostid, "Tests the gethostid API") {
   int defaultIP = gethostid();
   if (defaultIP == BAD_RC)  {
       TPF_TC_ERROR("ERROR:  gethostid failed, errno-%d",sock_errno());
   }
   else {
       struct   in_addr in = *((struct in_addr*) (&defaultIP));
       TPF_TC_INFO("gethostid success, return - %s",inet_ntoa(in));
   }
   return;
}

The following example validates that the calloc function returns initialized fields. Informational, error, and debug messages are potentially generated as part of the test case.

TPF_TESTCASE(calloc1,"Validate calloc returns initialized fields") {
   char* area = calloc(10);
   if (area != NULL) {
      TPF_TC_DEBUG("Calloc returned pointer %p",area);
      int i; 
      for (i = 0; i < 10; i++) {
         if (area[i] != 0) {
            TPF_TC_ERROR("calloc not init'd at position %d, found 0x%X, expected 0x00", i, area[i]);
            TPF_TC_INFO(" followed by: %s", &area[i+1]);
            break;
         }
      }
      if (i == 10) {
         TPF_TC_INFO("Validated full calloc");
      }
   } else {
      TPF_TC_ERROR("Calloc returned NULL\n");
   }
   // TPF_TC_ERROR will mark test case failed if appropriate
   return;
}