- add sources.
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / platform / posix_platform_backend_unittest.py
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 import unittest
5
6 from telemetry.core.platform import posix_platform_backend
7
8
9 class PosixPlatformBackendTest(unittest.TestCase):
10
11   def _GetChildPids(self, mock_ps_output, pid):
12     class TestBackend(posix_platform_backend.PosixPlatformBackend):
13
14       # pylint: disable=W0223
15
16       def _GetPsOutput(self, columns, pid=None):
17         return mock_ps_output
18
19     return TestBackend().GetChildPids(pid)
20
21   def testGetChildPidsWithGrandChildren(self):
22     lines = ['1 0 S', '2 1 R', '3 2 S', '4 1 R', '5 4 R']
23     result = self._GetChildPids(lines, 1)
24     self.assertEquals(set(result), set([2, 3, 4, 5]))
25
26   def testGetChildPidsWithNoSuchPid(self):
27     lines = ['1 0 S', '2 1 R', '3 2 S', '4 1 R', '5 4 R']
28     result = self._GetChildPids(lines, 6)
29     self.assertEquals(set(result), set())
30
31   def testGetChildPidsWithZombieChildren(self):
32     lines = ['1 0 S', '2 1 R', '3 2 S', '4 1 R', '5 4 Z']
33     result = self._GetChildPids(lines, 1)
34     self.assertEquals(set(result), set([2, 3, 4]))