[PATCH v2 3/3] tests: use expect_protocol_error in tests

Marek Chalupa mchqwerty at gmail.com
Wed Jul 16 02:40:25 PDT 2014


Turn FAIL_TESTs to TESTs. FAIL_TESTs are bad...
---
 tests/bad-buffer-test.c | 35 +++++------------------------------
 tests/subsurface-test.c | 40 ++++++++++++++++++++++++----------------
 2 files changed, 29 insertions(+), 46 deletions(-)

diff --git a/tests/bad-buffer-test.c b/tests/bad-buffer-test.c
index 86e0299..3b54ac6 100644
--- a/tests/bad-buffer-test.c
+++ b/tests/bad-buffer-test.c
@@ -60,34 +60,12 @@ create_bad_shm_buffer(struct client *client, int width, int height)
 	return buffer;
 }
 
-static void sighandler(int signum)
-{
-	/* this means failure */
-	exit(0);
-}
-
-FAIL_TEST(test_truncated_shm_file)
+TEST(test_truncated_shm_file)
 {
 	struct client *client;
 	struct wl_buffer *bad_buffer;
 	struct wl_surface *surface;
 	int frame;
-	struct sigaction new_action, old_action;
-
-	/* until the bad buffer creation, the SIGABRT or SIGSEGV signals
-	 * should fail the test. That means returning 0 */
-	new_action.sa_handler = sighandler;
-	sigemptyset(&new_action.sa_mask);
-	new_action.sa_flags = 0;
-
-	if (sigaction(SIGSEGV, &new_action, NULL) != 0) {
-		fprintf(stderr, "Failed setting new sigaction for SIGSEGV");
-		exit(0);
-	}
-	if (sigaction(SIGABRT, &new_action, &old_action) != 0) {
-		fprintf(stderr, "Failed setting new sigaction for SIGABRT");
-		exit(0);
-	}
 
 	client = client_create(46, 76, 111, 134);
 	assert(client);
@@ -95,15 +73,12 @@ FAIL_TEST(test_truncated_shm_file)
 
 	bad_buffer = create_bad_shm_buffer(client, 200, 200);
 
-	/* from this point we expect the signal */
-	if (sigaction(SIGABRT, &old_action, NULL) != 0) {
-		fprintf(stderr, "Failed setting old sigaction for SIGABRT");
-		exit(0);
-	}
-
 	wl_surface_attach(surface, bad_buffer, 0, 0);
 	wl_surface_damage(surface, 0, 0, 200, 200);
 	frame_callback_set(surface, &frame);
 	wl_surface_commit(surface);
-	frame_callback_wait(client, &frame);
+	frame_callback_wait_nofail(client, &frame);
+
+	expect_protocol_error(client, &wl_buffer_interface,
+			      WL_SHM_ERROR_INVALID_FD);
 }
diff --git a/tests/subsurface-test.c b/tests/subsurface-test.c
index 0670e7f..bee249b 100644
--- a/tests/subsurface-test.c
+++ b/tests/subsurface-test.c
@@ -133,7 +133,7 @@ TEST(test_subsurface_placement_protocol)
 	client_roundtrip(client);
 }
 
-FAIL_TEST(test_subsurface_paradox)
+TEST(test_subsurface_paradox)
 {
 	struct client *client;
 	struct wl_surface *parent;
@@ -148,10 +148,11 @@ FAIL_TEST(test_subsurface_paradox)
 	/* surface is its own parent */
 	wl_subcompositor_get_subsurface(subco, parent, parent);
 
-	client_roundtrip(client);
+	expect_protocol_error(client, &wl_subcompositor_interface,
+			      WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE);
 }
 
-FAIL_TEST(test_subsurface_identical_link)
+TEST(test_subsurface_identical_link)
 {
 	struct client *client;
 	struct compound_surface com;
@@ -164,10 +165,11 @@ FAIL_TEST(test_subsurface_identical_link)
 	/* surface is already a subsurface */
 	wl_subcompositor_get_subsurface(com.subco, com.child[0], com.parent);
 
-	client_roundtrip(client);
+	expect_protocol_error(client, &wl_subcompositor_interface,
+			      WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE);
 }
 
