/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1707.2.2 by Robert Collins
Start on bench_add, an add benchtest.
1
# Copyright (C) 2006 by Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
18
"""Benchmark test suite for bzr."""
19
1908.2.12 by John Arbash Meinel
Fix a small bug in _create_heavily_merged_tree when the target dir already exists
20
import errno
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
21
import os
22
import shutil
23
24
from bzrlib import (
25
    add,
26
    bzrdir,
27
    osutils,
28
    plugin,
29
    workingtree,
30
    )
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
31
from bzrlib.tests.TestUtil import TestLoader
1714.1.4 by Robert Collins
Add new benchmarks for status and commit.
32
from bzrlib.tests.blackbox import ExternalBase
33
1841.1.1 by John Arbash Meinel
Allow plugins to provide benchmarks just like they do tests
34
1714.1.4 by Robert Collins
Add new benchmarks for status and commit.
35
class Benchmark(ExternalBase):
36
1908.2.4 by John Arbash Meinel
Add the ability to specify a benchmark cache directory.
37
    CACHE_ROOT = None
38
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
39
    def make_kernel_like_tree(self, url=None, root='.',
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
40
                              link_working=False):
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
41
        """Setup a temporary tree roughly like a kernel tree.
42
        
43
        :param url: Creat the kernel like tree as a lightweight checkout
44
        of a new branch created at url.
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
45
        :param link_working: instead of creating a new copy of all files
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
46
            just hardlink the working tree. Tests must request this, because
47
            they must break links if they want to change the files
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
48
        """
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
49
        if url is not None:
50
            b = bzrdir.BzrDir.create_branch_convenience(url)
51
            d = bzrdir.BzrDir.create(root)
52
            bzrlib.branch.BranchReferenceFormat().initialize(d, b)
53
            tree = d.create_workingtree()
54
        else:
55
            tree = bzrdir.BzrDir.create_standalone_workingtree(root)
56
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
57
        self._link_or_copy_kernel_files(root=root, do_link=link_working)
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
58
        return tree
59
60
    def _make_kernel_files(self, root='.'):
1714.1.4 by Robert Collins
Add new benchmarks for status and commit.
61
        # a kernel tree has ~10000 and 500 directory, with most files around 
62
        # 3-4 levels deep. 
63
        # we simulate this by three levels of dirs named 0-7, givin 512 dirs,
64
        # and 20 files each.
65
        files = []
66
        for outer in range(8):
67
            files.append("%s/" % outer)
68
            for middle in range(8):
69
                files.append("%s/%s/" % (outer, middle))
70
                for inner in range(8):
71
                    prefix = "%s/%s/%s/" % (outer, middle, inner)
72
                    files.append(prefix)
73
                    files.extend([prefix + str(foo) for foo in range(20)])
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
74
        cwd = osutils.getcwd()
75
        os.chdir(root)
1714.1.4 by Robert Collins
Add new benchmarks for status and commit.
76
        self.build_tree(files)
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
77
        os.chdir(cwd)
78
1908.2.5 by John Arbash Meinel
Updated bench_bench tests to test exactly what we really want to test
79
    def _cache_kernel_like_tree(self):
80
        """Create the kernel_like_tree cache dir if it doesn't exist"""
81
        cache_dir, is_cached = self.get_cache_dir('kernel_like_tree')
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
82
        if cache_dir is None:
83
            return None
1908.2.5 by John Arbash Meinel
Updated bench_bench tests to test exactly what we really want to test
84
        if is_cached:
85
            return cache_dir
86
        os.mkdir(cache_dir)
87
        self._make_kernel_files(root=cache_dir)
88
        self._protect_files(cache_dir)
89
        return cache_dir
90
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
91
    def _link_or_copy_kernel_files(self, root, do_link=True):
92
        """Hardlink the kernel files from the cached location.
93
94
        If the platform doesn't correctly support hardlinking files, it
95
        reverts to just creating new ones.
96
        """
97
98
        if not osutils.hardlinks_good() or not do_link:
99
            # Turns out that 'shutil.copytree()' is no faster than
100
            # just creating them. Probably the python overhead.
101
            # Plain _make_kernel_files takes 5s
102
            # cp -a takes 3s
103
            # using hardlinks takes < 1s.
104
            self._make_kernel_files(root=root)
105
            return
106
1908.2.5 by John Arbash Meinel
Updated bench_bench tests to test exactly what we really want to test
107
        cache_dir = self._cache_kernel_like_tree()
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
108
        if cache_dir is None:
