예제 #1
0
def check_format(implementation: pqclean.Implementation):
    helpers.ensure_available('astyle')
    cfiles = implementation.cfiles()
    hfiles = implementation.hfiles()
    result = helpers.run_subprocess(
        ['astyle', '--dry-run', '--options=../.astylerc', *cfiles, *hfiles])
    assert (not ('Formatted' in result))
def check_preprocessor(implementation: pqclean.Implementation):
    cfiles = implementation.cfiles()
    hfiles = implementation.hfiles()
    errors = []
    for file in hfiles + cfiles:
        with open(file) as f:
            for i, line in enumerate(f):
                line = line.strip()
                if file in hfiles and i == 0 and line.startswith('#ifndef'):
                    continue
                if line.startswith('#if'):
                    errors.append("\n at {}:{}".format(file, i + 1))
    if errors:
        raise AssertionError("Prohibited use of preprocessor conditional" +
                             "".join(errors))
예제 #3
0
def check_tidy(implementation: pqclean.Implementation):
    ensure_available('clang-tidy')
    cfiles = glob(os.path.join(implementation.path(), '*.c'))
    common_files = glob(os.path.join('..', 'common', '*.c'))
    run_subprocess([
        'clang-tidy',
        '-quiet',
        '-header-filter=.*',
        *cfiles,
        *common_files,
        '--',
        '-iquote',
        os.path.join('..', 'common'),
        '-iquote',
        implementation.path(),
    ])
예제 #4
0
def test_clang_tidy(implementation: pqclean.Implementation):
    helpers.ensure_available('clang-tidy')
    cfiles = implementation.cfiles()
    common_files = glob(os.path.join('..', 'common', '*.c'))
    (returncode, _) = helpers.run_subprocess(
        [
            'clang-tidy', '-quiet', '-header-filter=.*', *additional_flags,
            *cfiles, *common_files, '--', '-iquote',
            os.path.join('..', 'common'), '-iquote',
            implementation.path()
        ],
        expected_returncode=None,
    )

    # Detect and gracefully avoid segfaults
    if returncode == -11:
        raise unittest.SkipTest("clang-tidy segfaulted")

    assert returncode == 0, "Clang-tidy returned %d" % returncode
예제 #5
0
파일: test_api_h.py 프로젝트: xvzcf/PQClean
def test_api_h(implementation: pqclean.Implementation):
    apipath = os.path.join(implementation.path(), 'api.h')
    errors = []
    with open(apipath) as f:
        for i, line in enumerate(f):
            if pattern.match(line):
                errors.append("\n at {}:{}".format(apipath, i+1))
    if errors:
        raise AssertionError(
            "Prohibited external include in api.h" + "".join(errors)
        )
예제 #6
0
def check_preprocessor(implementation: pqclean.Implementation):
    apipath = os.path.join(implementation.path(), 'api.h')
    errors = []
    p = re.compile(r'^\s*#include\s*"')
    with open(apipath) as f:
        for i, line in enumerate(f):
            if p.match(line):
                errors.append("\n at {}:{}".format(apipath, i + 1))
    if errors:
        raise AssertionError("Prohibited external include in api.h" +
                             "".join(errors))
예제 #7
0
def check_format(implementation: pqclean.Implementation):
    ensure_available('astyle')
    cfiles = implementation.cfiles()
    hfiles = implementation.hfiles()
    run_subprocess(
        ['astyle', '--dry-run', '--options=../.astylerc', *cfiles, *hfiles])