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