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.
6 from telemetry.core.platform import posix_platform_backend
9 class PosixPlatformBackendTest(unittest.TestCase):
11 def _GetChildPids(self, mock_ps_output, pid):
12 class TestBackend(posix_platform_backend.PosixPlatformBackend):
14 # pylint: disable=W0223
16 def _GetPsOutput(self, columns, pid=None):
19 return TestBackend().GetChildPids(pid)
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]))
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())
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]))