Handling Uninitialized Input Values in Test Cases

Question:
What value will VectorCAST assign to uninitialized input values in test cases?
Answer:
The automatically generated VectorCAST harness code does not do any initialization of test case input values that are not explicitly set in the test case. This is intentional, and allows for several different usage scenarios. Among these:
 
  1. It allows testing of "real world" behavior when functions are called with uninitialized data 
     
  2. It allows test cases to "inherit" data from previously executed code (i.e. startup code, initialization user code, or previous slots in a compound test case)
     
 
Despite the fact that VectorCAST code does not initialize these parameters, however, there are several factors that may influence the initialization of test case parameters: 

--

  1. In most operating environments, the processor startup code, operating system and/or C library will clear BSS and heap memory (as well as possibly other areas of memory) prior to main(). 
     
  2. For C++, the language standard explicitly requires that all uninitialized globals be initialized to zero prior to main(). 
     
  3. Certain VectorCAST features such as user code and automatic initialization test cases can be used to initialize memory and/or input parameters prior to execution of a test case. 

     
All of these behaviors are highly environment dependent, however, it is generally best not to assume that uninitialized values have any particular value. For example, some compilers do not automatically clear memory on startup, and instead leave that up to the end user. In such cases you will need to link extra startup code into your VectorCAST environment to create this behavior. (In most cases you can copy this startup code from your application.)

 
Another thing to consider with regards to uninitialized input values is whether the test case is the first one to run in the test harness. As mentioned above, some features of VectorCAST -- like compound test cases and range/list iterations -- allow multiple executions of test case or different test cases within a single harness execution. In these scenarios only the first test case executed will get the "default" values for uninitialized inputs. Subsequent test case executions will "inherit" any parameter values modified by previous test cases (neither the target nor the test harness are reset during the compound execution). This behavior is useful for setting up complex test scenarios, but can occasionally be confusing for users unfamiliar with the tools. 

 
So to summarize, if your test case depends on a value, you should explicitly set that value in the test case's "Input Values" column.
 


Article ID: 1513
Last updated: 2019-11-13
Revision: 2
VectorCAST -> C++ Unit Testing -> Handling Uninitialized Input Values in Test Cases
https://kb.vector.com/entry/1513/