Skip to content

Commit

Permalink
tests: Add a unit test for checksums
Browse files Browse the repository at this point in the history
Adds a CI dependency on the `pefile` python module.
  • Loading branch information
nirbheek committed Jan 22, 2020
1 parent b293852 commit bd17c9a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
6 changes: 4 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ jobs:
displayName: Install Dependencies
- script: |
set PATH=%CYGWIN_ROOT%\bin;%SYSTEMROOT%\system32
env.exe -- python3 -m pip --disable-pip-version-check install pytest-xdist
displayName: pip install pytest-xdist
env.exe -- python3 -m pip --disable-pip-version-check install pefile pytest-xdist
displayName: pip install pefile pytest-xdist
- script: |
set BOOST_ROOT=
set PATH=%CYGWIN_ROOT%\bin;%SYSTEMROOT%\system32
Expand Down Expand Up @@ -188,7 +188,9 @@ jobs:
mingw-w64-$(MSYS2_ARCH)-python2 ^
mingw-w64-$(MSYS2_ARCH)-python3 ^
mingw-w64-$(MSYS2_ARCH)-python3-setuptools ^
mingw-w64-$(MSYS2_ARCH)-python3-pip ^
%TOOLCHAIN%
%MSYS2_ROOT%\usr\bin\bash -lc "python3 -m pip --disable-pip-version-check install pefile"
displayName: Install Dependencies
- powershell: |
# https://github.com/mesonbuild/meson/issues/5807
Expand Down
2 changes: 1 addition & 1 deletion ci/azure-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ steps:
python --version
# Needed for running unit tests in parallel.
python -m pip --disable-pip-version-check install --upgrade pytest-xdist
python -m pip --disable-pip-version-check install --upgrade pefile pytest-xdist
echo ""
Expand Down
28 changes: 28 additions & 0 deletions run_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4655,6 +4655,34 @@ def test_link_environment_variable_optlink(self):
def test_link_environment_variable_rust(self):
self._check_ld('link', 'rust', 'link')

def test_pefile_checksum(self):
try:
import pefile
except ImportError:
if is_ci():
raise
raise unittest.SkipTest('pefile module not found')
testdir = os.path.join(self.common_test_dir, '6 linkshared')
self.init(testdir)
self.build()
# Test that binaries have a non-zero checksum
env = get_fake_env()
cc = env.detect_c_compiler(MachineChoice.HOST)
cc_id = cc.get_id()
ld_id = cc.get_linker_id()
dll = glob(os.path.join(self.builddir, '*mycpplib.dll'))[0]
exe = os.path.join(self.builddir, 'cppprog.exe')
for f in (dll, exe):
pe = pefile.PE(f)
msg = 'PE file: {!r}, compiler: {!r}, linker: {!r}'.format(f, cc_id, ld_id)
if cc_id == 'clang-cl':
# Latest clang-cl tested (7.0) does not write checksums out
self.assertFalse(pe.verify_checksum(), msg=msg)
else:
# Verify that a valid checksum was written by all other compilers
self.assertTrue(pe.verify_checksum(), msg=msg)


@unittest.skipUnless(is_osx(), "requires Darwin")
class DarwinTests(BasePlatformTests):
'''
Expand Down

0 comments on commit bd17c9a

Please sign in to comment.