109
            self._make_kernel_files(root=root)
110
            return
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
111
112
        # Hardlinking the target directory is *much* faster (7s => <1s).
1908.2.4 by John Arbash Meinel
Add the ability to specify a benchmark cache directory.
113
        osutils.copy_tree(cache_dir, root,
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
114
                          handlers={'file':os.link})
115
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
116
    def _create_kernel_like_added_tree(self, root, in_cache=False):
117
        """Create a kernel-like tree with the all files added
1908.2.5 by John Arbash Meinel
Updated bench_bench tests to test exactly what we really want to test
118
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
119
        :param root: The root directory to create the files
120
        :param in_cache: Is this being created in the cache dir?
121
        """
1908.2.5 by John Arbash Meinel
Updated bench_bench tests to test exactly what we really want to test
122
        # Get a basic tree with working files
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
123
        tree = self.make_kernel_like_tree(root=root,
124
                                          link_working=in_cache)
1908.2.5 by John Arbash Meinel
Updated bench_bench tests to test exactly what we really want to test
125
        # Add everything to it
1908.2.9 by John Arbash Meinel
Allow pre-warming the hash-cache
126
        tree.lock_write()
127
        try:
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
128
            add.smart_add_tree(tree, [root], recurse=True, save=True)
129
            if in_cache:
130
                self._protect_files(root+'/.bzr')
1908.2.9 by John Arbash Meinel
Allow pre-warming the hash-cache
131
        finally:
132
            tree.unlock()
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
133
        return tree
1908.2.5 by John Arbash Meinel
Updated bench_bench tests to test exactly what we really want to test
134
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
135
    def make_kernel_like_added_tree(self, root='.',
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
136
                                    link_working=True,
1908.2.9 by John Arbash Meinel
Allow pre-warming the hash-cache
137
                                    hot_cache=True):
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
138
        """Make a kernel like tree, with all files added
139
140
        :param root: Where to create the files
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
141
        :param link_working: Instead of copying all of the working tree
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
142
            files, just hardlink them to the cached files. Tests can unlink
143
            files that they will change.
1908.2.9 by John Arbash Meinel
Allow pre-warming the hash-cache
144
        :param hot_cache: Run through the newly created tree and make sure
145
            the stat-cache is correct. The old way of creating a freshly
146
            added tree always had a hot cache.
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
147
        """
1908.2.3 by John Arbash Meinel
Support caching a committed kernel-like tree, and mark hardlinked trees as readonly.
148
        # There isn't much underneath .bzr, so we don't support hardlinking
149
        # it. Testing showed there wasn't much gain, and there is potentially
150
        # a problem if someone modifies something underneath us.
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
151
        cache_dir, is_cached = self.get_cache_dir('kernel_like_added_tree')
152
        if cache_dir is None:
153
            # Not caching
154
            return self._create_kernel_like_added_tree(root, in_cache=False)
155
156
        if not is_cached:
157
            self._create_kernel_like_added_tree(root=cache_dir,
158
                                                in_cache=True)
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
159
1908.2.9 by John Arbash Meinel
Allow pre-warming the hash-cache
160
        return self._clone_tree(cache_dir, root,
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
161
                                link_working=link_working,
1908.2.9 by John Arbash Meinel
Allow pre-warming the hash-cache
162
                                hot_cache=hot_cache)
1908.2.3 by John Arbash Meinel
Support caching a committed kernel-like tree, and mark hardlinked trees as readonly.
163
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
164
    def _create_kernel_like_committed_tree(self, root, in_cache=False):
165
        """Create a kernel-like tree with all files added and committed"""
1908.2.5 by John Arbash Meinel
Updated bench_bench tests to test exactly what we really want to test
166
        # Get a basic tree with working files
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
167
        tree = self.make_kernel_like_added_tree(root=root,
168
                                                link_working=in_cache,
169
                                                hot_cache=(not in_cache))
1908.2.5 by John Arbash Meinel
Updated bench_bench tests to test exactly what we really want to test
170
        tree.commit('first post', rev_id='r1')
171
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
172
        if in_cache:
173
            self._protect_files(root+'/.bzr')
174
        return tree
1908.2.5 by John Arbash Meinel
Updated bench_bench tests to test exactly what we really want to test
175
1908.2.3 by John Arbash Meinel
Support caching a committed kernel-like tree, and mark hardlinked trees as readonly.
176
    def make_kernel_like_committed_tree(self, root='.',
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
177
                                    link_working=True,
178
                                    link_bzr=False,
1908.2.9 by John Arbash Meinel
Allow pre-warming the hash-cache
179
                                    hot_cache=True):
