Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(8679)

Unified Diff: src/common/module_unittest.cc

Issue 511003: Add APIs for querying Module data (Closed)
Patch Set: Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/common/module.cc ('K') | « src/common/module.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/common/module_unittest.cc
===================================================================
--- a/src/common/module_unittest.cc
+++ b/src/common/module_unittest.cc
@@ -329,63 +329,63 @@ TEST(Construct, AddFrames) {
entry3->rule_changes[0x36682fad3763ffffULL][".cfa"] =
"I think I know";
m.AddStackFrameEntry(entry3);
// Check that Write writes STACK CFI records properly.
m.Write(s, true);
string contents = s.str();
EXPECT_STREQ("MODULE os-name architecture id-string name with spaces\n"
- "STACK CFI INIT ddb5f41285aa7757 1486493370dc5073 \n"
- "STACK CFI INIT 8064f3af5e067e38 de2a5ee55509407"
- " .cfa: I think that I shall never see"
- " cannoli: a tree whose hungry mouth is prest"
- " stromboli: a poem lovely as a tree\n"
"STACK CFI INIT 5e8d0db0a7075c6c 1c7edb12a7aea229"
" .cfa: Whose woods are these\n"
"STACK CFI 36682fad3763ffff"
" .cfa: I think I know"
" stromboli: his house is in\n"
"STACK CFI 47ceb0f63c269d7f"
" calzone: the village though"
- " cannoli: he will not see me stopping here\n",
+ " cannoli: he will not see me stopping here\n"
+ "STACK CFI INIT 8064f3af5e067e38 de2a5ee55509407"
+ " .cfa: I think that I shall never see"
+ " cannoli: a tree whose hungry mouth is prest"
+ " stromboli: a poem lovely as a tree\n"
+ "STACK CFI INIT ddb5f41285aa7757 1486493370dc5073 \n",
contents.c_str());
// Check that GetStackFrameEntries works.
vector<Module::StackFrameEntry *> entries;
m.GetStackFrameEntries(&entries);
ASSERT_EQ(3U, entries.size());
// Check first entry.
- EXPECT_EQ(0xddb5f41285aa7757ULL, entries[0]->address);
- EXPECT_EQ(0x1486493370dc5073ULL, entries[0]->size);
- ASSERT_EQ(0U, entries[0]->initial_rules.size());
- ASSERT_EQ(0U, entries[0]->rule_changes.size());
+ EXPECT_EQ(0x5e8d0db0a7075c6cULL, entries[0]->address);
+ EXPECT_EQ(0x1c7edb12a7aea229ULL, entries[0]->size);
+ Module::RuleMap entry1_initial;
+ entry1_initial[".cfa"] = "Whose woods are these";
+ EXPECT_THAT(entries[0]->initial_rules, ContainerEq(entry1_initial));
+ Module::RuleChangeMap entry1_changes;
+ entry1_changes[0x36682fad3763ffffULL][".cfa"] = "I think I know";
+ entry1_changes[0x36682fad3763ffffULL]["stromboli"] = "his house is in";
+ entry1_changes[0x47ceb0f63c269d7fULL]["calzone"] = "the village though";
+ entry1_changes[0x47ceb0f63c269d7fULL]["cannoli"] =
+ "he will not see me stopping here";
+ EXPECT_THAT(entries[0]->rule_changes, ContainerEq(entry1_changes));
// Check second entry.
EXPECT_EQ(0x8064f3af5e067e38ULL, entries[1]->address);
EXPECT_EQ(0x0de2a5ee55509407ULL, entries[1]->size);
ASSERT_EQ(3U, entries[1]->initial_rules.size());
Module::RuleMap entry2_initial;
entry2_initial[".cfa"] = "I think that I shall never see";
entry2_initial["stromboli"] = "a poem lovely as a tree";
entry2_initial["cannoli"] = "a tree whose hungry mouth is prest";
EXPECT_THAT(entries[1]->initial_rules, ContainerEq(entry2_initial));
ASSERT_EQ(0U, entries[1]->rule_changes.size());
// Check third entry.
- EXPECT_EQ(0x5e8d0db0a7075c6cULL, entries[2]->address);
- EXPECT_EQ(0x1c7edb12a7aea229ULL, entries[2]->size);
- Module::RuleMap entry3_initial;
- entry3_initial[".cfa"] = "Whose woods are these";
- EXPECT_THAT(entries[2]->initial_rules, ContainerEq(entry3_initial));
- Module::RuleChangeMap entry3_changes;
- entry3_changes[0x36682fad3763ffffULL][".cfa"] = "I think I know";
- entry3_changes[0x36682fad3763ffffULL]["stromboli"] = "his house is in";
- entry3_changes[0x47ceb0f63c269d7fULL]["calzone"] = "the village though";
- entry3_changes[0x47ceb0f63c269d7fULL]["cannoli"] =
- "he will not see me stopping here";
- EXPECT_THAT(entries[2]->rule_changes, ContainerEq(entry3_changes));
+ EXPECT_EQ(0xddb5f41285aa7757ULL, entries[2]->address);
+ EXPECT_EQ(0x1486493370dc5073ULL, entries[2]->size);
+ ASSERT_EQ(0U, entries[2]->initial_rules.size());
+ ASSERT_EQ(0U, entries[2]->rule_changes.size());
}
TEST(Construct, UniqueFiles) {
Module m(MODULE_NAME, MODULE_OS, MODULE_ARCH, MODULE_ID);
Module::File *file1 = m.FindFile("foo");
Module::File *file2 = m.FindFile(string("bar"));
Module::File *file3 = m.FindFile(string("foo"));
Module::File *file4 = m.FindFile("bar");
@@ -483,8 +483,155 @@ TEST(Construct, DuplicateExterns) {
m.Write(s, true);
string contents = s.str();
EXPECT_STREQ("MODULE " MODULE_OS " " MODULE_ARCH " "
MODULE_ID " " MODULE_NAME "\n"
"PUBLIC ffff 0 _xyz\n",
contents.c_str());
}
+
+TEST(Lookup, Function) {
+ Module m(MODULE_NAME, MODULE_OS, MODULE_ARCH, MODULE_ID);
+
+ Module::Function *function1 = new(Module::Function);
+ function1->name = "_abc1";
+ function1->address = 0x1000;
+ function1->size = 0x900;
+ function1->parameter_size = 0x0;
+
+ Module::Function *function2 = new(Module::Function);
+ function2->name = "_xyz2";
+ function2->address = 0x2000;
+ function2->size = 0x900;
+ function2->parameter_size = 0x0;
+
+ Module::Function *function3 = new(Module::Function);
+ function3->name = "_def3";
+ function3->address = 0x3000;
+ function3->size = 0x900;
+ function3->parameter_size = 0x0;
+
+ // Put them in a vector.
+ vector<Module::Function *> vec;
+ vec.push_back(function1);
+ vec.push_back(function2);
+ vec.push_back(function3);
+
+ m.AddFunctions(vec.begin(), vec.end());
+
+ // Try looking up functions by address.
+ Module::Function* f = m.FindFunctionByAddress(0x1000);
+ EXPECT_EQ(function1, f);
+ f = m.FindFunctionByAddress(0x18FF);
+ EXPECT_EQ(function1, f);
+
+ f = m.FindFunctionByAddress(0x1900);
+ EXPECT_EQ((Module::Function*)NULL, f);
+ f = m.FindFunctionByAddress(0x1A00);
+ EXPECT_EQ((Module::Function*)NULL, f);
+
+ f = m.FindFunctionByAddress(0x2000);
+ EXPECT_EQ(function2, f);
+ f = m.FindFunctionByAddress(0x28FF);
+ EXPECT_EQ(function2, f);
+
+ f = m.FindFunctionByAddress(0x3000);
+ EXPECT_EQ(function3, f);
+ f = m.FindFunctionByAddress(0x38FF);
+ EXPECT_EQ(function3, f);
+
+ f = m.FindFunctionByAddress(0x3900);
+ EXPECT_EQ((Module::Function*)NULL, f);
+ f = m.FindFunctionByAddress(0x3A00);
+ EXPECT_EQ((Module::Function*)NULL, f);
+}
+
+TEST(Lookup, Externs) {
+ Module m(MODULE_NAME, MODULE_OS, MODULE_ARCH, MODULE_ID);
+
+ // Two externs.
+ Module::Extern* extern1 = new(Module::Extern);
+ extern1->address = 0x1000;
+ extern1->name = "_abc";
+ Module::Extern* extern2 = new(Module::Extern);
+ extern2->address = 0x2000;
+ extern2->name = "_xyz";
+
+ m.AddExtern(extern1);
+ m.AddExtern(extern2);
+
+ Module::Extern* e = m.FindExternByAddress(0xFFF);
+ EXPECT_EQ((Module::Extern*)NULL, e);
+
+ e = m.FindExternByAddress(0x1000);
+ EXPECT_EQ(extern1, e);
+ e = m.FindExternByAddress(0x1900);
+ EXPECT_EQ(extern1, e);
+ e = m.FindExternByAddress(0x1FFF);
+ EXPECT_EQ(extern1, e);
+
+ e = m.FindExternByAddress(0x2000);
+ EXPECT_EQ(extern2, e);
+ e = m.FindExternByAddress(0x2900);
+ EXPECT_EQ(extern2, e);
+ e = m.FindExternByAddress(0xFFFFFFFF);
+ EXPECT_EQ(extern2, e);
+}
+
+TEST(Lookup, StackFrameEntries) {
+ Module m(MODULE_NAME, MODULE_OS, MODULE_ARCH, MODULE_ID);
+
+ // First STACK CFI entry, with no initial rules or deltas.
+ Module::StackFrameEntry *entry1 = new Module::StackFrameEntry();
+ entry1->address = 0x2000;
+ entry1->size = 0x900;
+ m.AddStackFrameEntry(entry1);
+
+ // Second STACK CFI entry, with initial rules but no deltas.
+ Module::StackFrameEntry *entry2 = new Module::StackFrameEntry();
+ entry2->address = 0x3000;
+ entry2->size = 0x900;
+ entry2->initial_rules[".cfa"] = "I think that I shall never see";
+ entry2->initial_rules["stromboli"] = "a poem lovely as a tree";
+ entry2->initial_rules["cannoli"] = "a tree whose hungry mouth is prest";
+ m.AddStackFrameEntry(entry2);
+
+ // Third STACK CFI entry, with initial rules and deltas.
+ Module::StackFrameEntry *entry3 = new Module::StackFrameEntry();
+ entry3->address = 0x1000;
+ entry3->size = 0x900;
+ entry3->initial_rules[".cfa"] = "Whose woods are these";
+ entry3->rule_changes[0x47ceb0f63c269d7fULL]["calzone"] =
+ "the village though";
+ entry3->rule_changes[0x47ceb0f63c269d7fULL]["cannoli"] =
+ "he will not see me stopping here";
+ entry3->rule_changes[0x36682fad3763ffffULL]["stromboli"] =
+ "his house is in";
+ entry3->rule_changes[0x36682fad3763ffffULL][".cfa"] =
+ "I think I know";
+ m.AddStackFrameEntry(entry3);
+
+ Module::StackFrameEntry* s = m.FindStackFrameEntryByAddress(0x1000);
+ EXPECT_EQ(entry3, s);
+ s = m.FindStackFrameEntryByAddress(0x18FF);
+ EXPECT_EQ(entry3, s);
+
+ s = m.FindStackFrameEntryByAddress(0x1900);
+ EXPECT_EQ((Module::StackFrameEntry*)NULL, s);
+ s = m.FindStackFrameEntryByAddress(0x1A00);
+ EXPECT_EQ((Module::StackFrameEntry*)NULL, s);
+
+ s = m.FindStackFrameEntryByAddress(0x2000);
+ EXPECT_EQ(entry1, s);
+ s = m.FindStackFrameEntryByAddress(0x28FF);
+ EXPECT_EQ(entry1, s);
+
+ s = m.FindStackFrameEntryByAddress(0x3000);
+ EXPECT_EQ(entry2, s);
+ s = m.FindStackFrameEntryByAddress(0x38FF);
+ EXPECT_EQ(entry2, s);
+
+ s = m.FindStackFrameEntryByAddress(0x3900);
+ EXPECT_EQ((Module::StackFrameEntry*)NULL, s);
+ s = m.FindStackFrameEntryByAddress(0x3A00);
+ EXPECT_EQ((Module::StackFrameEntry*)NULL, s);
+}
« src/common/module.cc ('K') | « src/common/module.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 1004:630ec63f810e-tainted