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

Side by Side Diff: runtime/vm/object_test.cc

Issue 2711353003: Fixed tests not having MallocHooks initialized for tests in release mode. (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/malloc_hooks_unsupported.cc ('k') | runtime/vm/os.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
11 #include "vm/debugger.h" 11 #include "vm/debugger.h"
12 #include "vm/isolate.h" 12 #include "vm/isolate.h"
13 #include "vm/malloc_hooks.h"
13 #include "vm/object.h" 14 #include "vm/object.h"
14 #include "vm/object_store.h" 15 #include "vm/object_store.h"
15 #include "vm/simulator.h" 16 #include "vm/simulator.h"
16 #include "vm/symbols.h" 17 #include "vm/symbols.h"
17 #include "vm/unit_test.h" 18 #include "vm/unit_test.h"
18 #include "vm/code_descriptors.h" 19 #include "vm/code_descriptors.h"
19 20
20 namespace dart { 21 namespace dart {
21 22
22 DECLARE_FLAG(bool, write_protect_code); 23 DECLARE_FLAG(bool, write_protect_code);
(...skipping 2679 matching lines...) Expand 10 before | Expand all | Expand 10 after
2702 EXPECT_EQ(instructions.raw(), Instructions::FromPayloadStart(payload_start)); 2703 EXPECT_EQ(instructions.raw(), Instructions::FromPayloadStart(payload_start));
2703 const Object& result = 2704 const Object& result =
2704 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); 2705 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array()));
2705 EXPECT_EQ(1, Smi::Cast(result).Value()); 2706 EXPECT_EQ(1, Smi::Cast(result).Value());
2706 } 2707 }
2707 2708
2708 2709
2709 // Test for immutability of generated instructions. The test crashes with a 2710 // Test for immutability of generated instructions. The test crashes with a
2710 // segmentation fault when writing into it. 2711 // segmentation fault when writing into it.
2711 ISOLATE_UNIT_TEST_CASE(CodeImmutability) { 2712 ISOLATE_UNIT_TEST_CASE(CodeImmutability) {
2713 bool stack_trace_collection_enabled =
2714 MallocHooks::stack_trace_collection_enabled();
2715 MallocHooks::set_stack_trace_collection_enabled(false);
2712 extern void GenerateIncrement(Assembler * assembler); 2716 extern void GenerateIncrement(Assembler * assembler);
2713 Assembler _assembler_; 2717 Assembler _assembler_;
2714 GenerateIncrement(&_assembler_); 2718 GenerateIncrement(&_assembler_);
2715 const Function& function = Function::Handle(CreateFunction("Test_Code")); 2719 const Function& function = Function::Handle(CreateFunction("Test_Code"));
2716 Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); 2720 Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_));
2717 function.AttachCode(code); 2721 function.AttachCode(code);
2718 Instructions& instructions = Instructions::Handle(code.instructions()); 2722 Instructions& instructions = Instructions::Handle(code.instructions());
2719 uword payload_start = instructions.PayloadStart(); 2723 uword payload_start = instructions.PayloadStart();
2720 EXPECT_EQ(instructions.raw(), Instructions::FromPayloadStart(payload_start)); 2724 EXPECT_EQ(instructions.raw(), Instructions::FromPayloadStart(payload_start));
2721 // Try writing into the generated code, expected to crash. 2725 // Try writing into the generated code, expected to crash.
2722 *(reinterpret_cast<char*>(payload_start) + 1) = 1; 2726 *(reinterpret_cast<char*>(payload_start) + 1) = 1;
2723 if (!FLAG_write_protect_code) { 2727 if (!FLAG_write_protect_code) {
2724 // Since this test is expected to crash, crash if write protection of code 2728 // Since this test is expected to crash, crash if write protection of code
2725 // is switched off. 2729 // is switched off.
2726 // TODO(regis, fschneider): Should this be FATAL() instead? 2730 // TODO(regis, fschneider): Should this be FATAL() instead?
2727 OS::DebugBreak(); 2731 OS::DebugBreak();
2728 } 2732 }
2733 MallocHooks::set_stack_trace_collection_enabled(
2734 stack_trace_collection_enabled);
2729 } 2735 }
2730 2736
2731 2737
2732 // Test for Embedded String object in the instructions. 2738 // Test for Embedded String object in the instructions.
2733 ISOLATE_UNIT_TEST_CASE(EmbedStringInCode) { 2739 ISOLATE_UNIT_TEST_CASE(EmbedStringInCode) {
2734 extern void GenerateEmbedStringInCode(Assembler * assembler, const char* str); 2740 extern void GenerateEmbedStringInCode(Assembler * assembler, const char* str);
2735 const char* kHello = "Hello World!"; 2741 const char* kHello = "Hello World!";
2736 word expected_length = static_cast<word>(strlen(kHello)); 2742 word expected_length = static_cast<word>(strlen(kHello));
2737 Assembler _assembler_; 2743 Assembler _assembler_;
2738 GenerateEmbedStringInCode(&_assembler_, kHello); 2744 GenerateEmbedStringInCode(&_assembler_, kHello);
(...skipping 1956 matching lines...) Expand 10 before | Expand all | Expand 10 after
4695 // utf32->utf16 conversion. 4701 // utf32->utf16 conversion.
4696 int32_t char_codes[] = {0, 0x0a, 0x0d, 0x7f, 0xff, 4702 int32_t char_codes[] = {0, 0x0a, 0x0d, 0x7f, 0xff,
4697 0xffff, 0xd800, 0xdc00, 0xdbff, 0xdfff}; 4703 0xffff, 0xd800, 0xdc00, 0xdbff, 0xdfff};
4698 4704
4699 const String& str = 4705 const String& str =
4700 String::Handle(String::FromUTF32(char_codes, ARRAY_SIZE(char_codes))); 4706 String::Handle(String::FromUTF32(char_codes, ARRAY_SIZE(char_codes)));
4701 EXPECT(str.Equals(char_codes, ARRAY_SIZE(char_codes))); 4707 EXPECT(str.Equals(char_codes, ARRAY_SIZE(char_codes)));
4702 } 4708 }
4703 4709
4704 } // namespace dart 4710 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/malloc_hooks_unsupported.cc ('k') | runtime/vm/os.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698