root/test/test-mux-deserializer.c

Revision 77f5a390594493be73c9c376650fdc3c89ec6701, 4.3 kB (checked in by hansp <hansp>, 3 years ago)

Merge work from Andreas Rottmann.

Commit: a87491d9b52df355a8f70e74b37b3e190c18b7bf
Author: Andreas Rottmann <a.rottmann@gmx.at> Wed, 28 Nov 2007 15:38:41 +0100

Implemented FlowMuxDeserializer?

Commit: a578f2be176aa70639c01dd4e0ac36eef5ad7f18
Author: Andreas Rottmann <a.rottmann@gmx.at> Tue, 27 Nov 2007 19:57:30 +0100

Remove arch-tag

Commit: ab73ed84042042d0e2dc7704d0ebe0993f9571c6
Author: Andreas Rottmann <a.rottmann@gmx.at> Tue, 27 Nov 2007 19:54:19 +0100

Ignore FlowMuxSerializer? test binary

Commit: 3d933ea9284810901f4b7d49bb961a02b0857f78
Author: Andreas Rottmann <a.rottmann@gmx.at> Tue, 27 Nov 2007 19:52:35 +0100

Implemented FlowMuxSerializer?

Commit: 99cb378fbbf0c4c8b5a36d4876293c03d7e6a15f
Author: Andreas Rottmann <a.rottmann@gmx.at> Mon, 26 Nov 2007 23:33:50 +0100

FlowMux?: code cleanup

Commit: ee269ce7a38ef8f0c36c619b53044a259bcb2428
Author: Andreas Rottmann <a.rottmann@gmx.at> Sat, 24 Nov 2007 18:38:20 +0100

Ignore tests/test-demux

Commit: 17d223a8cbea08dbef823c13053048dde159511f
Author: Andreas Rottmann <a.rottmann@gmx.at> Sat, 24 Nov 2007 18:36:37 +0100

FlowMuxEvent?: channel_id is of type guint

Commit: d7a184fc67abdf31a3762e9b3948042741e797e8
Author: Andreas Rottmann <a.rottmann@gmx.at> Sat, 24 Nov 2007 18:34:21 +0100

Initial FlowDemux? implementation

Commit: 5c9fed9e08c7cc1e5c2ed3a95633d5d14b2442d7
Author: Andreas Rottmann <a.rottmann@gmx.at> Sat, 24 Nov 2007 16:07:34 +0100

FlowMux?: also forward object packets

Commit: b3c963e13786170e305e46b547e2f907467ad372
Author: Andreas Rottmann <a.rottmann@gmx.at> Sat, 24 Nov 2007 14:54:52 +0100

Revert source-code change

Commit: 793752be3d6ab60a0f0b169b7b70ad8f4f6cbb21
Author: Andreas Rottmann <a.rottmann@gmx.at> Fri, 23 Nov 2007 00:51:47 +0100

Small adjustments

Commit: 09571abdb57e36ff614d04569f68029d85d73af3
Author: Andreas Rottmann <a.rottmann@gmx.at> Thu, 22 Nov 2007 02:01:49 +0100

Initial .gitignore files

  • Property mode set to 100644
