summaryrefslogtreecommitdiff
path: root/axfer/test
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2021-03-11 14:21:42 +0900
committerJaroslav Kysela <perex@perex.cz>2021-03-11 09:30:02 +0100
commit92004425fc5d260052601dc5c329457eee73e7a3 (patch)
tree9cfad5ed4a870e84e9ee2f187767203a54c7f842 /axfer/test
parent5ab26fbc146bcb1a894970421a10188feed714a2 (diff)
downloadalsa-utils-92004425fc5d260052601dc5c329457eee73e7a3.tar.gz
axfer: test: use memfd_create() for mapper-test
The mapper test program writes audio data frame to files, and read them from the files, then validate them. For the operations, usage of any in-memory file is good to shorten time of overall operations. This commit uses shm by memfd_create(). Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'axfer/test')
-rw-r--r--axfer/test/mapper-test.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/axfer/test/mapper-test.c b/axfer/test/mapper-test.c
index 0bed4bb..477871d 100644
--- a/axfer/test/mapper-test.c
+++ b/axfer/test/mapper-test.c
@@ -6,11 +6,20 @@
//
// Licensed under the terms of the GNU General Public License, version 2.
+#include <aconfig.h>
+#ifdef HAVE_MEMFD_CREATE
+#define _GNU_SOURCE
+#endif
+
#include "../mapper.h"
#include "../misc.h"
#include "generator.h"
+#ifdef HAVE_MEMFD_CREATE
+#include <sys/mman.h>
+#endif
+
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
@@ -230,7 +239,11 @@ static int test_mapper(struct mapper_trial *trial, snd_pcm_access_t access,
for (i = 0; i < cntr_count; ++i) {
const char *path = trial->paths[i];
+#ifdef HAVE_MEMFD_CREATE
+ cntr_fds[i] = memfd_create(path, 0);
+#else
cntr_fds[i] = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
+#endif
if (cntr_fds[i] < 0) {
err = -errno;
goto end;
@@ -255,10 +268,8 @@ static int test_mapper(struct mapper_trial *trial, snd_pcm_access_t access,
frames_per_second, frames_per_buffer, check_buffer,
frame_count, cntr_fds, cntr_count);
end:
- for (i = 0; i < cntr_count; ++i) {
- unlink(trial->paths[i]);
+ for (i = 0; i < cntr_count; ++i)
close(cntr_fds[i]);
- }
free(cntr_fds);