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 #define TESTING | 5 #define TESTING |
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 #include "src/shared/assert.h" // NOLINT(build/include) | 14 #include "src/shared/assert.h" // NOLINT(build/include) |
15 #include "cc/service_one.h" // NOLINT(build/include) | 15 #include "cc/service_one.h" // NOLINT(build/include) |
16 #include "cc/service_two.h" // NOLINT(build/include) | 16 #include "cc/service_two.h" // NOLINT(build/include) |
17 | 17 |
18 static const int kDone = 1; | 18 static const int kDone = 1; |
19 | 19 |
20 static pthread_mutex_t mutex; | 20 static pthread_mutex_t mutex; |
21 static pthread_cond_t cond; | 21 static pthread_cond_t cond; |
22 static int status = 0; | 22 static int status = 0; |
23 | 23 |
24 static void ChangeStatusAndNotify(int new_status) { | 24 static void ChangeStatusAndNotify(int new_status) { |
25 pthread_mutex_lock(&mutex); | 25 pthread_mutex_lock(&mutex); |
26 status = new_status; | 26 status = new_status; |
27 pthread_cond_signal(&cond); | 27 pthread_cond_signal(&cond); |
28 pthread_mutex_unlock(&mutex); | 28 pthread_mutex_unlock(&mutex); |
29 } | 29 } |
30 | 30 |
31 static void WaitForStatus(int expected) { | 31 static void WaitForStatus(int expected) { |
32 pthread_mutex_lock(&mutex); | 32 pthread_mutex_lock(&mutex); |
33 while (expected != status) pthread_cond_wait(&cond, &mutex); | 33 while (expected != status) pthread_cond_wait(&cond, &mutex); |
34 pthread_mutex_unlock(&mutex); | 34 pthread_mutex_unlock(&mutex); |
35 } | 35 } |
36 | 36 |
37 static void* DartThreadEntry(void* arg) { | 37 static void* DartThreadEntry(void* arg) { |
38 const char* path = static_cast<const char*>(arg); | 38 const char* path = static_cast<const char*>(arg); |
39 FletchSetup(); | 39 DartinoSetup(); |
40 FletchRunSnapshotFromFile(path); | 40 DartinoRunSnapshotFromFile(path); |
41 FletchTearDown(); | 41 DartinoTearDown(); |
42 ChangeStatusAndNotify(kDone); | 42 ChangeStatusAndNotify(kDone); |
43 return NULL; | 43 return NULL; |
44 } | 44 } |
45 | 45 |
46 static void SetupMultipleSnapshotsTest(int argc, char** argv) { | 46 static void SetupMultipleSnapshotsTest(int argc, char** argv) { |
47 pthread_mutex_init(&mutex, NULL); | 47 pthread_mutex_init(&mutex, NULL); |
48 pthread_cond_init(&cond, NULL); | 48 pthread_cond_init(&cond, NULL); |
49 ServiceApiSetup(); | 49 ServiceApiSetup(); |
50 pthread_t thread; | 50 pthread_t thread; |
51 int result = pthread_create(&thread, NULL, DartThreadEntry, argv[1]); | 51 int result = pthread_create(&thread, NULL, DartThreadEntry, argv[1]); |
(...skipping 21 matching lines...) Expand all Loading... |
73 | 73 |
74 int main(int argc, char** argv) { | 74 int main(int argc, char** argv) { |
75 if (argc < 2) { | 75 if (argc < 2) { |
76 printf("Usage: %s <snapshot>\n", argv[0]); | 76 printf("Usage: %s <snapshot>\n", argv[0]); |
77 return 1; | 77 return 1; |
78 } | 78 } |
79 SetupMultipleSnapshotsTest(argc, argv); | 79 SetupMultipleSnapshotsTest(argc, argv); |
80 InteractWithServices(); | 80 InteractWithServices(); |
81 TearDownMultipleSnapshotsTest(); | 81 TearDownMultipleSnapshotsTest(); |
82 } | 82 } |
OLD | NEW |