From: Eli Bendersky Date: Sat, 17 Sep 2011 04:13:49 +0000 (+0300) Subject: the beginnings of a test harness X-Git-Tag: v0.10~117 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3bad293d5ce6165493131e60c227f9cc910849fc;p=pyelftools.git the beginnings of a test harness --- diff --git a/tests/run_tests.py b/tests/run_tests.py new file mode 100755 index 0000000..b86b3bf --- /dev/null +++ b/tests/run_tests.py @@ -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 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 index 0000000..5ce4182 Binary files /dev/null and b/tests/testfiles/z32.o.elf differ