Merge "Add new modem crash path. Gether QXDM logs for failed cases."
diff --git a/acts/framework/acts/base_test.py b/acts/framework/acts/base_test.py
index f4dec0c..3d424c9 100755
--- a/acts/framework/acts/base_test.py
+++ b/acts/framework/acts/base_test.py
@@ -696,11 +696,13 @@
             try:
                 ad.adb.wait_for_device()
                 ad.take_bug_report(test_name, begin_time)
-                tombstone_path = os.path.join(
-                    ad.log_path, "BugReports", "{},{}".format(
-                        begin_time, ad.serial).replace(' ', '_'))
-                utils.create_dir(tombstone_path)
-                ad.adb.pull('/data/tombstones/', tombstone_path, timeout=1200)
+                bugreport_path = os.path.join(ad.log_path, test_name)
+                utils.create_dir(bugreport_path)
+                ad.check_crash_report(True, test_name)
+                if getattr(ad, "qxdm_always_on", False):
+                    ad.log.info("Pull QXDM Logs")
+                    ad.pull_files(["/data/vendor/radio/diag_logs/logs/"],
+                                  bugreport_path)
             except Exception as e:
                 ad.log.error(
                     "Failed to take a bug report for %s with error %s",
diff --git a/acts/framework/acts/controllers/android_device.py b/acts/framework/acts/controllers/android_device.py
index 527ea04..1ce9433 100755
--- a/acts/framework/acts/controllers/android_device.py
+++ b/acts/framework/acts/controllers/android_device.py
@@ -44,7 +44,8 @@
 ANDROID_DEVICE_ADB_LOGCAT_PARAM_KEY = "adb_logcat_param"
 ANDROID_DEVICE_EMPTY_CONFIG_MSG = "Configuration is empty, abort!"
 ANDROID_DEVICE_NOT_LIST_CONFIG_MSG = "Configuration should be a list, abort!"
-CRASH_REPORT_PATHS = ("/data/tombstones/", "/data/ramdumps/", "/data/ramdump/")
+CRASH_REPORT_PATHS = ("/data/tombstones/", "/data/vendor/ramdump/",
+                      "/data/ramdump/")
 CRASH_REPORT_SKIPS = ("RAMDUMP_RESERVED", "RAMDUMP_STATUS")
 BUG_REPORT_TIMEOUT = 1200
 PULL_TIMEOUT = 300
@@ -853,14 +854,12 @@
                 new_br = False
         except adb.AdbError:
             new_br = False
-        br_path = os.path.join(self.log_path, "BugReports")
+        br_path = os.path.join(self.log_path, test_name)
         utils.create_dir(br_path)
-        base_name = ",{},{}.txt".format(begin_time, self.serial)
-        if new_br:
-            base_name = base_name.replace(".txt", ".zip")
-        test_name_len = utils.MAX_FILENAME_LEN - len(base_name)
-        out_name = test_name[:test_name_len] + base_name
-        full_out_path = os.path.join(br_path, out_name.replace(' ', '_'))
+        out_name = "AndroidDevice%s_%s" % (self.serial, begin_time.replace(
+            " ", "_").replace(":", "-"))
+        out_name = "%s.zip" % out_name if new_br else "%s.txt" % out_name
+        full_out_path = os.path.join(br_path, out_name)
         # in case device restarted, wait for adb interface to return
         self.wait_for_boot_completion()
         self.log.info("Taking bugreport for %s.", test_name)
@@ -894,7 +893,7 @@
             self.adb.pull(
                 "%s %s" % (file_name, remote_path), timeout=PULL_TIMEOUT)
 
-    def check_crash_report(self, log_crash_report=False):
+    def check_crash_report(self, log_crash_report=False, test_name=None):
         """check crash report on the device."""
         crash_reports = []
         for crash_path in CRASH_REPORT_PATHS:
@@ -903,8 +902,10 @@
                     continue
                 crash_reports.append(os.path.join(crash_path, report))
         if log_crash_report:
-            crash_log_path = os.path.join(self.log_path, "CrashReports",
-                                          time.strftime("%m-%d-%Y-%H-%M-%S"))
+            if not test_name:
+                test_name = time.strftime("%m-%d-%Y-%H-%M-%S")
+            crash_log_path = os.path.join(self.log_path, test_name,
+                                          "CrashReports")
             utils.create_dir(crash_log_path)
             self.pull_files(crash_reports, crash_log_path)
         return crash_reports
diff --git a/acts/framework/tests/acts_android_device_test.py b/acts/framework/tests/acts_android_device_test.py
index b79b7f6..d5b7908 100755
--- a/acts/framework/tests/acts_android_device_test.py
+++ b/acts/framework/tests/acts_android_device_test.py
@@ -99,9 +99,9 @@
         return "\t".join([str(self.serial), "device"])
 
     def bugreport(self, params, timeout=android_device.BUG_REPORT_TIMEOUT):
-        expected = os.path.join(logging.log_path,
-                                "AndroidDevice%s" % self.serial, "BugReports",
-                                "test_something,sometime,%s" % (self.serial))
+        expected = os.path.join(
+            logging.log_path, "AndroidDevice%s" % self.serial,
+            "test_something", "AndroidDevice%s_sometime" % self.serial)
         assert expected in params, "Expected '%s', got '%s'." % (expected,
                                                                  params)
 
@@ -276,14 +276,13 @@
         mock_serial = 1
         ad = android_device.AndroidDevice(serial=mock_serial)
         ad.take_bug_report("test_something", "sometime")
-        expected_path = os.path.join(logging.log_path, "AndroidDevice%s" %
-                                     ad.serial, "BugReports")
+        expected_path = os.path.join(
+            logging.log_path, "AndroidDevice%s" % ad.serial, "test_something")
         create_dir_mock.assert_called_with(expected_path)
 
     @mock.patch(
         'acts.controllers.adb.AdbProxy',
-        return_value=MockAdbProxy(
-            1, fail_br=True))
+        return_value=MockAdbProxy(1, fail_br=True))
     @mock.patch(
         'acts.controllers.fastboot.FastbootProxy',
         return_value=MockFastbootProxy(1))
