OLD | NEW |
1 #!/usr/bin/python -tt | 1 #!/usr/bin/python -tt |
2 # | 2 # |
3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Unit tests for bmpblk_utility. | 7 """Unit tests for bmpblk_utility. |
8 """ | 8 """ |
9 | 9 |
10 import os | 10 import os |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 self.assertEqual(0, rc) | 66 self.assertEqual(0, rc) |
67 | 67 |
68 def tearDown(self): | 68 def tearDown(self): |
69 rc, out, err = runprog('/bin/rm', '-rf', './FOO_DIR', 'FOO') | 69 rc, out, err = runprog('/bin/rm', '-rf', './FOO_DIR', 'FOO') |
70 self.assertEqual(0, rc) | 70 self.assertEqual(0, rc) |
71 | 71 |
72 | 72 |
73 class TestPackUnpack(unittest.TestCase): | 73 class TestPackUnpack(unittest.TestCase): |
74 | 74 |
75 def setUp(self): | 75 def setUp(self): |
| 76 self._cwd = os.getcwd() |
76 rc, out, err = runprog('/bin/rm', '-rf', './FOO_DIR', 'FOO') | 77 rc, out, err = runprog('/bin/rm', '-rf', './FOO_DIR', 'FOO') |
77 self.assertEqual(0, rc) | 78 self.assertEqual(0, rc) |
78 | 79 |
79 def testPackUnpack(self): | 80 def testPackUnpack(self): |
80 """Create, unpack, recreate without compression""" | 81 """Create, unpack, recreate without compression""" |
81 rc, out, err = runprog(prog, '-c', 'case_simple.yaml', 'FOO') | 82 rc, out, err = runprog(prog, '-c', 'case_simple.yaml', 'FOO') |
82 self.assertEqual(0, rc) | 83 self.assertEqual(0, rc) |
83 rc, out, err = runprog(prog, '-x', '-d', './FOO_DIR', 'FOO') | 84 rc, out, err = runprog(prog, '-x', '-d', './FOO_DIR', 'FOO') |
84 self.assertEqual(0, rc) | 85 self.assertEqual(0, rc) |
85 os.chdir('./FOO_DIR') | 86 os.chdir('./FOO_DIR') |
(...skipping 17 matching lines...) Expand all Loading... |
103 os.chdir('..') | 104 os.chdir('..') |
104 | 105 |
105 def testPackUnpackZ1(self): | 106 def testPackUnpackZ1(self): |
106 """Create, unpack, recreate with EFIv1 compression""" | 107 """Create, unpack, recreate with EFIv1 compression""" |
107 self.doPackUnpackZ('1'); | 108 self.doPackUnpackZ('1'); |
108 | 109 |
109 def testPackUnpackZ2(self): | 110 def testPackUnpackZ2(self): |
110 """Create, unpack, recreate with LZMA compression""" | 111 """Create, unpack, recreate with LZMA compression""" |
111 self.doPackUnpackZ('2'); | 112 self.doPackUnpackZ('2'); |
112 | 113 |
| 114 def doPackUnpackImplicitZ(self, comp, noncomp): |
| 115 """Create with given compression, unpack, repack without specifying""" |
| 116 # create with the specified compression scheme |
| 117 rc, out, err = runprog(prog, '-z', comp, '-c', 'case_simple.yaml', 'FOO') |
| 118 self.assertEqual(0, rc) |
| 119 # unpack. yaml file should have compression scheme in it |
| 120 rc, out, err = runprog(prog, '-f', '-x', '-d', './FOO_DIR', 'FOO') |
| 121 self.assertEqual(0, rc) |
| 122 os.chdir('./FOO_DIR') |
| 123 # create with no compression specified, should use default from yaml |
| 124 rc, out, err = runprog(prog, '-c', 'config.yaml', 'BAR') |
| 125 self.assertEqual(0, rc) |
| 126 # so new output should match original |
| 127 rc, out, err = runprog('/usr/bin/cmp', '../FOO', 'BAR') |
| 128 self.assertEqual(0, rc) |
| 129 # Now make sure that specifying a compression arg will override the default |
| 130 for mycomp in noncomp: |
| 131 # create with compression scheme different from default |
| 132 rc, out, err = runprog(prog, '-z', str(mycomp), '-c', 'config.yaml', 'BAR'
) |
| 133 self.assertEqual(0, rc) |
| 134 # should be different binary |
| 135 rc, out, err = runprog('/usr/bin/cmp', '../FOO', 'BAR') |
| 136 self.assertNotEqual(0, rc) |
| 137 os.chdir('..') |
| 138 |
| 139 def testPackUnpackImplicitZ(self): |
| 140 """Create, unpack, recreate with implicit compression""" |
| 141 self._allowed = range(3) |
| 142 for c in self._allowed: |
| 143 self.doPackUnpackImplicitZ(str(c), [x for x in self._allowed if x != c]) |
| 144 |
113 def tearDown(self): | 145 def tearDown(self): |
| 146 os.chdir(self._cwd) |
114 rc, out, err = runprog('/bin/rm', '-rf', './FOO_DIR', 'FOO') | 147 rc, out, err = runprog('/bin/rm', '-rf', './FOO_DIR', 'FOO') |
115 self.assertEqual(0, rc) | 148 self.assertEqual(0, rc) |
116 | 149 |
117 | 150 |
118 class TestReproducable(unittest.TestCase): | 151 class TestReproducable(unittest.TestCase): |
119 | 152 |
120 def setUp(self): | 153 def setUp(self): |
121 rc, out, err = runprog('/bin/rm', '-f', 'ORDER1', 'ORDER2') | 154 rc, out, err = runprog('/bin/rm', '-f', 'ORDER1', 'ORDER2') |
122 self.assertEqual(0, rc) | 155 self.assertEqual(0, rc) |
123 | 156 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 if __name__ == '__main__': | 195 if __name__ == '__main__': |
163 varname = 'BMPBLK' | 196 varname = 'BMPBLK' |
164 if varname not in os.environ: | 197 if varname not in os.environ: |
165 print('You must specify the path to bmpblk_utility in the $%s ' | 198 print('You must specify the path to bmpblk_utility in the $%s ' |
166 'environment variable.' % varname) | 199 'environment variable.' % varname) |
167 sys.exit(1) | 200 sys.exit(1) |
168 prog = os.environ[varname] | 201 prog = os.environ[varname] |
169 print "Testing prog...", prog | 202 print "Testing prog...", prog |
170 unittest.main() | 203 unittest.main() |
171 | 204 |
OLD | NEW |