summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2011-02-07 15:39:45 -0800
committerBill Richardson <wfrichar@chromium.org>2011-02-07 15:39:45 -0800
commit856e072e8119cab07fd884e54853f1c3897452ee (patch)
treef85b3811617f5f0d8ed6ac87d15c00cfb0a8f34e
parentbce044dee3d18fcd0ba559616a3767187b06aa8d (diff)
downloadvboot-856e072e8119cab07fd884e54853f1c3897452ee.tar.gz
Add test framework for bmpblk_utility.
BUG=chromium-os:11742 TEST=manual Check out sources, run: cd src/platform/vboot_reference make make runbmptests It should pass. Change-Id: I50ebdef26662e7446828315a3f5e2786624508b9 Review URL: http://codereview.chromium.org/6246150
-rw-r--r--Makefile3
-rw-r--r--tests/Makefile8
-rw-r--r--tests/bitmaps/Makefile8
-rw-r--r--tests/bitmaps/NotReallyA.bmpbin0 -> 1024 bytes
-rwxr-xr-xtests/bitmaps/TestBmpBlock.py49
-rw-r--r--tests/bitmaps/case_badbmp.yaml19
-rw-r--r--tests/bitmaps/case_nobmp.yaml19
-rw-r--r--utility/bmpblk_utility.cc4
8 files changed, 107 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 0d29bd50..d12639d0 100644
--- a/Makefile
+++ b/Makefile
@@ -77,3 +77,6 @@ runtests:
rbtest:
$(MAKE) -C tests rbtest
+
+runbmptests:
+ $(MAKE) -C tests runbmptests
diff --git a/tests/Makefile b/tests/Makefile
index 5c0e2e26..17da312b 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -94,7 +94,13 @@ runmisctests:
runfuzztests:
./gen_fuzz_test_cases.sh
-runtests: genkeys runcgpttests runcryptotests runmisctests runfuzztests
+# Run bmpblk_utility tests
+runbmptests:
+ $(MAKE) BUILD=$(shell readlink -f ${BUILD}) -C bitmaps runtests
+
+ALLTESTS=runcgpttests runcryptotests runmisctests runfuzztests runbmptests
+
+runtests: genkeys ${ALLTESTS}
# TODO: tests to run when ported to new API
# ./run_image_verification_tests.sh
diff --git a/tests/bitmaps/Makefile b/tests/bitmaps/Makefile
new file mode 100644
index 00000000..0d200ad6
--- /dev/null
+++ b/tests/bitmaps/Makefile
@@ -0,0 +1,8 @@
+# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+export BMPBLK=${BUILD}/utility/bmpblk_utility
+
+runtests:
+ ./TestBmpBlock.py -v
diff --git a/tests/bitmaps/NotReallyA.bmp b/tests/bitmaps/NotReallyA.bmp
new file mode 100644
index 00000000..1662526e
--- /dev/null
+++ b/tests/bitmaps/NotReallyA.bmp
Binary files differ
diff --git a/tests/bitmaps/TestBmpBlock.py b/tests/bitmaps/TestBmpBlock.py
new file mode 100755
index 00000000..9abe72df
--- /dev/null
+++ b/tests/bitmaps/TestBmpBlock.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python -tt
+
+"""Unit tests for bmpblk_utility.
+"""
+
+import os
+import sys
+import subprocess
+import unittest
+
+def runprog(*args):
+ """Runs specified program and args, returns (exitcode, stdout, stderr)."""
+ p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ out, err = p.communicate()
+ return (p.returncode, out, err)
+
+
+class TestBmpBlock(unittest.TestCase):
+
+ def testNoArgs(self):
+ """Running with no args should print usage and fail."""
+ rc, out, err = runprog(prog)
+ self.assertNotEqual(0, rc)
+ self.assertTrue(out.count("Usage:"))
+
+ def testMissingBmp(self):
+ """Missing a bmp specified in the yaml is an error."""
+ rc, out, err = runprog(prog, '-c', '-C', 'case_nobmp.yaml', 'FOO')
+ self.assertNotEqual(0, rc)
+ self.assertTrue(err.count("No such file or directory"))
+
+ def testInvalidBmp(self):
+ """A .bmp file that isn't really a BMP should fail."""
+ rc, out, err = runprog(prog, '-c', '-C', 'case_badbmp.yaml', 'FOO')
+ self.assertNotEqual(0, rc)
+ self.assertTrue(err.count("Unsupported image format"))
+
+
+# Run these tests
+if __name__ == '__main__':
+ varname = 'BMPBLK'
+ if varname not in os.environ:
+ print('You must specify the path to bmpblk_utility in the $%s '
+ 'environment variable.' % varname)
+ sys.exit(1)
+ prog = os.environ[varname]
+ print "Testing prog...", prog
+ unittest.main()
+
diff --git a/tests/bitmaps/case_badbmp.yaml b/tests/bitmaps/case_badbmp.yaml
new file mode 100644
index 00000000..1222aaf8
--- /dev/null
+++ b/tests/bitmaps/case_badbmp.yaml
@@ -0,0 +1,19 @@
+# Invalid specification: requests missing image file.
+
+bmpblock: 1.0
+
+# These are the individual images which are layered to produce a screen layout.
+images:
+ devmode: NotReallyA.bmp
+
+# These are all of the distinct layouts that we know how to display.
+screens:
+ dev_en:
+ - [0, 0, devmode]
+
+
+# To customize the images for a particular locale, just reorder this list so
+# that the default language appears first.
+localizations:
+ - [ dev_en, dev_en, dev_en, dev_en ]
+
diff --git a/tests/bitmaps/case_nobmp.yaml b/tests/bitmaps/case_nobmp.yaml
new file mode 100644
index 00000000..f88b9d5e
--- /dev/null
+++ b/tests/bitmaps/case_nobmp.yaml
@@ -0,0 +1,19 @@
+# Invalid specification: requests missing image file.
+
+bmpblock: 1.0
+
+# These are the individual images which are layered to produce a screen layout.
+images:
+ devmode: NoSuchFile.bmp
+
+# These are all of the distinct layouts that we know how to display.
+screens:
+ dev_en:
+ - [0, 0, devmode]
+
+
+# To customize the images for a particular locale, just reorder this list so
+# that the default language appears first.
+localizations:
+ - [ dev_en, dev_en, dev_en, dev_en ]
+
diff --git a/utility/bmpblk_utility.cc b/utility/bmpblk_utility.cc
index 8da3e18f..a87761cb 100644
--- a/utility/bmpblk_utility.cc
+++ b/utility/bmpblk_utility.cc
@@ -338,7 +338,7 @@ void BmpBlockUtil::fill_all_image_infos() {
it->second.data.height = get_bmp_image_height(it->second.raw_content);
break;
default:
- error("Unsupported image format.");
+ error("Unsupported image format.\n");
}
}
}
@@ -355,7 +355,7 @@ void BmpBlockUtil::compress_all_images(const Compression compress) {
}
break;
default:
- error("Unsupported data compression.");
+ error("Unsupported data compression.\n");
}
}