source: test/test-format-parallel.c @ 59ef093

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivelibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 59ef093 was 59ef093, checked in by Richard Sanger <rsangerarj@…>, 7 years ago

Adds more tests

  • Test hashing function is used
  • Test single threaded path works
  • Stress test with 100 threads
  • Test hash+singlethreaded works

Additionally fixes some bugs/compile warnings and removes some verbose debug printing

  • Property mode set to 100644
File size: 6.2 KB
Line 
1/*
2 * This file is part of libtrace
3 *
4 * Copyright (c) 2007 The University of Waikato, Hamilton, New Zealand.
5 * Authors: Daniel Lawson
6 *          Perry Lorier
7 *         
8 * All rights reserved.
9 *
10 * This code has been developed by the University of Waikato WAND
11 * research group. For further information please see http://www.wand.net.nz/
12 *
13 * libtrace is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * libtrace is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with libtrace; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 *
27 * $Id: test-rtclient.c,v 1.2 2006/02/27 03:41:12 perry Exp $
28 *
29 */
30#ifndef WIN32
31#  include <sys/time.h>
32#  include <netinet/in.h>
33#  include <netinet/in_systm.h>
34#  include <netinet/tcp.h>
35#  include <netinet/ip.h>
36#  include <netinet/ip_icmp.h>
37#  include <arpa/inet.h>
38#  include <sys/socket.h>
39#endif
40#include <stdio.h>
41#include <stdlib.h>
42#include <assert.h>
43#include <string.h>
44#include <sys/types.h>
45#include <time.h>
46#include <string.h>
47#include <signal.h>
48#include <unistd.h>
49
50#include "dagformat.h"
51#include "libtrace.h"
52#include "data-struct/vector.h"
53
54void iferr(libtrace_t *trace,const char *msg)
55{
56        libtrace_err_t err = trace_get_err(trace);
57        if (err.err_num==0)
58                return;
59        printf("Error: %s: %s\n", msg, err.problem);
60        exit(1);
61}
62
63const char *lookup_uri(const char *type) {
64        if (strchr(type,':'))
65                return type;
66        if (!strcmp(type,"erf"))
67                return "erf:traces/100_packets.erf";
68        if (!strcmp(type,"rawerf"))
69                return "rawerf:traces/100_packets.erf";
70        if (!strcmp(type,"pcap"))
71                return "pcap:traces/100_packets.pcap";
72        if (!strcmp(type,"wtf"))
73                return "wtf:traces/wed.wtf";
74        if (!strcmp(type,"rtclient"))
75                return "rtclient:chasm";
76        if (!strcmp(type,"pcapfile"))
77                return "pcapfile:traces/100_packets.pcap";
78        if (!strcmp(type,"pcapfilens"))
79                return "pcapfile:traces/100_packetsns.pcap";
80        if (!strcmp(type, "duck"))
81                return "duck:traces/100_packets.duck";
82        if (!strcmp(type, "legacyatm"))
83                return "legacyatm:traces/legacyatm.gz";
84        if (!strcmp(type, "legacypos"))
85                return "legacypos:traces/legacypos.gz";
86        if (!strcmp(type, "legacyeth"))
87                return "legacyeth:traces/legacyeth.gz";
88        if (!strcmp(type, "tsh"))
89                return "tsh:traces/10_packets.tsh.gz";
90        return type;
91}
92
93
94struct TLS {
95        bool seen_start_message;
96        bool seen_stop_message;
97        bool seen_paused_message;
98        bool seen_pausing_message;
99        int count;
100};
101int x;
102
103static void* per_packet(libtrace_t *trace, libtrace_packet_t *pkt, 
104                                                libtrace_message_t *mesg,
105                                                libtrace_thread_t *t) {
106        struct TLS *tls;
107        void* ret;
108        // Test internal TLS against __thread
109        static __thread bool seen_start_message = false;
110        static __thread bool seen_stop_message = false;
111        static __thread bool seen_paused_message = false;
112        static __thread bool seen_pausing_message = false;
113        static __thread count = 0;
114        tls = trace_get_tls(t);
115
116        if (pkt) {
117                int a,*b,c=0;
118                assert(tls != NULL);
119                assert(!seen_stop_message);
120                count++;
121                tls->count++;
122                if (count>100) {
123                        fprintf(stderr, "Too many packets someone should stop me!!\n");
124                        kill(getpid(), SIGTERM);
125                }
126                // Do some work to even out the load on cores
127                b = &c;
128                for (a = 0; a < 10000000; a++) {
129                        c += a**b;
130                }
131                x = c;
132        }
133        else switch (mesg->code) {
134                case MESSAGE_STARTED:
135                        assert(!seen_start_message || seen_paused_message);
136                        assert(tls == NULL);
137                        tls = calloc(sizeof(struct TLS), 1);
138                        ret = trace_set_tls(t, tls);
139                        assert(ret == NULL);
140                        seen_start_message = true;
141                        tls->seen_start_message = true;
142                        break;
143                case MESSAGE_STOPPED:
144                        assert(seen_start_message);
145                        assert(tls != NULL);
146                        assert(tls->seen_start_message);
147                        assert(tls->count == count);
148                        seen_stop_message = true;
149                        tls->seen_stop_message = true;
150                        free(tls);
151                        trace_set_tls(t, NULL);
152
153                        // All threads publish to verify the thread count
154                        trace_publish_result(trace, (uint64_t) 0, (void *) count);
155                        trace_post_reduce(trace);
156                        break;
157                case MESSAGE_TICK:
158                        assert(seen_start_message);
159                        fprintf(stderr, "Not expecting a tick packet\n");
160                        kill(getpid(), SIGTERM);
161                        break;
162                case MESSAGE_PAUSING:
163                        assert(seen_start_message);
164                        seen_pausing_message = true;
165                        tls->seen_pausing_message = true;
166                        break;
167                case MESSAGE_PAUSED:
168                        assert(seen_pausing_message);
169                        seen_paused_message = true;
170                        tls->seen_paused_message = true;
171                        break;
172        }
173        return pkt;
174}
175
176int main(int argc, char *argv[]) {
177        int error = 0;
178        int count = 0;
179        int expected = 100;
180        int i;
181        const char *tracename;
182        libtrace_t *trace;
183
184        if (argc<2) {
185                fprintf(stderr,"usage: %s type\n",argv[0]);
186                return 1;
187        }
188
189        tracename = lookup_uri(argv[1]);
190
191        trace = trace_create(tracename);
192        iferr(trace,tracename);
193
194        if (strcmp(argv[1],"rtclient")==0) expected=101;
195
196        trace_pstart(trace, NULL, per_packet, NULL);
197        iferr(trace,tracename);
198
199        /* Make sure traces survive a pause */
200        trace_ppause(trace);
201        iferr(trace,tracename);
202        trace_pstart(trace, NULL, NULL, NULL);
203        iferr(trace,tracename);
204
205        /* Wait for all threads to stop */
206        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        printf("\tLooks like %d threads were used!\n\tcounts(", libtrace_vector_get_size(&results));
213        for (i = 0; i < libtrace_vector_get_size(&results); i++) {
214                int ret;
215                libtrace_result_t result;
216                ret = libtrace_vector_get(&results, i, (void *) &result);
217                assert(ret == 1);
218                assert(libtrace_result_get_key(&result) == 0);
219                count += (int) libtrace_result_get_value(&result);
220                printf("%d,", (int) libtrace_result_get_value(&result));
221        }
222        printf(")\n");
223        libtrace_vector_destroy(&results);
224
225        if (error == 0) {
226                if (count == expected) {
227                        printf("success: %d packets read\n",expected);
228                } else {
229                        printf("failure: %d packets expected, %d seen\n",expected,count);
230                        error = 1;
231                }
232        } else {
233                iferr(trace,tracename);
234        }
235    trace_destroy(trace);
236    return error;
237}
Note: See TracBrowser for help on using the repository browser.