Skip to content

Commit f5b0386

Browse files
committed
Increase sync resolution; remove semaphore exclusivity
The O_EXCL flag passed when creating the semaphores was causing execution to fail on macOC. I've therefore removed exclusivity, which looks horrible to me, but allows execution to continue. Similarly, synchronisation was failing with event steps of 100, resulting in the FSM-Service test failing with a timeout error. Increasing the timer resolution to steps of 25 allows all the tests to pass successfully.
1 parent a143d17 commit f5b0386

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

tests/test_fsm.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ void * event_loop_thread(void * arg) {
468468
if (head != NULL) {
469469
while (head->event.type == TIMEOUT && head->event.time > currentTime) {
470470
// Wait a little bit so the other thread can synchronize
471-
currentTime += 100;
471+
currentTime += 25;
472472
pthread_mutex_unlock(&queue_mutex);
473473
usleep(1);
474474
pthread_mutex_lock(&queue_mutex);
@@ -633,9 +633,9 @@ START_TEST (fsm_pico_test) {
633633
local.global_data_len = 0;
634634
pthread_mutex_init(& local.global_data_mutex, NULL);
635635

636-
local.read_semaphore = sem_open("picofsmpico_read", O_CREAT | O_EXCL, 0644, 0);
636+
local.read_semaphore = sem_open("picofsmpicoread", O_CREAT, 0644, 0);
637637
ck_assert(local.read_semaphore != SEM_FAILED);
638-
local.connect_semaphore = sem_open("picofsmpico_connect", O_CREAT | O_EXCL, 0644, 0);
638+
local.connect_semaphore = sem_open("picofsmpicoconnect", O_CREAT, 0644, 0);
639639
ck_assert(local.connect_semaphore != SEM_FAILED);
640640

641641
picoShared = shared_new();
@@ -725,9 +725,9 @@ START_TEST (fsm_pico_test) {
725725
buffer_delete(symmetricKey);
726726

727727
sem_close(local.read_semaphore);
728-
sem_unlink("picofsmpico_read");
728+
sem_unlink("picofsmpicoread");
729729
sem_close(local.connect_semaphore);
730-
sem_unlink("picofsmpico_connect");
730+
sem_unlink("picofsmpicoconnect");
731731
}
732732
END_TEST
733733

@@ -871,11 +871,11 @@ START_TEST (fsm_service_test) {
871871
local.global_data_len = 0;
872872
pthread_mutex_init(& local.global_data_mutex, NULL);
873873

874-
local.read_semaphore = sem_open("picofsmservice_read", O_CREAT | O_EXCL, 0644, 0);
874+
local.read_semaphore = sem_open("picofsmserviceread", O_CREAT, 0644, 0);
875875
ck_assert(local.read_semaphore != SEM_FAILED);
876-
local.authenticated_semaphore = sem_open("picofsmservice_authenticate", O_CREAT | O_EXCL, 0644, 0);
876+
local.authenticated_semaphore = sem_open("picofsmserviceauthenticated", O_CREAT, 0644, 0);
877877
ck_assert(local.authenticated_semaphore != SEM_FAILED);
878-
local.stop_semaphore = sem_open("picofsmservice_stop", O_CREAT | O_EXCL, 0644, 0);
878+
local.stop_semaphore = sem_open("picofsmservicestop", O_CREAT, 0644, 0);
879879
ck_assert(local.stop_semaphore != SEM_FAILED);
880880

881881
picoShared = shared_new();
@@ -956,15 +956,14 @@ START_TEST (fsm_service_test) {
956956
buffer_delete(local.symmetricKey);
957957

958958
sem_close(local.read_semaphore);
959-
sem_unlink("picofsmservice_read");
959+
sem_unlink("picofsmserviceread");
960960
sem_close(local.authenticated_semaphore);
961-
sem_unlink("picofsmservice_authenticate");
961+
sem_unlink("picofsmserviceauthenticated");
962962
sem_close(local.stop_semaphore);
963-
sem_unlink("picofsmservice_stop");
963+
sem_unlink("picofsmservicestop");
964964
}
965965
END_TEST
966966

967-
968967
int main (void) {
969968
int number_failed;
970969
Suite * s;

0 commit comments

Comments
 (0)