package com.oracle.truffle.llvm.tests.debug;
import com.oracle.truffle.llvm.runtime.options.SulongEngineOption;
import com.oracle.truffle.llvm.tests.options.TestOptions;
import com.oracle.truffle.llvm.tests.Platform;
import org.graalvm.polyglot.Context;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.Set;
@RunWith(Parameterized.class)
public final class LLVMIRDebugTest extends LLVMDebugTestBase {
private static final String CONFIGURATION = "O0.bc";
private static final Path BC_DIR_PATH = Paths.get(TestOptions.TEST_SUITE_PATH, "irdebug");
private static final Path SRC_DIR_PATH = Paths.get(TestOptions.PROJECT_ROOT, "..", "tests", "com.oracle.truffle.llvm.tests.irdebug.native", "irdebug");
private static final Path TRACE_DIR_PATH = Paths.get(TestOptions.PROJECT_ROOT, "..", "tests", "com.oracle.truffle.llvm.tests.irdebug.native", "trace");
private static final String OPTION_LLDEBUG = "llvm.llDebug";
private static final String OPTION_LLDEBUG_SOURCES = "llvm.llDebug.sources";
@Parameters(name = "{0}")
public static Collection<Object[]> getConfigurations() {
try (Stream<Path> dirs = Files.walk(BC_DIR_PATH)) {
Set<String> blacklist = getBlacklist();
Collection<Object[]> testlist = dirs.filter(path -> path.endsWith(CONFIGURATION)).map(path -> new Object[]{getTestSource(path), CONFIGURATION}).collect(Collectors.toSet());
testlist.removeIf(t -> blacklist.contains(t[0]));
return testlist;
} catch (IOException e) {
throw new AssertionError("Error while finding tests!", e);
}
}
protected static Set<String> getBlacklist() {
Set<String> filenameBlacklist = new HashSet<>();
if (Platform.isAArch64()) {
filenameBlacklist.addAll(Arrays.asList("primitives.ll"));
}
return filenameBlacklist;
}
private static String getTestSource(Path path) {
String filename = path.getParent().getFileName().toString();
if (filename.endsWith(TEST_FOLDER_EXT)) {
return filename.substring(0, filename.length() - TEST_FOLDER_EXT.length());
}
return filename;
}
public LLVMIRDebugTest(String testName, String configuration) {
super(testName, configuration);
}
@Override
void setContextOptions(Context.Builder contextBuilder) {
contextBuilder.option(OPTION_LLDEBUG, String.valueOf(true));
contextBuilder.option(SulongEngineOption.LL_DEBUG_VERBOSE_NAME, String.valueOf(false));
final String sourceMapping = String.format("%s=%s", loadBitcodeSource().getPath(), loadOriginalSource().getPath());
contextBuilder.option(OPTION_LLDEBUG_SOURCES, sourceMapping);
}
@Override
Path getBitcodePath() {
return BC_DIR_PATH;
}
@Override
Path getSourcePath() {
return SRC_DIR_PATH;
}
@Override
Path getTracePath() {
return TRACE_DIR_PATH;
}
}