OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 | 2 |
3 // Redistribution and use in source and binary forms, with or without | 3 // Redistribution and use in source and binary forms, with or without |
4 // modification, are permitted provided that the following conditions are | 4 // modification, are permitted provided that the following conditions are |
5 // met: | 5 // met: |
6 // | 6 // |
7 // * Redistributions of source code must retain the above copyright | 7 // * Redistributions of source code must retain the above copyright |
8 // notice, this list of conditions and the following disclaimer. | 8 // notice, this list of conditions and the following disclaimer. |
9 // * Redistributions in binary form must reproduce the above | 9 // * Redistributions in binary form must reproduce the above |
10 // copyright notice, this list of conditions and the following | 10 // copyright notice, this list of conditions and the following |
(...skipping 10 matching lines...) Expand all Loading... |
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
29 #include <limits.h> | 29 #include <limits.h> |
30 | 30 |
| 31 #ifndef WIN32 |
| 32 #include <signal.h> // kill |
| 33 #include <unistd.h> // getpid |
| 34 #endif // WIN32 |
| 35 |
31 #include "v8.h" | 36 #include "v8.h" |
32 | 37 |
33 #include "api.h" | 38 #include "api.h" |
34 #include "isolate.h" | 39 #include "isolate.h" |
35 #include "compilation-cache.h" | 40 #include "compilation-cache.h" |
36 #include "execution.h" | 41 #include "execution.h" |
37 #include "objects.h" | 42 #include "objects.h" |
38 #include "snapshot.h" | 43 #include "snapshot.h" |
39 #include "platform.h" | 44 #include "platform.h" |
40 #include "utils.h" | 45 #include "utils.h" |
(...skipping 17146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17187 v8::HandleScope scope; | 17192 v8::HandleScope scope; |
17188 LocalContext context; | 17193 LocalContext context; |
17189 | 17194 |
17190 // Compile a try-finally clause where the finally block causes a GC | 17195 // Compile a try-finally clause where the finally block causes a GC |
17191 // while there still is a message pending for external reporting. | 17196 // while there still is a message pending for external reporting. |
17192 TryCatch try_catch; | 17197 TryCatch try_catch; |
17193 try_catch.SetVerbose(true); | 17198 try_catch.SetVerbose(true); |
17194 CompileRun("try { throw new Error(); } finally { gc(); }"); | 17199 CompileRun("try { throw new Error(); } finally { gc(); }"); |
17195 CHECK(try_catch.HasCaught()); | 17200 CHECK(try_catch.HasCaught()); |
17196 } | 17201 } |
| 17202 |
| 17203 |
| 17204 #ifndef WIN32 |
| 17205 class ThreadInterruptTest { |
| 17206 public: |
| 17207 ThreadInterruptTest() : sem_(NULL), sem_value_(0) { } |
| 17208 ~ThreadInterruptTest() { delete sem_; } |
| 17209 |
| 17210 void RunTest() { |
| 17211 sem_ = i::OS::CreateSemaphore(0); |
| 17212 |
| 17213 InterruptThread i_thread(this); |
| 17214 i_thread.Start(); |
| 17215 |
| 17216 sem_->Wait(); |
| 17217 CHECK_EQ(kExpectedValue, sem_value_); |
| 17218 } |
| 17219 |
| 17220 private: |
| 17221 static const int kExpectedValue = 1; |
| 17222 |
| 17223 class InterruptThread : public i::Thread { |
| 17224 public: |
| 17225 explicit InterruptThread(ThreadInterruptTest* test) |
| 17226 : Thread("InterruptThread"), test_(test) {} |
| 17227 |
| 17228 virtual void Run() { |
| 17229 struct sigaction action; |
| 17230 |
| 17231 // Ensure that we'll enter waiting condition |
| 17232 i::OS::Sleep(100); |
| 17233 |
| 17234 // Setup signal handler |
| 17235 memset(&action, 0, sizeof(action)); |
| 17236 action.sa_handler = SignalHandler; |
| 17237 sigaction(SIGCHLD, &action, NULL); |
| 17238 |
| 17239 // Send signal |
| 17240 kill(getpid(), SIGCHLD); |
| 17241 |
| 17242 // Ensure that if wait has returned because of error |
| 17243 i::OS::Sleep(100); |
| 17244 |
| 17245 // Set value and signal semaphore |
| 17246 test_->sem_value_ = 1; |
| 17247 test_->sem_->Signal(); |
| 17248 } |
| 17249 |
| 17250 static void SignalHandler(int signal) { |
| 17251 } |
| 17252 |
| 17253 private: |
| 17254 ThreadInterruptTest* test_; |
| 17255 struct sigaction sa_; |
| 17256 }; |
| 17257 |
| 17258 i::Semaphore* sem_; |
| 17259 volatile int sem_value_; |
| 17260 }; |
| 17261 |
| 17262 |
| 17263 THREADED_TEST(SemaphoreInterruption) { |
| 17264 ThreadInterruptTest().RunTest(); |
| 17265 } |
| 17266 #endif // WIN32 |
OLD | NEW |