This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new 55d85be918 fix(plc4j/test-generator): Fixed an issue causing 
core-dumps on Mac
55d85be918 is described below

commit 55d85be9182afa367454b1f3f2e7025e52068a8b
Author: christoferdutz <[email protected]>
AuthorDate: Thu Mar 2 08:57:37 2023 +0100

    fix(plc4j/test-generator): Fixed an issue causing core-dumps on Mac
---
 plc4j/utils/test-generator/pom.xml                 | 26 ++++++++------
 .../ParserSerializerTestsuiteGenerator.groovy      | 42 +++++++++++++++-------
 2 files changed, 45 insertions(+), 23 deletions(-)

diff --git a/plc4j/utils/test-generator/pom.xml 
b/plc4j/utils/test-generator/pom.xml
index e022bad95a..9f090dbb2d 100644
--- a/plc4j/utils/test-generator/pom.xml
+++ b/plc4j/utils/test-generator/pom.xml
@@ -92,6 +92,17 @@
   </dependencyManagement>
 
   <dependencies>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-spi</artifactId>
+      <version>0.11.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-utils-pcap-shared</artifactId>
+      <version>0.11.0-SNAPSHOT</version>
+    </dependency>
+
     <dependency>
       <groupId>org.apache.groovy</groupId>
       <artifactId>groovy-xml</artifactId>
@@ -102,15 +113,14 @@
       <artifactId>pcap4j-core</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.apache.plc4x</groupId>
-      <artifactId>plc4j-utils-pcap-shared</artifactId>
-      <version>0.11.0-SNAPSHOT</version>
+      <groupId>org.xmlunit</groupId>
+      <artifactId>xmlunit-matchers</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.apache.plc4x</groupId>
-      <artifactId>plc4j-spi</artifactId>
-      <version>0.11.0-SNAPSHOT</version>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
     </dependency>
+
     <dependency>
       <groupId>org.junit.jupiter</groupId>
       <artifactId>junit-jupiter-engine</artifactId>
@@ -121,10 +131,6 @@
       <artifactId>spock-core</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.xmlunit</groupId>
-      <artifactId>xmlunit-matchers</artifactId>
-    </dependency>
   </dependencies>
 
 </project>
\ No newline at end of file
diff --git 
a/plc4j/utils/test-generator/src/main/groovy/org/apache/plc4x/test/generator/ParserSerializerTestsuiteGenerator.groovy
 
b/plc4j/utils/test-generator/src/main/groovy/org/apache/plc4x/test/generator/ParserSerializerTestsuiteGenerator.groovy
index f5fe44802f..b16ca99067 100644
--- 
a/plc4j/utils/test-generator/src/main/groovy/org/apache/plc4x/test/generator/ParserSerializerTestsuiteGenerator.groovy
+++ 
b/plc4j/utils/test-generator/src/main/groovy/org/apache/plc4x/test/generator/ParserSerializerTestsuiteGenerator.groovy
@@ -20,6 +20,7 @@ package org.apache.plc4x.test.generator
 
 import groovy.xml.MarkupBuilder
 import groovyjarjarpicocli.CommandLine
+import org.apache.commons.lang3.SystemUtils
 import org.apache.plc4x.java.spi.generation.ByteOrder
 import org.apache.plc4x.java.spi.generation.ReadBufferByteBased
 import org.apache.plc4x.java.spi.generation.WriteBufferXmlBased
@@ -62,6 +63,16 @@ class ParserSerializerTestsuiteGenerator implements Runnable 
{
     static Consumer<Integer> exitFunc = System::exit
 
     static void main(String... args) {
+        if (SystemUtils.IS_OS_MAC) {
+            // On my Intel Mac I found the libs in: 
"/usr/local/Cellar/libpcap/1.10.1/lib"
+            // On my M1 Mac I found the libs in: 
"/opt/homebrew/Cellar/libpcap/1.10.1/lib"
+            if (new File("/usr/local/Cellar/libpcap/1.10.1/lib").exists()) {
+                System.getProperties().setProperty("jna.library.path", 
"/usr/local/Cellar/libpcap/1.10.1/lib");
+            } else if (new File("/opt/homebrew/opt/libpcap/lib").exists()) {
+                System.getProperties().setProperty("jna.library.path", 
"/opt/homebrew/opt/libpcap/lib");
+            }
+        }
+
         int exitCode = new CommandLine(new 
ParserSerializerTestsuiteGenerator()).execute(args)
         exitFunc.accept(exitCode)
     }
@@ -155,25 +166,30 @@ class ParserSerializerTestsuiteGenerator implements 
Runnable {
         def values = []
         def pcapHandle = Pcaps.openOffline(pcapFile, 
PcapHandle.TimestampPrecision.NANO)
         Packet packet
-        while ((packet = pcapHandle.nextPacket) != null) {
-            def udpPacket = packet.get(UdpPacket.class)
-            if (udpPacket != null) {
-                values << udpPacket.payload.rawData
-            } else {
-                def tcpPacket = packet.get(TcpPacket.class)
-                if (tcpPacket != null) {
-                    values << tcpPacket.payload.rawData
+        try {
+            while ((packet = pcapHandle.nextPacket) != null) {
+                def udpPacket = packet.get(UdpPacket.class)
+                if (udpPacket != null) {
+                    values << udpPacket.payload.rawData
                 } else {
-                    def ethernetPacket = packet.get(EthernetPacket.class)
-                    if(ethernetPacket != null) {
-                        values << ethernetPacket.rawData
+                    def tcpPacket = packet.get(TcpPacket.class)
+                    if (tcpPacket != null) {
+                        values << tcpPacket.payload.rawData
                     } else {
-                        values << new byte[]{0, 0, 0, 0}
+                        def ethernetPacket = packet.get(EthernetPacket.class)
+                        if (ethernetPacket != null) {
+                            values << ethernetPacket.rawData
+                        } else {
+                            values << new byte[]{0, 0, 0, 0}
+                        }
                     }
                 }
             }
+        } catch (Exception e) {
+            e.printStackTrace()
+        } finally {
+            pcapHandle.close()
         }
-        pcapHandle.close()
         values
     }
 

Reply via email to