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

Unified Diff: vm/snapshot_test.cc

Issue 10911159: - Add a test case to test Source code generation of all the corelibs (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 3 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 | « vm/object.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vm/snapshot_test.cc
===================================================================
--- vm/snapshot_test.cc (revision 11999)
+++ vm/snapshot_test.cc (working copy)
@@ -681,6 +681,84 @@
};
+static RawString* UnmangleName(const String& name) {
+ intptr_t len = name.Length();
+ intptr_t start = 0;
+ intptr_t at_pos = len; // Position of '@' in the name.
+ intptr_t dot_pos = len; // Position of '.' in the name.
+
+ for (int i = 0; i < name.Length(); i++) {
+ if (name.CharAt(i) == '@') {
+ ASSERT(at_pos == len);
+ at_pos = i;
+ } else if (name.CharAt(i) == '.') {
+ dot_pos = i;
+ break;
+ }
+ }
+ intptr_t limit = (at_pos < dot_pos ? at_pos : dot_pos);
+ if (start == 0 && limit == len) {
+ // This name is fine as it is.
+ return name.raw();
+ }
+
+ const String& result =
+ String::Handle(String::SubString(name, start, (limit - start)));
+
+ // Look for a second '@' now to correctly handle names like
+ // "_ReceivePortImpl@6be832b._internal@6be832b".
+ at_pos = len;
+ for (int i = dot_pos; i < name.Length(); i++) {
+ if (name.CharAt(i) == '@') {
+ ASSERT(at_pos == len);
+ at_pos = i;
+ }
+ }
+
+ intptr_t suffix_len = at_pos - dot_pos;
+ if (suffix_len > 1) {
+ // This is a named constructor. Add the name back to the string.
+ const String& suffix =
+ String::Handle(String::SubString(name, dot_pos, suffix_len));
+ return String::Concat(result, suffix);
+ }
+
+ return result.raw();
+}
+
+
+static void GenerateSourceAndCheck(const Script& script) {
hausner 2012/09/07 22:12:29 You could pass in the private_key value that is us
siva 2012/09/09 04:57:29 Good point. Passed in private key and got rid of
+ // Check if we are able to generate the source from the token stream.
+ // Rescan this source and compare the token stream to see if they are
+ // the same.
+ const TokenStream& expected_tokens = TokenStream::Handle(script.tokens());
+ TokenStream::Iterator expected_iterator(expected_tokens, 0);
+ const String& str = String::Handle(expected_tokens.GenerateSource());
+ const String& dummy_key = String::Handle(String::New(""));
+ Scanner scanner(str, dummy_key);
+ const TokenStream& reconstructed_tokens =
+ TokenStream::Handle(TokenStream::New(scanner.GetStream(), dummy_key));
+ expected_iterator.SetCurrentPosition(0);
+ TokenStream::Iterator reconstructed_iterator(reconstructed_tokens, 0);
+ Token::Kind expected_kind = expected_iterator.CurrentTokenKind();
+ Token::Kind reconstructed_kind = reconstructed_iterator.CurrentTokenKind();
+ String& expected_literal = String::Handle();
+ String& actual_literal = String::Handle();
+ while (expected_kind != Token::kEOS && reconstructed_kind != Token::kEOS) {
+ EXPECT_EQ(expected_kind, reconstructed_kind);
+ expected_literal ^= expected_iterator.CurrentLiteral();
+ expected_literal = UnmangleName(expected_literal);
+ actual_literal ^= reconstructed_iterator.CurrentLiteral();
+ actual_literal = UnmangleName(actual_literal);
+ EXPECT(expected_literal.Equals(actual_literal));
+ expected_iterator.Advance();
+ reconstructed_iterator.Advance();
+ expected_kind = expected_iterator.CurrentTokenKind();
+ reconstructed_kind = reconstructed_iterator.CurrentTokenKind();
+ }
+}
+
+
TEST_CASE(SerializeScript) {
const char* kScriptChars =
"class A {\n"
@@ -746,30 +824,51 @@
// Check if we are able to generate the source from the token stream.
// Rescan this source and compare the token stream to see if they are
// the same.
- str ^= serialized_tokens.GenerateSource();
- const String& dummy_key = String::Handle(String::New(""));
- Scanner scanner(str, dummy_key);
- const TokenStream& reconstructed_tokens =
- TokenStream::Handle(TokenStream::New(scanner.GetStream(), dummy_key));
- expected_iterator.SetCurrentPosition(0);
- TokenStream::Iterator reconstructed_iterator(reconstructed_tokens, 0);
- expected_kind = expected_iterator.CurrentTokenKind();
- Token::Kind reconstructed_kind = reconstructed_iterator.CurrentTokenKind();
- while (expected_kind != Token::kEOS && reconstructed_kind != Token::kEOS) {
- EXPECT_EQ(expected_kind, reconstructed_kind);
- expected_literal ^= expected_iterator.CurrentLiteral();
- actual_literal ^= reconstructed_iterator.CurrentLiteral();
- EXPECT(expected_literal.Equals(actual_literal));
- expected_iterator.Advance();
- reconstructed_iterator.Advance();
- expected_kind = expected_iterator.CurrentTokenKind();
- reconstructed_kind = reconstructed_iterator.CurrentTokenKind();
- }
+ GenerateSourceAndCheck(serialized_script);
free(buffer);
}
+static void IterateScripts(const Library& lib) {
+ const Array& lib_scripts = Array::Handle(lib.LoadedScripts());
+ Script& script = Script::Handle();
+ for (intptr_t i = 0; i < lib_scripts.Length(); i++) {
+ script ^= lib_scripts.At(i);
+ EXPECT(!script.IsNull());
+ GenerateSourceAndCheck(script);
+ }
+}
+
+TEST_CASE(GenerateSource) {
+ Library& lib = Library::Handle();
+ // Check core lib.
+ lib = Library::CoreLibrary();
+ EXPECT(!lib.IsNull());
+ IterateScripts(lib);
+
+ // Check core impl lib.
+ lib = Library::CoreImplLibrary();
+ EXPECT(!lib.IsNull());
+ IterateScripts(lib);
+
+ // Check isolate lib.
+ lib = Library::IsolateLibrary();
+ EXPECT(!lib.IsNull());
+ IterateScripts(lib);
+
+ // Check math lib.
+ lib = Library::MathLibrary();
+ EXPECT(!lib.IsNull());
+ IterateScripts(lib);
+
+ // Check mirrors lib.
+ lib = Library::MirrorsLibrary();
+ EXPECT(!lib.IsNull());
+ IterateScripts(lib);
+}
+
+
// Only ia32 and x64 can run execution tests.
#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
UNIT_TEST_CASE(FullSnapshot) {
« no previous file with comments | « vm/object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698