如何从LoadRunner生成与操作系统无关的通用唯一IDentifier UUID [英] How to generate Universally Unique IDentifier, UUID from LoadRunner independent of the OS

查看:244
本文介绍了如何从LoadRunner生成与操作系统无关的通用唯一IDentifier UUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在脚本编写时,我已经经历过几次在LoadRunner中生成UUID的需求,但是没有内置函数可以这样做.我同时使用linux和Windows负载生成器.

I have experienced the need of generating UUID in LoadRunner several times while scripting but there is no in-build function to do so. I am using both linux and windows load generators.

感谢Scott Moore编写了以下代码,该代码使用Windows内置CoCreateGuid函数(取决于ole32.dll)来生成所需的UUID.但是,该代码完全取决于Windows平台,在Linux平台上不起作用.

Thanks to Scott Moore for writing the below code which uses windows in-build CoCreateGuid function (dependent on ole32.dll) to generate required UUID. However that code is completely dependent on windows platform and doesn't work in Linux platform.

如何从独立于操作系统的Loadrunner生成UUID?

How can we generate UUID from Loadrunner independent of OS?

    #include "lrun.h"
    #include "web_api.h"
    #include "lrw_custom_body.h"
    #include "stdlib.h"
    #include "stdio.h"
    #include "string.h"
    int lr_guid_gen()
    {
        typedef struct _GUID
        {
            unsigned long Data1;
            unsigned short Data2;
            unsigned short Data3;
            unsigned char Data4[8];
        } GUID;

        GUID m_guid;
        char buf[50];

        lr_load_dll ("ole32.dll");

        CoCreateGuid(&m_guid);

        sprintf (buf, "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
        m_guid.Data1, m_guid.Data2, m_guid.Data3,
        m_guid.Data4[0], m_guid.Data4[1], m_guid.Data4[2], m_guid.Data4[3],
        m_guid.Data4[4], m_guid.Data4[5], m_guid.Data4[6], m_guid.Data4[7]);

        lr_save_string(buf, "PAR_GUID");

        return 0;
    }

推荐答案

您可以使用以下技巧,不需要任何代码. 定义一个十六进制参数,如下所示:

You can use the following trick which doesn't require any code. Define a hex parameter as follows:

然后将其与以下代码一起使用: lr_eval_string("{MyHex}{MyHex}-{MyHex}-{MyHex}-{MyHex}-{MyHex}{MyHex}{MyHex}")

Then use it with this code: lr_eval_string("{MyHex}{MyHex}-{MyHex}-{MyHex}-{MyHex}-{MyHex}{MyHex}{MyHex}")

这篇关于如何从LoadRunner生成与操作系统无关的通用唯一IDentifier UUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