Ignore:
Timestamp:
09/16/14 02:35:10 (7 years ago)
Author:
Richard Sanger <rsangerarj@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
d994324
Parents:
50b1bee
Message:

Refactor the combining step to allow user defined functions here.

Remove the old trace_get_results, now instead simply provide a reporter function which gets called as soon as results are ready.
The combiner function used determines the order of these results and when they are released etc.
The combiner function can be selected from those built-in or a custom version can be defined results are provided when ready.
Quickly hacked the parallel tests to work with this update, these are still a bit messy.

Also some fixes some compile warnings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/test-format-parallel-hasher.c

    rf051c1b r2498008  
    9999        int count;
    100100};
    101 int x;
    102 
     101
     102static int totalpkts = 0;
     103static int expected;
     104static void report_result(libtrace_t *trace, libtrace_result_t *result, libtrace_message_t *mesg) {
     105        static int totalthreads = 0;
     106        if (result) {
     107                assert(libtrace_result_get_key(result) == 0);
     108                printf("%d,", (int) libtrace_result_get_value(result));
     109                totalthreads++;
     110                totalpkts += (int) libtrace_result_get_value(result);
     111                assert(libtrace_result_get_value(result) == 25 ||
     112                        libtrace_result_get_value(result) == expected - 25);
     113        } else {
     114                switch(mesg->code) {
     115                        case MESSAGE_STARTING:
     116                                // Should have two threads here
     117                                assert(libtrace_get_perpkt_count(trace) == 2);
     118                                printf("\tLooks like %d threads are being used!\n\tcounts(", libtrace_get_perpkt_count(trace));
     119                                break;
     120                        case MESSAGE_STOPPING:
     121                                printf(")\n");
     122                                assert(totalthreads == libtrace_get_perpkt_count(trace));
     123                                break;
     124                }
     125        }
     126}
     127
     128static int x;
    103129static void* per_packet(libtrace_t *trace, libtrace_packet_t *pkt,
    104130                                                libtrace_message_t *mesg,
     
    177203 * Test that the hasher function works
    178204 */
    179 int test_hasher(const char *tracename, int expected) {
     205int test_hasher(const char *tracename) {
    180206        libtrace_t *trace;
    181207        int error = 0;
    182         int count = 0;
    183208        int i;
    184209        int hashercount = 0;
     
    195220
    196221        // Start it
    197         trace_pstart(trace, NULL, per_packet, NULL);
     222        trace_pstart(trace, NULL, per_packet, report_result);
    198223        iferr(trace,tracename);
    199224        /* Make sure traces survive a pause and restart */
     
    205230        /* Wait for all threads to stop */
    206231        trace_join(trace);
    207         libtrace_vector_t results;
    208 
    209         /* Now lets check the results */
    210         libtrace_vector_init(&results, sizeof(libtrace_result_t));
    211         trace_get_results(trace, &results);
    212         // Should have two results/threads here
    213         assert(libtrace_vector_get_size(&results) == 2);
    214         for (i = 0; i < libtrace_vector_get_size(&results); i++) {
    215                 int ret;
    216                 libtrace_result_t result;
    217                 ret = libtrace_vector_get(&results, i, (void *) &result);
    218                 assert(ret == 1);
    219                 assert(libtrace_result_get_key(&result) == 0);
    220                 count += (int) libtrace_result_get_value(&result);
    221                 printf("%d,", (int) libtrace_result_get_value(&result));
    222                
    223         }
    224         printf(")\n");
    225         for (i = 0; i < libtrace_vector_get_size(&results); i++) {
    226                 int ret;
    227                 libtrace_result_t result;
    228                 ret = libtrace_vector_get(&results, i, (void *) &result);
    229                 assert(libtrace_result_get_value(&result) == 25 ||
    230                         libtrace_result_get_value(&result) == expected - 25);
    231         }
    232         libtrace_vector_destroy(&results);
    233 
     232
     233        /* Now check we have all received all the packets */
    234234        if (error == 0) {
    235                 if (count == expected) {
     235                if (totalpkts == expected) {
    236236                        printf("success: %d packets read\n",expected);
    237237                } else {
    238                         printf("failure: %d packets expected, %d seen\n",expected,count);
     238                        printf("failure: %d packets expected, %d seen\n",expected,totalpkts);
    239239                        error = 1;
    240240                }
     
    250250int main(int argc, char *argv[]) {
    251251        int error = 0;
    252         int expected = 100;
    253252        const char *tracename;
     253        expected = 100;
    254254
    255255        if (argc<2) {
     
    262262        if (strcmp(argv[1],"rtclient")==0) expected=101;
    263263
    264         error = test_hasher(tracename, expected);
     264        error = test_hasher(tracename);
    265265
    266266    return error;
Note: See TracChangeset for help on using the changeset viewer.