[gnome-continuous] tasks/memusage: Many fixes



commit eeabedba013b83d62543377ef96b03db71b13dc1
Author: Colin Walters <walters verbum org>
Date:   Sun Dec 15 21:37:27 2013 -0500

    tasks/memusage: Many fixes
    
    Okay, so the random timeout values which worked on my laptop
    don't on the build server, shockingly enough.
    
    We now use a wrapper script that tells gnome-shell to exit cleanly, so
    the massifs logs make it to disk.  We wait for it to exit, and then do
    a full "sync" so that the file actually makes to the "disk".

 Makefile-tests.am              |    1 +
 src/js/tasks/task-memusage.js  |   22 ++------
 src/tests/gnome-shell-valgrind |  100 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 107 insertions(+), 16 deletions(-)
---
diff --git a/Makefile-tests.am b/Makefile-tests.am
index f9233ae..b0c2ce1 100644
--- a/Makefile-tests.am
+++ b/Makefile-tests.am
@@ -20,5 +20,6 @@ testdatadir = $(pkgdatadir)/tests
 testdata_DATA = src/tests/gnome-ostree-export-journal-to-serialdev \
        src/tests/gnome-ostree-export-journal-to-serialdev.service \
        src/tests/gnome-continuous-startstopapps \
+       src/tests/gnome-shell-valgrind \
        $(NULL)
 endif
