GP-0: Fix some tests (mock.slaspec, register count)

This commit is contained in:
Dan
2025-01-06 11:41:55 -05:00
parent acf5ac688a
commit ea95c146b5
4 changed files with 37 additions and 18 deletions
@@ -53,7 +53,8 @@ public enum TraceObjectInterfaceUtils {
List<TraceObjectInterfaceFactory> instances = List<TraceObjectInterfaceFactory> instances =
ClassSearcher.getInstances(TraceObjectInterfaceFactory.class); ClassSearcher.getInstances(TraceObjectInterfaceFactory.class);
if (instances.isEmpty()) { if (instances.isEmpty()) {
Msg.warn(this, "ClassSearcher not active, yet. Falling back to built-ins"); Msg.warn(this, "ClassSearcher not active, yet. " +
"Falling back to built-in TraceObjectInterfaces.");
instances = List.of(new BuiltinTraceObjectInterfaceFactory()); instances = List.of(new BuiltinTraceObjectInterfaceFactory());
} }
mapByClass = instances mapByClass = instances
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -32,16 +32,24 @@ import ghidra.util.Msg;
import resources.ResourceManager; import resources.ResourceManager;
public class SleighLanguageHelper { public class SleighLanguageHelper {
private static SleighLanguage MOCK_BE_64_LANGUAGE;
private static ResourceFile getResourceFile(String name) { private static ResourceFile getResourceFile(String name) {
URL url = ResourceManager.getResource(name); URL url = ResourceManager.getResource(name);
if (url == null) { if (url == null) {
return null; return null;
} }
return new ResourceFile(url.getPath()); ResourceFile maybeInJar = new ResourceFile(url.toExternalForm());
ResourceFile notInJar = new ResourceFile(maybeInJar.getFile(true));
return notInJar;
} }
public static SleighLanguage getMockBE64Language() public synchronized static SleighLanguage getMockBE64Language()
throws DecoderException, UnknownInstructionException, SAXException, IOException { throws DecoderException, UnknownInstructionException, SAXException, IOException {
if (MOCK_BE_64_LANGUAGE != null) {
return MOCK_BE_64_LANGUAGE;
}
ResourceFile cSpecFile = getResourceFile("mock.cpsec"); ResourceFile cSpecFile = getResourceFile("mock.cpsec");
CompilerSpecDescription cSpecDesc = CompilerSpecDescription cSpecDesc =
@@ -50,6 +58,7 @@ public class SleighLanguageHelper {
ResourceFile pSpecFile = getResourceFile("mock.pspec"); ResourceFile pSpecFile = getResourceFile("mock.pspec");
ResourceFile slaSpecFile = getResourceFile("mock.slaspec"); ResourceFile slaSpecFile = getResourceFile("mock.slaspec");
ResourceFile slaFile = getResourceFile("mock.sla"); ResourceFile slaFile = getResourceFile("mock.sla");
if (slaFile == null || !slaFile.exists() || if (slaFile == null || !slaFile.exists() ||
(slaSpecFile.lastModified() > slaFile.lastModified())) { (slaSpecFile.lastModified() > slaFile.lastModified())) {
assertNotNull("Cannot find mock.slaspec", slaSpecFile); assertNotNull("Cannot find mock.slaspec", slaSpecFile);
@@ -61,8 +70,8 @@ public class SleighLanguageHelper {
catch (IOException | RecognitionException e) { catch (IOException | RecognitionException e) {
throw new AssertionError(e); throw new AssertionError(e);
} }
slaFile = getResourceFile("mock.sla"); slaFile = new ResourceFile(slaSpecFile.getParentFile(), "mock.sla");
assertNotNull("Cannot find mock.sla (after compilation)"); assertTrue("Cannot find mock.sla (after compilation)", slaFile.exists());
} }
SleighLanguageDescription langDesc = new SleighLanguageDescription( SleighLanguageDescription langDesc = new SleighLanguageDescription(
@@ -74,12 +83,14 @@ public class SleighLanguageHelper {
0, // minor version 0, // minor version
false, // deprecated false, // deprecated
new HashMap<>(), // truncatedSpaceMap new HashMap<>(), // truncatedSpaceMap
new ArrayList<>(List.of(cSpecDesc)), new HashMap<>() // externalNames new ArrayList<>(List.of(cSpecDesc)), // compiler specs
new HashMap<>() // externalNames
); );
langDesc.setDefsFile(lDefsFile); langDesc.setDefsFile(lDefsFile);
langDesc.setSpecFile(pSpecFile); langDesc.setSpecFile(pSpecFile);
langDesc.setSlaFile(slaFile); langDesc.setSlaFile(slaFile);
return new SleighLanguage(langDesc); MOCK_BE_64_LANGUAGE = new SleighLanguage(langDesc);
return MOCK_BE_64_LANGUAGE;
} }
} }
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,9 +30,10 @@ import utilities.util.FileUtilities;
*/ */
public class ResourceFile implements Comparable<ResourceFile> { public class ResourceFile implements Comparable<ResourceFile> {
private static final String JAR_FILE_PREFIX = "jar:file:"; private static final String FILE_PREFIX = "file:";
private Resource resource; private static final String JAR_FILE_PREFIX = "jar:" + FILE_PREFIX;
private static Map<String, JarResource> jarRootsMap = new HashMap<>(); private final Resource resource;
private static final Map<String, JarResource> jarRootsMap = new HashMap<>();
/** /**
* Construct a ResourceFile that represents a normal file in the file system. * Construct a ResourceFile that represents a normal file in the file system.
@@ -93,7 +94,13 @@ public class ResourceFile implements Comparable<ResourceFile> {
throw new IllegalArgumentException("Failed to open jar: " + filePath, e); throw new IllegalArgumentException("Failed to open jar: " + filePath, e);
} }
} }
resource = new FileResource(new File(absolutePath)); else if (absolutePath.startsWith(FILE_PREFIX)) {
String filePath = absolutePath.substring(FILE_PREFIX.length());
resource = new FileResource(new File(filePath));
}
else {
resource = new FileResource(new File(absolutePath));
}
} }
/** /**
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -563,7 +563,7 @@ public class DebuggerTraceRegistersProviderTest extends AbstractDebuggerRegister
waitForDialogComponent(DebuggerAvailableRegistersDialog.class); waitForDialogComponent(DebuggerAvailableRegistersDialog.class);
List<AvailableRegisterRow> modelData = dialog.availableTableModel.getModelData(); List<AvailableRegisterRow> modelData = dialog.availableTableModel.getModelData();
assertEquals(52, modelData.size()); assertEquals(getPlatform().getLanguage().getRegisters().size(), modelData.size());
AvailableRegisterRow pcAvail = AvailableRegisterRow pcAvail =
modelData.stream().filter(r -> r.getRegister() == pc).findFirst().orElse(null); modelData.stream().filter(r -> r.getRegister() == pc).findFirst().orElse(null);
assertNotNull(pcAvail); assertNotNull(pcAvail);