summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Henningsson <david.henningsson@canonical.com>2014-05-30 12:04:21 +0200
committerDavid Henningsson <david.henningsson@canonical.com>2014-06-27 14:30:56 +0200
commit1afec0e5a37012655c87b204e343d6548678e329 (patch)
tree3f26064d4100d6227fda016b476806a564a6fc9c /src
parenta476371254eb78071db243f4fb9cecc0c52fabce (diff)
tests: Add pstream/srbchannel test
Runs four tests: 1) Small packets, iochannel 2) Big packets, iochannel 3) Small packets, srbchannel 4) Big packets, srbchannel Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am6
-rw-r--r--src/tests/srbchannel-test.c138
2 files changed, 144 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index e388bd2a0..44d9050c8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -271,6 +271,7 @@ TESTS_daemon = \
if !OS_IS_WIN32
TESTS_default += \
+ srbchannel-test \
sigbus-test \
usergroup-test
endif
@@ -349,6 +350,11 @@ format_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
format_test_LDADD = $(AM_LDADD) libpulsecore-@PA_MAJORMINOR@.la libpulse.la libpulsecommon-@PA_MAJORMINOR@.la
format_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
+srbchannel_test_SOURCES = tests/srbchannel-test.c
+srbchannel_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
+srbchannel_test_LDADD = $(AM_LDADD) libpulse.la libpulsecommon-@PA_MAJORMINOR@.la
+srbchannel_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBCHECK_LIBS)
+
get_binary_name_test_SOURCES = tests/get-binary-name-test.c
get_binary_name_test_CFLAGS = $(AM_CFLAGS) $(LIBCHECK_CFLAGS)
get_binary_name_test_LDADD = $(AM_LDADD) libpulse.la libpulsecommon-@PA_MAJORMINOR@.la
diff --git a/src/tests/srbchannel-test.c b/src/tests/srbchannel-test.c
new file mode 100644
index 000000000..78a401b16
--- /dev/null
+++ b/src/tests/srbchannel-test.c
@@ -0,0 +1,138 @@
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2014 David Henningsson, Canonical Ltd.
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License,
+ or (at your option) any later version.
+
+ PulseAudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <unistd.h>
+#include <check.h>
+
+#include <pulse/mainloop.h>
+#include <pulsecore/packet.h>
+#include <pulsecore/pstream.h>
+#include <pulsecore/iochannel.h>
+#include <pulsecore/memblock.h>
+
+int packets_received;
+int packets_checksum;
+int packets_length;
+
+static void packet_received(pa_pstream *p, pa_packet *packet, const pa_ancil *ancil, void *userdata) {
+ unsigned int i;
+ fail_unless(packets_length == (int) packet->length);
+ packets_received++;
+ for (i = 0; i < packet->length; i++)
+ packets_checksum += packet->data[i];
+}
+
+static void packet_test(int npackets, int plength, pa_mainloop *ml, pa_pstream *p1, pa_pstream *p2) {
+ pa_packet *packet = pa_packet_new(plength);
+ int i;
+ int psum = 0, totalsum = 0;
+ pa_log_info("Sending %d packets of length %d", npackets, plength);
+ packets_received = 0;
+ packets_checksum = 0;
+ packets_length = plength;
+ pa_pstream_set_receive_packet_callback(p2, packet_received, NULL);
+
+ for (i = 0; i < plength; i++) {
+ packet->data[i] = i;
+ psum += packet->data[i];
+ }
+
+ for (i = 0; i < npackets; i++) {
+ pa_pstream_send_packet(p1, packet, NULL);
+ totalsum += psum;
+ pa_mainloop_iterate(ml, 0, NULL);
+ }
+
+ while (packets_received < npackets)
+ pa_mainloop_iterate(ml, 1, NULL);
+
+ fail_unless(packets_checksum == totalsum);
+ pa_log_debug("Correct checksum received (%d)", packets_checksum);
+ pa_packet_unref(packet);
+}
+
+START_TEST (srbchannel_test) {
+
+ int pipefd[4];
+
+ pa_mainloop *ml = pa_mainloop_new();
+ pa_mempool *mp = pa_mempool_new(true, 0);
+ pa_iochannel *io1, *io2;
+ pa_pstream *p1, *p2;
+ pa_srbchannel *sr1, *sr2;
+ pa_srbchannel_template srt;
+
+ fail_unless(pipe(pipefd) == 0);
+ fail_unless(pipe(&pipefd[2]) == 0);
+ io1 = pa_iochannel_new(pa_mainloop_get_api(ml), pipefd[2], pipefd[1]);
+ io2 = pa_iochannel_new(pa_mainloop_get_api(ml), pipefd[0], pipefd[3]);
+ p1 = pa_pstream_new(pa_mainloop_get_api(ml), io1, mp);
+ p2 = pa_pstream_new(pa_mainloop_get_api(ml), io2, mp);
+
+ pa_log_debug("Pipes: fd %d -> %d, %d -> %d", pipefd[1], pipefd[0], pipefd[3], pipefd[2]);
+
+ packet_test(250, 5, ml, p1, p2);
+ packet_test(10, 1234567, ml, p1, p2);
+
+ pa_log_debug("And now the same thing with srbchannel...");
+
+ sr1 = pa_srbchannel_new(pa_mainloop_get_api(ml), mp);
+ pa_srbchannel_export(sr1, &srt);
+ pa_pstream_set_srbchannel(p1, sr1);
+ sr2 = pa_srbchannel_new_from_template(pa_mainloop_get_api(ml), &srt);
+ pa_pstream_set_srbchannel(p2, sr2);
+
+ packet_test(250, 5, ml, p1, p2);
+ packet_test(10, 1234567, ml, p1, p2);
+
+ pa_pstream_unref(p1);
+ pa_pstream_unref(p2);
+ pa_mempool_free(mp);
+ pa_mainloop_free(ml);
+}
+END_TEST
+
+
+int main(int argc, char *argv[]) {
+ int failed = 0;
+ Suite *s;
+ TCase *tc;
+ SRunner *sr;
+
+ if (!getenv("MAKE_CHECK"))
+ pa_log_set_level(PA_LOG_DEBUG);
+
+ s = suite_create("srbchannel");
+ tc = tcase_create("srbchannel");
+ tcase_add_test(tc, srbchannel_test);
+ suite_add_tcase(s, tc);
+
+ sr = srunner_create(s);
+ srunner_run_all(sr, CK_NORMAL);
+ failed = srunner_ntests_failed(sr);
+ srunner_free(sr);
+
+ return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}