Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(535)

Unified Diff: runtime/vm/ic_data_test.cc

Issue 8357034: Transitioning to new IC structure: change IC data to include function name; pass IC data instead ... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/ic_data.cc ('k') | runtime/vm/ic_stubs.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/ic_data_test.cc
===================================================================
--- runtime/vm/ic_data_test.cc (revision 0)
+++ runtime/vm/ic_data_test.cc (revision 0)
@@ -0,0 +1,75 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "vm/ic_data.h"
+#include "vm/code_index_table.h"
+#include "vm/unit_test.h"
+
+namespace dart {
+
+static RawFunction* GetDummyTarget(const char* name) {
+ Assembler assembler;
+ assembler.ret();
+ const Code& code =
+ Code::Handle(Code::FinalizeCode(name, &assembler));
+ const String& function_name =
+ String::ZoneHandle(String::NewSymbol(name));
+ const Function& function = Function::Handle(Function::New(
+ function_name, RawFunction::kFunction, true, false, 0));
+ function.SetCode(code);
+ CodeIndexTable* code_index_table = Isolate::Current()->code_index_table();
+ ASSERT(code_index_table != NULL);
+ code_index_table->AddFunction(function);
+ return function.raw();
+}
+
+
+static bool SameClassArrays(const GrowableArray<const Class*>& a,
+ const GrowableArray<const Class*>& b) {
+ if (a.length() != b.length()) {
+ return false;
+ }
+ for (int i = 0; i < a.length(); i++) {
+ if (a[i]->raw() != b[i]->raw()) {
+ return false;
+ }
+ }
+ return true;
+}
+
+
+TEST_CASE(ICDataTest) {
+ const String& name = String::Handle(String::New("Luxemburgerli"));
+ ICData ic_data(name, 1);
+ EXPECT_EQ(1, ic_data.NumberOfArgumentsChecked());
+ EXPECT_EQ(0, ic_data.NumberOfChecks());
+ EXPECT_EQ(name.raw(), ic_data.FunctionName());
+ GrowableArray<const Class*> classes;
+ const Function& target = Function::Handle(GetDummyTarget(name.ToCString()));
+ ObjectStore* object_store = Isolate::Current()->object_store();
+ const Class& smi_class = Class::ZoneHandle(object_store->smi_class());
+ classes.Add(&smi_class);
+ ic_data.AddCheck(classes, target);
+
+ EXPECT_EQ(1, ic_data.NumberOfArgumentsChecked());
+ EXPECT_EQ(1, ic_data.NumberOfChecks());
+ EXPECT_EQ(name.raw(), ic_data.FunctionName());
+
+ GrowableArray<const Class*> test_classes;
+ Function& test_target = Function::Handle();
+ ic_data.GetCheckAt(0, &test_classes, &test_target);
+
+ EXPECT(SameClassArrays(classes, test_classes));
+ EXPECT_EQ(target.raw(), test_target.raw());
+
+ const Function& new_target =
+ Function::Handle(GetDummyTarget(name.ToCString()));
+ ic_data.SetCheckAt(0, classes, new_target);
+ ic_data.GetCheckAt(0, &test_classes, &test_target);
+
+ EXPECT(SameClassArrays(classes, test_classes));
+ EXPECT_EQ(new_target.raw(), test_target.raw());
+}
+
+} // namespace dart
« no previous file with comments | « runtime/vm/ic_data.cc ('k') | runtime/vm/ic_stubs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698