Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(810)

Side by Side Diff: bin/ctest_unittest.py

Issue 3606008: Add ctest that calls the au test harness. (Closed) Base URL: http://git.chromium.org/git/crosutils.git
Patch Set: Remove comment Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « bin/ctest.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2010 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
7 """Unit tests for ctest."""
8
9 import ctest
10 import mox
11 import os
12 import unittest
13 import urllib
14
15 _TEST_BOOT_DESC = """
16 --arch="x86"
17 --output_dir="/home/chrome-bot/0.8.70.5-a1"
18 --espfs_mountpoint="/home/chrome-bot/0.8.70.5-a1/esp"
19 --enable_rootfs_verification
20 """
21
22 class CrosTestTest(mox.MoxTestBase):
23 """Test class for CTest."""
24
25 def setUp(self):
26 mox.MoxTestBase.setUp(self)
27 self.board = 'test-board'
28 self.channel = 'test-channel'
29 self.version = '1.2.3.4.5'
30 self.revision = '7ghfa9999-12345'
31 self.image_name = 'TestOS-%s-%s' % (self.version, self.revision)
32 self.download_folder = 'test_folder'
33 self.latestbase = 'http://test-latest/TestOS'
34 self.zipbase = 'http://test-zips/archive/TestOS'
35 self.image_url = '%s/%s/%s/%s/%s.zip' % (self.zipbase, self.channel,
36 self.board, self.version,
37 self.image_name)
38
39 def testModifyBootDesc(self):
40 """Tests to make sure we correctly modify a boot desc."""
41 in_chroot_path = ctest.ReinterpretPathForChroot(os.path.abspath(
42 self.download_folder))
43 self.mox.StubOutWithMock(__builtins__, 'open')
44 self.mox.StubOutWithMock(ctest.fileinput, 'input')
45 m_file = self.mox.CreateMock(file)
46
47 mock_file = _TEST_BOOT_DESC.splitlines(True)
48 ctest.fileinput.input('%s/%s' % (os.path.abspath(self.download_folder),
49 'boot.desc'),
50 inplace=1).AndReturn(mock_file)
51
52 m_file.write('\n')
53 m_file.write(' --arch="x86"\n')
54 m_file.write(' --output_dir="%s"\n' % in_chroot_path)
55 m_file.write(' --espfs_mountpoint="%s/%s"\n' % (in_chroot_path, 'esp'))
56 m_file.write(' --enable_rootfs_verification\n')
57
58 self.mox.ReplayAll()
59 ctest.ModifyBootDesc(os.path.abspath(self.download_folder), m_file)
60 self.mox.VerifyAll()
61
62
63 def testGetLatestZipUrl(self):
64 """Test case that tests GetLatestZipUrl with test urls."""
65 self.mox.StubOutWithMock(urllib, 'urlopen')
66 m_file = self.mox.CreateMock(file)
67
68 urllib.urlopen('%s/%s/LATEST-%s' % (self.latestbase, self.channel,
69 self.board)).AndReturn(m_file)
70 m_file.read().AndReturn('%s.bin.gz' % self.image_name)
71 m_file.close()
72
73 self.mox.ReplayAll()
74 self.assertEquals(ctest.GetLatestZipUrl(self.board, self.channel,
75 self.latestbase, self.zipbase),
76 self.image_url)
77 self.mox.VerifyAll()
78
79 def testGrabZipAndExtractImageUseCached(self):
80 """Test case where cache holds our image."""
81 self.mox.StubOutWithMock(os.path, 'exists')
82 self.mox.StubOutWithMock(__builtins__, 'open')
83 m_file = self.mox.CreateMock(file)
84
85 os.path.exists('%s/%s' % (
86 self.download_folder, 'download_url')).AndReturn(True)
87
88 open('%s/%s' % (self.download_folder, 'download_url')).AndReturn(m_file)
89 m_file.read().AndReturn(self.image_url)
90 m_file.close()
91
92 os.path.exists('%s/%s' % (
93 self.download_folder, ctest._IMAGE_TO_EXTRACT)).AndReturn(True)
94
95 self.mox.ReplayAll()
96 ctest.GrabZipAndExtractImage(self.image_url, self.download_folder,
97 ctest._IMAGE_TO_EXTRACT)
98 self.mox.VerifyAll()
99
100 def CommonDownloadAndExtractImage(self):
101 """Common code to mock downloading image, unzipping it and setting url."""
102 zip_path = os.path.join(self.download_folder, 'image.zip')
103 m_file = self.mox.CreateMock(file)
104
105 ctest.RunCommand(['rm', '-rf', self.download_folder], print_cmd=False)
106 os.mkdir(self.download_folder)
107 urllib.urlretrieve(self.image_url, zip_path)
108 ctest.RunCommand(['unzip', '-d', self.download_folder, zip_path],
109 print_cmd=False, error_message=mox.IgnoreArg())
110
111 ctest.ModifyBootDesc(self.download_folder)
112
113 open('%s/%s' % (self.download_folder, 'download_url'),
114 'w+').AndReturn(m_file)
115 m_file.write(self.image_url)
116 m_file.close()
117
118 self.mox.ReplayAll()
119 ctest.GrabZipAndExtractImage(self.image_url, self.download_folder,
120 ctest._IMAGE_TO_EXTRACT)
121 self.mox.VerifyAll()
122
123 def testGrabZipAndExtractImageNoCache(self):
124 """Test case where download_url doesn't exist."""
125 self.mox.StubOutWithMock(os.path, 'exists')
126 self.mox.StubOutWithMock(os, 'mkdir')
127 self.mox.StubOutWithMock(__builtins__, 'open')
128 self.mox.StubOutWithMock(ctest, 'RunCommand')
129 self.mox.StubOutWithMock(urllib, 'urlretrieve')
130 self.mox.StubOutWithMock(ctest, 'ModifyBootDesc')
131
132 m_file = self.mox.CreateMock(file)
133
134 os.path.exists('%s/%s' % (
135 self.download_folder, 'download_url')).AndReturn(False)
136
137 self.CommonDownloadAndExtractImage()
138
139
140 def testGrabZipAndExtractImageWrongCache(self):
141 """Test case where download_url exists but doesn't match our url."""
142 self.mox.StubOutWithMock(os.path, 'exists')
143 self.mox.StubOutWithMock(os, 'mkdir')
144 self.mox.StubOutWithMock(__builtins__, 'open')
145 self.mox.StubOutWithMock(ctest, 'RunCommand')
146 self.mox.StubOutWithMock(urllib, 'urlretrieve')
147 self.mox.StubOutWithMock(ctest, 'ModifyBootDesc')
148
149 m_file = self.mox.CreateMock(file)
150
151 os.path.exists('%s/%s' % (
152 self.download_folder, 'download_url')).AndReturn(True)
153
154 open('%s/%s' % (self.download_folder, 'download_url')).AndReturn(m_file)
155 m_file.read().AndReturn(self.image_url)
156 m_file.close()
157
158 os.path.exists('%s/%s' % (
159 self.download_folder, ctest._IMAGE_TO_EXTRACT)).AndReturn(False)
160
161 self.CommonDownloadAndExtractImage()
162
163
164 if __name__ == '__main__':
165 unittest.main()
OLDNEW
« no previous file with comments | « bin/ctest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698