• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#   Copyright (c) 2021 Huawei Device Co., Ltd.
4#   Licensed under the Apache License, Version 2.0 (the "License");
5#   you may not use this file except in compliance with the License.
6#   You may obtain a copy of the License at
7#
8#       http://www.apache.org/licenses/LICENSE-2.0
9#
10#   Unless required by applicable law or agreed to in writing, software
11#   distributed under the License is distributed on an "AS IS" BASIS,
12#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13#   See the License for the specific language governing permissions and
14#   limitations under the License.
15
16import os
17import unittest
18import argparse
19from command_script import HostElfEntry
20from command_script import parser_add_argument
21from command_script import check_args
22from command_script import main
23
24
25def fake_parser():
26    parser = argparse.ArgumentParser()
27    parser.add_argument('-p', '--pid')
28    parser.add_argument('-app', '--package_name')
29    parser.add_argument('-l', '--local_program')
30    parser.add_argument('-c', '--cmd')
31    parser.add_argument('-t', '--tid')
32    parser.add_argument('-sw', '--system_wide', action='store_true')
33    parser.add_argument('-a', '--activity')
34    parser.add_argument('-n', '--not_hdc_root')
35    parser.add_argument('-lib', '--local_lib_dir')
36    parser.add_argument('-r', '--record_options', default='-d 1')
37    parser.add_argument('-o', '--output_perf_data', default='perf.data')
38    return parser
39
40
41class TestCommandScript(unittest.TestCase):
42
43    def setUp(self):
44        print("set up")
45
46    def tearDown(self):
47        print("tear down")
48
49    def test_host_elf_entry(self):
50        result = HostElfEntry('test_path', 'test_lib_name').__str__()
51        self.assertEqual(result, '[path: test_path, name test_lib_name,'
52                                 ' score test_lib_score]')
53
54    def test_parser_add_argument(self):
55        self.parser = fake_parser()
56        args = self.parser.parse_args(['-p', '14'])
57        result = args.pid
58        self.assertEqual(result, '14')
59
60    def test_check_args(self):
61        self.args = parser_add_argument()
62        result = check_args(self.args)
63        self.assertEqual(result, True)
64
65    def test_main(self):
66        self.parser = fake_parser()
67        args = self.parser.parse_args(['-sw'])
68        main(args)
69        if os.path.exists('perf.data'):
70            result = True
71        else:
72            result = False
73        self.assertEqual(result, True)
74
75