Line 
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
3 /* test-mux-deserializer.c - Tests for the multiplexer deserializer.
4  *
5  * Copyright (C) 2007 Andreas Rottmann
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this program.  If not, see
19  * <http://www.gnu.org/licenses/>.
20  *
21  * Authors: Andreas Rottmann <a.rottmann@gmx.at>
22  */
23
24 #define TEST_UNIT_NAME "FlowMuxDeserializer"
25 #define TEST_TIMEOUT_S 20
26
27 #include "test-common.c"
28
29 #define N_CHANNELS 5
30 #define BUFFER_SIZE 4096
31 #define MAX_CHUNK_SIZE (1 << 16)
32 #define ITERATIONS 500
33 #define BUFFER_PROPABILITY 5
34
35 typedef struct
36 {
37     guint channel_id;
38     guint32 size;
39 } Chunk;
40
41 static void
42 add_chunk (GQueue *expected_chunks, guint channel_id, guint32 size)
43 {
44   Chunk *chunk = g_new (Chunk, 1);
45   chunk->channel_id = channel_id;
46   chunk->size = size;
47   g_queue_push_tail (expected_chunks, chunk);
48 }
49
50 static void
51 test_run (void)
52 {
53   FlowMuxDeserializer *deserializer;
54   FlowUserAdapter *adapter;
55   FlowPad *input_pad;
56   FlowPacket *packet;
57   GQueue *expected_chunks;
58   guint32 chunk_size;
59   guchar *buffer;
60   int i, len;
61   Chunk *chunk;
62   FlowPacketQueue *input_packet_queue;
63   guint current_channel_id;
64  
65   deserializer = flow_mux_deserializer_new ();
66
67   adapter = flow_user_adapter_new ();
68   flow_pad_connect (FLOW_PAD (flow_simplex_element_get_output_pad (
69                                       FLOW_SIMPLEX_ELEMENT (deserializer))),
70                     FLOW_PAD (flow_simplex_element_get_input_pad (
71                                       FLOW_SIMPLEX_ELEMENT (adapter))));
72   input_pad = FLOW_PAD (flow_simplex_element_get_input_pad (FLOW_SIMPLEX_ELEMENT(deserializer)));
73  
74   buffer = g_malloc (BUFFER_SIZE);
75   memset (buffer, 0xaa, BUFFER_SIZE);
76
77   chunk_size = 0;
78   expected_chunks = g_queue_new ();
79   for (i = 0; i < ITERATIONS; i++)
80   {
81     FlowPacket *header;
82     guint hdr_size;
83    
84     current_channel_id = g_random_int_range (0, N_CHANNELS);
85     len = g_random_int_range (1, MAX_CHUNK_SIZE);
86     hdr_size = flow_mux_deserializer_get_header_size (deserializer);
87     flow_mux_deserializer_unparse_header (deserializer, buffer, current_channel_id, len);
88     header = flow_packet_new (FLOW_PACKET_FORMAT_BUFFER, buffer, hdr_size);
89     flow_pad_push (input_pad, header);
90     add_chunk (expected_chunks, current_channel_id, len);
91
92     while (len > 0)
93     {
94       guint n = g_random_int_range (1, BUFFER_SIZE);
95       if (n > len)
96         n = len;
97       flow_pad_push (input_pad, flow_packet_new (FLOW_PACKET_FORMAT_BUFFER, buffer, n));
98       len -= n;
99     }
100   }
101  
102   flow_pad_push (input_pad, flow_create_simple_event_packet (FLOW_STREAM_DOMAIN, FLOW_STREAM_END));
103
104   input_packet_queue = flow_user_adapter_get_input_queue (adapter);
105
106   while ((chunk = g_queue_pop_head (expected_chunks)) != NULL)
107   {
108     guint32 size;
109     gpointer data;
110
111     while ((packet = flow_packet_queue_pop_packet (input_packet_queue)) == NULL)
112       flow_user_adapter_wait_for_input (adapter);
113
114     data = flow_packet_get_data (packet);
115     if (packet->format != FLOW_PACKET_FORMAT_OBJECT
116         || !FLOW_IS_MUX_EVENT (data))
117       test_end (TEST_RESULT_FAILED, "expected mux event packet");
118
119     if (flow_mux_event_get_channel_id (FLOW_MUX_EVENT (data)) != chunk->channel_id)
120       test_end (TEST_RESULT_FAILED, "unexpected channel id in mux event packet");
121
122     flow_packet_free (packet);
123    
124     size = 0;
125     while (TRUE)
126     {
127       while (!flow_packet_queue_peek_packet (input_packet_queue, &packet, NULL))
128         flow_user_adapter_wait_for_input (adapter);
129       if (packet->format != FLOW_PACKET_FORMAT_BUFFER)
130         break;
131       size += packet->size;
132       flow_packet_queue_drop_packet (input_packet_queue);
133     }
134
135     if (size != chunk->size)
136       test_end (TEST_RESULT_FAILED, "chunk differs in size");
137    
138     g_free (chunk);
139   }
140   g_queue_free (expected_chunks);
141   g_free (buffer);
142 }
Note: See TracBrowser for help on using the browser.