1#!/bin/sh
2#
3# Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.
4#
5# Licensed under the Apache License 2.0 (the "License").  You may not use
6# this file except in compliance with the License.  You can obtain a copy
7# in the file LICENSE in the source distribution or at
8# https://www.openssl.org/source/license.html
9
10#
11# OpenSSL external testing using the pkcs11-provider
12#
13
14PWD="$(pwd)"
15
16SRCTOP="$(cd $SRCTOP; pwd)"
17BLDTOP="$(cd $BLDTOP; pwd)"
18
19if [ "$SRCTOP" != "$BLDTOP" ] ; then
20    echo "Out of tree builds not supported with pkcsa11-provider test!"
21    exit 1
22fi
23
24O_EXE="$BLDTOP/apps"
25O_BINC="$BLDTOP/include"
26O_SINC="$SRCTOP/include"
27O_LIB="$BLDTOP"
28
29unset OPENSSL_CONF
30
31export PATH="$O_EXE:$PATH"
32export LD_LIBRARY_PATH="$O_LIB:$LD_LIBRARY_PATH"
33export OPENSSL_ROOT_DIR="$O_LIB"
34
35# Check/Set openssl version
36OPENSSL_VERSION=`openssl version | cut -f 2 -d ' '`
37
38echo "------------------------------------------------------------------"
39echo "Testing OpenSSL using pkcs11-provider:"
40echo "   CWD:                $PWD"
41echo "   SRCTOP:             $SRCTOP"
42echo "   BLDTOP:             $BLDTOP"
43echo "   OPENSSL_ROOT_DIR:   $OPENSSL_ROOT_DIR"
44echo "   OpenSSL version:    $OPENSSL_VERSION"
45echo "------------------------------------------------------------------"
46
47PKCS11_PROVIDER_BUILDDIR=$OPENSSL_ROOT_DIR/pkcs11-provider/builddir
48
49echo "------------------------------------------------------------------"
50echo "Building pkcs11-provider"
51echo "------------------------------------------------------------------"
52
53PKG_CONFIG_PATH="$BLDTOP" meson setup $PKCS11_PROVIDER_BUILDDIR $OPENSSL_ROOT_DIR/pkcs11-provider/ || exit 1
54meson compile -C $PKCS11_PROVIDER_BUILDDIR pkcs11 || exit 1
55
56echo "------------------------------------------------------------------"
57echo "Running tests"
58echo "------------------------------------------------------------------"
59
60# The OpenSSL app uses ${HARNESS_OSSL_PREFIX} as a prefix for its standard output
61HARNESS_OSSL_PREFIX= meson test -C $PKCS11_PROVIDER_BUILDDIR
62
63if [ $? -ne 0 ]; then
64    cat $PKCS11_PROVIDER_BUILDDIR/meson-logs/testlog.txt
65    exit 1
66fi
67
68rm -rf $PKCS11_PROVIDER_BUILDDIR
69
70exit 0
71