def test_merge_script_api_parameters(self):
     """Test the step-level merge front-end."""
     build_properties = json.dumps({
         'some': {
             'complicated': ['nested', {
                 'json': None,
                 'object': 'thing',
             }]
         }
     })
     task_output_dir = 'some/task/output/dir'
     profdata_dir = '/some/different/path/to/profdata/default.profdata'
     profdata_file = os.path.join(profdata_dir, 'default.profdata')
     args = [
         'script_name', '--output-json', 'output.json',
         '--build-properties', build_properties, '--summary-json',
         'summary.json', '--task-output-dir', task_output_dir,
         '--profdata-dir', profdata_dir, '--llvm-profdata', 'llvm-profdata',
         'a.json', 'b.json', 'c.json'
     ]
     with mock.patch.object(merger, 'merge_profiles') as mock_merge:
         mock_merge.return_value = None
         with mock.patch.object(sys, 'argv', args):
             merge_results.main()
             self.assertEqual(
                 mock_merge.call_args,
                 mock.call(task_output_dir, profdata_file, '.profraw',
                           'llvm-profdata'))
Beispiel #2
0
    def test_argparse_sparse(self):
        """Ensure that sparse flag defaults to true, and is set to correct value"""
        # Basic required args
        build_properties = json.dumps({
            'some': {
                'complicated': ['nested', {
                    'json': None,
                    'object': 'thing',
                }]
            }
        })
        task_output_dir = 'some/task/output/dir'
        profdata_dir = '/some/different/path/to/profdata/default.profdata'
        profdata_file = os.path.join(profdata_dir, 'base_unittests.profdata')
        args = [
            'script_name', '--output-json', 'output.json',
            '--build-properties', build_properties, '--summary-json',
            'summary.json', '--task-output-dir', task_output_dir,
            '--profdata-dir', profdata_dir, '--llvm-profdata', 'llvm-profdata',
            'a.json', 'b.json', 'c.json', '--test-target-name',
            'base_unittests'
        ]

        test_scenarios = [
            {
                # Base set of args should set --sparse to false by default
                'args': None,
                'expected_outcome': False,
            },
            {
                # Sparse should parse True when only --sparse is specified
                'args': ['--sparse'],
                'expected_outcome': True,
            }
        ]

        for scenario in test_scenarios:
            args = copy.deepcopy(args)
            additional_args = scenario['args']
            if additional_args:
                args.extend(additional_args)
            expected_outcome = scenario['expected_outcome']

            with mock.patch.object(merger, 'merge_profiles') as mock_merge:
                mock_merge.return_value = None, None
                with mock.patch.object(sys, 'argv', args):
                    merge_results.main()
                    self.assertEqual(
                        mock_merge.call_args,
                        mock.call(task_output_dir,
                                  profdata_file,
                                  '.profraw',
                                  'llvm-profdata',
                                  sparse=expected_outcome,
                                  skip_validation=False), None)