Esempio n. 1
0
and executed for every scheme/implementation.
"""

import os
import platform
import unittest

import pytest

import helpers
import pqclean


@pytest.mark.parametrize(
    'implementation,test_dir,impl_path, init, destr',
    [(impl, *helpers.isolate_test_files(impl.path(), 'test_functest_'))
     for impl in pqclean.Scheme.all_supported_implementations()],
    ids=[str(impl) for impl in pqclean.Scheme.all_supported_implementations()],
)
@helpers.filtered_test
def test_functest(implementation, impl_path, test_dir, init, destr):
    init()
    dest_dir = os.path.join(test_dir, 'bin')
    helpers.make('functest',
                 TYPE=implementation.scheme.type,
                 SCHEME=implementation.scheme.name,
                 IMPLEMENTATION=implementation.name,
                 SCHEME_DIR=impl_path,
                 DEST_DIR=dest_dir,
                 working_dir=os.path.join(test_dir, 'test'))
    helpers.run_subprocess([
"""

import datetime
import glob
import os

import pytest

import helpers
import pqclean


@pytest.mark.parametrize(
    'implementation,test_dir,impl_path, init, destr',
    [(impl,
      *helpers.isolate_test_files(impl.path(), 'test_makefile_deps_'))
     for impl in pqclean.Scheme.all_supported_implementations()],
    ids=[str(impl) for impl in pqclean.Scheme.all_supported_implementations()],
)
@helpers.filtered_test
def test_makefile_dependencies(implementation, impl_path, test_dir,
                               init, destr):
    init()
    # initial build - want to have *all* files in place at beginning
    helpers.make('clean', working_dir=impl_path)
    helpers.make(working_dir=impl_path)
    # test case for each candidate file
    cfiles = glob.glob(os.path.join(impl_path, '*.c'))
    sfiles = glob.glob(os.path.join(impl_path, '*.[sS]'))
    incfiles = glob.glob(os.path.join(impl_path, '*.inc'))
    hfiles = glob.glob(os.path.join(impl_path, '*.h'))
Esempio n. 3
0
import pqclean


@functools.lru_cache()
def valgrind_supports_exit_early():
    """Checks if we support early exit from valgrind"""
    version = helpers.run_subprocess(['valgrind', '--version'])
    match = re.match(r'valgrind-(\d)\.(\d+).*', version)
    if match:
        return int(match.group(2)) >= 14
    return False


@pytest.mark.parametrize(
    'implementation,test_dir,impl_path, init, destr',
    [(impl, *helpers.isolate_test_files(impl.path(), 'test_valgrind_'))
     for impl in pqclean.Scheme.all_supported_implementations()],
    ids=[str(impl) for impl in pqclean.Scheme.all_supported_implementations()],
)
@helpers.filtered_test
def test_valgrind(implementation: pqclean.Implementation, impl_path, test_dir,
                  init, destr):
    if (platform.machine() not in ('i386', 'x86_64')
            or platform.system() != 'Linux'):
        raise unittest.SkipTest()
    init()

    dest_dir = os.path.join(test_dir, 'bin')

    helpers.make(TYPE=implementation.scheme.type,
                 SCHEME=implementation.scheme.name,
Esempio n. 4
0
Checks that the all exported symbols are properly namespaced, i.e., all
start with "PQCLEAN_SCHEMENAME_".
"""

import sys
import unittest

import pytest

import helpers
import pqclean


@pytest.mark.parametrize(
    'implementation,test_dir,impl_path,init,destr',
    [(impl, *helpers.isolate_test_files(impl.path(), 'test_symbol_ns_'))
     for impl in pqclean.Scheme.all_supported_implementations()],
    ids=[str(impl) for impl in pqclean.Scheme.all_supported_implementations()],
)
@helpers.filtered_test
def test_symbol_namespaces(implementation, impl_path, test_dir, init, destr):
    if sys.platform not in ['linux', 'darwin']:
        raise unittest.SkipTest("Unsupported platform")
    init()
    helpers.make(working_dir=impl_path)
    out = helpers.run_subprocess(
        ['nm', '-g', implementation.libname()],
        impl_path,
    )

    lines = out.strip().split("\n")
Esempio n. 5
0
Checks that (hash of the) test vectors produced on this platform matches
the one provided in the META file for every scheme/implementation.
"""

import hashlib
import os

import pytest

import helpers
import pqclean


@pytest.mark.parametrize(
    'implementation,test_dir,impl_path,init,destr',
    [(impl, *helpers.isolate_test_files(impl.path(), 'test_testvectors_'))
     for sig in pqclean.Signature.all_sigs() for impl in sig.implementations],
    ids=[
        str(impl) for sig in pqclean.Signature.all_sigs()
        for impl in sig.implementations
    ],
)
@helpers.filtered_test
def test_testvectors(implementation, impl_path, test_dir, init, destr):
    init()
    dest_dir = os.path.join(test_dir, 'bin')
    helpers.make('testvectors',
                 TYPE=implementation.scheme.type,
                 SCHEME=implementation.scheme.name,
                 SCHEME_DIR=impl_path,
                 IMPLEMENTATION=implementation.name,
Esempio n. 6
0
import json
import os

import pytest

import helpers
import pqclean


@pytest.mark.parametrize(
    'implementation,test_dir,impl_path, init, destr',
    [(impl, *helpers.isolate_test_files(impl.path(), 'test_printparams_'))
     for impl in pqclean.Scheme.all_implementations()],
    ids=[str(impl) for impl in pqclean.Scheme.all_implementations()],
)
@helpers.filtered_test
def test_metadata_sizes(implementation, impl_path, test_dir, init, destr):
    init()
    metadata = implementation.scheme.metadata()
    helpers.make('printparams',
                 TYPE=implementation.scheme.type,
                 SCHEME=implementation.scheme.name,
                 IMPLEMENTATION=implementation.name,
                 SCHEME_DIR=impl_path,
                 working_dir=os.path.join('..', 'test'))

    out = helpers.run_subprocess(
        [
            os.path.join(
                '..', 'bin', 'printparams_{}_{}{}'.format(
                    implementation.scheme.name, implementation.name,