results_cache_unittest.py revision 4578ec10ee49f6341cc840c5ea41b1899af4caff
1#!/usr/bin/python
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
7import unittest
8
9from utils import logger
10
11from results_cache import Result
12from results_cache import ResultsCache
13import mock_instance
14
15output = """CMD (True): ./run_remote_tests.sh --remote=172.17.128.241  --board=lumpy   LibCBench
16CMD (None): cd /usr/local/google/home/yunlian/gd/src/build/images/lumpy/latest/../../../../..; cros_sdk  -- ./in_chroot_cmd6X7Cxu.sh
17Identity added: /tmp/run_remote_tests.PO1234567/autotest_key (/tmp/run_remote_tests.PO1234567/autotest_key)
18INFO    : Using emerged autotests already installed at /build/lumpy/usr/local/autotest.
19
20INFO    : Running the following control files 1 times:
21INFO    :  * 'client/site_tests/platform_LibCBench/control'
22
23INFO    : Running client test client/site_tests/platform_LibCBench/control
24./server/autoserv -m 172.17.128.241 --ssh-port 22 -c client/site_tests/platform_LibCBench/control -r /tmp/run_remote_tests.PO1234567/platform_LibCBench --test-retry=0 --args
25ERROR:root:import statsd failed, no stats will be reported.
2614:20:22 INFO | Results placed in /tmp/run_remote_tests.PO1234567/platform_LibCBench
2714:20:22 INFO | Processing control file
2814: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'
2914:20:23 ERROR| [stderr] Warning: Permanently added '172.17.128.241' (RSA) to the list of known hosts.
3014:20:23 INFO | INFO	----	----	kernel=3.8.11	localtime=May 22 14:20:23	timestamp=1369257623
3114:20:23 INFO | Installing autotest on 172.17.128.241
3214:20:23 INFO | Using installation dir /usr/local/autotest
3314:20:23 WARNI| No job_repo_url for <remote host: 172.17.128.241>
3414:20:23 INFO | Could not install autotest using the packaging system: No repos to install an autotest client from. Trying other methods
3514:20:23 INFO | Installation of autotest completed
3614:20:24 WARNI| No job_repo_url for <remote host: 172.17.128.241>
3714:20:24 INFO | Executing /usr/local/autotest/bin/autotest /usr/local/autotest/control phase 0
3814:20:24 INFO | Entered autotestd_monitor.
3914:20:24 INFO | Finished launching tail subprocesses.
4014:20:24 INFO | Finished waiting on autotestd to start.
4114:20:26 INFO | START	----	----	timestamp=1369257625	localtime=May 22 14:20:25
4214:20:26 INFO | 	START	platform_LibCBench	platform_LibCBench	timestamp=1369257625	localtime=May 22 14:20:25
4314:20:30 INFO | 		GOOD	platform_LibCBench	platform_LibCBench	timestamp=1369257630	localtime=May 22 14:20:30	completed successfully
4414:20:30 INFO | 	END GOOD	platform_LibCBench	platform_LibCBench	timestamp=1369257630	localtime=May 22 14:20:30
4514:20:31 INFO | END GOOD	----	----	timestamp=1369257630	localtime=May 22 14:20:30
4614:20:31 INFO | Got lock of exit_code_file.
4714:20:31 INFO | Released lock of exit_code_file and closed it.
48OUTPUT: ==============================
49OUTPUT: Current time: 2013-05-22 14:20:32.818831 Elapsed: 0:01:30 ETA: Unknown
50Done: 0% [                                                  ]
51OUTPUT: Thread Status:
52RUNNING:  1 ('ttt: LibCBench (1)' 0:01:21)
53Machine Status:
54Machine                        Thread     Lock Status                    Checksum
55172.17.128.241                 ttt: LibCBench (1) True RUNNING                   3ba9f2ecbb222f20887daea5583d86ba
56
57OUTPUT: ==============================
5814:20:33 INFO | Killing child processes.
5914:20:33 INFO | Client complete
6014:20:33 INFO | Finished processing control file
6114: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'
6214:20:33 ERROR| [stderr] Warning: Permanently added '172.17.128.241' (RSA) to the list of known hosts.
63
64INFO    : Test results:
65-------------------------------------------------------------------
66platform_LibCBench                                      [  PASSED  ]
67platform_LibCBench/platform_LibCBench                   [  PASSED  ]
68platform_LibCBench/platform_LibCBench                     b_malloc_big1__0_                                     0.00375231466667
69platform_LibCBench/platform_LibCBench                     b_malloc_big2__0_                                     0.002951359
70platform_LibCBench/platform_LibCBench                     b_malloc_bubble__0_                                   0.015066374
71platform_LibCBench/platform_LibCBench                     b_malloc_sparse__0_                                   0.015053784
72platform_LibCBench/platform_LibCBench                     b_malloc_thread_local__0_                             0.01138439
73platform_LibCBench/platform_LibCBench                     b_malloc_thread_stress__0_                            0.0367894733333
74platform_LibCBench/platform_LibCBench                     b_malloc_tiny1__0_                                    0.000768474333333
75platform_LibCBench/platform_LibCBench                     b_malloc_tiny2__0_                                    0.000581407333333
76platform_LibCBench/platform_LibCBench                     b_pthread_create_serial1__0_                          0.0291785246667
77platform_LibCBench/platform_LibCBench                     b_pthread_createjoin_serial1__0_                      0.031907936
78platform_LibCBench/platform_LibCBench                     b_pthread_createjoin_serial2__0_                      0.043485347
79platform_LibCBench/platform_LibCBench                     b_pthread_uselesslock__0_                             0.0294113346667
80platform_LibCBench/platform_LibCBench                     b_regex_compile____a_b_c__d_b__                       0.00529833933333
81platform_LibCBench/platform_LibCBench                     b_regex_search____a_b_c__d_b__                        0.00165455066667
82platform_LibCBench/platform_LibCBench                     b_regex_search___a_25_b__                             0.0496191923333
83platform_LibCBench/platform_LibCBench                     b_stdio_putcgetc__0_                                  0.100005711667
84platform_LibCBench/platform_LibCBench                     b_stdio_putcgetc_unlocked__0_                         0.0371443833333
85platform_LibCBench/platform_LibCBench                     b_string_memset__0_                                   0.00275405066667
86platform_LibCBench/platform_LibCBench                     b_string_strchr__0_                                   0.00456903
87platform_LibCBench/platform_LibCBench                     b_string_strlen__0_                                   0.044893587
88platform_LibCBench/platform_LibCBench                     b_string_strstr___aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac__ 0.118360778
89platform_LibCBench/platform_LibCBench                     b_string_strstr___aaaaaaaaaaaaaaaaaaaaaaaaac__        0.068957325
90platform_LibCBench/platform_LibCBench                     b_string_strstr___aaaaaaaaaaaaaacccccccccccc__        0.0135694476667
91platform_LibCBench/platform_LibCBench                     b_string_strstr___abcdefghijklmnopqrstuvwxyz__        0.0134553343333
92platform_LibCBench/platform_LibCBench                     b_string_strstr___azbycxdwevfugthsirjqkplomn__        0.0133123556667
93platform_LibCBench/platform_LibCBench                     b_utf8_bigbuf__0_                                     0.0473772253333
94platform_LibCBench/platform_LibCBench                     b_utf8_onebyone__0_                                   0.130938538333
95-------------------------------------------------------------------
96Total PASS: 2/2 (100%)
97
98INFO    : Elapsed time: 0m16s
99"""
100
101error = """
102ERROR: Identity added: /tmp/run_remote_tests.Z4Ld/autotest_key (/tmp/run_remote_tests.Z4Ld/autotest_key)
103INFO    : Using emerged autotests already installed at /build/lumpy/usr/local/autotest.
104INFO    : Running the following control files 1 times:
105INFO    :  * 'client/site_tests/platform_LibCBench/control'
106INFO    : Running client test client/site_tests/platform_LibCBench/control
107INFO    : Test results:
108INFO    : Elapsed time: 0m18s
109"""
110
111
112keyvals = {'': 'PASS', 'b_stdio_putcgetc__0_': '0.100005711667', 'b_string_strstr___azbycxdwevfugthsirjqkplomn__': '0.0133123556667', 'b_malloc_thread_local__0_': '0.01138439', 'b_string_strlen__0_': '0.044893587', 'b_malloc_sparse__0_': '0.015053784', 'b_string_memset__0_': '0.00275405066667', 'platform_LibCBench': 'PASS', 'b_pthread_uselesslock__0_': '0.0294113346667', 'b_string_strchr__0_': '0.00456903', 'b_pthread_create_serial1__0_': '0.0291785246667', 'b_string_strstr___aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac__': '0.118360778', 'b_string_strstr___aaaaaaaaaaaaaacccccccccccc__': '0.0135694476667', 'b_pthread_createjoin_serial1__0_': '0.031907936', 'b_malloc_thread_stress__0_': '0.0367894733333', 'b_regex_search____a_b_c__d_b__': '0.00165455066667', 'b_malloc_bubble__0_': '0.015066374', 'b_malloc_big2__0_': '0.002951359', 'b_stdio_putcgetc_unlocked__0_': '0.0371443833333', 'b_pthread_createjoin_serial2__0_': '0.043485347', 'b_regex_search___a_25_b__': '0.0496191923333', 'b_utf8_bigbuf__0_': '0.0473772253333', 'b_malloc_big1__0_': '0.00375231466667', 'b_regex_compile____a_b_c__d_b__': '0.00529833933333', 'b_string_strstr___aaaaaaaaaaaaaaaaaaaaaaaaac__': '0.068957325', 'b_malloc_tiny2__0_': '0.000581407333333', 'b_utf8_onebyone__0_': '0.130938538333', 'b_malloc_tiny1__0_': '0.000768474333333', 'b_string_strstr___abcdefghijklmnopqrstuvwxyz__': '0.0134553343333'}
113
114class MockResult(Result):
115
116  def __init__(self, chromeos_root, logger, label_name):
117    super(MockResult, self).__init__(chromeos_root, logger, label_name)
118
119  def _FindFilesInResultsDir(self, find_args):
120    return ""
121
122  def _GetKeyvals(self):
123    return keyvals
124
125
126class ResultTest(unittest.TestCase):
127  def testCreateFromRun(self):
128    result = MockResult.CreateFromRun(logger.GetLogger(), "/tmp", "lumpy",
129                                  "test1", output, error, 0)
130    self.assertEqual(result.keyvals, keyvals)
131    self.assertEqual(result.chroot_results_dir, "/tmp/run_remote_tests.PO1234567/platform_LibCBench")
132    self.assertEqual(result.results_dir, "/tmp/chroot/tmp/run_remote_tests.PO1234567/platform_LibCBench")
133    self.assertEqual(result.retval, 0)
134
135if __name__ == "__main__":
136  unittest.main()
137