From 1714041a6712b34a75a913e0fb67b894d5e08cec Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 16 Feb 2021 00:55:15 +0100 Subject: [PATCH] add test for jni126 - stop_sync() deadlock with a key with passphrase. --- .../pEp/jniadapter/test/jni126/Makefile | 37 +++++++++++ .../pEp/jniadapter/test/jni126/TestAlice.java | 64 +++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 test/java/foundation/pEp/jniadapter/test/jni126/Makefile create mode 100644 test/java/foundation/pEp/jniadapter/test/jni126/TestAlice.java diff --git a/test/java/foundation/pEp/jniadapter/test/jni126/Makefile b/test/java/foundation/pEp/jniadapter/test/jni126/Makefile new file mode 100644 index 0000000..d550140 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/jni126/Makefile @@ -0,0 +1,37 @@ +include ../../../../../../../Makefile.conf +include ../Makefile.conf + +TEST_UNIT_NAME=jni126 + +JAVA_CLASSES = \ + TestAlice.class \ + ../utils/AdapterBaseTestContext.class \ + ../utils/AdapterTestUtils.class \ + ../utils/TestCallbacks.class + +.PHONY: pitytest compile alice test clean + +all: alice compile + +pitytest: + $(MAKE) -C $(PITYTEST_DIR) + +alice: compile clean-pep-home-alice + cd $(JAVA_CWD);pwd;HOME=$(JAVA_PEP_HOME_DIR_ALICE) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestAlice + +compile: $(JAVA_CLASSES) pitytest + +%.class: %.java + cd $(JAVA_CWD);javac -cp $(CLASSPATH) $(JAVA_PKG_BASEPATH)/$(TEST_UNIT_NAME)/$< + +clean: + rm -f $(JAVA_CLASSES) + rm -f *.class + rm -f *.log + rm -Rf .gnupg + rm -Rf .lldb + +clean-pep-home: clean-pep-home-alice + +clean-pep-home-alice: + rm -rf $(PEP_HOME_DIR_ALICE)/.pEp diff --git a/test/java/foundation/pEp/jniadapter/test/jni126/TestAlice.java b/test/java/foundation/pEp/jniadapter/test/jni126/TestAlice.java new file mode 100644 index 0000000..273974c --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/jni126/TestAlice.java @@ -0,0 +1,64 @@ +package foundation.pEp.jniadapter.test.jni126; + +import foundation.pEp.jniadapter.*; +import foundation.pEp.jniadapter.test.utils.AdapterBaseTestContext; +import foundation.pEp.pitytest.TestSuite; +import foundation.pEp.pitytest.TestUnit; +import foundation.pEp.pitytest.utils.TestUtils; + +import static foundation.pEp.pitytest.TestLogger.*; +import static foundation.pEp.pitytest.utils.TestUtils.*; + +class Jni126TestContext extends AdapterBaseTestContext { + @Override + public void init() throws Throwable { + super.init(); + + alice = engine.importKey(keyAliceSecPassphrase).get(0); +// log(AdapterTestUtils.identityToString(alice, true)); + + alice.user_id = "23"; + alice = engine.setOwnKey(alice, alice.fpr); +// log(AdapterTestUtils.identityToString(alice, true)); + + engine.config_passphrase("passphrase_alice"); + engine.setPassphraseRequiredCallback(new Sync.PassphraseRequiredCallback() { + @Override + public String passphraseRequired(PassphraseType type) { + log("passphraseRequired() called"); + log("Please Enter Passphrase..."); + sleep(2000); + return "passphrase_alice"; + } + }); + } + +} + +class TestAlice { + public static void main(String[] args) throws Exception { + TestSuite.getDefault().setVerbose(true); + TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN); + + AdapterBaseTestContext jni126Ctx = new Jni126TestContext(); + + new TestUnit("startSync()/stopSync()", jni126Ctx, ctx -> { + for(int reps = 0; reps < 3; reps++) { + ctx.engine.startSync(); + for (int i = 0; i < 10; i++) { + log("sync enabled"); + sleep(100); + } + ctx.engine.stopSync(); + for (int i = 0; i < 10; i++) { + log("sync disbled"); + sleep(100); + } + } + }); + + TestSuite.getDefault().run(); + } +} + +