From 8920f345c79103ef1ef93dd880d8f51d4e22681c Mon Sep 17 00:00:00 2001 From: "plind44@gmail.com" Date: Mon, 10 Feb 2014 19:46:34 +0000 Subject: [PATCH] MIPS: Add NaN test to cctest/test-macro-assembler-mips. NaN value is different on MIPS and x86 architectures, and TEST(NaNx) tests checks the case where a x86 NaN value is serialized into the snapshot on the simulator during cross compilation. BUG= R=plind44@gmail.com Review URL: https://codereview.chromium.org/144473008 Patch from Balazs Kilvady . git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19241 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- test/cctest/test-macro-assembler-mips.cc | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/cctest/test-macro-assembler-mips.cc b/test/cctest/test-macro-assembler-mips.cc index b200949..3154aac 100644 --- a/test/cctest/test-macro-assembler-mips.cc +++ b/test/cctest/test-macro-assembler-mips.cc @@ -132,5 +132,47 @@ TEST(CopyBytes) { } +static void TestNaN(const char *code) { + // NaN value is different on MIPS and x86 architectures, and TEST(NaNx) + // tests checks the case where a x86 NaN value is serialized into the + // snapshot on the simulator during cross compilation. + v8::HandleScope scope(CcTest::isolate()); + v8::Local context = CcTest::NewContext(PRINT_EXTENSION); + v8::Context::Scope context_scope(context); + + v8::Local script = v8::Script::Compile(v8_str(code)); + v8::Local result = v8::Local::Cast(script->Run()); + // Have to populate the handle manually, as it's not Cast-able. + i::Handle o = + v8::Utils::OpenHandle(result); + i::Handle array1(reinterpret_cast(*o)); + i::FixedDoubleArray* a = i::FixedDoubleArray::cast(array1->elements()); + double value = a->get_scalar(0); + CHECK(std::isnan(value) && + i::BitCast(value) == + i::BitCast( + i::FixedDoubleArray::canonical_not_the_hole_nan_as_double())); +} + + +TEST(NaN0) { + TestNaN( + "var result;" + "for (var i = 0; i < 2; i++) {" + " result = new Array(Number.NaN, Number.POSITIVE_INFINITY);" + "}" + "result;"); +} + + +TEST(NaN1) { + TestNaN( + "var result;" + "for (var i = 0; i < 2; i++) {" + " result = [NaN];" + "}" + "result;"); +} + #undef __ -- 2.7.4