The container test program writes audio data frame to file, and read them from the file, then validate them. For the operations, usage of any in-memory file is good to shorten time of overall operations.
This commit uses shm via memfd_create(). As a result, overall time to run is shorten one half of before, depending on machine environment.
I note that we can achieve the same result by using O_TMPFILE flag in open(2) system call, however the implementation of O_TMPFILE is to add i-node without name on underling file system, thus it has overhead depending on implementation in each file system. On the other hand, memfd_create() is directly relevant to shm and expected to be less overhead.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- axfer/test/container-test.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/axfer/test/container-test.c b/axfer/test/container-test.c index 4d825b6..4e2dcc2 100644 --- a/axfer/test/container-test.c +++ b/axfer/test/container-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 "../container.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> @@ -142,16 +151,17 @@ static int callback(struct test_generator *gen, snd_pcm_access_t access, if (buf == NULL) return -ENOMEM;
- // Remove a result of a previous trial. - unlink(name); - for (i = 0; i < ARRAY_SIZE(entries); ++i) { int fd; off64_t pos;
frames_per_second = entries[i];
+#ifdef HAVE_MEMFD_CREATE + fd = memfd_create(name, 0); +#else fd = open(name, O_RDWR | O_CREAT | O_TRUNC, 0644); +#endif if (fd < 0) { err = -errno; break; @@ -176,7 +186,6 @@ static int callback(struct test_generator *gen, snd_pcm_access_t access, assert(err == 0);
close(fd); - unlink(name); }
free(buf);