1908.2.3 by John Arbash Meinel
Support caching a committed kernel-like tree, and mark hardlinked trees as readonly.
180
        """Make a kernel like tree, with all files added and committed
181
182
        :param root: Where to create the files
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
183
        :param link_working: Instead of copying all of the working tree
1908.2.3 by John Arbash Meinel
Support caching a committed kernel-like tree, and mark hardlinked trees as readonly.
184
            files, just hardlink them to the cached files. Tests can unlink
185
            files that they will change.
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
186
        :param link_bzr: Hardlink the .bzr directory. For readonly 
1908.2.3 by John Arbash Meinel
Support caching a committed kernel-like tree, and mark hardlinked trees as readonly.
187
            operations this is safe, and shaves off a lot of setup time
188
        """
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
189
        cache_dir, is_cached = self.get_cache_dir('kernel_like_committed_tree')
190
        if cache_dir is None:
191
            return self._create_kernel_like_committed_tree(root=root,
192
                                                           in_cache=False)
193
194
        if not is_cached:
195
            self._create_kernel_like_committed_tree(root=cache_dir,
196
                                                    in_cache=True)
1908.2.3 by John Arbash Meinel
Support caching a committed kernel-like tree, and mark hardlinked trees as readonly.
197
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
198
        # Now we have a cached tree, just copy it
1908.2.9 by John Arbash Meinel
Allow pre-warming the hash-cache
199
        return self._clone_tree(cache_dir, root,
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
200
                                link_bzr=link_bzr,
201
                                link_working=link_working,
1908.2.9 by John Arbash Meinel
Allow pre-warming the hash-cache
202
                                hot_cache=hot_cache)
1707.2.2 by Robert Collins
Start on bench_add, an add benchtest.
203
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
204
    def _create_many_commit_tree(self, root, in_cache=False):
205
        tree = bzrdir.BzrDir.create_standalone_workingtree(root)
1756.1.2 by Aaron Bentley
Show logs using get_revisions
206
        tree.lock_write()
207
        try:
208
            for i in xrange(1000):
209
                tree.commit('no-changes commit %d' % i)
210
        finally:
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
211
            tree.unlock()
212
        if in_cache:
213
            self._protect_files(root+'/.bzr')
1908.2.6 by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached
214
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
215
        return tree
1908.2.6 by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached
216
217
    def make_many_commit_tree(self, directory_name='.',
218
                              hardlink=False):
219
        """Create a tree with many commits.
220
        
221
        No file changes are included. Not hardlinking the working tree, 
222
        because there are no working tree files.
1756.2.19 by Aaron Bentley
Add benchmarks for merged trees
223
        """
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
224
        cache_dir, is_cached = self.get_cache_dir('many_commit_tree')
225
        if cache_dir is None:
226
            return self._create_many_commit_tree(root=directory_name,
227
                                                 in_cache=False)
228
229
        if not is_cached:
230
            self._create_many_commit_tree(root=cache_dir, in_cache=True)
231
1908.2.9 by John Arbash Meinel
Allow pre-warming the hash-cache
232
        return self._clone_tree(cache_dir, directory_name,
233
                                link_bzr=hardlink,
234
                                hot_cache=True)
1908.2.6 by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached
235
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
236
    def _create_heavily_merged_tree(self, root, in_cache=False):
1908.2.12 by John Arbash Meinel
Fix a small bug in _create_heavily_merged_tree when the target dir already exists
237
        try:
238
            os.mkdir(root)
239
        except (IOError, OSError), e:
240
            if e.errno not in (errno.EEXIST,):
241
                raise
242
1908.2.6 by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached
243
        tree = bzrdir.BzrDir.create_standalone_workingtree(
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
244
                root + '/tree1')
1756.2.19 by Aaron Bentley
Add benchmarks for merged trees
245
        tree.lock_write()
246
        try:
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
247
            tree2 = tree.bzrdir.sprout(root + '/tree2').open_workingtree()
1756.2.21 by Aaron Bentley
Clean up merge log benchmark
248
            tree2.lock_write()
1756.2.19 by Aaron Bentley
Add benchmarks for merged trees
249
            try:
1756.2.21 by Aaron Bentley
Clean up merge log benchmark
250
                for i in xrange(250):
