Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ppc64, ppc64le and riscv64 architectures #3930

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
public enum Architecture {

X64,
ARM64;
ARM64,
PPC,
RISCV;

public static Architecture current() {
final String architecture = System.getProperty("os.arch", "");
Expand All @@ -45,6 +47,11 @@ public static Architecture current() {
return X64;
case "aarch64":
return ARM64;
case "ppc64":
case "ppc64le":
return PPC;
case "riscv64":
return RISCV;
default:
throw new IllegalArgumentException("can not determine architecture from [" + architecture + "]");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.gradle;

import org.opensearch.gradle.test.GradleUnitTestCase;

public class ArchitectureTests extends GradleUnitTestCase {

final String architecture = System.getProperty("os.arch", "");

public void testCurrentArchitecture() {
assertEquals(Architecture.X64, currentArchitecture("amd64"));
assertEquals(Architecture.X64, currentArchitecture("x86_64"));
assertEquals(Architecture.ARM64, currentArchitecture("aarch64"));
assertEquals(Architecture.PPC, currentArchitecture("ppc64"));
assertEquals(Architecture.PPC, currentArchitecture("ppc64le"));
assertEquals(Architecture.RISCV, currentArchitecture("riscv64"));
}

public void testInvalidCurrentArchitecture() {
assertThrows("can not determine architecture from [", IllegalArgumentException.class, () -> currentArchitecture("fooBar64"));
}

/**
* Determines the return value of {@link Architecture#current()} based on a string representing a potential OS Architecture.
*
* @param osArchToTest An expected value of the {@code os.arch} system property on another architecture.
* @return the value of the {@link Architecture} enum which would have resulted with the given value.
* @throws IllegalArgumentException if the string is not mapped to a value of the {@link Architecture} enum.
*/
private Architecture currentArchitecture(String osArchToTest) throws IllegalArgumentException {
// Test new architecture
System.setProperty("os.arch", osArchToTest);
try {
return Architecture.current();
} finally {
// Restore actual architecture property value
System.setProperty("os.arch", this.architecture);
}
}
}