Skip to content

Commit

Permalink
test cases/linuxlike/14 static dynamic linkage: fixing Cygwin
Browse files Browse the repository at this point in the history
  • Loading branch information
dememax committed Oct 30, 2024
1 parent 46e9e5b commit 78a74fd
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions test cases/linuxlike/14 static dynamic linkage/verify_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import sys
import argparse

def handle_common(path, is_static):
"""Handle the common case."""
def check_zlib_symbol_common(path, is_static):
"""Tests if the binary contains zlibVersion symbol (non-Cygwin version)."""
try:
sym_opt = '--defined-only' if is_static else '--undefined-only'
output = subprocess.check_output(['nm', sym_opt, '-P', '-A', path]).decode('utf-8')
Expand All @@ -21,13 +21,15 @@ def handle_common(path, is_static):
return 0
return 1

def handle_cygwin(path, is_static):
"""Handle the Cygwin case."""
def check_zlib_symbol_cygwin(path, is_static):
"""Tests if the binary contains zlibVersion symbol (Cygwin case)."""
output = subprocess.check_output(['nm', path]).decode('utf-8')
# TODO: Dynamic test!
print(f"handle_cygwin(path={path}, is_static={is_static}): {output!r}")
if (('I __imp_zlibVersion' in output) or ('D __imp_zlibVersion' in output)):
return 1
# No matter static or dynamic, the name must exist in nm output
if ' zlibVersion' not in output:
return 2
is_dynamic = ('I __imp_zlibVersion' in output) or ('D __imp_zlibVersion' in output)
if is_dynamic == is_static: # expected/got mismatch?
return 3
return 0

def main():
Expand All @@ -38,9 +40,9 @@ def main():
parser.add_argument('-s', '--static', action='store_true', default=False)
args = parser.parse_args()
if args.platform == 'cygwin':
return handle_cygwin(args.path, args.static)
return check_zlib_symbol_cygwin(args.path, args.static)
else:
return handle_common(args.path, args.static)
return check_zlib_symbol_common(args.path, args.static)


if __name__ == '__main__':
Expand Down

0 comments on commit 78a74fd

Please sign in to comment.