diff --git a/tests/runtest.sh b/tests/runtest.sh new file mode 100644 index 0000000..624097c --- /dev/null +++ b/tests/runtest.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +mkdir ibmtpm1661 +cd ibmtpm1661 +wget https://downloads.sourceforge.net/project/ibmswtpm2/ibmtpm1661.tar.gz +tar xvf ibmtpm1661.tar.gz +cd src +make +export PATH="$(realpath .):$PATH" +cd ../.. + +mkdir junit +cd junit +wget https://sourceforge.net/projects/junit/files/junit/4.10/junit4.10.zip +unzip junit4.10.zip +export JUNIT_HOME=$(realpath .) +export CLASSPATH="$(realpath .)/junit4.10/junit-4.10.jar:$(CLASSPATH)" +cd .. + +git clone https://github.com/danni/python-pkcs11 +cd python-pkcs11 +sed "s/'setuptools_scm',//" setup.py -i +sed "s/test_suite='tests',//" setup.py -i +python3 setup.py build +python3 -m pip install . --upgrade +cd .. + +git clone https://github.com/tpm2-software/tpm2-tss-engine +cd tpm2-tss-engine +./bootstrap && ./configure && make && make install +cd .. + +export TPM2_PKCS11_MODULE=/usr/lib64/pkcs11/libtpm2_pkcs11.so +export modpath=/usr/lib64/pkcs11/libtpm2_pkcs11.so +export LD_LIBRARY_PATH="/usr/lib64/pkcs11:$LD_LIBRARY_PATH" +export LD_RUN_PATH="/usr/lib64/pkcs11:$LD_RUN_PATH" + +cd source +patch -p1 < ../tests/use-global-lib-for-testing.patch +autoreconf -i && ./configure --enable-integration && make + +make check +result=$? + +cp test/integration/*.log /tmp/artifacts + +exit $result diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..8e86e08 --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,37 @@ +- hosts: localhost + tags: + - classic + roles: + - role: standard-test-source + - role: standard-test-basic + required_packages: + - autoconf-archive + - python3-devel + - java-devel + - sqlite-devel + - libyaml-devel + - libcmocka-devel + - tpm2-abrmd-devel + - nss-tools + - expect + - opensc + - gnutls-utils + - libtool + - automake + - openssl + - openssl-devel + - sed + - tpm2-tss + - tpm2-tss-devel + - tpm2-tools + - tpm2-abrmd + - tpm2-abrmd-selinux + - python3 + - vim-common + - perl-Digest-SHA + - dbus-daemon + tests: + - intel-tpm2: + dir: . + run: ./runtest.sh + timeout: 240m diff --git a/tests/use-global-lib-for-testing.patch b/tests/use-global-lib-for-testing.patch new file mode 100644 index 0000000..7f1968c --- /dev/null +++ b/tests/use-global-lib-for-testing.patch @@ -0,0 +1,79 @@ +From 92d8e3487bd58bd31af7ef6c5053b8a67aa79a50 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Hor=C3=A1=C4=8Dek?= + +Date: Wed, 9 Nov 2022 21:01:42 +0100 +Subject: [PATCH] use global lib for testing + +--- + configure.ac | 4 ++-- + Makefile.am | 5 +---- + test/integration/PKCS11JavaTests.java | 2 +- + test/integration/pkcs11-dbup.sh.nosetup | 2 +- + 4 files changed, 5 insertions(+), 8 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 442ee87..d212b78 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -331,9 +331,9 @@ AC_DEFUN([integration_test_checks], [ + AS_IF([test "x$tpm2_abrmd" != "xyes"], + [AC_MSG_ERROR([Integration tests enabled but tpm2-abrmd executable not found.])]) + +- AM_PATH_PYTHON([3.7], ++ AM_PATH_PYTHON([3.6], + [AC_SUBST([PYTHON_INTERPRETER], [$PYTHON])], +- [AC_MSG_ERROR([Integration tests enabled but python >= 3.7 executable not found.])] ++ [AC_MSG_ERROR([Integration tests enabled but python >= 3.6 executable not found.])] + ) + + AC_PYTHON_MODULE([$PYTHON], [pkcs11]) +diff --git a/Makefile.am b/Makefile.am +index 0f5e05b..c8dfc11 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -112,15 +112,12 @@ AM_TESTS_ENVIRONMENT = \ + PYTHON_INTERPRETER=@PYTHON_INTERPRETER@ \ + TEST_FUNC_LIB=$(srcdir)/test/integration/scripts/int-test-funcs.sh \ + TEST_FIXTURES=$(abs_top_srcdir)/test/integration/fixtures \ +- PATH=$(abs_top_srcdir)/tools:./src:$(PATH) \ +- PYTHONPATH=$(abs_top_srcdir)/tools \ +- TPM2_PKCS11_MODULE=$(abs_builddir)/src/.libs/libtpm2_pkcs11.so \ + TEST_JAVA_ROOT=$(JAVAROOT) \ + PACKAGE_URL=$(PACKAGE_URL) \ + CC=$(CC) \ + dbus-run-session + +-TESTS_LDADD = $(noinst_LTLIBRARIES) $(lib_LTLIBRARIES) $(p11lib_LTLIBRARIES) $(AM_LDFLAGS) $(CMOCKA_LIBS) $(CRYPTO_LIBS) ++TESTS_LDADD = $(noinst_LTLIBRARIES) /usr/lib64/pkcs11/libtpm2_pkcs11.so $(AM_LDFLAGS) $(CMOCKA_LIBS) $(CRYPTO_LIBS) + + TESTS_CFLAGS = $(CMOCKA_CFLAGS) + +diff --git a/test/integration/PKCS11JavaTests.java b/test/integration/PKCS11JavaTests.java +index 021c0bb..58e1409 100644 +--- a/test/integration/PKCS11JavaTests.java ++++ b/test/integration/PKCS11JavaTests.java +@@ -38,7 +38,7 @@ public class PKCS11JavaTests { + * + */ + String cwd = System.getProperty("user.dir"); +- Path libPath = Paths.get(cwd, "src/.libs/libtpm2_pkcs11.so.0.0.0"); ++ Path libPath = Paths.get("/usr/lib64/pkcs11/libtpm2_pkcs11.so"); + + String version = System.getProperty("java.version"); + String [] chunks = version.split("\\."); +diff --git a/test/integration/pkcs11-dbup.sh.nosetup b/test/integration/pkcs11-dbup.sh.nosetup +index 73f6f71..3a64716 100755 +--- a/test/integration/pkcs11-dbup.sh.nosetup ++++ b/test/integration/pkcs11-dbup.sh.nosetup +@@ -67,7 +67,7 @@ echo "TPM2_PKCS11_STORE=$TPM2_PKCS11_STORE" + # So we need to use the 1.0 tpm2_ptool + # XXX should we prepend the current? + # +-PYTHONPATH=$tempdir/tpm2-pkcs11-$oldver/tools ++export PYTHONPATH=$tempdir/tpm2-pkcs11-$oldver/tools + echo $PYTHONPATH + + tpm2_ptool init +-- +2.38.1 +