[Scummvm-cvs-logs] SF.net SVN: scummvm:[52012] tools/branches/gsoc2010-decompiler/decompiler/ test

pidgeot at users.sourceforge.net pidgeot at users.sourceforge.net
Thu Aug 12 00:37:16 CEST 2010


Revision: 52012
          http://scummvm.svn.sourceforge.net/scummvm/?rev=52012&view=rev
Author:   pidgeot
Date:     2010-08-11 22:37:16 +0000 (Wed, 11 Aug 2010)

Log Message:
-----------
DECOMPILER: Add some Kyra-related tests

Modified Paths:
--------------
    tools/branches/gsoc2010-decompiler/decompiler/test/cfg_test.h
    tools/branches/gsoc2010-decompiler/decompiler/test/codegen.h
    tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h
    tools/branches/gsoc2010-decompiler/decompiler/test/module.mk

Modified: tools/branches/gsoc2010-decompiler/decompiler/test/cfg_test.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/cfg_test.h	2010-08-11 22:11:56 UTC (rev 52011)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/cfg_test.h	2010-08-11 22:37:16 UTC (rev 52012)
@@ -26,6 +26,7 @@
 #include "decompiler/disassembler.h"
 #include "decompiler/graph.h"
 #include "decompiler/scummv6/engine.h"
+#include "decompiler/kyra/engine.h"
 
 #include <vector>
 #define GET(vertex) (boost::get(boost::vertex_name, g, vertex))
@@ -616,4 +617,51 @@
 		delete c;
 		delete engine;
 	}
+
+	void testFunctionDetection() {
+		std::vector<Instruction> insts;
+		Kyra::Kyra2Engine *engine = new Kyra::Kyra2Engine();
+		Disassembler *d = engine->getDisassembler(insts);
+		d->open("decompiler/test/_START04.EMC");
+		d->disassemble();
+		delete d;
+		ControlFlow *c = new ControlFlow(insts, engine);
+		c->createGroups();
+		Graph g = c->analyze();
+		TS_ASSERT(engine->_functions.size() == 15);
+		FuncMap::iterator it = engine->_functions.begin();
+		TS_ASSERT(it->first == 0x0);
+		++it;
+		TS_ASSERT(it->first == 0x7E);
+		++it;
+		TS_ASSERT(it->first == 0xFC);
+		++it;
+		TS_ASSERT(it->first == 0x100);
+		++it;
+		TS_ASSERT(it->first == 0x1F4);
+		++it;
+		TS_ASSERT(it->first == 0x1F8);
+		++it;
+		TS_ASSERT(it->first == 0x276);
+		++it;
+		TS_ASSERT(it->first == 0x278);
+		++it;
+		TS_ASSERT(it->first == 0x2DE);
+		++it;
+		TS_ASSERT(it->first == 0x2E0);
+		++it;
+		TS_ASSERT(it->first == 0x30C);
+		++it;
+		TS_ASSERT(it->first == 0x30E);
+		++it;
+		TS_ASSERT(it->first == 0x33A);
+		++it;
+		TS_ASSERT(it->first == 0x33C);
+		++it;
+		TS_ASSERT(it->first == 0x33E);
+		++it;
+
+		delete c;
+		delete engine;
+	}
 };

Modified: tools/branches/gsoc2010-decompiler/decompiler/test/codegen.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/codegen.h	2010-08-11 22:11:56 UTC (rev 52011)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/codegen.h	2010-08-11 22:37:16 UTC (rev 52012)
@@ -27,6 +27,7 @@
 #include "decompiler/graph.h"
 #include "decompiler/codegen.h"
 #include "decompiler/scummv6/engine.h"
+#include "decompiler/kyra/engine.h"
 
 #include <vector>
 #define GET(vertex) (boost::get(boost::vertex_name, g, vertex))
@@ -265,4 +266,68 @@
 		delete engine;
 	}
 