-FAIL_TEST(test_subsurface_change_link)
+TEST(test_subsurface_change_link)
 {
 	struct client *client;
 	struct compound_surface com;
@@ -182,7 +184,8 @@ FAIL_TEST(test_subsurface_change_link)
 	/* surface is already a subsurface */
 	wl_subcompositor_get_subsurface(com.subco, com.child[0], stranger);
 
-	client_roundtrip(client);
+	expect_protocol_error(client, &wl_subcompositor_interface,
+			      WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE);
 }
 
 TEST(test_subsurface_nesting)
@@ -221,7 +224,7 @@ TEST(test_subsurface_nesting_parent)
 	client_roundtrip(client);
 }
 
-FAIL_TEST(test_subsurface_loop_paradox)
+TEST(test_subsurface_loop_paradox)
 {
 	struct client *client;
 	struct wl_surface *surface[3];
@@ -240,10 +243,11 @@ FAIL_TEST(test_subsurface_loop_paradox)
 	wl_subcompositor_get_subsurface(subco, surface[2], surface[1]);
 	wl_subcompositor_get_subsurface(subco, surface[0], surface[2]);
 
-	client_roundtrip(client);
+	expect_protocol_error(client, &wl_subcompositor_interface,
+			      WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE);
 }
 
-FAIL_TEST(test_subsurface_place_above_stranger)
+TEST(test_subsurface_place_above_stranger)
 {
 	struct client *client;
 	struct compound_surface com;
@@ -258,10 +262,11 @@ FAIL_TEST(test_subsurface_place_above_stranger)
 	/* bad sibling */
 	wl_subsurface_place_above(com.sub[0], stranger);
 
-	client_roundtrip(client);
+	expect_protocol_error(client, &wl_subsurface_interface,
+			      WL_SUBSURFACE_ERROR_BAD_SURFACE);
 }
 
-FAIL_TEST(test_subsurface_place_below_stranger)
+TEST(test_subsurface_place_below_stranger)
 {
 	struct client *client;
 	struct compound_surface com;
@@ -276,10 +281,11 @@ FAIL_TEST(test_subsurface_place_below_stranger)
 	/* bad sibling */
 	wl_subsurface_place_below(com.sub[0], stranger);
 
-	client_roundtrip(client);
+	expect_protocol_error(client, &wl_subsurface_interface,
+			      WL_SUBSURFACE_ERROR_BAD_SURFACE);
 }
 
-FAIL_TEST(test_subsurface_place_above_foreign)
+TEST(test_subsurface_place_above_foreign)
 {
 	struct client *client;
 	struct compound_surface com1;
@@ -294,10 +300,11 @@ FAIL_TEST(test_subsurface_place_above_foreign)
 	/* bad sibling */
 	wl_subsurface_place_above(com1.sub[0], com2.child[0]);
 
-	client_roundtrip(client);
+	expect_protocol_error(client, &wl_subsurface_interface,
+			      WL_SUBSURFACE_ERROR_BAD_SURFACE);
 }
 
-FAIL_TEST(test_subsurface_place_below_foreign)
+TEST(test_subsurface_place_below_foreign)
 {
 	struct client *client;
 	struct compound_surface com1;
@@ -312,7 +319,8 @@ FAIL_TEST(test_subsurface_place_below_foreign)
 	/* bad sibling */
 	wl_subsurface_place_below(com1.sub[0], com2.child[0]);
 
-	client_roundtrip(client);
+	expect_protocol_error(client, &wl_subsurface_interface,
+			      WL_SUBSURFACE_ERROR_BAD_SURFACE);
 }
 
 TEST(test_subsurface_destroy_protocol)
-- 
2.0.1



More information about the wayland-devel mailing list