From: marja@chromium.org Date: Fri, 7 Feb 2014 10:28:00 +0000 (+0000) Subject: Add regression tests for PrePreparser. X-Git-Tag: upstream/4.7.83~10821 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7a53841cd1debfa63ca9d7cbf6783c5be549fe7e;p=platform%2Fupstream%2Fv8.git Add regression tests for PrePreparser. These tests ensure that PreParser doesn't start producing less data when it's getting refactored. BUG=3126 LOG=N R=ulan@chromium.org Review URL: https://codereview.chromium.org/157373002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19192 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc index d79f594..4dd7971 100644 --- a/test/cctest/test-parsing.cc +++ b/test/cctest/test-parsing.cc @@ -1874,3 +1874,69 @@ TEST(NoErrorsIdentifierNames) { RunParserSyncTest(context_data, statement_data, kSuccess); } + + +TEST(DontRegressPreParserDataSizes) { + // These tests make sure that PreParser doesn't start producing less data. + + v8::V8::Initialize(); + + int marker; + CcTest::i_isolate()->stack_guard()->SetStackLimit( + reinterpret_cast(&marker) - 128 * 1024); + + struct TestCase { + const char* program; + int symbols; + int functions; + } test_cases[] = { + // Labels, variables and functions are recorded as symbols. + {"{label: 42}", 1, 0}, {"{label: 42; label2: 43}", 2, 0}, + {"var x = 42;", 1, 0}, {"var x = 42, y = 43;", 2, 0}, + {"function foo() {}", 1, 1}, {"function foo() {} function bar() {}", 2, 2}, + // Labels, variables and functions insize lazy functions are not recorded. + {"function lazy() { var a, b, c; }", 1, 1}, + {"function lazy() { a: 1; b: 2; c: 3; }", 1, 1}, + {"function lazy() { function a() {} function b() {} function c() {} }", 1, + 1}, + {NULL, 0, 0} + }; + // Each function adds 5 elements to the preparse function data. + const int kDataPerFunction = 5; + + uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); + for (int i = 0; test_cases[i].program; i++) { + const char* program = test_cases[i].program; + i::Utf8ToUtf16CharacterStream stream( + reinterpret_cast(program), + static_cast(strlen(program))); + i::CompleteParserRecorder log; + i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); + scanner.Initialize(&stream); + + i::PreParser preparser(&scanner, &log, stack_limit); + preparser.set_allow_lazy(true); + preparser.set_allow_natives_syntax(true); + i::PreParser::PreParseResult result = preparser.PreParseProgram(); + CHECK_EQ(i::PreParser::kPreParseSuccess, result); + if (log.symbol_ids() != test_cases[i].symbols) { + i::OS::Print( + "Expected preparse data for program:\n" + "\t%s\n" + "to contain %d symbols, however, received %d symbols.\n", + program, test_cases[i].symbols, log.symbol_ids()); + CHECK(false); + } + if (log.function_position() != test_cases[i].functions * kDataPerFunction) { + i::OS::Print( + "Expected preparse data for program:\n" + "\t%s\n" + "to contain %d functions, however, received %d functions.\n", + program, test_cases[i].functions, + log.function_position() / kDataPerFunction); + CHECK(false); + } + i::ScriptDataImpl data(log.ExtractData()); + CHECK(!data.has_error()); + } +}