From 0bec3189c22b91c647975cf3ad204b0a361caf95 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 23 Jun 2019 17:48:35 +0200 Subject: Add basic test case for fstree extended attributes Signed-off-by: David Oberhollenzer --- tests/Makemodule.am | 7 ++++-- tests/fstree_xattr.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 tests/fstree_xattr.c diff --git a/tests/Makemodule.am b/tests/Makemodule.am index 17f36b2..d70c796 100644 --- a/tests/Makemodule.am +++ b/tests/Makemodule.am @@ -31,12 +31,15 @@ test_fstree_from_file_LDADD = libfstree.a libutil.a test_fstree_init_SOURCES = tests/fstree_init.c test_fstree_init_LDADD = libfstree.a libutil.a +test_fstree_xattr_SOURCES = tests/fstree_xattr.c +test_fstree_xattr_LDADD = libfstree.a libutil.a + check_PROGRAMS += test_canonicalize_name test_mknode_simple test_mknode_slink check_PROGRAMS += test_mknode_reg test_mknode_dir test_gen_inode_table check_PROGRAMS += test_add_by_path test_get_path test_fstree_sort -check_PROGRAMS += test_fstree_from_file test_fstree_init +check_PROGRAMS += test_fstree_from_file test_fstree_init test_fstree_xattr TESTS += test_canonicalize_name test_mknode_simple test_mknode_slink TESTS += test_mknode_reg test_mknode_dir test_gen_inode_table TESTS += test_add_by_path test_get_path test_fstree_sort test_fstree_from_file -TESTS += test_fstree_init +TESTS += test_fstree_init test_fstree_xattr diff --git a/tests/fstree_xattr.c b/tests/fstree_xattr.c new file mode 100644 index 0000000..9ac6907 --- /dev/null +++ b/tests/fstree_xattr.c @@ -0,0 +1,69 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +#include "fstree.h" + +#include +#include +#include + +int main(void) +{ + tree_node_t *a, *b, *c, *d; + struct stat sb; + fstree_t fs; + + assert(fstree_init(&fs, 512, NULL) == 0); + + memset(&sb, 0, sizeof(sb)); + sb.st_mode = S_IFCHR | 0640; + sb.st_rdev = 1337; + + a = fstree_add_generic(&fs, "/a", &sb, NULL); + b = fstree_add_generic(&fs, "/b", &sb, NULL); + c = fstree_add_generic(&fs, "/c", &sb, NULL); + d = fstree_add_generic(&fs, "/d", &sb, NULL); + assert(a != NULL); + assert(b != NULL); + assert(c != NULL); + assert(d != NULL); + + assert(fstree_add_xattr(&fs, a, "foo", "bar") == 0); + + assert(fstree_add_xattr(&fs, b, "foo", "bar") == 0); + assert(fstree_add_xattr(&fs, b, "baz", "qux") == 0); + + assert(fstree_add_xattr(&fs, c, "foo", "something else") == 0); + + assert(fstree_add_xattr(&fs, d, "baz", "qux") == 0); + assert(fstree_add_xattr(&fs, d, "foo", "bar") == 0); + + assert(a->xattr != NULL); + assert(b->xattr != NULL); + assert(c->xattr != NULL); + assert(d->xattr != NULL); + + assert(a->xattr != b->xattr); + assert(a->xattr != c->xattr); + assert(a->xattr != d->xattr); + assert(b->xattr != c->xattr); + assert(b->xattr != d->xattr); + assert(c->xattr != d->xattr); + + assert(a->xattr->num_attr == 1); + assert(b->xattr->num_attr == 2); + assert(c->xattr->num_attr == 1); + assert(d->xattr->num_attr == 2); + + assert(a->xattr->ref[0] == b->xattr->ref[0]); + assert(a->xattr->ref[0] == c->xattr->ref[1]); + assert(a->xattr->ref[0] != c->xattr->ref[0]); + assert(b->xattr->ref[1] == d->xattr->ref[0]); + + fstree_xattr_deduplicate(&fs); + + assert(b->xattr == d->xattr); + assert(a->xattr != b->xattr); + assert(a->xattr != c->xattr); + + fstree_cleanup(&fs); + return EXIT_SUCCESS; +} -- cgit v1.2.3