251
                    revision_id = tree.commit('no-changes commit %d-a' % i)
252
                    tree2.branch.fetch(tree.branch, revision_id)
253
                    tree2.set_pending_merges([revision_id])
254
                    revision_id = tree2.commit('no-changes commit %d-b' % i)
255
                    tree.branch.fetch(tree2.branch, revision_id)
256
                    tree.set_pending_merges([revision_id])
257
                tree.set_pending_merges([])
1756.2.19 by Aaron Bentley
Add benchmarks for merged trees
258
            finally:
1908.2.6 by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached
259
                tree2.unlock()
1756.2.21 by Aaron Bentley
Clean up merge log benchmark
260
        finally:
1908.2.6 by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached
261
            tree.unlock()
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
262
        if in_cache:
263
            self._protect_files(root+'/tree1/.bzr')
264
        return tree
1908.2.6 by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached
265
266
    def make_heavily_merged_tree(self, directory_name='.',
267
                                 hardlink=False):
268
        """Create a tree in which almost every commit is a merge.
269
       
270
        No file changes are included.  This produces two trees, 
271
        one of which is returned.  Except for the first commit, every
272
        commit in its revision-history is a merge another commit in the other
273
        tree.  Not hardlinking the working tree, because there are no working 
274
        tree files.
275
        """
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
276
        cache_dir, is_cached = self.get_cache_dir('heavily_merged_tree')
277
        if cache_dir is None:
278
            # Not caching
279
            return self._create_heavily_merged_tree(root=directory_name,
280
                                                    in_cache=False)
281
282
        if not is_cached:
283
            self._create_heavily_merged_tree(root=cache_dir, in_cache=True)
284
1908.2.6 by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached
285
        tree_dir = cache_dir + '/tree1'
1908.2.9 by John Arbash Meinel
Allow pre-warming the hash-cache
286
        return self._clone_tree(tree_dir, directory_name,
287
                                link_bzr=hardlink,
288
                                hot_cache=True)
1756.2.19 by Aaron Bentley
Add benchmarks for merged trees
289
1707.2.2 by Robert Collins
Start on bench_add, an add benchtest.
290
1908.2.13 by John Arbash Meinel
Factor out all helper functions into a tree creator class
291
class TreeCreator(object):
292
    """Just a basic class which is used to create various test trees"""
293
294
    CACHE_ROOT = None
295
296
    def __init__(self, tree_name, link_bzr=False, link_working=False,
297
                 hot_cache=True):
298
        """Instantiate a new creator object, supply the id of the tree"""
299
300
        self._tree_name = tree_name
301
        self._link_bzr = link_bzr
302
        self._link_working = link_working
303
        self._hot_cache = hot_cache
304
305
    @staticmethod
306
    def is_caching_enabled():
307
        """Will we try to cache the tree we create?"""
308
        return TreeCreator.CACHE_ROOT is not None
309
310
    def is_cached(self):
311
        """Is this tree already cached?"""
312
        cache_dir = self._get_cache_dir()
313
        if cache_dir is None:
314
            return False
315
        return os.path.exists(cache_dir):
316
        
317
    def create(self, root):
318
        """Create a new tree at 'root'.
319
320
        :return: A WorkingTree object.
321
        """
322
        cache_dir = self._get_cache_dir()
323
        if cache_dir is None:
324
            # Not caching
325
            return self._create_tree(root, in_cache=False)
326
327
        if not self.is_cached():
328
            self._create_tree(root=cache_dir, in_cache=True)
329
330
        return self._clone_cached_tree(root)
331
332
    def _get_cache_dir(self):
333
        """Get the directory to use for caching this tree
334
335
        :return: The path to use for caching. If None, caching is disabled
336
        """
337
        if self.CACHE_ROOT is None:
338
            return None
339
        return osutils.pathjoin(self.CACHE_ROOT, extra)
340
341
    def _create_tree(self, root, in_cache=False):
342
        """Create the desired tree in the given location.
343
344
        Children should override this function to provide the actual creation
345
        of the desired tree. This will be called by 'create()'. If it is
346
        building a tree in the cache, before copying it to the real target,
347
        it will pass in_cache=True
348
        """
349
        raise NotImplemented(self._create_tree)
350
351
    def _clone_cached_tree(self, dest):
352
        """Copy the contents of the cached dir into the destination
353
        Optionally hardlink certain pieces of the tree.
354
355
        This is just meant as a helper function for child classes
356
357
        :param dest: The destination to copy things to
358
        """
