root/test/test-mux-serializer.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-serializer.c - Tests for the multiplexer serializer.
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 "FlowMuxSerializer"
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 ITERATIONS 500
32 #define BUFFER_PROPABILITY 5
33
34 typedef struct
35 {
36     guint channel_id;
37     guint32 size;
38 } Chunk;
39
40 static void
41 add_chunk (GQueue *expected_chunks, guint channel_id, guint32 size)
42 {
43   Chunk *chunk = g_new (Chunk, 1);
44   chunk->channel_id = channel_id;
45   chunk->size = size;
46   g_queue_push_tail (expected_chunks, chunk);
47 }
48
49 static void
50 test_run (void)
51 {
52   FlowMuxSerializer *serializer;
53   FlowUserAdapter *adapter;
54   FlowPad *input_pad;
55   FlowPacket *packet;
56   GQueue *expected_chunks;
57   guint32 chunk_size;
58   guchar *buffer;
59   int i, len;
60   Chunk *chunk;
61   FlowPacketQueue *input_packet_queue;
62   guchar *hdr_buffer;
63   guint current_channel_id;
64   guint hdr_size;
65  
66   serializer = flow_mux_serializer_new ();
67
68   adapter = flow_user_adapter_new ();
69   flow_pad_connect (FLOW_PAD (flow_simplex_element_get_output_pad (
70                                       FLOW_SIMPLEX_ELEMENT (serializer))),
71                     FLOW_PAD (flow_simplex_element_get_input_pad (
72                                       FLOW_SIMPLEX_ELEMENT (adapter))));
73   input_pad = FLOW_PAD (flow_simplex_element_get_input_pad (FLOW_SIMPLEX_ELEMENT(serializer)));
74  
75   buffer = g_malloc (BUFFER_SIZE);
76
77   current_channel_id = g_random_int_range (0, N_CHANNELS);
78   flow_pad_push (input_pad, flow_packet_new_take_object (flow_mux_event_new (current_channel_id), 0));
79   chunk_size = 0;
80   expected_chunks = g_queue_new ();
81   for (i = 0; i < ITERATIONS; i++)
82   {
83     len = g_random_int_range (1, BUFFER_SIZE);
84     memset (buffer, 0xaa, len);
85
86     if (g_random_int () % BUFFER_PROPABILITY != 0)
87     {
88       packet = flow_packet_new (FLOW_PACKET_FORMAT_BUFFER, buffer, len);
89       chunk_size += len;
90     }
91     else
92     {
93       guint channel_id = g_random_int_range (0, N_CHANNELS);
94
95       add_chunk (expected_chunks, current_channel_id, chunk_size);
96      
97       packet = flow_packet_new_take_object (flow_mux_event_new (channel_id), 0);
98       current_channel_id = channel_id;
99       chunk_size = 0;
100     }
101     flow_pad_push (input_pad, packet);
102   }
103   if (chunk_size > 0)
104     add_chunk (expected_chunks, current_channel_id, chunk_size);
105  
106   flow_pad_push (input_pad, flow_create_simple_event_packet (FLOW_STREAM_DOMAIN, FLOW_STREAM_END));
107
108   hdr_size = flow_mux_serializer_get_header_size (serializer);
109   hdr_buffer = g_alloca (hdr_size);
110   input_packet_queue = flow_user_adapter_get_input_queue (adapter);
111
112   while ((chunk = g_queue_pop_head (expected_chunks)) != NULL)
113   {
114     guint channel_id;
115     guint32 size;
116
117     while (!flow_packet_queue_peek_packet (input_packet_queue, NULL, NULL))
118       flow_user_adapter_wait_for_input (adapter);
119    
120     if (!flow_packet_queue_pop_bytes_exact (input_packet_queue, hdr_buffer, hdr_size))
121       test_end (TEST_RESULT_FAILED, "header corrupted");
122    
123     flow_mux_serializer_parse_header (serializer, hdr_buffer, &channel_id, &size);
124     if (chunk->channel_id != channel_id || chunk->size != size)
125       test_end (TEST_RESULT_FAILED, "chunk corrupt");
126
127     while (size > 0)
128     {
129       guint to_read = size;
130       gint read;
131      
132       if (to_read > BUFFER_SIZE)
133         to_read = BUFFER_SIZE;
134       read = flow_packet_queue_pop_bytes (input_packet_queue, buffer, to_read);
135       g_assert (read > 0);
136       size -= read;
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.