diff options
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/alsa-time-test.c | 200 | ||||
-rw-r--r-- | src/tests/gtk-test.c | 62 | ||||
-rw-r--r-- | src/tests/interpol-test.c | 38 | ||||
-rw-r--r-- | src/tests/ipacl-test.c | 7 | ||||
-rw-r--r-- | src/tests/sync-playback.c | 7 | ||||
-rw-r--r-- | src/tests/thread-mainloop-test.c | 2 |
6 files changed, 308 insertions, 8 deletions
diff --git a/src/tests/alsa-time-test.c b/src/tests/alsa-time-test.c new file mode 100644 index 00000000..3858bf7b --- /dev/null +++ b/src/tests/alsa-time-test.c @@ -0,0 +1,200 @@ +#include <assert.h> +#include <inttypes.h> +#include <time.h> + +#include <alsa/asoundlib.h> + +static uint64_t timespec_us(const struct timespec *ts) { + return + ts->tv_sec * 1000000LLU + + ts->tv_nsec / 1000LLU; +} + +int main(int argc, char *argv[]) { + const char *dev; + int r; + snd_pcm_hw_params_t *hwparams; + snd_pcm_sw_params_t *swparams; + snd_pcm_status_t *status; + snd_pcm_t *pcm; + unsigned rate = 44100; + unsigned periods = 0; + snd_pcm_uframes_t boundary, buffer_size = 44100/10; /* 100s */ + int dir = 1; + struct timespec start, last_timestamp = { 0, 0 }; + uint64_t start_us; + snd_pcm_sframes_t last_avail, last_delay; + struct pollfd *pollfds; + int n_pollfd; + int64_t sample_count = 0; + + snd_pcm_hw_params_alloca(&hwparams); + snd_pcm_sw_params_alloca(&swparams); + snd_pcm_status_alloca(&status); + + r = clock_gettime(CLOCK_MONOTONIC, &start); + assert(r == 0); + + start_us = timespec_us(&start); + + dev = argc > 1 ? argv[1] : "front:AudioPCI"; + + r = snd_pcm_open(&pcm, dev, SND_PCM_STREAM_PLAYBACK, 0); + assert(r == 0); + + r = snd_pcm_hw_params_any(pcm, hwparams); + assert(r == 0); + + r = snd_pcm_hw_params_set_rate_resample(pcm, hwparams, 0); + assert(r == 0); + + r = snd_pcm_hw_params_set_access(pcm, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED); + assert(r == 0); + + r = snd_pcm_hw_params_set_format(pcm, hwparams, SND_PCM_FORMAT_S16_LE); + assert(r == 0); + + r = snd_pcm_hw_params_set_rate_near(pcm, hwparams, &rate, NULL); + assert(r == 0); + + r = snd_pcm_hw_params_set_channels(pcm, hwparams, 2); + assert(r == 0); + + r = snd_pcm_hw_params_set_periods_integer(pcm, hwparams); + assert(r == 0); + + r = snd_pcm_hw_params_set_periods_near(pcm, hwparams, &periods, &dir); + assert(r == 0); + + r = snd_pcm_hw_params_set_buffer_size_near(pcm, hwparams, &buffer_size); + assert(r == 0); + + r = snd_pcm_hw_params(pcm, hwparams); + assert(r == 0); + + r = snd_pcm_hw_params_current(pcm, hwparams); + assert(r == 0); + + r = snd_pcm_sw_params_set_avail_min(pcm, swparams, 1); + assert(r == 0); + + r = snd_pcm_sw_params_set_period_event(pcm, swparams, 1); + assert(r == 0); + + r = snd_pcm_hw_params_get_buffer_size(hwparams, &buffer_size); + assert(r == 0); + r = snd_pcm_sw_params_set_start_threshold(pcm, swparams, buffer_size); + assert(r == 0); + + r = snd_pcm_sw_params_get_boundary(swparams, &boundary); + assert(r == 0); + r = snd_pcm_sw_params_set_stop_threshold(pcm, swparams, boundary); + assert(r == 0); + + r = snd_pcm_sw_params_set_tstamp_mode(pcm, swparams, SND_PCM_TSTAMP_ENABLE); + assert(r == 0); + + r = snd_pcm_sw_params(pcm, swparams); + assert(r == 0); + + r = snd_pcm_prepare(pcm); + assert(r == 0); + + r = snd_pcm_sw_params_current(pcm, swparams); + assert(r == 0); + +/* assert(snd_pcm_hw_params_is_monotonic(hwparams) > 0); */ + + n_pollfd = snd_pcm_poll_descriptors_count(pcm); + assert(n_pollfd > 0); + + pollfds = malloc(sizeof(struct pollfd) * n_pollfd); + assert(pollfds); + + r = snd_pcm_poll_descriptors(pcm, pollfds, n_pollfd); + assert(r == n_pollfd); + + for (;;) { + snd_pcm_sframes_t avail, delay; +/* snd_pcm_uframes_t avail2; */ + struct timespec now, timestamp; + unsigned short revents; + int written = 0; + uint64_t now_us, timestamp_us; + snd_pcm_state_t state; + + r = poll(pollfds, n_pollfd, 0); + assert(r >= 0); + + r = snd_pcm_poll_descriptors_revents(pcm, pollfds, n_pollfd, &revents); + assert(r == 0); + + assert((revents & ~POLLOUT) == 0); + +/* state = snd_pcm_get_state(pcm); */ + + avail = snd_pcm_avail(pcm); + assert(avail >= 0); + + r = snd_pcm_status(pcm, status); + assert(r == 0); + + printf("%lu %lu\n", (unsigned long) avail, (unsigned long) snd_pcm_status_get_avail(status)); + + assert(avail == (snd_pcm_sframes_t) snd_pcm_status_get_avail(status)); + snd_pcm_status_get_htstamp(status, ×tamp); + delay = snd_pcm_status_get_delay(status); + state = snd_pcm_status_get_state(status); + +/* r = snd_pcm_avail_delay(pcm, &avail, &delay); */ +/* assert(r == 0); */ + +/* r = snd_pcm_htimestamp(pcm, &avail2, ×tamp); */ +/* assert(r == 0); */ + +/* assert(avail == (snd_pcm_sframes_t) avail2); */ + + r = clock_gettime(CLOCK_MONOTONIC, &now); + assert(r == 0); + + assert(!revents || avail > 0); + + if (avail) { + snd_pcm_sframes_t sframes; + static const uint16_t samples[2] = { 0, 0 }; + + sframes = snd_pcm_writei(pcm, samples, 1); + assert(sframes == 1); + + written = 1; + sample_count++; + } + + if (!written && + memcmp(×tamp, &last_timestamp, sizeof(timestamp)) == 0 && + avail == last_avail && + delay == last_delay) { + /* This is boring */ + continue; + } + + now_us = timespec_us(&now); + timestamp_us = timespec_us(×tamp); + + printf("%llu\t%llu\t%llu\t%li\t%li\t%i\t%i\t%i\n", + (unsigned long long) (now_us - start_us), + (unsigned long long) (timestamp_us ? timestamp_us - start_us : 0), + (unsigned long long) ((sample_count - 1 - delay) * 1000000LU / 44100), + (signed long) avail, + (signed long) delay, + revents, + written, + state); + + last_avail = avail; + last_delay = delay; + last_timestamp = timestamp; + } + + return 0; +} diff --git a/src/tests/gtk-test.c b/src/tests/gtk-test.c new file mode 100644 index 00000000..a2d3e69a --- /dev/null +++ b/src/tests/gtk-test.c @@ -0,0 +1,62 @@ +/*** + This file is part of PulseAudio. + + 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 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 <gtk/gtk.h> +#include <glib.h> + +#include <pulse/context.h> +#include <pulse/glib-mainloop.h> + +int main(int argc, char *argv[]) { + + pa_context *c; + pa_glib_mainloop *m; + GtkWidget *window; + int r; + + gtk_init(&argc, &argv); + + g_set_application_name("This is a test"); + gtk_window_set_default_icon_name("foobar"); + g_setenv("PULSE_PROP_media.role", "phone", TRUE); + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW (window), g_get_application_name()); + gtk_widget_show_all(window); + + m = pa_glib_mainloop_new(NULL); + g_assert(m); + + c = pa_context_new(pa_glib_mainloop_get_api(m), NULL); + g_assert(c); + + r = pa_context_connect(c, NULL, 0, NULL); + g_assert(r == 0); + + gtk_main(); + + pa_context_unref(c); + pa_glib_mainloop_free(m); + + return 0; +} diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 9d930774..d7da660c 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -39,10 +39,23 @@ static pa_context *context = NULL; static pa_stream *stream = NULL; static pa_mainloop_api *mainloop_api = NULL; +static pa_bool_t playback = TRUE; static void stream_write_cb(pa_stream *p, size_t nbytes, void *userdata) { /* Just some silence */ - pa_stream_write(p, pa_xmalloc0(nbytes), nbytes, pa_xfree, 0, PA_SEEK_RELATIVE); + pa_assert_se(pa_stream_write(p, pa_xmalloc0(nbytes), nbytes, pa_xfree, 0, PA_SEEK_RELATIVE) == 0); +} + +static void stream_read_cb(pa_stream *p, size_t nbytes, void *userdata) { + /* We don't care, just drop the data */ + + while (pa_stream_readable_size(p) > 0) { + const void *d; + size_t b; + + pa_assert_se(pa_stream_peek(p, &d, &b) == 0); + pa_assert_se(pa_stream_drop(p) == 0); + } } /* This is called whenever the context status changes */ @@ -68,8 +81,13 @@ static void context_state_callback(pa_context *c, void *userdata) { stream = pa_stream_new(c, "interpol-test", &ss, NULL); assert(stream); - pa_stream_connect_playback(stream, NULL, NULL, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL); - pa_stream_set_write_callback(stream, stream_write_cb, NULL); + if (playback) { + pa_assert_se(pa_stream_connect_playback(stream, NULL, NULL, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL) == 0); + pa_stream_set_write_callback(stream, stream_write_cb, NULL); + } else { + pa_assert_se(pa_stream_connect_record(stream, NULL, NULL, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE) == 0); + pa_stream_set_read_callback(stream, stream_read_cb, NULL); + } break; } @@ -90,6 +108,8 @@ int main(int argc, char *argv[]) { struct timeval start, last_info = { 0, 0 }; pa_usec_t old_t = 0, old_rtc = 0; + playback = argc <= 1 || !pa_streq(argv[1], "-r"); + /* Set up a new main loop */ m = pa_threaded_mainloop_new(); assert(m); @@ -106,7 +126,8 @@ int main(int argc, char *argv[]) { pa_gettimeofday(&start); - pa_threaded_mainloop_start(m); + r = pa_threaded_mainloop_start(m); + assert(r >= 0); for (k = 0; k < 5000; k++) { pa_bool_t success = FALSE, changed = FALSE; @@ -138,7 +159,14 @@ int main(int argc, char *argv[]) { if (success) { rtc = pa_timeval_diff(&now, &start); - printf("%i\t%llu\t%llu\t%llu\t%llu\t%u\t%u\n", k, (unsigned long long) rtc, (unsigned long long) t, (unsigned long long) (rtc-old_rtc), (unsigned long long) (t-old_t), changed, playing); + printf("%i\t%llu\t%llu\t%llu\t%llu\t%u\t%u\n", k, + (unsigned long long) rtc, + (unsigned long long) t, + (unsigned long long) (rtc-old_rtc), + (unsigned long long) (t-old_t), + changed, + playing); + fflush(stdout); old_t = t; old_rtc = rtc; diff --git a/src/tests/ipacl-test.c b/src/tests/ipacl-test.c index bcdd469a..f89665cd 100644 --- a/src/tests/ipacl-test.c +++ b/src/tests/ipacl-test.c @@ -25,12 +25,15 @@ #endif #include "../pulsecore/winsock.h" +#include "../pulsecore/macro.h" #include <pulsecore/ipacl.h> int main(int argc, char *argv[]) { struct sockaddr_in sa; +#ifdef HAVE_IPV6 struct sockaddr_in6 sa6; +#endif int fd; int r; pa_ip_acl *acl; @@ -87,13 +90,14 @@ int main(int argc, char *argv[]) { close(fd); +#ifdef HAVE_IPV6 fd = socket(PF_INET6, SOCK_STREAM, 0); assert(fd >= 0); memset(&sa6, 0, sizeof(sa6)); sa6.sin6_family = AF_INET6; sa6.sin6_port = htons(22); - inet_pton(AF_INET6, "::1", &sa6.sin6_addr); + pa_assert_se(inet_pton(AF_INET6, "::1", &sa6.sin6_addr) == 1); r = connect(fd, (struct sockaddr*) &sa6, sizeof(sa6)); assert(r >= 0); @@ -129,6 +133,7 @@ int main(int argc, char *argv[]) { pa_ip_acl_free(acl); close(fd); +#endif return 0; } diff --git a/src/tests/sync-playback.c b/src/tests/sync-playback.c index 42c479a1..f2a15601 100644 --- a/src/tests/sync-playback.c +++ b/src/tests/sync-playback.c @@ -174,11 +174,16 @@ int main(int argc, char *argv[]) { pa_context_set_state_callback(context, context_state_callback, NULL); - pa_context_connect(context, NULL, 0, NULL); + /* Connect the context */ + if (pa_context_connect(context, NULL, 0, NULL) < 0) { + fprintf(stderr, "pa_context_connect() failed.\n"); + goto quit; + } if (pa_mainloop_run(m, &ret) < 0) fprintf(stderr, "pa_mainloop_run() failed.\n"); +quit: pa_context_unref(context); for (i = 0; i < NSTREAMS; i++) diff --git a/src/tests/thread-mainloop-test.c b/src/tests/thread-mainloop-test.c index 263cd57d..3bcf4f16 100644 --- a/src/tests/thread-mainloop-test.c +++ b/src/tests/thread-mainloop-test.c @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) { pa_assert_se(m = pa_threaded_mainloop_new()); pa_assert_se(a = pa_threaded_mainloop_get_api(m)); - pa_threaded_mainloop_start(m); + pa_assert_se(pa_threaded_mainloop_start(m) >= 0); pa_threaded_mainloop_lock(m); |