diff --git a/src/js/tasks/task-memusage.js b/src/js/tasks/task-memusage.js
index 0d9cc0c..3367ef8 100644
--- a/src/js/tasks/task-memusage.js
+++ b/src/js/tasks/task-memusage.js
@@ -44,9 +44,10 @@ const TaskMemusage = new Lang.Class({
     },
 
     TestTrees: ['-devel-debug'],
-    CompleteIdleWaitSeconds: 60,
+    CompleteIdleWaitSeconds: 5,
 
-    RequiredMessageIDs: ["0ce153587afa4095832d233c17a88001" // gnome-session ok
+    RequiredMessageIDs: ["0ce153587afa4095832d233c17a88001", // gnome-session ok
+                         "c15ddcb848ed44d9b39fadcfe7a34795" // gnome-shell-valgrind ok
                         ],
 
     FailedMessageIDs:   [],
@@ -77,25 +78,14 @@ const TaskMemusage = new Lang.Class({
    
     _prepareDisk: function(mntdir, arch, cancellable) {
         let osname = this._buildData['snapshot']['osname'];
+        let datadir = LibQA.getDatadir();
         let [deployDir, deployEtcDir] = LibQA.getDeployDirs(mntdir, osname);
         let shellPath = deployDir.resolve_relative_path('usr/bin/gnome-shell');
         let shellDotRealPath = deployDir.resolve_relative_path('usr/bin/gnome-shell.real');
         GSystem.file_rename(shellPath, shellDotRealPath, cancellable);
-        let massifWrapper = '#!/bin/sh\ntouch /var/tmp/massif-started;exec valgrind --tool=massif 
--smc-check=all --massif-out-file=/var/tmp/massif-gnome-shell.$$ /usr/bin/gnome-shell.real\n';
-        shellPath.replace_contents(massifWrapper, null, false,
-                                   Gio.FileCreateFlags.REPLACE_DESTINATION,
-                                   cancellable);
+        let massifWrapperSrc = datadir.resolve_relative_path('tests/gnome-shell-valgrind');
+        massifWrapperSrc.copy(shellPath, Gio.FileCopyFlags.OVERWRITE, cancellable, null, null);
         GSystem.file_chmod(shellPath, 493, cancellable);
         print("Replaced " + shellPath.get_path() + " with massif wrapper");
-        let desktopFile = '[Desktop Entry]\n\
-Encoding=UTF-8\n\
-Name=Timed logout\n\
-Exec=/usr/bin/sh -c \'sleep 30; touch /var/tmp/timed-logout.done; killall gnome-session\'\n\
-Terminal=false\n\
-Type=Application\n';
-        let dest = deployEtcDir.resolve_relative_path('xdg/autostart/gnome-continuous-timed-logout.desktop');
-        GSystem.file_ensure_directory(dest.get_parent(), true, cancellable);
-        dest.replace_contents(desktopFile, null, false, Gio.FileCreateFlags.REPLACE_DESTINATION,
-                              cancellable);
     }
 });
diff --git a/src/tests/gnome-shell-valgrind b/src/tests/gnome-shell-valgrind
new file mode 100644
index 0000000..476af94
--- /dev/null
+++ b/src/tests/gnome-shell-valgrind
@@ -0,0 +1,100 @@
+#!/usr/bin/env gjs
+// -*- mode: js; indent-tabs-mode: nil; tab-width: 2; -*-
+// Copyright (C) 2013 Colin Walters <walters verbum org>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the
+// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+const GLib = imports.gi.GLib;
+const Gio = imports.gi.Gio;
+const Lang = imports.lang;
+
+let running = true;
+let shellProcExited = false;
+let shellBusNameAvailable = false;
+let shellProxy = null;
+
+// Once we have a shell proxy, install a timeout in the shell process
+// for 10 seconds later.
+function onShellProxy(obj, result) {
+    print("Shell proxy created");
+    shellProxy = obj.new_finish(result);
+    let delayus = 5 * imports.gi.GLib.USEC_PER_SEC;
+    let result;
+    for (let i = 0; i < 30; i++) {
+        try {
+            result = shellProxy.call_sync("Eval", GLib.Variant.new("(s)",
+                                                                   ["imports.gi.GLib.timeout_add_seconds(0, 
10, function() { imports.system.exit(0); });"]),
+                                          0, -1, null);
+            break;
+        } catch (e) {
+            print("Caught " + e + ", retrying in 5 seconds");
+            if (e.domain != Gio.DBusError)
+                throw e;
+            GLib.usleep(delayus);
+        }
+    }
+    let [success, resultval] = result.deep_unpack();
+    if (!success)
+        throw("Failed to eval: " + resultval);
+    print("Successfully installed shell timeout for 10 seconds: " + resultval);
+}
+
+// Wait for the shell DBus name to appear
+Gio.bus_watch_name(Gio.BusType.SESSION,
+                   "org.gnome.Shell", 0,
+                   function(conn, name, owner) {
+                       print("gnome-shell-valgrind: Shell appeared");
+                       shellBusNameAvailable = true;
+                       if (shellProxy)
+                           return;
+                       Gio.DBusProxy.new(conn, Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES, null, owner,
+                                         "/org/gnome/Shell",
+                                         "org.gnome.Shell", null,
+                                         onShellProxy);
+                   },
+                   function() {
+                       shellBusNameAvailable = false;
+                   });
+
+// And asynchronously spawn the real shell under massif as a
+// subprocess.  We indirect via /usr/bin/sh -c to use $$
+let pid = Gio.File.new_for_path('/proc/self').query_info('standard::symlink-target',
+                                                         Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
+                                                         null).get_symlink_target();
+let logPath = '/var/tmp/massif-gnome-shell.' + pid;
+let shellProc = Gio.Subprocess.new(['valgrind', '--tool=massif', '--smc-check=all',
+                                    '--massif-out-file=' + logPath,
+                                    '/usr/bin/gnome-shell.real'],
+                                   Gio.SubprocessFlags.STDIN_INHERIT);
+
+shellProc.wait_async(null, function(obj, result) {
+    print("gnome-shell-valgrind: shell exited");
+    shellProcExited = true;
+    shellProc.wait_finish(result);
+});
+
+let ctx = GLib.MainContext.default();
+while (!(shellProcExited && !shellBusNameAvailable))
+    ctx.iteration(true);
+print("gnome-shell-valgrind: exiting, results in " + logPath);
+
+Gio.Subprocess.new(['sync'], 0).wait_check(null);
+
+let [success, stdout, stderr, estatus] =
+    GLib.spawn_sync(null,
+                    ['gnome-continuous-journal-log-hack',
+                     'c15ddcb848ed44d9b39fadcfe7a34795=gnome-shell-valgrind complete'],
+                    null, GLib.SpawnFlags.SEARCH_PATH, null);


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