Highlighted
Absent Member.
Absent Member.
164 views

Using C functions in Service test.

Hi

Can we use user defined functions in HP Service test?

I am trying a simple C addition function and its not working?

int a,b
int addNum(a,b)
{
int result = a + b;

return result;
}

Thanks for your help.
0 Likes
5 Replies
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Using C functions in Service test.

You can use. What is the problem you are facing?
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Using C functions in Service test.

Action()
{
int add(int a,int b)
{
int result = (a+b);
return result;
}

int result2 = add (5,3);

lr_log_message( "We are on iteration #%s", lr_eval_string( "{result2}" ) );

return 0;
}

Above is the code i am using in main Action in service test and i am getting the below errors.

Action.c (6): syntax error; found `{' expecting `;'
Action.c (6): skipping `{'
Action.c (7): undeclared identifier `a'
Action.c (7): undeclared identifier `b'
Action.c (8): illegal expression
Action.c (8): syntax error; found `a' expecting `)'
Action.c (8): syntax error; found `a' expecting `)'
Action.c (8): syntax error; found `a' expecting `;'
Action.c (8): syntax error; found `}' expecting `;'
Action.c (8): unrecognized declaration
Action.c (8): unrecognized declaration
Action.c (8): warning: empty declaration
Action.c (9): unrecognized declaration
Action.c (10): unrecognized declaration
Action.c (12): initializer must be constant
Action.c (18): syntax error; found "We are on iteration ... expecting `)'
Action.c (18): skipping "We are on iteration ... `,' `lr_eval_string' `(' "{result2}"
Action.c (18): redeclaration of `lr_log_message' previously declared at C:\\Program Files\\HP\\Service Test\\include/lrun.h (504)
Action.c (18): syntax error; found `)' expecting `;'
Action.c (18): skipping `)'
Action.c (20): unrecognized declaration
Action.c (20): too many errors

Where do i place the function block and how do i call the function in my actions?
0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Using C functions in Service test.

Move it outside of Action section. It should be ....

int add(int a,int b)
{
int result = (a+b);
return result;
}

Action()
{

lr_output_message(">>>> %d <<<<", add(5,6));
return 0;
}
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Using C functions in Service test.

Thank you ! it works but i am getting different error

Action.c(10): Error: C interpreter run time error: Action.c (10): Error -- memory violation : Exception ACCESS_VIOLATION received.

Action.c(10): Notify: CCI trace: Action.c(10): lr_log_message(0x03180149 "We are on iteration #%s", 😎
.
Action.c(10): Notify: CCI trace: Compiled_code(0): Action()

My Code:
Action()
{
lr_log_message( "We are on iteration #%s", add (5,3));
return 0;
}

int add(int a,int b)
{
int result = (a+b);
return result;
}
0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Using C functions in Service test.

In correct usage. Try this.
Action()
{
lr_log_message( "We are on iteration #%d", add (5,3));
return 0;
}

int add(int a,int b)
{
int result = (a+b);
return result;
}
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.