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); }
static TestData * _commonSetup(void) { TestData *data = parcMemory_AllocateAndClear(sizeof(TestData)); assertNotNull(data, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(TestData)); data->commandRingBuffer = parcRingBuffer1x1_Create(128, NULL); data->commandNotifier = parcNotifier_Create(); data->framework = rtaFramework_Create(data->commandRingBuffer, data->commandNotifier); assertNotNull(data->framework, "rtaFramework_Create returned null"); CCNxStackConfig *stackConfig = ccnxStackConfig_Create(); apiConnector_ProtocolStackConfig(stackConfig); testingLower_ProtocolStackConfig(stackConfig); protocolStack_ComponentsConfigArgs(stackConfig, apiConnector_GetName(), testingLower_GetName(), NULL); rtaFramework_NonThreadedStepCount(data->framework, 10); // Create the protocol stack data->stackId = 1; RtaCommandCreateProtocolStack *createStack = rtaCommandCreateProtocolStack_Create(data->stackId, stackConfig); _rtaFramework_ExecuteCreateStack(data->framework, createStack); rtaCommandCreateProtocolStack_Release(&createStack); rtaFramework_NonThreadedStepCount(data->framework, 10); data->stack = (rtaFramework_GetProtocolStackByStackId(data->framework, data->stackId))->stack; // Create a connection in the stack int error = socketpair(AF_UNIX, SOCK_STREAM, 0, data->api_fds); assertFalse(error, "Error creating socket pair: (%d) %s", errno, strerror(errno)); CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create(); apiConnector_ConnectionConfig(connConfig); tlvCodec_ConnectionConfig(connConfig); testingLower_ConnectionConfig(connConfig); RtaCommandOpenConnection *openConnection = rtaCommandOpenConnection_Create(data->stackId, data->api_fds[PAIR_OTHER], data->api_fds[PAIR_TRANSPORT], ccnxConnectionConfig_GetJson(connConfig)); _rtaFramework_ExecuteOpenConnection(data->framework, openConnection); rtaCommandOpenConnection_Release(&openConnection); rtaFramework_NonThreadedStepCount(data->framework, 10); data->connection = rtaConnectionTable_GetByApiFd(data->framework->connectionTable, data->api_fds[PAIR_OTHER]); // cleanup ccnxConnectionConfig_Destroy(&connConfig); ccnxStackConfig_Release(&stackConfig); return 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); }