[gnome-settings-daemon/benzea/power-test-speedup: 1/2] power: Read external monitor mock file location from environment



commit efd72b5444c70adb37b43520fd1548773d229dc9
Author: Benjamin Berg <bberg redhat com>
Date:   Fri Sep 28 16:54:36 2018 +0200

    power: Read external monitor mock file location from environment
    
    We need to use a variable location for the mock file to be able to run
    multiple tests in parallel. As we don't need the GSD_MOCKED environment
    variable for any other purpose anymore, rename it to
    GSD_MOCK_EXTERNAL_MONITOR_FILE and use it to pass in a filename for
    mocking purposes.

 plugins/power/gpm-common.c | 33 +++++++++++++++++++--------------
 plugins/power/gpm-common.h |  2 --
 plugins/power/test.py      |  8 +++++---
 3 files changed, 24 insertions(+), 19 deletions(-)
---
diff --git a/plugins/power/gpm-common.c b/plugins/power/gpm-common.c
index 60f3795f..079b36ce 100644
--- a/plugins/power/gpm-common.c
+++ b/plugins/power/gpm-common.c
@@ -315,21 +315,20 @@ gsd_power_enable_screensaver_watchdog (void)
 }
 
 static gpointer
-parse_mocked (gpointer data)
+parse_mock_mock_external_monitor (gpointer data)
 {
-       const char *mocked;
-       mocked = g_getenv ("GSD_MOCKED");
-       if (!mocked)
-               return GINT_TO_POINTER (FALSE);
-       return GINT_TO_POINTER (TRUE);
+       const char *mocked_file;
+       mocked_file = g_getenv ("GSD_MOCK_EXTERNAL_MONITOR_FILE");
+
+       return g_strdup (mocked_file);
 }
 
-gboolean
-is_mocked (void)
+static const gchar *
+get_mock_external_monitor_file (void)
 {
          static GOnce mocked_once = G_ONCE_INIT;
-         g_once (&mocked_once, parse_mocked, NULL);
-         return GPOINTER_TO_INT (mocked_once.retval);
+         g_once (&mocked_once, parse_mock_mock_external_monitor, NULL);
+         return mocked_once.retval;
 }
 
 static gboolean
@@ -366,13 +365,15 @@ screen_destroyed (gpointer  user_data,
 void
 watch_external_monitor (GnomeRRScreen *screen)
 {
+       const gchar *filename;
        GFile *file;
        GFileMonitor *monitor;
 
-       if (!is_mocked ())
+       filename = get_mock_external_monitor_file ();
+       if (!filename)
                return;
 
-       file = g_file_new_for_commandline_arg ("GSD_MOCK_EXTERNAL_MONITOR");
+       file = g_file_new_for_commandline_arg (filename);
        monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, NULL);
        g_object_unref (file);
        g_signal_connect (monitor, "changed",
@@ -384,8 +385,12 @@ static gboolean
 mock_external_monitor_is_connected (GnomeRRScreen *screen)
 {
        char *mock_external_monitor_contents;
+       const gchar *filename;
+
+       filename = get_mock_external_monitor_file ();
+       g_assert (filename);
 
-       if (g_file_get_contents ("GSD_MOCK_EXTERNAL_MONITOR", &mock_external_monitor_contents, NULL, NULL)) {
+       if (g_file_get_contents (filename, &mock_external_monitor_contents, NULL, NULL)) {
                if (mock_external_monitor_contents[0] == '1') {
                        g_free (mock_external_monitor_contents);
                        g_debug ("Mock external monitor is on");
@@ -409,7 +414,7 @@ external_monitor_is_connected (GnomeRRScreen *screen)
         GnomeRROutput **outputs;
         guint i;
 
-        if (is_mocked ())
+        if (get_mock_external_monitor_file ())
                 return mock_external_monitor_is_connected (screen);
 
        g_assert (screen != NULL);
diff --git a/plugins/power/gpm-common.h b/plugins/power/gpm-common.h
index 40c55b2e..ea02596a 100644
--- a/plugins/power/gpm-common.h
+++ b/plugins/power/gpm-common.h
@@ -36,8 +36,6 @@ gboolean         gsd_power_is_hardware_a_tablet         (void);
 guint            gsd_power_enable_screensaver_watchdog  (void);
 void             reset_idletime                         (void);
 
-gboolean        is_mocked (void);
-
 /* Backlight helpers */
 
 /* on ACPI machines we have 4-16 levels, on others it's ~150 */
diff --git a/plugins/power/test.py b/plugins/power/test.py
index c789940c..8c085618 100755
--- a/plugins/power/test.py
+++ b/plugins/power/test.py
@@ -43,7 +43,9 @@ class PowerPluginTest(gsdtestcase.GSDTestCase):
     COMMON_SUSPEND_METHODS=['Suspend', 'Hibernate', 'SuspendThenHibernate']
 
     def setUp(self):
-        os.environ['GSD_MOCKED']='1'
+        self.mock_external_monitor_file = os.path.join(self.workdir, 'GSD_MOCK_EXTERNAL_MONITOR')
+        os.environ['GSD_MOCK_EXTERNAL_MONITOR_FILE'] = self.mock_external_monitor_file
+
         self.check_logind_gnome_session()
         self.start_logind()
         self.daemon_death_expected = False
@@ -168,7 +170,7 @@ class PowerPluginTest(gsdtestcase.GSDTestCase):
         Gio.Settings.sync()
 
         try:
-            os.unlink('GSD_MOCK_EXTERNAL_MONITOR')
+            os.unlink(self.mock_external_monitor_file)
         except OSError:
             pass
 
@@ -255,7 +257,7 @@ class PowerPluginTest(gsdtestcase.GSDTestCase):
             val = b'1'
         else:
             val = b'0'
-        GLib.file_set_contents ('GSD_MOCK_EXTERNAL_MONITOR', val)
+        GLib.file_set_contents (self.mock_external_monitor_file, val)
 
     def set_composite_battery_discharging(self, icon='battery-good-symbolic'):
         self.obj_upower.SetupDisplayDevice(


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]