test_utils.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright 2017 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. """Test utilities for cygprofile scripts."""
  5. import collections
  6. import process_profiles
  7. # Used by ProfileFile to generate unique file names.
  8. _FILE_COUNTER = 0
  9. SimpleTestSymbol = collections.namedtuple(
  10. 'SimpleTestSymbol', ['name', 'offset', 'size'])
  11. class TestSymbolOffsetProcessor(process_profiles.SymbolOffsetProcessor):
  12. def __init__(self, symbol_infos):
  13. super().__init__(None)
  14. self._symbol_infos = symbol_infos
  15. class TestProfileManager(process_profiles.ProfileManager):
  16. def __init__(self, filecontents_mapping):
  17. super().__init__(filecontents_mapping.keys())
  18. self._filecontents_mapping = filecontents_mapping
  19. def _ReadOffsets(self, filename):
  20. return self._filecontents_mapping[filename]
  21. def _ReadJSON(self, filename):
  22. return self._filecontents_mapping[filename]
  23. def ProfileFile(timestamp_sec, phase, process_name=None):
  24. global _FILE_COUNTER
  25. _FILE_COUNTER += 1
  26. if process_name:
  27. name_str = process_name + '-'
  28. else:
  29. name_str = ''
  30. return 'test-directory/profile-hitmap-{}{}-{}.txt_{}'.format(
  31. name_str, _FILE_COUNTER, timestamp_sec * 1000 * 1000 * 1000, phase)