迁移将C代码从IDE写入LoadRunner的文件时,我们需要进行哪些修改?

时间:2016-08-18 11:37:13

标签: c loadrunner

以下代码在Codeblocks IDE中运行良好。当我将它粘贴到LoadRunner中的action()时,它会产生以下编译错误:

  

Action.c(7):未声明的标识符FILE'

     

Action.c(7):未声明的标识符fptr'd:\ bits \ heyo \\

     

combined_heyo.c(5):2个错误,不写pre_cci.ci

这是我的代码:

#include "stdio.h"

int main() {
    char c[1000] = {"abcd"}; //Initialize a character array
    FILE *fptr;
    fptr=fopen("c:\\program.txt","w");
    if(fptr==NULL){
        printf("Error!");
        exit(1);
    }
    fprintf(fptr,"%s",c);
    fclose(fptr);
    return 0;
}

2 个答案:

答案 0 :(得分:0)

在加载时从虚拟用户编写文件是一个非常糟糕的主意。它不仅是该用户,而且是运行该虚拟用户的所有用户。您将对数十/数十/数百个用户的写头访问进行大规模争用。这也会将本地文件系统变成负载生成器的瓶颈。

考虑将您编写的数据放在基于外部服务的存储库(例如队列)中,您可以根据需要将其从中提取。导致在测试期间写出数据的最常见的愿望是将数据传递给另一个用户。如果这是您的愿望,请考虑RabbitMQ或类似的

答案 1 :(得分:0)

/*my mistake was that i used FILE instead of long, this is because the structure file is included in "stdio.h" file which cant be included by typing # include statement in loadrunner , this was caught when i saw th function reference for fprintf() in loadrunner help. Although this code works but should be avoided running with multiple users (see james pulley answer for more details)*/

/*corrected code*/




vuser_init()
{
char *filename = "c:\\helloworld.txt";
char c[1000] = {"abcd"};

long file;

   file=fopen(filename,"w");



   fprintf(file,"%s",c);

   fclose(file);

return 0;
}