static bool _finalize_timer() { timer_read_begin(); struct timer_info *timer = get_timer_info(); timer_read_end(); assert( timer != NULL ); debug( "Deleting timer callbacks ( timer_callbacks = %p ).", timer->timer_callbacks ); if ( timer->timer_callbacks != NULL ) { for ( dlist_element *e = timer->timer_callbacks->next; e; e = e->next ) { xfree( e->data ); } delete_dlist( timer->timer_callbacks ); timer->timer_callbacks = NULL; } else { error( "All timer callbacks are already deleted or not created yet." ); } timer_write_begin(); delete_timer_info( timer ); timer_write_end(); return true; }
// find elements of "charlie" <-> "bravo" <-> "alpha" static void test_find_element() { char element_data1[] = "alpha"; char element_data2[] = "bravo"; char element_data3[] = "charlie"; char no_such_element[] = "NO SUCH ELEMENT"; dlist_element *new_element = create_dlist(); insert_after_dlist( new_element, element_data1 ); insert_after_dlist( new_element, element_data2 ); insert_after_dlist( new_element, element_data3 ); dlist_element *e = NULL; e = find_element( new_element, element_data3 ); assert_true( new_element->next == e ); e = find_element( new_element, element_data2 ); assert_true( new_element->next->next == e ); e = find_element( new_element, element_data1 ); assert_true( new_element->next->next->next == e ); e = find_element( new_element->next->next->next, element_data2 ); assert_true( new_element->next->next == e ); e = find_element( new_element, no_such_element ); assert_true( e == NULL ); delete_dlist( new_element ); }
void finalize_probe_timer_table( void ) { dlist_element *dlist; for ( dlist = probe_timer_table->next; dlist != NULL; dlist = dlist->next ) { xfree( dlist->data ); } delete_dlist( probe_timer_table ); probe_timer_table = NULL; probe_timer_last = NULL; }
static void test_create_dlist() { dlist_element *new_element = create_dlist(); assert_true( new_element != NULL ); assert_true( new_element->data == NULL ); assert_true( new_element->next == NULL ); assert_true( new_element->prev == NULL ); delete_dlist( new_element ); }
void delete_action_list( action_list *list ) { assert( list != NULL ); for ( dlist_element *element = get_first_element( list ); element != NULL; element = element->next ) { action *action = element->data; if ( action != NULL ) { delete_action( action ); } } delete_dlist( list ); }
static void setup_reverse_path( int status, const path *p, void *user_data ) { assert(user_data); packet_out_params *params = user_data; if ( status != SETUP_SUCCEEDED ) { error( "Failed to set up path ( status = %d ).", status ); output_packet( params->packet, params->out_datapath_id, params->out_port_no, params->out_vid ); free_buffer( params->packet ); xfree( params ); return; } struct ofp_match rmatch; set_ipv4_reverse_match( &rmatch, &(p->match) ); rmatch.dl_vlan = params->out_vid; openflow_actions *vlan_actions; vlan_actions = create_openflow_actions_to_update_vid( params->out_vid, params->in_vid ); path *rpath = create_path( rmatch, p->priority, p->idle_timeout, p->hard_timeout ); assert( rpath != NULL ); list_element *hops = p->hops; dlist_element *rhops = create_dlist(); while ( hops != NULL ) { hop *h = hops->data; assert( h != NULL ); hop *rh = create_hop( h->datapath_id, h->out_port, h->in_port, vlan_actions ); if ( vlan_actions ) { delete_actions( vlan_actions ); vlan_actions = NULL; } assert( rh != NULL ); rhops = insert_before_dlist( rhops, rh ); hops = hops->next; } while ( rhops != NULL && rhops->data != NULL ) { append_hop_to_path( rpath, ( hop * ) rhops->data ); rhops = rhops->next; } bool ret = setup_path( rpath, handle_setup, params, NULL, NULL ); if ( ret != true ) { error( "Failed to set up reverse path." ); output_packet( params->packet, params->out_datapath_id, params->out_port_no, params->out_vid ); free_buffer( params->packet ); xfree( params ); } delete_path( rpath ); delete_dlist( rhops ); }
void delete_action_bucket_list( bucket_list *list ) { assert( list != NULL ); dlist_element *element = get_first_element( list ); while ( element != NULL ) { bucket *b = element->data; if ( b != NULL ) { delete_action_bucket( b ); } element = element->next; } delete_dlist( list ); }
// Remove "charlie" of "alpha" <-> "bravo" <-> "charlie" static void test_remove_last_element() { char element_data2[] = "bravo"; char element_data3[] = "charlie"; dlist_element *alpha = create_dlist(); dlist_element *bravo = insert_after_dlist( alpha, element_data2 ); dlist_element *charlie = insert_after_dlist( bravo, element_data3 ); assert_true( delete_dlist_element( charlie ) ); assert_true( bravo->next == NULL ); assert_true( bravo->prev == alpha ); delete_dlist( alpha ); }
// "alpha" <-> "bravo" <-> "charlie" static void test_get_last_element() { char element_data2[] = "bravo"; char element_data3[] = "charlie"; dlist_element *alpha = create_dlist(); dlist_element *bravo = insert_after_dlist( alpha, element_data2 ); dlist_element *charlie = insert_after_dlist( bravo, element_data3 ); assert_true( get_last_element( alpha ) == charlie ); assert_true( get_last_element( bravo ) == charlie ); assert_true( get_last_element( charlie ) == charlie ); delete_dlist( alpha ); }
/** * Deletes event callbacks from callback list. * @param None * @return bool True if the list is deleted */ bool finalize_timer() { dlist_element *e; debug( "Deleting timer callbacks ( timer_callbacks = %p ).", timer_callbacks ); if ( timer_callbacks != NULL ) { for ( e = timer_callbacks->next; e; e = e->next ) { xfree( e->data ); } delete_dlist( timer_callbacks ); timer_callbacks = NULL; } else { error( "All timer callbacks are already deleted or not created yet." ); } return true; }
// NULL <- "alpha" <-> "bravo" <-> "charlie" <-> new_element static void test_insert_before_dlist() { char element_data1[] = "alpha"; char element_data2[] = "bravo"; char element_data3[] = "charlie"; dlist_element *new_element = create_dlist(); assert_true( insert_before_dlist( new_element, element_data1 ) ); assert_true( insert_before_dlist( new_element, element_data2 ) ); assert_true( insert_before_dlist( new_element, element_data3 ) ); assert_string_equal( new_element->prev->data, "charlie" ); assert_string_equal( new_element->prev->prev->data, "bravo" ); assert_string_equal( new_element->prev->prev->prev->data, "alpha" ); assert_true( new_element->prev->prev->prev->prev == NULL ); assert_true( new_element->prev->next == new_element ); assert_true( new_element->prev->prev->next->next == new_element ); assert_true( new_element->prev->prev->prev->next->next->next == new_element ); delete_dlist( new_element ); }
static void test_delete_dlist_aborts_with_NULL_dlist() { expect_string( mock_die, output, "element must not be NULL" ); expect_assert_failure( delete_dlist( NULL ) ); }