George Burgess IV | ed69676 | 2016-09-12 18:24:54 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 2 | |
| 3 | # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
Yunlian Jiang | fbda049 | 2015-12-21 15:32:44 -0800 | [diff] [blame] | 7 | """Module of result cache unittest.""" |
| 8 | |
| 9 | from __future__ import print_function |
| 10 | |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 11 | import mock |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 12 | import os |
| 13 | import tempfile |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 14 | import unittest |
| 15 | |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 16 | import image_checksummer |
| 17 | import machine_manager |
Caroline Tice | e627fd6 | 2015-12-11 12:07:59 -0800 | [diff] [blame] | 18 | import test_flag |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 19 | |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 20 | from label import MockLabel |
| 21 | from results_cache import CacheConditions |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 22 | from results_cache import Result |
| 23 | from results_cache import ResultsCache |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 24 | from results_cache import TelemetryResult |
Yunlian Jiang | 0d1a9f3 | 2015-12-09 10:47:11 -0800 | [diff] [blame] | 25 | from cros_utils import command_executer |
| 26 | from cros_utils import logger |
| 27 | from cros_utils import misc |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 28 | |
Yunlian Jiang | 4ef1352 | 2015-12-29 13:20:45 -0800 | [diff] [blame] | 29 | OUTPUT = """CMD (True): ./test_that.sh\ |
| 30 | --remote=172.17.128.241 --board=lumpy LibCBench |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 31 | CMD (None): cd /usr/local/google/home/yunlian/gd/src/build/images/lumpy/latest/../../../../..; cros_sdk -- ./in_chroot_cmd6X7Cxu.sh |
cmtice | d96e457 | 2015-05-19 16:19:25 -0700 | [diff] [blame] | 32 | Identity added: /tmp/test_that.PO1234567/autotest_key (/tmp/test_that.PO1234567/autotest_key) |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 33 | INFO : Using emerged autotests already installed at /build/lumpy/usr/local/autotest. |
| 34 | |
| 35 | INFO : Running the following control files 1 times: |
| 36 | INFO : * 'client/site_tests/platform_LibCBench/control' |
| 37 | |
| 38 | INFO : Running client test client/site_tests/platform_LibCBench/control |
cmtice | d96e457 | 2015-05-19 16:19:25 -0700 | [diff] [blame] | 39 | ./server/autoserv -m 172.17.128.241 --ssh-port 22 -c client/site_tests/platform_LibCBench/control -r /tmp/test_that.PO1234567/platform_LibCBench --test-retry=0 --args |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 40 | ERROR:root:import statsd failed, no stats will be reported. |
cmtice | d96e457 | 2015-05-19 16:19:25 -0700 | [diff] [blame] | 41 | 14:20:22 INFO | Results placed in /tmp/test_that.PO1234567/platform_LibCBench |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 42 | 14:20:22 INFO | Processing control file |
| 43 | 14:20:23 INFO | Starting master ssh connection '/usr/bin/ssh -a -x -N -o ControlMaster=yes -o ControlPath=/tmp/_autotmp_VIIP67ssh-master/socket -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o ConnectTimeout=30 -o ServerAliveInterval=180 -o ServerAliveCountMax=3 -o ConnectionAttempts=4 -o Protocol=2 -l root -p 22 172.17.128.241' |
| 44 | 14:20:23 ERROR| [stderr] Warning: Permanently added '172.17.128.241' (RSA) to the list of known hosts. |
| 45 | 14:20:23 INFO | INFO ---- ---- kernel=3.8.11 localtime=May 22 14:20:23 timestamp=1369257623 |
| 46 | 14:20:23 INFO | Installing autotest on 172.17.128.241 |
| 47 | 14:20:23 INFO | Using installation dir /usr/local/autotest |
| 48 | 14:20:23 WARNI| No job_repo_url for <remote host: 172.17.128.241> |
| 49 | 14:20:23 INFO | Could not install autotest using the packaging system: No repos to install an autotest client from. Trying other methods |
| 50 | 14:20:23 INFO | Installation of autotest completed |
| 51 | 14:20:24 WARNI| No job_repo_url for <remote host: 172.17.128.241> |
| 52 | 14:20:24 INFO | Executing /usr/local/autotest/bin/autotest /usr/local/autotest/control phase 0 |
| 53 | 14:20:24 INFO | Entered autotestd_monitor. |
| 54 | 14:20:24 INFO | Finished launching tail subprocesses. |
| 55 | 14:20:24 INFO | Finished waiting on autotestd to start. |
| 56 | 14:20:26 INFO | START ---- ---- timestamp=1369257625 localtime=May 22 14:20:25 |
| 57 | 14:20:26 INFO | START platform_LibCBench platform_LibCBench timestamp=1369257625 localtime=May 22 14:20:25 |
| 58 | 14:20:30 INFO | GOOD platform_LibCBench platform_LibCBench timestamp=1369257630 localtime=May 22 14:20:30 completed successfully |
| 59 | 14:20:30 INFO | END GOOD platform_LibCBench platform_LibCBench timestamp=1369257630 localtime=May 22 14:20:30 |
| 60 | 14:20:31 INFO | END GOOD ---- ---- timestamp=1369257630 localtime=May 22 14:20:30 |
| 61 | 14:20:31 INFO | Got lock of exit_code_file. |
| 62 | 14:20:31 INFO | Released lock of exit_code_file and closed it. |
| 63 | OUTPUT: ============================== |
| 64 | OUTPUT: Current time: 2013-05-22 14:20:32.818831 Elapsed: 0:01:30 ETA: Unknown |
| 65 | Done: 0% [ ] |
| 66 | OUTPUT: Thread Status: |
| 67 | RUNNING: 1 ('ttt: LibCBench (1)' 0:01:21) |
| 68 | Machine Status: |
| 69 | Machine Thread Lock Status Checksum |
| 70 | 172.17.128.241 ttt: LibCBench (1) True RUNNING 3ba9f2ecbb222f20887daea5583d86ba |
| 71 | |
| 72 | OUTPUT: ============================== |
| 73 | 14:20:33 INFO | Killing child processes. |
| 74 | 14:20:33 INFO | Client complete |
| 75 | 14:20:33 INFO | Finished processing control file |
| 76 | 14:20:33 INFO | Starting master ssh connection '/usr/bin/ssh -a -x -N -o ControlMaster=yes -o ControlPath=/tmp/_autotmp_aVJUgmssh-master/socket -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o ConnectTimeout=30 -o ServerAliveInterval=180 -o ServerAliveCountMax=3 -o ConnectionAttempts=4 -o Protocol=2 -l root -p 22 172.17.128.241' |
| 77 | 14:20:33 ERROR| [stderr] Warning: Permanently added '172.17.128.241' (RSA) to the list of known hosts. |
| 78 | |
| 79 | INFO : Test results: |
| 80 | ------------------------------------------------------------------- |
| 81 | platform_LibCBench [ PASSED ] |
| 82 | platform_LibCBench/platform_LibCBench [ PASSED ] |
| 83 | platform_LibCBench/platform_LibCBench b_malloc_big1__0_ 0.00375231466667 |
| 84 | platform_LibCBench/platform_LibCBench b_malloc_big2__0_ 0.002951359 |
| 85 | platform_LibCBench/platform_LibCBench b_malloc_bubble__0_ 0.015066374 |
| 86 | platform_LibCBench/platform_LibCBench b_malloc_sparse__0_ 0.015053784 |
| 87 | platform_LibCBench/platform_LibCBench b_malloc_thread_local__0_ 0.01138439 |
| 88 | platform_LibCBench/platform_LibCBench b_malloc_thread_stress__0_ 0.0367894733333 |
| 89 | platform_LibCBench/platform_LibCBench b_malloc_tiny1__0_ 0.000768474333333 |
| 90 | platform_LibCBench/platform_LibCBench b_malloc_tiny2__0_ 0.000581407333333 |
| 91 | platform_LibCBench/platform_LibCBench b_pthread_create_serial1__0_ 0.0291785246667 |
| 92 | platform_LibCBench/platform_LibCBench b_pthread_createjoin_serial1__0_ 0.031907936 |
| 93 | platform_LibCBench/platform_LibCBench b_pthread_createjoin_serial2__0_ 0.043485347 |
| 94 | platform_LibCBench/platform_LibCBench b_pthread_uselesslock__0_ 0.0294113346667 |
| 95 | platform_LibCBench/platform_LibCBench b_regex_compile____a_b_c__d_b__ 0.00529833933333 |
| 96 | platform_LibCBench/platform_LibCBench b_regex_search____a_b_c__d_b__ 0.00165455066667 |
| 97 | platform_LibCBench/platform_LibCBench b_regex_search___a_25_b__ 0.0496191923333 |
| 98 | platform_LibCBench/platform_LibCBench b_stdio_putcgetc__0_ 0.100005711667 |
| 99 | platform_LibCBench/platform_LibCBench b_stdio_putcgetc_unlocked__0_ 0.0371443833333 |
| 100 | platform_LibCBench/platform_LibCBench b_string_memset__0_ 0.00275405066667 |
| 101 | platform_LibCBench/platform_LibCBench b_string_strchr__0_ 0.00456903 |
| 102 | platform_LibCBench/platform_LibCBench b_string_strlen__0_ 0.044893587 |
| 103 | platform_LibCBench/platform_LibCBench b_string_strstr___aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac__ 0.118360778 |
| 104 | platform_LibCBench/platform_LibCBench b_string_strstr___aaaaaaaaaaaaaaaaaaaaaaaaac__ 0.068957325 |
| 105 | platform_LibCBench/platform_LibCBench b_string_strstr___aaaaaaaaaaaaaacccccccccccc__ 0.0135694476667 |
| 106 | platform_LibCBench/platform_LibCBench b_string_strstr___abcdefghijklmnopqrstuvwxyz__ 0.0134553343333 |
| 107 | platform_LibCBench/platform_LibCBench b_string_strstr___azbycxdwevfugthsirjqkplomn__ 0.0133123556667 |
| 108 | platform_LibCBench/platform_LibCBench b_utf8_bigbuf__0_ 0.0473772253333 |
| 109 | platform_LibCBench/platform_LibCBench b_utf8_onebyone__0_ 0.130938538333 |
| 110 | ------------------------------------------------------------------- |
| 111 | Total PASS: 2/2 (100%) |
| 112 | |
| 113 | INFO : Elapsed time: 0m16s |
| 114 | """ |
| 115 | |
| 116 | error = """ |
cmtice | d96e457 | 2015-05-19 16:19:25 -0700 | [diff] [blame] | 117 | ERROR: Identity added: /tmp/test_that.Z4Ld/autotest_key (/tmp/test_that.Z4Ld/autotest_key) |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 118 | INFO : Using emerged autotests already installed at /build/lumpy/usr/local/autotest. |
| 119 | INFO : Running the following control files 1 times: |
| 120 | INFO : * 'client/site_tests/platform_LibCBench/control' |
| 121 | INFO : Running client test client/site_tests/platform_LibCBench/control |
| 122 | INFO : Test results: |
| 123 | INFO : Elapsed time: 0m18s |
| 124 | """ |
| 125 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 126 | keyvals = {'': 'PASS', |
| 127 | 'b_stdio_putcgetc__0_': '0.100005711667', |
| 128 | 'b_string_strstr___azbycxdwevfugthsirjqkplomn__': '0.0133123556667', |
| 129 | 'b_malloc_thread_local__0_': '0.01138439', |
| 130 | 'b_string_strlen__0_': '0.044893587', |
| 131 | 'b_malloc_sparse__0_': '0.015053784', |
| 132 | 'b_string_memset__0_': '0.00275405066667', |
| 133 | 'platform_LibCBench': 'PASS', |
| 134 | 'b_pthread_uselesslock__0_': '0.0294113346667', |
| 135 | 'b_string_strchr__0_': '0.00456903', |
| 136 | 'b_pthread_create_serial1__0_': '0.0291785246667', |
| 137 | 'b_string_strstr___aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac__': |
| 138 | '0.118360778', |
| 139 | 'b_string_strstr___aaaaaaaaaaaaaacccccccccccc__': '0.0135694476667', |
| 140 | 'b_pthread_createjoin_serial1__0_': '0.031907936', |
| 141 | 'b_malloc_thread_stress__0_': '0.0367894733333', |
| 142 | 'b_regex_search____a_b_c__d_b__': '0.00165455066667', |
| 143 | 'b_malloc_bubble__0_': '0.015066374', |
| 144 | 'b_malloc_big2__0_': '0.002951359', |
| 145 | 'b_stdio_putcgetc_unlocked__0_': '0.0371443833333', |
| 146 | 'b_pthread_createjoin_serial2__0_': '0.043485347', |
| 147 | 'b_regex_search___a_25_b__': '0.0496191923333', |
| 148 | 'b_utf8_bigbuf__0_': '0.0473772253333', |
| 149 | 'b_malloc_big1__0_': '0.00375231466667', |
| 150 | 'b_regex_compile____a_b_c__d_b__': '0.00529833933333', |
| 151 | 'b_string_strstr___aaaaaaaaaaaaaaaaaaaaaaaaac__': '0.068957325', |
| 152 | 'b_malloc_tiny2__0_': '0.000581407333333', |
| 153 | 'b_utf8_onebyone__0_': '0.130938538333', |
| 154 | 'b_malloc_tiny1__0_': '0.000768474333333', |
| 155 | 'b_string_strstr___abcdefghijklmnopqrstuvwxyz__': '0.0134553343333'} |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 156 | |
| 157 | TMP_DIR1 = '/tmp/tmpAbcXyz' |
| 158 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 159 | |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 160 | class MockResult(Result): |
Yunlian Jiang | aefb76c | 2015-12-29 08:59:52 -0800 | [diff] [blame] | 161 | """Mock result class.""" |
Yunlian Jiang | fbda049 | 2015-12-21 15:32:44 -0800 | [diff] [blame] | 162 | def __init__(self, mylogger, label, logging_level, machine): |
| 163 | super(MockResult, self).__init__(mylogger, label, logging_level, machine) |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 164 | |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 165 | def FindFilesInResultsDir(self, find_args): |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 166 | return '' |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 167 | |
Caroline Tice | eddb063 | 2016-04-14 09:19:02 -0700 | [diff] [blame] | 168 | # pylint: disable=arguments-differ |
| 169 | def GetKeyvals(self, temp=False): |
| 170 | if temp: |
Yunlian Jiang | aefb76c | 2015-12-29 08:59:52 -0800 | [diff] [blame] | 171 | pass |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 172 | return keyvals |
| 173 | |
| 174 | |
| 175 | class ResultTest(unittest.TestCase): |
Yunlian Jiang | aefb76c | 2015-12-29 08:59:52 -0800 | [diff] [blame] | 176 | """Result test class.""" |
Yunlian Jiang | 4ef1352 | 2015-12-29 13:20:45 -0800 | [diff] [blame] | 177 | |
| 178 | def __init__(self, *args, **kwargs): |
| 179 | super(ResultTest, self).__init__(*args, **kwargs) |
| 180 | self.callFakeProcessResults = False |
| 181 | self.fakeCacheReturnResult = None |
| 182 | self.callGetResultsDir = False |
| 183 | self.callProcessResults = False |
| 184 | self.callGetPerfReportFiles = False |
| 185 | self.kv_dict = None |
| 186 | self.tmpdir = '' |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 187 | self.callGetNewKeyvals = False |
Rahul Chaudhry | b45d1fa | 2016-07-29 14:24:07 -0700 | [diff] [blame] | 188 | self.callGetResultsFile = False |
Yunlian Jiang | 4ef1352 | 2015-12-29 13:20:45 -0800 | [diff] [blame] | 189 | self.callGetPerfDataFiles = False |
| 190 | self.args = None |
| 191 | self.callGatherPerfResults = False |
| 192 | self.mock_logger = mock.Mock(spec=logger.Logger) |
| 193 | self.mock_cmd_exec = mock.Mock(spec=command_executer.CommandExecuter) |
| 194 | self.mock_label = MockLabel('mock_label', 'chromeos_image', '/tmp', 'lumpy', |
| 195 | 'remote', 'image_args', 'cache_dir', 'average', |
| 196 | 'gcc', None) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 197 | |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 198 | def testCreateFromRun(self): |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 199 | result = MockResult.CreateFromRun(logger.GetLogger(), 'average', |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 200 | self.mock_label, 'remote1', OUTPUT, error, |
| 201 | 0, True, 0) |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 202 | self.assertEqual(result.keyvals, keyvals) |
Yunlian Jiang | 9e53333 | 2013-09-30 15:45:46 -0700 | [diff] [blame] | 203 | self.assertEqual(result.chroot_results_dir, |
cmtice | d96e457 | 2015-05-19 16:19:25 -0700 | [diff] [blame] | 204 | '/tmp/test_that.PO1234567/platform_LibCBench') |
Yunlian Jiang | 9e53333 | 2013-09-30 15:45:46 -0700 | [diff] [blame] | 205 | self.assertEqual(result.results_dir, |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 206 | '/tmp/chroot/tmp/test_that.PO1234567/platform_LibCBench') |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 207 | self.assertEqual(result.retval, 0) |
| 208 | |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 209 | def setUp(self): |
| 210 | self.result = Result(self.mock_logger, self.mock_label, 'average', |
| 211 | self.mock_cmd_exec) |
| 212 | |
| 213 | @mock.patch.object(os.path, 'isdir') |
| 214 | @mock.patch.object(command_executer.CommandExecuter, 'RunCommand') |
| 215 | @mock.patch.object(command_executer.CommandExecuter, 'CopyFiles') |
| 216 | def test_copy_files_to(self, mock_copyfiles, mock_runcmd, mock_isdir): |
| 217 | |
| 218 | files = ['src_file_1', 'src_file_2', 'src_file_3'] |
| 219 | dest_dir = '/tmp/test' |
| 220 | self.mock_cmd_exec.RunCommand = mock_runcmd |
| 221 | self.mock_cmd_exec.CopyFiles = mock_copyfiles |
| 222 | |
| 223 | mock_copyfiles.return_value = 0 |
| 224 | |
| 225 | #test 1. dest_dir exists; CopyFiles returns 0. |
| 226 | mock_isdir.return_value = True |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 227 | self.result.CopyFilesTo(dest_dir, files) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 228 | self.assertEqual(mock_runcmd.call_count, 0) |
| 229 | self.assertEqual(mock_copyfiles.call_count, 3) |
| 230 | first_args = mock_copyfiles.call_args_list[0][0] |
| 231 | second_args = mock_copyfiles.call_args_list[1][0] |
| 232 | third_args = mock_copyfiles.call_args_list[2][0] |
| 233 | self.assertEqual(first_args, ('src_file_1', '/tmp/test/src_file_1.0')) |
| 234 | self.assertEqual(second_args, ('src_file_2', '/tmp/test/src_file_2.0')) |
| 235 | self.assertEqual(third_args, ('src_file_3', '/tmp/test/src_file_3.0')) |
| 236 | |
| 237 | mock_runcmd.reset_mock() |
| 238 | mock_copyfiles.reset_mock() |
| 239 | #test 2. dest_dir does not exist; CopyFiles returns 0. |
| 240 | mock_isdir.return_value = False |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 241 | self.result.CopyFilesTo(dest_dir, files) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 242 | self.assertEqual(mock_runcmd.call_count, 3) |
| 243 | self.assertEqual(mock_copyfiles.call_count, 3) |
| 244 | self.assertEqual(mock_runcmd.call_args_list[0], |
| 245 | mock_runcmd.call_args_list[1]) |
| 246 | self.assertEqual(mock_runcmd.call_args_list[0], |
| 247 | mock_runcmd.call_args_list[2]) |
| 248 | self.assertEqual(mock_runcmd.call_args_list[0][0], ('mkdir -p /tmp/test',)) |
| 249 | |
| 250 | #test 3. CopyFiles returns 1 (fails). |
| 251 | mock_copyfiles.return_value = 1 |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 252 | self.assertRaises(Exception, self.result.CopyFilesTo, dest_dir, files) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 253 | |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 254 | @mock.patch.object(Result, 'CopyFilesTo') |
| 255 | def test_copy_results_to(self, mockCopyFilesTo): |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 256 | perf_data_files = ['/tmp/perf.data.0', '/tmp/perf.data.1', |
| 257 | '/tmp/perf.data.2'] |
| 258 | perf_report_files = ['/tmp/perf.report.0', '/tmp/perf.report.1', |
| 259 | '/tmp/perf.report.2'] |
| 260 | |
| 261 | self.result.perf_data_files = perf_data_files |
| 262 | self.result.perf_report_files = perf_report_files |
| 263 | |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 264 | self.result.CopyFilesTo = mockCopyFilesTo |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 265 | self.result.CopyResultsTo('/tmp/results/') |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 266 | self.assertEqual(mockCopyFilesTo.call_count, 2) |
| 267 | self.assertEqual(len(mockCopyFilesTo.call_args_list), 2) |
| 268 | self.assertEqual(mockCopyFilesTo.call_args_list[0][0], |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 269 | ('/tmp/results/', perf_data_files)) |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 270 | self.assertEqual(mockCopyFilesTo.call_args_list[1][0], |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 271 | ('/tmp/results/', perf_report_files)) |
| 272 | |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 273 | def test_get_new_keyvals(self): |
| 274 | kv_dict = {} |
| 275 | |
| 276 | def FakeGetDataMeasurementsFiles(): |
| 277 | filename = os.path.join(os.getcwd(), 'unittest_keyval_file.txt') |
| 278 | return [filename] |
| 279 | |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 280 | self.result.GetDataMeasurementsFiles = FakeGetDataMeasurementsFiles |
| 281 | kv_dict2, udict = self.result.GetNewKeyvals(kv_dict) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 282 | self.assertEqual(kv_dict2, |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 283 | {u'Box2D__Box2D': 4775, |
| 284 | u'Mandreel__Mandreel': 6620, |
| 285 | u'Gameboy__Gameboy': 9901, |
| 286 | u'Crypto__Crypto': 8737, |
| 287 | u'telemetry_page_measurement_results__num_errored': 0, |
| 288 | u'telemetry_page_measurement_results__num_failed': 0, |
| 289 | u'PdfJS__PdfJS': 6455, |
| 290 | u'Total__Score': 7918, |
| 291 | u'EarleyBoyer__EarleyBoyer': 14340, |
| 292 | u'MandreelLatency__MandreelLatency': 5188, |
| 293 | u'CodeLoad__CodeLoad': 6271, |
| 294 | u'DeltaBlue__DeltaBlue': 14401, |
| 295 | u'Typescript__Typescript': 9815, |
| 296 | u'SplayLatency__SplayLatency': 7653, |
| 297 | u'zlib__zlib': 16094, |
| 298 | u'Richards__Richards': 10358, |
| 299 | u'RegExp__RegExp': 1765, |
| 300 | u'NavierStokes__NavierStokes': 9815, |
| 301 | u'Splay__Splay': 4425, |
| 302 | u'RayTrace__RayTrace': 16600}) |
| 303 | self.assertEqual( |
| 304 | udict, {u'Box2D__Box2D': u'score', |
| 305 | u'Mandreel__Mandreel': u'score', |
| 306 | u'Gameboy__Gameboy': u'score', |
| 307 | u'Crypto__Crypto': u'score', |
| 308 | u'telemetry_page_measurement_results__num_errored': u'count', |
| 309 | u'telemetry_page_measurement_results__num_failed': u'count', |
| 310 | u'PdfJS__PdfJS': u'score', |
| 311 | u'Total__Score': u'score', |
| 312 | u'EarleyBoyer__EarleyBoyer': u'score', |
| 313 | u'MandreelLatency__MandreelLatency': u'score', |
| 314 | u'CodeLoad__CodeLoad': u'score', |
| 315 | u'DeltaBlue__DeltaBlue': u'score', |
| 316 | u'Typescript__Typescript': u'score', |
| 317 | u'SplayLatency__SplayLatency': u'score', |
| 318 | u'zlib__zlib': u'score', |
| 319 | u'Richards__Richards': u'score', |
| 320 | u'RegExp__RegExp': u'score', |
| 321 | u'NavierStokes__NavierStokes': u'score', |
| 322 | u'Splay__Splay': u'score', |
| 323 | u'RayTrace__RayTrace': u'score'}) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 324 | |
| 325 | def test_append_telemetry_units(self): |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 326 | kv_dict = {u'Box2D__Box2D': 4775, |
| 327 | u'Mandreel__Mandreel': 6620, |
| 328 | u'Gameboy__Gameboy': 9901, |
| 329 | u'Crypto__Crypto': 8737, |
| 330 | u'PdfJS__PdfJS': 6455, |
| 331 | u'Total__Score': 7918, |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 332 | u'EarleyBoyer__EarleyBoyer': 14340, |
| 333 | u'MandreelLatency__MandreelLatency': 5188, |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 334 | u'CodeLoad__CodeLoad': 6271, |
| 335 | u'DeltaBlue__DeltaBlue': 14401, |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 336 | u'Typescript__Typescript': 9815, |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 337 | u'SplayLatency__SplayLatency': 7653, |
| 338 | u'zlib__zlib': 16094, |
| 339 | u'Richards__Richards': 10358, |
| 340 | u'RegExp__RegExp': 1765, |
| 341 | u'NavierStokes__NavierStokes': 9815, |
| 342 | u'Splay__Splay': 4425, |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 343 | u'RayTrace__RayTrace': 16600} |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 344 | units_dict = {u'Box2D__Box2D': u'score', |
| 345 | u'Mandreel__Mandreel': u'score', |
| 346 | u'Gameboy__Gameboy': u'score', |
| 347 | u'Crypto__Crypto': u'score', |
| 348 | u'PdfJS__PdfJS': u'score', |
| 349 | u'Total__Score': u'score', |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 350 | u'EarleyBoyer__EarleyBoyer': u'score', |
| 351 | u'MandreelLatency__MandreelLatency': u'score', |
| 352 | u'CodeLoad__CodeLoad': u'score', |
| 353 | u'DeltaBlue__DeltaBlue': u'score', |
| 354 | u'Typescript__Typescript': u'score', |
| 355 | u'SplayLatency__SplayLatency': u'score', |
| 356 | u'zlib__zlib': u'score', |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 357 | u'Richards__Richards': u'score', |
| 358 | u'RegExp__RegExp': u'score', |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 359 | u'NavierStokes__NavierStokes': u'score', |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 360 | u'Splay__Splay': u'score', |
| 361 | u'RayTrace__RayTrace': u'score'} |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 362 | |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 363 | results_dict = self.result.AppendTelemetryUnits(kv_dict, units_dict) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 364 | self.assertEqual(results_dict, |
| 365 | {u'Box2D__Box2D': [4775, u'score'], |
| 366 | u'Splay__Splay': [4425, u'score'], |
| 367 | u'Gameboy__Gameboy': [9901, u'score'], |
| 368 | u'Crypto__Crypto': [8737, u'score'], |
| 369 | u'PdfJS__PdfJS': [6455, u'score'], |
| 370 | u'Total__Score': [7918, u'score'], |
| 371 | u'EarleyBoyer__EarleyBoyer': [14340, u'score'], |
| 372 | u'MandreelLatency__MandreelLatency': [5188, u'score'], |
| 373 | u'DeltaBlue__DeltaBlue': [14401, u'score'], |
| 374 | u'SplayLatency__SplayLatency': [7653, u'score'], |
| 375 | u'Mandreel__Mandreel': [6620, u'score'], |
| 376 | u'Richards__Richards': [10358, u'score'], |
| 377 | u'zlib__zlib': [16094, u'score'], |
| 378 | u'CodeLoad__CodeLoad': [6271, u'score'], |
| 379 | u'Typescript__Typescript': [9815, u'score'], |
| 380 | u'RegExp__RegExp': [1765, u'score'], |
| 381 | u'RayTrace__RayTrace': [16600, u'score'], |
| 382 | u'NavierStokes__NavierStokes': [9815, u'score']}) |
| 383 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 384 | @mock.patch.object(misc, 'GetInsideChrootPath') |
| 385 | @mock.patch.object(tempfile, 'mkdtemp') |
| 386 | @mock.patch.object(command_executer.CommandExecuter, 'RunCommand') |
Yunlian Jiang | fbda049 | 2015-12-21 15:32:44 -0800 | [diff] [blame] | 387 | @mock.patch.object(command_executer.CommandExecuter, |
| 388 | 'ChrootRunCommandWOutput') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 389 | def test_get_keyvals(self, mock_chrootruncmd, mock_runcmd, mock_mkdtemp, |
| 390 | mock_getpath): |
| 391 | |
| 392 | self.kv_dict = {} |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 393 | self.callGetNewKeyvals = False |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 394 | |
| 395 | def reset(): |
| 396 | self.kv_dict = {} |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 397 | self.callGetNewKeyvals = False |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 398 | mock_chrootruncmd.reset_mock() |
| 399 | mock_runcmd.reset_mock() |
| 400 | mock_mkdtemp.reset_mock() |
| 401 | mock_getpath.reset_mock() |
| 402 | |
| 403 | def FakeGetNewKeyvals(kv_dict): |
| 404 | self.kv_dict = kv_dict |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 405 | self.callGetNewKeyvals = True |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 406 | return_kvdict = {'first_time': 680, 'Total': 10} |
| 407 | return_udict = {'first_time': 'ms', 'Total': 'score'} |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 408 | return return_kvdict, return_udict |
| 409 | |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 410 | mock_mkdtemp.return_value = TMP_DIR1 |
| 411 | mock_chrootruncmd.return_value = ['', |
| 412 | ('%s,PASS\n%s/telemetry_Crosperf,PASS\n') |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 413 | % (TMP_DIR1, TMP_DIR1), ''] |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 414 | mock_getpath.return_value = TMP_DIR1 |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 415 | self.result.ce.ChrootRunCommandWOutput = mock_chrootruncmd |
| 416 | self.result.ce.RunCommand = mock_runcmd |
| 417 | self.result.GetNewKeyvals = FakeGetNewKeyvals |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 418 | self.result.suite = 'telemetry_Crosperf' |
| 419 | self.result.results_dir = '/tmp/test_that_resultsNmq' |
| 420 | |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 421 | # Test 1. no self.temp_dir. |
Caroline Tice | eddb063 | 2016-04-14 09:19:02 -0700 | [diff] [blame] | 422 | res = self.result.GetKeyvals() |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 423 | self.assertTrue(self.callGetNewKeyvals) |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 424 | self.assertEqual(self.kv_dict, {'': 'PASS', 'telemetry_Crosperf': 'PASS'}) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 425 | self.assertEqual(mock_runcmd.call_count, 1) |
| 426 | self.assertEqual(mock_runcmd.call_args_list[0][0], |
| 427 | ('cp -r /tmp/test_that_resultsNmq/* %s' % TMP_DIR1,)) |
| 428 | self.assertEqual(mock_chrootruncmd.call_count, 1) |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 429 | self.assertEqual(mock_chrootruncmd.call_args_list[0][0], ( |
| 430 | '/tmp', ('python generate_test_report --no-color --csv %s') % TMP_DIR1)) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 431 | self.assertEqual(mock_getpath.call_count, 1) |
| 432 | self.assertEqual(mock_mkdtemp.call_count, 1) |
| 433 | self.assertEqual(res, {'Total': [10, 'score'], 'first_time': [680, 'ms']}) |
| 434 | |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 435 | # Test 2. self.temp_dir |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 436 | reset() |
| 437 | mock_chrootruncmd.return_value = ['', |
| 438 | ('/tmp/tmpJCajRG,PASS\n/tmp/tmpJCajRG/' |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 439 | 'telemetry_Crosperf,PASS\n'), ''] |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 440 | mock_getpath.return_value = '/tmp/tmpJCajRG' |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 441 | self.result.temp_dir = '/tmp/tmpJCajRG' |
Caroline Tice | eddb063 | 2016-04-14 09:19:02 -0700 | [diff] [blame] | 442 | res = self.result.GetKeyvals() |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 443 | self.assertEqual(mock_runcmd.call_count, 0) |
| 444 | self.assertEqual(mock_mkdtemp.call_count, 0) |
| 445 | self.assertEqual(mock_chrootruncmd.call_count, 1) |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 446 | self.assertTrue(self.callGetNewKeyvals) |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 447 | self.assertEqual(self.kv_dict, {'': 'PASS', 'telemetry_Crosperf': 'PASS'}) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 448 | self.assertEqual(res, {'Total': [10, 'score'], 'first_time': [680, 'ms']}) |
| 449 | |
| 450 | # Test 3. suite != telemetry_Crosperf. Normally this would be for |
| 451 | # running non-Telemetry autotests, such as BootPerfServer. In this test |
| 452 | # case, the keyvals we have set up were returned from a Telemetry test run; |
| 453 | # so this pass is basically testing that we don't append the units to the |
| 454 | # test results (which we do for Telemetry autotest runs). |
| 455 | reset() |
| 456 | self.result.suite = '' |
Caroline Tice | eddb063 | 2016-04-14 09:19:02 -0700 | [diff] [blame] | 457 | res = self.result.GetKeyvals() |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 458 | self.assertEqual(res, {'Total': 10, 'first_time': 680}) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 459 | |
| 460 | def test_get_results_dir(self): |
| 461 | |
| 462 | self.result.out = '' |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 463 | self.assertRaises(Exception, self.result.GetResultsDir) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 464 | |
| 465 | self.result.out = OUTPUT |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 466 | resdir = self.result.GetResultsDir() |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 467 | self.assertEqual(resdir, '/tmp/test_that.PO1234567/platform_LibCBench') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 468 | |
Caroline Tice | 8d818fb | 2015-12-16 16:42:54 -0800 | [diff] [blame] | 469 | @mock.patch.object(command_executer.CommandExecuter, 'RunCommandGeneric') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 470 | def test_find_files_in_results_dir(self, mock_runcmd): |
| 471 | |
| 472 | self.result.results_dir = None |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 473 | res = self.result.FindFilesInResultsDir('-name perf.data') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 474 | self.assertIsNone(res) |
| 475 | |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 476 | self.result.ce.RunCommand = mock_runcmd |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 477 | self.result.results_dir = '/tmp/test_results' |
| 478 | mock_runcmd.return_value = [0, '/tmp/test_results/perf.data', ''] |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 479 | res = self.result.FindFilesInResultsDir('-name perf.data') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 480 | self.assertEqual(mock_runcmd.call_count, 1) |
| 481 | self.assertEqual(mock_runcmd.call_args_list[0][0], |
| 482 | ('find /tmp/test_results -name perf.data',)) |
| 483 | self.assertEqual(res, '/tmp/test_results/perf.data') |
| 484 | |
| 485 | mock_runcmd.reset_mock() |
| 486 | mock_runcmd.return_value = [1, '', ''] |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 487 | self.assertRaises(Exception, self.result.FindFilesInResultsDir, |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 488 | '-name perf.data') |
| 489 | |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 490 | @mock.patch.object(Result, 'FindFilesInResultsDir') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 491 | def test_get_perf_data_files(self, mock_findfiles): |
| 492 | self.args = None |
| 493 | |
| 494 | mock_findfiles.return_value = 'line1\nline1\n' |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 495 | self.result.FindFilesInResultsDir = mock_findfiles |
| 496 | res = self.result.GetPerfDataFiles() |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 497 | self.assertEqual(res, ['line1', 'line1']) |
| 498 | self.assertEqual(mock_findfiles.call_args_list[0][0], ('-name perf.data',)) |
| 499 | |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 500 | def test_get_perf_report_files(self): |
| 501 | self.args = None |
| 502 | |
| 503 | def FakeFindFiles(find_args): |
| 504 | self.args = find_args |
| 505 | return 'line1\nline1\n' |
| 506 | |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 507 | self.result.FindFilesInResultsDir = FakeFindFiles |
| 508 | res = self.result.GetPerfReportFiles() |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 509 | self.assertEqual(res, ['line1', 'line1']) |
| 510 | self.assertEqual(self.args, '-name perf.data.report') |
| 511 | |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 512 | def test_get_data_measurement_files(self): |
| 513 | self.args = None |
| 514 | |
| 515 | def FakeFindFiles(find_args): |
| 516 | self.args = find_args |
| 517 | return 'line1\nline1\n' |
| 518 | |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 519 | self.result.FindFilesInResultsDir = FakeFindFiles |
| 520 | res = self.result.GetDataMeasurementsFiles() |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 521 | self.assertEqual(res, ['line1', 'line1']) |
| 522 | self.assertEqual(self.args, '-name perf_measurements') |
| 523 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 524 | @mock.patch.object(misc, 'GetInsideChrootPath') |
| 525 | @mock.patch.object(command_executer.CommandExecuter, 'ChrootRunCommand') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 526 | def test_generate_perf_report_files(self, mock_chrootruncmd, mock_getpath): |
| 527 | fake_file = '/usr/chromeos/chroot/tmp/results/fake_file' |
| 528 | self.result.perf_data_files = ['/tmp/results/perf.data'] |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 529 | self.result.board = 'lumpy' |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 530 | mock_getpath.return_value = fake_file |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 531 | self.result.ce.ChrootRunCommand = mock_chrootruncmd |
| 532 | tmp = self.result.GeneratePerfReportFiles() |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 533 | self.assertEqual(tmp, ['/tmp/chroot%s' % fake_file]) |
| 534 | self.assertEqual(mock_chrootruncmd.call_args_list[0][0], |
| 535 | ('/tmp', |
| 536 | ('/tmp/perf.static report -n --symfs /build/lumpy ' |
| 537 | '--vmlinux /build/lumpy/usr/lib/debug/boot/vmlinux ' |
| 538 | '--kallsyms /build/lumpy/boot/System.map-* -i ' |
| 539 | '%s --stdio > %s') % (fake_file, fake_file))) |
| 540 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 541 | @mock.patch.object(misc, 'GetOutsideChrootPath') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 542 | def test_populate_from_run(self, mock_getpath): |
| 543 | |
| 544 | def FakeGetResultsDir(): |
| 545 | self.callGetResultsDir = True |
| 546 | return '/tmp/results_dir' |
| 547 | |
Rahul Chaudhry | b45d1fa | 2016-07-29 14:24:07 -0700 | [diff] [blame] | 548 | def FakeGetResultsFile(): |
| 549 | self.callGetResultsFile = True |
| 550 | return [] |
| 551 | |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 552 | def FakeGetPerfDataFiles(): |
| 553 | self.callGetPerfDataFiles = True |
| 554 | return [] |
| 555 | |
| 556 | def FakeGetPerfReportFiles(): |
| 557 | self.callGetPerfReportFiles = True |
| 558 | return [] |
| 559 | |
Caroline Tice | eddb063 | 2016-04-14 09:19:02 -0700 | [diff] [blame] | 560 | def FakeProcessResults(show_results=False): |
Yunlian Jiang | aefb76c | 2015-12-29 08:59:52 -0800 | [diff] [blame] | 561 | if show_results: |
| 562 | pass |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 563 | self.callProcessResults = True |
| 564 | |
Yunlian Jiang | aefb76c | 2015-12-29 08:59:52 -0800 | [diff] [blame] | 565 | if mock_getpath: |
| 566 | pass |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 567 | mock.get_path = '/tmp/chromeos/tmp/results_dir' |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 568 | self.result.chromeos_root = '/tmp/chromeos' |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 569 | |
| 570 | self.callGetResultsDir = False |
Rahul Chaudhry | b45d1fa | 2016-07-29 14:24:07 -0700 | [diff] [blame] | 571 | self.callGetResultsFile = False |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 572 | self.callGetPerfDataFiles = False |
| 573 | self.callGetPerfReportFiles = False |
| 574 | self.callProcessResults = False |
| 575 | |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 576 | self.result.GetResultsDir = FakeGetResultsDir |
Rahul Chaudhry | b45d1fa | 2016-07-29 14:24:07 -0700 | [diff] [blame] | 577 | self.result.GetResultsFile = FakeGetResultsFile |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 578 | self.result.GetPerfDataFiles = FakeGetPerfDataFiles |
| 579 | self.result.GeneratePerfReportFiles = FakeGetPerfReportFiles |
| 580 | self.result.ProcessResults = FakeProcessResults |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 581 | |
Caroline Tice | eddb063 | 2016-04-14 09:19:02 -0700 | [diff] [blame] | 582 | self.result.PopulateFromRun(OUTPUT, '', 0, 'test', |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 583 | 'telemetry_Crosperf') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 584 | self.assertTrue(self.callGetResultsDir) |
Rahul Chaudhry | b45d1fa | 2016-07-29 14:24:07 -0700 | [diff] [blame] | 585 | self.assertTrue(self.callGetResultsFile) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 586 | self.assertTrue(self.callGetPerfDataFiles) |
| 587 | self.assertTrue(self.callGetPerfReportFiles) |
| 588 | self.assertTrue(self.callProcessResults) |
| 589 | |
| 590 | def test_process_results(self): |
| 591 | |
Caroline Tice | eddb063 | 2016-04-14 09:19:02 -0700 | [diff] [blame] | 592 | def FakeGetKeyvals(show_all=False): |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 593 | if show_all: |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 594 | return {'first_time': 680, 'Total': 10} |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 595 | else: |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 596 | return {'Total': 10} |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 597 | |
| 598 | def FakeGatherPerfResults(): |
| 599 | self.callGatherPerfResults = True |
| 600 | |
| 601 | self.callGatherPerfResults = False |
| 602 | |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 603 | self.result.GetKeyvals = FakeGetKeyvals |
| 604 | self.result.GatherPerfResults = FakeGatherPerfResults |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 605 | |
| 606 | self.result.retval = 0 |
Caroline Tice | eddb063 | 2016-04-14 09:19:02 -0700 | [diff] [blame] | 607 | self.result.ProcessResults() |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 608 | self.assertTrue(self.callGatherPerfResults) |
Caroline Tice | eddb063 | 2016-04-14 09:19:02 -0700 | [diff] [blame] | 609 | self.assertEqual(len(self.result.keyvals), 2) |
| 610 | self.assertEqual(self.result.keyvals, {'Total': 10, |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 611 | 'retval': 0}) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 612 | |
| 613 | self.result.retval = 1 |
Caroline Tice | eddb063 | 2016-04-14 09:19:02 -0700 | [diff] [blame] | 614 | self.result.ProcessResults() |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 615 | self.assertEqual(len(self.result.keyvals), 2) |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 616 | self.assertEqual(self.result.keyvals, {'Total': 10, 'retval': 1}) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 617 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 618 | @mock.patch.object(misc, 'GetInsideChrootPath') |
Yunlian Jiang | fbda049 | 2015-12-21 15:32:44 -0800 | [diff] [blame] | 619 | @mock.patch.object(command_executer.CommandExecuter, |
| 620 | 'ChrootRunCommandWOutput') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 621 | def test_populate_from_cache_dir(self, mock_runchrootcmd, mock_getpath): |
| 622 | |
Caroline Tice | eddb063 | 2016-04-14 09:19:02 -0700 | [diff] [blame] | 623 | # pylint: disable=redefined-builtin |
| 624 | def FakeMkdtemp(dir=None): |
Yunlian Jiang | aefb76c | 2015-12-29 08:59:52 -0800 | [diff] [blame] | 625 | if dir: |
| 626 | pass |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 627 | return self.tmpdir |
| 628 | |
| 629 | current_path = os.getcwd() |
| 630 | cache_dir = os.path.join(current_path, 'test_cache/test_input') |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 631 | self.result.ce = command_executer.GetCommandExecuter(log_level='average') |
| 632 | self.result.ce.ChrootRunCommandWOutput = mock_runchrootcmd |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 633 | mock_runchrootcmd.return_value = ['', |
| 634 | ('%s,PASS\n%s/\telemetry_Crosperf,PASS\n') |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 635 | % (TMP_DIR1, TMP_DIR1), ''] |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 636 | mock_getpath.return_value = TMP_DIR1 |
| 637 | self.tmpdir = tempfile.mkdtemp() |
| 638 | save_real_mkdtemp = tempfile.mkdtemp |
| 639 | tempfile.mkdtemp = FakeMkdtemp |
| 640 | |
Caroline Tice | eddb063 | 2016-04-14 09:19:02 -0700 | [diff] [blame] | 641 | self.result.PopulateFromCacheDir(cache_dir, 'sunspider', |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 642 | 'telemetry_Crosperf') |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 643 | self.assertEqual( |
| 644 | self.result.keyvals, |
| 645 | {u'Total__Total': [444.0, u'ms'], |
| 646 | u'regexp-dna__regexp-dna': [16.2, u'ms'], |
| 647 | u'telemetry_page_measurement_results__num_failed': [0, u'count'], |
| 648 | u'telemetry_page_measurement_results__num_errored': [0, u'count'], |
| 649 | u'string-fasta__string-fasta': [23.2, u'ms'], |
| 650 | u'crypto-sha1__crypto-sha1': [11.6, u'ms'], |
| 651 | u'bitops-3bit-bits-in-byte__bitops-3bit-bits-in-byte': [3.2, u'ms'], |
| 652 | u'access-nsieve__access-nsieve': [7.9, u'ms'], |
| 653 | u'bitops-nsieve-bits__bitops-nsieve-bits': [9.4, u'ms'], |
| 654 | u'string-validate-input__string-validate-input': [19.3, u'ms'], |
| 655 | u'3d-raytrace__3d-raytrace': [24.7, u'ms'], |
| 656 | u'3d-cube__3d-cube': [28.0, u'ms'], |
| 657 | u'string-unpack-code__string-unpack-code': [46.7, u'ms'], |
| 658 | u'date-format-tofte__date-format-tofte': [26.3, u'ms'], |
| 659 | u'math-partial-sums__math-partial-sums': [22.0, u'ms'], |
| 660 | '\telemetry_Crosperf': ['PASS', ''], |
| 661 | u'crypto-aes__crypto-aes': [15.2, u'ms'], |
| 662 | u'bitops-bitwise-and__bitops-bitwise-and': [8.4, u'ms'], |
| 663 | u'crypto-md5__crypto-md5': [10.5, u'ms'], |
| 664 | u'string-tagcloud__string-tagcloud': [52.8, u'ms'], |
| 665 | u'access-nbody__access-nbody': [8.5, u'ms'], |
| 666 | 'retval': 0, |
| 667 | u'math-spectral-norm__math-spectral-norm': [6.6, u'ms'], |
| 668 | u'math-cordic__math-cordic': [8.7, u'ms'], |
| 669 | u'access-binary-trees__access-binary-trees': [4.5, u'ms'], |
| 670 | u'controlflow-recursive__controlflow-recursive': [4.4, u'ms'], |
| 671 | u'access-fannkuch__access-fannkuch': [17.8, u'ms'], |
| 672 | u'string-base64__string-base64': [16.0, u'ms'], |
| 673 | u'date-format-xparb__date-format-xparb': [20.9, u'ms'], |
| 674 | u'3d-morph__3d-morph': [22.1, u'ms'], |
| 675 | u'bitops-bits-in-byte__bitops-bits-in-byte': [9.1, u'ms']}) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 676 | |
| 677 | # Clean up after test. |
| 678 | tempfile.mkdtemp = save_real_mkdtemp |
| 679 | command = 'rm -Rf %s' % self.tmpdir |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 680 | self.result.ce.RunCommand(command) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 681 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 682 | @mock.patch.object(misc, 'GetRoot') |
| 683 | @mock.patch.object(command_executer.CommandExecuter, 'RunCommand') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 684 | def test_cleanup(self, mock_runcmd, mock_getroot): |
| 685 | |
| 686 | # Test 1. 'rm_chroot_tmp' is True; self.results_dir exists; |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 687 | # self.temp_dir exists; results_dir name contains 'test_that_results_'. |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 688 | mock_getroot.return_value = ['/tmp/tmp_AbcXyz', 'test_that_results_fake'] |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 689 | self.result.ce.RunCommand = mock_runcmd |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 690 | self.result.results_dir = 'test_results_dir' |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 691 | self.result.temp_dir = 'testtemp_dir' |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 692 | self.result.CleanUp(True) |
| 693 | self.assertEqual(mock_getroot.call_count, 1) |
| 694 | self.assertEqual(mock_runcmd.call_count, 2) |
| 695 | self.assertEqual(mock_runcmd.call_args_list[0][0], |
| 696 | ('rm -rf test_results_dir',)) |
| 697 | self.assertEqual(mock_runcmd.call_args_list[1][0], |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 698 | ('rm -rf testtemp_dir',)) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 699 | |
| 700 | # Test 2. Same, except ath results_dir name does not contain |
| 701 | # 'test_that_results_' |
| 702 | mock_getroot.reset_mock() |
| 703 | mock_runcmd.reset_mock() |
| 704 | mock_getroot.return_value = ['/tmp/tmp_AbcXyz', 'other_results_fake'] |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 705 | self.result.ce.RunCommand = mock_runcmd |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 706 | self.result.results_dir = 'test_results_dir' |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 707 | self.result.temp_dir = 'testtemp_dir' |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 708 | self.result.CleanUp(True) |
| 709 | self.assertEqual(mock_getroot.call_count, 1) |
| 710 | self.assertEqual(mock_runcmd.call_count, 2) |
| 711 | self.assertEqual(mock_runcmd.call_args_list[0][0], |
| 712 | ('rm -rf /tmp/tmp_AbcXyz',)) |
| 713 | self.assertEqual(mock_runcmd.call_args_list[1][0], |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 714 | ('rm -rf testtemp_dir',)) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 715 | |
| 716 | # Test 3. mock_getroot returns nothing; 'rm_chroot_tmp' is False. |
| 717 | mock_getroot.reset_mock() |
| 718 | mock_runcmd.reset_mock() |
| 719 | self.result.CleanUp(False) |
| 720 | self.assertEqual(mock_getroot.call_count, 0) |
| 721 | self.assertEqual(mock_runcmd.call_count, 1) |
| 722 | self.assertEqual(mock_runcmd.call_args_list[0][0], |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 723 | ('rm -rf testtemp_dir',)) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 724 | |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 725 | # Test 4. 'rm_chroot_tmp' is True, but result_dir & temp_dir are None. |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 726 | mock_getroot.reset_mock() |
| 727 | mock_runcmd.reset_mock() |
| 728 | self.result.results_dir = None |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 729 | self.result.temp_dir = None |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 730 | self.result.CleanUp(True) |
| 731 | self.assertEqual(mock_getroot.call_count, 0) |
| 732 | self.assertEqual(mock_runcmd.call_count, 0) |
| 733 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 734 | @mock.patch.object(misc, 'GetInsideChrootPath') |
| 735 | @mock.patch.object(command_executer.CommandExecuter, 'ChrootRunCommand') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 736 | def test_store_to_cache_dir(self, mock_chrootruncmd, mock_getpath): |
| 737 | |
Yunlian Jiang | aefb76c | 2015-12-29 08:59:52 -0800 | [diff] [blame] | 738 | def FakeMkdtemp(directory=''): |
| 739 | if directory: |
| 740 | pass |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 741 | return self.tmpdir |
| 742 | |
Yunlian Jiang | aefb76c | 2015-12-29 08:59:52 -0800 | [diff] [blame] | 743 | if mock_chrootruncmd or mock_getpath: |
| 744 | pass |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 745 | current_path = os.getcwd() |
| 746 | cache_dir = os.path.join(current_path, 'test_cache/test_output') |
| 747 | |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 748 | self.result.ce = command_executer.GetCommandExecuter(log_level='average') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 749 | self.result.out = OUTPUT |
| 750 | self.result.err = error |
| 751 | self.result.retval = 0 |
| 752 | self.tmpdir = tempfile.mkdtemp() |
| 753 | if not os.path.exists(self.tmpdir): |
| 754 | os.makedirs(self.tmpdir) |
| 755 | self.result.results_dir = os.path.join(os.getcwd(), 'test_cache') |
| 756 | save_real_mkdtemp = tempfile.mkdtemp |
| 757 | tempfile.mkdtemp = FakeMkdtemp |
| 758 | |
| 759 | mock_mm = machine_manager.MockMachineManager('/tmp/chromeos_root', 0, |
David Sharp | a936834 | 2016-01-22 17:52:01 -0800 | [diff] [blame] | 760 | 'average', '') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 761 | mock_mm.machine_checksum_string['mock_label'] = 'fake_machine_checksum123' |
| 762 | |
Caroline Tice | e627fd6 | 2015-12-11 12:07:59 -0800 | [diff] [blame] | 763 | mock_keylist = ['key1', 'key2', 'key3'] |
| 764 | test_flag.SetTestMode(True) |
| 765 | self.result.StoreToCacheDir(cache_dir, mock_mm, mock_keylist) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 766 | |
| 767 | # Check that the correct things were written to the 'cache'. |
| 768 | test_dir = os.path.join(os.getcwd(), 'test_cache/test_output') |
| 769 | base_dir = os.path.join(os.getcwd(), 'test_cache/compare_output') |
| 770 | self.assertTrue(os.path.exists(os.path.join(test_dir, 'autotest.tbz2'))) |
| 771 | self.assertTrue(os.path.exists(os.path.join(test_dir, 'machine.txt'))) |
| 772 | self.assertTrue(os.path.exists(os.path.join(test_dir, 'results.txt'))) |
| 773 | |
| 774 | f1 = os.path.join(test_dir, 'machine.txt') |
| 775 | f2 = os.path.join(base_dir, 'machine.txt') |
| 776 | cmd = 'diff %s %s' % (f1, f2) |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 777 | [_, out, _] = self.result.ce.RunCommandWOutput(cmd) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 778 | self.assertEqual(len(out), 0) |
| 779 | |
| 780 | f1 = os.path.join(test_dir, 'results.txt') |
| 781 | f2 = os.path.join(base_dir, 'results.txt') |
| 782 | cmd = 'diff %s %s' % (f1, f2) |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 783 | [_, out, _] = self.result.ce.RunCommandWOutput(cmd) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 784 | self.assertEqual(len(out), 0) |
| 785 | |
| 786 | # Clean up after test. |
| 787 | tempfile.mkdtemp = save_real_mkdtemp |
| 788 | command = 'rm %s/*' % test_dir |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 789 | self.result.ce.RunCommand(command) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 790 | |
| 791 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 792 | TELEMETRY_RESULT_KEYVALS = { |
| 793 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 794 | 'math-cordic (ms)': |
| 795 | '11.4', |
| 796 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 797 | 'access-nbody (ms)': |
| 798 | '6.9', |
| 799 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 800 | 'access-fannkuch (ms)': |
| 801 | '26.3', |
| 802 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 803 | 'math-spectral-norm (ms)': |
| 804 | '6.3', |
| 805 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 806 | 'bitops-nsieve-bits (ms)': |
| 807 | '9.3', |
| 808 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 809 | 'math-partial-sums (ms)': |
| 810 | '32.8', |
| 811 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 812 | 'regexp-dna (ms)': |
| 813 | '16.1', |
| 814 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 815 | '3d-cube (ms)': |
| 816 | '42.7', |
| 817 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 818 | 'crypto-md5 (ms)': |
| 819 | '10.8', |
| 820 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 821 | 'crypto-sha1 (ms)': |
| 822 | '12.4', |
| 823 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 824 | 'string-tagcloud (ms)': |
| 825 | '47.2', |
| 826 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 827 | 'string-fasta (ms)': |
| 828 | '36.3', |
| 829 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 830 | 'access-binary-trees (ms)': |
| 831 | '7.3', |
| 832 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 833 | 'date-format-xparb (ms)': |
| 834 | '138.1', |
| 835 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 836 | 'crypto-aes (ms)': |
| 837 | '19.2', |
| 838 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 839 | 'Total (ms)': |
| 840 | '656.5', |
| 841 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 842 | 'string-base64 (ms)': |
| 843 | '17.5', |
| 844 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 845 | 'string-validate-input (ms)': |
| 846 | '24.8', |
| 847 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 848 | '3d-raytrace (ms)': |
| 849 | '28.7', |
| 850 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 851 | 'controlflow-recursive (ms)': |
| 852 | '5.3', |
| 853 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 854 | 'bitops-bits-in-byte (ms)': |
| 855 | '9.8', |
| 856 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 857 | '3d-morph (ms)': |
| 858 | '50.2', |
| 859 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 860 | 'bitops-bitwise-and (ms)': |
| 861 | '8.8', |
| 862 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 863 | 'access-nsieve (ms)': |
| 864 | '8.6', |
| 865 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 866 | 'date-format-tofte (ms)': |
| 867 | '31.2', |
| 868 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 869 | 'bitops-3bit-bits-in-byte (ms)': |
| 870 | '3.5', |
| 871 | 'retval': 0, |
| 872 | 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html ' |
| 873 | 'string-unpack-code (ms)': |
| 874 | '45.0' |
| 875 | } |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 876 | |
Yunlian Jiang | fbda049 | 2015-12-21 15:32:44 -0800 | [diff] [blame] | 877 | PURE_TELEMETRY_OUTPUT = """ |
| 878 | page_name,3d-cube (ms),3d-morph (ms),3d-raytrace (ms),Total (ms),access-binary-trees (ms),access-fannkuch (ms),access-nbody (ms),access-nsieve (ms),bitops-3bit-bits-in-byte (ms),bitops-bits-in-byte (ms),bitops-bitwise-and (ms),bitops-nsieve-bits (ms),controlflow-recursive (ms),crypto-aes (ms),crypto-md5 (ms),crypto-sha1 (ms),date-format-tofte (ms),date-format-xparb (ms),math-cordic (ms),math-partial-sums (ms),math-spectral-norm (ms),regexp-dna (ms),string-base64 (ms),string-fasta (ms),string-tagcloud (ms),string-unpack-code (ms),string-validate-input (ms)\r\nhttp://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html,42.7,50.2,28.7,656.5,7.3,26.3,6.9,8.6,3.5,9.8,8.8,9.3,5.3,19.2,10.8,12.4,31.2,138.1,11.4,32.8,6.3,16.1,17.5,36.3,47.2,45.0,24.8\r |
| 879 | """ |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 880 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 881 | |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 882 | class TelemetryResultTest(unittest.TestCase): |
Yunlian Jiang | aefb76c | 2015-12-29 08:59:52 -0800 | [diff] [blame] | 883 | """Telemetry result test.""" |
Yunlian Jiang | 4ef1352 | 2015-12-29 13:20:45 -0800 | [diff] [blame] | 884 | |
| 885 | def __init__(self, *args, **kwargs): |
| 886 | super(TelemetryResultTest, self).__init__(*args, **kwargs) |
| 887 | self.callFakeProcessResults = False |
| 888 | self.result = None |
| 889 | self.mock_logger = mock.Mock(spec=logger.Logger) |
| 890 | self.mock_cmd_exec = mock.Mock(spec=command_executer.CommandExecuter) |
| 891 | self.mock_label = MockLabel('mock_label', 'chromeos_image', '/tmp', |
| 892 | 'lumpy', 'remote', 'image_args', 'cache_dir', |
| 893 | 'average', 'gcc', None) |
| 894 | self.mock_machine = machine_manager.MockCrosMachine('falco.cros', |
| 895 | '/tmp/chromeos', |
| 896 | 'average') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 897 | |
| 898 | def test_populate_from_run(self): |
| 899 | |
| 900 | def FakeProcessResults(): |
| 901 | self.callFakeProcessResults = True |
| 902 | |
| 903 | self.callFakeProcessResults = False |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 904 | self.result = TelemetryResult(self.mock_logger, self.mock_label, 'average', |
| 905 | self.mock_cmd_exec) |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 906 | self.result.ProcessResults = FakeProcessResults |
Caroline Tice | eddb063 | 2016-04-14 09:19:02 -0700 | [diff] [blame] | 907 | self.result.PopulateFromRun(OUTPUT, error, 3, 'fake_test', |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 908 | 'telemetry_Crosperf') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 909 | self.assertTrue(self.callFakeProcessResults) |
| 910 | self.assertEqual(self.result.out, OUTPUT) |
| 911 | self.assertEqual(self.result.err, error) |
| 912 | self.assertEqual(self.result.retval, 3) |
| 913 | |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 914 | def test_populate_from_cache_dir_and_process_results(self): |
| 915 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 916 | self.result = TelemetryResult(self.mock_logger, self.mock_label, 'average', |
| 917 | self.mock_machine) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 918 | current_path = os.getcwd() |
| 919 | cache_dir = os.path.join(current_path, |
| 920 | 'test_cache/test_puretelemetry_input') |
Caroline Tice | eddb063 | 2016-04-14 09:19:02 -0700 | [diff] [blame] | 921 | self.result.PopulateFromCacheDir(cache_dir, '', '') |
Yunlian Jiang | fbda049 | 2015-12-21 15:32:44 -0800 | [diff] [blame] | 922 | self.assertEqual(self.result.out.strip(), PURE_TELEMETRY_OUTPUT.strip()) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 923 | self.assertEqual(self.result.err, '') |
| 924 | self.assertEqual(self.result.retval, 0) |
| 925 | self.assertEqual(self.result.keyvals, TELEMETRY_RESULT_KEYVALS) |
| 926 | |
| 927 | |
| 928 | class ResultsCacheTest(unittest.TestCase): |
Yunlian Jiang | aefb76c | 2015-12-29 08:59:52 -0800 | [diff] [blame] | 929 | """Resultcache test class.""" |
Yunlian Jiang | 4ef1352 | 2015-12-29 13:20:45 -0800 | [diff] [blame] | 930 | |
| 931 | def __init__(self, *args, **kwargs): |
| 932 | super(ResultsCacheTest, self).__init__(*args, **kwargs) |
| 933 | self.fakeCacheReturnResult = None |
| 934 | self.mock_logger = mock.Mock(spec=logger.Logger) |
| 935 | self.mock_label = MockLabel('mock_label', 'chromeos_image', '/tmp', 'lumpy', |
| 936 | 'remote', 'image_args', 'cache_dir', 'average', |
| 937 | 'gcc', None) |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 938 | |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 939 | def setUp(self): |
| 940 | self.results_cache = ResultsCache() |
| 941 | |
Caroline Tice | e627fd6 | 2015-12-11 12:07:59 -0800 | [diff] [blame] | 942 | mock_machine = machine_manager.MockCrosMachine('falco.cros', |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 943 | '/tmp/chromeos', 'average') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 944 | |
| 945 | mock_mm = machine_manager.MockMachineManager('/tmp/chromeos_root', 0, |
David Sharp | a936834 | 2016-01-22 17:52:01 -0800 | [diff] [blame] | 946 | 'average', '') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 947 | mock_mm.machine_checksum_string['mock_label'] = 'fake_machine_checksum123' |
| 948 | |
| 949 | self.results_cache.Init(self.mock_label.chromeos_image, |
| 950 | self.mock_label.chromeos_root, |
| 951 | 'sunspider', |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 952 | 1, # benchmark_run.iteration, |
| 953 | '', # benchmark_run.test_args, |
| 954 | '', # benchmark_run.profiler_args, |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 955 | mock_mm, |
Caroline Tice | e627fd6 | 2015-12-11 12:07:59 -0800 | [diff] [blame] | 956 | mock_machine, |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 957 | self.mock_label.board, |
| 958 | [CacheConditions.CACHE_FILE_EXISTS, |
| 959 | CacheConditions.CHECKSUMS_MATCH], |
| 960 | self.mock_logger, |
| 961 | 'average', |
| 962 | self.mock_label, |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 963 | '', # benchmark_run.share_cache |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 964 | 'telemetry_Crosperf', |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 965 | True, # benchmark_run.show_all_results |
| 966 | False) # benchmark_run.run_local |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 967 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 968 | @mock.patch.object(image_checksummer.ImageChecksummer, 'Checksum') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 969 | def test_get_cache_dir_for_write(self, mock_checksum): |
| 970 | |
| 971 | def FakeGetMachines(label): |
Yunlian Jiang | aefb76c | 2015-12-29 08:59:52 -0800 | [diff] [blame] | 972 | if label: |
| 973 | pass |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 974 | m1 = machine_manager.MockCrosMachine( |
| 975 | 'lumpy1.cros', self.results_cache.chromeos_root, 'average') |
| 976 | m2 = machine_manager.MockCrosMachine( |
| 977 | 'lumpy2.cros', self.results_cache.chromeos_root, 'average') |
| 978 | return [m1, m2] |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 979 | |
| 980 | mock_checksum.return_value = 'FakeImageChecksumabc123' |
| 981 | self.results_cache.machine_manager.GetMachines = FakeGetMachines |
| 982 | self.results_cache.machine_manager.machine_checksum['mock_label'] = \ |
| 983 | 'FakeMachineChecksumabc987' |
| 984 | # Based on the label, benchmark and machines, get the directory in which |
| 985 | # to store the cache information for this test run. |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 986 | result_path = self.results_cache.GetCacheDirForWrite() |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 987 | # Verify that the returned directory is correct (since the label |
| 988 | # contained a cache_dir, named 'cache_dir', that's what is expected in |
| 989 | # the result, rather than '~/cros_scratch'). |
| 990 | comp_path = os.path.join(os.getcwd(), |
| 991 | 'cache_dir/54524606abaae4fdf7b02f49f7ae7127_' |
Caroline Tice | e627fd6 | 2015-12-11 12:07:59 -0800 | [diff] [blame] | 992 | 'sunspider_1_fda29412ceccb72977516c4785d08e2c_' |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 993 | 'FakeImageChecksumabc123_FakeMachineChecksum' |
| 994 | 'abc987__6') |
| 995 | self.assertEqual(result_path, comp_path) |
| 996 | |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 997 | def test_form_cache_dir(self): |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 998 | # This is very similar to the previous test (FormCacheDir is called |
| 999 | # from GetCacheDirForWrite). |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1000 | cache_key_list = ('54524606abaae4fdf7b02f49f7ae7127', 'sunspider', '1', |
| 1001 | '7215ee9c7d9dc229d2921a40e899ec5f', |
| 1002 | 'FakeImageChecksumabc123', '*', '*', '6') |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 1003 | path = self.results_cache.FormCacheDir(cache_key_list) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1004 | self.assertEqual(len(path), 1) |
| 1005 | path1 = path[0] |
| 1006 | test_dirname = ('54524606abaae4fdf7b02f49f7ae7127_sunspider_1_7215ee9' |
| 1007 | 'c7d9dc229d2921a40e899ec5f_FakeImageChecksumabc123_*_*_6') |
| 1008 | comp_path = os.path.join(os.getcwd(), 'cache_dir', test_dirname) |
| 1009 | self.assertEqual(path1, comp_path) |
| 1010 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 1011 | @mock.patch.object(image_checksummer.ImageChecksummer, 'Checksum') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1012 | def test_get_cache_key_list(self, mock_checksum): |
| 1013 | # This tests the mechanism that generates the various pieces of the |
| 1014 | # cache directory name, based on various conditions. |
| 1015 | |
| 1016 | def FakeGetMachines(label): |
Yunlian Jiang | aefb76c | 2015-12-29 08:59:52 -0800 | [diff] [blame] | 1017 | if label: |
| 1018 | pass |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 1019 | m1 = machine_manager.MockCrosMachine( |
| 1020 | 'lumpy1.cros', self.results_cache.chromeos_root, 'average') |
| 1021 | m2 = machine_manager.MockCrosMachine( |
| 1022 | 'lumpy2.cros', self.results_cache.chromeos_root, 'average') |
| 1023 | return [m1, m2] |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1024 | |
| 1025 | mock_checksum.return_value = 'FakeImageChecksumabc123' |
| 1026 | self.results_cache.machine_manager.GetMachines = FakeGetMachines |
| 1027 | self.results_cache.machine_manager.machine_checksum['mock_label'] = \ |
| 1028 | 'FakeMachineChecksumabc987' |
| 1029 | |
| 1030 | # Test 1. Generating cache name for reading (not writing). |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 1031 | key_list = self.results_cache.GetCacheKeyList(True) |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 1032 | self.assertEqual(key_list[0], '*') # Machine checksum value, for read. |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1033 | self.assertEqual(key_list[1], 'sunspider') |
| 1034 | self.assertEqual(key_list[2], '1') |
Caroline Tice | e627fd6 | 2015-12-11 12:07:59 -0800 | [diff] [blame] | 1035 | self.assertEqual(key_list[3], 'fda29412ceccb72977516c4785d08e2c') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1036 | self.assertEqual(key_list[4], 'FakeImageChecksumabc123') |
| 1037 | self.assertEqual(key_list[5], '*') |
| 1038 | self.assertEqual(key_list[6], '*') |
| 1039 | self.assertEqual(key_list[7], '6') |
| 1040 | |
| 1041 | # Test 2. Generating cache name for writing, with local image type. |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 1042 | key_list = self.results_cache.GetCacheKeyList(False) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1043 | self.assertEqual(key_list[0], '54524606abaae4fdf7b02f49f7ae7127') |
| 1044 | self.assertEqual(key_list[1], 'sunspider') |
| 1045 | self.assertEqual(key_list[2], '1') |
Caroline Tice | e627fd6 | 2015-12-11 12:07:59 -0800 | [diff] [blame] | 1046 | self.assertEqual(key_list[3], 'fda29412ceccb72977516c4785d08e2c') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1047 | self.assertEqual(key_list[4], 'FakeImageChecksumabc123') |
| 1048 | self.assertEqual(key_list[5], 'FakeMachineChecksumabc987') |
| 1049 | self.assertEqual(key_list[6], '') |
| 1050 | self.assertEqual(key_list[7], '6') |
| 1051 | |
| 1052 | # Test 3. Generating cache name for writing, with trybot image type. |
| 1053 | self.results_cache.label.image_type = 'trybot' |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 1054 | key_list = self.results_cache.GetCacheKeyList(False) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1055 | self.assertEqual(key_list[0], '54524606abaae4fdf7b02f49f7ae7127') |
Caroline Tice | e627fd6 | 2015-12-11 12:07:59 -0800 | [diff] [blame] | 1056 | self.assertEqual(key_list[3], 'fda29412ceccb72977516c4785d08e2c') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1057 | self.assertEqual(key_list[4], '54524606abaae4fdf7b02f49f7ae7127') |
| 1058 | self.assertEqual(key_list[5], 'FakeMachineChecksumabc987') |
| 1059 | |
| 1060 | # Test 4. Generating cache name for writing, with official image type. |
| 1061 | self.results_cache.label.image_type = 'official' |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 1062 | key_list = self.results_cache.GetCacheKeyList(False) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1063 | self.assertEqual(key_list[0], '54524606abaae4fdf7b02f49f7ae7127') |
| 1064 | self.assertEqual(key_list[1], 'sunspider') |
| 1065 | self.assertEqual(key_list[2], '1') |
Caroline Tice | e627fd6 | 2015-12-11 12:07:59 -0800 | [diff] [blame] | 1066 | self.assertEqual(key_list[3], 'fda29412ceccb72977516c4785d08e2c') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1067 | self.assertEqual(key_list[4], '*') |
| 1068 | self.assertEqual(key_list[5], 'FakeMachineChecksumabc987') |
| 1069 | self.assertEqual(key_list[6], '') |
| 1070 | self.assertEqual(key_list[7], '6') |
| 1071 | |
| 1072 | # Test 5. Generating cache name for writing, with local image type, and |
| 1073 | # specifying that the image path must match the cached image path. |
| 1074 | self.results_cache.label.image_type = 'local' |
| 1075 | self.results_cache.cache_conditions.append(CacheConditions.IMAGE_PATH_MATCH) |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 1076 | key_list = self.results_cache.GetCacheKeyList(False) |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1077 | self.assertEqual(key_list[0], '54524606abaae4fdf7b02f49f7ae7127') |
Caroline Tice | e627fd6 | 2015-12-11 12:07:59 -0800 | [diff] [blame] | 1078 | self.assertEqual(key_list[3], 'fda29412ceccb72977516c4785d08e2c') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1079 | self.assertEqual(key_list[4], 'FakeImageChecksumabc123') |
| 1080 | self.assertEqual(key_list[5], 'FakeMachineChecksumabc987') |
| 1081 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 1082 | @mock.patch.object(command_executer.CommandExecuter, 'RunCommand') |
| 1083 | @mock.patch.object(os.path, 'isdir') |
| 1084 | @mock.patch.object(Result, 'CreateFromCacheHit') |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1085 | def test_read_result(self, mock_create, mock_isdir, mock_runcmd): |
| 1086 | |
| 1087 | self.fakeCacheReturnResult = None |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 1088 | |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1089 | def FakeGetCacheDirForRead(): |
| 1090 | return self.fakeCacheReturnResult |
| 1091 | |
| 1092 | def FakeGetCacheDirForWrite(): |
| 1093 | return self.fakeCacheReturnResult |
| 1094 | |
| 1095 | mock_cmd_exec = mock.Mock(spec=command_executer.CommandExecuter) |
| 1096 | fake_result = Result(self.mock_logger, self.mock_label, 'average', |
| 1097 | mock_cmd_exec) |
| 1098 | fake_result.retval = 0 |
| 1099 | |
| 1100 | # Set up results_cache _GetCacheDirFor{Read,Write} to return |
| 1101 | # self.fakeCacheReturnResult, which is initially None (see above). |
| 1102 | # So initially, no cache dir is returned. |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 1103 | self.results_cache.GetCacheDirForRead = FakeGetCacheDirForRead |
| 1104 | self.results_cache.GetCacheDirForWrite = FakeGetCacheDirForWrite |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1105 | |
| 1106 | mock_isdir.return_value = True |
| 1107 | save_cc = [CacheConditions.CACHE_FILE_EXISTS, |
| 1108 | CacheConditions.CHECKSUMS_MATCH] |
| 1109 | self.results_cache.cache_conditions.append(CacheConditions.FALSE) |
| 1110 | |
| 1111 | # Test 1. CacheCondition.FALSE, which means do not read from the cache. |
| 1112 | # (force re-running of test). Result should be None. |
| 1113 | res = self.results_cache.ReadResult() |
| 1114 | self.assertIsNone(res) |
| 1115 | self.assertEqual(mock_runcmd.call_count, 1) |
| 1116 | |
| 1117 | # Test 2. Remove CacheCondition.FALSE. Result should still be None, |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 1118 | # because GetCacheDirForRead is returning None at the moment. |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1119 | mock_runcmd.reset_mock() |
| 1120 | self.results_cache.cache_conditions = save_cc |
| 1121 | res = self.results_cache.ReadResult() |
| 1122 | self.assertIsNone(res) |
| 1123 | self.assertEqual(mock_runcmd.call_count, 0) |
| 1124 | |
Yunlian Jiang | 655dfa3 | 2015-12-30 09:12:09 -0800 | [diff] [blame] | 1125 | # Test 3. Now set up cache dir to be returned by GetCacheDirForRead. |
cmtice | c490e07 | 2014-06-13 15:38:45 -0700 | [diff] [blame] | 1126 | # Since cache_dir is found, will call Result.CreateFromCacheHit, which |
| 1127 | # which will actually all our mock_create and should return fake_result. |
| 1128 | self.fakeCacheReturnResult = 'fake/cache/dir' |
| 1129 | mock_create.return_value = fake_result |
| 1130 | res = self.results_cache.ReadResult() |
| 1131 | self.assertEqual(mock_runcmd.call_count, 0) |
| 1132 | self.assertEqual(res, fake_result) |
| 1133 | |
| 1134 | # Test 4. os.path.isdir(cache_dir) will now return false, so result |
| 1135 | # should be None again (no cache found). |
| 1136 | mock_isdir.return_value = False |
| 1137 | res = self.results_cache.ReadResult() |
| 1138 | self.assertEqual(mock_runcmd.call_count, 0) |
| 1139 | self.assertIsNone(res) |
| 1140 | |
| 1141 | # Test 5. os.path.isdir returns true, but mock_create now returns None |
| 1142 | # (the call to CreateFromCacheHit returns None), so overal result is None. |
| 1143 | mock_isdir.return_value = True |
| 1144 | mock_create.return_value = None |
| 1145 | res = self.results_cache.ReadResult() |
| 1146 | self.assertEqual(mock_runcmd.call_count, 0) |
| 1147 | self.assertIsNone(res) |
| 1148 | |
| 1149 | # Test 6. Everything works 'as expected', result should be fake_result. |
| 1150 | mock_create.return_value = fake_result |
| 1151 | res = self.results_cache.ReadResult() |
| 1152 | self.assertEqual(mock_runcmd.call_count, 0) |
| 1153 | self.assertEqual(res, fake_result) |
| 1154 | |
| 1155 | # Test 7. The run failed; result should be None. |
| 1156 | mock_create.return_value = fake_result |
| 1157 | fake_result.retval = 1 |
| 1158 | self.results_cache.cache_conditions.append(CacheConditions.RUN_SUCCEEDED) |
| 1159 | res = self.results_cache.ReadResult() |
| 1160 | self.assertEqual(mock_runcmd.call_count, 0) |
| 1161 | self.assertIsNone(res) |
| 1162 | |
| 1163 | |
| 1164 | if __name__ == '__main__': |
Yunlian Jiang | 4578ec1 | 2013-05-22 14:54:39 -0700 | [diff] [blame] | 1165 | unittest.main() |