summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-03-07 00:22:40 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-03-07 00:22:40 +0100
commit5cc1d55d769e278f51eeb057b08d04afd6bb0c44 (patch)
tree1b58358a591c948da940f053750b6e0092f00f24 /tests
parent4dd955d2c1dac90e9c20b5a9ac1deb0fd489f9b8 (diff)
Add a simple benchmark program for the xattr key/value recorder
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests')
-rw-r--r--tests/libsqfs/Makemodule.am5
-rw-r--r--tests/libsqfs/xattr_benchmark.c124
2 files changed, 129 insertions, 0 deletions
diff --git a/tests/libsqfs/Makemodule.am b/tests/libsqfs/Makemodule.am
index 0ad19d9..5ebb94b 100644
--- a/tests/libsqfs/Makemodule.am
+++ b/tests/libsqfs/Makemodule.am
@@ -7,8 +7,13 @@ test_table_LDADD = libsquashfs.la
test_xattr_writer_SOURCES = tests/libsqfs/xattr_writer.c tests/test.h
test_xattr_writer_LDADD = libsquashfs.la
+xattr_benchmark_SOURCES = tests/libsqfs/xattr_benchmark.c
+xattr_benchmark_LDADD = libcommon.a libsquashfs.la libcompat.a
+
LIBSQFS_TESTS = \
test_abi test_table test_xattr_writer
+noinst_PROGRAMS += xattr_benchmark
+
check_PROGRAMS += $(LIBSQFS_TESTS)
TESTS += $(LIBSQFS_TESTS)
diff --git a/tests/libsqfs/xattr_benchmark.c b/tests/libsqfs/xattr_benchmark.c
new file mode 100644
index 0000000..918a636
--- /dev/null
+++ b/tests/libsqfs/xattr_benchmark.c
@@ -0,0 +1,124 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * xattr_benchmark.c
+ *
+ * Copyright (C) 2021 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+#include "compat.h"
+#include "common.h"
+
+#include "sqfs/xattr_writer.h"
+#include "sqfs/xattr.h"
+
+#include <stdlib.h>
+#include <getopt.h>
+#include <string.h>
+#include <stdio.h>
+
+static struct option long_opts[] = {
+ { "block-count", required_argument, NULL, 'b' },
+ { "groups-size", required_argument, NULL, 'g' },
+ { "version", no_argument, NULL, 'V' },
+ { "help", no_argument, NULL, 'h' },
+ { NULL, 0, NULL, 0 },
+};
+
+static const char *short_opts = "g:b:hV";
+
+static const char *help_string =
+"Usage: xattr_benchmark [OPTIONS...]\n"
+"\n"
+"Possible options:\n"
+"\n"
+" --block-count, -b <count> How many unique xattr blocks to generate.\n"
+" --group-size, -g <count> Number of key-value pairs to generate for each\n"
+" xattr block.\n"
+"\n";
+
+int main(int argc, char **argv)
+{
+ long blkidx, grpidx, block_count = 0, group_size = 0;
+ sqfs_xattr_writer_t *xwr;
+ sqfs_u32 id;
+ int ret;
+
+ for (;;) {
+ int i = getopt_long(argc, argv, short_opts, long_opts, NULL);
+ if (i == -1)
+ break;
+
+ switch (i) {
+ case 'b':
+ block_count = strtol(optarg, NULL, 0);
+ break;
+ case 'g':
+ group_size = strtol(optarg, NULL, 0);
+ break;
+ case 'h':
+ fputs(help_string, stdout);
+ return EXIT_SUCCESS;
+ case 'V':
+ print_version("xattr_benchmark");
+ return EXIT_SUCCESS;
+ default:
+ goto fail_arg;
+ }
+ }
+
+ if (block_count <= 0) {
+ fputs("A block count > 0 must be specified.\n", stderr);
+ goto fail_arg;
+ }
+
+ if (group_size <= 0) {
+ fputs("A group size > 0 must be specified.\n", stderr);
+ goto fail_arg;
+ }
+
+ /* setup writer */
+ xwr = sqfs_xattr_writer_create(0);
+
+ /* generate blocks */
+ for (blkidx = 0; blkidx < block_count; ++blkidx) {
+ ret = sqfs_xattr_writer_begin(xwr, 0);
+ if (ret < 0) {
+ sqfs_perror(NULL, "begin xattr block", ret);
+ goto fail;
+ }
+
+ for (grpidx = 0; grpidx < group_size; ++grpidx) {
+ char key[64], value[64];
+
+ snprintf(key, sizeof(key), "user.group%ld.key%ld",
+ blkidx, grpidx);
+
+ snprintf(value, sizeof(value), "group%ld/value%ld",
+ blkidx, grpidx);
+
+ ret = sqfs_xattr_writer_add(xwr, key, value,
+ strlen(value));
+
+ if (ret < 0) {
+ sqfs_perror(NULL, "add to xattr block", ret);
+ goto fail;
+ }
+ }
+
+ ret = sqfs_xattr_writer_end(xwr, &id);
+ if (ret < 0) {
+ sqfs_perror(NULL, "end xattr block", ret);
+ goto fail;
+ }
+ }
+
+ /* cleanup */
+ sqfs_destroy(xwr);
+ return EXIT_SUCCESS;
+fail:
+ sqfs_destroy(xwr);
+ return EXIT_FAILURE;
+fail_arg:
+ fputs("Try `xattr_benchmark --help' for more information.\n", stderr);
+ return EXIT_FAILURE;
+}