Remove linux_chromium_gn_dbg from the chromium CQ.
[chromium-blink-merge.git] / tools / perf / profile_creators / profile_generator_unittest.py
blobfdd064ad3552ae05f80e7cc6e30432971ac32137
1 # Copyright 2014 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.
5 import os
6 import shutil
7 import socket
8 import tempfile
9 import unittest
11 from profile_creators import profile_generator
14 class ProfileGeneratorUnitTest(unittest.TestCase):
15 def setUp(self):
16 self.test_directory = tempfile.mkdtemp()
17 super(ProfileGeneratorUnitTest, self).setUp()
19 def _CreateFunkyFilesAndOnePlainFile(self, sandbox_directory):
20 """Create several special files and one plain file in |sandbox_directory|.
21 """
22 if os.path.exists(sandbox_directory):
23 shutil.rmtree(sandbox_directory)
25 os.mkdir(sandbox_directory)
27 # Make a plain file.
28 plain_filename = os.path.join(sandbox_directory, 'plain_file')
29 open(plain_filename, 'a').close()
31 # Make a directory.
32 directory_filename = os.path.join(sandbox_directory, 'directory')
33 os.mkdir(directory_filename)
35 if getattr(os, 'symlink', None): # Symlinks not supported on Windows.
36 # Make a symlink.
37 symlink_filename = os.path.join(sandbox_directory, 'symlink')
38 os.symlink(plain_filename, symlink_filename)
40 # Make a broken symlink.
41 nonexistant_filename = os.path.join(sandbox_directory, 'i_dont_exist')
42 broken_symlink_filename = os.path.join(sandbox_directory,
43 'broken_symlink')
44 os.symlink(nonexistant_filename, broken_symlink_filename)
46 # Make a named socket.
47 if getattr(socket, 'AF_UNIX', None): # Windows doesn't support these.
48 socket_filename = os.path.join(sandbox_directory, 'named_socket')
49 the_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
50 the_socket.bind(socket_filename)
52 def testIsPseudoFile(self):
53 sandbox_dir = os.path.join(self.test_directory, "sandbox")
54 self._CreateFunkyFilesAndOnePlainFile(sandbox_dir)
56 # If we can copy the directory, we're golden!
57 sandbox_dir_copy = os.path.join(self.test_directory, "sandbox_copy")
58 # pylint: disable=W0212
59 shutil.copytree(sandbox_dir, sandbox_dir_copy,
60 ignore=profile_generator._IsPseudoFile)
62 # Check that only the directory and plain file got copied.
63 dir_contents = os.listdir(sandbox_dir_copy)
64 dir_contents.sort()
65 self.assertEqual(['directory', 'plain_file'], dir_contents)
67 def tearDown(self):
68 shutil.rmtree(self.test_directory)