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