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-singlethreaded.c

    rf051c1b r2498008  
    9999        int count;
    100100};
    101 int x;
    102 
     101
     102static int totalpkts = 0;
     103static void report_result(libtrace_t *trace, libtrace_result_t *result, libtrace_message_t *mesg) {
     104        static int totalthreads = 0;
     105        if (result) {
     106                assert(libtrace_result_get_key(result) == 0);
     107                printf("%d,", (int) libtrace_result_get_value(result));
     108                totalthreads++;
     109                totalpkts += (int) libtrace_result_get_value(result);
     110        } else {
     111                switch(mesg->code) {
     112                        case MESSAGE_STARTING:
     113                                // Should have a single thread here
     114                                assert(libtrace_get_perpkt_count(trace) == 1);
     115                                printf("\tLooks like %d threads are being used!\n\tcounts(", libtrace_get_perpkt_count(trace));
     116                                break;
     117                        case MESSAGE_STOPPING:
     118                                printf(")\n");
     119                                assert(totalthreads == libtrace_get_perpkt_count(trace));
     120                                break;
     121                }
     122        }
     123}
     124
     125static int x;
    103126static void* per_packet(libtrace_t *trace, libtrace_packet_t *pkt,
    104127                                                libtrace_message_t *mesg,
     
    167190        libtrace_t *trace;
    168191        int error = 0;
    169         int count = 0;
    170192        int i;
    171193        printf("Testing single threaded\n");
     
    180202
    181203        // Start it
    182         trace_pstart(trace, NULL, per_packet, NULL);
     204        trace_pstart(trace, NULL, per_packet, report_result);
    183205        iferr(trace,tracename);
    184206
     
    191213        /* Wait for all threads to stop */
    192214        trace_join(trace);
    193         libtrace_vector_t results;
    194 
    195         /* Now lets check the results */
    196         libtrace_vector_init(&results, sizeof(libtrace_result_t));
    197         trace_get_results(trace, &results);
    198         // Should have one result/thread here
    199         assert(libtrace_vector_get_size(&results) == 1);
    200         for (i = 0; i < libtrace_vector_get_size(&results); i++) {
    201                 int ret;
    202                 libtrace_result_t result;
    203                 ret = libtrace_vector_get(&results, i, (void *) &result);
    204                 assert(ret == 1);
    205                 assert(libtrace_result_get_key(&result) == 0);
    206                 count += (int) libtrace_result_get_value(&result);
    207                 printf("%d,", (int) libtrace_result_get_value(&result));
    208         }
    209         printf(")\n");
    210         libtrace_vector_destroy(&results);
    211 
     215
     216        /* Now check we have all received all the packets */
    212217        if (error == 0) {
    213                 if (count == expected) {
     218                if (totalpkts == expected) {
    214219                        printf("success: %d packets read\n",expected);
    215220                } else {
    216                         printf("failure: %d packets expected, %d seen\n",expected,count);
     221                        printf("failure: %d packets expected, %d seen\n",expected,totalpkts);
    217222                        error = 1;
    218223                }
Note: See TracChangeset for help on using the changeset viewer.