1 import unittest 2 3 from autotest_lib.client.common_lib.cros.cfm.metrics import ( 4 media_info_metrics_extractor) 5 6 MEDIA_TYPE = media_info_metrics_extractor.MediaType 7 DIRECTION = media_info_metrics_extractor.Direction 8 9 10 # pylint: disable=missing-docstring 11 class MediaInfoMetricsExtractorTest(unittest.TestCase): 12 13 def setUp(self): 14 self.extractor = media_info_metrics_extractor.MediaInfoMetricsExtractor( 15 TEST_DATA_POINTS) 16 17 def testGlobalMetric(self): 18 metric = self.extractor.get_top_level_metric('processcpuusage') 19 self.assertEqual(metric, [(1, [105]), (2, [95])]) 20 21 def testMediaMetric(self): 22 metric = self.extractor.get_media_metric( 23 'fps', media_type=MEDIA_TYPE.VIDEO, 24 direction=DIRECTION.RECEIVER) 25 self.assertEqual(metric, [(1, [8, 23]), (2, [25, 12])]) 26 27 def testPostProcessReturnsScalar(self): 28 metric = self.extractor.get_media_metric( 29 'fps', 30 media_type=MEDIA_TYPE.VIDEO, 31 direction=DIRECTION.RECEIVER, 32 post_process_func=sum) 33 self.assertEqual(metric, [(1, [31]), (2, [37])]) 34 35 def testPostProcessReturnsList(self): 36 metric = self.extractor.get_media_metric( 37 'fps', 38 media_type=MEDIA_TYPE.VIDEO, 39 direction=DIRECTION.RECEIVER, 40 post_process_func=lambda values: [x + 1 for x in values]) 41 self.assertEqual(metric, [(1, [9, 24]), (2, [26, 13])]) 42 43 def testMetricNameDoesNotExist(self): 44 self.assertRaises( 45 KeyError, 46 lambda: self.extractor.get_top_level_metric('does_not_exist')) 47 48 def testWildcardMediaType(self): 49 metric = self.extractor.get_media_metric( 50 'bytessent', direction=DIRECTION.SENDER) 51 self.assertEqual( 52 metric, [(1.0, [58978, 3826779]), (2.0, [59206, 3986136])]) 53 54 def testNoneValueMediaMetricsSkipped(self): 55 metric = self.extractor.get_media_metric( 56 'fps', 57 media_type=MEDIA_TYPE.VIDEO, 58 direction=DIRECTION.BANDWIDTH_ESTIMATION) 59 self.assertEquals(0, len(metric)) 60 61 def testNoneValueTopLevelMetricsSkipped(self): 62 metric = self.extractor.get_top_level_metric('gpuProcessCpuUsage') 63 self.assertEqual(metric, [(2.0, [0])]) 64 65 66 # Two data points extracted from a real call. Somewhat post processed to make 67 # numbers easier to use in tests. 68 TEST_DATA_POINTS = [{ 69 u'gpuProcessCpuUsage': 70 None, 71 u'processcpuusage': 72 105, 73 u'timestamp': 1, 74 u'systemcpuusage': 75 615, 76 u'media': [{ 77 u'leakybucketdelay': 0, 78 u'availablerecvbitrate': 0, 79 u'ssrc': None, 80 u'availablesendbitrate': 2187820, 81 u'direction': 2, 82 u'height': None, 83 u'fractionlost': -1, 84 u'fpsnetwork': None, 85 u'width': None, 86 u'fps': None, 87 u'mediatype': 2 88 }, { 89 u'bytessent': 58978, 90 u'direction': 0, 91 u'ssrc': 511990786, 92 u'fractionlost': 0, 93 u'transmissionbitrate': 1212, 94 u'packetssent': 946, 95 u'mediatype': 1 96 }, { 97 u'bytessent': 3826779, 98 u'fps': 21, 99 u'ssrc': 4134692703, 100 u'direction': 0, 101 u'height': 720, 102 u'mediatype': 2, 103 u'encodeUsagePercent': 19, 104 u'fpsnetwork': 20, 105 u'transmissionbitrate': 1246604, 106 u'packetssent': 5166, 107 u'fractionlost': 0, 108 u'width': 1280, 109 u'avgEncodeMs': 7 110 }, { 111 u'speechExpandRate': 0, 112 u'fractionlost': 0, 113 u'ssrc': 6666, 114 u'packetsreceived': 1129, 115 u'recvbitrate': 41523, 116 u'direction': 1, 117 u'bytesreceived': 111317, 118 u'mediatype': 1 119 }, { 120 u'speechExpandRate': 0, 121 u'fractionlost': 0, 122 u'ssrc': 6667, 123 u'packetsreceived': 1016, 124 u'recvbitrate': 41866, 125 u'direction': 1, 126 u'bytesreceived': 100225, 127 u'mediatype': 1 128 }, { 129 u'frameSpacingMaxMs': 524, 130 u'fps': 8, 131 u'ssrc': 1491110400, 132 u'direction': 1, 133 u'packetsreceived': 3475, 134 u'recvbitrate': 449595, 135 u'fractionlost': 0, 136 u'height': 720, 137 u'bytesreceived': 3863701, 138 u'fpsnetwork': 8, 139 u'width': 1280, 140 u'mediatype': 2, 141 u'fpsdecoded': 8 142 }, { 143 u'frameSpacingMaxMs': 363, 144 u'fps': 23, 145 u'ssrc': 2738775122, 146 u'direction': 1, 147 u'packetsreceived': 3419, 148 u'recvbitrate': 2228961, 149 u'fractionlost': 0, 150 u'height': 180, 151 u'bytesreceived': 3829959, 152 u'fpsnetwork': 22, 153 u'width': 320, 154 u'mediatype': 2, 155 u'fpsdecoded': 23 156 }], 157 u'browserProcessCpuUsage': 158 46 159 }, { 160 u'gpuProcessCpuUsage': 161 0, 162 u'processcpuusage': 163 95, 164 u'timestamp': 2, 165 u'systemcpuusage': 166 580, 167 u'media': [{ 168 u'leakybucketdelay': 0, 169 u'availablerecvbitrate': 0, 170 u'ssrc': None, 171 u'availablesendbitrate': 2187820, 172 u'direction': 2, 173 u'height': None, 174 u'fractionlost': -1, 175 u'fpsnetwork': None, 176 u'width': None, 177 u'fps': None, 178 u'mediatype': 2 179 }, { 180 u'bytessent': 59206, 181 u'direction': 0, 182 u'ssrc': 511990786, 183 u'fractionlost': 0, 184 u'transmissionbitrate': 1820, 185 u'packetssent': 952, 186 u'mediatype': 1 187 }, { 188 u'bytessent': 3986136, 189 u'fps': 21, 190 u'ssrc': 4134692703, 191 u'direction': 0, 192 u'height': 720, 193 u'mediatype': 2, 194 u'encodeUsagePercent': 19, 195 u'fpsnetwork': 20, 196 u'transmissionbitrate': 1272311, 197 u'packetssent': 5325, 198 u'fractionlost': 0, 199 u'width': 1280, 200 u'avgEncodeMs': 8 201 }, { 202 u'speechExpandRate': 0, 203 u'fractionlost': 0, 204 u'ssrc': 6666, 205 u'packetsreceived': 1147, 206 u'recvbitrate': 8527, 207 u'direction': 1, 208 u'bytesreceived': 112385, 209 u'mediatype': 1 210 }, { 211 u'speechExpandRate': 0, 212 u'fractionlost': 0, 213 u'ssrc': 6667, 214 u'packetsreceived': 1062, 215 u'recvbitrate': 35321, 216 u'direction': 1, 217 u'bytesreceived': 104649, 218 u'mediatype': 1 219 }, { 220 u'frameSpacingMaxMs': 330, 221 u'fps': 25, 222 u'ssrc': 1491110400, 223 u'direction': 1, 224 u'packetsreceived': 3694, 225 u'recvbitrate': 1963721, 226 u'fractionlost': 0, 227 u'height': 720, 228 u'bytesreceived': 4109657, 229 u'fpsnetwork': 26, 230 u'width': 1280, 231 u'mediatype': 2, 232 u'fpsdecoded': 25 233 }, { 234 u'frameSpacingMaxMs': 363, 235 u'fps': 12, 236 u'ssrc': 2738775122, 237 u'direction': 1, 238 u'packetsreceived': 3440, 239 u'recvbitrate': 147018, 240 u'fractionlost': 0, 241 u'height': 180, 242 u'bytesreceived': 3848373, 243 u'fpsnetwork': 13, 244 u'width': 320, 245 u'mediatype': 2, 246 u'fpsdecoded': 12 247 }], 248 u'browserProcessCpuUsage': 249 38 250 }] 251 252 253