Merge lp:~ted/hud/automatic-shutdown into lp:hud/phablet

Proposed by Ted Gould
Status: Merged
Approved by: Pete Woods
Approved revision: 375
Merged at revision: 373
Proposed branch: lp:~ted/hud/automatic-shutdown
Merge into: lp:hud/phablet
Prerequisite: lp:~pete-woods/hud/cmake
Diff against target: 654 lines (+414/-6)
10 files modified
src/CMakeLists.txt (+2/-0)
src/hud-service.c (+10/-1)
src/hudquery.c (+18/-2)
src/hudquery.h (+2/-0)
src/watchdog.c (+178/-0)
src/watchdog.h (+53/-0)
tests/CMakeLists.txt (+1/-0)
tests/hud-performance.c (+1/-1)
tests/test-source.c (+2/-2)
tests/test-watchdog.c (+147/-0)
To merge this branch: bzr merge lp:~ted/hud/automatic-shutdown
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Pete Woods (community) Approve
Review via email: mp+156145@code.launchpad.net

This proposal supersedes a proposal from 2013-03-26.

Commit message

Shutdown the HUD service if it's not used for 10 minutes.

Description of the change

Adds a watchdog to shutdown if it's not being used. This is to help with memory and CPU usage on mobile platforms, all services that might not be used are being asked to shutdown with this style of watchdog.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:374
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~ted/hud/automatic-shutdown/+merge/156145/+edit-commit-message

http://s-jenkins:8080/job/hud-small-ci/280/
Executed test runs:
    FAILURE: http://s-jenkins:8080/job/hud-small-ci/./build=pbuilder,distribution=quantal,flavor=i386/280/console

Click here to trigger a rebuild:
http://s-jenkins:8080/job/hud-small-ci/280/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Pete Woods (pete-woods) wrote :

An obvious initial problem is that this is be generating artifacts into the source tree during tests. All generated artifacts must go into the binary tree.

(incomplete review)

review: Needs Fixing
lp:~ted/hud/automatic-shutdown updated
375. By Ted Gould

