|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, IBM Corporation. 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.Files; |
| 25 | +import java.nio.file.Path; |
| 26 | +import jdk.test.lib.process.ProcessTools; |
| 27 | + |
| 28 | +/** |
| 29 | + * @test |
| 30 | + * @bug 8319516 |
| 31 | + * @summary verify that System.loadLibrary on AIX is able to load libraries from ".a" (archive) file |
| 32 | + * @requires os.family == "aix" |
| 33 | + * @library /test/lib/ |
| 34 | + * @build jdk.test.lib.process.ProcessTools |
| 35 | + * @run main/othervm LoadAIXLibraryFromArchiveObject |
| 36 | + */ |
| 37 | +public class LoadAIXLibraryFromArchiveObject { |
| 38 | + |
| 39 | + private static final String TEST_LIBRARY_NAME = "foobar"; |
| 40 | + // creates a ".a" archive file in a test specific directory and then |
| 41 | + // launches a java application passing this directory through "-Djava.library.path". |
| 42 | + // the java application then attempts to load the library using System.loadLibrary() |
| 43 | + public static void main(String[] args) throws Exception { |
| 44 | + String javaHome = System.getProperty("java.home"); |
| 45 | + Path libj2pcscSo = Path.of(javaHome).resolve("lib", "libj2pcsc.so"); |
| 46 | + if (!Files.exists(libj2pcscSo)) { |
| 47 | + throw new AssertionError(libj2pcscSo + " is missing"); |
| 48 | + } |
| 49 | + String archiveFileName = "lib" + TEST_LIBRARY_NAME + ".a"; |
| 50 | + // copy over libj2pcsc.so as an archive file to test specific scratch dir |
| 51 | + Path testNativeLibDir = Path.of("native").toAbsolutePath(); |
| 52 | + Files.createDirectories(testNativeLibDir); |
| 53 | + Path libFooBarArchive = testNativeLibDir.resolve(archiveFileName); |
| 54 | + Files.copy(libj2pcscSo, libFooBarArchive); |
| 55 | + // launch a java application which calls System.loadLibrary and is passed |
| 56 | + // the directory containing the native library archive file, through |
| 57 | + // -Djava.library.path |
| 58 | + ProcessBuilder processBuilder = ProcessTools.createTestJavaProcessBuilder( |
| 59 | + "-Djava.library.path=" + testNativeLibDir, |
| 60 | + LoadAIXLibraryFromArchiveObject.LoadLibraryApp.class.getName()); |
| 61 | + ProcessTools.executeCommand(processBuilder).shouldHaveExitValue(0); |
| 62 | + } |
| 63 | + |
| 64 | + static class LoadLibraryApp { |
| 65 | + public static void main(final String[] args) throws Exception { |
| 66 | + System.out.println("attempting to load library " + TEST_LIBRARY_NAME); |
| 67 | + System.loadLibrary(TEST_LIBRARY_NAME); |
| 68 | + System.out.println(TEST_LIBRARY_NAME + " successfully loaded"); |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | + |
0 commit comments