How to include C library in Loadrunner

1,439 views
Skip to first unread message

Krishnakanth PPS

unread,
May 25, 2010, 8:13:55 AM5/25/10
to LR-Loa...@googlegroups.com
Hi.

I need to write a code to upload a file through sftp.

I want to call a libcurl.dll through a dll file. I am pasting a script from http://curl.haxx.se/libcurl/c/ftpupload.html and trying to make modifications to these to suit my requirements.

But then, loadrunner include files do not have the below files and thus getting an error. 
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
Has anyone tried doing such an upload by creating function that upload a file to sftp server or by creating a dll which calls the libcurl.dll file and the libssh2.dll file
Thanks for any help.
Krishna Kanth 

--
You received this message because you are subscribed to the Google "LoadRunner" group.
To post to this group, send email to LR-Loa...@googlegroups.com
To unsubscribe from this group, send email to
LR-LoadRunne...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/LR-LoadRunner?hl=en

Anaz Mohamed

unread,
May 25, 2010, 8:30:42 AM5/25/10
to lr-loa...@googlegroups.com
Use Global.h
--
Regards,
Anaz

chaitanya bhatt

unread,
May 25, 2010, 8:35:18 AM5/25/10
to lr-loa...@googlegroups.com
The 'Missing dependency' issue can be resolved by including glibc libarary( GNU standard C libarary). Its open source. Google the string "glibc" and click the first link to download the files from the internet.
 
-Chaitanya M Bhatt

John Crunk

unread,
May 25, 2010, 9:02:13 AM5/25/10
to lr-loa...@googlegroups.com
You should be able to use FTP protocol to do this without the libraries. Have you tried it or mixing FTP and http?

John Crunk Ph.D ABD
Sent from my iPhone

Krishnakanth PPS

unread,
May 25, 2010, 9:22:48 AM5/25/10
to lr-loa...@googlegroups.com
FTP and FTPS use the ssl protocol and the SFTP uses ssh protocol.

And it is a sftp server, so I need to use the sftp protocol. 

Mixing ftp and http, I believe you are talking about the system command in LR, we have that solution which has been decided as a workaround solution in case this C code solution doesnt work. 

Let me try other options. 

pablomar

unread,
May 25, 2010, 9:35:43 AM5/25/10
to lr-loa...@googlegroups.com
and what about if you build a dll and put whatever you want in it (and you don't need to worry about the "particularities" of loadrunner ... sorry, this morning I'm too tired of loadrunner and its buggy RDP protocol)

coming back to your question: if you create a dll, then you have to load it in loadrunner and just use it (ok, and install the dll on every Load Generator ... that's a little painful, but it's gonna be a cleaner solution, I guess)

I can give you examples for it

Krishnakanth PPS

unread,
May 25, 2010, 9:44:22 AM5/25/10
to lr-loa...@googlegroups.com
I am looking at creating a dll, but then there would be a dependency on libcurl.dll and the libssh2.dll and I have put them in every load generator. 

My problem starts with this error message.

Action.c:4: stdio.h: No such file or directory
Action.c:5: string.h: No such file or directory
Action.c:10: fcntl.h: No such file or directory
Action.c:11: errno.h: No such file or directory
Action.c:15: unistd.h: No such file or directory

I actually downloaded opensource C++ compilers like Pelles C and CodeLite and even MinGW and tried to include the location of the above mentioned .h files, but then there is a deeper dependency inside the other cURL files. which gives me even more errors.

Thats why I want to build a dll of the sftp upload C code, which call the libcurl and the libssh2.dll files. and all I need to do is to place them in all the LGs. Thank god my load is not going to be beyond 500 users.

Thank you for all your suggestions . Please keep them coming.


pablomar

unread,
May 25, 2010, 10:02:52 AM5/25/10
to lr-loa...@googlegroups.com
I use the free version of Microsoft Visual C++ (express edition) when I need to build a dll, not big deal

do you wanna try ? 
the secret is in the .h, here we go:

#ifndef _krishnakanth_H
#define _krishnakanth_H

#ifdef __cplusplus
extern "C" {
#endif


#ifdef WIN32
// to compile the dll
#define EXPORT __declspec(dllexport)

#else
// to be used for loadRunner
#define EXPORT extern
#endif

EXPORT int yourFunction1(char *param1, char *param2, int param3);
        EXPORT int yourFunction2(char *param1, char *param2, int param3);
        EXPORT int yourFunction3(char *param1, char *param2, int param3);


#ifdef __cplusplus
}
#endif


#endif


and then, the .cpp:

#include "stdafx.h"
#include "krishnakanth.h" // your own .h
#include "lrun.h" // from loadrunner
#include <stdio.h>
#include <string.h>
#include <stdlib.h>



// needed for the dll
int WINAPI DllMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
return 0;
}

extern "C" __declspec(dllexport) int yourFunction1(char *param1, char *param2, int param3)
{
//what ever you need to do
}


extern "C" __declspec(dllexport) int yourFunction2(char *param1, char *param2, int param3)
{
//what ever you need to do
}

