Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import shutil, tempfile |
| 4 | import sys |
| 5 | import os |
| 6 | import imp |
| 7 | import unittest |
| 8 | try: |
| 9 | from oeqa.utils.commands import get_bb_var |
| 10 | except ImportError: |
| 11 | pass |
| 12 | |
| 13 | # module under test |
| 14 | module_file_name = "ext-sdk-prepare.py" |
| 15 | module_path = "" |
| 16 | |
| 17 | class ExtSdkPrepareTest(unittest.TestCase): |
| 18 | |
| 19 | """ unit test for fix for Yocto #9019 """ |
| 20 | |
| 21 | @classmethod |
| 22 | def setUpClass(self): |
| 23 | # copy module under test to temp dir |
| 24 | self.test_dir = tempfile.mkdtemp() |
| 25 | module_dest_path = os.path.join(self.test_dir, module_file_name) |
| 26 | try: |
| 27 | shutil.copy(module_path, self.test_dir) |
| 28 | # load module under test |
| 29 | self.test_mod = imp.load_source("", module_dest_path) |
| 30 | except: |
| 31 | print "error: unable to copy or load %s [src: %s, dst: %s]" % \ |
| 32 | (module_file_name, module_path, module_dest_path) |
| 33 | sys.exit(1) |
| 34 | |
| 35 | def test_prepare_unexpected(self): |
| 36 | # test data |
| 37 | # note: pathnames have been truncated from the actual bitbake |
| 38 | # output as they are not important for the test. |
| 39 | test_data = ( |
| 40 | 'NOTE: Running noexec task 9 of 6539 (ID: 28, quilt/quilt-native_0.64.bb, do_build)\n' |
| 41 | 'NOTE: Running task 10 of 6539 (ID: 29, quilt/quilt-native_0.64.bb, do_package)\n' |
| 42 | 'NOTE: Running task 11 of 6539 (ID: 30, quilt/quilt-native_0.64.bb, do_rm_work)\n' |
| 43 | 'NOTE: Running noexec task 6402 of 6539 (ID: 1, images/core-image-sato.bb, do_patch)\n' |
| 44 | 'NOTE: Running task 6538 of 6539 (ID: 14, images/core-image-sato.bb, do_rm_work)\n' |
| 45 | ) |
| 46 | # expected warning output |
| 47 | expected = [ (' task 10 of 6539 (ID: 29, quilt/quilt-native_0.64.bb, do_package)') ] |
| 48 | # recipe to test, matching test input data |
| 49 | recipes = [ "core-image-sato.bb" ] |
| 50 | |
| 51 | # run the test |
| 52 | output = self.test_mod.check_unexpected(test_data, recipes) |
| 53 | self.assertEqual(output, expected) |
| 54 | |
| 55 | @classmethod |
| 56 | def tearDownClass(self): |
| 57 | # remove temp dir |
| 58 | shutil.rmtree(self.test_dir) |
| 59 | |
| 60 | if __name__ == '__main__': |
| 61 | # running from command line - i.e., not under oe-selftest |
| 62 | # directory containing module under test comes from command line |
| 63 | if len(sys.argv) == 2 and os.path.isdir(sys.argv[1]): |
| 64 | module_path = os.path.join(sys.argv[1], module_file_name) |
| 65 | suite = unittest.TestLoader().loadTestsFromTestCase(ExtSdkPrepareTest) |
| 66 | unittest.TextTestRunner().run(suite) |
| 67 | else: |
| 68 | progname = os.path.basename(sys.argv[0]) |
| 69 | print "%s: missing directory path" % progname |
| 70 | print "usage: %s /path/to/directory-of(ext-sdk-prepare.py)" % progname |
| 71 | sys.exit(1) |
| 72 | else: |
| 73 | # running under oe-selftest |
| 74 | # determine module source dir from COREBASE and expected path |
| 75 | module_path = os.path.join(get_bb_var("COREBASE"), "meta", "files", module_file_name) |