[PATCH libinput 2/2] test: Add context reference counting test

Jonas Ådahl jadahl at gmail.com
Mon Jun 23 14:56:42 PDT 2014


This test relies on valgrind detecting the leak and use-after-free.

Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
---
 test/misc.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/test/misc.c b/test/misc.c
index ad2e1f6..85d7a84 100644
--- a/test/misc.c
+++ b/test/misc.c
@@ -371,12 +371,32 @@ START_TEST(event_conversion_touch)
 }
 END_TEST
 
+START_TEST(context_ref_counting)
+{
+	struct libinput *li;
+
+	/* These tests rely on valgrind to detect memory leak and use after
+	 * free errors. */
+
+	li = libinput_path_create_context(&simple_interface, NULL);
+	ck_assert_notnull(li);
+	libinput_unref(li);
+
+	li = libinput_path_create_context(&simple_interface, NULL);
+	ck_assert_notnull(li);
+	libinput_ref(li);
+	libinput_unref(li);
+	libinput_unref(li);
+}
+END_TEST
+
 int main (int argc, char **argv) {
 	litest_add_no_device("events:conversion", event_conversion_device_notify);
 	litest_add_no_device("events:conversion", event_conversion_pointer);
 	litest_add_no_device("events:conversion", event_conversion_pointer_abs);
 	litest_add_no_device("events:conversion", event_conversion_key);
 	litest_add_no_device("events:conversion", event_conversion_touch);
+	litest_add_no_device("context:refcount", context_ref_counting);
 
 	return litest_run(argc, argv);
 }
-- 
1.9.1



More information about the wayland-devel mailing list