Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into wip/interpreter-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
DieKautz committed Jan 8, 2024
2 parents 552aeaf + 6e11884 commit a4d180f
Show file tree
Hide file tree
Showing 62 changed files with 580 additions and 561 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ jobs:
bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r jacoco.xml
if: ${{ env.RUN_WITH_COVERAGE == 'true' && job.status == 'success' }}
- name: Zip Graal compiler dumps
if: always()
shell: bash
run: "[[ -d graal_dumps ]] && zip -r graal_dumps.zip graal_dumps || true"
- name: Upload Graal compiler dumps
if: always()
uses: actions/upload-artifact@v3
with:
name: graal_dumps
Expand Down
15 changes: 3 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,11 @@ A [Squeak/Smalltalk][squeak] VM and Polyglot Programming Environment for the [Gr

## Getting Started

1. Download the latest [GraalVM distribution][graalvm_download] for your platform.
2. Use the [GraalVM Updater][graalvm_updater] to install the TruffleSqueak
component for your platform:
1. Download and extract the latest [TruffleSqueak standalone][ts_latest] for your platform.
2. Run the following in a terminal to start TruffleSqueak:

```bash
$GRAALVM_HOME/bin/gu \
-C https://raw.githubusercontent.com/hpi-swa/trufflesqueak/main/gu-catalog.properties \
install smalltalk
```

3. You should now be able to run TruffleSqueak:

```bash
$GRAALVM_HOME/bin/trufflesqueak
bin/trufflesqueak [<option>...] [<imageName> [<argument>...]]
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -177,7 +176,7 @@ protected void printHelp(final OptionCategory maxCategory) {

@Override
protected void collectArguments(final Set<String> options) {
options.addAll(Arrays.asList(SqueakLanguageOptions.CODE_FLAG, SqueakLanguageOptions.CODE_FLAG_SHORT, SqueakLanguageOptions.HEADLESS_FLAG,
options.addAll(List.of(SqueakLanguageOptions.CODE_FLAG, SqueakLanguageOptions.CODE_FLAG_SHORT, SqueakLanguageOptions.HEADLESS_FLAG,
SqueakLanguageOptions.QUIET_FLAG, SqueakLanguageOptions.PRINT_IMAGE_PATH_FLAG, SqueakLanguageOptions.RESOURCE_SUMMARY_FLAG, SqueakLanguageOptions.TRANSCRIPT_FORWARDING_FLAG));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public final class SqueakLanguageOptions {
public static final String RESOURCE_SUMMARY_HELP = "Print resource summary on context exit";
public static final String SIGNAL_INPUT_SEMAPHORE = "signal-input-semaphore";
public static final String SIGNAL_INPUT_SEMAPHORE_HELP = "Signal the input semaphore";
public static final String STACK_DEPTH_PROTECTION = "stack-depth-protection";
public static final String STACK_DEPTH_PROTECTION_FLAG = "--" + STACK_DEPTH_PROTECTION;
public static final String STACK_DEPTH_PROTECTION_HELP = "Enable stack depth protection";
public static final String STARTUP = "disable-startup";
public static final String STARTUP_HELP = "Disable image startup routine in headless mode";
public static final String TESTING = "testing";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@
import de.hpi.swa.trufflesqueak.model.layout.ObjectLayouts.PROCESS;
import de.hpi.swa.trufflesqueak.model.layout.ObjectLayouts.PROCESS_SCHEDULER;
import de.hpi.swa.trufflesqueak.nodes.accessing.ArrayObjectNodes.ArrayObjectReadNode;
import de.hpi.swa.trufflesqueak.test.SqueakTests.SqueakTest;
import de.hpi.swa.trufflesqueak.util.DebugUtils;

public class AbstractSqueakTestCaseWithImage extends AbstractSqueakTestCase {
private static final int SQUEAK_TIMEOUT_SECONDS = 60 * (DebugUtils.UNDER_DEBUG ? 1000 : 1);
private static final int SQUEAK_TIMEOUT_SECONDS = 90 * (DebugUtils.UNDER_DEBUG ? 1000 : 1);
private static final int TIMEOUT_SECONDS = SQUEAK_TIMEOUT_SECONDS + 2;
private static final int TEST_IMAGE_LOAD_TIMEOUT_SECONDS = 45 * (DebugUtils.UNDER_DEBUG ? 1000 : 1);
private static final int PRIORITY_10_LIST_INDEX = 9;
protected static final String PASSED_VALUE = "passed";
private static final String TEST_IMAGE_FILE_NAME = "test-64bit.image";

protected static final String[] TRUFFLESQUEAK_TEST_CASE_NAMES = truffleSqueakTestCaseNames();

Expand Down Expand Up @@ -123,27 +125,15 @@ protected static final void assumeNotOnMXGate() {
}

private static String getPathToTestImage() {
final String imagePath64bit = getPathToTestImage("test-64bit.image");
if (imagePath64bit != null) {
return imagePath64bit;
}
final String imagePath32bit = getPathToTestImage("test-32bit.image");
if (imagePath32bit != null) {
return imagePath32bit;
}
throw SqueakException.create("Unable to locate test image.");
}

private static String getPathToTestImage(final String imageName) {
Path currentDirectory = Paths.get(System.getProperty("user.dir")).toAbsolutePath();
while (currentDirectory != null) {
final File file = currentDirectory.resolve("images").resolve(imageName).toFile();
final File file = currentDirectory.resolve("images").resolve(TEST_IMAGE_FILE_NAME).toFile();
if (file.exists()) {
return file.getAbsolutePath();
}
currentDirectory = currentDirectory.getParent();
}
return null;
throw SqueakException.create("Unable to locate test image.");
}

/**
Expand Down Expand Up @@ -171,19 +161,21 @@ protected static void patchMethod(final String className, final String selector,
assertNotEquals(NilObject.SINGLETON, patchResult);
}

protected static TestResult runTestCase(final TestRequest request) {
protected static TestResult runTestCase(final SqueakTest test) {
if (testWithImageIsActive) {
throw new IllegalStateException("The previous test case has not finished yet");
}
try {
return runWithTimeout(request, AbstractSqueakTestCaseWithImage::extractFailuresAndErrorsFromTestResult, TIMEOUT_SECONDS);
return runWithTimeout(test, AbstractSqueakTestCaseWithImage::extractFailuresAndErrorsFromTestResult, TIMEOUT_SECONDS);
} catch (final TimeoutException e) {
return TestResult.fromException("did not terminate in " + TIMEOUT_SECONDS + "s", e);
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException("Test was interrupted");
} catch (final ExecutionException e) {
return TestResult.fromException("failed with an error", e.getCause());
} finally {
image.interrupt.clear();
}
}

Expand All @@ -195,7 +187,6 @@ protected static <T, R> R runWithTimeout(final T argument, final Function<T, R>
} finally {
testWithImageIsActive = false;
}

});
try {
return future.get(timeout, TimeUnit.SECONDS);
Expand All @@ -210,16 +201,16 @@ protected static <T, R> R runWithTimeout(final T argument, final Function<T, R>
}
}

private static TestResult extractFailuresAndErrorsFromTestResult(final TestRequest request) {
final Object result = evaluate(testCommand(request));
if (!(result instanceof final NativeObject n) || !n.isByteType()) {
private static TestResult extractFailuresAndErrorsFromTestResult(final SqueakTest test) {
final Object result = evaluate(testCommand(test));
if (!(result instanceof final NativeObject no) || !no.isByteType()) {
return TestResult.failure("did not return a ByteString, got " + result);
}
final String testResult = ((NativeObject) result).asStringUnsafe();
final String testResult = no.asStringUnsafe();
if (PASSED_VALUE.equals(testResult)) {
return TestResult.success();
} else {
final boolean shouldPass = (boolean) evaluate(shouldPassCommand(request));
final boolean shouldPass = (boolean) evaluate(shouldPassCommand(test));
// we cannot estimate or reliably clean up the state of the image after some unknown
// exception was thrown
if (shouldPass) {
Expand All @@ -230,39 +221,28 @@ private static TestResult extractFailuresAndErrorsFromTestResult(final TestReque
}
}

private static String testCommand(final TestRequest request) {
private static String testCommand(final SqueakTest test) {
return String.format("[(%s selector: #%s) runCase. '%s'] on: TestFailure, Error do: [:e | (String streamContents: [:s | e printVerboseOn: s]) withUnixLineEndings ]",
request.testCase, request.testSelector, PASSED_VALUE);
test.className(), test.selector(), PASSED_VALUE);
}

private static String shouldPassCommand(final TestRequest request) {
return String.format("[(%s selector: #%s) shouldPass] on: Error do: [:e | false]", request.testCase, request.testSelector);
private static String shouldPassCommand(final SqueakTest test) {
return String.format("[(%s selector: #%s) shouldPass] on: Error do: [:e | false]", test.className(), test.selector());
}

protected record TestRequest(String testCase, String testSelector) {
}
protected record TestResult(boolean passed, String message, Throwable reason) {

protected static final class TestResult {
private static final TestResult SUCCESS = new TestResult(true, PASSED_VALUE, null);
protected final boolean passed;
protected final String message;
protected final Throwable reason;

private TestResult(final boolean passed, final String message, final Throwable reason) {
this.passed = passed;
this.message = message;
this.reason = reason;
}

protected static TestResult fromException(final String message, final Throwable reason) {
private static TestResult fromException(final String message, final Throwable reason) {
return new TestResult(false, message, reason);
}

protected static TestResult failure(final String message) {
private static TestResult failure(final String message) {
return new TestResult(false, message, null);
}

protected static TestResult success() {
private static TestResult success() {
return SUCCESS;
}
}
Expand All @@ -279,14 +259,15 @@ private static String[] truffleSqueakTestCaseNames() {
}

protected static final String getPathToInImageCode() {
Path currentDirectory = Paths.get(System.getProperty("user.dir")).toAbsolutePath();
final Path userDir = Paths.get(System.getProperty("user.dir")).toAbsolutePath();
Path currentDirectory = userDir;
while (currentDirectory != null) {
final File file = currentDirectory.resolve("src").resolve("image").resolve("src").toFile();
if (file.isDirectory()) {
return file.getAbsolutePath();
}
currentDirectory = currentDirectory.getParent();
}
return null;
throw new IllegalStateException("Unable to find in image code in " + userDir + " and its parents");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -76,7 +75,7 @@ public void testPushLiteralConstants() {
final int bytecodeStart = 32;
final Object[] expectedResults = getTestObjects(32);
final List<Object> literalsList = new ArrayList<>(Collections.singletonList(68419598L));
literalsList.addAll(Arrays.asList(expectedResults));
literalsList.addAll(List.of(expectedResults));
final AbstractSqueakObject rcvr = image.specialObjectsArray;
for (int i = 0; i < expectedResults.length; i++) {
final CompiledCodeObject method = makeMethod(literalsList.toArray(), bytecodeStart + i, 124);
Expand All @@ -95,7 +94,7 @@ public void testPushLiteralVariables() {
final int bytecodeStart = 64;
final Object[] expectedResults = getTestObjects(32);
final List<Object> literalsList = new ArrayList<>(Collections.singletonList(68419598L));
literalsList.addAll(Arrays.asList(expectedResults));
literalsList.addAll(List.of(expectedResults));
final AbstractSqueakObject rcvr = image.specialObjectsArray;
for (int i = 0; i < 32; i++) {
final CompiledCodeObject method = makeMethod(literalsList.toArray(), bytecodeStart + i, 124);
Expand Down Expand Up @@ -202,7 +201,7 @@ public void testExtendedPushTemporaryVariables() {
public void testExtendedPushLiteralConstants() {
final Object[] expectedResults = getTestObjects(64);
final List<Object> literalsList = new ArrayList<>(Collections.singletonList(68419598L));
literalsList.addAll(Arrays.asList(expectedResults));
literalsList.addAll(List.of(expectedResults));
final AbstractSqueakObject rcvr = image.specialObjectsArray;
for (int i = 0; i < expectedResults.length; i++) {
final CompiledCodeObject method = makeMethod(literalsList.toArray(), 128, 128 + i, 124);
Expand All @@ -220,7 +219,7 @@ public void testExtendedPushLiteralConstants() {
public void testExtendedPushLiteralVariables() {
final Object[] expectedResults = getTestObjects(64);
final List<Object> literalsList = new ArrayList<>(Collections.singletonList(68419598L));
literalsList.addAll(Arrays.asList(expectedResults));
literalsList.addAll(List.of(expectedResults));
final AbstractSqueakObject rcvr = image.specialObjectsArray;
for (int i = 0; i < expectedResults.length; i++) {
final CompiledCodeObject method = makeMethod(literalsList.toArray(), 128, 192 + i, 124);
Expand Down Expand Up @@ -361,7 +360,7 @@ public void testDoubleExtendedPushReceiverVariables() {
public void testDoubleExtendedPushLiteralConstants() {
final Object[] expectedResults = getTestObjects(255);
final List<Object> literalsList = new ArrayList<>(Collections.singletonList(68419598L));
literalsList.addAll(Arrays.asList(expectedResults));
literalsList.addAll(List.of(expectedResults));
final AbstractSqueakObject rcvr = image.specialObjectsArray;
for (int i = 0; i < expectedResults.length; i++) {
final CompiledCodeObject method = makeMethod(literalsList.toArray(), 132, 96, i, 124);
Expand All @@ -379,7 +378,7 @@ public void testDoubleExtendedPushLiteralConstants() {
public void testDoubleExtendedPushLiteralVariables() {
final Object[] expectedResults = getTestObjects(255);
final List<Object> literalsList = new ArrayList<>(Collections.singletonList(68419598L));
literalsList.addAll(Arrays.asList(expectedResults));
literalsList.addAll(List.of(expectedResults));
final AbstractSqueakObject rcvr = image.specialObjectsArray;
for (int i = 0; i < expectedResults.length; i++) {
final CompiledCodeObject method = makeMethod(literalsList.toArray(), 132, 128, i, 124);
Expand Down
Loading

0 comments on commit a4d180f

Please sign in to comment.