| OLD | NEW |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 #include "conformance_test_shared.h" // NOLINT(build/include) | 5 #include "conformance_test_shared.h" // NOLINT(build/include) |
| 6 | 6 |
| 7 #include <pthread.h> | 7 #include <pthread.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 | 10 |
| 11 #include "include/fletch_api.h" | 11 #include "include/dartino_api.h" |
| 12 #include "include/service_api.h" | 12 #include "include/service_api.h" |
| 13 | 13 |
| 14 static const int kDone = 1; | 14 static const int kDone = 1; |
| 15 | 15 |
| 16 static pthread_mutex_t mutex; | 16 static pthread_mutex_t mutex; |
| 17 static pthread_cond_t cond; | 17 static pthread_cond_t cond; |
| 18 static int status = 0; | 18 static int status = 0; |
| 19 | 19 |
| 20 static void ChangeStatusAndNotify(int new_status) { | 20 static void ChangeStatusAndNotify(int new_status) { |
| 21 pthread_mutex_lock(&mutex); | 21 pthread_mutex_lock(&mutex); |
| 22 status = new_status; | 22 status = new_status; |
| 23 pthread_cond_signal(&cond); | 23 pthread_cond_signal(&cond); |
| 24 pthread_mutex_unlock(&mutex); | 24 pthread_mutex_unlock(&mutex); |
| 25 } | 25 } |
| 26 | 26 |
| 27 static void WaitForStatus(int expected) { | 27 static void WaitForStatus(int expected) { |
| 28 pthread_mutex_lock(&mutex); | 28 pthread_mutex_lock(&mutex); |
| 29 while (expected != status) pthread_cond_wait(&cond, &mutex); | 29 while (expected != status) pthread_cond_wait(&cond, &mutex); |
| 30 pthread_mutex_unlock(&mutex); | 30 pthread_mutex_unlock(&mutex); |
| 31 } | 31 } |
| 32 | 32 |
| 33 static void* DartThreadEntry(void* arg) { | 33 static void* DartThreadEntry(void* arg) { |
| 34 const char* path = static_cast<char*>(arg); | 34 const char* path = static_cast<char*>(arg); |
| 35 FletchSetup(); | 35 DartinoSetup(); |
| 36 FletchRunSnapshotFromFile(path); | 36 DartinoRunSnapshotFromFile(path); |
| 37 FletchTearDown(); | 37 DartinoTearDown(); |
| 38 ChangeStatusAndNotify(kDone); | 38 ChangeStatusAndNotify(kDone); |
| 39 return NULL; | 39 return NULL; |
| 40 } | 40 } |
| 41 | 41 |
| 42 static void RunSnapshotInNewThread(char* path) { | 42 static void RunSnapshotInNewThread(char* path) { |
| 43 pthread_t thread; | 43 pthread_t thread; |
| 44 int result = pthread_create(&thread, NULL, DartThreadEntry, path); | 44 int result = pthread_create(&thread, NULL, DartThreadEntry, path); |
| 45 if (result != 0) { | 45 if (result != 0) { |
| 46 perror("Failed to start thread"); | 46 perror("Failed to start thread"); |
| 47 exit(1); | 47 exit(1); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 void SetupConformanceTest(int argc, char** argv) { | 51 void SetupConformanceTest(int argc, char** argv) { |
| 52 pthread_mutex_init(&mutex, NULL); | 52 pthread_mutex_init(&mutex, NULL); |
| 53 pthread_cond_init(&cond, NULL); | 53 pthread_cond_init(&cond, NULL); |
| 54 ServiceApiSetup(); | 54 ServiceApiSetup(); |
| 55 RunSnapshotInNewThread(argv[1]); | 55 RunSnapshotInNewThread(argv[1]); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void TearDownConformanceTest() { | 58 void TearDownConformanceTest() { |
| 59 WaitForStatus(kDone); | 59 WaitForStatus(kDone); |
| 60 ServiceApiTearDown(); | 60 ServiceApiTearDown(); |
| 61 } | 61 } |
| OLD | NEW |