summaryrefslogtreecommitdiff
path: root/hidl_trace_recorder/HidlTraceRecorder.py
blob: 9cba11aea171291a07fc6848c9403570e2cec4ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
#
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import datetime
import logging
import os

from vts.runners.host import asserts
from vts.runners.host import test_runner
from vts.testcases.template.cts_test import cts_test


class HidlTraceRecorder(cts_test.CtsTest):
    """A HIDL HAL API trace recorder.

    This class uses an apk which is packaged as part of VTS. It uses to test the
    VTS TF's instrumentation preparer and post-processing modules. Those two
    Java TF-side modules are cherry-picked to CTS to collect HIDL traces while
    running various CTS test cases without having to package them as part of
    VTS.
    """

    REMOTE_PROFILINT_TRACE_PATH = "/google/data/rw/teams/android-vts/cts-traces"

    def RunTestCase(self, test_case):
        '''Runs a test_case.

        Args:
            test_case: a cts test config.
        '''
        # before running the cts test module enable profiling.
        self.profiling.EnableVTSProfiling(
            self.dut.shell.one, hal_instrumentation_lib_path="")
        self.dut.stop()  # stop framework
        self.dut.start()  # start framework

        profiling_trace_path = os.path.join(
            self.REMOTE_PROFILINT_TRACE_PATH,
            datetime.datetime.now().strftime("%Y%m%d"),
            self.GetTestName(test_case))
        if not os.path.exists(profiling_trace_path):
            os.makedirs(profiling_trace_path)

        logging.info("Run %s", self.GetTestName(test_case))
        self.dut.adb.shell("am instrument -w -r %s/%s" % (test_case["package"],
                                                          test_case["runner"]))

        # after running the cts test module, copy trace files and disable profiling.
        self.profiling.GetTraceFiles(self.dut, profiling_trace_path)
        self.profiling.DisableVTSProfiling(self.dut.shell.one)

if __name__ == "__main__":
    test_runner.main()