Highlighted
Absent Member.. Absent Member..
Absent Member..
3877 views

Writing a library of functions for use in LoadRunner scripts.

Jump to solution

I would like to write a couple of custom functions that will be used in my Vuser scripts.  The functions are basic and will use only standard C functions already supported by LoadRunner: string, file, math, etc.

 

I have read through several sources of information pertaining to this subject including the LoadRunner documentation and material on the Internet.  These sources provide useful information to varying degrees.  That is: they are too vague, incomplete, or more complicated than my needs require.  My challenge is magnified by the fact that I am writing Vuser scripts on Windows that will run on a Linux Load Generator.

 

Any suggestions for a suitable method that would allow me to write a couple of functions that would: A.) read content from a file and B.) generate a string of random characters?  I would like to be able to use the functions in different scripts without copying/pasting the code.  However, while not ideal, I can certainly manage that.

 

Thanks in advance.

 

Brian

0 Likes
1 Solution

Accepted Solutions
Highlighted
Honored Contributor.
Honored Contributor.

Re: Writing a library of functions for use in LoadRunner scripts.

Jump to solution

Hello Brian,

 

What you basically need to do is the following:

1. Create a custom .h file, let's say "myfunctions.h". Example:

#ifndef _MYFUNCTIONS_H_
#define _MYFUNCTIONS_H_

int doSomething(int nArg1, int nArg2)
{
     return nArg1 + nArg2;
}

#endif // _MYFUNCTIONS_H_

2. Put all your custom code in this "myfunctions.h" file.

3. Put the "myfunctions.h" file in a shared network location, for example in "/var/lib/bar" on Linux or in "C:\lib" on Windows

 

Now you have a function library. This "myfunctions.h" library can be included and reused in all your scripts so that you don't need to copy-paste the same code for every new VuGen script you create.

 

To make the "myfunctions.h" library part of your scripts you need to "include" it in your scripts:

3. Create a new VuGen script (or open an existing one)

4. In VuGen open "globals.h" file for editin (the file is part of any C-based script)

5. Add an "#include" directive for the "myfunctions.h", for example:

#ifdef LR_UNIX // If running on Linux - include the file from this folder
#include "/var/lib/bar/myfunctions.h"
#endif

#ifndef LR_UNIX // If not running on Linux (i.e. running on Windows) - include the file from this folder
#include "C:\\lib\\myfunctions.h"
#endif

 

Hope this helps. Let me know if it  works for you.

Igor Markov
R&D Manager, Performance Engineering Core

View solution in original post

4 Replies
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Writing a library of functions for use in LoadRunner scripts.

Jump to solution

Hello Brian

 

Please note that we are break and fix support, and we are disposal to assist you with problems related to LoadRunner, on this case that you are requesting some help on custom code, unfortunately this is out of our scope.

 

 

However, you can search on the Internet how to create your own C code that satisfied your needs.

 

I'm sorry for the inconvenience that this could cause

 

 

Regards,

Daniela Gómez Alvarado
Customer Support Engineer

If you find that this or any other post resolves your issue, please be sure to mark it as an accepted solution.
If you are satisfied with anyone’s response please remember to give them a KUDOS by clicking on the STAR at the bottom left of the post and show your appreciation.
0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Re: Writing a library of functions for use in LoadRunner scripts.

Jump to solution

Hello Daniela,

I believe that helping a customer by guiding him how to create and use a shared function library for multiple LR scripts is exactly in scope of HP support. A customer will write the code himself, but the guidance on where to write it, how to include it efficiently in multiple scripts, and what to do if things don't work, is just the kind of information that needs to be provided here.

Igor Markov
R&D Manager, Performance Engineering Core
Highlighted
Honored Contributor.
Honored Contributor.

Re: Writing a library of functions for use in LoadRunner scripts.

Jump to solution

Hello Brian,

 

What you basically need to do is the following:

1. Create a custom .h file, let's say "myfunctions.h". Example:

#ifndef _MYFUNCTIONS_H_
#define _MYFUNCTIONS_H_

int doSomething(int nArg1, int nArg2)
{
     return nArg1 + nArg2;
}

#endif // _MYFUNCTIONS_H_

2. Put all your custom code in this "myfunctions.h" file.

3. Put the "myfunctions.h" file in a shared network location, for example in "/var/lib/bar" on Linux or in "C:\lib" on Windows

 

Now you have a function library. This "myfunctions.h" library can be included and reused in all your scripts so that you don't need to copy-paste the same code for every new VuGen script you create.

 

To make the "myfunctions.h" library part of your scripts you need to "include" it in your scripts:

3. Create a new VuGen script (or open an existing one)

4. In VuGen open "globals.h" file for editin (the file is part of any C-based script)

5. Add an "#include" directive for the "myfunctions.h", for example:

#ifdef LR_UNIX // If running on Linux - include the file from this folder
#include "/var/lib/bar/myfunctions.h"
#endif

#ifndef LR_UNIX // If not running on Linux (i.e. running on Windows) - include the file from this folder
#include "C:\\lib\\myfunctions.h"
#endif

 

Hope this helps. Let me know if it  works for you.

Igor Markov
R&D Manager, Performance Engineering Core

View solution in original post

Highlighted
Absent Member.. Absent Member..
Absent Member..

Re: Writing a library of functions for use in LoadRunner scripts.

Jump to solution

I am finally circling back to accept this post as a solution.  This post reinforces other solutions that I have seen to this need.

Generally speaking, I would say that this method does not follow the convention typically associated with header (.h) files.  That is, putting implementation code in a header file.  However, it does appear to be a workable solution.

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.