merge_lib_test.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env vpython3
  2. # Copyright 2019 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. import os
  6. import subprocess
  7. import sys
  8. import unittest
  9. import mock
  10. import merge_lib as merger
  11. class MergeLibTest(unittest.TestCase):
  12. # pylint: disable=super-with-arguments
  13. def __init__(self, *args, **kwargs):
  14. super(MergeLibTest, self).__init__(*args, **kwargs)
  15. self.maxDiff = None
  16. # pylint: enable=super-with-arguments
  17. @mock.patch.object(subprocess, 'check_output')
  18. def test_validate_and_convert_profraw(self, mock_cmd):
  19. test_cases = [
  20. ([''], [['mock.profdata'], [], []]),
  21. (['Counter overflow'], [[], ['mock.profraw'], ['mock.profraw']]),
  22. (subprocess.CalledProcessError(
  23. 255,
  24. 'llvm-cov merge -o mock.profdata -sparse=true mock.profraw',
  25. output='Malformed profile'), [[], ['mock.profraw'], []]),
  26. ]
  27. for side_effect, expected_results in test_cases:
  28. mock_cmd.side_effect = side_effect
  29. output_profdata_files = []
  30. invalid_profraw_files = []
  31. counter_overflows = []
  32. merger._validate_and_convert_profraw(
  33. 'mock.profraw', output_profdata_files, invalid_profraw_files,
  34. counter_overflows, '/usr/bin/llvm-cov')
  35. self.assertEqual(
  36. expected_results,
  37. [output_profdata_files, invalid_profraw_files, counter_overflows])
  38. if __name__ == '__main__':
  39. unittest.main()