NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

TestStand TestData API for Test Report Output

I would like to include some data in my TestStand (v2.0) test report in addition to the pass/fail result. I have tried the testData->replaceStringFuncPtr method of inserting a string to the report. However, I have had mixed success. Many strings cause TestStand to error or even terminate.

The following is successful:
sprintf(test_info, "My grounding test info 6\nNew line\nAnother\nAnd another!\n");
testData->replaceStringFuncPtr(&testData->outBuffer, test_info);

The following is an example of code causing an error:
sprintf(test_info, "aaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaaaaa");
testData->replaceStringFuncPtr(&testData->outBuffer, test_info);

Do you have any suggestions? Is there an API availa
ble for tTestData? I would like to know what the maximum string length is and also what type of formatting is allowed (i.e., "\t" for tabs).

Thanks!
0 Kudos
Message 1 of 9
(4,869 Views)
I'm not quite sure why the second example you gave is not working in your case, as the very same code seems to work fine for me. I have included a .zip file containing a sequence file with a sequence that calls a LabWindows/CVI .dll function utilizing the same code as you specified. Run it with the Sequential Process Model's Single Pass entry point, and you will see the string you specified show up in the "ReportText" for the step.

There really isn't an API for the tTestData structure as it really has a specific functionality defined within itself for passing test data back and forth from TestStand to your code modules and include any additional data in the inBuffer, outBuffer, and so on. For more information on how to use the tTestData structure you shou
ld look at the section in the TestStand User Manual (accessible under the Sequence Editor's Help Menu) entitled "Chapter 13 Module Adapters >> C/CVI Standard Prototype Adapter".

As for the formatting options available for the Result.ReportText string that is to be placed in the report, this is provided within the "PutOneResultInReport" sequence used by the sequential process model. If you are using the html report option, you can see in that sequence under the "Add ReportText (OutBuffer)" step that the expression is using the "FindandReplace" expression function to replace all "\n" newline escape characters with the appropriate "
" html markup (this appears to be the only escape character that is handled in the ReportText string). If you want to add extra formatting for things such as "\t" tab escape characters, you can simply change this expression statement step to include that.

Jason F.
Applications Engineer
National Instruments
www.ni.com/ask
0 Kudos
Message 2 of 9
(4,869 Views)
Question: Do you know if there is a limit to the size of the outBuffer char array?

Thanks for your reply. I was able to solve the problem and do ample formatting with your assistance.

Allan
0 Kudos
Message 3 of 9
(4,869 Views)
There isn't a set limit, but rather a theoretical one based on your system's capabilities. When you use outBuffer, TestStand is going to copy whatever you place into it in the Step.Result.ReportText string variable. Whenever the process to do this copy hits a limit when malloc'ing memory to carry it out, you've hit the maximum size of data. Try using the mallocFuncPtr member of tTestData to malloc a huge chunk of memory to be copied into outBuffer with replaceStringFuncPtr in a loop (remembering to free what you receive) with an ever increasing size request, and see where you max out at.

Jason F.
Applications Engineer
National Instruments
www.ni.com/ask
0 Kudos
Message 4 of 9
(4,869 Views)
Thanks for the recommendations. I have a couple new questions:

1. Is there an advantage to using a char* and mallocFuncPtr versus a char array in TestStand? I may need to use large strings in my test report and would like to know if there are certain memory considerations that I should be aware of when using TestStand.

2. Is there a special purpose for mallocFuncPtr? How does this differ from using malloc? (The documentation seems to indicate that mallocFuncPtr is a pointer to malloc.)
0 Kudos
Message 5 of 9
(4,869 Views)
Here's the answers to your latest questions:

1) If you use a char array in your code module, its size is fixed to the constant you specify, malloc allows you to dynamically select the size of the buffer you want to use at run-time. The memory concerns should still be thought of and addressed in the same fashion as I mentioned in my other post.

2) It doesn't really matter which one you use as long as you remember to properly free what you allocate before your function exits. If you don't then you will have a memory leak.

Jason F.
Applications Engineer
National Instruments
www.ni.com/ask
0 Kudos
Message 6 of 9
(4,869 Views)

Hi,

 

 

I have question to the following sentence from the last message:

 

--------------------------------

2) It doesn't really matter which one you use as long as you remember to properly free what you allocate before your function exits. If you don't then you will have a memory leak.

--------------------------------


I wonder how to free the memory properly?!  Because the "malloc" is used to allocate buffer spaces to a pointer parameter that passes back to TestStand, and thus, therefore, I am a bit puzzled on where to put the "free" function.

 

 

Peggy

 

0 Kudos
Message 7 of 9
(4,307 Views)

"2) It doesn't really matter which one you use as long as you remember to properly free what you allocate before your function exits. If you don't then you will have a memory leak."

 

This is incorrect. The purpose of these function pointers is to allow you to reallocate the buffers such that TestStand can still free them. For inBuffer,outBuffer, and errorMessage do not use malloc, instead use the function pointers the structure provides. Your malloc doesn't necessarily work with TestStand's free. In fact, with or without TestStand, malloc and free are not necessarily compatible across DLL boundaries depending on the versions, vendors, and certain compiler settings for the pair of C libraries involved. 

Message Edited by James Grey on 03-17-2010 05:28 PM
0 Kudos
Message 8 of 9
(4,299 Views)

I am getting more confused now.  So, say the following code would be incorrect?!

 

 

void DLLEXPORT DLLSTDCALL StringValueTest(tTestData *pTestData, tTestError *pTestError) 

{

     pTestData->stringMeasurement = (char *)malloc(1024);

 

     strcpy(pTestData->stringMeasurement,"my output string");

}

 

 

Peggy

 

 

 

0 Kudos
Message 9 of 9
(4,295 Views)