Merge lp:~ted/qtmir/ual-pause into lp:qtmir

Proposed by Ted Gould
Status: Merged
Approved by: Gerry Boland
Approved revision: 274
Merged at revision: 276
Proposed branch: lp:~ted/qtmir/ual-pause
Merge into: lp:qtmir
Diff against target: 1079 lines (+75/-689)
16 files modified
src/modules/Unity/Application/Application.pro (+0/-2)
src/modules/Unity/Application/application.cpp (+2/-2)
src/modules/Unity/Application/applicationcontroller.h (+3/-0)
src/modules/Unity/Application/processcontroller.cpp (+0/-231)
src/modules/Unity/Application/processcontroller.h (+0/-62)
src/modules/Unity/Application/taskcontroller.cpp (+12/-69)
src/modules/Unity/Application/taskcontroller.h (+3/-7)
src/modules/Unity/Application/upstart/applicationcontroller.cpp (+19/-0)
src/modules/Unity/Application/upstart/applicationcontroller.h (+3/-0)
tests/modules/ApplicationManager/application_manager_test.cpp (+0/-18)
tests/modules/TaskController/taskcontroller_test.cpp (+4/-198)
tests/modules/common/common.pri (+1/-3)
tests/modules/common/mock_application_controller.h (+26/-2)
tests/modules/common/mock_oom_controller.h (+0/-34)
tests/modules/common/mock_process_controller.h (+0/-45)
tests/modules/common/qtmir_test.h (+2/-16)
To merge this branch: bzr merge lp:~ted/qtmir/ual-pause
Reviewer Review Type Date Requested Status
Gerry Boland (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+236033@code.launchpad.net

Commit message

Use UAL pause/resume functions for stopping/continuing all tasks in the cgroup

Description of the change

Switching from internal functions for doing all the signaling and OOM adjusting to using the ones in UAL.

 * Are there any related MPs required for this MP to build/function as expected? Please list.

https://code.launchpad.net/~ted/unity8/dash-oom-score/+merge/238888

 * Did you perform an exploratory manual test run of your code change and any related functionality?

Yup.

 * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?

Naw, just removing a one-line dep. I think I'm good for that change.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ted Gould (ted) wrote :

Okay, to get all the Oxide renderers you'll need this too:

https://code.launchpad.net/~ted/ubuntu-app-launch/setuid-oom-adjust/+merge/236422

Revision history for this message
Gerry Boland (gerboland) wrote :

Hey Ted, thanks for this! Lots of red, yay! Couple of things I noticed before doing a full review:

Please add checklist: https://wiki.ubuntu.com/Process/Merges/Checklists/QtMir
with the list of required MRs

As you're removing ProcessController, I suspect you can remove qtmir's dependence on process-cpp package.

+++ src/modules/Unity/Application/taskcontroller.h
-/*
- * Copyright (C) 2013-2014 Canonical, Ltd.
+/* Copyright (C) 2013-2014 Canonical, Ltd.
Unnecessary change

+++ src/modules/Unity/Application/upstart/applicationcontroller.cpp
+bool ApplicationController::pauseApplicationWithAppId(const QString& appId)
+ qDebug() << "ApplicationController::pauseApplication FAILED to stop appId=" << appId;
failed to _pause_ appId

+ qDebug() << "ApplicationController::resumeApplication FAILED to stop appId=" << appId;
failed to _resume_

+++ tests/modules/common/mock_application_controller.h
+ (void) appId;
Us Qt people tend to use a macro for this: Q_UNUSED(appId);

And couple of higher-level questions about UAL's behaviour (mostly confirmations for me):
1. UAL changes the OOM-killer score when we pause/resume apps, yes?
2. UAL gives app a unlikely-to-be-killed OOM score on start of that app?

Something that worries me about this change is that apps not managed by upstart will no longer have correct OOM-killer weights. Are trust helpers managed by upstart these days? Does the OSK get a good OOM-killer value? I need to test this carefully.

review: Needs Fixing
Revision history for this message
Ted Gould (ted) wrote :

On Mon, 2014-10-06 at 12:17 +0000, Gerry Boland wrote:

> As you're removing ProcessController, I suspect you can remove qtmir's
> dependence on process-cpp package.

Not my goal, but it seems so. There were a few pieces left to kill. r262

> +++ src/modules/Unity/Application/taskcontroller.h
> -/*
> - * Copyright (C) 2013-2014 Canonical, Ltd.
> +/* Copyright (C) 2013-2014 Canonical, Ltd.
> Unnecessary change

Fixed r263.

> +++ src/modules/Unity/Application/upstart/applicationcontroller.cpp
> +bool ApplicationController::pauseApplicationWithAppId(const QString& appId)
> + qDebug() << "ApplicationController::pauseApplication FAILED to stop appId=" << appId;
> failed to _pause_ appId
>
> + qDebug() << "ApplicationController::resumeApplication FAILED to stop appId=" << appId;
> failed to _resume_

Fixed r264.

> +++ tests/modules/common/mock_application_controller.h
> + (void) appId;
> Us Qt people tend to use a macro for this: Q_UNUSED(appId);

Fixed r265.

> And couple of higher-level questions about UAL's behaviour (mostly
> confirmations for me):
> 1. UAL changes the OOM-killer score when we pause/resume apps, yes?

Correct.

> 2. UAL gives app a unlikely-to-be-killed OOM score on start of that
> app?

Correct.

> Something that worries me about this change is that apps not managed
> by upstart will no longer have correct OOM-killer weights. Are trust
> helpers managed by upstart these days? Does the OSK get a good
> OOM-killer value? I need to test this carefully.

All processes are managed by Upstart, so they can all have an OOM score
set in their Upstart job. For instance that's how UAL sets the initial
value, it makes Upstart do it on job creation. I don't know that the OSK
job has that configured properly though.

lp:~ted/qtmir/ual-pause updated
262. By Ted Gould

Trying to remove process-cpp entirely

263. By Ted Gould

No clue how that got changed

264. By Ted Gould

Debug message cut-and-paste error

265. By Ted Gould

Use Q_UNUSED() macro

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~ted/qtmir/ual-pause updated
266. By Ted Gould

Merge trunk

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~ted/qtmir/ual-pause updated
267. By Ted Gould

Removing the process module from the QMake files

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~ted/qtmir/ual-pause updated
268. By Ted Gould

Switch to using the accessor in the application object

269. By Ted Gould

Changing the API back to being appId based so that we don't have to let longAppId through.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~ted/qtmir/ual-pause updated
270. By Ted Gould

Apparently a new process-cpp inclusion

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

CI still not happy. Appears we still use process-cpp in a test. You'd better restore it, and we'll change that later.

review: Needs Fixing
Revision history for this message
Gerry Boland (gerboland) wrote :

One important piece of info for you:
https://code.launchpad.net/~unity-team/qtmir/dash-killed-less-likely/+merge/237915
this will land first, and we need the ability to give Dash a custom OOM weight. You need to adjust this to suit unfortunately.

review: Needs Fixing
Revision history for this message
Gerry Boland (gerboland) wrote :

- pid_t pid = m_appController->primaryPidForAppId(app->appId());
- if (pid == 0) {
- pid = app->pid();
- }
-m_processController->oomController()->ensureProcessLikelyToBeKilled(pid);

This code is needed, as unity-dash is not managed by UAL, but is spawned by upstart, and we need to suspend/resume it

review: Needs Fixing
lp:~ted/qtmir/ual-pause updated
271. By Ted Gould

Partial trunk update

272. By Ted Gould

Getting closer to trunk

273. By Ted Gould

Merge trunk

Revision history for this message
Ted Gould (ted) wrote :

As discussed on IRC here's the change to the dash Upstart job to put the OOM score at 200.

https://code.launchpad.net/~ted/unity8/dash-oom-score/+merge/238888

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~ted/qtmir/ual-pause updated
274. By Ted Gould

Add pack process-cpp-dev

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

Working well. Only issue is that dash is not being suspended/resumed. This bit of code you removed was doing it:

- pid_t pid = m_appController->primaryPidForAppId(app->appId());
- if (pid == 0) {
- pid = app->pid();
- }

i.e. if UAL didn't know the PID for the process, then we'd use the PID that AppMan saves. Then you could call signal(SIGSTOP) manually. That'll do to fix it.
Thanks
-G

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

Hey Ted,
my apologies but I've been told that your initial design to not suspend/resume the dash is now correct. Can you please revert revision 275. Then am happy to approve
-Gerry

review: Needs Fixing
Revision history for this message
Ted Gould (ted) wrote :

Pushed without r275

Revision history for this message
Gerry Boland (gerboland) wrote :

Works great, thanks Ted

 * Did you perform an exploratory manual test run of the code change and any related functionality?
Yep
 * Did CI run pass? If not, please explain why.
Y

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/modules/Unity/Application/Application.pro'
--- src/modules/Unity/Application/Application.pro 2014-09-17 17:29:42 +0000
+++ src/modules/Unity/Application/Application.pro 2014-10-24 15:59:35 +0000
@@ -36,7 +36,6 @@
36 ubuntukeyboardinfo.cpp \36 ubuntukeyboardinfo.cpp \
37 mirsurfaceitem.cpp \37 mirsurfaceitem.cpp \
38 mirbuffersgtexture.cpp \38 mirbuffersgtexture.cpp \
39 processcontroller.cpp \
40 proc_info.cpp \39 proc_info.cpp \
41 session.cpp \40 session.cpp \
42 sessionmanager.cpp \41 sessionmanager.cpp \
@@ -60,7 +59,6 @@
60 mirsurfaceitemmodel.h \59 mirsurfaceitemmodel.h \
61 mirbuffersgtexture.h \60 mirbuffersgtexture.h \
62 objectlistmodel.h \61 objectlistmodel.h \
63 processcontroller.h \
64 proc_info.h \62 proc_info.h \
65 session.h \63 session.h \
66 session_interface.h \64 session_interface.h \
6765
=== modified file 'src/modules/Unity/Application/application.cpp'
--- src/modules/Unity/Application/application.cpp 2014-10-13 10:07:10 +0000
+++ src/modules/Unity/Application/application.cpp 2014-10-24 15:59:35 +0000
@@ -325,13 +325,13 @@
325void Application::onSessionSuspended()325void Application::onSessionSuspended()
326{326{
327 qCDebug(QTMIR_APPLICATIONS) << "Application::onSessionSuspended - appId=" << appId();327 qCDebug(QTMIR_APPLICATIONS) << "Application::onSessionSuspended - appId=" << appId();
328 m_taskController->suspend(this);328 m_taskController->suspend(longAppId());
329}329}
330330
331void Application::onSessionResumed()331void Application::onSessionResumed()
332{332{
333 qCDebug(QTMIR_APPLICATIONS) << "Application::onSessionResumed - appId=" << appId();333 qCDebug(QTMIR_APPLICATIONS) << "Application::onSessionResumed - appId=" << appId();
334 m_taskController->resume(this);334 m_taskController->resume(longAppId());
335}335}
336336
337void Application::respawn()337void Application::respawn()
338338
=== modified file 'src/modules/Unity/Application/applicationcontroller.h'
--- src/modules/Unity/Application/applicationcontroller.h 2014-07-02 22:56:08 +0000
+++ src/modules/Unity/Application/applicationcontroller.h 2014-10-24 15:59:35 +0000
@@ -48,6 +48,9 @@
48 virtual bool stopApplicationWithAppId(const QString &appId) = 0;48 virtual bool stopApplicationWithAppId(const QString &appId) = 0;
49 virtual bool startApplicationWithAppIdAndArgs(const QString &appId, const QStringList &arguments) = 0;49 virtual bool startApplicationWithAppIdAndArgs(const QString &appId, const QStringList &arguments) = 0;
5050
51 virtual bool pauseApplicationWithAppId(const QString &appId) = 0;
52 virtual bool resumeApplicationWithAppId(const QString &appId) = 0;
53
51 virtual QFileInfo findDesktopFileForAppId(const QString &appId) const = 0;54 virtual QFileInfo findDesktopFileForAppId(const QString &appId) const = 0;
5255
53Q_SIGNALS:56Q_SIGNALS:
5457
=== removed file 'src/modules/Unity/Application/processcontroller.cpp'
--- src/modules/Unity/Application/processcontroller.cpp 2014-10-10 08:38:30 +0000
+++ src/modules/Unity/Application/processcontroller.cpp 1970-01-01 00:00:00 +0000
@@ -1,231 +0,0 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#include "processcontroller.h"
19
20#include "logging.h"
21
22// Process C++
23#include <core/posix/process.h>
24#include <core/posix/this_process.h>
25#include <core/posix/linux/proc/process/oom_adj.h>
26#include <core/posix/linux/proc/process/oom_score_adj.h>
27
28// std
29#include <signal.h>
30#include <unistd.h>
31
32/*
33 * ProcessController
34 * This class manages individual processes during their lifetime. It allows one to pause
35 * and resume processes.
36 *
37 * It also has methods to set a score on processes which is used by the Out of Memory (OOM)
38 * process killer to decide what process gets killed in a low memory situation.
39 */
40
41namespace plpp = core::posix::linux::proc::process;
42
43namespace qtmir
44{
45
46ProcessController::OomController::OomController()
47{
48}
49
50/*!
51 * \brief ProcessController::OomController::ensureProcessLikelyToBeKilled
52 * \param pid
53 * Set the process OOM-killer score so that the process is _more_ likely to be killed
54 * in a low memory situation
55 */
56
57/*
58 * Useful information about these OOM-weighting methods
59 *
60 * the "Process C++" library wraps some APIs exported by the kernel in the the /proc filesystem.
61 * The OOM score is one of these, but the APIs for it changed from Linux 2.6.36 onward.
62 *
63 * === Up to Linux 2.6.36 ===
64 * /proc/[pid]/oom_adj (wrapped by plpp::OomAdj) was used up to 2.6.36 (is deprecated now)
65 * Valid values are in the range -16 to +15, plus the special value -17, which disables
66 * OOM-killing altogether for this process. A positive score increases the likelihood
67 * of this process being killed by the OOM-killer; a negative score decreases the likelihood.
68 *
69 * The default value for this file is 0; a new process inherits its parent's oom_adj setting.
70 *
71 * === Linux 2.6.36 and later ===
72 * /proc/[pid]/oom_score_adj (wrapped by plpp::OomScoreAdj) is the recommended API. Valid
73 * values are in the range -1000 (never kill) to 1000 (always kill).
74 *
75 * For backward compatibility with previous kernels, /proc/[pid]/oom_adj can still be used to
76 * tune the badness score. Its value is scaled linearly with oom_score_adj. So writing to
77 * /proc/[pid]/oom_score_adj or /proc/[pid]/oom_adj will change the other with its scaled value.
78 *
79 * === How OOM score changing is implemented ===
80 * To support all available kernels, we thus perform the following for any OOM score change:
81 * 1. Attempt to use the newer kernel API (plpp::OomScoreAdj). Fetch the min & max possible
82 * values and calculate a desired score for the process.
83 * 2. If that fails, fall back to the older kernel API (plpp::OomSAdj), again fetching min
84 * & max possible values and calculating a desired score for the process.
85 */
86void ProcessController::OomController::ensureProcessLikelyToBeKilled(pid_t pid)
87{
88 // We avoid boundary values for oom_score_adj. For that, we
89 // set it to 80% of the total available range.
90 static const float defaultPercentage = 0.8;
91
92 core::posix::Process process(pid);
93
94 try {
95 plpp::OomScoreAdj shellScore;
96 core::posix::this_process::instance() >> shellScore;
97
98 plpp::OomScoreAdj processScore
99 {
100 static_cast<int>((plpp::OomScoreAdj::max_value() - shellScore.value) * defaultPercentage) + shellScore.value
101 };
102
103 process << processScore;
104 } catch(...) {
105 // Accessing OomScoreAdj resulted in an exception being thrown.
106 // Trying with the deprecated OomAdj now as a last resort.
107 try
108 {
109 process << plpp::OomAdj{plpp::OomAdj::max_value()};
110 } catch(...)
111 {
112 qDebug() << "ensureProcessIsLikelyToBeKilled failed for pid=" << pid;
113 }
114 }
115}
116
117/*!
118 * \brief ProcessController::OomController::ensureProcessLessLikelyToBeKilled
119 * \param pid
120 * Set the process OOM-killer score so that, in a low memory situation, the process
121 * is _more_ likely to be killed than the foreground application, but less likely
122 * than the background applications
123 */
124void ProcessController::OomController::ensureProcessLessLikelyToBeKilled(pid_t pid)
125{
126 // Set it to 50% of the total available range.
127 static const float defaultPercentage = 0.5;
128
129 core::posix::Process process(pid);
130
131 try {
132 plpp::OomScoreAdj shellScore;
133 core::posix::this_process::instance() >> shellScore;
134
135 plpp::OomScoreAdj processScore
136 {
137 static_cast<int>((plpp::OomScoreAdj::max_value() - shellScore.value) * defaultPercentage) + shellScore.value
138 };
139
140 process << processScore;
141 } catch(...) {
142 // Accessing OomScoreAdj resulted in an exception being thrown.
143 // Trying with the deprecated OomAdj now as a last resort.
144 try
145 {
146 process << plpp::OomAdj{plpp::OomAdj::max_value()};
147 } catch(...)
148 {
149 qDebug() << "ensureProcessIsLessLikelyToBeKilled failed for pid=" << pid;
150 }
151 }
152}
153
154/*!
155 * \brief ProcessController::OomController::ensureProcessUnlikelyToBeKilled
156 * \param pid
157 * Set the process OOM-killer weighting so that the process is _less_ likely to be killed
158 * in a low memory situation
159 */
160void ProcessController::OomController::ensureProcessUnlikelyToBeKilled(pid_t pid)
161{
162 // By system default, we set the oom_score_adj of Unity8 to -10 (via lightdm).
163 // As we want to avoid that any app's oom_score_adj is <= Unity8's oom_score_adj,
164 // (i.e. Unity8 would be killed before that app is) we choose a default increase of +1.
165 static const int default_increase = 1;
166
167 core::posix::Process process(pid);
168
169 try {
170 plpp::OomScoreAdj shellScore;
171 core::posix::this_process::instance() >> shellScore;
172
173 plpp::OomScoreAdj processScore
174 {
175 shellScore.value + default_increase
176 };
177
178 process << processScore;
179 } catch(...) {
180 // Accessing OomScoreAdj resulted in an exception being thrown.
181 // Trying with the deprecated OomAdj now as a last resort.
182 // By system default, we set the oom_score_adj of Unity8 to -10 (via lightdm).
183 // As we want to avoid that any app's oom_score_adj or oom_adj is <= Unity8's oom_score_adj,
184 // we choose a default value of -9 for oom_score_adj and 0 for oom_adj.
185 static const int defaultValue = 0;
186
187 try
188 {
189 process << plpp::OomAdj{defaultValue};
190 } catch(...)
191 {
192 qDebug() << "ensureProcessIsUnlikelyToBeKilled failed for pid" << pid;
193 }
194 }
195}
196
197ProcessController::ProcessController()
198 : m_oomController(new ProcessController::OomController())
199{
200}
201
202ProcessController::~ProcessController()
203{
204}
205
206const QSharedPointer<ProcessController::OomController>& ProcessController::oomController() const
207{
208 return m_oomController;
209}
210
211/*!
212 * \brief ProcessController::sigStopProcessGroupForPid
213 * \param pid
214 * \return True if process was stopped successfully, false otherwise
215 */
216bool ProcessController::sigStopProcessGroupForPid(pid_t pid) const
217{
218 return -1 != kill(-pid, SIGSTOP);
219}
220
221/*!
222 * \brief ProcessController::sigContinueProcessGroupForPid
223 * \param pid
224 * \return True of process was resumed successfully, false otherwise
225 */
226bool ProcessController::sigContinueProcessGroupForPid(pid_t pid) const
227{
228 return -1 != kill(-pid, SIGCONT);
229}
230
231} // namespace qtmir
2320
=== removed file 'src/modules/Unity/Application/processcontroller.h'
--- src/modules/Unity/Application/processcontroller.h 2014-10-10 08:38:30 +0000
+++ src/modules/Unity/Application/processcontroller.h 1970-01-01 00:00:00 +0000
@@ -1,62 +0,0 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#ifndef PROCESS_CONTROLLER_H
19#define PROCESS_CONTROLLER_H
20
21#include <QSharedPointer>
22
23#include <sys/types.h>
24
25namespace qtmir
26{
27
28class ProcessController
29{
30public:
31 class OomController
32 {
33 public:
34 OomController();
35 OomController(const OomController&) = delete;
36 virtual ~OomController() = default;
37
38 OomController& operator=(const OomController&) = delete;
39
40 virtual void ensureProcessLikelyToBeKilled(pid_t);
41 virtual void ensureProcessLessLikelyToBeKilled(pid_t);
42 virtual void ensureProcessUnlikelyToBeKilled(pid_t);
43 };
44
45 ProcessController();
46 ProcessController(const ProcessController&) = delete;
47 virtual ~ProcessController();
48
49 ProcessController& operator=(const ProcessController&) = delete;
50
51 virtual const QSharedPointer<OomController>& oomController() const;
52
53 virtual bool sigStopProcessGroupForPid(pid_t pid) const;
54 virtual bool sigContinueProcessGroupForPid(pid_t pid) const;
55
56protected:
57 QSharedPointer<OomController> m_oomController;
58};
59
60} // namespace qtmir
61
62#endif // PROCESS_CONTROLLER_H
630
=== modified file 'src/modules/Unity/Application/taskcontroller.cpp'
--- src/modules/Unity/Application/taskcontroller.cpp 2014-10-10 08:38:30 +0000
+++ src/modules/Unity/Application/taskcontroller.cpp 2014-10-24 15:59:35 +0000
@@ -23,12 +23,6 @@
23// Qt23// Qt
24#include <QStringList>24#include <QStringList>
2525
26// Process C++
27#include <core/posix/process.h>
28#include <core/posix/this_process.h>
29#include <core/posix/linux/proc/process/oom_adj.h>
30#include <core/posix/linux/proc/process/oom_score_adj.h>
31
32// STL26// STL
33#include <mutex>27#include <mutex>
3428
@@ -41,11 +35,9 @@
4135
42TaskController::TaskController(36TaskController::TaskController(
43 QObject *parent,37 QObject *parent,
44 const QSharedPointer<ApplicationController> &appController,38 const QSharedPointer<ApplicationController> &appController) :
45 const QSharedPointer<ProcessController> &processController) :
46 QObject(parent),39 QObject(parent),
47 m_appController(appController),40 m_appController(appController)
48 m_processController(processController)
49{41{
50 connect(m_appController.data(),42 connect(m_appController.data(),
51 &ApplicationController::applicationAboutToBeStarted,43 &ApplicationController::applicationAboutToBeStarted,
@@ -53,11 +45,6 @@
53 &TaskController::processStarting);45 &TaskController::processStarting);
5446
55 connect(m_appController.data(),47 connect(m_appController.data(),
56 &ApplicationController::applicationStarted,
57 this,
58 &TaskController::onApplicationStarted);
59
60 connect(m_appController.data(),
61 &ApplicationController::applicationStopped,48 &ApplicationController::applicationStopped,
62 this,49 this,
63 &TaskController::processStopped);50 &TaskController::processStopped);
@@ -109,64 +96,20 @@
109 return m_appController->findDesktopFileForAppId(appId);96 return m_appController->findDesktopFileForAppId(appId);
110}97}
11198
112bool TaskController::suspend(const Application* app)99bool TaskController::suspend(const QString &appId)
113{100{
114 qCDebug(QTMIR_APPLICATIONS) << "TaskController::suspend - appId=" << app->appId();101 qCDebug(QTMIR_APPLICATIONS) << "TaskController::suspend - appId=" << appId;
115 pid_t pid = m_appController->primaryPidForAppId(app->appId());102 return m_appController->pauseApplicationWithAppId(appId);
116 if (pid == 0) {103}
117 pid = app->pid();104
118 }105bool TaskController::resume(const QString &appId)
119106{
120 // FIXME This harcodes the unity8-dash name, we should consider a different approach,107 qCDebug(QTMIR_APPLICATIONS) << "TaskController::resume - appId=" << appId;
121 // some privileged way to define which apps should be less likely to be killed.108 return m_appController->resumeApplicationWithAppId(appId);
122 if (app->appId() == "unity8-dash") {
123 m_processController->oomController()->ensureProcessLessLikelyToBeKilled(pid);
124 } else {
125 m_processController->oomController()->ensureProcessLikelyToBeKilled(pid);
126 }
127
128 if (pid) {
129 // We do assume that the app was launched by ubuntu-app-launch and with that,
130 // in its own process group. For that, we interpret the pid as pgid and
131 // sigstop the complete process group on suspend.
132 return m_processController->sigStopProcessGroupForPid(pid);
133 } else {
134 return false;
135 }
136}
137
138bool TaskController::resume(const Application* app)
139{
140 qCDebug(QTMIR_APPLICATIONS) << "TaskController::resume - appId=" << app->appId();
141 pid_t pid = m_appController->primaryPidForAppId(app->appId());
142 if (pid == 0) {
143 pid = app->pid();
144 }
145
146 m_processController->oomController()->ensureProcessUnlikelyToBeKilled(pid);
147
148 if (pid) {
149 // We do assume that the app was launched by ubuntu-app-launch and with that,
150 // in its own process group. For that, we interpret the pid as pgid and
151 // sigcont the complete process group on resume.
152 return m_processController->sigContinueProcessGroupForPid(pid);
153 return true;
154 } else {
155 qCDebug(QTMIR_APPLICATIONS) << "TaskController::resume - couldn't find PID to resume for appId=" << app->appId();
156 return false;
157 }
158}
159
160void TaskController::onApplicationStarted(const QString& id)
161{
162 pid_t pid = m_appController->primaryPidForAppId(id);
163 m_processController->oomController()->ensureProcessUnlikelyToBeKilled(pid);
164}109}
165110
166void TaskController::onApplicationFocusRequest(const QString& id)111void TaskController::onApplicationFocusRequest(const QString& id)
167{112{
168 pid_t pid = m_appController->primaryPidForAppId(id);
169 m_processController->oomController()->ensureProcessUnlikelyToBeKilled(pid);
170 Q_EMIT requestFocus(id);113 Q_EMIT requestFocus(id);
171}114}
172115
173116
=== modified file 'src/modules/Unity/Application/taskcontroller.h'
--- src/modules/Unity/Application/taskcontroller.h 2014-09-18 09:39:48 +0000
+++ src/modules/Unity/Application/taskcontroller.h 2014-10-24 15:59:35 +0000
@@ -23,7 +23,6 @@
2323
24#include "application.h"24#include "application.h"
25#include "applicationcontroller.h"25#include "applicationcontroller.h"
26#include "processcontroller.h"
2726
28namespace qtmir27namespace qtmir
29{28{
@@ -34,15 +33,14 @@
34public:33public:
35 TaskController(34 TaskController(
36 QObject *parent,35 QObject *parent,
37 const QSharedPointer<ApplicationController> &appController,36 const QSharedPointer<ApplicationController> &appController);
38 const QSharedPointer<ProcessController> &processController = QSharedPointer<ProcessController>(new ProcessController()));
39 ~TaskController();37 ~TaskController();
4038
41 bool start(const QString &appId, const QStringList &args);39 bool start(const QString &appId, const QStringList &args);
42 bool stop(const QString &appId);40 bool stop(const QString &appId);
4341
44 bool suspend(const Application* app);42 bool suspend(const QString &appId);
45 bool resume(const Application* app);43 bool resume(const QString &appId);
4644
47 bool appIdHasProcessId(const QString &appId, const quint64 pid) const;45 bool appIdHasProcessId(const QString &appId, const quint64 pid) const;
48 QFileInfo findDesktopFileForAppId(const QString &appId) const;46 QFileInfo findDesktopFileForAppId(const QString &appId) const;
@@ -55,7 +53,6 @@
55 void requestResume(const QString &appId);53 void requestResume(const QString &appId);
5654
57private Q_SLOTS:55private Q_SLOTS:
58 void onApplicationStarted(const QString &id);
59 void onApplicationFocusRequest(const QString &id);56 void onApplicationFocusRequest(const QString &id);
60 void onApplicationResumeRequest(const QString &id);57 void onApplicationResumeRequest(const QString &id);
6158
@@ -63,7 +60,6 @@
6360
64private:61private:
65 const QSharedPointer<ApplicationController> m_appController;62 const QSharedPointer<ApplicationController> m_appController;
66 const QSharedPointer<ProcessController> m_processController;
67};63};
6864
69} // namespace qtmir65} // namespace qtmir
7066
=== modified file 'src/modules/Unity/Application/upstart/applicationcontroller.cpp'
--- src/modules/Unity/Application/upstart/applicationcontroller.cpp 2014-07-01 13:38:06 +0000
+++ src/modules/Unity/Application/upstart/applicationcontroller.cpp 2014-10-24 15:59:35 +0000
@@ -203,6 +203,25 @@
203 return result;203 return result;
204}204}
205205
206bool ApplicationController::pauseApplicationWithAppId(const QString& appId)
207{
208 auto result = ubuntu_app_launch_pause_application(toLongAppIdIfPossible(appId).toLatin1().constData());
209 if (!result)
210 qDebug() << "ApplicationController::pauseApplication FAILED to pause appId=" << appId;
211
212 return result;
213}
214
215bool ApplicationController::resumeApplicationWithAppId(const QString& appId)
216{
217 auto result = ubuntu_app_launch_resume_application(toLongAppIdIfPossible(appId).toLatin1().constData());
218 if (!result)
219 qDebug() << "ApplicationController::resumeApplication FAILED to resume appId=" << appId;
220
221 return result;
222}
223
224
206QFileInfo ApplicationController::findDesktopFileForAppId(const QString &appId) const225QFileInfo ApplicationController::findDesktopFileForAppId(const QString &appId) const
207{226{
208 qCDebug(QTMIR_APPLICATIONS) << "ApplicationController::desktopFilePathForAppId - appId=" << appId;227 qCDebug(QTMIR_APPLICATIONS) << "ApplicationController::desktopFilePathForAppId - appId=" << appId;
209228
=== modified file 'src/modules/Unity/Application/upstart/applicationcontroller.h'
--- src/modules/Unity/Application/upstart/applicationcontroller.h 2014-07-01 13:38:06 +0000
+++ src/modules/Unity/Application/upstart/applicationcontroller.h 2014-10-24 15:59:35 +0000
@@ -37,6 +37,9 @@
37 bool stopApplicationWithAppId(const QString& appId) override;37 bool stopApplicationWithAppId(const QString& appId) override;
38 bool startApplicationWithAppIdAndArgs(const QString& appId, const QStringList& arguments) override;38 bool startApplicationWithAppIdAndArgs(const QString& appId, const QStringList& arguments) override;
3939
40 bool pauseApplicationWithAppId(const QString& appId) override;
41 bool resumeApplicationWithAppId(const QString& appId) override;
42
40 QFileInfo findDesktopFileForAppId(const QString &appId) const override;43 QFileInfo findDesktopFileForAppId(const QString &appId) const override;
4144
42private:45private:
4346
=== modified file 'tests/modules/ApplicationManager/application_manager_test.cpp'
--- tests/modules/ApplicationManager/application_manager_test.cpp 2014-10-10 08:38:30 +0000
+++ tests/modules/ApplicationManager/application_manager_test.cpp 2014-10-24 15:59:35 +0000
@@ -56,12 +56,6 @@
5656
57 EXPECT_CALL(desktopFileReaderFactory, createInstance(_, _)).Times(1);57 EXPECT_CALL(desktopFileReaderFactory, createInstance(_, _)).Times(1);
5858
59 EXPECT_CALL(processController, sigStopProcessGroupForPid(_)).Times(1);
60 EXPECT_CALL(processController, sigContinueProcessGroupForPid(_)).Times(1);
61 EXPECT_CALL(oomController, ensureProcessUnlikelyToBeKilled(_)).Times(1);
62 EXPECT_CALL(oomController, ensureProcessLikelyToBeKilled(_)).Times(1);
63 EXPECT_CALL(oomController, ensureProcessLessLikelyToBeKilled(_)).Times(0);
64
65 auto application = applicationManager.startApplication(59 auto application = applicationManager.startApplication(
66 appId,60 appId,
67 ApplicationManager::NoFlag,61 ApplicationManager::NoFlag,
@@ -87,12 +81,6 @@
8781
88 ON_CALL(appController,appIdHasProcessId(_,_)).WillByDefault(Return(false));82 ON_CALL(appController,appIdHasProcessId(_,_)).WillByDefault(Return(false));
8983
90 EXPECT_CALL(processController, sigStopProcessGroupForPid(_)).Times(1);
91 EXPECT_CALL(processController, sigContinueProcessGroupForPid(_)).Times(1);
92 EXPECT_CALL(oomController, ensureProcessUnlikelyToBeKilled(_)).Times(1);
93 EXPECT_CALL(oomController, ensureProcessLikelyToBeKilled(_)).Times(0);
94 EXPECT_CALL(oomController, ensureProcessLessLikelyToBeKilled(_)).Times(1);
95
96 bool authed = true;84 bool authed = true;
9785
98 std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("Oo", procId);86 std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("Oo", procId);
@@ -131,12 +119,6 @@
131 onSessionStarting( mirSession );119 onSessionStarting( mirSession );
132120
133 EXPECT_NE(nullptr, application);121 EXPECT_NE(nullptr, application);
134
135 appIds.insert(appId);
136 auto it = appController.children.find(appId);
137 if (it != appController.children.end())
138 EXPECT_CALL(oomController,
139 ensureProcessUnlikelyToBeKilled(it->pid())).Times(1);
140 }122 }
141123
142 for (auto appId : appIds)124 for (auto appId : appIds)
143125
=== modified file 'tests/modules/TaskController/taskcontroller_test.cpp'
--- tests/modules/TaskController/taskcontroller_test.cpp 2014-09-10 11:01:14 +0000
+++ tests/modules/TaskController/taskcontroller_test.cpp 2014-10-24 15:59:35 +0000
@@ -19,13 +19,8 @@
19#include <Unity/Application/desktopfilereader.h>19#include <Unity/Application/desktopfilereader.h>
20#include <Unity/Application/application.h>20#include <Unity/Application/application.h>
2121
22#include "mock_oom_controller.h"
23#include "mock_process_controller.h"
24#include "mock_desktop_file_reader.h"22#include "mock_desktop_file_reader.h"
2523
26#include <core/posix/fork.h>
27#include <core/posix/linux/proc/process/oom_score_adj.h>
28
29#include <gmock/gmock.h>24#include <gmock/gmock.h>
30#include <gtest/gtest.h>25#include <gtest/gtest.h>
3126
@@ -56,6 +51,8 @@
5651
57 MOCK_METHOD1(stopApplicationWithAppId, bool(const QString&));52 MOCK_METHOD1(stopApplicationWithAppId, bool(const QString&));
58 MOCK_METHOD2(startApplicationWithAppIdAndArgs, bool(const QString&, const QStringList&));53 MOCK_METHOD2(startApplicationWithAppIdAndArgs, bool(const QString&, const QStringList&));
54 MOCK_METHOD1(pauseApplicationWithAppId, bool(const QString&));
55 MOCK_METHOD1(resumeApplicationWithAppId, bool(const QString&));
59};56};
60}57}
6158
@@ -72,19 +69,8 @@
7269
73 EXPECT_CALL(appController, startApplicationWithAppIdAndArgs(appId, QStringList())).Times(1).WillRepeatedly(Return(true));70 EXPECT_CALL(appController, startApplicationWithAppIdAndArgs(appId, QStringList())).Times(1).WillRepeatedly(Return(true));
7471
75 testing::NiceMock<MockOomController> oomController;
76 QSharedPointer<ProcessController::OomController> oomControllerPtr(
77 &oomController,
78 [](ProcessController::OomController*){});
79
80 NiceMock<testing::MockProcessController> processController(oomControllerPtr);
81 QSharedPointer<ProcessController> processControllerPtr(
82 &processController,
83 [](ProcessController*){});
84
85 TaskController taskController(nullptr,72 TaskController taskController(nullptr,
86 appControllerPtr,73 appControllerPtr);
87 processControllerPtr);
8874
89 taskController.start(appId, QStringList());75 taskController.start(appId, QStringList());
90}76}
@@ -102,189 +88,9 @@
10288
103 EXPECT_CALL(appController, stopApplicationWithAppId(appId)).Times(1).WillRepeatedly(Return(true));89 EXPECT_CALL(appController, stopApplicationWithAppId(appId)).Times(1).WillRepeatedly(Return(true));
10490
105 testing::NiceMock<MockOomController> oomController;
106 QSharedPointer<ProcessController::OomController> oomControllerPtr(
107 &oomController,
108 [](ProcessController::OomController*){});
109
110 NiceMock<testing::MockProcessController> processController(oomControllerPtr);
111 QSharedPointer<ProcessController> processControllerPtr(
112 &processController,
113 [](ProcessController*){});
114
115 TaskController taskController(nullptr,91 TaskController taskController(nullptr,
116 appControllerPtr,92 appControllerPtr);
117 processControllerPtr);
11893
119 taskController.stop(appId);94 taskController.stop(appId);
120}95}
12196
122TEST(TaskController, suspendingAnApplicationAdjustsOomScoreForCorrectPid)
123{
124 using namespace ::testing;
125
126 const QString appId{"com.canonical.does.not.exist"};
127
128 testing::NiceMock<TriggerableApplicationController> appController;
129 QSharedPointer<TriggerableApplicationController> appControllerPtr(
130 &appController,
131 [](ApplicationController*){});
132
133 EXPECT_CALL(appController, primaryPidForAppId(appId)).Times(1).WillRepeatedly(Return(-1));
134
135 testing::NiceMock<MockOomController> oomController;
136 QSharedPointer<ProcessController::OomController> oomControllerPtr(
137 &oomController,
138 [](ProcessController::OomController*){});
139
140 NiceMock<testing::MockProcessController> processController(oomControllerPtr);
141 QSharedPointer<ProcessController> processControllerPtr(
142 &processController,
143 [](ProcessController*){});
144
145 EXPECT_CALL(oomController, ensureProcessLikelyToBeKilled(-1)).Times(1);
146
147 auto taskController = QSharedPointer<TaskController>(new TaskController(nullptr,
148 appControllerPtr,
149 processControllerPtr));
150
151
152 auto mockDesktopFileReader = new NiceMock<MockDesktopFileReader>(appId, QFileInfo());
153 ON_CALL(*mockDesktopFileReader, loaded()).WillByDefault(Return(true));
154 ON_CALL(*mockDesktopFileReader, appId()).WillByDefault(Return(appId));
155 Application *app = new Application(taskController, mockDesktopFileReader, Application::Running, QStringList(), nullptr);
156 taskController->suspend(app);
157 delete app;
158}
159
160TEST(TaskController, resumingAnApplicationAdjustsOomScoreForCorrectPid)
161{
162 using namespace ::testing;
163
164 const QString appId{"com.canonical.does.not.exist"};
165
166 testing::NiceMock<TriggerableApplicationController> appController;
167 QSharedPointer<TriggerableApplicationController> appControllerPtr(
168 &appController,
169 [](ApplicationController*){});
170
171 EXPECT_CALL(appController, primaryPidForAppId(appId)).Times(1).WillRepeatedly(Return(-1));
172
173 testing::NiceMock<MockOomController> oomController;
174 QSharedPointer<ProcessController::OomController> oomControllerPtr(
175 &oomController,
176 [](ProcessController::OomController*){});
177
178 NiceMock<testing::MockProcessController> processController(oomControllerPtr);
179 QSharedPointer<ProcessController> processControllerPtr(
180 &processController,
181 [](ProcessController*){});
182
183 EXPECT_CALL(oomController, ensureProcessUnlikelyToBeKilled(-1)).Times(1);
184
185 auto taskController = QSharedPointer<TaskController>(new TaskController(nullptr,
186 appControllerPtr,
187 processControllerPtr));
188
189
190 auto mockDesktopFileReader = new NiceMock<MockDesktopFileReader>(appId, QFileInfo());
191 ON_CALL(*mockDesktopFileReader, loaded()).WillByDefault(Return(true));
192 ON_CALL(*mockDesktopFileReader, appId()).WillByDefault(Return(appId));
193 Application *app = new Application(taskController, mockDesktopFileReader, Application::Running, QStringList(), nullptr);
194 taskController->resume(app);
195 delete app;
196}
197
198TEST(TaskController, aStartedApplicationIsOomScoreAdjusted)
199{
200 using namespace ::testing;
201
202 const QString appId{"com.canonical.does.not.exist"};
203
204 testing::NiceMock<TriggerableApplicationController> appController;
205 QSharedPointer<TriggerableApplicationController> appControllerPtr(
206 &appController,
207 [](ApplicationController*){});
208 EXPECT_CALL(appController, primaryPidForAppId(appId)).Times(1).WillRepeatedly(Return(42));
209
210 testing::NiceMock<MockOomController> oomController;
211 QSharedPointer<ProcessController::OomController> oomControllerPtr(
212 &oomController,
213 [](ProcessController::OomController*){});
214
215 NiceMock<testing::MockProcessController> processController(oomControllerPtr);
216 QSharedPointer<ProcessController> processControllerPtr(
217 &processController,
218 [](ProcessController*){});
219
220 EXPECT_CALL(oomController, ensureProcessUnlikelyToBeKilled(42)).Times(1);
221
222 TaskController taskController(nullptr,
223 appControllerPtr,
224 processControllerPtr);
225
226 appControllerPtr->triggerApplicationStarted(appId);
227}
228
229TEST(TaskController, aFocusedApplicationIsOomScoreAdjusted)
230{
231 using namespace ::testing;
232
233 const QString appId{"com.canonical.does.not.exist"};
234
235 testing::NiceMock<TriggerableApplicationController> appController;
236 QSharedPointer<TriggerableApplicationController> appControllerPtr(
237 &appController,
238 [](ApplicationController*){});
239 EXPECT_CALL(appController, primaryPidForAppId(appId)).Times(1).WillRepeatedly(Return(42));
240
241 testing::NiceMock<MockOomController> oomController;
242 QSharedPointer<ProcessController::OomController> oomControllerPtr(
243 &oomController,
244 [](ProcessController::OomController*){});
245
246 NiceMock<testing::MockProcessController> processController(oomControllerPtr);
247 QSharedPointer<ProcessController> processControllerPtr(
248 &processController,
249 [](ProcessController*){});
250
251 EXPECT_CALL(oomController, ensureProcessUnlikelyToBeKilled(42)).Times(1);
252
253 TaskController taskController(nullptr,
254 appControllerPtr,
255 processControllerPtr);
256
257 appControllerPtr->triggerApplicationFocusRequest(appId);
258}
259
260TEST(TaskController, oomControllerUpdatesOomScoreAdjCorrectly)
261{
262 ProcessController::OomController oomController;
263
264 auto child = core::posix::fork([]()
265 {
266 while (true);
267
268 return core::posix::exit::Status::success;
269 }, core::posix::StandardStream::empty);
270
271 EXPECT_GT(child.pid(), 0);
272
273 core::posix::linux::proc::process::OomScoreAdj oomScoreAdj;
274 child >> oomScoreAdj;
275
276 core::posix::linux::proc::process::OomScoreAdj likelyOomScoreAdj, unlikelyOomScoreAdj;
277 {
278 oomController.ensureProcessLikelyToBeKilled(child.pid());
279 child >> likelyOomScoreAdj;
280
281 EXPECT_GE(likelyOomScoreAdj.value, oomScoreAdj.value);
282 }
283
284 {
285 oomController.ensureProcessUnlikelyToBeKilled(child.pid());
286 child >> unlikelyOomScoreAdj;
287
288 EXPECT_LE(unlikelyOomScoreAdj.value, likelyOomScoreAdj.value);
289 }
290}
29197
=== modified file 'tests/modules/common/common.pri'
--- tests/modules/common/common.pri 2014-09-11 16:18:40 +0000
+++ tests/modules/common/common.pri 2014-10-24 15:59:35 +0000
@@ -1,5 +1,5 @@
1CONFIG += no_keywords # keywords clash with ProcessC++1CONFIG += no_keywords # keywords clash with ProcessC++
2PKGCONFIG += process-cpp ubuntu-app-launch-22PKGCONFIG += ubuntu-app-launch-2 process-cpp
33
4QT += quick4QT += quick
55
@@ -7,8 +7,6 @@
7 ../common/mock_desktop_file_reader.h \7 ../common/mock_desktop_file_reader.h \
8 ../common/mock_focus_controller.h \8 ../common/mock_focus_controller.h \
9 ../common/mock_mir_session.h \9 ../common/mock_mir_session.h \
10 ../common/mock_oom_controller.h \
11 ../common/mock_process_controller.h \
12 ../common/mock_proc_info.h \10 ../common/mock_proc_info.h \
13 ../common/mock_prompt_session.h \11 ../common/mock_prompt_session.h \
14 ../common/mock_prompt_session_manager.h \12 ../common/mock_prompt_session_manager.h \
1513
=== modified file 'tests/modules/common/mock_application_controller.h'
--- tests/modules/common/mock_application_controller.h 2014-07-01 13:38:06 +0000
+++ tests/modules/common/mock_application_controller.h 2014-10-24 15:59:35 +0000
@@ -34,6 +34,8 @@
3434
35 MOCK_METHOD1(stopApplicationWithAppId, bool(const QString&));35 MOCK_METHOD1(stopApplicationWithAppId, bool(const QString&));
36 MOCK_METHOD2(startApplicationWithAppIdAndArgs, bool(const QString&, const QStringList&));36 MOCK_METHOD2(startApplicationWithAppIdAndArgs, bool(const QString&, const QStringList&));
37 MOCK_METHOD1(pauseApplicationWithAppId, bool(const QString&));
38 MOCK_METHOD1(resumeApplicationWithAppId, bool(const QString&));
3739
38 MockApplicationController()40 MockApplicationController()
39 {41 {
@@ -57,6 +59,14 @@
57 ON_CALL(*this, startApplicationWithAppIdAndArgs(_, _))59 ON_CALL(*this, startApplicationWithAppIdAndArgs(_, _))
58 .WillByDefault(60 .WillByDefault(
59 Invoke(this, &MockApplicationController::doStartApplicationWithAppIdAndArgs));61 Invoke(this, &MockApplicationController::doStartApplicationWithAppIdAndArgs));
62
63 ON_CALL(*this, pauseApplicationWithAppId(_))
64 .WillByDefault(
65 Invoke(this, &MockApplicationController::doPauseApplicationWithAppId));
66
67 ON_CALL(*this, resumeApplicationWithAppId(_))
68 .WillByDefault(
69 Invoke(this, &MockApplicationController::doResumeApplicationWithAppId));
60 }70 }
6171
62 pid_t doPrimaryPidForAppId(const QString& appId)72 pid_t doPrimaryPidForAppId(const QString& appId)
@@ -85,14 +95,14 @@
8595
86 bool doStopApplicationWithAppId(const QString& appId)96 bool doStopApplicationWithAppId(const QString& appId)
87 {97 {
88 (void) appId;98 Q_UNUSED(appId);
8999
90 return false;100 return false;
91 }101 }
92102
93 bool doStartApplicationWithAppIdAndArgs(const QString& appId, const QStringList& args)103 bool doStartApplicationWithAppIdAndArgs(const QString& appId, const QStringList& args)
94 {104 {
95 (void) args;105 Q_UNUSED(args);
96106
97 auto child = core::posix::fork([]()107 auto child = core::posix::fork([]()
98 {108 {
@@ -110,6 +120,20 @@
110 return false;120 return false;
111 }121 }
112122
123 bool doPauseApplicationWithAppId(const QString& appId)
124 {
125 Q_UNUSED(appId);
126
127 return false;
128 }
129
130 bool doResumeApplicationWithAppId(const QString& appId)
131 {
132 Q_UNUSED(appId);
133
134 return false;
135 }
136
113 QMap<QString, core::posix::ChildProcess> children;137 QMap<QString, core::posix::ChildProcess> children;
114};138};
115} // namespace testing139} // namespace testing
116140
=== removed file 'tests/modules/common/mock_oom_controller.h'
--- tests/modules/common/mock_oom_controller.h 2014-10-10 08:38:30 +0000
+++ tests/modules/common/mock_oom_controller.h 1970-01-01 00:00:00 +0000
@@ -1,34 +0,0 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17#ifndef MOCK_OOM_CONTROLLER_H
18#define MOCK_OOM_CONTROLLER_H
19
20#include <Unity/Application/processcontroller.h>
21
22#include <gmock/gmock.h>
23
24namespace testing
25{
26struct MockOomController : public qtmir::ProcessController::OomController
27{
28 MOCK_METHOD1(ensureProcessLikelyToBeKilled, void(pid_t));
29 MOCK_METHOD1(ensureProcessLessLikelyToBeKilled, void(pid_t));
30 MOCK_METHOD1(ensureProcessUnlikelyToBeKilled, void(pid_t));
31};
32}
33
34#endif // MOCK_OOM_CONTROLLER_H
350
=== removed file 'tests/modules/common/mock_process_controller.h'
--- tests/modules/common/mock_process_controller.h 2014-07-01 13:38:06 +0000
+++ tests/modules/common/mock_process_controller.h 1970-01-01 00:00:00 +0000
@@ -1,45 +0,0 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17#ifndef MOCK_PROCESS_CONTROLLER_H
18#define MOCK_PROCESS_CONTROLLER_H
19
20#include <Unity/Application/processcontroller.h>
21
22#include <gmock/gmock.h>
23
24namespace testing
25{
26struct MockProcessController : public qtmir::ProcessController
27{
28 MockProcessController(const QSharedPointer<qtmir::ProcessController::OomController>& oomController)
29 : m_oomController(oomController)
30 {
31 }
32
33 const QSharedPointer<qtmir::ProcessController::OomController>& oomController() const
34 {
35 return m_oomController;
36 }
37
38 MOCK_CONST_METHOD1(sigStopProcessGroupForPid, bool(pid_t));
39 MOCK_CONST_METHOD1(sigContinueProcessGroupForPid, bool(pid_t));
40
41 QSharedPointer<qtmir::ProcessController::OomController> m_oomController;
42};
43}
44
45#endif // MOCK_PROCESS_CONTROLLER_H
460
=== modified file 'tests/modules/common/qtmir_test.h'
--- tests/modules/common/qtmir_test.h 2014-09-11 16:18:40 +0000
+++ tests/modules/common/qtmir_test.h 2014-10-24 15:59:35 +0000
@@ -20,8 +20,6 @@
2020
21#include <gtest/gtest.h>21#include <gtest/gtest.h>
2222
23#include <core/posix/linux/proc/process/oom_score_adj.h>
24
25#include <Unity/Application/application_manager.h>23#include <Unity/Application/application_manager.h>
26#include <Unity/Application/applicationcontroller.h>24#include <Unity/Application/applicationcontroller.h>
27#include <Unity/Application/mirsurfacemanager.h>25#include <Unity/Application/mirsurfacemanager.h>
@@ -32,8 +30,6 @@
3230
33#include "mock_application_controller.h"31#include "mock_application_controller.h"
34#include "mock_desktop_file_reader.h"32#include "mock_desktop_file_reader.h"
35#include "mock_oom_controller.h"
36#include "mock_process_controller.h"
37#include "mock_proc_info.h"33#include "mock_proc_info.h"
38#include "mock_mir_session.h"34#include "mock_mir_session.h"
39#include "mock_focus_controller.h"35#include "mock_focus_controller.h"
@@ -80,12 +76,7 @@
80{76{
81public:77public:
82 QtMirTest()78 QtMirTest()
83 : processController{79 : mirConfig{
84 QSharedPointer<ProcessController::OomController> (
85 &oomController,
86 [](ProcessController::OomController*){})
87 }
88 , mirConfig{
89 QSharedPointer<FakeMirServerConfiguration> (new FakeMirServerConfiguration)80 QSharedPointer<FakeMirServerConfiguration> (new FakeMirServerConfiguration)
90 }81 }
91 , taskController{82 , taskController{
@@ -94,10 +85,7 @@
94 nullptr,85 nullptr,
95 QSharedPointer<ApplicationController>(86 QSharedPointer<ApplicationController>(
96 &appController,87 &appController,
97 [](ApplicationController*){}),88 [](ApplicationController*){})
98 QSharedPointer<ProcessController>(
99 &processController,
100 [](ProcessController*){})
101 )89 )
102 )90 )
103 }91 }
@@ -150,8 +138,6 @@
150 return nullptr;138 return nullptr;
151 }139 }
152140
153 testing::NiceMock<testing::MockOomController> oomController;
154 testing::NiceMock<testing::MockProcessController> processController;
155 testing::NiceMock<testing::MockApplicationController> appController;141 testing::NiceMock<testing::MockApplicationController> appController;
156 testing::NiceMock<testing::MockProcInfo> procInfo;142 testing::NiceMock<testing::MockProcInfo> procInfo;
157 testing::NiceMock<testing::MockDesktopFileReaderFactory> desktopFileReaderFactory;143 testing::NiceMock<testing::MockDesktopFileReaderFactory> desktopFileReaderFactory;

Subscribers

People subscribed via source and target branches