1 /* 2 * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.nio.file.Path; 25 import org.testng.annotations.Test; 26 import jdk.incubator.foreign.MemorySegment; 27 import static org.testng.Assert.assertNotNull; 28 29 /* 30 * @test 31 * @library .. /test/lib 32 * @modules jdk.incubator.jextract 33 * @build JextractToolRunner 34 * @bug 8260929 35 * @summary jextract crashes with Crossing storage unit boundaries 36 * @run testng/othervm --enable-native-access=jdk.incubator.jextract,ALL-UNNAMED Test8261578 37 */ 38 public class Test8261578 extends JextractToolRunner { 39 @Test 40 public void test1() { 41 Path outputPath = getOutputFilePath("output_1"); 42 Path headerFile = getInputFilePath("test8261578_1.h"); 43 run("-d", outputPath.toString(), headerFile.toString()).checkSuccess(); 44 try(Loader loader = classLoader(outputPath)) { 45 Class<?> ndpi_class = loader.loadClass("ndpi_flow_tcp_struct"); 46 assertNotNull(ndpi_class); 47 48 checkMethod(ndpi_class, "gnutella_msg_id$slice", MemorySegment.class, MemorySegment.class); 49 } finally { 50 deleteDir(outputPath); 51 } 52 } 53 54 @Test 55 public void test2() { 56 Path outputPath = getOutputFilePath("output_2"); 57 Path headerFile = getInputFilePath("test8261578_2.h"); 58 run("-d", outputPath.toString(), headerFile.toString()).checkSuccess(); 59 try(Loader loader = classLoader(outputPath)) { 60 Class<?> foo_class = loader.loadClass("foo"); 61 assertNotNull(foo_class); 62 63 checkMethod(foo_class, "clear_color$slice", MemorySegment.class, MemorySegment.class); 64 checkMethod(foo_class, "clear_z$get", int.class, MemorySegment.class); 65 checkMethod(foo_class, "clear_z$set", void.class, MemorySegment.class, int.class); 66 checkMethod(foo_class, "clear_s$get", byte.class, MemorySegment.class); 67 checkMethod(foo_class, "clear_s$set", void.class, MemorySegment.class, byte.class); 68 } finally { 69 deleteDir(outputPath); 70 } 71 } 72 73 @Test 74 public void test3() { 75 Path outputPath = getOutputFilePath("output_3"); 76 Path headerFile = getInputFilePath("test8261578_3.h"); 77 run("-d", outputPath.toString(), headerFile.toString()).checkSuccess(); 78 try(Loader loader = classLoader(outputPath)) { 79 Class<?> plugin_class = loader.loadClass("PluginCodec_H323AudioG7231AnnexC"); 80 assertNotNull(plugin_class); 81 82 checkMethod(plugin_class, "maxAl_sduAudioFrames$get", byte.class, MemorySegment.class); 83 checkMethod(plugin_class, "maxAl_sduAudioFrames$set", void.class, MemorySegment.class, byte.class); 84 } finally { 85 deleteDir(outputPath); 86 } 87 } 88 }