| OLD | NEW |
| 1 # Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 import os | 6 import os |
| 7 import unittest | 7 import unittest |
| 8 | 8 |
| 9 from infra.services.sysmon import android_device_metrics | 9 from infra.services.sysmon import android_device_metrics |
| 10 from infra_libs import ts_mon | 10 from infra_libs import ts_mon |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 self.invalid_json_file = os.path.join( | 21 self.invalid_json_file = os.path.join( |
| 22 DATA_DIR, 'invalid_files', 'invalid_json_android_device_status.json') | 22 DATA_DIR, 'invalid_files', 'invalid_json_android_device_status.json') |
| 23 self.not_dict_file = os.path.join( | 23 self.not_dict_file = os.path.join( |
| 24 DATA_DIR, 'invalid_files', 'not_dict_android_device_status.json') | 24 DATA_DIR, 'invalid_files', 'not_dict_android_device_status.json') |
| 25 self.invalid_version_file = os.path.join( | 25 self.invalid_version_file = os.path.join( |
| 26 DATA_DIR, 'invalid_files', 'invalid_version_android_device_status.json') | 26 DATA_DIR, 'invalid_files', 'invalid_version_android_device_status.json') |
| 27 self.valid_file = os.path.join( | 27 self.valid_file = os.path.join( |
| 28 DATA_DIR, 'valid_files', 'android_device_status.json') | 28 DATA_DIR, 'valid_files', 'android_device_status.json') |
| 29 self.no_temp_file = os.path.join( | 29 self.no_temp_file = os.path.join( |
| 30 DATA_DIR, 'valid_files', 'no_temp_android_device_status.json') | 30 DATA_DIR, 'valid_files', 'no_temp_android_device_status.json') |
| 31 self.port_path_file = os.path.join( |
| 32 DATA_DIR, 'valid_files', 'some_port_paths.json') |
| 31 | 33 |
| 32 # A test device in the representative json file. | 34 # A test device in the representative json file. |
| 33 self.device_id = '06c38708006afff3' | 35 self.device_id = '06c38708006afff3' |
| 34 | 36 |
| 35 def _assert_read_status(self, should_equal='good'): | 37 def _assert_read_status(self, should_equal='good'): |
| 36 read_status = android_device_metrics.metric_read_status.get() | 38 read_status = android_device_metrics.metric_read_status.get() |
| 37 self.assertEqual(read_status, should_equal) | 39 self.assertEqual(read_status, should_equal) |
| 38 | 40 |
| 39 def _assert_all_none(self, device_id): | 41 def _assert_all_none(self, device_id): |
| 40 fields = {'device_id': device_id} | 42 fields = {'device_id': device_id} |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 def test_no_metric_sent(self): | 105 def test_no_metric_sent(self): |
| 104 with open(self.no_temp_file) as f: | 106 with open(self.no_temp_file) as f: |
| 105 file_time = float(json.load(f)['timestamp']) | 107 file_time = float(json.load(f)['timestamp']) |
| 106 | 108 |
| 107 android_device_metrics.get_device_statuses( | 109 android_device_metrics.get_device_statuses( |
| 108 self.no_temp_file, now=file_time) | 110 self.no_temp_file, now=file_time) |
| 109 self._assert_read_status(should_equal='good') | 111 self._assert_read_status(should_equal='good') |
| 110 | 112 |
| 111 fields = {'device_id': self.device_id} | 113 fields = {'device_id': self.device_id} |
| 112 self.assertIsNone(android_device_metrics.cpu_temp.get(fields=fields)) | 114 self.assertIsNone(android_device_metrics.cpu_temp.get(fields=fields)) |
| 115 |
| 116 def test_port_paths(self): |
| 117 with open(self.port_path_file) as f: |
| 118 file_time = float(json.load(f)['timestamp']) |
| 119 |
| 120 android_device_metrics.get_device_statuses( |
| 121 self.port_path_file, now=file_time) |
| 122 self._assert_read_status(should_equal='good') |
| 123 |
| 124 fields = {'device_id': self.device_id} |
| 125 self.assertEqual( |
| 126 android_device_metrics.batt_charge.get(fields=fields), 100.0) |
| 127 self.assertEqual(android_device_metrics.batt_temp.get(fields=fields), 26.8) |
| 128 self.assertEqual(android_device_metrics.cpu_temp.get(fields=fields), 26) |
| 129 self.assertEqual(android_device_metrics.dev_os.get(fields=fields), 'KTU84P') |
| 130 self.assertEqual( |
| 131 android_device_metrics.dev_status.get(fields=fields), 'good') |
| 132 self.assertEqual(android_device_metrics.dev_type.get(fields=fields), |
| 133 'hammerhead') |
| 134 self.assertEqual( |
| 135 android_device_metrics.dev_uptime.get(fields=fields), 2162.74) |
| 136 |
| 137 fields = {'device_id': '1/23'} |
| 138 self.assertEqual( |
| 139 android_device_metrics.dev_status.get(fields=fields), None) |
| 140 |
| 141 fields = {'device_id': '09/8765'} |
| 142 self.assertEqual( |
| 143 android_device_metrics.dev_status.get(fields=fields), None) |
| OLD | NEW |