Re: [PATCH 5/5] tests: Add a new test for logging outputs parser

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 16/03/16 13:05, Ján Tomko wrote:
> On Wed, Mar 16, 2016 at 12:05:37PM +0100, Erik Skultety wrote:
>> Now that the logging output parser has been refactored, add a test for its
>> functionality.
> 
> It would be nice to add the test before the refactor, if possible.
> 
>> ---
>>  tests/virlogtest.c | 49 +++++++++++++++++++++++++++++++++++++++++++++----
>>  1 file changed, 45 insertions(+), 4 deletions(-)
>>
> 
>> +static int
>> +testLogParseOutputs(const void *opaque)
>> +{
>> +    int ret = -1;
>> +    const struct testLogData *data = opaque;
>> +
>> +    ret = virLogParseOutputs(data->str);
>> +    if (ret < 0) {
>> +        if (!data->pass) {
>> +            VIR_TEST_DEBUG("Got expected error: %s\n",
>> +                           virGetLastErrorMessage());
>> +            virResetLastError();
>> +            ret = 0;
>> +            goto cleanup;
>> +        }
>> +    } else if (ret != data->count) {
>> +            VIR_TEST_DEBUG("Expected number of parsed outputs is %d, "
>> +                           "but got %d\n", data->count, ret);
>> +            goto cleanup;
>> +    } else if (!data->pass) {
>> +        VIR_TEST_DEBUG("Test should have failed\n");
>> +        goto cleanup;
>> +    }
>> +
>> +    ret = 0;
>> + cleanup:
>> +    virLogReset();
>> +    return ret;
>> +}
>>  
>>  static int
>>  mymain(void)
>>  {
>>      int ret = 0;
>>  
>> -#define DO_TEST_FULL(name, test, str, pass)                                 \
>> +#define DO_TEST_FULL(name, test, str, count, pass)                          \
>>      do {                                                                    \
>>          struct testLogData data = {                                         \
>> -            str, pass                                                       \
>> +            str, count, pass                                                \
>>          };                                                                  \
>>          if (virtTestRun(name, test, &data) < 0)                             \
>>              ret = -1;                                                       \
>>      } while (0)
>>  
>>  #define TEST_LOG_MATCH_FAIL(str)                                            \
>> -    DO_TEST_FULL("testLogMatch " # str, testLogMatch, str, false)
>> +    DO_TEST_FULL("testLogMatch " # str, testLogMatch, str, 0, false)
>>  #define TEST_LOG_MATCH(str)                                                 \
>> -    DO_TEST_FULL("testLogMatch " # str, testLogMatch, str, true)
>> +    DO_TEST_FULL("testLogMatch " # str, testLogMatch, str, 0, true)
>> +
>> +#define TEST_PARSE_OUTPUTS_FAIL(str, count)                                 \
>> +    DO_TEST_FULL("testLogParseOutputs " # str, testLogParseOutputs, str, count, false)
>> +#define TEST_PARSE_OUTPUTS(str, count)                                      \
>> +    DO_TEST_FULL("testLogParseOutputs " # str, testLogParseOutputs, str, count, true)
>> +
>>  
>>      TEST_LOG_MATCH("2013-10-11 15:43:43.866+0000: 28302: info : libvirt version: 1.1.3");
>>  
>>      TEST_LOG_MATCH_FAIL("libvirt:  error : cannot execute binary /usr/libexec/libvirt_lxc: No such file or directory");
>> +    TEST_PARSE_OUTPUTS("1:file:/tmp/foo", 1);
>> +    TEST_PARSE_OUTPUTS("1:file:/tmp/foo  2:stderr", 2);
> 
> virLogParseOutputs not only parses the log outputs, but also registers
> them. This will result in the creation of the /tmp/foo file.
> 
> Please use /dev/null as the file.

Oops, fixed.

> 
> ACK with that change, pushed before the actual refactor.
> 
> Jan
> 

I adjusted all the patches according to your notes, except for patch 4/5
where I didn't split those changes into a separate commit, I modified
the commit message to reflect all the changes, not just adding macros. I
dropped 1/5, since there was nothing left after adjustments and also
moved 4 and 5 to the front (before doing the refactor).

I pushed the series, thank you for review.

Erik

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]