~ubuntu-branches/ubuntu/wily/upower/wily

« back to all changes in this revision

Viewing changes to debian/patches/test_updates.patch

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2013-03-19 19:19:51 UTC
  • mfrom: (17.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130319191951-2lmdpe40kitm2zbx
Tags: 0.9.20-1
* New upstream release.
* Bump libpolkit-gobject-1-dev build dependency as per upstream
  configure.ac.
* Build with --enable-deprecated, we are not ready yet to drop
  suspend/hibernate functionality.
* Bump Standards-Version to 3.9.4. No changes necessary.
* Add "build" autopkgtest to compile/link/run a simple program against
  libupower-glib.
* Drop unnecessary "needs-root" restriction from upstream-system
  autopkgtest.
* Add no_deprecation_define.patch: Do not require applications to define
  UPOWER_ENABLE_DEPRECATED to access suspend/resume functionality. We are
  not ready to do that yet in Debian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Index: upower-0.9.19/src/linux/integration-test
2
 
===================================================================
3
 
--- upower-0.9.19.orig/src/linux/integration-test       2013-03-18 09:22:00.000000000 +0100
4
 
+++ upower-0.9.19/src/linux/integration-test    2013-03-18 09:25:35.714794057 +0100
5
 
@@ -32,6 +32,12 @@
6
 
     sys.stderr.write('Skipping tests, PyGobject not available for Python 3, or missing GI typelibs: %s\n' % str(e))
7
 
     sys.exit(0)
8
 
 
9
 
+try:
10
 
+    from gi.repository import UMockdev
11
 
+except ImportError:
12
 
+    sys.stderr.write('Skipping tests, umockdev not available (https://launchpad.net/umockdev/)\n')
13
 
+    sys.exit(0)
14
 
+
15
 
 UP = 'org.freedesktop.UPower'
16
 
 
17
 
 (UP_DEVICE_STATE_UNKNOWN, 
18
 
@@ -46,115 +52,58 @@
19
 
         # run from local build tree if we are in one, otherwise use system instance
20
 
         builddir = os.getenv('top_builddir', '.')
21
 
         if os.access (os.path.join(builddir, 'src', 'upowerd'), os.X_OK):
22
 
-            daemon_path = os.path.join(builddir, 'src', 'upowerd')
23
 
+            cls.daemon_path = os.path.join(builddir, 'src', 'upowerd')
24
 
             print('Testing binaries from local build tree')
25
 
         else:
26
 
             print('Testing installed system binaries')
27
 
-            daemon_path = None
28
 
+            cls.daemon_path = None
29
 
             with open('/usr/share/dbus-1/system-services/org.freedesktop.UPower.service') as f:
30
 
                 for line in f:
31
 
                     if line.startswith('Exec='):
32
 
-                        daemon_path = line.split('=', 1)[1].strip()
33
 
+                        cls.daemon_path = line.split('=', 1)[1].strip()
34
 
                         break
35
 
-            assert daemon_path, 'could not determine daemon path from D-BUS .service file'
36
 
+            assert cls.daemon_path, 'could not determine daemon path from D-BUS .service file'
37
 
 
38
 
         # fail on CRITICALs on client side
39
 
         GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_WARNING|
40
 
                                   GLib.LogLevelFlags.LEVEL_ERROR|
41
 
                                   GLib.LogLevelFlags.LEVEL_CRITICAL)
42
 
 
43
 
-        # if we are root, test the real thing on the system bus, otherwise
44
 
-        # start on the session bus
45
 
-        if os.geteuid() == 0:
46
 
-            # kill running daemons
47
 
-            subprocess.call(['killall', 'upowerd'])
48
 
-
49
 
-            cls.dbus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
50
 
-            cls.daemon_argv = [daemon_path]
51
 
-            print('Testing as root on the system bus')
52
 
-        else:
53
 
-            cls.dbus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
54
 
-            cls.daemon_argv = [daemon_path, '--test']
55
 
+        # set up a fake system D-BUS
56
 
+        cls.test_bus = Gio.TestDBus.new(Gio.TestDBusFlags.NONE)
57
 
+        cls.test_bus.up()
58
 
+        del os.environ['DBUS_SESSION_BUS_ADDRESS']
59
 
+        os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = cls.test_bus.get_bus_address()
60
 
 
61
 
-            # use dbus-lauch if possible
62
 
-            print('Testing as user on the session bus')
63
 
+        cls.dbus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
64
 
 
65
 
+    @classmethod
66
 
+    def tearDownClass(cls):
67
 
+        cls.test_bus.down()
68
 
 
69
 
     def setUp(self):
70
 
-        '''Set up a local sysfs tree and determine paths.
71
 
+        '''Set up a local umockdev testbed.
72
 
         
73
 
-        The sysfs tree is empty initially and needs to be populated with
74
 
-        @add_device.
75
 
+        The testbed is initially empty.
76
 
         '''
77
 
-        self.sysfs = tempfile.mkdtemp()
78
 
+        self.testbed = UMockdev.Testbed.new()
79
 
 
80
 
         self.proxy = None 
81
 
         self.log = None
82
 
         self.daemon = None
83
 
 
84
 
     def tearDown(self):
85
 
+        del self.testbed
86
 
         self.stop_daemon()
87
 
-        shutil.rmtree(self.sysfs)
88
 
 
89
 
         # on failures, print daemon log
90
 
-        if not self._outcomeForDoCleanups.success:
91
 
+        if not self._outcomeForDoCleanups.success and self.log:
92
 
             with open(self.log.name) as f:
93
 
                 sys.stderr.write('\n-------------- daemon log: ----------------\n')
94
 
                 sys.stderr.write(f.read())
95
 
                 sys.stderr.write('------------------------------\n')
96
 
 
97
 
     #
98
 
-    # Methods for fake sysfs
99
 
-    #
100
 
-
101
 
-    def add_device(self, subsystem, name, attributes, properties=None):
102
 
-        '''Add a new device to the local sysfs tree.
103
 
-        
104
 
-        Return the device path.
105
 
-        '''
106
 
-        dev_dir = os.path.join(self.sysfs, 'devices', name)
107
 
-        if not os.path.isdir(dev_dir):
108
 
-            os.makedirs(dev_dir)
109
 
-        class_dir = os.path.join(self.sysfs, 'class', subsystem)
110
 
-        if not os.path.isdir(class_dir):
111
 
-            os.makedirs(class_dir)
112
 
-
113
 
-        os.symlink(os.path.join('..', '..', 'devices', name), os.path.join(class_dir, name))
114
 
-        os.symlink(os.path.join('..', '..', 'class', subsystem), os.path.join(dev_dir, 'subsystem'))
115
 
-
116
 
-        attributes['uevent'] = self._props_to_str(properties)
117
 
-
118
 
-        for a, v in attributes.items():
119
 
-            self.set_sys_attribute(dev_dir, a, v)
120
 
-
121
 
-        return dev_dir
122
 
-
123
 
-    def get_sys_attribute(self, devpath, name):
124
 
-        '''Get device attribute from the local sysfs tree.'''
125
 
-
126
 
-        with open(os.path.join(devpath, name), 'r') as f:
127
 
-            return f.read()
128
 
-
129
 
-    def set_sys_attribute(self, devpath, name, value):
130
 
-        '''Set device attribute in the local sysfs tree.'''
131
 
-
132
 
-        with open(os.path.join(devpath, name), 'w') as f:
133
 
-            f.write(value)
134
 
-
135
 
-    def set_sys_property(self, devpath, name, value):
136
 
-        '''Set device udev property in the local sysfs tree.'''
137
 
-
138
 
-        prop_str = self.get_sys_attribute(devpath, 'uevent')
139
 
-        props = {}
140
 
-        for l in prop_str.splitlines():
141
 
-            (k, v) = l.split('=')
142
 
-            props[k] = v.rstrip()
143
 
-
144
 
-        props[name] = value
145
 
-
146
 
-        self.set_sys_attribute(devpath, 'uevent', self._props_to_str(props))
147
 
-
148
 
-    #
149
 
     # Daemon control and D-BUS I/O
150
 
     #
151
 
 
152
 
@@ -169,9 +118,11 @@
153
 
         '''
154
 
         env = os.environ.copy()
155
 
         env['G_DEBUG'] = 'fatal-criticals'
156
 
-        env['SYSFS_PATH'] = self.sysfs
157
 
+        # note: Python doesn't propagate the setenv from Testbed.new(), so we
158
 
+        # have to do that ourselves
159
 
+        env['UMOCKDEV_DIR'] = self.testbed.get_root_dir()
160
 
         self.log = tempfile.NamedTemporaryFile()
161
 
-        self.daemon = subprocess.Popen(self.daemon_argv,
162
 
+        self.daemon = subprocess.Popen(['umockdev-wrapper', self.daemon_path, '-v'],
163
 
                 env=env, stdout=self.log, stderr=subprocess.STDOUT)
164
 
 
165
 
         # wait until the daemon gets online
166
 
@@ -247,8 +198,8 @@
167
 
         self.stop_daemon()
168
 
 
169
 
         # online AC
170
 
-        ac = self.add_device('power_supply', 'AC', 
171
 
-                {'type': 'Mains', 'online': '1' })
172
 
+        ac = self.testbed.add_device('power_supply', 'AC', None,
173
 
+                ['type', 'Mains', 'online', '1' ], [])
174
 
 
175
 
         self.start_daemon()
176
 
         devs = self.proxy.EnumerateDevices()
177
 
@@ -263,7 +214,7 @@
178
 
         self.stop_daemon()
179
 
 
180
 
         # offline AC
181
 
-        self.set_sys_attribute(ac, 'online', '0')
182
 
+        self.testbed.set_attribute(ac, 'online', '0')
183
 
         self.start_daemon()
184
 
         devs = self.proxy.EnumerateDevices()
185
 
         self.assertEqual(len(devs), 1)
186
 
@@ -274,14 +225,14 @@
187
 
         self.stop_daemon()
188
 
 
189
 
         # offline AC + discharging battery
190
 
-        bat0 = self.add_device('power_supply', 'BAT0', 
191
 
-                {'type': 'Battery', 
192
 
-                 'present': '1', 
193
 
-                 'status': 'Discharging',
194
 
-                 'energy_full': '60000000',
195
 
-                 'energy_full_design': '80000000',
196
 
-                 'energy_now': '48000000',
197
 
-                 'voltage_now': '12000000'})
198
 
+        bat0 = self.testbed.add_device('power_supply', 'BAT0', None,
199
 
+                ['type', 'Battery', 
200
 
+                 'present', '1', 
201
 
+                 'status', 'Discharging',
202
 
+                 'energy_full', '60000000',
203
 
+                 'energy_full_design', '80000000',
204
 
+                 'energy_now', '48000000',
205
 
+                 'voltage_now', '12000000'], [])
206
 
 
207
 
         self.start_daemon()
208
 
         devs = self.proxy.EnumerateDevices()
209
 
@@ -304,7 +255,7 @@
210
 
         self.stop_daemon()
211
 
 
212
 
         # offline AC + discharging low battery
213
 
-        self.set_sys_attribute(bat0, 'energy_now', '1500000')
214
 
+        self.testbed.set_attribute(bat0, 'energy_now', '1500000')
215
 
         self.start_daemon()
216
 
         self.assertEqual(self.get_dbus_property('OnBattery'), True)
217
 
         self.assertEqual(self.get_dbus_property('OnLowBattery'), True)
218
 
@@ -314,7 +265,7 @@
219
 
         self.stop_daemon()
220
 
 
221
 
         # now connect AC again
222
 
-        self.set_sys_attribute(ac, 'online', '1')
223
 
+        self.testbed.set_attribute(ac, 'online', '1')
224
 
         self.start_daemon()
225
 
         devs = self.proxy.EnumerateDevices()
226
 
         self.assertEqual(len(devs), 2)
227
 
@@ -328,23 +279,23 @@
228
 
         '''Multiple batteries'''
229
 
 
230
 
         # one well charged, one low
231
 
-        bat0 = self.add_device('power_supply', 'BAT0', 
232
 
-                {'type': 'Battery', 
233
 
-                 'present': '1', 
234
 
-                 'status': 'Discharging',
235
 
-                 'energy_full': '60000000',
236
 
-                 'energy_full_design': '80000000',
237
 
-                 'energy_now': '48000000',
238
 
-                 'voltage_now': '12000000'})
239
 
-
240
 
-        bat1 = self.add_device('power_supply', 'BAT1', 
241
 
-                {'type': 'Battery', 
242
 
-                 'present': '1', 
243
 
-                 'status': 'Discharging',
244
 
-                 'energy_full': '60000000',
245
 
-                 'energy_full_design': '80000000',
246
 
-                 'energy_now': '1500000',
247
 
-                 'voltage_now': '12000000'})
248
 
+        bat0 = self.testbed.add_device('power_supply', 'BAT0', None,
249
 
+                ['type', 'Battery', 
250
 
+                 'present', '1', 
251
 
+                 'status', 'Discharging',
252
 
+                 'energy_full', '60000000',
253
 
+                 'energy_full_design', '80000000',
254
 
+                 'energy_now', '48000000',
255
 
+                 'voltage_now', '12000000'], [])
256
 
+
257
 
+        bat1 = self.testbed.add_device('power_supply', 'BAT1', None,
258
 
+                ['type', 'Battery', 
259
 
+                 'present', '1', 
260
 
+                 'status', 'Discharging',
261
 
+                 'energy_full', '60000000',
262
 
+                 'energy_full_design', '80000000',
263
 
+                 'energy_now', '1500000',
264
 
+                 'voltage_now', '12000000'], [])
265
 
 
266
 
         self.start_daemon()
267
 
         devs = self.proxy.EnumerateDevices()
268
 
@@ -357,7 +308,7 @@
269
 
         self.stop_daemon()
270
 
 
271
 
         # now set both to low
272
 
-        self.set_sys_attribute(bat0, 'energy_now', '1500000')
273
 
+        self.testbed.set_attribute(bat0, 'energy_now', '1500000')
274
 
         self.start_daemon()
275
 
         self.assertEqual(self.get_dbus_property('OnBattery'), True)
276
 
         self.assertEqual(self.get_dbus_property('OnLowBattery'), True)
277
 
@@ -366,14 +317,14 @@
278
 
     def test_unknown_battery_status(self):
279
 
         '''Unknown battery charge status'''
280
 
 
281
 
-        bat0 = self.add_device('power_supply', 'BAT0', 
282
 
-                {'type': 'Battery', 
283
 
-                 'present': '1', 
284
 
-                 'status': 'unknown',
285
 
-                 'energy_full': '60000000',
286
 
-                 'energy_full_design': '80000000',
287
 
-                 'energy_now': '48000000',
288
 
-                 'voltage_now': '12000000'})
289
 
+        bat0 = self.testbed.add_device('power_supply', 'BAT0', None,
290
 
+                ['type', 'Battery', 
291
 
+                 'present', '1', 
292
 
+                 'status', 'unknown',
293
 
+                 'energy_full', '60000000',
294
 
+                 'energy_full_design', '80000000',
295
 
+                 'energy_now', '48000000',
296
 
+                 'voltage_now', '12000000'], [])
297
 
 
298
 
         # with no other power sources, the OnBattery value here is really
299
 
         # arbitrary, so don't test it. The only thing we know for sure is that
300
 
@@ -383,14 +334,14 @@
301
 
         self.stop_daemon()
302
 
 
303
 
         # However, if we have an AC, we can infer
304
 
-        ac = self.add_device('power_supply', 'AC', 
305
 
-                {'type': 'Mains', 'online': '0' })
306
 
+        ac = self.testbed.add_device('power_supply', 'AC', None,
307
 
+                ['type', 'Mains', 'online', '0'], [])
308
 
         self.start_daemon()
309
 
         self.assertEqual(self.get_dbus_property('OnBattery'), True)
310
 
         self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
311
 
         self.stop_daemon()
312
 
 
313
 
-        self.set_sys_attribute(ac, 'online', '1')
314
 
+        self.testbed.set_attribute(ac, 'online', '1')
315
 
         self.start_daemon()
316
 
         self.assertEqual(self.get_dbus_property('OnBattery'), False)
317
 
         self.assertEqual(self.get_dbus_property('OnLowBattery'), False)
318
 
@@ -401,15 +352,15 @@
319
 
         
320
 
         energy_* is in uWh, while charge_* is in uAh.
321
 
         '''
322
 
-        bat0 = self.add_device('power_supply', 'BAT0', 
323
 
-                {'type': 'Battery', 
324
 
-                 'present': '1', 
325
 
-                 'status': 'Discharging',
326
 
-                 'charge_full': '10500000',
327
 
-                 'charge_full_design': '11000000',
328
 
-                 'charge_now': '7875000',
329
 
-                 'current_now': '787000',
330
 
-                 'voltage_now': '12000000'})
331
 
+        bat0 = self.testbed.add_device('power_supply', 'BAT0', None,
332
 
+                ['type', 'Battery', 
333
 
+                 'present', '1', 
334
 
+                 'status', 'Discharging',
335
 
+                 'charge_full', '10500000',
336
 
+                 'charge_full_design', '11000000',
337
 
+                 'charge_now', '7875000',
338
 
+                 'current_now', '787000',
339
 
+                 'voltage_now', '12000000'], [])
340
 
 
341
 
         self.start_daemon()
342
 
         devs = self.proxy.EnumerateDevices()
343
 
@@ -431,14 +382,14 @@
344
 
     def test_battery_energy_charge_mixed(self):
345
 
         '''battery which reports current energy, but full charge'''
346
 
 
347
 
-        bat0 = self.add_device('power_supply', 'BAT0', 
348
 
-                {'type': 'Battery', 
349
 
-                 'present': '1', 
350
 
-                 'status': 'Discharging',
351
 
-                 'charge_full': '10500000',
352
 
-                 'charge_full_design': '11000000',
353
 
-                 'energy_now': '50400000',
354
 
-                 'voltage_now': '12000000'})
355
 
+        bat0 = self.testbed.add_device('power_supply', 'BAT0', None,
356
 
+                ['type', 'Battery', 
357
 
+                 'present', '1', 
358
 
+                 'status', 'Discharging',
359
 
+                 'charge_full', '10500000',
360
 
+                 'charge_full_design', '11000000',
361
 
+                 'energy_now', '50400000',
362
 
+                 'voltage_now', '12000000'], [])
363
 
 
364
 
         self.start_daemon()
365
 
         devs = self.proxy.EnumerateDevices()
366
 
@@ -461,12 +412,12 @@
367
 
         '''UPS properties with and without AC'''
368
 
 
369
 
         # add a charging UPS
370
 
-        ups0 = self.add_device('usb', 'hiddev0', {}, 
371
 
-                {'DEVNAME': 'null', 'UPOWER_VENDOR': 'APC',
372
 
-                 'UPOWER_BATTERY_TYPE': 'ups',
373
 
-                 'UPOWER_FAKE_DEVICE': '1',
374
 
-                 'UPOWER_FAKE_HID_CHARGING': '1',
375
 
-                 'UPOWER_FAKE_HID_PERCENTAGE': '70'})
376
 
+        ups0 = self.testbed.add_device('usb', 'hiddev0', None, [],
377
 
+                ['DEVNAME', 'null', 'UPOWER_VENDOR', 'APC',
378
 
+                 'UPOWER_BATTERY_TYPE', 'ups',
379
 
+                 'UPOWER_FAKE_DEVICE', '1',
380
 
+                 'UPOWER_FAKE_HID_CHARGING', '1',
381
 
+                 'UPOWER_FAKE_HID_PERCENTAGE', '70'])
382
 
 
383
 
         self.start_daemon()
384
 
         devs = self.proxy.EnumerateDevices()
385
 
@@ -482,7 +433,7 @@
386
 
         self.stop_daemon()
387
 
 
388
 
         # now switch to discharging UPS
389
 
-        self.set_sys_property(ups0, 'UPOWER_FAKE_HID_CHARGING', '0')
390
 
+        self.testbed.set_property(ups0, 'UPOWER_FAKE_HID_CHARGING', '0')
391
 
 
392
 
         self.start_daemon()
393
 
         devs = self.proxy.EnumerateDevices()
394
 
@@ -497,7 +448,7 @@
395
 
         self.stop_daemon()
396
 
 
397
 
         # low UPS charge
398
 
-        self.set_sys_property(ups0, 'UPOWER_FAKE_HID_PERCENTAGE', '2')
399
 
+        self.testbed.set_property(ups0, 'UPOWER_FAKE_HID_PERCENTAGE', '2')
400
 
         self.start_daemon()
401
 
         self.assertEqual(self.get_dbus_dev_property(ups0_up, 'Percentage'), 2.0)
402
 
         self.assertEqual(self.get_dbus_dev_property(ups0_up, 'State'), UP_DEVICE_STATE_DISCHARGING)
403
 
@@ -506,8 +457,8 @@
404
 
         self.stop_daemon()
405
 
 
406
 
         # now add an offline AC, should still be on battery
407
 
-        ac = self.add_device('power_supply', 'AC', 
408
 
-                {'type': 'Mains', 'online': '0' })
409
 
+        ac = self.testbed.add_device('power_supply', 'AC', None,
410
 
+                ['type', 'Mains', 'online', '0'], [])
411
 
         self.start_daemon()
412
 
         devs = self.proxy.EnumerateDevices()
413
 
         self.assertEqual(len(devs), 2)
414
 
@@ -523,7 +474,7 @@
415
 
         self.stop_daemon()
416
 
 
417
 
         # now plug in the AC, should switch to OnBattery=False
418
 
-        self.set_sys_attribute(ac, 'online', '1')
419
 
+        self.testbed.set_attribute(ac, 'online', '1')
420
 
         self.start_daemon()
421
 
         self.assertEqual(self.get_dbus_property('OnBattery'), False)
422
 
         self.assertEqual(self.get_dbus_property('OnLowBattery'), False)