mirror of
https://github.com/open-quantum-safe/liboqs.git
synced 2025-12-07 00:02:12 -05:00
Switch style checks to Python test suite
This commit is contained in:
parent
91614924b6
commit
52ccd7729a
@ -16,42 +16,43 @@ jobs:
|
||||
<<: *oqsjob
|
||||
environment:
|
||||
IMAGE: dstebila/liboqs:amd64-buster-0.0.4
|
||||
SKIP_TESTS: style
|
||||
x86_64-xenial-gcc49:
|
||||
<<: *oqsjob
|
||||
environment:
|
||||
IMAGE: dstebila/liboqs:x86_64-xenial-0.0.4
|
||||
IMAGE: dstebila/liboqs:x86_64-xenial-0.0.5
|
||||
CC: gcc-4.9
|
||||
CONFIGURE_ARGS: --disable-sig-picnic
|
||||
x86_64-xenial-gcc5:
|
||||
<<: *oqsjob
|
||||
environment:
|
||||
IMAGE: dstebila/liboqs:x86_64-xenial-0.0.4
|
||||
IMAGE: dstebila/liboqs:x86_64-xenial-0.0.5
|
||||
CC: gcc-5
|
||||
x86_64-xenial-gcc6:
|
||||
<<: *oqsjob
|
||||
environment:
|
||||
IMAGE: dstebila/liboqs:x86_64-xenial-0.0.4
|
||||
IMAGE: dstebila/liboqs:x86_64-xenial-0.0.5
|
||||
CC: gcc-6
|
||||
x86_64-xenial-gcc7:
|
||||
<<: *oqsjob
|
||||
environment:
|
||||
IMAGE: dstebila/liboqs:x86_64-xenial-0.0.4
|
||||
IMAGE: dstebila/liboqs:x86_64-xenial-0.0.5
|
||||
CC: gcc-7
|
||||
x86_64-xenial-gcc8:
|
||||
<<: *oqsjob
|
||||
environment:
|
||||
IMAGE: dstebila/liboqs:x86_64-xenial-0.0.4
|
||||
IMAGE: dstebila/liboqs:x86_64-xenial-0.0.5
|
||||
CC: gcc-8
|
||||
x86_64-xenial-gcc8-noopenssl:
|
||||
<<: *oqsjob
|
||||
environment:
|
||||
IMAGE: dstebila/liboqs:x86_64-xenial-0.0.4
|
||||
IMAGE: dstebila/liboqs:x86_64-xenial-0.0.5
|
||||
CC: gcc-8
|
||||
CONFIGURE_ARGS: --without-openssl
|
||||
x86_64-xenial-gcc8-noshared:
|
||||
<<: *oqsjob
|
||||
environment:
|
||||
IMAGE: dstebila/liboqs:x86_64-xenial-0.0.4
|
||||
IMAGE: dstebila/liboqs:x86_64-xenial-0.0.5
|
||||
CC: gcc-8
|
||||
CONFIGURE_ARGS: --disable-shared
|
||||
|
||||
|
||||
68
.travis.yml
68
.travis.yml
@ -4,25 +4,6 @@ sudo: true
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env:
|
||||
- CC_OVERRIDE=gcc
|
||||
- ENABLE_SIG_PICNIC=0
|
||||
- WITH_OPENSSL=1
|
||||
- CHECK_STYLE=true
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- doxygen
|
||||
- graphviz
|
||||
- python3-pytest
|
||||
before_install:
|
||||
- sh .travis/install-clang-format-linux.sh
|
||||
script:
|
||||
- .travis/all-tests.sh
|
||||
- os: linux
|
||||
compiler: arm-linux-gnueabi-gcc
|
||||
addons:
|
||||
@ -34,55 +15,6 @@ matrix:
|
||||
script:
|
||||
- scripts/arm-cross-compile.sh
|
||||
- scripts/arm-run-tests-qemu.sh
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env:
|
||||
- CC_OVERRIDE=gcc-4.9
|
||||
- ENABLE_SIG_PICNIC=0
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- gcc-4.9
|
||||
- doxygen
|
||||
- graphviz
|
||||
- python3-pytest
|
||||
before_install:
|
||||
- sh .travis/install-clang-format-linux.sh
|
||||
script:
|
||||
- .travis/all-tests.sh
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env: CC_OVERRIDE=gcc-5
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- gcc-5
|
||||
- doxygen
|
||||
- graphviz
|
||||
- python3-pytest
|
||||
script:
|
||||
- .travis/all-tests.sh
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env:
|
||||
- CC_OVERRIDE=gcc-6
|
||||
- WITH_OPENSSL=1
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- gcc-6
|
||||
- libssl-dev
|
||||
- doxygen
|
||||
- graphviz
|
||||
- python3-pytest
|
||||
script:
|
||||
- .travis/all-tests.sh
|
||||
- os: osx
|
||||
compiler: clang
|
||||
env:
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
###
|
||||
# Install clang-format on Linux
|
||||
###
|
||||
|
||||
set -e
|
||||
|
||||
if [ ! -x "$(which clang-format-3.9)" ]; then
|
||||
sudo add-apt-repository 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main'
|
||||
wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -qq -y clang-format-3.9
|
||||
fi;
|
||||
@ -1,79 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
###
|
||||
# Checks that all non-upstream files satisfy prettyprint requirements.
|
||||
###
|
||||
|
||||
set -e
|
||||
|
||||
source $(dirname $0)/defs.sh
|
||||
|
||||
if [[ "x${TRAVIS}" == "xtrue" ]];
|
||||
then
|
||||
if [[ ! "x${CHECK_STYLE}" == "xtrue" ]];
|
||||
then
|
||||
echo "When running on Travis, style-check is only run on some builds."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Make sure that there are no modified files to start with
|
||||
MODIFIED=$(git status -s)
|
||||
if [[ ! -z "${MODIFIED}" ]];
|
||||
then
|
||||
${PRINT_RED}
|
||||
echo "There are modified files present in the directory prior to prettyprint check. This may indicate that some files should be added to .gitignore or need to be committed.";
|
||||
${PRINT_RESET}
|
||||
git status -s
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
# Find clang-format
|
||||
TRY_CLANGFORMAT="/usr/local/Cellar/clang-format/2016-06-27/bin/clang-format"
|
||||
if [[ ! -x $(which ${TRY_CLANGFORMAT}) ]];
|
||||
then
|
||||
TRY_CLANGFORMAT="clang-format-3.9"
|
||||
if [[ ! -x $(which ${TRY_CLANGFORMAT}) ]];
|
||||
then
|
||||
TRY_CLANGFORMAT="clang-format"
|
||||
if [[ ! -x $(which ${TRY_CLANGFORMAT}) ]];
|
||||
then
|
||||
${PRINT_RED}
|
||||
echo "Cannot find clang-format."
|
||||
${PRINT_RESET}
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check clang-format version
|
||||
set +e
|
||||
CLANG_FORMAT_VERSION=$(${TRY_CLANGFORMAT} -version | grep 3.9)
|
||||
ERROR_CODE=$?
|
||||
set -e
|
||||
if [ ${ERROR_CODE} -ne 0 ];
|
||||
then
|
||||
${PRINT_RED}
|
||||
echo "clang-format is not version 3.9."
|
||||
${PRINT_RESET}
|
||||
${TRY_CLANGFORMAT} -version
|
||||
exit 1
|
||||
fi;
|
||||
|
||||
# Pretty-print everything
|
||||
make prettyprint CLANGFORMAT=${TRY_CLANGFORMAT}
|
||||
|
||||
# Check if there are any modified files
|
||||
MODIFIED=$(git status -s)
|
||||
if [[ ! -z "${MODIFIED}" ]]; then
|
||||
${PRINT_RED}
|
||||
echo "Code does not adhere to the project standards. Run \"make prettyprint\".";
|
||||
${PRINT_RESET}
|
||||
git status -s
|
||||
exit 1;
|
||||
else
|
||||
${PRINT_GREEN}
|
||||
echo "Code adheres to the project standards (prettyprint).";
|
||||
${PRINT_RESET}
|
||||
exit 0;
|
||||
fi;
|
||||
@ -1,5 +1,7 @@
|
||||
import functools
|
||||
import os
|
||||
import os.path
|
||||
import pytest
|
||||
import subprocess
|
||||
|
||||
# subprocess.run is not defined on older versions of Python that are present on our test platform
|
||||
@ -113,3 +115,14 @@ def is_sig_enabled_by_name(name):
|
||||
if sig_symbol == symbol:
|
||||
return True
|
||||
return False
|
||||
|
||||
def filtered_test(func):
|
||||
funcname = func.__name__[len("test_"):]
|
||||
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
if ('SKIP_TESTS' in os.environ) and (funcname in os.environ['SKIP_TESTS'].lower().split(',')):
|
||||
pytest.skip("Test disabled by filter")
|
||||
else:
|
||||
return func(*args, **kwargs)
|
||||
return wrapper
|
||||
48
tests/test_style.py
Normal file
48
tests/test_style.py
Normal file
@ -0,0 +1,48 @@
|
||||
import hashlib
|
||||
import helpers
|
||||
import os
|
||||
import os.path
|
||||
import pytest
|
||||
|
||||
@helpers.filtered_test
|
||||
def test_style():
|
||||
|
||||
modified_files = helpers.run_subprocess(
|
||||
['git', 'status', '-s']
|
||||
)
|
||||
if (modified_files != ""):
|
||||
assert False, "There are modified files present in the directory prior to prettyprint check. This may indicate that some files should be added to .gitignore or need to be committed."
|
||||
|
||||
clang_formats = ['/usr/local/Cellar/clang-format/2016-06-27/bin/clang-format', 'clang-format-3.9', 'clang-format']
|
||||
found_clang_format = None
|
||||
for clang_format in clang_formats:
|
||||
try:
|
||||
helpers.run_subprocess(
|
||||
[clang_format, '/dev/null'],
|
||||
)
|
||||
found_clang_format = clang_format
|
||||
break
|
||||
finally:
|
||||
pass
|
||||
assert found_clang_format != None, 'No clang-format found'
|
||||
|
||||
version = helpers.run_subprocess(
|
||||
[found_clang_format, '-version']
|
||||
)
|
||||
assert 'version 3.9' in version, 'Invalid clang-format version (' + version + ')'
|
||||
|
||||
helpers.run_subprocess(
|
||||
['make', 'prettyprint'],
|
||||
env = {'CLANGFORMAT': found_clang_format},
|
||||
)
|
||||
|
||||
modified_files = helpers.run_subprocess(
|
||||
['git', 'status', '-s']
|
||||
)
|
||||
if (modified_files != ""):
|
||||
assert False, "Some files do not adhere to project style standards. See the last list of files below `git status -s`"
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
pytest.main(sys.argv)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user