2016-03-15 15:30:20 +01:00
|
|
|
/*
|
|
|
|
* logging unit-tests
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Linaro Ltd.
|
|
|
|
*
|
|
|
|
* Author: Alex Bennée <alex.bennee@linaro.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
2016-08-18 20:46:03 +02:00
|
|
|
#include <glib/gstdio.h>
|
2016-03-15 15:30:20 +01:00
|
|
|
|
|
|
|
#include "qemu-common.h"
|
2016-06-15 19:27:15 +02:00
|
|
|
#include "qapi/error.h"
|
|
|
|
#include "qemu/log.h"
|
2016-03-15 15:30:20 +01:00
|
|
|
|
|
|
|
static void test_parse_range(void)
|
|
|
|
{
|
2016-06-15 19:27:15 +02:00
|
|
|
Error *err = NULL;
|
|
|
|
|
|
|
|
qemu_set_dfilter_ranges("0x1000+0x100", &error_abort);
|
2016-03-15 15:30:20 +01:00
|
|
|
|
|
|
|
g_assert_false(qemu_log_in_addr_range(0xfff));
|
|
|
|
g_assert(qemu_log_in_addr_range(0x1000));
|
|
|
|
g_assert(qemu_log_in_addr_range(0x1001));
|
|
|
|
g_assert(qemu_log_in_addr_range(0x10ff));
|
|
|
|
g_assert_false(qemu_log_in_addr_range(0x1100));
|
|
|
|
|
2016-06-15 19:27:15 +02:00
|
|
|
qemu_set_dfilter_ranges("0x1000-0x100", &error_abort);
|
2016-03-15 15:30:20 +01:00
|
|
|
|
|
|
|
g_assert_false(qemu_log_in_addr_range(0x1001));
|
|
|
|
g_assert(qemu_log_in_addr_range(0x1000));
|
|
|
|
g_assert(qemu_log_in_addr_range(0x0f01));
|
|
|
|
g_assert_false(qemu_log_in_addr_range(0x0f00));
|
|
|
|
|
2016-06-15 19:27:15 +02:00
|
|
|
qemu_set_dfilter_ranges("0x1000..0x1100", &error_abort);
|
2016-03-15 15:30:20 +01:00
|
|
|
|
|
|
|
g_assert_false(qemu_log_in_addr_range(0xfff));
|
|
|
|
g_assert(qemu_log_in_addr_range(0x1000));
|
|
|
|
g_assert(qemu_log_in_addr_range(0x1100));
|
|
|
|
g_assert_false(qemu_log_in_addr_range(0x1101));
|
|
|
|
|
2016-06-15 19:27:15 +02:00
|
|
|
qemu_set_dfilter_ranges("0x1000..0x1000", &error_abort);
|
2016-03-15 15:30:20 +01:00
|
|
|
|
|
|
|
g_assert_false(qemu_log_in_addr_range(0xfff));
|
|
|
|
g_assert(qemu_log_in_addr_range(0x1000));
|
|
|
|
g_assert_false(qemu_log_in_addr_range(0x1001));
|
|
|
|
|
2016-06-15 19:27:15 +02:00
|
|
|
qemu_set_dfilter_ranges("0x1000+0x100,0x2100-0x100,0x3000..0x3100",
|
|
|
|
&error_abort);
|
2016-03-15 15:30:20 +01:00
|
|
|
g_assert(qemu_log_in_addr_range(0x1050));
|
|
|
|
g_assert(qemu_log_in_addr_range(0x2050));
|
|
|
|
g_assert(qemu_log_in_addr_range(0x3050));
|
|
|
|
|
log: Clean up misuse of Range for -dfilter
Range encodes an integer interval [a,b] as { begin = a, end = b + 1 },
where a \in [0,2^64-1] and b \in [1,2^64]. Thus, zero end is to be
interpreted as 2^64.
The implementation of -dfilter (commit 3514552) uses Range
differently: it encodes [a,b] as { begin = a, end = b }. The code
works, but it contradicts the specification of Range in range.h.
Switch to the specified representation. Since it can't represent
[0,UINT64_MAX], we have to reject that now. Add a test for it.
While we're rejecting anyway: observe that we reject -dfilter LOB..UPB
where LOB > UPB when UPB is zero, but happily create an empty Range
when it isn't. Reject it then, too, and add a test for it.
While there, add a positive test for the problematic upper bound
UINT64_MAX.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2016-07-01 13:47:46 +02:00
|
|
|
qemu_set_dfilter_ranges("0xffffffffffffffff-1", &error_abort);
|
|
|
|
g_assert(qemu_log_in_addr_range(UINT64_MAX));
|
|
|
|
g_assert_false(qemu_log_in_addr_range(UINT64_MAX - 1));
|
|
|
|
|
|
|
|
qemu_set_dfilter_ranges("0..0xffffffffffffffff", &err);
|
2016-07-01 13:47:49 +02:00
|
|
|
g_assert(qemu_log_in_addr_range(0));
|
|
|
|
g_assert(qemu_log_in_addr_range(UINT64_MAX));
|
|
|
|
|
log: Clean up misuse of Range for -dfilter
Range encodes an integer interval [a,b] as { begin = a, end = b + 1 },
where a \in [0,2^64-1] and b \in [1,2^64]. Thus, zero end is to be
interpreted as 2^64.
The implementation of -dfilter (commit 3514552) uses Range
differently: it encodes [a,b] as { begin = a, end = b }. The code
works, but it contradicts the specification of Range in range.h.
Switch to the specified representation. Since it can't represent
[0,UINT64_MAX], we have to reject that now. Add a test for it.
While we're rejecting anyway: observe that we reject -dfilter LOB..UPB
where LOB > UPB when UPB is zero, but happily create an empty Range
when it isn't. Reject it then, too, and add a test for it.
While there, add a positive test for the problematic upper bound
UINT64_MAX.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2016-07-01 13:47:46 +02:00
|
|
|
qemu_set_dfilter_ranges("2..1", &err);
|
|
|
|
error_free_or_abort(&err);
|
|
|
|
|
2016-06-15 19:27:15 +02:00
|
|
|
qemu_set_dfilter_ranges("0x1000+onehundred", &err);
|
|
|
|
error_free_or_abort(&err);
|
|
|
|
|
|
|
|
qemu_set_dfilter_ranges("0x1000+0", &err);
|
|
|
|
error_free_or_abort(&err);
|
2016-03-15 15:30:20 +01:00
|
|
|
}
|
2016-03-15 15:30:23 +01:00
|
|
|
|
2016-08-18 20:46:03 +02:00
|
|
|
static void set_log_path_tmp(char const *dir, char const *tpl, Error **errp)
|
2016-03-15 15:30:23 +01:00
|
|
|
{
|
2016-08-18 20:46:03 +02:00
|
|
|
gchar *file_path = g_build_filename(dir, tpl, NULL);
|
|
|
|
|
|
|
|
qemu_set_log_filename(file_path, errp);
|
|
|
|
g_free(file_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_parse_path(gconstpointer data)
|
|
|
|
{
|
|
|
|
gchar const *tmp_path = data;
|
2016-06-15 19:27:16 +02:00
|
|
|
Error *err = NULL;
|
|
|
|
|
2016-08-18 20:46:03 +02:00
|
|
|
set_log_path_tmp(tmp_path, "qemu.log", &error_abort);
|
|
|
|
set_log_path_tmp(tmp_path, "qemu-%d.log", &error_abort);
|
|
|
|
set_log_path_tmp(tmp_path, "qemu.log.%d", &error_abort);
|
2016-06-15 19:27:16 +02:00
|
|
|
|
2016-08-18 20:46:03 +02:00
|
|
|
set_log_path_tmp(tmp_path, "qemu-%d%d.log", &err);
|
2016-06-15 19:27:16 +02:00
|
|
|
error_free_or_abort(&err);
|
2016-03-15 15:30:23 +01:00
|
|
|
}
|
2016-03-15 15:30:20 +01:00
|
|
|
|
2016-08-18 20:46:03 +02:00
|
|
|
/* Remove a directory and all its entries (non-recursive). */
|
|
|
|
static void rmdir_full(gchar const *root)
|
|
|
|
{
|
|
|
|
GDir *root_gdir = g_dir_open(root, 0, NULL);
|
|
|
|
gchar const *entry_name;
|
|
|
|
|
|
|
|
g_assert_nonnull(root_gdir);
|
|
|
|
while ((entry_name = g_dir_read_name(root_gdir)) != NULL) {
|
|
|
|
gchar *entry_path = g_build_filename(root, entry_name, NULL);
|
|
|
|
g_assert(g_remove(entry_path) == 0);
|
|
|
|
g_free(entry_path);
|
|
|
|
}
|
|
|
|
g_dir_close(root_gdir);
|
|
|
|
g_assert(g_rmdir(root) == 0);
|
|
|
|
}
|
|
|
|
|
2016-03-15 15:30:20 +01:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2016-08-18 20:46:03 +02:00
|
|
|
gchar *tmp_path = g_dir_make_tmp("qemu-test-logging.XXXXXX", NULL);
|
|
|
|
int rc;
|
|
|
|
|
2016-03-15 15:30:20 +01:00
|
|
|
g_test_init(&argc, &argv, NULL);
|
2016-08-18 20:46:03 +02:00
|
|
|
g_assert_nonnull(tmp_path);
|
2016-03-15 15:30:20 +01:00
|
|
|
|
|
|
|
g_test_add_func("/logging/parse_range", test_parse_range);
|
2016-08-18 20:46:03 +02:00
|
|
|
g_test_add_data_func("/logging/parse_path", tmp_path, test_parse_path);
|
|
|
|
|
|
|
|
rc = g_test_run();
|
2016-03-15 15:30:20 +01:00
|
|
|
|
2016-08-18 20:46:03 +02:00
|
|
|
rmdir_full(tmp_path);
|
|
|
|
g_free(tmp_path);
|
|
|
|
return rc;
|
2016-03-15 15:30:20 +01:00
|
|
|
}
|