Re: [Intel-gfx] [RFC i-g-t 2/4] igt_aux: Add igt_set_autoresume_delay()

2016-11-08 Thread Chris Wilson
On Mon, Nov 07, 2016 at 07:05:14PM -0500, Lyude wrote:
> The default autoresume delay is about 5 seconds. It's possible on a
> system that's not very fast this might not be a long enough time, since
> an asynchronous hotplug event we scheduled on the chamelium that was
> intended to happen during suspend could happen before we actually manage
> to suspend. So, add a function that allows us to increase the autoresume
> time to ensure this never happens during suspend/resume tests with the
> chamelium.
> 
> Signed-off-by: Lyude 
> ---
>  lib/igt_aux.c | 46 ++
>  lib/igt_aux.h |  1 +
>  2 files changed, 47 insertions(+)
> 
> diff --git a/lib/igt_aux.c b/lib/igt_aux.c
> index 9754148..26d32fd 100644
> --- a/lib/igt_aux.c
> +++ b/lib/igt_aux.c
> @@ -812,6 +812,52 @@ void igt_system_suspend_autoresume(enum 
> igt_suspend_state state,
>   close(power_dir);
>  }
>  
> +static int original_autoresume_delay;
> +
> +static void igt_restore_autoresume_delay(int sig)
> +{
> + int delay_fd;
> + char delay_str[10];
> +
> + igt_assert((delay_fd = 
> open("/sys/module/suspend/parameters/pm_test_delay",
> + O_WRONLY)) >= 0);
> +
> + snprintf(delay_str, sizeof(delay_str), "%d", original_autoresume_delay);
> + igt_assert(write(delay_fd, delay_str, strlen(delay_str)));
> +
> + close(delay_fd);
> +}
> +
> +/**
> + * igt_set_autoresume_delay:
> + * @delay_secs: The delay in seconds before resuming the system
> + *
> + * Sets how long we wait to resume the system after suspending it, using the
> + * suspend.pm_test_delay variable. On exit, the original delay value is
> + * restored.
> + */
> +void igt_set_autoresume_delay(int delay_secs)
> +{
> + int delay_fd;
> + char delay_str[10];
> +
> + igt_skip_on_simulation();
> +
> + igt_assert((delay_fd = 
> open("/sys/module/suspend/parameters/pm_test_delay",
> + O_RDWR)) >= 0);

Are these test failures? No, then don't assert. Do it within your
igt_fixture() block and use igt_require to skip.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [RFC i-g-t 2/4] igt_aux: Add igt_set_autoresume_delay()

2016-11-07 Thread Lyude
The default autoresume delay is about 5 seconds. It's possible on a
system that's not very fast this might not be a long enough time, since
an asynchronous hotplug event we scheduled on the chamelium that was
intended to happen during suspend could happen before we actually manage
to suspend. So, add a function that allows us to increase the autoresume
time to ensure this never happens during suspend/resume tests with the
chamelium.

Signed-off-by: Lyude 
---
 lib/igt_aux.c | 46 ++
 lib/igt_aux.h |  1 +
 2 files changed, 47 insertions(+)

diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 9754148..26d32fd 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -812,6 +812,52 @@ void igt_system_suspend_autoresume(enum igt_suspend_state 
state,
close(power_dir);
 }
 
+static int original_autoresume_delay;
+
+static void igt_restore_autoresume_delay(int sig)
+{
+   int delay_fd;
+   char delay_str[10];
+
+   igt_assert((delay_fd = 
open("/sys/module/suspend/parameters/pm_test_delay",
+   O_WRONLY)) >= 0);
+
+   snprintf(delay_str, sizeof(delay_str), "%d", original_autoresume_delay);
+   igt_assert(write(delay_fd, delay_str, strlen(delay_str)));
+
+   close(delay_fd);
+}
+
+/**
+ * igt_set_autoresume_delay:
+ * @delay_secs: The delay in seconds before resuming the system
+ *
+ * Sets how long we wait to resume the system after suspending it, using the
+ * suspend.pm_test_delay variable. On exit, the original delay value is
+ * restored.
+ */
+void igt_set_autoresume_delay(int delay_secs)
+{
+   int delay_fd;
+   char delay_str[10];
+
+   igt_skip_on_simulation();
+
+   igt_assert((delay_fd = 
open("/sys/module/suspend/parameters/pm_test_delay",
+   O_RDWR)) >= 0);
+
+   if (!original_autoresume_delay) {
+   igt_assert(read(delay_fd, delay_str, sizeof(delay_str)));
+   original_autoresume_delay = atoi(delay_str);
+   igt_install_exit_handler(igt_restore_autoresume_delay);
+   }
+
+   snprintf(delay_str, sizeof(delay_str), "%d", delay_secs);
+   igt_assert(write(delay_fd, delay_str, strlen(delay_str)));
+
+   close(delay_fd);
+}
+
 /**
  * igt_drop_root:
  *
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 973a9cd..7cee901 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -174,6 +174,7 @@ void igt_skip_without_suspend_support(enum 
igt_suspend_state state,
  enum igt_suspend_test test);
 void igt_system_suspend_autoresume(enum igt_suspend_state state,
   enum igt_suspend_test test);
+void igt_set_autoresume_delay(int delay_secs);
 
 /* dropping priviledges */
 void igt_drop_root(void);
-- 
2.7.4

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx