| 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* argv) { | 37 static void* DartThreadEntry(void* argv) { |
| 38 const char** paths = static_cast<const char**>(argv); | 38 const char** paths = static_cast<const char**>(argv); |
| 39 FletchSetup(); | 39 DartinoSetup(); |
| 40 FletchProgram programs[2]; | 40 DartinoProgram programs[2]; |
| 41 int exitcodes[2]; | 41 int exitcodes[2]; |
| 42 programs[0] = FletchLoadSnapshotFromFile(paths[1]); | 42 programs[0] = DartinoLoadSnapshotFromFile(paths[1]); |
| 43 programs[1] = FletchLoadSnapshotFromFile(paths[2]); | 43 programs[1] = DartinoLoadSnapshotFromFile(paths[2]); |
| 44 FletchRunMultipleMain(2, programs, exitcodes); | 44 DartinoRunMultipleMain(2, programs, exitcodes); |
| 45 FletchDeleteProgram(programs[0]); | 45 DartinoDeleteProgram(programs[0]); |
| 46 FletchDeleteProgram(programs[1]); | 46 DartinoDeleteProgram(programs[1]); |
| 47 FletchTearDown(); | 47 DartinoTearDown(); |
| 48 ChangeStatusAndNotify(kDone); | 48 ChangeStatusAndNotify(kDone); |
| 49 return NULL; | 49 return NULL; |
| 50 } | 50 } |
| 51 | 51 |
| 52 static void SetupMultipleSnapshotsTest(int argc, char** argv) { | 52 static void SetupMultipleSnapshotsTest(int argc, char** argv) { |
| 53 pthread_mutex_init(&mutex, NULL); | 53 pthread_mutex_init(&mutex, NULL); |
| 54 pthread_cond_init(&cond, NULL); | 54 pthread_cond_init(&cond, NULL); |
| 55 ServiceApiSetup(); | 55 ServiceApiSetup(); |
| 56 pthread_t thread; | 56 pthread_t thread; |
| 57 int result = pthread_create(&thread, NULL, DartThreadEntry, argv); | 57 int result = pthread_create(&thread, NULL, DartThreadEntry, argv); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 79 | 79 |
| 80 int main(int argc, char** argv) { | 80 int main(int argc, char** argv) { |
| 81 if (argc < 3) { | 81 if (argc < 3) { |
| 82 printf("Usage: %s <snapshot_one> <snapshot_two>\n", argv[0]); | 82 printf("Usage: %s <snapshot_one> <snapshot_two>\n", argv[0]); |
| 83 return 1; | 83 return 1; |
| 84 } | 84 } |
| 85 SetupMultipleSnapshotsTest(argc, argv); | 85 SetupMultipleSnapshotsTest(argc, argv); |
| 86 InteractWithServices(); | 86 InteractWithServices(); |
| 87 TearDownMultipleSnapshotsTest(); | 87 TearDownMultipleSnapshotsTest(); |
| 88 } | 88 } |
| OLD | NEW |