2 * Copyright (C) 2005-2008 by Pieter Palmers
4 * This file is part of FFADO
5 * FFADO = Free Firewire (pro-)audio drivers for linux
7 * FFADO is based upon FreeBoB
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) version 3 of the License.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "debugmodule/debugmodule.h"
26 #include "libutil/IpcRingBuffer.h"
27 #include "libutil/SystemTimeSource.h"
37 DECLARE_GLOBAL_DEBUG_MODULE
;
43 static void sighandler (int sig
)
48 ////////////////////////////////////////////////
50 ////////////////////////////////////////////////
51 const char *argp_program_version
= "test-ipcringbuffer 0.1";
52 const char *argp_program_bug_address
= "<ffado-devel@lists.sf.net>";
53 static char doc
[] = "test-avccmd -- test program to test the ipc ringbuffer class.";
54 static char args_doc
[] = "DIRECTION";
55 static struct argp_option options
[] = {
56 {"verbose", 'v', "level", 0, "Produce verbose output" },
74 // Parse a single option.
76 parse_opt( int key
, char* arg
, struct argp_state
* state
)
78 // Get the input argument from `argp_parse', which we
79 // know is a pointer to our arguments structure.
80 struct arguments
* arguments
= ( struct arguments
* ) state
->input
;
87 arguments
->verbose
= strtol( arg
, &tail
, 0 );
89 fprintf( stderr
, "Could not parse 'verbose' argument\n" );
90 return ARGP_ERR_UNKNOWN
;
95 if (state
->arg_num
>= MAX_ARGS
) {
96 // Too many arguments.
99 arguments
->args
[state
->arg_num
] = arg
;
103 if(arguments
->nargs
<= 0) {
104 printMessage("not enough arguments\n");
109 return ARGP_ERR_UNKNOWN
;
114 static struct argp argp
= { options
, parse_opt
, args_doc
, doc
};
116 ///////////////////////////
118 //////////////////////////
120 main(int argc
, char **argv
)
122 signal (SIGINT
, sighandler
);
123 signal (SIGPIPE
, sighandler
);
126 if ( argp_parse ( &argp
, argc
, argv
, 0, 0, &arguments
) ) {
127 fprintf( stderr
, "Could not parse command line\n" );
131 setDebugLevel(arguments
.verbose
);
135 long int direction
= strtol( arguments
.args
[0], &tail
, 0 );
137 fprintf( stderr
, "Could not parse direction argument\n" );
141 printMessage("Testing shared memory direction %ld\n", direction
);
143 #define TEST_SAMPLERATE 44100
146 IpcRingBuffer
* b
= NULL
;
148 b
= new IpcRingBuffer("testbuff",
149 IpcRingBuffer::eBT_Master
,
150 IpcRingBuffer::eD_Outward
,
151 IpcRingBuffer::eB_Blocking
,
152 NB_BUFFERS
, BUFF_SIZE
);
154 debugError("Could not create master\n");
158 b
= new IpcRingBuffer("testbuff",
159 IpcRingBuffer::eBT_Master
,
160 IpcRingBuffer::eD_Inward
,
161 IpcRingBuffer::eB_Blocking
,
162 NB_BUFFERS
, BUFF_SIZE
);
164 debugError("Could not create master\n");
169 b
->setVerboseLevel(arguments
.verbose
);
171 char buff
[BUFF_SIZE
];
173 long int time_to_sleep
= 1000*1000*BUFF_SIZE
/TEST_SAMPLERATE
;
176 debugError("Could not init buffer\n");
183 snprintf(buff
, BUFF_SIZE
, "test %d", cnt
);
185 printMessage("writing '%s'...\n", buff
);
187 IpcRingBuffer::eResult res
= b
->Write(buff
);
188 if(res
!= IpcRingBuffer::eR_OK
&& res
!= IpcRingBuffer::eR_Again
) {
189 debugError("Could not write to segment\n");
192 if(res
== IpcRingBuffer::eR_Again
) {
193 printMessage(" Try again on %d...\n", cnt
);
197 usleep(time_to_sleep
);
200 printMessage("reading...\n");
203 IpcRingBuffer::eResult res
= b
->Read(buff
);
204 if(res
!= IpcRingBuffer::eR_OK
&& res
!= IpcRingBuffer::eR_Again
) {
205 debugError("Could not receive from queue\n");
210 printMessage(" read: '%s'\n", buff
);
212 if(res
== IpcRingBuffer::eR_Again
) {
213 printMessage(" Try again on %d...\n", cnt
);