Changeset 5997


Ignore:
Timestamp:
Jun 2, 2008, 3:52:16 PM (14 years ago)
Author:
charles
Message:

add in some very simple bitfield tests, and add a #define option to turn it into a speed test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/utils-test.c

    r5860 r5997  
    44#include "utils.h"
    55
     6#define VERBOSE 1
     7#define NUM_LOOPS 1
     8#define SPEED_TEST 0
     9
     10#if SPEED_TEST
     11#undef VERBOSE
    612#define VERBOSE 0
     13#undef NUM_LOOPS
     14#define NUM_LOOPS 200
     15#endif
    716
    817int test = 0;
     
    2029}
    2130
     31static int
     32test_bitfields( void )
     33{
     34    int i;
     35    int bitcount = 5000000;
     36    tr_bitfield * field = tr_bitfieldNew( bitcount );
     37
     38    /* make every seventh one true */
     39    for( i=0; i<bitcount; ++i )
     40        if( !( i % 7 ) )
     41            tr_bitfieldAdd( field, i );
     42
     43    /* check to see if `has' has the right bits */
     44    for( i=0; i<bitcount; ++i )
     45        check( tr_bitfieldHas( field, i ) == (!(i%7)) );
     46
     47    tr_bitfieldFree( field );
     48    return 0;
     49}
     50
     51
    2252
    2353int
     
    2656    char *in, *out;
    2757    int len;
     58    int i;
     59    int l;
    2860
    2961    /* base64 */
     
    4072    tr_free( out );
    4173
     74    /* simple bitfield tests */
     75    for( l=0; l<NUM_LOOPS; ++l )
     76        if(( i = test_bitfields( )))
     77            return i;
     78
    4279    return 0;
    4380}
Note: See TracChangeset for help on using the changeset viewer.