[v2,2/2] tests: add timeout tests

Submitted by Marek Chalupa on Nov. 12, 2014, 12:14 p.m.

Details

Message ID 1415794487-28104-2-git-send-email-mchqwerty@gmail.com
State Accepted
Commit 1d2ef9ee082407b1970c26d0ad799703c2e76aa1
Headers show

Not browsing as part of any series.

Commit Message

Marek Chalupa Nov. 12, 2014, 12:14 p.m.
sanity tests for timeouts.

v2:
  use test_sleep instead of sleep
  add few more test-cases

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
---
 tests/sanity-test.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

Patch hide | download patch | download mbox

diff --git a/tests/sanity-test.c b/tests/sanity-test.c
index 46f4f85..bd3f70c 100644
--- a/tests/sanity-test.c
+++ b/tests/sanity-test.c
@@ -29,6 +29,9 @@ 
 #include "test-runner.h"
 #include "wayland-util.h"
 
+#define WL_HIDE_DEPRECATED
+#include "test-compositor.h"
+
 extern int leak_check_enabled;
 
 TEST(empty)
@@ -125,3 +128,67 @@  TEST(sanity_fd_exec)
 
 	exec_fd_leak_check(nr_fds + 2);
 }
+
+FAIL_TEST(timeout_tst)
+{
+	test_set_timeout(1);
+	/* test should reach timeout */
+	test_sleep(2);
+}
+
+TEST(timeout2_tst)
+{
+	/* the test should end before reaching timeout,
+	 * thus it should pass */
+	test_set_timeout(1);
+	/* 200 000 microsec = 0.2 sec */
+	test_usleep(200000);
+}
+
+FAIL_TEST(timeout_reset_tst)
+{
+	test_set_timeout(5);
+	test_set_timeout(10);
+	test_set_timeout(1);
+
+	/* test should fail on timeout */
+	test_sleep(2);
+}
+
+TEST(timeout_turnoff)
+{
+	test_set_timeout(1);
+	test_set_timeout(0);
+
+	test_usleep(2);
+}
+
+/* test timeouts with test-compositor */
+FAIL_TEST(tc_timeout_tst)
+{
+	struct display *d = display_create();
+	client_create(d, timeout_tst);
+	display_run(d);
+	display_destroy(d);
+}
+
+FAIL_TEST(tc_timeout2_tst)
+{
+	struct display *d = display_create();
+	client_create(d, timeout_reset_tst);
+	display_run(d);
+	display_destroy(d);
+}
+
+TEST(tc_timeout3_tst)
+{
+	struct display *d = display_create();
+
+	client_create(d, timeout2_tst);
+	display_run(d);
+
+	client_create(d, timeout_turnoff);
+	display_run(d);
+
+	display_destroy(d);
+}

Comments

On Wed, 12 Nov 2014 13:14:47 +0100
Marek Chalupa <mchqwerty@gmail.com> wrote:

> sanity tests for timeouts.
> 
> v2:
>   use test_sleep instead of sleep
>   add few more test-cases
> 
> Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
> ---
>  tests/sanity-test.c | 67
> +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed,
> 67 insertions(+)
> 
> diff --git a/tests/sanity-test.c b/tests/sanity-test.c
> index 46f4f85..bd3f70c 100644
> --- a/tests/sanity-test.c
> +++ b/tests/sanity-test.c
> @@ -29,6 +29,9 @@
>  #include "test-runner.h"
>  #include "wayland-util.h"
>  
> +#define WL_HIDE_DEPRECATED
> +#include "test-compositor.h"
> +
>  extern int leak_check_enabled;
>  
>  TEST(empty)
> @@ -125,3 +128,67 @@ TEST(sanity_fd_exec)
>  
>  	exec_fd_leak_check(nr_fds + 2);
>  }
> +
> +FAIL_TEST(timeout_tst)
> +{
> +	test_set_timeout(1);
> +	/* test should reach timeout */
> +	test_sleep(2);
> +}
> +
> +TEST(timeout2_tst)
> +{
> +	/* the test should end before reaching timeout,
> +	 * thus it should pass */
> +	test_set_timeout(1);
> +	/* 200 000 microsec = 0.2 sec */
> +	test_usleep(200000);
> +}
> +
> +FAIL_TEST(timeout_reset_tst)
> +{
> +	test_set_timeout(5);
> +	test_set_timeout(10);
> +	test_set_timeout(1);
> +
> +	/* test should fail on timeout */
> +	test_sleep(2);
> +}
> +
> +TEST(timeout_turnoff)
> +{
> +	test_set_timeout(1);
> +	test_set_timeout(0);
> +
> +	test_usleep(2);
> +}
> +
> +/* test timeouts with test-compositor */
> +FAIL_TEST(tc_timeout_tst)
> +{
> +	struct display *d = display_create();
> +	client_create(d, timeout_tst);
> +	display_run(d);
> +	display_destroy(d);
> +}
> +
> +FAIL_TEST(tc_timeout2_tst)
> +{
> +	struct display *d = display_create();
> +	client_create(d, timeout_reset_tst);
> +	display_run(d);
> +	display_destroy(d);
> +}
> +
> +TEST(tc_timeout3_tst)
> +{
> +	struct display *d = display_create();
> +
> +	client_create(d, timeout2_tst);
> +	display_run(d);
> +
> +	client_create(d, timeout_turnoff);
> +	display_run(d);
> +
> +	display_destroy(d);
> +}

Both patches pushed.


Thanks,
pq