From ae23141b366bf22307ab9d510df37e0b6fef6c6f Mon Sep 17 00:00:00 2001 From: ulbi Date: Sun, 14 Jul 2024 10:01:35 +0200 Subject: [PATCH] [mongodb] Fix `MongoDBPersistenceServiceTest` fails on CPU without AVX support (#17049) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #17046 Signed-off-by: René Ulbricht --- .../mongodb/internal/DataCreationHelper.java | 25 ++++++++++++++++++- .../MongoDBPersistenceServiceTest.java | 2 -- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.persistence.mongodb/src/test/java/org/openhab/persistence/mongodb/internal/DataCreationHelper.java b/bundles/org.openhab.persistence.mongodb/src/test/java/org/openhab/persistence/mongodb/internal/DataCreationHelper.java index 83ecd75b40c07..ac4deaf77322c 100644 --- a/bundles/org.openhab.persistence.mongodb/src/test/java/org/openhab/persistence/mongodb/internal/DataCreationHelper.java +++ b/bundles/org.openhab.persistence.mongodb/src/test/java/org/openhab/persistence/mongodb/internal/DataCreationHelper.java @@ -15,6 +15,9 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; import java.time.LocalDate; import java.time.ZonedDateTime; import java.util.ArrayList; @@ -224,6 +227,26 @@ public static Stream provideOpenhabItemTypes() { new QuantityType<>("25.00 °F")))); } + /** + * Checks if the current system supports AVX (Advanced Vector Extensions). + * AVX is a set of CPU instructions that can greatly improve performance for certain operations. + * + * @return true if AVX is supported, false otherwise + */ + public static boolean isAVXSupported() { + try (BufferedReader reader = new BufferedReader(new FileReader("/proc/cpuinfo"))) { + String line; + while ((line = reader.readLine()) != null) { + if (line.toLowerCase().contains("avx")) { + return true; + } + } + } catch (IOException e) { + return false; + } + return false; + } + /** * Provides a stream of arguments to be used for parameterized tests. * @@ -234,7 +257,7 @@ public static Stream provideOpenhabItemTypes() { * @return A stream of Arguments, each containing a DatabaseTestContainer instance. */ public static Stream provideDatabaseBackends() { - if (DockerClientFactory.instance().isDockerAvailable()) { + if (DockerClientFactory.instance().isDockerAvailable() && isAVXSupported()) { // If Docker is available, create a stream of Arguments with all backends return Stream.of( // Create a DatabaseTestContainer with a MemoryBackend diff --git a/bundles/org.openhab.persistence.mongodb/src/test/java/org/openhab/persistence/mongodb/internal/MongoDBPersistenceServiceTest.java b/bundles/org.openhab.persistence.mongodb/src/test/java/org/openhab/persistence/mongodb/internal/MongoDBPersistenceServiceTest.java index dff84eacd1e73..afd122c42aaf4 100644 --- a/bundles/org.openhab.persistence.mongodb/src/test/java/org/openhab/persistence/mongodb/internal/MongoDBPersistenceServiceTest.java +++ b/bundles/org.openhab.persistence.mongodb/src/test/java/org/openhab/persistence/mongodb/internal/MongoDBPersistenceServiceTest.java @@ -29,7 +29,6 @@ import org.bson.Document; import org.bson.types.ObjectId; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -63,7 +62,6 @@ * * @author René Ulbricht - Initial contribution */ -@Disabled("Fails on CPUs without AVX support, see: https://github.com/openhab/openhab-addons/issues/17046") public class MongoDBPersistenceServiceTest { /**