summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile4
-rw-r--r--tests/test-logging.c107
2 files changed, 111 insertions, 0 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 60371ca008..d27e31d2b7 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -97,6 +97,8 @@ check-unit-y += tests/test-crypto-ivgen$(EXESUF)
check-unit-y += tests/test-crypto-afsplit$(EXESUF)
check-unit-y += tests/test-crypto-xts$(EXESUF)
check-unit-y += tests/test-crypto-block$(EXESUF)
+gcov-files-test-logging-y = tests/test-logging.c
+check-unit-y += tests/test-logging$(EXESUF)
check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
@@ -436,6 +438,8 @@ tests/test-timed-average$(EXESUF): tests/test-timed-average.o qemu-timer.o \
tests/test-base64$(EXESUF): tests/test-base64.o \
libqemuutil.a libqemustub.a
+tests/test-logging$(EXESUF): tests/test-logging.o $(test-util-obj-y)
+
tests/test-qapi-types.c tests/test-qapi-types.h :\
$(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \
diff --git a/tests/test-logging.c b/tests/test-logging.c
new file mode 100644
index 0000000000..193fa9213e
--- /dev/null
+++ b/tests/test-logging.c
@@ -0,0 +1,107 @@
+/*
+ * 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"
+#include <glib.h>
+
+#include "qemu-common.h"
+#include "include/qemu/log.h"
+
+static void test_parse_range(void)
+{
+ qemu_set_dfilter_ranges("0x1000+0x100");
+
+ 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));
+
+ qemu_set_dfilter_ranges("0x1000-0x100");
+
+ 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));
+
+ qemu_set_dfilter_ranges("0x1000..0x1100");
+
+ 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));
+
+ qemu_set_dfilter_ranges("0x1000..0x1000");
+
+ 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));
+
+ qemu_set_dfilter_ranges("0x1000+0x100,0x2100-0x100,0x3000..0x3100");
+ g_assert(qemu_log_in_addr_range(0x1050));
+ g_assert(qemu_log_in_addr_range(0x2050));
+ g_assert(qemu_log_in_addr_range(0x3050));
+}
+
+#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
+static void test_parse_invalid_range_subprocess(void)
+{
+ qemu_set_dfilter_ranges("0x1000+onehundred");
+}
+static void test_parse_invalid_range(void)
+{
+ g_test_trap_subprocess("/logging/parse_invalid_range/subprocess", 0, 0);
+ g_test_trap_assert_failed();
+ g_test_trap_assert_stdout("");
+ g_test_trap_assert_stderr("*Failed to parse range in: 0x1000+onehundred\n");
+}
+static void test_parse_zero_range_subprocess(void)
+{
+ qemu_set_dfilter_ranges("0x1000+0");
+}
+static void test_parse_zero_range(void)
+{
+ g_test_trap_subprocess("/logging/parse_zero_range/subprocess", 0, 0);
+ g_test_trap_assert_failed();
+ g_test_trap_assert_stdout("");
+ g_test_trap_assert_stderr("*Failed to parse range in: 0x1000+0\n");
+}
+#endif
+
+int main(int argc, char **argv)
+{
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/logging/parse_range", test_parse_range);
+#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
+ g_test_add_func("/logging/parse_invalid_range/subprocess", test_parse_invalid_range_subprocess);
+ g_test_add_func("/logging/parse_invalid_range", test_parse_invalid_range);
+ g_test_add_func("/logging/parse_zero_range/subprocess", test_parse_zero_range_subprocess);
+ g_test_add_func("/logging/parse_zero_range", test_parse_zero_range);
+#endif
+
+ return g_test_run();
+}