Testing: bound latch waits and shut down thread pools in JNI tests

pull/251/head
Chris Conlon 2026-08-06 15:28:33 -06:00
parent 9ca89c4210
commit b5ad4c9321
18 changed files with 97 additions and 56 deletions

View File

@ -28,6 +28,7 @@ import java.util.Iterator;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import org.junit.Assume;
@ -780,7 +781,8 @@ public class AesCcmTest {
});
}
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
if (exceptions.size() > 0) {
@ -843,7 +845,8 @@ public class AesCcmTest {
});
}
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
if (exceptions.size() > 0) {
@ -906,7 +909,8 @@ public class AesCcmTest {
});
}
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
if (exceptions.size() > 0) {
@ -1266,7 +1270,8 @@ public class AesCcmTest {
});
}
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
if (exceptions.size() > 0) {

View File

@ -39,6 +39,7 @@ import java.util.Iterator;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import com.wolfssl.wolfcrypt.Aes;
@ -315,7 +316,8 @@ public class AesCmacTest {
});
}
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
Iterator<Object> i = results.iterator();

View File

@ -29,6 +29,7 @@ import java.util.Iterator;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import org.junit.Assume;
@ -934,7 +935,9 @@ public class AesGcmTest {
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* compare all digests, all should be the same across threads */
Iterator<Integer> listIterator = results.iterator();
@ -1005,7 +1008,9 @@ public class AesGcmTest {
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* compare all digests, all should be the same across threads */
Iterator<Integer> listIterator = results.iterator();
@ -1075,7 +1080,9 @@ public class AesGcmTest {
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* compare all digests, all should be the same across threads */
Iterator<Integer> listIterator = results.iterator();

View File

@ -28,6 +28,7 @@ import java.util.Arrays;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.Assume;
import org.junit.BeforeClass;
@ -565,7 +566,8 @@ public class AesGmacTest {
});
}
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
for (Exception e : exception) {

View File

@ -29,6 +29,7 @@ import java.util.Iterator;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import javax.crypto.ShortBufferException;
import java.nio.ByteBuffer;
@ -689,7 +690,9 @@ public class AesTest {
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* compare all digests, all should be the same across threads */
Iterator<Integer> listIterator = results.iterator();

View File

@ -29,6 +29,7 @@ import java.util.Iterator;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import java.nio.ByteBuffer;
@ -362,7 +363,9 @@ public class Des3Test {
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* compare all digests, all should be the same across threads */
Iterator<Integer> listIterator = results.iterator();

View File

@ -36,6 +36,7 @@ import java.util.Iterator;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import java.security.KeyPairGenerator;
@ -450,21 +451,17 @@ public class EccTest {
alice2.releaseNativeStruct();
aliceX963.releaseNativeStruct();
bob.releaseNativeStruct();
results.add(failed);
latch.countDown();
}
if (failed == 1) {
results.add(1);
}
else {
results.add(0);
}
}
});
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* Look for any failures that happened */
Iterator<Integer> listIterator = results.iterator();
@ -572,21 +569,17 @@ public class EccTest {
bob.releaseNativeStruct();
bob = null;
}
results.add(failed);
latch.countDown();
}
if (failed == 1) {
results.add(1);
}
else {
results.add(0);
}
}
});
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* Look for any failures that happened */
Iterator<Integer> listIterator = results.iterator();
@ -792,7 +785,9 @@ public class EccTest {
}
/* Wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* Verify all results are consistent */
String[] firstResult = results.poll();
@ -834,7 +829,9 @@ public class EccTest {
}
/* Wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* Verify all results are consistent */
String[] firstResult = results.poll();

View File

@ -38,6 +38,7 @@ import java.util.Iterator;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import com.wolfssl.wolfcrypt.Fips;
@ -535,21 +536,17 @@ public class HmacTest {
failed = 1;
} finally {
results.add(failed);
latch.countDown();
}
if (failed == 1) {
results.add(1);
}
else {
results.add(0);
}
}
});
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* Look for any failures that happened */
Iterator<Integer> listIterator = results.iterator();

View File

@ -30,6 +30,7 @@ import java.util.Iterator;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import javax.crypto.ShortBufferException;
@ -255,7 +256,9 @@ public class Md5Test {
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* compare all digests, all should be the same across threads */
Iterator<byte[]> listIterator = results.iterator();

View File

@ -35,6 +35,7 @@ import java.nio.ByteBuffer;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import com.wolfssl.wolfcrypt.Rng;
@ -206,7 +207,9 @@ public class RngTest {
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
Iterator<byte[]> listIterator = results.iterator();
byte[] current = listIterator.next();

View File

@ -38,6 +38,7 @@ import java.util.Iterator;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import java.security.MessageDigest;
@ -927,21 +928,17 @@ public class RsaTest {
}
priv.releaseNativeStruct();
pub.releaseNativeStruct();
results.add(failed);
latch.countDown();
}
if (failed == 1) {
results.add(1);
}
else {
results.add(0);
}
}
});
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* Look for any failures that happened */
Iterator<Integer> listIterator = results.iterator();

View File

@ -30,6 +30,7 @@ import java.util.Iterator;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import javax.crypto.ShortBufferException;
@ -224,7 +225,9 @@ public class Sha224Test {
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* compare all digests, all should be the same across threads */
Iterator<byte[]> listIterator = results.iterator();

View File

@ -30,6 +30,7 @@ import java.util.Iterator;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import javax.crypto.ShortBufferException;
@ -239,7 +240,9 @@ public class Sha256Test {
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* compare all digests, all should be the same across threads */
Iterator<byte[]> listIterator = results.iterator();

View File

@ -30,6 +30,7 @@ import java.util.Iterator;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import javax.crypto.ShortBufferException;
@ -251,7 +252,9 @@ public class Sha384Test {
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* compare all digests, all should be the same across threads */
Iterator<byte[]> listIterator = results.iterator();

View File

@ -30,6 +30,7 @@ import java.util.Iterator;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import org.junit.Test;
@ -281,7 +282,9 @@ public class Sha3Test {
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* compare all digests, all should be the same across threads */
Iterator<byte[]> listIterator = results.iterator();

View File

@ -30,6 +30,7 @@ import java.util.Iterator;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import javax.crypto.ShortBufferException;
@ -255,7 +256,9 @@ public class Sha512Test {
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* compare all digests, all should be the same across threads */
Iterator<byte[]> listIterator = results.iterator();

View File

@ -30,6 +30,7 @@ import java.util.Iterator;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import javax.crypto.ShortBufferException;
@ -237,7 +238,9 @@ public class ShaTest {
}
/* wait for all threads to complete */
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
service.shutdown();
/* compare all digests, all should be the same across threads */
Iterator<byte[]> listIterator = results.iterator();

View File

@ -36,6 +36,7 @@ import java.security.KeyPairGenerator;
import java.util.Arrays;
import java.util.Base64;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
@ -1017,7 +1018,8 @@ public class WolfCryptTest {
});
}
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
executor.shutdown();
assertEquals("No thread failures should occur", 0, failures.get());
@ -1062,7 +1064,8 @@ public class WolfCryptTest {
});
}
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
executor.shutdown();
assertEquals("No thread failures should occur", 0, failures.get());
@ -1177,7 +1180,8 @@ public class WolfCryptTest {
});
}
latch.await();
assertTrue("timed out waiting for threads to finish",
latch.await(120, TimeUnit.SECONDS));
executor.shutdown();
assertEquals("No thread failures should occur", 0, failures.get());