Skip to content

Commit

Permalink
Fix running tests (#598)
Browse files Browse the repository at this point in the history
* test: Fix missing testlog

```console
$ cd test && python3 all_tests.py
Traceback (most recent call last):
  File "…/pyelftools/test/all_tests.py", line 29, in <module>
    sys.exit(main())
             ^^^^^^
  File "…/pyelftools/test/all_tests.py", line 21, in main
    testlog.error('Error: Please run me from the root dir of pyelftools!')
    ^^^^^^^
NameError: name 'testlog' is not defined
```

Signed-off-by: Philipp Hahn <phahn-oss@avm.de>

* test: Run test with locale C

Otherwise the output of `readelf` might be translated and comparison
with the English output from `readelf.py` will fail.

```console
$ LC_ALL=de_DE.UTF-8 ./test/run_readelf_tests.py
Test file 'test/testfiles_for_readelf/aarch64-pac-bti.elf'
.......................FAIL
....for file test/testfiles_for_readelf/aarch64-pac-bti.elf
....for option "-e"
....Output #1 is readelf, Output #2 is pyelftools
@@ Mismatch on line #0:
>>elf-header:<<
>>elf header:<<
 ([('equal', 0, 3, 0, 3), ('replace', 3, 4, 3, 4), ('equal', 4, 11, 4, 11)])
```

Signed-off-by: Philipp Hahn <phahn-oss@avm.de>

---------

Signed-off-by: Philipp Hahn <phahn-oss@avm.de>
  • Loading branch information
pmhahn authored Feb 24, 2025
1 parent 96d64eb commit aad8631
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 1 addition & 2 deletions test/all_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def run_test_script(path, *args):

def main():
if not is_in_rootdir():
testlog.error('Error: Please run me from the root dir of pyelftools!')
return 1
sys.exit('Error: Please run me from the root dir of pyelftools!')
run_test_script('test/run_all_unittests.py')
run_test_script('test/run_examples_test.py')
run_test_script('test/run_readelf_tests.py', '--parallel')
Expand Down
3 changes: 2 additions & 1 deletion test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def run_exe(exe_path, args=[], echo=False):
popen_cmd.insert(0, sys.executable)
if echo:
print('[cmd]', ' '.join(popen_cmd))
proc = subprocess.Popen(popen_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
env = dict(os.environ, LC_ALL="C")
proc = subprocess.Popen(popen_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
proc_stdout = proc.communicate()[0]
return proc.returncode, proc_stdout.decode('latin-1')

Expand Down

0 comments on commit aad8631

Please sign in to comment.