binman: Add a function to create a sample ELF file

It is useful to create an ELF file for testing purposes, with just the
right attributes used by the test. Add a function to handle this, along
with a test that it works correctly.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py
index 42d94cb..3172982 100644
--- a/tools/binman/elf_test.py
+++ b/tools/binman/elf_test.py
@@ -5,9 +5,12 @@
 # Test for the elf module
 
 import os
+import shutil
 import sys
+import tempfile
 import unittest
 
+import command
 import elf
 import test_util
 import tools
@@ -136,6 +139,23 @@
         elf.debug = False
         self.assertTrue(len(stdout.getvalue()) > 0)
 
+    def testMakeElf(self):
+        """Test for the MakeElf function"""
+        outdir = tempfile.mkdtemp(prefix='elf.')
+        expected_text = b'1234'
+        expected_data = b'wxyz'
+        elf_fname = os.path.join(outdir, 'elf')
+        bin_fname = os.path.join(outdir, 'elf')
+
+        # Make an Elf file and then convert it to a fkat binary file. This
+        # should produce the original data.
+        elf.MakeElf(elf_fname, expected_text, expected_data)
+        stdout = command.Output('objcopy', '-O', 'binary', elf_fname, bin_fname)
+        with open(bin_fname, 'rb') as fd:
+            data = fd.read()
+        self.assertEqual(expected_text + expected_data, data)
+        shutil.rmtree(outdir)
+
 
 if __name__ == '__main__':
     unittest.main()