+	// This test requires _START04.EMC from the CD demo of
+	// Legend of Kyrandia: Hand of Fate, found in MISC_EMC.PAK.
+	// ba2821ac6da96394ce0af75a3cbe48eb *_START04.EMC
+	void testKyra2Start04CodeGen() {
+		std::vector<Instruction> insts;
+		Kyra::Kyra2Engine *engine = new Kyra::Kyra2Engine();
+		Disassembler *d = engine->getDisassembler(insts);
+		d->open("decompiler/test/_START04.EMC");
+		d->disassemble();
+		delete d;
+		ControlFlow *c = new ControlFlow(insts, engine);
+		c->createGroups();
+		Graph g = c->analyze();
+		engine->postCFG(insts, g);
+		onullstream ns;
+		CodeGenerator *cg = engine->getCodeGenerator(ns);
+		cg->generate(g);
+
+		VertexIterator v = boost::vertices(g).first;
+		std::vector<std::string> output, expected;
+		expected.push_back("auto_sub0x278(param1, param2, param3, param4) {");
+		expected.push_back("if (((param4 < var2) && ((param2 > var2) && ((param3 < var1) && (param1 > var1))))) {");
+		expected.push_back("retval = o1_queryGameFlag(3);");
+		expected.push_back("if (retval) {");
+		expected.push_back("retval = o2_drawBox(param1, param2, param3, param4, 199);");
+		expected.push_back("}");
+		expected.push_back("retval = 1;");
+		expected.push_back("return;");
+		expected.push_back("}");
+		expected.push_back("retval = o1_queryGameFlag(3);");
+		expected.push_back("if (retval) {");
+		expected.push_back("retval = o2_drawBox(param1, param2, param3, param4, 132);");
+		expected.push_back("}");
+		expected.push_back("retval = 0;");
+		expected.push_back("return;");
+		expected.push_back("}");
+
+		GroupPtr gr = GET(*v);
+		// Find first node
+		while (gr->_prev != NULL)
+			gr = gr->_prev;
+
+		// Find right starting node
+		while (gr->_start->_address != 0x278)
+			gr = gr->_next;
+
+		// Copy out all lines of code from function
+		while (gr->_start->_address <= 0x2DC) {
+			for (std::vector<CodeLine>::iterator it = gr->_code.begin(); it != gr->_code.end(); ++it) {
+				if (it->_line.compare("") != 0)
+					output.push_back(it->_line);
+			}
+			gr = gr->_next;
+		}
+		TS_ASSERT(output.size() == expected.size());
+		CodeIterator it, it2;
+		for (it = output.begin(), it2 = expected.begin(); it != output.end() && it2 != expected.end(); ++it, ++it2) {
+			TS_ASSERT(removeSpaces(*it).compare(removeSpaces(*it2)) == 0);
+		}
+
+		delete cg;
+		delete c;
+		delete engine;
+	}
 };

Modified: tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h	2010-08-11 22:11:56 UTC (rev 52011)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/disassembler_test.h	2010-08-11 22:37:16 UTC (rev 52012)
@@ -25,6 +25,7 @@
 #include "disassembler/pasc.h"
 #include "disassembler/subopcode.h"
 #include "decompiler/scummv6/disassembler.h"
+#include "decompiler/kyra/engine.h"
 
 class DisassemblerTestSuite : public CxxTest::TestSuite {
 public:
@@ -247,4 +248,33 @@
 			TS_ASSERT(false);
 		}
 	}
+
+	// This test requires _START04.EMC from the CD demo of
+	// Legend of Kyrandia: Hand of Fate, found in MISC_EMC.PAK.
+	// ba2821ac6da96394ce0af75a3cbe48eb *_START04.EMC
+	void testKyra2Start04() {
+		try {
+			std::vector<Instruction> insts;
+			Kyra::Kyra2Engine engine;
+			Disassembler* s = engine.getDisassembler(insts);
+			s->open("decompiler/test/_START04.EMC");
+			s->disassemble();
+
+			TS_ASSERT(insts.size() == 481);
+
+			//These scripts are far too big to check all instructions, so we just check a few different ones
+			TS_ASSERT(insts[16]._address == 0x20);
+			TS_ASSERT(insts[16]._opcode == 15);
+			TS_ASSERT(insts[16]._name == "ifNotJmp");
+			TS_ASSERT(insts[16]._stackChange == -1);
+			TS_ASSERT(insts[38]._address == 0x54);
+			TS_ASSERT(insts[38]._opcode == 14);
+			TS_ASSERT(insts[38]._name == "o1_setHandItem");
+			TS_ASSERT(insts[38]._stackChange == 0);
+
+			delete s;
+		} catch (...) {
+			TS_ASSERT(false);
+		}
+	}
 };

Modified: tools/branches/gsoc2010-decompiler/decompiler/test/module.mk
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/test/module.mk	2010-08-11 22:11:56 UTC (rev 52011)
+++ tools/branches/gsoc2010-decompiler/decompiler/test/module.mk	2010-08-11 22:37:16 UTC (rev 52012)
@@ -15,6 +15,9 @@
 	decompiler/scummv6/disassembler.o \
 	decompiler/scummv6/codegen.o \
 	decompiler/scummv6/engine.o \
+	decompiler/kyra/disassembler.o \
+	decompiler/kyra/codegen.o \
+	decompiler/kyra/engine.o \
 	decompiler/test/disassembler/pasc.o \
 	decompiler/test/disassembler/subopcode.o	\
 	decompiler/unknown_opcode.o \


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list