the beginnings of a test harness
authorEli Bendersky <eliben@gmail.com>
Sat, 17 Sep 2011 04:13:49 +0000 (07:13 +0300)
committerEli Bendersky <eliben@gmail.com>
Sat, 17 Sep 2011 04:13:49 +0000 (07:13 +0300)
tests/run_tests.py [new file with mode: 0755]
tests/testfiles/z32.elf [new file with mode: 0755]
tests/testfiles/z32.o.elf [new file with mode: 0644]

diff --git a/tests/run_tests.py b/tests/run_tests.py
new file mode 100755 (executable)
index 0000000..b86b3bf
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+#-------------------------------------------------------------------------------
+# tests/run_tests.py
+#
+# Automatic test runner for elftools & readelf
+#
+# Eli Bendersky (eliben@gmail.com)
+# This code is in the public domain
+#-------------------------------------------------------------------------------
+import os, sys
+import subprocess
+
+
+def discover_testfiles(rootdir):
+    """ Discover test files in the given directory. Yield them one by one.
+    """
+    for filename in os.listdir(rootdir):
+        _, ext = os.path.splitext(filename)
+        if ext == '.elf':
+            yield os.path.join(rootdir, filename)
+
+
+def die(msg):
+    print 'Error:', msg
+    sys.exit(1)
+
+
+def is_in_rootdir():
+    """ Check whether the current dir is the root dir of pyelftools
+    """
+    dirstuff = os.listdir('.')
+    return 'tests' in dirstuff and 'elftools' in dirstuff
+    
+
+def main():
+    if not is_in_rootdir():
+        die('Please run me from the root dir of pyelftools!')
+
+
+if __name__ == '__main__':
+    main()
+    print list(discover_testfiles('tests/testfiles'))
+
+
+
diff --git a/tests/testfiles/z32.elf b/tests/testfiles/z32.elf
new file mode 100755 (executable)
index 0000000..d6b3cd1
Binary files /dev/null and b/tests/testfiles/z32.elf differ
diff --git a/tests/testfiles/z32.o.elf b/tests/testfiles/z32.o.elf
new file mode 100644 (file)
index 0000000..5ce4182
Binary files /dev/null and b/tests/testfiles/z32.o.elf differ