public static Program buildProgram() throws Exception {

		ToyProgramBuilder builder = new ToyProgramBuilder("sample1", true);
		Program program = builder.getProgram();

		builder.createMemory("test", "0x1001000", 0x5500);

		// create an 'Exports' node
		builder.createEntryPoint("0x1006420", "entry");
		builder.createLabel("0x1006420", "entry");

		// imports symbol tree node
		builder.createExternalLibraries("ADVAPI32.dll", "comdlg32.dll", "GDI32.dll", "KERNEL32.dll",
			"MSVCRT.dll", "SHELL32.dll", "USER32.dll", "WINSPOOL.DRV");
		builder.createExternalReference("0x1001000", "ADVAPI32.dll", "IsTextUnicode", 0);
		builder.createLabel("0x1001000", "ADVAPI32.dll_IsTextUnicode");
		builder.createExternalReference("0x1001004", "ADVAPI32.dll", "RegCreateKeyW", 0);
		builder.createLabel("0x1001004", "ADVAPI32.dll_RegCreateKeyW");
		builder.createExternalReference("0x1001008", "ADVAPI32.dll", "RegQueryValueExW", 0);
		builder.createLabel("0x1001008", "ADVAPI32.dll_RegQueryValueExW");
		builder.createExternalReference("0x100100c", "ADVAPI32.dll", "RegSetValueExW", 0);
		builder.createLabel("0x100100c", "ADVAPI32.dll_RegSetValueExW");
		builder.createExternalReference("0x1001010", "ADVAPI32.dll", "RegOpenKeyExA", 0);
		builder.createLabel("0x1001010", "ADVAPI32.dll_RegOpenKeyExA");
		builder.createExternalReference("0x1001014", "ADVAPI32.dll", "RegQueryValueExA", 0);
		builder.createLabel("0x1001014", "ADVAPI32.dll_RegQueryValueExA");
		builder.createExternalReference("0x1001018", "ADVAPI32.dll", "RegCloseKey", 0);
		builder.createLabel("0x1001018", "ADVAPI32.dll_RegCloseKey");

		ExternalManager externalManager = builder.getProgram().getExternalManager();
		int tx = program.startTransaction("Test Transaction");
		externalManager.setExternalPath("ADVAPI32.dll", "/path/to/ADVAPI32.DLL", true);
		program.endTransaction(tx, true);

		// functions
		builder.createEmptyFunction("doStuff", null, "0x10048a3", 19, new Undefined1DataType(),
			new ParameterImpl("param_1", new IntegerDataType(), program),
			new ParameterImpl("param_2", new IntegerDataType(), program));

		//@formatter:off
		ParameterImpl p = new ParameterImpl(null /*auto name*/, new IntegerDataType(), program);
		builder.createEmptyFunction("ghidra", null, "0x1002cf5", 121, new Undefined1DataType(),
			p, p, p, p, p, p, p, p, p);
		//@formatter:on

		builder.createStackReference("1002d06", RefType.DATA, 0x8, SourceType.ANALYSIS, 0);
		builder.createMemoryCallReference("0x1002cf9", "0x10048a3"); // call 'doStuff' function

		builder.createLabel("0x1002d2b", "AnotherLocal", "ghidra");
		builder.createLabel("0x1002d1f", "MyLocal", "ghidra");

		//@formatter:off
		Function function = builder.createEmptyFunction("sscanf", null, "0x100415a", 78, 
			new Undefined1DataType(),
			new ParameterImpl("destStr", new IntegerDataType(), program), 
			new ParameterImpl("param_3", new IntegerDataType(), program),
			new ParameterImpl("param_4", new IntegerDataType(), program));
		//@formatter:on

		Variable var = new LocalVariableImpl("i", new IntegerDataType(), -0x4, program);
		builder.addFunctionVariable(function, var);
		var = new LocalVariableImpl("count", new IntegerDataType(), -0x8, program);
		builder.addFunctionVariable(function, var);
		var = new LocalVariableImpl("formatCount", new IntegerDataType(), -0xc, program);
		builder.addFunctionVariable(function, var);

		return program;
	}
A comparator to sort Symbols the same way as the SymbolNode sorts
Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreeTestUtils.java