int main (void) { cs_error_t res; cpg_handle_t handle; size_t buffer_lens[ALLOCATIONS]; void *buffers[ALLOCATIONS]; int i, j; printf ("stress cpgzc running %d allocations for %d iterations\n", ALLOCATIONS, ITERATIONS); signal (SIGINT, sigintr_handler); res = cpg_initialize (&handle, &callbacks); if (res != CS_OK) { printf ("FAIL %d\n", res); exit (-1); } for (j = 0; j < ITERATIONS; j++) { for (i = 0; i < ALLOCATIONS; i++) { buffer_lens[i] = (random() % MAX_SIZE) + 1; res = cpg_zcb_alloc ( handle, buffer_lens[i], &buffers[i]); if (res != CS_OK) { printf ("FAIL %d\n", res); exit (-1); } } for (i = 0; i < ALLOCATIONS; i++) { res = cpg_zcb_free ( handle, buffers[i]); if (res != CS_OK) { printf ("FAIL %d\n", res); exit (-1); } } if ((j != 0) && (j % 20) == 0) { printf ("iteration %d\n", j); } } cpg_finalize (handle); printf ("PASS\n"); exit (0); }
static void send_some_more_messages_zcb (void) { msg_t *my_msg; int i; int send_now; size_t payload_size; size_t total_size; unsigned int sha1_len; cs_error_t res; cpg_flow_control_state_t fc_state; void *zcb_buffer; if (cpg_fd < 0) return; send_now = my_msgs_to_send; payload_size = (rand() % 100000); total_size = payload_size + sizeof (msg_t); cpg_zcb_alloc (cpg_handle, total_size, &zcb_buffer); my_msg = (msg_t*)zcb_buffer; qb_log(LOG_DEBUG, "send_now:%d", send_now); my_msg->pid = my_pid; my_msg->nodeid = my_nodeid; my_msg->size = sizeof (msg_t) + payload_size; my_msg->seq = my_msgs_sent; for (i = 0; i < payload_size; i++) { my_msg->payload[i] = i; } PK11_DigestBegin(sha1_context); PK11_DigestOp(sha1_context, my_msg->payload, payload_size); PK11_DigestFinal(sha1_context, my_msg->sha1, &sha1_len, sizeof(my_msg->sha1)); for (i = 0; i < send_now; i++) { res = cpg_flow_control_state_get (cpg_handle, &fc_state); if (res == CS_OK && fc_state == CPG_FLOW_CONTROL_ENABLED) { /* lets do this later */ send_some_more_messages_later (); qb_log (LOG_INFO, "flow control enabled."); goto free_buffer; } res = cpg_zcb_mcast_joined (cpg_handle, CPG_TYPE_AGREED, zcb_buffer, total_size); if (res == CS_ERR_TRY_AGAIN) { /* lets do this later */ send_some_more_messages_later (); goto free_buffer; } else if (res != CS_OK) { qb_log (LOG_ERR, "cpg_mcast_joined error:%d, exiting.", res); exit (-2); } my_msgs_sent++; my_msgs_to_send--; } free_buffer: cpg_zcb_free (cpg_handle, zcb_buffer); }
static void send_some_more_messages_zcb (void) { msg_t *my_msg; int i; int send_now; size_t payload_size; size_t total_size; hash_state sha1_hash; cs_error_t res; cpg_flow_control_state_t fc_state; void *zcb_buffer; if (cpg_fd < 0) return; send_now = my_msgs_to_send; payload_size = (rand() % 100000); total_size = payload_size + sizeof (msg_t); cpg_zcb_alloc (cpg_handle, total_size, &zcb_buffer); my_msg = (msg_t*)zcb_buffer; //syslog (LOG_DEBUG,"%s() send_now:%d", __func__, send_now); my_msg->pid = my_pid; my_msg->nodeid = my_nodeid; my_msg->size = sizeof (msg_t) + payload_size; my_msg->seq = 0; for (i = 0; i < payload_size; i++) { my_msg->payload[i] = i; } sha1_init (&sha1_hash); sha1_process (&sha1_hash, my_msg->payload, payload_size); sha1_done (&sha1_hash, my_msg->sha1); for (i = 0; i < send_now; i++) { res = cpg_flow_control_state_get (cpg_handle, &fc_state); if (res == CS_OK && fc_state == CPG_FLOW_CONTROL_ENABLED) { /* lets do this later */ send_some_more_messages_later (); syslog (LOG_INFO, "%s() flow control enabled.", __func__); goto free_buffer; } res = cpg_zcb_mcast_joined (cpg_handle, CPG_TYPE_AGREED, zcb_buffer, total_size); if (res == CS_ERR_TRY_AGAIN) { /* lets do this later */ send_some_more_messages_later (); // if (i > 0) { // syslog (LOG_INFO, "%s() TRY_AGAIN %d to send.", // __func__, my_msgs_to_send); // } goto free_buffer; } else if (res != CS_OK) { syslog (LOG_ERR, "%s() -> cpg_mcast_joined error:%d, exiting.", __func__, res); exit (-2); } my_msgs_to_send--; } free_buffer: cpg_zcb_free (cpg_handle, zcb_buffer); }