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

Side by Side Diff: tests/bitmaps/TestBmpBlock.py

Issue 6508006: Enable EFIv1 compression in bmpbklk_utility. (Closed) Base URL: http://git.chromium.org/git/vboot_reference.git@master
Patch Set: Added tests, updated copyrights, moved bmpblk_util.h as suggested. Created 9 years, 10 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 | « tests/bitmaps/Background.bmp ('k') | tests/bitmaps/Word.bmp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 import sys 11 import sys
12 import subprocess 12 import subprocess
13 import unittest 13 import unittest
14 14
15 def runprog(*args): 15 def runprog(*args):
16 """Runs specified program and args, returns (exitcode, stdout, stderr).""" 16 """Runs specified program and args, returns (exitcode, stdout, stderr)."""
17 p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 17 p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
18 out, err = p.communicate() 18 out, err = p.communicate()
19 return (p.returncode, out, err) 19 return (p.returncode, out, err)
20 20
21 21
22 class TestBmpBlock(unittest.TestCase): 22 class TestFailures(unittest.TestCase):
23 23
24 def testNoArgs(self): 24 def testNoArgs(self):
25 """Running with no args should print usage and fail.""" 25 """Running with no args should print usage and fail."""
26 rc, out, err = runprog(prog) 26 rc, out, err = runprog(prog)
27 self.assertNotEqual(0, rc) 27 self.assertNotEqual(0, rc)
28 self.assertTrue(err.count("missing BMPBLOCK name")) 28 self.assertTrue(err.count("missing BMPBLOCK name"))
29 self.assertTrue(out.count("bmpblk_utility")) 29 self.assertTrue(out.count("bmpblk_utility"))
30 30
31 def testMissingBmp(self): 31 def testMissingBmp(self):
32 """Missing a bmp specified in the yaml is an error.""" 32 """Missing a bmp specified in the yaml is an error."""
33 rc, out, err = runprog(prog, '-c', 'case_nobmp.yaml', 'FOO') 33 rc, out, err = runprog(prog, '-c', 'case_nobmp.yaml', 'FOO')
34 self.assertNotEqual(0, rc) 34 self.assertNotEqual(0, rc)
35 self.assertTrue(err.count("No such file or directory")) 35 self.assertTrue(err.count("No such file or directory"))
36 36
37 def testInvalidBmp(self): 37 def testInvalidBmp(self):
38 """A .bmp file that isn't really a BMP should fail.""" 38 """A .bmp file that isn't really a BMP should fail."""
39 rc, out, err = runprog(prog, '-c', 'case_badbmp.yaml', 'FOO') 39 rc, out, err = runprog(prog, '-c', 'case_badbmp.yaml', 'FOO')
40 self.assertNotEqual(0, rc) 40 self.assertNotEqual(0, rc)
41 self.assertTrue(err.count("Unsupported image format")) 41 self.assertTrue(err.count("Unsupported image format"))
42 42
43 def testBadCompression(self):
44 """Wrong compression types should fail."""
45 rc, out, err = runprog(prog, '-z', '99', '-c', 'case_simple.yaml', 'FOO')
46 self.assertNotEqual(0, rc)
47 self.assertTrue(err.count("compression type"))
48
49
50 class TestOverWrite(unittest.TestCase):
51
52 def setUp(self):
53 rc, out, err = runprog('/bin/rm', '-rf', './FOO_DIR', 'FOO')
54 self.assertEqual(0, rc)
55
56 def testOverwrite(self):
57 """Create, unpack, unpack again, with and without -f"""
58 rc, out, err = runprog(prog, '-c', 'case_simple.yaml', 'FOO')
59 self.assertEqual(0, rc)
60 rc, out, err = runprog(prog, '-x', '-d', './FOO_DIR', 'FOO')
61 self.assertEqual(0, rc)
62 rc, out, err = runprog(prog, '-x', '-d', './FOO_DIR', 'FOO')
63 self.assertNotEqual(0, rc)
64 self.assertTrue(err.count("File exists"))
65 rc, out, err = runprog(prog, '-x', '-d', './FOO_DIR', '-f', 'FOO')
66 self.assertEqual(0, rc)
67
68 def tearDown(self):
69 rc, out, err = runprog('/bin/rm', '-rf', './FOO_DIR', 'FOO')
70 self.assertEqual(0, rc)
71
72
73 class TestPackUnpack(unittest.TestCase):
74
75 def setUp(self):
76 rc, out, err = runprog('/bin/rm', '-rf', './FOO_DIR', 'FOO')
77 self.assertEqual(0, rc)
78
79 def testPackUnpack(self):
80 """Create, unpack, recreate without compression"""
81 rc, out, err = runprog(prog, '-c', 'case_simple.yaml', 'FOO')
82 self.assertEqual(0, rc)
83 rc, out, err = runprog(prog, '-x', '-d', './FOO_DIR', 'FOO')
84 self.assertEqual(0, rc)
85 os.chdir('./FOO_DIR')
86 rc, out, err = runprog(prog, '-c', 'config.yaml', 'BAR')
87 self.assertEqual(0, rc)
88 rc, out, err = runprog('/usr/bin/cmp', '../FOO', 'BAR')
89 self.assertEqual(0, rc)
90 os.chdir('..')
91
92 def testPackUnpackZ(self):
93 """Create, unpack, recreate with explicit compression"""
94 rc, out, err = runprog(prog, '-z', '1', '-c', 'case_simple.yaml', 'FOO')
95 self.assertEqual(0, rc)
96 rc, out, err = runprog(prog, '-x', '-d', './FOO_DIR', 'FOO')
97 self.assertEqual(0, rc)
98 os.chdir('./FOO_DIR')
99 rc, out, err = runprog(prog, '-z', '1', '-c', 'config.yaml', 'BAR')
100 self.assertEqual(0, rc)
101 rc, out, err = runprog('/usr/bin/cmp', '../FOO', 'BAR')
102 self.assertEqual(0, rc)
103 os.chdir('..')
104
105 def tearDown(self):
106 rc, out, err = runprog('/bin/rm', '-rf', './FOO_DIR', 'FOO')
107 self.assertEqual(0, rc)
108
43 109
44 # Run these tests 110 # Run these tests
45 if __name__ == '__main__': 111 if __name__ == '__main__':
46 varname = 'BMPBLK' 112 varname = 'BMPBLK'
47 if varname not in os.environ: 113 if varname not in os.environ:
48 print('You must specify the path to bmpblk_utility in the $%s ' 114 print('You must specify the path to bmpblk_utility in the $%s '
49 'environment variable.' % varname) 115 'environment variable.' % varname)
50 sys.exit(1) 116 sys.exit(1)
51 prog = os.environ[varname] 117 prog = os.environ[varname]
52 print "Testing prog...", prog 118 print "Testing prog...", prog
53 unittest.main() 119 unittest.main()
54 120
OLDNEW
« no previous file with comments | « tests/bitmaps/Background.bmp ('k') | tests/bitmaps/Word.bmp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698