Path: blob/master/test/jdk/java/foreign/TestSymbolLookup.java
41145 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"26* @modules jdk.incubator.foreign/jdk.internal.foreign27* @run testng/othervm --enable-native-access=ALL-UNNAMED TestSymbolLookup28*/2930import jdk.incubator.foreign.SymbolLookup;31import jdk.incubator.foreign.MemoryAccess;32import jdk.incubator.foreign.MemoryLayouts;33import jdk.incubator.foreign.MemorySegment;34import jdk.incubator.foreign.ResourceScope;35import org.testng.annotations.Test;3637import static org.testng.Assert.*;3839// FYI this test is run on 64-bit platforms only for now,40// since the windows 32-bit linker fails and there41// is some fallback behaviour to use the 64-bit linker,42// where cygwin gets in the way and we accidentally pick up its43// link.exe44public class TestSymbolLookup {45static {46System.loadLibrary("LookupTest");47}4849static final SymbolLookup LOOKUP = SymbolLookup.loaderLookup();5051@Test52public void testSimpleLookup() {53assertFalse(LOOKUP.lookup("f").isEmpty());54}5556@Test57public void testInvalidSymbolLookup() {58assertTrue(LOOKUP.lookup("nonExistent").isEmpty());59}6061@Test62public void testVariableSymbolLookup() {63MemorySegment segment = LOOKUP.lookup("c").get().asSegment(MemoryLayouts.JAVA_INT.byteSize(), ResourceScope.globalScope());64assertEquals(MemoryAccess.getInt(segment), 42);65}66}676869