source: test/test-format.c @ 568a341

cachetimestampsdevelopdpdk-ndagetsilivendag_formatrc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformance
Last change on this file since 568a341 was 568a341, checked in by Shane Alcock <salcock@…>, 3 years ago

Update test suite for pcapng

Also added a new test for set_capture_length(). Setting the caplen
for pcapng is a bit more complicated than most formats, so I
needed a test for that format anyway. Figured I may as well add
tests for some of the other truncatable formats as well.

I've also added a 'complex.pcapng' test trace -- I haven't written
any tests that use it but it is useful for checking if you can
still read the full variety of pcapng records.

  • Property mode set to 100644
File size: 3.8 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
48#include "dagformat.h"
49#include "libtrace.h"
50
51void iferr(libtrace_t *trace,const char *msg)
52{
53        libtrace_err_t err = trace_get_err(trace);
54        if (err.err_num==0)
55                return;
56        printf("Error: %s: %s\n", msg, err.problem);
57        exit(1);
58}
59
60const char *lookup_uri(const char *type) {
61        if (strchr(type,':'))
62                return type;
63        if (!strcmp(type,"erf"))
64                return "erf:traces/100_packets.erf";
65        if (!strcmp(type,"rawerf"))
66                return "rawerf:traces/100_packets.erf";
67        if (!strcmp(type,"pcap"))
68                return "pcap:traces/100_packets.pcap";
69        if (!strcmp(type,"pcapng"))
70                return "pcap:traces/100_packets.pcapng";
71        if (!strcmp(type,"wtf"))
72                return "wtf:traces/wed.wtf";
73        if (!strcmp(type,"rtclient"))
74                return "rtclient:chasm";
75        if (!strcmp(type,"pcapfile"))
76                return "pcapfile:traces/100_packets.pcap";
77        if (!strcmp(type,"pcapfilens"))
78                return "pcapfile:traces/100_packetsns.pcap";
79        if (!strcmp(type, "duck"))
80                return "duck:traces/100_packets.duck";
81        if (!strcmp(type, "legacyatm"))
82                return "legacyatm:traces/legacyatm.gz";
83        if (!strcmp(type, "legacypos"))
84                return "legacypos:traces/legacypos.gz";
85        if (!strcmp(type, "legacyeth"))
86                return "legacyeth:traces/legacyeth.gz";
87        if (!strcmp(type, "tsh"))
88                return "tsh:traces/10_packets.tsh.gz";
89        return type;
90}
91
92int main(int argc, char *argv[]) {
93        int psize = 0;
94        int error = 0;
95        int count = 0;
96        int level = 0;
97        int expected = 100;
98        const char *tracename;
99        libtrace_t *trace;
100        libtrace_packet_t *packet;
101
102        if (argc<2) {
103                fprintf(stderr,"usage: %s type\n",argv[0]);
104                return 1;
105        }
106
107        tracename = lookup_uri(argv[1]);
108
109        trace = trace_create(tracename);
110        iferr(trace,tracename);
111
112        if (strcmp(argv[1],"rtclient")==0) expected=101;
113       
114        level=0;
115
116        trace_start(trace);
117        iferr(trace,tracename);
118       
119        packet=trace_create_packet();
120        for (;;) {
121                if ((psize = trace_read_packet(trace, packet)) <0) {
122                        error = 1;
123                        iferr(trace,tracename);
124                        break;
125                }
126                if (psize == 0) {
127                        error = 0;
128                        break;
129                }
130                count ++;
131                if (count>100)
132                        break;
133                /* Make sure traces survive a pause */
134                trace_pause(trace);
135                trace_start(trace);
136        }
137        trace_destroy_packet(packet);
138        if (error == 0) {
139                if (count == expected) {
140                        printf("success: %d packets read\n",expected);
141                } else {
142                        printf("failure: %d packets expected, %d seen\n",expected,count);
143                        error = 1;
144                }
145        } else {
146                iferr(trace,tracename);
147        }
148        trace_destroy(trace);
149        return error;
150}
Note: See TracBrowser for help on using the repository browser.