LONGBOW_TEST_CASE(Global, parcNotifier_ThreadedTest) { TestData *data = parcMemory_AllocateAndClear(sizeof(TestData)); assertNotNull(data, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(TestData)); data->notifier = parcNotifier_Create(); data->notificationsToSend = 10; data->notificationsToRecieve = data->notificationsToSend; data->notificationsSent = 0; data->notificationsReceived = 0; data->barrier = 2; pthread_create(&data->consumerThread, NULL, consumer, data); pthread_create(&data->producerThread, NULL, producer, data); // wait for them to exit pthread_join(data->producerThread, NULL); pthread_join(data->consumerThread, NULL); assertTrue(data->notificationsReceived >= data->notificationsToRecieve, "Did not write all items got %u expected %u\n", data->notificationsReceived, data->notificationsToRecieve); parcNotifier_Release(&data->notifier); parcMemory_Deallocate((void **) &data); }
LONGBOW_TEST_CASE(Global, parcNotifier_PauseEvent_NotPaused) { PARCNotifier *notifier = parcNotifier_Create(); parcNotifier_PauseEvents(notifier); assertTrue(notifier->paused == 1, "Not paused, got %d expected %d", notifier->paused, 1); assertTrue(notifier->skippedNotify == 0, "Wrong skipped, got %d expected %d", notifier->skippedNotify, 0); parcNotifier_Release(¬ifier); }
LONGBOW_TEST_CASE(Global, parcNotifier_Notify_First) { PARCNotifier *notifier = parcNotifier_Create(); bool success = parcNotifier_Notify(notifier); assertTrue(success, "Did not succeed on first notify"); assertTrue(notifier->paused == 1, "Not paused, got %d expected %d", notifier->paused, 1); assertTrue(notifier->skippedNotify == 0, "Wrong skipped, got %d expected %d", notifier->skippedNotify, 0); parcNotifier_Release(¬ifier); }
LONGBOW_TEST_CASE(Global, parcNotifier_Notify_Twice) { PARCNotifier *notifier = parcNotifier_Create(); parcNotifier_Notify(notifier); bool success = parcNotifier_Notify(notifier); assertFalse(success, "Should have failed on second notify"); assertTrue(notifier->paused == 1, "Not paused, got %d expected %d", notifier->paused, 1); assertTrue(notifier->skippedNotify == 1, "Wrong skipped, got %d expected %d", notifier->skippedNotify, 1); parcNotifier_Release(¬ifier); }
static void _commonTeardown(TestData *data) { rtaFramework_Teardown(data->framework); parcRingBuffer1x1_Release(&data->commandRingBuffer); parcNotifier_Release(&data->commandNotifier); rtaFramework_Destroy(&data->framework); close(data->api_fds[0]); close(data->api_fds[1]); parcMemory_Deallocate((void **) &data); }