Windows test fixes; Test cleanup

This commit is contained in:
dragonmacher
2026-03-02 21:40:26 +00:00
parent 1d779fd600
commit 441a328262
27 changed files with 159 additions and 138 deletions
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -185,7 +185,7 @@ public class ProjectExperimentsTest extends AbstractGhidraHeadedIntegrationTest
ProjectData data = env.getProject().getProjectData();
data.addDomainFolderChangeListener(rdfl);
ToyProgramBuilder b = new ToyProgramBuilder("test", true);
ToyProgramBuilder b = new ToyProgramBuilder();
Program program = b.getProgram();
data.getRootFolder().createFile(program.getName(), program, new ConsoleTaskMonitor());
@@ -201,7 +201,7 @@ public class ProjectExperimentsTest extends AbstractGhidraHeadedIntegrationTest
ProjectData data = env.getProject().getProjectData();
data.addDomainFolderChangeListener(rdfl);
ToyProgramBuilder b = new ToyProgramBuilder("test", true);
ToyProgramBuilder b = new ToyProgramBuilder();
Program program = b.getProgram();
DomainFolder myFolder = data.getRootFolder().createFolder("MyFolder");
DomainFile file = myFolder.createFile(program.getName(), program, new ConsoleTaskMonitor());
@@ -223,7 +223,7 @@ public class ProjectExperimentsTest extends AbstractGhidraHeadedIntegrationTest
ProjectData data = env.getProject().getProjectData();
data.addDomainFolderChangeListener(rdfl);
ToyProgramBuilder b = new ToyProgramBuilder("test", true);
ToyProgramBuilder b = new ToyProgramBuilder();
Program program = b.getProgram();
DomainFolder myFolder = data.getRootFolder().createFolder("MyFolder");
myFolder.createFile(program.getName(), program, new ConsoleTaskMonitor());
@@ -51,6 +51,7 @@ import ghidra.program.model.util.*;
import ghidra.program.util.DefaultLanguageService;
import ghidra.program.util.GhidraProgramUtilities;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.TestEnv;
import ghidra.util.*;
import ghidra.util.exception.*;
import ghidra.util.task.TaskMonitor;
@@ -59,6 +60,8 @@ import utility.function.ExceptionalCallback;
// TODO: Move this class into a different package (i.e., ghidra.test.program)
public class ProgramBuilder {
private static Set<ProgramBuilder> allBuilders = new HashSet<>();
public static final String _ARM = "ARM:LE:32:v7";
public static final String _AARCH64 = "AARCH64:LE:64:v8A";
public static final String _X86 = "x86:LE:32:default";
@@ -138,6 +141,9 @@ public class ProgramBuilder {
CompilerSpec compilerSpec = compilerSpecID == null ? language.getDefaultCompilerSpec()
: language.getCompilerSpecByID(new CompilerSpecID(compilerSpecID));
program = new ProgramDB(name, language, compilerSpec, consumer == null ? this : consumer);
allBuilders.add(this);
setAnalyzed();
program.setTemporary(true); // ignore changes
}
@@ -151,6 +157,9 @@ public class ProgramBuilder {
public ProgramBuilder(String name, Language language) throws Exception {
CompilerSpec compilerSpec = language.getDefaultCompilerSpec();
program = new ProgramDB(name, language, compilerSpec, this);
allBuilders.add(this);
setAnalyzed();
program.setTemporary(true); // ignore changes
}
@@ -214,7 +223,19 @@ public class ProgramBuilder {
return addr;
}
/**
* A methods called by {@link TestEnv} to cleanup all resources.
*/
public static void disposeAllBuilders() {
HashSet<ProgramBuilder> set = new HashSet<>(allBuilders);
allBuilders.clear();
for (ProgramBuilder builder : set) {
builder.dispose();
}
}
public void dispose() {
allBuilders.remove(this);
if (program.isUsedBy(this)) {
// Make sure any buffered events are processed before we release. This fixes a timing
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -145,6 +145,10 @@ public class ProjectTestUtils {
File secondLockFile = new File(lockFile.getAbsolutePath() + "~");
if (secondLockFile.exists()) {
deleted = secondLockFile.delete();
if (!deleted) {
Msg.warn(ProjectTestUtils.class, "Unable to delete the second lock file: " + secondLockFile);
}
}
return deleted;
@@ -50,6 +50,7 @@ import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.util.PluginException;
import ghidra.framework.project.DefaultProjectManager;
import ghidra.framework.protocol.ghidra.GhidraURL;
import ghidra.program.database.ProgramBuilder;
import ghidra.program.database.ProgramDB;
import ghidra.program.model.data.FileDataTypeManager;
import ghidra.program.model.lang.*;
@@ -1075,6 +1076,8 @@ public class TestEnv {
privateWaitForSwingRunnables();
programManager.disposeOpenPrograms();
ProgramBuilder.disposeAllBuilders();
if (gp.getProject() == null) {
throw new IllegalStateException("The TestEnv's GhidraProject has already been closed!");
}
@@ -34,18 +34,11 @@ public class ToyProgramBuilder extends ProgramBuilder {
private List<Address> definedInstrAddresses;
/**
* Construct toy program builder using specified toy language
* @param name program name
* @param languageName toy language ID (note: only builder variant supports all instructions)
* @param consumer program consumer (if null this builder will be used as consumer and must be disposed to release program)
* @throws Exception
* Default toy program using the default big endian language.
* @throws Exception if there are any exceptions
*/
public ToyProgramBuilder(String name, String languageName, Object consumer) throws Exception {
super(name, checkLanguageName(languageName), consumer);
Program program = getProgram();
addrFactory = program.getAddressFactory();
defaultSpace = addrFactory.getDefaultAddressSpace();
definedInstrAddresses = new ArrayList<>();
public ToyProgramBuilder() throws Exception {
this("TestProgram", true);
}
/**
@@ -53,7 +46,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* This builder will be the program consumer and must be disposed
* @param name program name
* @param bigEndian language endianness
* @throws Exception
* @throws Exception if there are any exceptions
*/
public ToyProgramBuilder(String name, boolean bigEndian) throws Exception {
this(name, bigEndian, false, null);
@@ -64,8 +57,9 @@ public class ToyProgramBuilder extends ProgramBuilder {
* This builder will be the program consumer and must be disposed
* @param name program name
* @param bigEndian language endianness
* @param consumer program consumer (if null this builder will be used as consumer and must be disposed to release program)
* @throws Exception
* @param consumer program consumer (if null this builder will be used as consumer and must be
* disposed to release program)
* @throws Exception if there are any exceptions
*/
public ToyProgramBuilder(String name, boolean bigEndian, Object consumer) throws Exception {
this(name, bigEndian, false, consumer);
@@ -76,8 +70,10 @@ public class ToyProgramBuilder extends ProgramBuilder {
* This builder will be the program consumer and must be disposed
* @param name program name
* @param bigEndian language endianness
* @param consumer program consumer (if null this builder will be used as consumer and must be disposed to release program)
* @throws Exception
* @param wordAligned true if word aligned
* @param consumer program consumer (if null this builder will be used as consumer and must be
* disposed to release program)
* @throws Exception if there are any exceptions
*/
public ToyProgramBuilder(String name, boolean bigEndian, boolean wordAligned, Object consumer)
throws Exception {
@@ -95,13 +91,6 @@ public class ToyProgramBuilder extends ProgramBuilder {
return bigEndian ? TOY_LANGUAGE_ID_BE : TOY_LANGUAGE_ID_LE;
}
private static String checkLanguageName(String languageName) {
if (!languageName.startsWith(_TOY_LANGUAGE_PREFIX)) {
throw new IllegalArgumentException("Toy language required");
}
return languageName;
}
/**
* Get address in default ram space
* @param offset address offset
@@ -190,7 +179,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add NOP instruction bytes of specified byte length
* @param offset instruction address offset
* @param length length of NOP instruction in bytes
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesNOP(long offset, int length) throws MemoryAccessException {
addBytesNOP(toHex(offset), length);
@@ -200,7 +189,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add NOP instruction bytes of specified byte length
* @param addr instruction address
* @param length length of NOP instruction in bytes
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesNOP(String addr, int length) throws MemoryAccessException {
if (length == 1) {
@@ -224,7 +213,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
/**
* Add simple fall-through (consumes 2-bytes)
* @param offset instruction address offset
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesFallthrough(long offset) throws MemoryAccessException {
addBytesFallthrough(toHex(offset));
@@ -233,7 +222,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
/**
* Add simple fall-through (consumes 2-bytes)
* @param addr instruction address
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesFallthrough(String addr) throws MemoryAccessException {
addInstructionWords(addr(addr), (short) 0xd100); // or r0,r0,r0
@@ -244,7 +233,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* @param offset instruction address offset
* @param srcRegIndex source register index (0..15)
* @param destRegIndex destination register index (contained indirect memory address) (0..15)
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesStore(long offset, int srcRegIndex, int destRegIndex)
throws MemoryAccessException {
@@ -256,7 +245,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* @param addr instruction address
* @param srcRegIndex source register index (0..15)
* @param destRegIndex destination register index (contained indirect memory address) (0..15)
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesStore(String addr, int srcRegIndex, int destRegIndex)
throws MemoryAccessException {
@@ -269,7 +258,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* @param offset instruction address offset
* @param srcRegIndex source register index (contained indirect memory address) (0..15)
* @param destRegIndex destination register index (0..15)
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesLoad(long offset, int srcRegIndex, int destRegIndex)
throws MemoryAccessException {
@@ -281,7 +270,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* @param addr instruction address
* @param srcRegIndex source register index (contained indirect memory address) (0..15)
* @param destRegIndex destination register index (0..15)
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesLoad(String addr, int srcRegIndex, int destRegIndex)
throws MemoryAccessException {
@@ -293,7 +282,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add move immediate instruction (consumes 2-bytes)
* @param offset instruction offset
* @param imm immediate byte value
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesMoveImmediate(long offset, short imm) throws MemoryAccessException {
addBytesMoveImmediate(toHex(offset), imm);
@@ -303,7 +292,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add move immediate instruction (consumes 2-bytes)
* @param addr instruction address
* @param imm immediate byte value
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesMoveImmediate(String addr, short imm) throws MemoryAccessException {
addInstructionWords(addr(addr), (short) ((imm & 0x700) << 4 | (imm & 0xff))); // imm r0,#<imm>
@@ -313,7 +302,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add simple fall-through which sets noflow context value on next instruction (consumes 2-bytes)
* @param offset instruction address offset
* @param ctxVal context value (0-15)
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesFallthroughSetNoFlowContext(long offset, int ctxVal)
throws MemoryAccessException {
@@ -324,7 +313,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add simple fall-through which sets noflow context value on next instruction (consumes 2-bytes)
* @param addr instruction address
* @param ctxVal context value (0-15)
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesFallthroughSetNoFlowContext(String addr, int ctxVal)
throws MemoryAccessException {
@@ -336,7 +325,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* @param offset instruction address offset
* @param ctxVal context value (0-15)
* @param target context target address offset
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesFallthroughSetNoFlowContext(long offset, int ctxVal, long target)
throws MemoryAccessException {
@@ -348,7 +337,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* @param addr instruction address
* @param ctxVal context value (0-15)
* @param targetAddr context target address
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesFallthroughSetNoFlowContext(String addr, int ctxVal, String targetAddr)
throws MemoryAccessException {
@@ -362,7 +351,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add simple fall-through which sets flowing context value on next instruction (consumes 2-bytes)
* @param offset instruction address offset
* @param ctxVal context value (0-15)
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesFallthroughSetFlowContext(long offset, int ctxVal)
throws MemoryAccessException {
@@ -373,7 +362,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add simple fall-through which sets flowing context value on next instruction (consumes 2-bytes)
* @param addr instruction address
* @param ctxVal context value (0-15)
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesFallthroughSetFlowContext(String addr, int ctxVal)
throws MemoryAccessException {
@@ -384,7 +373,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add call (consumes 2-bytes)
* @param offset instruction address offset
* @param dest call destination offset
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesCall(long offset, long dest) throws MemoryAccessException {
addBytesCall(toHex(offset), toHex(dest));
@@ -394,7 +383,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add call (consumes 2-bytes)
* @param offset instruction address offset
* @param dest call destination offset
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesCall(String offset, long dest) throws MemoryAccessException {
addBytesCall(offset, toHex(dest));
@@ -404,7 +393,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add call (consumes 2-bytes)
* @param addr instruction address
* @param destAddr call destination address
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesCall(String addr, String destAddr) throws MemoryAccessException {
Address address = addr(addr);
@@ -417,7 +406,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add call w/ delayslot (consumes 4-bytes)
* @param offset instruction address offset
* @param dest call destination offset
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesCallWithDelaySlot(long offset, long dest) throws MemoryAccessException {
addBytesCallWithDelaySlot(toHex(offset), toHex(dest));
@@ -427,7 +416,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add call w/ delayslot (consumes 4-bytes)
* @param addr instruction address
* @param destAddr call destination address
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesCallWithDelaySlot(String addr, String destAddr)
throws MemoryAccessException {
@@ -441,7 +430,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
/**
* Add terminal/return (consumes 2-bytes)
* @param offset instruction address offset
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesReturn(long offset) throws MemoryAccessException {
addBytesReturn(toHex(offset));
@@ -450,7 +439,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
/**
* Add terminal/return (consumes 2-bytes)
* @param addr instruction address
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesReturn(String addr) throws MemoryAccessException {
addInstructionWords(addr(addr), (short) 0xf400); // ret
@@ -460,7 +449,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add branch (consumes 2-bytes)
* @param offset address offset
* @param dest call destination offset
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesBranch(long offset, long dest) throws MemoryAccessException {
addBytesBranch(toHex(offset), toHex(dest));
@@ -470,7 +459,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add branch (consumes 2-bytes)
* @param addr instruction address offset
* @param destAddr call destination address
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesBranch(String addr, String destAddr) throws MemoryAccessException {
Address address = addr(addr);
@@ -483,7 +472,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add branch (consumes 2-bytes)
* @param offset instruction address offset
* @param dest call destination offset
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesBranchConditional(long offset, long dest) throws MemoryAccessException {
addBytesBranchConditional(toHex(offset), toHex(dest));
@@ -493,7 +482,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add branch (consumes 2-bytes)
* @param addr instruction address
* @param destAddr call destination address
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesBranchConditional(String addr, String destAddr)
throws MemoryAccessException {
@@ -506,7 +495,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
/**
* Add conditional skip (consumes 2-bytes)
* @param offset instruction address offset
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesSkipConditional(long offset) throws MemoryAccessException {
addBytesSkipConditional(toHex(offset));
@@ -515,7 +504,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
/**
* Add conditional skip (consumes 2-bytes)
* @param addr instruction address
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesSkipConditional(String addr) throws MemoryAccessException {
Address address = addr(addr);
@@ -526,7 +515,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add branch w/ delay slot (consumes 4-bytes)
* @param offset instruction address offset
* @param dest call destination offset
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesBranchWithDelaySlot(long offset, long dest) throws MemoryAccessException {
addBytesBranchWithDelaySlot(toHex(offset), toHex(dest));
@@ -536,7 +525,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add branch w/ delay slot (consumes 4-bytes)
* @param addr instruction address
* @param destAddr call destination address
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesBranchWithDelaySlot(String addr, String destAddr)
throws MemoryAccessException {
@@ -551,7 +540,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add COP instruction for exercising nfctx context (consumes 2-bytes). Location will not be added to
* defined instruction address list.
* @param offset instruction address offset
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesCopInstruction(long offset) throws MemoryAccessException {
addBytesCopInstruction(toHex(offset));
@@ -561,7 +550,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add COP instruction for exercising nfctx context (consumes 2-bytes). Location will not be added to
* defined instruction address list.
* @param addr instruction address
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesCopInstruction(String addr) throws MemoryAccessException {
addInstructionWords(addr(addr), (short) 0xda00);
@@ -571,7 +560,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add BAD instruction (consumes 2-bytes). Location will not be added to
* defined instruction address list.
* @param offset bad instruction address offset
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesBadInstruction(long offset) throws MemoryAccessException {
addBytesBadInstruction(toHex(offset));
@@ -581,7 +570,7 @@ public class ToyProgramBuilder extends ProgramBuilder {
* Add BAD instruction (consumes 2-bytes). Location will not be added to
* defined instruction address list.
* @param addr bad instruction address
* @throws MemoryAccessException
* @throws MemoryAccessException shouldn't happen
*/
public void addBytesBadInstruction(String addr) throws MemoryAccessException {
// do not add to definedInstrAddresses
@@ -48,10 +48,6 @@ public class DataReferencesTest extends AbstractGhidraHeadedIntegrationTest {
private TestEnv env;
private PluginTool tool;
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*/
@Before
public void setUp() throws Exception {
env = new TestEnv();
@@ -81,7 +77,6 @@ public class DataReferencesTest extends AbstractGhidraHeadedIntegrationTest {
@After
public void tearDown() {
env.release(program);
env.dispose();
}
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -39,8 +39,7 @@ import ghidra.program.database.ProgramDB;
import ghidra.program.model.data.*;
import ghidra.program.model.data.StandAloneDataTypeManager.LanguageUpdateOption;
import ghidra.program.model.lang.*;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.TestEnv;
import ghidra.test.*;
import ghidra.util.InvalidNameException;
import ghidra.util.Msg;
import ghidra.util.task.TaskMonitor;
@@ -57,7 +56,7 @@ public abstract class AbstractCreateArchiveTest extends AbstractGhidraHeadedInte
protected TreeModelModCounter treeModelModListener;
protected ProgramDB buildProgram() throws Exception {
ProgramBuilder builder = new ProgramBuilder("notepad", ProgramBuilder._TOY, this);
ProgramBuilder builder = new ToyProgramBuilder();
builder.createMemory(".text", "0x1001000", 0x6600);
builder.createMemory(".data", "0x1008000", 0x600);
@@ -242,7 +241,6 @@ public abstract class AbstractCreateArchiveTest extends AbstractGhidraHeadedInte
// this handles the save changes dialog and potential analysis dialogs
closeAllWindows();
env.release(program);
env.dispose();
}
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,7 +26,8 @@ import docking.action.DockingActionIf;
import docking.widgets.tree.GTreeNode;
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
import ghidra.app.plugin.core.datamgr.actions.UpdateSourceArchiveNamesAction;
import ghidra.app.plugin.core.datamgr.archive.*;
import ghidra.app.plugin.core.datamgr.archive.Archive;
import ghidra.app.plugin.core.datamgr.archive.DataTypeManagerHandler;
import ghidra.app.plugin.core.datamgr.tree.*;
import ghidra.app.services.DataTypeManagerService;
import ghidra.app.services.ProgramManager;
@@ -35,8 +36,7 @@ import ghidra.framework.plugintool.PluginTool;
import ghidra.program.database.ProgramBuilder;
import ghidra.program.database.ProgramDB;
import ghidra.program.model.data.*;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.TestEnv;
import ghidra.test.*;
import ghidra.util.task.TaskMonitor;
import utilities.util.FileUtilities;
@@ -111,7 +111,7 @@ public class ArchiveRemappedHeadedTest extends AbstractGhidraHeadedIntegrationTe
}
private ProgramDB buildProgram() throws Exception {
ProgramBuilder builder = new ProgramBuilder("notepad", ProgramBuilder._TOY, this);
ProgramBuilder builder = new ToyProgramBuilder();
return builder.getProgram();
}
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,6 +29,7 @@ import ghidra.program.database.ProgramBuilder;
import ghidra.program.database.ProgramDB;
import ghidra.program.model.data.DataTypeManager;
import ghidra.test.AbstractGhidraHeadlessIntegrationTest;
import ghidra.test.ToyProgramBuilder;
import ghidra.util.task.TaskMonitor;
import utilities.util.FileUtilities;
@@ -67,7 +68,7 @@ public class ArchiveRemappedHeadlessTest extends AbstractGhidraHeadlessIntegrati
}
private ProgramDB buildProgram() throws Exception {
ProgramBuilder builder = new ProgramBuilder("notepad", ProgramBuilder._TOY, this);
ProgramBuilder builder = new ToyProgramBuilder();
return builder.getProgram();
}
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -164,7 +164,7 @@ public class CreateArchive1Test extends AbstractCreateArchiveTest {
// verify that the archive was saved by opening it again and checking it has the right stuff.
// create file to cause a name collision
File file = writeTempFile("MyArchive.gdt");
writeTempFile("MyArchive.gdt");
int insertedCount = getTreeModelInsertedNodeCount();
Msg.trace(this, testName.getMethodName() + ":NODE COUNT: " + insertedCount);
@@ -258,7 +258,7 @@ public class CreateArchive1Test extends AbstractCreateArchiveTest {
// verify that the archive did not get saved to that name.
// create file to cause a name collision
File file = writeTempFile("MyArchive.gdt");
writeTempFile("MyArchive.gdt");
createNewArchive("MyArchive.gdt", false);
@@ -60,7 +60,7 @@ public class EnumEditor1Test extends AbstractGhidraHeadedIntegrationTest {
tool.addPlugin(DataTypeManagerPlugin.class.getName());
plugin = getPlugin(tool, DataTypeManagerPlugin.class);
ToyProgramBuilder builder = new ToyProgramBuilder("notepad", true);
ToyProgramBuilder builder = new ToyProgramBuilder();
builder.addCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
program = builder.getProgram();
@@ -620,7 +620,7 @@ public class EnumEditor1Test extends AbstractGhidraHeadedIntegrationTest {
Enum enummDt = createRedGreenBlueEnum();
DataTypeManager dtm = program.getListing().getDataTypeManager();
enummDt = (Enum) enummDt.clone(dtm);
enummDt = enummDt.clone(dtm);
edit(enummDt);
@@ -641,7 +641,7 @@ public class EnumEditor1Test extends AbstractGhidraHeadedIntegrationTest {
Enum enummDt = createRedGreenBlueEnum();
DataTypeManager dtm = program.getListing().getDataTypeManager();
enummDt = (Enum) enummDt.clone(dtm);
enummDt = enummDt.clone(dtm);
edit(enummDt);
@@ -695,7 +695,7 @@ public class EnumEditor1Test extends AbstractGhidraHeadedIntegrationTest {
Enum enummDt = createRedGreenBlueEnum();
DataTypeManager dtm = program.getListing().getDataTypeManager();
enummDt = (Enum) enummDt.clone(dtm);
enummDt = enummDt.clone(dtm);
edit(enummDt);
@@ -1204,7 +1204,7 @@ public class EnumEditor1Test extends AbstractGhidraHeadedIntegrationTest {
private JTextField getTextField(Container container, String name) {
Component[] c = container.getComponents();
for (Component element : c) {
if ((element instanceof JTextField) && ((JTextField) element).getName().equals(name)) {
if ((element instanceof JTextField) && element.getName().equals(name)) {
return (JTextField) element;
}
if (element instanceof Container) {
@@ -47,7 +47,7 @@ public class EnumEditor2Test extends AbstractGhidraHeadedIntegrationTest {
@Before
public void setUp() throws Exception {
ToyProgramBuilder builder = new ToyProgramBuilder("notepad", true);
ToyProgramBuilder builder = new ToyProgramBuilder();
builder.addCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
program = builder.getProgram();
@@ -804,7 +804,7 @@ public class EnumEditor2Test extends AbstractGhidraHeadedIntegrationTest {
private JTextField getTextField(Container container, String name) {
Component[] c = container.getComponents();
for (Component element : c) {
if ((element instanceof JTextField) && ((JTextField) element).getName().equals(name)) {
if ((element instanceof JTextField) && element.getName().equals(name)) {
return (JTextField) element;
}
if (element instanceof Container) {
@@ -880,7 +880,7 @@ public class EnumEditor2Test extends AbstractGhidraHeadedIntegrationTest {
Component[] c = container.getComponents();
for (Component element : c) {
if (element instanceof JLabel) {
if (name.equals(((JLabel) element).getName())) {
if (name.equals(element.getName())) {
return ((JLabel) element).getText();
}
}
@@ -185,7 +185,7 @@ public class GoToAddressLabelPluginWithNamespaceTest extends AbstractGhidraHeade
}
private void buildProgram() throws Exception {
ToyProgramBuilder builder = new ToyProgramBuilder("Test", false);
ToyProgramBuilder builder = new ToyProgramBuilder();
builder.createMemory("Block1", "0x1000", 1000);
@@ -60,7 +60,7 @@ public class LabelFieldFactoryTest extends AbstractGhidraHeadedIntegrationTest {
}
private ProgramDB buildProgram() throws Exception {
ToyProgramBuilder builder = new ToyProgramBuilder("notepad", true);
ToyProgramBuilder builder = new ToyProgramBuilder();
builder.createMemory(".text", "1001000", 0x4000);
builder.addBytesNOP("1002000", 6);
@@ -75,7 +75,7 @@ public class PlateFieldFactoryTest extends AbstractGhidraHeadedIntegrationTest {
}
private ProgramDB buildProgram() throws Exception {
ToyProgramBuilder builder = new ToyProgramBuilder("notepad", true);
ToyProgramBuilder builder = new ToyProgramBuilder();
builder.createMemory(".text", "0x1001000", 0x6600);
builder.createEntryPoint("0x1001100", "entry");
@@ -58,7 +58,7 @@ public class PostCommentFieldFactoryTest extends AbstractGhidraHeadedIntegration
}
private ProgramDB buildProgram() throws Exception {
ToyProgramBuilder builder = new ToyProgramBuilder("notepad", true);
ToyProgramBuilder builder = new ToyProgramBuilder();
builder.createMemory(".text", "0x1001000", 0x10000);
builder.createEmptyFunction(null, "1001000", 1000, null);
@@ -61,7 +61,7 @@ public class PreCommentFieldFactoryTest extends AbstractGhidraHeadedIntegrationT
}
private ProgramDB buildProgram() throws Exception {
ToyProgramBuilder builder = new ToyProgramBuilder("notepad", true);
ToyProgramBuilder builder = new ToyProgramBuilder();
builder.createMemory(".text", "0x1001000", 0x6600);
builder.createEmptyFunction(null, "1001000", 1000, null);
builder.createReturnInstruction("1001000");
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -40,10 +40,6 @@ public class RegisterFieldFactoryTest extends AbstractGhidraHeadedIntegrationTes
private CodeBrowserPlugin cb;
private Program program;
public RegisterFieldFactoryTest() {
super();
}
@Before
public void setUp() throws Exception {
@@ -57,7 +53,7 @@ public class RegisterFieldFactoryTest extends AbstractGhidraHeadedIntegrationTes
}
private ProgramDB buildProgram() throws Exception {
ToyProgramBuilder builder = new ToyProgramBuilder("notepad", true);
ToyProgramBuilder builder = new ToyProgramBuilder();
builder.createMemory(".text", "0x1001000", 0x6600);
builder.createEmptyFunction(null, "1001000", 40, null);
builder.createReturnInstruction("1001000");
@@ -115,7 +111,7 @@ public class RegisterFieldFactoryTest extends AbstractGhidraHeadedIntegrationTes
if (reg.isProcessorContext() || reg.hasChildren()) {
continue;
}
nonContextRegs.add(reg);
nonContextRegs.add(reg);
}
return nonContextRegs;
}
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -101,7 +101,7 @@ public class AddViewToProjectTest extends AbstractGhidraHeadlessIntegrationTest
// make sure we have projects to use as the project view...
Project project = ProjectTestUtils.getProject(DIRECTORY_NAME, PROJECT_VIEW1);
try {
ToyProgramBuilder builder = new ToyProgramBuilder("Test", true);
ToyProgramBuilder builder = new ToyProgramBuilder();
DomainFolder rootFolder = project.getProjectData().getRootFolder();
rootFolder.createFile("Test", builder.getProgram(), TaskMonitor.DUMMY);
builder.dispose();
@@ -48,7 +48,7 @@ public class SearchAndReplaceDialogTest extends AbstractGhidraHeadedIntegrationT
SearchAndReplacePlugin plugin = getPlugin(tool, SearchAndReplacePlugin.class);
ToyProgramBuilder builder = new ToyProgramBuilder("Test", true);
ToyProgramBuilder builder = new ToyProgramBuilder();
builder.createLabel("0x100", "myFooLabel");
builder.createLabel("0x200", "myBarLabel");
program = builder.getProgram();
@@ -49,7 +49,7 @@ public class DefinedDataIteratorTest extends AbstractGhidraHeadlessIntegrationTe
@Before
public void setUp() throws Exception {
builder = new ToyProgramBuilder("DefinedDataIteratorTests", false);
builder = new ToyProgramBuilder();
program = builder.getProgram();
dtm = program.getDataTypeManager();
@@ -80,8 +80,8 @@ public class DefinedDataIteratorTest extends AbstractGhidraHeadlessIntegrationTe
builder.createString("0x10", "test1", StandardCharsets.UTF_8, true, stringDT);
builder.applyFixedLengthDataType("0x100", struct1DT, struct1DT.getLength());
List<Data> list = CollectionUtils.asList((Iterable<Data>)
DefinedDataIterator.byDataType(program, dt -> dt instanceof IntegerDataType));
List<Data> list = CollectionUtils.asList((Iterable<Data>) DefinedDataIterator
.byDataType(program, dt -> dt instanceof IntegerDataType));
assertTrue(list.get(0).getAddress().getOffset() == 0x0);
assertTrue(list.get(1).getAddress().getOffset() == 0x100);
@@ -137,8 +137,8 @@ public class DefinedDataIteratorTest extends AbstractGhidraHeadlessIntegrationTe
builder.applyFixedLengthDataType("0x20", intDT, intTD.getLength());
// iterating by data type ignores typedefs, so we should get all 3 ints
List<Data> list = CollectionUtils.asList((Iterable<Data>)
DefinedDataIterator.byDataType(program, dt -> dt instanceof IntegerDataType));
List<Data> list = CollectionUtils.asList((Iterable<Data>) DefinedDataIterator
.byDataType(program, dt -> dt instanceof IntegerDataType));
assertEquals(3, list.size());
@@ -49,7 +49,7 @@ public class DefinedStringIteratorTest extends AbstractGhidraHeadlessIntegration
@Before
public void setUp() throws Exception {
builder = new ToyProgramBuilder("DefinedStringIteratorTests", false);
builder = new ToyProgramBuilder();
program = builder.getProgram();
dtm = program.getDataTypeManager();
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -32,7 +32,7 @@ public class DecompilerTest extends AbstractGhidraHeadedIntegrationTest {
@Before
public void setUp() throws Exception {
ToyProgramBuilder builder = new ToyProgramBuilder("notepad_decompiler", true);
ToyProgramBuilder builder = new ToyProgramBuilder();
builder.createMemory("test", "0x0", 2);
builder.addBytesReturn(0x0);
builder.createFunction("0x0");
@@ -222,7 +222,6 @@ public class VTMatchApplyFunctionSignatureTest extends AbstractGhidraHeadedInteg
f2.setSignatureSource(SourceType.ANALYSIS);
});
p.addConsumer(this);
return p;
}
finally {
@@ -240,7 +239,6 @@ public class VTMatchApplyFunctionSignatureTest extends AbstractGhidraHeadedInteg
builder.createEmptyFunction(null, "0x10938", 0x10, DataType.DEFAULT);
p.addConsumer(this);
return p;
}
finally {
@@ -15,32 +15,47 @@
*/
package ghidra.framework.main;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.net.URL;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import docking.DialogComponentProvider;
import docking.test.AbstractDockingTest;
import ghidra.app.services.CodeViewerService;
import ghidra.app.services.ProgramManager;
import ghidra.framework.data.DomainFileProxy;
import ghidra.framework.model.*;
import ghidra.framework.model.DomainFolder;
import ghidra.framework.model.Project;
import ghidra.framework.model.ProjectLocator;
import ghidra.framework.model.ToolAssociationInfo;
import ghidra.framework.model.ToolServices;
import ghidra.framework.model.ToolTemplate;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.protocol.ghidra.GhidraURL;
import ghidra.framework.protocol.ghidra.Handler;
import ghidra.program.database.*;
import ghidra.program.database.ProgramContentHandler;
import ghidra.program.database.ProgramDB;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.*;
import ghidra.program.model.symbol.Namespace;
import ghidra.program.model.symbol.SourceType;
import ghidra.program.model.symbol.SymbolTable;
import ghidra.program.util.ProgramLocation;
import ghidra.server.remote.ServerTestUtil;
import ghidra.test.*;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.TestEnv;
import ghidra.test.ToyProgramBuilder;
import ghidra.util.exception.AssertException;
import ghidra.util.task.TaskMonitor;
import utilities.util.FileUtilities;
@@ -72,6 +87,7 @@ public class LaunchUrlInToolTest extends AbstractGhidraHeadedIntegrationTest {
env.getFrontEndTool();
program = (ProgramDB) buildProgram();
Project project = env.getProject();
DomainFolder rootFolder = project.getProjectData().getRootFolder();
rootFolder.createFile("Test", program, TaskMonitor.DUMMY);
@@ -84,7 +100,7 @@ public class LaunchUrlInToolTest extends AbstractGhidraHeadedIntegrationTest {
}
private Program buildProgram() throws Exception {
ToyProgramBuilder builder = new ToyProgramBuilder(FILENAME, true, ProgramBuilder._TOY);
ToyProgramBuilder builder = new ToyProgramBuilder(FILENAME, true);
builder.createMemory("test1", "0x1001000", 0xb000);
builder.addBytesFallthrough("0x1001010");
builder.addBytesFallthrough("0x1001020");
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -76,7 +76,7 @@ public class AbstractBlockGraphTest extends AbstractGhidraHeadedIntegrationTest
protected void openProgram() throws Exception {
builder = new ToyProgramBuilder("sample", true);
builder = new ToyProgramBuilder();
builder.createMemory("caller", "0x01002200", 8);
builder.createMemory("simple", "0x01002239", 8);
builder.createMemory("not_graphed", "0x01002300", 8);
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -74,7 +74,7 @@ public class AbstractDataReferenceGraphTest extends AbstractGhidraHeadedIntegrat
protected void openProgram() throws Exception {
builder = new ToyProgramBuilder("sample", true);
builder = new ToyProgramBuilder();
builder.createMemory("data", "0x01000000", 64);
builder.createMemory("caller", "0x01002200", 8);