From 542607f4c602e632b32efe2b6fd21f81ff52bd8d Mon Sep 17 00:00:00 2001 From: Diego Elio 'Flameeyes' Pettenò Date: Fri, 17 Jul 2009 21:03:22 +0200 Subject: Make the rtstutter tests mostly pointless without CLOCK_REALTIME. On the other hand, this actually makes the test build, and test at least that it doesn't abort away, when the CLOCK_REALTIME interface is not present (or when clock_gettime is not found). --- src/tests/rtstutter.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/tests') diff --git a/src/tests/rtstutter.c b/src/tests/rtstutter.c index a4b5d596..c93fee93 100644 --- a/src/tests/rtstutter.c +++ b/src/tests/rtstutter.c @@ -67,7 +67,9 @@ static void* work(void *p) { pa_log_notice("CPU%i: Sleeping for 1s", PA_PTR_TO_UINT(p)); sleep(1); +#ifdef CLOCK_REALTIME pa_assert_se(clock_gettime(CLOCK_REALTIME, &end) == 0); +#endif nsec = (uint64_t) ((((double) rand())*(double)(msec_upper-msec_lower)*PA_NSEC_PER_MSEC)/RAND_MAX) + @@ -84,7 +86,9 @@ static void* work(void *p) { } do { +#ifdef CLOCK_REALTIME pa_assert_se(clock_gettime(CLOCK_REALTIME, &now) == 0); +#endif } while (now.tv_sec < end.tv_sec || (now.tv_sec == end.tv_sec && now.tv_nsec < end.tv_nsec)); } -- cgit From a2b207e38ac35ffc048351f76d83f7f9db37bb6c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 20 Jul 2009 15:47:57 +0100 Subject: daemon: before exec'ing ourselves, make sure nobody plays games with /proc/self/exe --- src/tests/mix-test.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/tests') diff --git a/src/tests/mix-test.c b/src/tests/mix-test.c index c7a30d67..3f65cbac 100644 --- a/src/tests/mix-test.c +++ b/src/tests/mix-test.c @@ -83,8 +83,10 @@ static void dump_block(const pa_sample_spec *ss, const pa_memchunk *chunk) { case PA_SAMPLE_S24RE: { uint8_t *u = d; - for (i = 0; i < chunk->length / pa_frame_size(ss); i++) - printf("0x%02x%02x%02xx ", *(u++), *(u++), *(u++)); + for (i = 0; i < chunk->length / pa_frame_size(ss); i++) { + printf("0x%02x%02x%02xx ", *u, *(u+1), *(u+2)); + u += 3; + } break; } -- cgit From 59659e1db64d2a88787943da75cf6c510d0ad98f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 24 Jul 2009 20:22:19 +0200 Subject: interpol-test: allow configuration of latency --- src/tests/interpol-test.c | 81 +++++++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 27 deletions(-) (limited to 'src/tests') diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 0c906d3e..007555c3 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -43,20 +43,37 @@ static pa_context *context = NULL; static pa_stream *stream = NULL; static pa_mainloop_api *mainloop_api = NULL; static pa_bool_t playback = TRUE; +static pa_usec_t latency = 0; static void stream_write_cb(pa_stream *p, size_t nbytes, void *userdata) { /* Just some silence */ - pa_assert_se(pa_stream_write(p, pa_xmalloc0(nbytes), nbytes, pa_xfree, 0, PA_SEEK_RELATIVE) == 0); + + for (;;) { + void *data; + + pa_assert_se((nbytes = pa_stream_writable_size(p)) != (size_t) -1); + + if (nbytes <= 0) + break; + + pa_assert_se(pa_stream_begin_write(p, &data, &nbytes) == 0); + pa_memzero(data, nbytes); + pa_assert_se(pa_stream_write(p, data, nbytes, NULL, 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 */ + /* We don't care about the data, just drop it */ - while (pa_stream_readable_size(p) > 0) { - const void *d; - size_t b; + for (;;) { + const void *data; - pa_assert_se(pa_stream_peek(p, &d, &b) == 0); + pa_assert_se((nbytes = pa_stream_readable_size(p)) != (size_t) -1); + + if (nbytes <= 0) + break; + + pa_assert_se(pa_stream_peek(p, &data, &nbytes) == 0); pa_assert_se(pa_stream_drop(p) == 0); } } @@ -82,27 +99,36 @@ static void context_state_callback(pa_context *c, void *userdata) { case PA_CONTEXT_READY: { pa_stream_flags_t flags = PA_STREAM_AUTO_TIMING_UPDATE; - + pa_buffer_attr attr; static const pa_sample_spec ss = { .format = PA_SAMPLE_S16LE, .rate = 44100, .channels = 2 }; + pa_zero(attr); + attr.maxlength = (uint32_t) -1; + attr.tlength = latency > 0 ? (uint32_t) pa_usec_to_bytes(latency, &ss) : (uint32_t) -1; + attr.prebuf = (uint32_t) -1; + attr.minreq = (uint32_t) -1; + attr.fragsize = (uint32_t) -1; + #ifdef INTERPOLATE flags |= PA_STREAM_INTERPOLATE_TIMING; #endif + if (latency > 0) + flags |= PA_STREAM_ADJUST_LATENCY; + fprintf(stderr, "Connection established.\n"); - stream = pa_stream_new(c, "interpol-test", &ss, NULL); - assert(stream); + pa_assert_se(stream = pa_stream_new(c, "interpol-test", &ss, NULL)); if (playback) { - pa_assert_se(pa_stream_connect_playback(stream, NULL, NULL, flags, NULL, NULL) == 0); + pa_assert_se(pa_stream_connect_playback(stream, NULL, &attr, flags, NULL, NULL) == 0); pa_stream_set_write_callback(stream, stream_write_cb, NULL); } else { - pa_assert_se(pa_stream_connect_record(stream, NULL, NULL, flags) == 0); + pa_assert_se(pa_stream_connect_record(stream, NULL, &attr, flags) == 0); pa_stream_set_read_callback(stream, stream_read_cb, NULL); } @@ -123,7 +149,7 @@ static void context_state_callback(pa_context *c, void *userdata) { int main(int argc, char *argv[]) { pa_threaded_mainloop* m = NULL; - int k, r; + int k; struct timeval start, last_info = { 0, 0 }; pa_usec_t old_t = 0, old_rtc = 0; #ifdef CORK @@ -134,24 +160,22 @@ int main(int argc, char *argv[]) { playback = argc <= 1 || !pa_streq(argv[1], "-r"); - /* Set up a new main loop */ - m = pa_threaded_mainloop_new(); - assert(m); - - mainloop_api = pa_threaded_mainloop_get_api(m); + latency = + (argc >= 2 && !pa_streq(argv[1], "-r")) ? atoi(argv[1]) : + (argc >= 3 ? atoi(argv[2]) : 0); - context = pa_context_new(mainloop_api, argv[0]); - assert(context); + /* Set up a new main loop */ + pa_assert_se(m = pa_threaded_mainloop_new()); + pa_assert_se(mainloop_api = pa_threaded_mainloop_get_api(m)); + pa_assert_se(context = pa_context_new(mainloop_api, argv[0])); pa_context_set_state_callback(context, context_state_callback, NULL); - r = pa_context_connect(context, NULL, 0, NULL); - assert(r >= 0); + pa_assert_se(pa_context_connect(context, NULL, 0, NULL) >= 0); pa_gettimeofday(&start); - r = pa_threaded_mainloop_start(m); - assert(r >= 0); + pa_assert_se(pa_threaded_mainloop_start(m) >= 0); /* #ifdef CORK */ for (k = 0; k < 20000; k++) @@ -160,7 +184,7 @@ int main(int argc, char *argv[]) { /* #endif */ { pa_bool_t success = FALSE, changed = FALSE; - pa_usec_t t, rtc; + pa_usec_t t, rtc, d; struct timeval now, tv; pa_bool_t playing = FALSE; @@ -169,7 +193,8 @@ int main(int argc, char *argv[]) { if (stream) { const pa_timing_info *info; - if (pa_stream_get_time(stream, &t) >= 0) + if (pa_stream_get_time(stream, &t) >= 0 && + pa_stream_get_latency(stream, &d, NULL) >= 0) success = TRUE; if ((info = pa_stream_get_timing_info(stream))) { @@ -191,14 +216,16 @@ int main(int argc, char *argv[]) { pa_bool_t cork_now; #endif rtc = pa_timeval_diff(&now, &start); - printf("%i\t%llu\t%llu\t%llu\t%llu\t%lli\t%u\t%u\n", k, + printf("%i\t%llu\t%llu\t%llu\t%llu\t%lli\t%u\t%u\t%llu\t%llu\n", k, (unsigned long long) rtc, (unsigned long long) t, (unsigned long long) (rtc-old_rtc), (unsigned long long) (t-old_t), (signed long long) rtc - (signed long long) t, changed, - playing); + playing, + (unsigned long long) latency, + (unsigned long long) d); fflush(stdout); old_t = t; -- cgit From 49fd8ee72e76cd27a978a843ecc58ad10fe077bc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 1 Aug 2009 02:03:22 +0200 Subject: core-util: replace remaining fixed size destination string functions by _malloc() versions This helps portability to GNU/Hurd. Patch originally from Samuel Thibault but modified. Closes ticket #546 --- src/tests/get-binary-name-test.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/tests') diff --git a/src/tests/get-binary-name-test.c b/src/tests/get-binary-name-test.c index a34e38fd..e49f2eff 100644 --- a/src/tests/get-binary-name-test.c +++ b/src/tests/get-binary-name-test.c @@ -23,12 +23,33 @@ #include #include +#include #include +#include int main(int argc, char *argv[]) { - char exename[PATH_MAX]; + char *exename; + size_t allocated = 128; + + for (;;) { + exename = pa_xmalloc(allocated); + + if (!pa_get_binary_name(exename, allocated)) { + printf("failed to read binary name\n"); + pa_xfree(exename); + break; + } + + if (strlen(exename) < allocated - 1) { + printf("%s\n", exename); + pa_xfree(exename); + break; + } + + pa_xfree(exename); + allocated *= 2; + } - printf("%s\n", pa_get_binary_name(exename, sizeof(exename))); return 0; } -- cgit From 9bd3398f94114387dc91bf930bdad90d58711e88 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 8 Aug 2009 04:30:42 +0200 Subject: mix-test: fix test for s24-32 samples --- src/tests/mix-test.c | 74 +++++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 33 deletions(-) (limited to 'src/tests') diff --git a/src/tests/mix-test.c b/src/tests/mix-test.c index 3f65cbac..f9f76da3 100644 --- a/src/tests/mix-test.c +++ b/src/tests/mix-test.c @@ -69,6 +69,8 @@ static void dump_block(const pa_sample_spec *ss, const pa_memchunk *chunk) { break; } + case PA_SAMPLE_S24_32NE: + case PA_SAMPLE_S24_32RE: case PA_SAMPLE_S32NE: case PA_SAMPLE_S32RE: { uint32_t *u = d; @@ -84,7 +86,7 @@ static void dump_block(const pa_sample_spec *ss, const pa_memchunk *chunk) { uint8_t *u = d; for (i = 0; i < chunk->length / pa_frame_size(ss); i++) { - printf("0x%02x%02x%02xx ", *u, *(u+1), *(u+2)); + printf("0x%02x%02x%02xx ", *u, *(u+1), *(u+2)); u += 3; } @@ -125,66 +127,72 @@ static pa_memblock* generate_block(pa_mempool *pool, const pa_sample_spec *ss) { case PA_SAMPLE_U8: case PA_SAMPLE_ULAW: case PA_SAMPLE_ALAW: { - static const uint8_t u8_samples[] = - { 0x00, 0xFF, 0x7F, 0x80, 0x9f, - 0x3f, 0x01, 0xF0, 0x20, 0x21 }; + static const uint8_t u8_samples[] = { + 0x00, 0xFF, 0x7F, 0x80, 0x9f, + 0x3f, 0x01, 0xF0, 0x20, 0x21 + }; - memcpy(d, &u8_samples[0], sizeof(u8_samples)); + memcpy(d, u8_samples, sizeof(u8_samples)); break; } case PA_SAMPLE_S16NE: case PA_SAMPLE_S16RE: { - static const uint16_t u16_samples[] = - { 0x0000, 0xFFFF, 0x7FFF, 0x8000, 0x9fff, - 0x3fff, 0x0001, 0xF000, 0x0020, 0x0021 }; + static const uint16_t u16_samples[] = { + 0x0000, 0xFFFF, 0x7FFF, 0x8000, 0x9fff, + 0x3fff, 0x0001, 0xF000, 0x0020, 0x0021 + }; - memcpy(d, &u16_samples[0], sizeof(u16_samples)); + memcpy(d, u16_samples, sizeof(u16_samples)); break; } + case PA_SAMPLE_S24_32NE: + case PA_SAMPLE_S24_32RE: case PA_SAMPLE_S32NE: case PA_SAMPLE_S32RE: { - static const uint32_t u32_samples[] = - { 0x00000001, 0xFFFF0002, 0x7FFF0003, 0x80000004, 0x9fff0005, - 0x3fff0006, 0x00010007, 0xF0000008, 0x00200009, 0x0021000A }; + static const uint32_t u32_samples[] = { + 0x00000001, 0xFFFF0002, 0x7FFF0003, 0x80000004, 0x9fff0005, + 0x3fff0006, 0x00010007, 0xF0000008, 0x00200009, 0x0021000A + }; - memcpy(d, &u32_samples[0], sizeof(u32_samples)); + memcpy(d, u32_samples, sizeof(u32_samples)); break; } case PA_SAMPLE_S24NE: case PA_SAMPLE_S24RE: { - /* Need to be on a byte array because they are not aligned */ - static const uint8_t u24_samples[] = - { 0x00, 0x00, 0x01, - 0xFF, 0xFF, 0x02, - 0x7F, 0xFF, 0x03, - 0x80, 0x00, 0x04, - 0x9f, 0xff, 0x05, - 0x3f, 0xff, 0x06, - 0x01, 0x00, 0x07, - 0xF0, 0x00, 0x08, - 0x20, 0x00, 0x09, - 0x21, 0x00, 0x0A }; - - memcpy(d, &u24_samples[0], sizeof(u24_samples)); + /* Need to be on a byte array because they are not aligned */ + static const uint8_t u24_samples[] = { + 0x00, 0x00, 0x01, + 0xFF, 0xFF, 0x02, + 0x7F, 0xFF, 0x03, + 0x80, 0x00, 0x04, + 0x9f, 0xff, 0x05, + 0x3f, 0xff, 0x06, + 0x01, 0x00, 0x07, + 0xF0, 0x00, 0x08, + 0x20, 0x00, 0x09, + 0x21, 0x00, 0x0A + }; + + memcpy(d, u24_samples, sizeof(u24_samples)); break; } case PA_SAMPLE_FLOAT32NE: case PA_SAMPLE_FLOAT32RE: { float *u = d; - static const float float_samples[] = - { 0.0f, -1.0f, 1.0f, 4711.0f, 0.222f, - 0.33f, -.3f, 99.0f, -0.555f, -.123f }; + static const float float_samples[] = { + 0.0f, -1.0f, 1.0f, 4711.0f, 0.222f, + 0.33f, -.3f, 99.0f, -0.555f, -.123f + }; if (ss->format == PA_SAMPLE_FLOAT32RE) { for (i = 0; i < 10; i++) u[i] = swap_float(float_samples[i]); - } else { - memcpy(d, &float_samples[0], sizeof(float_samples)); - } + } else + memcpy(d, float_samples, sizeof(float_samples)); break; } -- cgit From 0f2a4ed422530b56b3744efe8055540644c0e774 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 14 Aug 2009 20:03:30 +0200 Subject: volume: guarantee dB/linear conversion is reversible --- src/tests/voltest.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/tests') diff --git a/src/tests/voltest.c b/src/tests/voltest.c index 2dcfa53c..64aec5c6 100644 --- a/src/tests/voltest.c +++ b/src/tests/voltest.c @@ -1,8 +1,33 @@ +/*** + 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.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 +#endif + #include #include #include +#include + int main(int argc, char *argv[]) { pa_volume_t v; pa_cvolume cv; @@ -60,5 +85,16 @@ int main(int argc, char *argv[]) { printf("After: volume: [%s]; balance: %2.1f (intended: %2.1f) %s\n", pa_cvolume_snprint(s, sizeof(s), &r), k, b, k < b-.05 || k > b+.5 ? "MISMATCH" : ""); } + for (v = PA_VOLUME_MUTED; v <= PA_VOLUME_NORM*2; v += 1) { + + double l = pa_sw_volume_to_linear(v); + pa_volume_t k = pa_sw_volume_from_linear(l); + double db = pa_sw_volume_to_dB(v); + pa_volume_t r = pa_sw_volume_from_dB(db); + + pa_assert(k == v); + pa_assert(r == v); + } + return 0; } -- cgit