Skip to content

Commit

Permalink
Use openssl test framework (#56)
Browse files Browse the repository at this point in the history
* use openssl test harness directly
  • Loading branch information
baentsch committed May 19, 2022
1 parent e422884 commit 8cd9487
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 371 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- run:
name: Build OQS-OpenSSL provider
command: |
./scripts/preptests.sh && mkdir _build && cd _build && cmake -GNinja -DOPENSSL_ROOT_DIR=$(pwd)/../.local -DCMAKE_PREFIX_PATH=$(pwd)/../.local .. && ninja
mkdir _build && cd _build && cmake -GNinja -DOPENSSL_ROOT_DIR=$(pwd)/../.local -DCMAKE_PREFIX_PATH=$(pwd)/../.local .. && ninja
- run:
name: Run tests
command: |
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ Core component testing can be run via the following command:

Add `-V` to the `ctest` command for verbose output.

*Note*: Some parts of testing depend on OpenSSL components. These can be
activated by executing `./scripts/preptests.sh` before building the provider.
*Note*: Some parts of testing depend on OpenSSL components. Be sure to have
these available (done automatically by the scripts provided).
See [the test README](test/README.md) for details.

Additional interoperability tests (with OQS-OpenSSL1.1.1) are available in the
Expand Down
24 changes: 0 additions & 24 deletions scripts/preptests.sh

This file was deleted.

46 changes: 17 additions & 29 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,27 @@ if (NOT DEFINED OPENSSL_BLDTOP)
set(OPENSSL_BLDTOP "${CMAKE_CURRENT_SOURCE_DIR}/../openssl")
endif()

# oqs_test_groups.c relies on OpenSSL internals, which must be copied to
# this directory to run this test:
#
# {openssl}/test/helpers/ssltestlib.c -> test/ssltestlib.c
# {openssl}/test/helpers/ssltestlib.h -> test/ssltestlib.h
# (they need some work to make independent from OpenSSL, patches are
# available in test/ssltestlib.c.patch and test/ssltestlib.h.patch)
#
# {openssl}/test/certs/ -> test/oqs_test_groups/certs/
# (just copy the whole directory over as is)
#
# {openssl}/test/recipes/90-test_sslapi_data/passwd.txt
# -> test/oqs_test_groups/passwd.txt
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/ssltestlib.h
AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/ssltestlib.c
AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/oqs_test_groups/passwd.txt
AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/oqs_test_groups/certs
AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/oqs_test_groups/certs)
message("-- Including test oqs_groups")
add_test(
if (NOT IS_DIRECTORY ${OPENSSL_BLDTOP})
message(WARNING "OpenSSL build directory '${OPENSSL_BLDTOP}' not present. Some dependent tests will be skipped.")
else()
add_test(
NAME oqs_groups
COMMAND oqs_test_groups
"oqsprovider"
"${CMAKE_CURRENT_SOURCE_DIR}/oqs.cnf"
"${CMAKE_CURRENT_SOURCE_DIR}/oqs_test_groups/certs"
"${CMAKE_CURRENT_SOURCE_DIR}/oqs_test_groups/passwd.txt"
"${OPENSSL_BLDTOP}/test/certs"
"${OPENSSL_BLDTOP}/test/recipes/90-test_sslapi_data/passwd.txt"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test-groups
)
set_tests_properties(oqs_signatures oqs_groups
)
set_tests_properties(oqs_groups
PROPERTIES ENVIRONMENT "OPENSSL_MODULES=${CMAKE_BINARY_DIR}/oqsprov"
)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test-groups)
add_executable(oqs_test_groups oqs_test_groups.c ssltestlib.c test_common.c)
target_link_libraries(oqs_test_groups ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
endif()
)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test-groups)
add_executable(oqs_test_groups oqs_test_groups.c test_common.c ${OPENSSL_BLDTOP}/test/helpers/ssltestlib.c)
target_include_directories(oqs_test_groups PRIVATE ${OPENSSL_BLDTOP}/include)
target_include_directories(oqs_test_groups PRIVATE ${OPENSSL_BLDTOP}/test)
target_include_directories(oqs_test_groups PRIVATE ${OPENSSL_BLDTOP}/apps/include)
target_link_libraries(oqs_test_groups ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_BLDTOP}/test/libtestutil.a)

add_executable(oqs_test_endecode oqs_test_endecode.c test_common.c)
target_include_directories(oqs_test_endecode PRIVATE ${OPENSSL_BLDTOP}/include)
Expand All @@ -67,3 +53,5 @@ set_tests_properties(oqs_endecode
PROPERTIES ENVIRONMENT "OPENSSL_MODULES=${CMAKE_BINARY_DIR}/oqsprov"
)

endif() # NOT IS_DIRECTORY ${OPENSSL_BLDTOP}

15 changes: 1 addition & 14 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
# oqs-provider testing

The tests in this folder are running separately from the OpenSSL test framework but utilize some of its plumbing.
The tests in this folder are running separately from the OpenSSL test framework but utilize some of its plumbing. Therefore the OpenSSL code base, incl. its "test" directory must be locally available. The script `../scripts/fullbuild.sh`ensures this.

## Patches

Not the full OpenSSL test infrastructure is embedded such as to allow the tests to run stand-alone. Therefore, some modifications are made to test support code via patches.

The required patches are generated within this folder and assuming OpenSSL has been cloned into `../openssl` as per the [README](../README.md) using this command

diff -u ../openssl/test/helpers/ssltestlib.c ssltestlib.c > ssltestlib.c.patch

As OpenSSL continues to evolve it may be necessary to update these patches.

## Applying patches

Patches are applied by running `scripts/preptests.sh` in the oqs-provider main folder (`..`) before building oqs-provider.
2 changes: 1 addition & 1 deletion test/oqs_test_groups.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <openssl/provider.h>
#include <openssl/ssl.h>
#include <string.h>
#include "ssltestlib.h"
#include "helpers/ssltestlib.h"
#include "test_common.h"
#include <openssl/core_names.h>

Expand Down
Loading

0 comments on commit 8cd9487

Please sign in to comment.