extern "C" __declspec(dllexport) int yourFunction3(char *param1, char *param2, int param3)
{
//what ever you need to do
}


for the project:
you need to add and additional dependency lrun50.lib (a loadrunner library)
and the path for the loadrunner h files (lrun50.h in this case)


have fun :-)


Krishnakanth PPS

unread,
May 25, 2010, 10:04:57 AM5/25/10
to lr-loa...@googlegroups.com
Scary. But let me try. :)

Thanks a lot :)

pablomar

unread,
May 25, 2010, 10:09:01 AM5/25/10
to lr-loa...@googlegroups.com
sorry, you need to add lib50.lib if you are going to use some loadrunner function inside your dll, you don't need it otherwise

Krishnakanth PPS

unread,
May 25, 2010, 10:17:15 AM5/25/10
to lr-loa...@googlegroups.com
oh ok. but not looking at any lr function inside the dll. 

I dont want to complicate a flex protocol script which invoke 3 dlls one inside the other and then call a lr function from inside the dll. No way :).

Let me get through the first piece of code first :)

pablomar

unread,
May 25, 2010, 11:03:25 AM5/25/10
to lr-loa...@googlegroups.com
ok, let's do it step by step.

1_ install MS Visual C++ express edition
2_ create a dll with a dummy function, just to add two numbers or something like that
3_ call it from a loadrunner script (something like)


#include "C:\\Users\\Krishna\\Documents\\Visual Studio 2008\\Projects\\krishna\\krishna\\krishna.h" // your actual path here

vuser_init()
{
    lr_load_dll("C:\\Users\\Krishna\\Documents\\Visual Studio 2008\\Projects\\krishna\\Debug\\krishna.dll"); // here as well
    return 0;
}

Action.c
{
    lr_message("we got = %d", yourFunction1(2, 2) ); // call to your dummy function

James Pulley

unread,
May 25, 2010, 11:48:57 AM5/25/10
to lr-loa...@googlegroups.com

If you’re going to build a DLL, you might as well go all the way and inherit the LoadRunner parameterization engine and timing functions.   See the Vugen manual, advanced concepts, creating virtual users with Visual Studio.   It’s a short section, maybe 20 pages, but there is gold there given the path you are headed down.

 

James Pulley

========================================================

http://www.loadrunnerbythehour.com  

Fixed rate, defined deliverables, onshore USA trained and mentored staff

http://www.thescriptfarm.com

Project-based, negotiated deliverables, off site and on shore

http://www.PowerTest.com

Onsite Consulting, SQA Architecture and Process

=========================================================

Krishnakanth PPS

unread,
May 25, 2010, 12:20:01 PM5/25/10
to lr-loa...@googlegroups.com
Hi James.

Why would I need to inherit the LR param engine and the timing functions, when all I am doing is creating a dll that uploads a file to an sftp server?

It is just a flex protocol script, which has a upload file action which is not being recorded by the application, so we are writing a custom c code which uploads it to a sftp server. 

James Pulley

unread,
May 25, 2010, 12:43:25 PM5/25/10
to lr-loa...@googlegroups.com

Multiple distinct files representing the distinct action of multiple users?  (Read the parameter name from a file plus the ability to time how long it takes to upload the file??)

Krishnakanth PPS

unread,
May 25, 2010, 12:51:12 PM5/25/10
to lr-loa...@googlegroups.com
Yes. We are not really ( we may) looking at response times of the uploading capability, but trying to figure what would be impact on network when a n  number of users start uploading a file each. There is a bandwidth comes into the picture here. 

I was told libcurl does it really fast, so we are sort of keen on using libcurl. 

The flex protocol did not record the uploading of the file, but recorded the pushing it from sftp server to the app server. 

So thats the scenario.

James Pulley

unread,
May 25, 2010, 1:01:06 PM5/25/10
to lr-loa...@googlegroups.com

Then perhaps you need a network test tool, not an application test tool.   I recommend IxChariot from Ixia Communications.   The “thunk time” for a LoadRunner professional to pick up and run with IxChariot is roughly a half a day.   As a plus the transfer is memory on host A to memory on host B, so you don’t have to worry about the overhead of disk writes or other service processing overhead for representing file transfers.

 

Plus, for a given number of virtual users it is less expensive than LoadRunner…

Krishnakanth PPS

unread,
May 25, 2010, 1:44:27 PM5/25/10
to lr-loa...@googlegroups.com
Cool. but we have about 30 scripts of which 5 are flex based, and of which 1 script has this particular upload issue.

So going for Ixia would not be a good option.

I can create a batch file that uploads files into sftp and check the network usage as a background noise to find out whats the impact. 

We have a workaround of using a system( command) { which I believe was suggested by you in one of my previous emails}, but we are sort of looking at seeing how we can figure out using curl library inside the script.

if nothing works we fall back on system command, as I have a backup script ready which uses the system command option :).

Krishnakanth PPS

unread,
May 25, 2010, 1:45:19 PM5/25/10
to lr-loa...@googlegroups.com
I am really really looking at having a hands on Ixia and Spirient, but havent got a really really valid business case so far ;). 
Reply all
Reply to author
Forward
0 new messages