@@ -303,8 +302,7 @@
 
     @mock.patch(
         'acts.controllers.adb.AdbProxy',
-        return_value=MockAdbProxy(
-            1, fail_br_before_N=True))
+        return_value=MockAdbProxy(1, fail_br_before_N=True))
     @mock.patch(
         'acts.controllers.fastboot.FastbootProxy',
         return_value=MockFastbootProxy(1))
@@ -318,8 +316,8 @@
         mock_serial = 1
         ad = android_device.AndroidDevice(serial=mock_serial)
         ad.take_bug_report("test_something", "sometime")
-        expected_path = os.path.join(logging.log_path, "AndroidDevice%s" %
-                                     ad.serial, "BugReports")
+        expected_path = os.path.join(
+            logging.log_path, "AndroidDevice%s" % ad.serial, "test_something")
         create_dir_mock.assert_called_with(expected_path)
 
     @mock.patch('acts.controllers.adb.AdbProxy', return_value=MockAdbProxy(1))
@@ -434,8 +432,9 @@
         with open(mock_adb_log_path, 'w') as f:
             f.write(MOCK_ADB_LOGCAT)
         ad.cat_adb_log("some_test", MOCK_ADB_LOGCAT_BEGIN_TIME)
-        cat_file_path = os.path.join(ad.log_path, "AdbLogExcerpts", (
-            "some_test,02-29 14:02:20.123,%s,%s.txt") % (ad.model, ad.serial))
+        cat_file_path = os.path.join(
+            ad.log_path, "AdbLogExcerpts",
+            ("some_test,02-29 14:02:20.123,%s,%s.txt") % (ad.model, ad.serial))
         with open(cat_file_path, 'r') as f:
             actual_cat = f.read()
         self.assertEqual(actual_cat, ''.join(MOCK_ADB_LOGCAT_CAT_RESULT))