1#!/usr/bin/env python3.4
2#
3#   Copyright 2017 - Google
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16"""
17    Test Script for Telephony Post Flight check.
18"""
19import os
20from acts.asserts import fail
21from acts.base_test import BaseTestClass
22from acts.test_decorators import test_tracker_info
23from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
24
25
26class TelLivePostflightTest(TelephonyBaseTest):
27    def setup_class(self):
28        super().setup_class()
29
30        self.user_params["telephony_auto_rerun"] = 0
31
32    def teardown_class(self):
33        pass
34
35    def setup_test(self):
36        pass
37
38    def on_pass(self, *arg):
39        pass
40
41    def on_fail(self, *arg):
42        pass
43
44    @test_tracker_info(uuid="ba6e260e-d2e1-4c01-9d51-ef2df1591039")
45    @TelephonyBaseTest.tel_test_wrap
46    def test_check_crash(self):
47        msg = ""
48        for ad in self.android_devices:
49            post_crash = ad.check_crash_report(self.test_id)
50            pre_crash = getattr(ad, "crash_report_preflight", [])
51            crash_diff = list(set(post_crash).difference(set(pre_crash)))
52            if crash_diff:
53                msg += "%s find new crash reports %s " % (ad.serial,
54                                                          crash_diff)
55                ad.log.error("Find new crash reports %s", crash_diff)
56                crash_path = os.path.join(ad.log_path, self.test_name,
57                                          "Crashes")
58                os.makedirs(crash_path, exist_ok=True)
59                ad.pull_files(crash_diff, crash_path)
60                self._ad_take_bugreport(ad, self.test_name, self.begin_time)
61        if msg:
62            fail(msg)
63        return True
64
65    @test_tracker_info(uuid="a94a0145-27be-4610-90f7-3af561d1b1ec")
66    @TelephonyBaseTest.tel_test_wrap
67    def test_check_dialer_crash(self):
68        msg = ""
69        for ad in self.android_devices:
70            tombstones = ad.get_file_names("/data/tombstones/")
71            if not tombstones: continue
72            for tombstone in tombstones:
73                if ad.adb.shell("cat %s | grep pid | grep dialer" % tombstone):
74                    message = "%s dialer crash: %s " % (ad.serial, tombstone)
75                    ad.log.error(message)
76                    msg += message
77                    crash_path = os.path.join(ad.log_path, self.test_name,
78                                              "Crashes")
79                    os.makedirs(crash_path, exist_ok=True)
80                    ad.pull_files([tombstone], crash_path)
81        if msg:
82            fail(msg)
83        return True
84
85    @test_tracker_info(uuid="707d4a33-2e21-40ea-bd27-d15f4e3ff0f0")
86    @TelephonyBaseTest.tel_test_wrap
87    def test_check_data_accounting_failures(self):
88        msg = ""
89        for ad in self.android_devices:
90            ad.log.info("data_accounting_errors: %s", dict(ad.data_accounting))
91            if any(ad.data_accounting.values()):
92                msg += "%s %s" % (ad.serial, dict(ad.data_accounting))
93        if msg:
94            fail(msg)
95        return True
96