Removing autotools built files from the ignore file

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Pete Woods (pete-woods) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2013-03-27 23:46:44 +0000
+++ src/CMakeLists.txt 2013-04-02 14:39:23 +0000
@@ -96,6 +96,7 @@
96pronounce-dict.h96pronounce-dict.h
97query-columns.h97query-columns.h
98usage-tracker.h98usage-tracker.h
99watchdog.h
99)100)
100101
101set(HUD_SERVICE_LIB_SOURCES102set(HUD_SERVICE_LIB_SOURCES
@@ -125,6 +126,7 @@
125load-app-info.c126load-app-info.c
126pronounce-dict.c127pronounce-dict.c
127usage-tracker.c128usage-tracker.c
129watchdog.c
128)130)
129131
130add_glib_enumtypes_t(HUD_SERVICE_LIB_SOURCES132add_glib_enumtypes_t(HUD_SERVICE_LIB_SOURCES
131133
=== modified file 'src/hud-service.c'
--- src/hud-service.c 2013-03-26 17:33:39 +0000
+++ src/hud-service.c 2013-04-02 14:39:23 +0000
@@ -36,6 +36,7 @@
36#include "hud-iface.h"36#include "hud-iface.h"
37#include "shared-values.h"37#include "shared-values.h"
38#include "hudquery.h"38#include "hudquery.h"
39#include "watchdog.h"
3940
40/* Prototypes */41/* Prototypes */
41static void bus_method (GDBusConnection *connection,42static void bus_method (GDBusConnection *connection,
@@ -65,6 +66,7 @@
65 .set_property = NULL66 .set_property = NULL
66};67};
67static HudApplicationList * application_list = NULL;68static HudApplicationList * application_list = NULL;
69static HudWatchdog * watchdog = NULL;
6870
69/* Get our error domain */71/* Get our error domain */
70GQuark72GQuark
@@ -228,7 +230,7 @@
228static HudQuery *230static HudQuery *
229build_query (HudSourceList * all_sources, HudApplicationList * app_list, GDBusConnection * connection, const gchar * search_string)231build_query (HudSourceList * all_sources, HudApplicationList * app_list, GDBusConnection * connection, const gchar * search_string)
230{232{
231 HudQuery * query = hud_query_new (HUD_SOURCE(all_sources), application_list, search_string, 10, connection, ++query_count);233 HudQuery * query = hud_query_new (HUD_SOURCE(all_sources), watchdog, application_list, search_string, 10, connection, ++query_count);
232234
233 g_ptr_array_add(query_list, query);235 g_ptr_array_add(query_list, query);
234 g_object_weak_ref(G_OBJECT(query), query_destroyed, query_list);236 g_object_weak_ref(G_OBJECT(query), query_destroyed, query_list);
@@ -263,6 +265,8 @@
263 GDBusMethodInvocation *invocation,265 GDBusMethodInvocation *invocation,
264 gpointer user_data)266 gpointer user_data)
265{267{
268 hud_watchdog_ping(watchdog);
269
266 if (g_str_equal (method_name, "CreateQuery")) {270 if (g_str_equal (method_name, "CreateQuery")) {
267 HudSourceList *all_sources = user_data;271 HudSourceList *all_sources = user_data;
268 GVariant * vsearch;272 GVariant * vsearch;
@@ -385,6 +389,7 @@
385static GVariant *389static GVariant *
386bus_get_prop (GDBusConnection * connection, const gchar * sender, const gchar * object_path, const gchar * interface_name, const gchar * property_name, GError ** error, gpointer user_data)390bus_get_prop (GDBusConnection * connection, const gchar * sender, const gchar * object_path, const gchar * interface_name, const gchar * property_name, GError ** error, gpointer user_data)
387{391{
392 hud_watchdog_ping(watchdog);
388 // HudSource *source = user_data;393 // HudSource *source = user_data;
389394
390 if (g_str_equal(property_name, "OpenQueries")) {395 if (g_str_equal(property_name, "OpenQueries")) {
@@ -532,9 +537,13 @@
532537
533 signal(SIGTERM, sigterm_graceful_exit);538 signal(SIGTERM, sigterm_graceful_exit);
534 539
540 watchdog = hud_watchdog_new(mainloop);
541
535 g_main_loop_run (mainloop);542 g_main_loop_run (mainloop);
536 g_main_loop_unref (mainloop);543 g_main_loop_unref (mainloop);
537544
545 g_clear_object(&watchdog);
546
538 g_object_unref (application_list);547 g_object_unref (application_list);
539 g_object_unref (source_list);548 g_object_unref (source_list);
540 g_ptr_array_free(query_list, TRUE);549 g_ptr_array_free(query_list, TRUE);
541550
=== modified file 'src/hudquery.c'
--- src/hudquery.c 2013-03-26 18:32:27 +0000
+++ src/hudquery.c 2013-04-02 14:39:23 +0000
@@ -30,6 +30,7 @@
30#include "application-source.h"30#include "application-source.h"
31#include "application-list.h"31#include "application-list.h"
32#include "query-columns.h"32#include "query-columns.h"
33#include "watchdog.h"
3334
34/**35/**
35 * SECTION:hudquery36 * SECTION:hudquery
@@ -58,6 +59,7 @@
58{59{
59 GObject parent_instance;60 GObject parent_instance;
6061
62 HudWatchdog * watchdog;
61 HudSource *all_sources;63 HudSource *all_sources;
62 HudApplicationList *app_list;64 HudApplicationList *app_list;
63 HudSource *current_source;65 HudSource *current_source;
@@ -285,6 +287,7 @@
285{287{
286 guint64 start_time;288 guint64 start_time;
287289
290 hud_watchdog_ping(query->watchdog);
288 start_time = g_get_monotonic_time ();291 start_time = g_get_monotonic_time ();
289292
290 dee_model_clear(query->results_model);293 dee_model_clear(query->results_model);
@@ -416,6 +419,7 @@
416 g_clear_pointer(&query->appstack_name, g_free);419 g_clear_pointer(&query->appstack_name, g_free);
417420
418 g_clear_object(&query->voice);421 g_clear_object(&query->voice);
422 g_clear_object(&query->watchdog);
419423
420 G_OBJECT_CLASS (hud_query_parent_class)424 G_OBJECT_CLASS (hud_query_parent_class)
421 ->finalize (object);425 ->finalize (object);
@@ -427,6 +431,7 @@
427{431{
428 g_return_val_if_fail(HUD_IS_QUERY(user_data), FALSE);432 g_return_val_if_fail(HUD_IS_QUERY(user_data), FALSE);
429 HudQuery * query = HUD_QUERY(user_data);433 HudQuery * query = HUD_QUERY(user_data);
434 hud_watchdog_ping(query->watchdog);
430435
431 g_debug("Voice query is loading");436 g_debug("Voice query is loading");
432 hud_query_iface_com_canonical_hud_query_emit_voice_query_loading (437 hud_query_iface_com_canonical_hud_query_emit_voice_query_loading (
@@ -484,6 +489,7 @@
484{489{
485 g_return_val_if_fail(HUD_IS_QUERY(user_data), FALSE);490 g_return_val_if_fail(HUD_IS_QUERY(user_data), FALSE);
486 HudQuery * query = HUD_QUERY(user_data);491 HudQuery * query = HUD_QUERY(user_data);
492 hud_watchdog_ping(query->watchdog);
487493
488 g_debug("Updating Query to: '%s'", search_string);494 g_debug("Updating Query to: '%s'", search_string);
489495
@@ -517,6 +523,7 @@
517{523{
518 g_return_val_if_fail(HUD_IS_QUERY(user_data), FALSE);524 g_return_val_if_fail(HUD_IS_QUERY(user_data), FALSE);
519 HudQuery * query = HUD_QUERY(user_data);525 HudQuery * query = HUD_QUERY(user_data);
526 hud_watchdog_ping(query->watchdog);
520527
521 g_debug("Updating App to: '%s'", app_id);528 g_debug("Updating App to: '%s'", app_id);
522529
@@ -540,7 +547,8 @@
540handle_execute (HudQueryIfaceComCanonicalHudQuery * skel, GDBusMethodInvocation * invocation, GVariant * command_id, guint timestamp, gpointer user_data)547handle_execute (HudQueryIfaceComCanonicalHudQuery * skel, GDBusMethodInvocation * invocation, GVariant * command_id, guint timestamp, gpointer user_data)
541{548{
542 g_return_val_if_fail(HUD_IS_QUERY(user_data), FALSE);549 g_return_val_if_fail(HUD_IS_QUERY(user_data), FALSE);
543 //HudQuery * query = HUD_QUERY(user_data);550 HudQuery * query = HUD_QUERY(user_data);
551 hud_watchdog_ping(query->watchdog);
544552
545 /* Do good */553 /* Do good */
546 GVariant * inner = g_variant_get_variant(command_id);554 GVariant * inner = g_variant_get_variant(command_id);
@@ -578,7 +586,8 @@
578handle_parameterized (HudQueryIfaceComCanonicalHudQuery * skel, GDBusMethodInvocation * invocation, GVariant * command_id, guint timestamp, gpointer user_data)586handle_parameterized (HudQueryIfaceComCanonicalHudQuery * skel, GDBusMethodInvocation * invocation, GVariant * command_id, guint timestamp, gpointer user_data)
579{587{
580 g_return_val_if_fail(HUD_IS_QUERY(user_data), FALSE);588 g_return_val_if_fail(HUD_IS_QUERY(user_data), FALSE);
581 //HudQuery * query = HUD_QUERY(user_data);589 HudQuery * query = HUD_QUERY(user_data);
590 hud_watchdog_ping(query->watchdog);
582591
583 GVariant * inner = g_variant_get_variant(command_id);592 GVariant * inner = g_variant_get_variant(command_id);
584 guint64 id = g_variant_get_uint64(inner);593 guint64 id = g_variant_get_uint64(inner);
@@ -630,6 +639,7 @@
630{639{
631 g_return_val_if_fail(HUD_IS_QUERY(user_data), FALSE);640 g_return_val_if_fail(HUD_IS_QUERY(user_data), FALSE);
632 HudQuery * query = HUD_QUERY(user_data);641 HudQuery * query = HUD_QUERY(user_data);
642 hud_watchdog_ping(query->watchdog);
633643
634 HudClientQueryToolbarItems item = hud_client_query_toolbar_items_get_value_from_nick(arg_item);644 HudClientQueryToolbarItems item = hud_client_query_toolbar_items_get_value_from_nick(arg_item);
635645
@@ -681,6 +691,7 @@
681{691{
682 g_return_val_if_fail(HUD_IS_QUERY(user_data), FALSE);692 g_return_val_if_fail(HUD_IS_QUERY(user_data), FALSE);
683 HudQuery * query = HUD_QUERY(user_data);693 HudQuery * query = HUD_QUERY(user_data);
694 hud_watchdog_ping(query->watchdog);
684695
685 /* Close the query */696 /* Close the query */
686 hud_query_close(query);697 hud_query_close(query);
@@ -791,6 +802,7 @@
791 **/802 **/
792HudQuery *803HudQuery *
793hud_query_new (HudSource *all_sources,804hud_query_new (HudSource *all_sources,
805 HudWatchdog *watchdog,
794 HudApplicationList *application_list,806 HudApplicationList *application_list,
795 const gchar *search_string,807 const gchar *search_string,
796 gint num_results,808 gint num_results,
@@ -807,6 +819,10 @@
807 query->app_list = g_object_ref (application_list);819 query->app_list = g_object_ref (application_list);
808 query->search_string = g_strdup (search_string);820 query->search_string = g_strdup (search_string);
809 query->token_list = NULL;821 query->token_list = NULL;
822
823 if (watchdog != NULL) {
824 query->watchdog = g_object_ref(watchdog);
825 }
810 826
811 if (query->search_string[0] != '\0') {827 if (query->search_string[0] != '\0') {
812 query->token_list = hud_token_list_new_from_string (query->search_string);828 query->token_list = hud_token_list_new_from_string (query->search_string);
813829
=== modified file 'src/hudquery.h'
--- src/hudquery.h 2013-02-27 17:35:32 +0000
+++ src/hudquery.h 2013-04-02 14:39:23 +0000
@@ -22,6 +22,7 @@
22#include "hudsource.h"22#include "hudsource.h"
23#include "hudresult.h"23#include "hudresult.h"
24#include "application-list.h"24#include "application-list.h"
25#include "watchdog.h"
2526
26#define HUD_TYPE_QUERY (hud_query_get_type ())27#define HUD_TYPE_QUERY (hud_query_get_type ())
27#define HUD_QUERY(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \28#define HUD_QUERY(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
@@ -36,6 +37,7 @@
36GType hud_query_get_type (void);37GType hud_query_get_type (void);
3738
38HudQuery * hud_query_new (HudSource *all_sources,39HudQuery * hud_query_new (HudSource *all_sources,
40 HudWatchdog * watchdog,
39 HudApplicationList * application_list,41 HudApplicationList * application_list,
40 const gchar *search_string,42 const gchar *search_string,
41 gint num_results,43 gint num_results,
4244
=== added file 'src/watchdog.c'
--- src/watchdog.c 1970-01-01 00:00:00 +0000
+++ src/watchdog.c 2013-04-02 14:39:23 +0000
@@ -0,0 +1,178 @@
1/*
2 * Copyright © 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#ifdef HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <stdlib.h>
23#include "watchdog.h"
24
25#define DEFAULT_TIMEOUT 600 /* seconds, or 10 minutes */
26
27typedef struct _HudWatchdogPrivate HudWatchdogPrivate;
28struct _HudWatchdogPrivate {
29 guint timeout;
30 gulong timer;
31 GMainLoop * loop;
32};
33
34#define HUD_WATCHDOG_GET_PRIVATE(o) \
35(G_TYPE_INSTANCE_GET_PRIVATE ((o), HUD_WATCHDOG_TYPE, HudWatchdogPrivate))
36
37static void hud_watchdog_class_init (HudWatchdogClass *klass);
38static void hud_watchdog_init (HudWatchdog *self);
39static void hud_watchdog_dispose (GObject *object);
40static void hud_watchdog_finalize (GObject *object);
41static gboolean fire_watchdog (gpointer user_data);
42
43G_DEFINE_TYPE (HudWatchdog, hud_watchdog, G_TYPE_OBJECT);
44
45static void
46hud_watchdog_class_init (HudWatchdogClass *klass)
47{
48 GObjectClass *object_class = G_OBJECT_CLASS (klass);
49
50 g_type_class_add_private (klass, sizeof (HudWatchdogPrivate));
51
52 object_class->dispose = hud_watchdog_dispose;
53 object_class->finalize = hud_watchdog_finalize;
54
55 return;
56}
57
58static void
59hud_watchdog_init (HudWatchdog *self)
60{
61 self->priv = HUD_WATCHDOG_GET_PRIVATE(self);
62
63 const gchar * envvar = g_getenv("HUD_SERVICE_TIMEOUT");
64 if (envvar == NULL) {
65 self->priv->timeout = DEFAULT_TIMEOUT;
66 } else {
67 self->priv->timeout = atoi(envvar);
68 }
69
70 if (self->priv->timeout != 0) {
71 self->priv->timer = g_timeout_add_seconds(self->priv->timeout, fire_watchdog, self);
72 }
73
74 return;
75}
76
77static void
78hud_watchdog_dispose (GObject *object)
79{
80 HudWatchdog * self = HUD_WATCHDOG(object);
81
82 if (self->priv->timer != 0) {
83 g_source_remove(self->priv->timer);
84 self->priv->timer = 0;
85 }
86
87 G_OBJECT_CLASS (hud_watchdog_parent_class)->dispose (object);
88 return;
89}
90
91static void
92hud_watchdog_finalize (GObject *object)
93{
94
95 G_OBJECT_CLASS (hud_watchdog_parent_class)->finalize (object);
96 return;
97}
98
99/* Oh noes! It's our time to go! Do this! */
100static gboolean
101fire_watchdog (gpointer user_data)
102{
103 g_return_val_if_fail(IS_HUD_WATCHDOG(user_data), TRUE);
104 HudWatchdog * self = HUD_WATCHDOG(user_data);
105
106 g_debug("Firing Watchdog");
107
108 if (self->priv->loop != NULL) {
109 g_main_loop_quit(self->priv->loop);
110 }
111
112 return FALSE;
113}
114
115/**
116 * hud_watchdog_new:
117 * @loop: Mainloop to quit if we timeout
118 *
119 * Sets up a watchdog that will quit on the main loop if it
120 * doesn't get enough attention. Reminds of an girlfriend
121 * I had once...
122 *
123 * Return value: (transfer full): A new #HudWatchdog object
124 */
125HudWatchdog *
126hud_watchdog_new (GMainLoop * loop)
127{
128 HudWatchdog * watchdog = g_object_new(HUD_WATCHDOG_TYPE, NULL);
129
130 watchdog->priv->loop = loop;
131
132 return watchdog;
133}
134
135/**
136 * hud_watchdog_ping:
137 * @watchdog: Watchdog to give attention to
138 *
139 * Makes sure to startover and not timeout.
140 */
141void
142hud_watchdog_ping (HudWatchdog * watchdog)
143{
144 /* Doing a silent fail on NULL so that our tests can not worry about
145 setting up dummy watchdogs when just testing the query. They have
146 their own timeouts */
147 if (watchdog == NULL) {
148 return;
149 }
150
151 g_return_if_fail(IS_HUD_WATCHDOG(watchdog));
152
153 if (watchdog->priv->timer != 0) {
154 g_source_remove(watchdog->priv->timer);
155 watchdog->priv->timer = 0;
156 }
157
158 if (watchdog->priv->timeout != 0) {
159 watchdog->priv->timer = g_timeout_add_seconds(watchdog->priv->timeout, fire_watchdog, watchdog);
160 }
161 return;
162}
163
164/**
165 * hud_watchdog_get_timeout:
166 * @watchdog: Watchdog to interegate
167 *
168 * Get the timeout of this watchdog.
169 *
170 * Return value: The number of seconds before it goes off
171 */
172guint
173hud_watchdog_get_timeout (HudWatchdog * watchdog)
174{
175 g_return_val_if_fail(IS_HUD_WATCHDOG(watchdog), 0);
176
177 return watchdog->priv->timeout;
178}
0179
=== added file 'src/watchdog.h'
--- src/watchdog.h 1970-01-01 00:00:00 +0000
+++ src/watchdog.h 2013-04-02 14:39:23 +0000
@@ -0,0 +1,53 @@
1/*
2 * Copyright © 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#ifndef __HUD_WATCHDOG_H__
19#define __HUD_WATCHDOG_H__
20
21#include <glib-object.h>
22
23G_BEGIN_DECLS
24
25#define HUD_WATCHDOG_TYPE (hud_watchdog_get_type ())
26#define HUD_WATCHDOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HUD_WATCHDOG_TYPE, HudWatchdog))
27#define HUD_WATCHDOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), HUD_WATCHDOG_TYPE, HudWatchdogClass))
28#define IS_HUD_WATCHDOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HUD_WATCHDOG_TYPE))
29#define IS_HUD_WATCHDOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), HUD_WATCHDOG_TYPE))
30#define HUD_WATCHDOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), HUD_WATCHDOG_TYPE, HudWatchdogClass))
31
32typedef struct _HudWatchdog HudWatchdog;
33typedef struct _HudWatchdogClass HudWatchdogClass;
34typedef struct _HudWatchdogPrivate HudWatchdogPrivate;
35
36struct _HudWatchdogClass {
37 GObjectClass parent_class;
38};
39
40struct _HudWatchdog {
41 GObject parent;
42 HudWatchdogPrivate * priv;
43};
44
45GType hud_watchdog_get_type (void);
46
47HudWatchdog * hud_watchdog_new (GMainLoop * loop);
48void hud_watchdog_ping (HudWatchdog * watchdog);
49guint hud_watchdog_get_timeout (HudWatchdog * watchdog);
50
51G_END_DECLS
52
53#endif
054
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2013-04-02 08:34:53 +0000
+++ tests/CMakeLists.txt 2013-04-02 14:39:23 +0000
@@ -129,6 +129,7 @@
129# HUD Test Suite129# HUD Test Suite
130#######################130#######################
131131
132hudtest(test-watchdog test-watchdog.c test-watchdog.xml)
132hudtest(test-distance test-distance.c test-distance.xml)133hudtest(test-distance test-distance.c test-distance.xml)
133hudtest(test-hud-item test-huditem.c test-hud-item.xml)134hudtest(test-hud-item test-huditem.c test-hud-item.xml)
134hudtest(test-result-highlighting test-result-highlighting.c test-result-highlighting.xml)135hudtest(test-result-highlighting test-result-highlighting.c test-result-highlighting.xml)
135136
=== modified file 'tests/hud-performance.c'
--- tests/hud-performance.c 2013-03-19 01:19:32 +0000
+++ tests/hud-performance.c 2013-04-02 14:39:23 +0000
@@ -63,7 +63,7 @@
63 gchar *part_search = g_strndup (search, j);63 gchar *part_search = g_strndup (search, j);
6464
65 start_time = g_get_monotonic_time ();65 start_time = g_get_monotonic_time ();
66 query = hud_query_new (source, NULL, part_search, 1u<<30, g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL), 0);66 query = hud_query_new (source, NULL, NULL, part_search, 1u<<30, g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL), 0);
67 g_print ("%-60s: %dus\n", part_search,67 g_print ("%-60s: %dus\n", part_search,
68 (int) (g_get_monotonic_time () - start_time));68 (int) (g_get_monotonic_time () - start_time));
69 g_object_unref (query);69 g_object_unref (query);
7070
=== modified file 'tests/test-source.c'
--- tests/test-source.c 2013-03-26 17:33:39 +0000
+++ tests/test-source.c 2013-04-02 14:39:23 +0000
@@ -193,7 +193,7 @@
193{193{
194 g_debug ("query: [%s], on [%s]", search, g_dbus_connection_get_unique_name(session));194 g_debug ("query: [%s], on [%s]", search, g_dbus_connection_get_unique_name(session));
195195
196 HudQuery * query = hud_query_new (source, list, search, 1u << 30, session, query_count);196 HudQuery * query = hud_query_new (source, NULL, list, search, 1u << 30, session, query_count);
197197
198 return query;198 return query;
199}199}
@@ -355,7 +355,7 @@
355 g_assert(G_N_ELEMENTS(expected) == G_N_ELEMENTS(expected_distances));355 g_assert(G_N_ELEMENTS(expected) == G_N_ELEMENTS(expected_distances));
356356
357 AppListDummy * dummy = app_list_dummy_new(HUD_SOURCE(collector));357 AppListDummy * dummy = app_list_dummy_new(HUD_SOURCE(collector));
358 HudQuery *query = hud_query_new (HUD_SOURCE(source_list), HUD_APPLICATION_LIST(dummy), search, 1u << 30, session, 6);358 HudQuery *query = hud_query_new (HUD_SOURCE(source_list), NULL, HUD_APPLICATION_LIST(dummy), search, 1u << 30, session, 6);
359 test_source_make_assertions_ext (query, appstack, appstack_expected_ids, appstack_expected_icons, G_N_ELEMENTS(appstack_expected_ids), path, name, expected, expected_distances, G_N_ELEMENTS(expected));359 test_source_make_assertions_ext (query, appstack, appstack_expected_ids, appstack_expected_icons, G_N_ELEMENTS(appstack_expected_ids), path, name, expected, expected_distances, G_N_ELEMENTS(expected));
360360
361 // Change the app to the manual_source361 // Change the app to the manual_source
362362
=== added file 'tests/test-watchdog.c'
--- tests/test-watchdog.c 1970-01-01 00:00:00 +0000
+++ tests/test-watchdog.c 2013-04-02 14:39:23 +0000
@@ -0,0 +1,147 @@
1/*
2Test code for watchdog
3
4Copyright 2013 Canonical Ltd.
5
6Authors:
7 Ted Gould <ted@canonical.com>
8
9This program is free software: you can redistribute it and/or modify it
10under the terms of the GNU General Public License version 3, as published
11by the Free Software Foundation.
12
13This program is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranties of
15MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
16PURPOSE. See the GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License along
19with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include <glib.h>
23#include <glib-object.h>
24
25#include "watchdog.h"
26
27static void
28test_watchdog_create (void)
29{
30 g_unsetenv("HUD_SERVICE_TIMEOUT");
31
32 /* Try with NULL */
33 HudWatchdog * doggie = hud_watchdog_new(NULL);
34
35 g_assert(IS_HUD_WATCHDOG(doggie));
36 g_assert(hud_watchdog_get_timeout(doggie) == 600);
37
38 g_clear_object(&doggie);
39
40 /* Give it a loop */
41 GMainLoop * loop = g_main_loop_new(NULL, FALSE);
42 doggie = hud_watchdog_new(loop);
43
44 g_assert(IS_HUD_WATCHDOG(doggie));
45 g_assert(hud_watchdog_get_timeout(doggie) == 600);
46
47 g_clear_object(&doggie);
48 g_main_loop_unref(loop);
49
50 /* Set the environment variable */
51 g_setenv("HUD_SERVICE_TIMEOUT", "1000", TRUE);
52
53 doggie = hud_watchdog_new(NULL);
54
55 g_assert(IS_HUD_WATCHDOG(doggie));
56 g_assert(hud_watchdog_get_timeout(doggie) == 1000);
57
58 g_clear_object(&doggie);
59
60 return;
61}
62
63static gboolean
64final_fail (gpointer ploop)
65{
66 g_error("Timeout not via the watchdog. It didn't work.");
67 g_main_loop_quit((GMainLoop *)ploop);
68 return FALSE;
69}
70
71static gboolean
72ping_watchdog (gpointer pwatchdog)
73{
74 hud_watchdog_ping(pwatchdog);
75 return FALSE;
76}
77
78static gboolean
79hit_one_sec (gpointer pboolean)
80{
81 gboolean * onesec = (gboolean *)pboolean;
82 *onesec = TRUE;
83 return FALSE;
84}
85
86static void
87test_watchdog_timing (void)
88{
89 HudWatchdog * doggie = NULL;
90 GMainLoop * loop = NULL;
91
92 g_setenv("HUD_SERVICE_TIMEOUT", "1", TRUE);
93
94 /* Test base timeout */
95 loop = g_main_loop_new(NULL, FALSE);
96 doggie = hud_watchdog_new(loop);
97
98 glong final = g_timeout_add_seconds(5, final_fail, loop);
99 g_main_loop_run(loop);
100 g_source_remove(final);
101
102 g_clear_object(&doggie);
103
104 /* Test a single ping */
105 gboolean one_sec_hit = FALSE;
106 doggie = hud_watchdog_new(loop);
107
108 final = g_timeout_add_seconds(3, final_fail, loop);
109 g_timeout_add(500, ping_watchdog, doggie);
110 g_timeout_add(1000, hit_one_sec, &one_sec_hit);
111
112 g_main_loop_run(loop);
113 g_source_remove(final);
114
115 g_assert(one_sec_hit);
116 g_clear_object(&doggie);
117
118
119 /* Clean up the loop */
120 g_main_loop_unref(loop);
121
122 return;
123}
124
125/* Build the test suite */
126static void
127test_watchdog_suite (void)
128{
129 g_test_add_func ("/hud/watchdog/create", test_watchdog_create);
130 g_test_add_func ("/hud/watchdog/timing", test_watchdog_timing);
131 return;
132}
133
134gint
135main (gint argc, gchar * argv[])
136{
137#ifndef GLIB_VERSION_2_36
138 g_type_init ();
139#endif
140
141 g_test_init(&argc, &argv, NULL);
142
143 /* Test suites */
144 test_watchdog_suite();
145
146 return g_test_run ();
147}

Subscribers

People subscribed via source and target branches