359
        # We use shutil.copyfile so that we don't copy permissions
360
        # because most of our source trees are marked readonly to
361
        # prevent modifying in the case of hardlinks
362
        handlers = {'file':shutil.copyfile}
363
        if osutils.hardlinks_good():
364
            if self._link_working:
365
                if self._link_bzr:
366
                    handlers = {'file':os.link}
367
                else:
368
                    # Don't hardlink files inside bzr
369
                    def file_handler(source, dest):
370
                        if '.bzr/' in source:
371
                            shutil.copyfile(source, dest)
372
                        else:
373
                            os.link(source, dest)
374
                    handlers = {'file':file_handler}
375
            elif self._link_bzr:
376
                # Only link files inside .bzr/
377
                def file_handler(source, dest):
378
                    if '.bzr/' in source:
379
                        os.link(source, dest)
380
                    else:
381
                        shutil.copyfile(source, dest)
382
                handlers = {'file':file_handler}
383
384
        source = self._get_cache_dir()
385
        osutils.copy_tree(source, dest, handlers=handlers)
386
        tree = workingtree.WorkingTree.open(dest)
387
        if self._hot_cache:
388
            tree.lock_write()
389
            try:
390
                # tree._hashcache.scan() just checks and removes
391
                # entries that are out of date
392
                # we need to actually store new ones
393
                for path, ie in tree.inventory.iter_entries_by_dir():
394
                    tree.get_file_sha1(ie.file_id, path)
395
            finally:
396
                tree.unlock()
397
        # If we didn't iterate the tree, the hash cache is technically
398
        # invalid, and it would be better to remove it, but there is
399
        # no public api for that.
400
        return tree
401
402
    def _protect_files(self, root):
403
        """Chmod all files underneath 'root' to prevent writing
404
405
        This is a helper function for child classes.
406
407
        :param root: The base directory to modify
408
        """
409
        for dirinfo, entries in osutils.walkdirs(root):
410
            for relpath, name, kind, st, abspath in entries:
411
                if kind == 'file':
412
                    os.chmod(abspath, 0440)
413
414
1707.2.2 by Robert Collins
Start on bench_add, an add benchtest.
415
def test_suite():
416
    """Build and return a TestSuite which contains benchmark tests only."""
417
    testmod_names = [ \
418
                   'bzrlib.benchmarks.bench_add',
1755.2.1 by Robert Collins
Add a benchmark for make_kernel_like_tree.
419
                   'bzrlib.benchmarks.bench_bench',
1714.1.4 by Robert Collins
Add new benchmarks for status and commit.
420
                   'bzrlib.benchmarks.bench_checkout',
1714.1.5 by Robert Collins
Add commit benchmark.
421
                   'bzrlib.benchmarks.bench_commit',
1757.2.10 by Robert Collins
Give all inventory entries __slots__ that are useful with the current codebase.
422
                   'bzrlib.benchmarks.bench_inventory',
1756.1.7 by Aaron Bentley
Merge bzr.dev
423
                   'bzrlib.benchmarks.bench_log',
1756.1.2 by Aaron Bentley
Show logs using get_revisions
424
                   'bzrlib.benchmarks.bench_osutils',
1752.1.2 by Aaron Bentley
Benchmark the rocks command
425
                   'bzrlib.benchmarks.bench_rocks',
1714.1.4 by Robert Collins
Add new benchmarks for status and commit.
426
                   'bzrlib.benchmarks.bench_status',
1534.10.33 by Aaron Bentley
Add canonicalize_path benchmark
427
                   'bzrlib.benchmarks.bench_transform',
1732.1.11 by John Arbash Meinel
Trying multiple things to get WorkingTree.list_files time down
428
                   'bzrlib.benchmarks.bench_workingtree',
1707.2.2 by Robert Collins
Start on bench_add, an add benchtest.
429
                   ]
1841.1.1 by John Arbash Meinel
Allow plugins to provide benchmarks just like they do tests
430
    suite = TestLoader().loadTestsFromModuleNames(testmod_names) 
431
432
    # Load any benchmarks from plugins
1711.2.78 by John Arbash Meinel
Cleanup the imports in bzrlib.benchmark
433
    for name, module in plugin.all_plugins().items():
434
        if getattr(module, 'bench_suite', None) is not None:
435
            suite.addTest(module.bench_suite())
1841.1.1 by John Arbash Meinel
Allow plugins to provide benchmarks just like they do tests
436
437
    return suite