OLD | NEW |
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/assert.h" | 5 #include "platform/assert.h" |
6 #include "vm/allocation.h" | 6 #include "vm/allocation.h" |
7 #include "vm/longjump.h" | 7 #include "vm/longjump.h" |
8 #include "vm/unit_test.h" | 8 #include "vm/unit_test.h" |
9 | 9 |
10 namespace dart { | 10 namespace dart { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 int data = 1; | 81 int data = 1; |
82 StackAllocatedDestructionHelper(&data); | 82 StackAllocatedDestructionHelper(&data); |
83 EXPECT_EQ(4, data); | 83 EXPECT_EQ(4, data); |
84 } | 84 } |
85 | 85 |
86 | 86 |
87 static void StackAllocatedLongJumpHelper(int* ptr, LongJumpScope* jump) { | 87 static void StackAllocatedLongJumpHelper(int* ptr, LongJumpScope* jump) { |
88 TestValueObject stacked(ptr); | 88 TestValueObject stacked(ptr); |
89 EXPECT_EQ(2, *ptr); | 89 EXPECT_EQ(2, *ptr); |
90 *ptr = 3; | 90 *ptr = 3; |
91 const Error& error = | 91 const Error& error = Error::Handle(LanguageError::New( |
92 Error::Handle(LanguageError::New( | 92 String::Handle(String::New("StackAllocatedLongJump")))); |
93 String::Handle(String::New("StackAllocatedLongJump")))); | |
94 jump->Jump(1, error); | 93 jump->Jump(1, error); |
95 UNREACHABLE(); | 94 UNREACHABLE(); |
96 } | 95 } |
97 | 96 |
98 | 97 |
99 TEST_CASE(StackAllocatedLongJump) { | 98 TEST_CASE(StackAllocatedLongJump) { |
100 LongJumpScope jump; | 99 LongJumpScope jump; |
101 int data = 1; | 100 int data = 1; |
102 if (setjmp(*jump.Set()) == 0) { | 101 if (setjmp(*jump.Set()) == 0) { |
103 StackAllocatedLongJumpHelper(&data, &jump); | 102 StackAllocatedLongJumpHelper(&data, &jump); |
(...skipping 24 matching lines...) Expand all Loading... |
128 int data = 1; | 127 int data = 1; |
129 StackResourceDestructionHelper(&data); | 128 StackResourceDestructionHelper(&data); |
130 EXPECT_EQ(7, data); | 129 EXPECT_EQ(7, data); |
131 } | 130 } |
132 | 131 |
133 | 132 |
134 static void StackedStackResourceLongJumpHelper(int* ptr, LongJumpScope* jump) { | 133 static void StackedStackResourceLongJumpHelper(int* ptr, LongJumpScope* jump) { |
135 TestStackedStackResource stacked(ptr); | 134 TestStackedStackResource stacked(ptr); |
136 EXPECT_EQ(4, *ptr); | 135 EXPECT_EQ(4, *ptr); |
137 *ptr = 5; | 136 *ptr = 5; |
138 const Error& error = | 137 const Error& error = Error::Handle(LanguageError::New( |
139 Error::Handle(LanguageError::New( | 138 String::Handle(String::New("StackedStackResourceLongJump")))); |
140 String::Handle(String::New("StackedStackResourceLongJump")))); | |
141 jump->Jump(1, error); | 139 jump->Jump(1, error); |
142 UNREACHABLE(); | 140 UNREACHABLE(); |
143 } | 141 } |
144 | 142 |
145 | 143 |
146 static void StackResourceLongJumpHelper(int* ptr, LongJumpScope* jump) { | 144 static void StackResourceLongJumpHelper(int* ptr, LongJumpScope* jump) { |
147 TestStackResource stacked(ptr); | 145 TestStackResource stacked(ptr); |
148 EXPECT_EQ(2, *ptr); | 146 EXPECT_EQ(2, *ptr); |
149 *ptr = 3; | 147 *ptr = 3; |
150 StackedStackResourceLongJumpHelper(ptr, jump); | 148 StackedStackResourceLongJumpHelper(ptr, jump); |
151 UNREACHABLE(); | 149 UNREACHABLE(); |
152 } | 150 } |
153 | 151 |
154 | 152 |
155 TEST_CASE(StackResourceLongJump) { | 153 TEST_CASE(StackResourceLongJump) { |
156 LongJumpScope* base = Thread::Current()->long_jump_base(); | 154 LongJumpScope* base = Thread::Current()->long_jump_base(); |
157 { | 155 { |
158 LongJumpScope jump; | 156 LongJumpScope jump; |
159 int data = 1; | 157 int data = 1; |
160 if (setjmp(*jump.Set()) == 0) { | 158 if (setjmp(*jump.Set()) == 0) { |
161 StackResourceLongJumpHelper(&data, &jump); | 159 StackResourceLongJumpHelper(&data, &jump); |
162 UNREACHABLE(); | 160 UNREACHABLE(); |
163 } | 161 } |
164 EXPECT_EQ(7, data); | 162 EXPECT_EQ(7, data); |
165 } | 163 } |
166 ASSERT(base == Thread::Current()->long_jump_base()); | 164 ASSERT(base == Thread::Current()->long_jump_base()); |
167 } | 165 } |
168 | 166 |
169 } // namespace dart | 167 } // namespace dart |
OLD | NEW |