diff options
author | Jussi Laako <jussi.laako@linux.intel.com> | 2014-03-25 15:25:44 +0200 |
---|---|---|
committer | Jussi Laako <jussi.laako@linux.intel.com> | 2014-03-25 15:26:50 +0200 |
commit | bb0ada3bddfeeb4e98d3415c37266061c865005f (patch) | |
tree | f644444272c1a5f01b333977a94677bdc80f2184 /tests/kernel/xattr/test.c | |
download | ecryptfs-utils-bb0ada3bddfeeb4e98d3415c37266061c865005f.tar.gz ecryptfs-utils-bb0ada3bddfeeb4e98d3415c37266061c865005f.tar.bz2 ecryptfs-utils-bb0ada3bddfeeb4e98d3415c37266061c865005f.zip |
Initial release for Tizenupstream/104submit/tizen/20140325.142353
Change-Id: I5f609bdfdf73bda344b01c41519f6cd65ea76f55
Diffstat (limited to 'tests/kernel/xattr/test.c')
-rw-r--r-- | tests/kernel/xattr/test.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/tests/kernel/xattr/test.c b/tests/kernel/xattr/test.c new file mode 100644 index 0000000..a552fbc --- /dev/null +++ b/tests/kernel/xattr/test.c @@ -0,0 +1,111 @@ +/* + * Author: Colin King <colin.king@canonical.com> + * + * Copyright (C) 2013 Canonical, Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <sys/xattr.h> + +static const char *names[] = { + "user.test1", + "user.test2", + "user.test3", + NULL +}; + +static const char *values[] = { + "test value #1", + "test value #2", + "test value #3", + NULL +}; + +int main(int argc, char **argv) +{ + ssize_t len, names_len = 0; + int i, rc; + char buffer[1024]; + char *ptr = buffer; + + if (argc != 2) { + fprintf(stderr, "Usage: %s file\n", argv[0]); + exit(EXIT_FAILURE); + } + + for (i = 0; names[i]; i++) { + if (setxattr(argv[1], names[i], values[i], strlen(values[i]), 0) < 0) + exit(EXIT_FAILURE); + names_len += 1 + strlen(names[i]); + } + + /* + * Sanity check that listxattr returns correct length + */ + len = listxattr(argv[1], NULL, 0); + if (len != names_len) + exit(EXIT_FAILURE); + + len = listxattr(argv[1], buffer, sizeof(buffer)); + if (len < 0) + exit(EXIT_FAILURE); + + /* + * Check listxattr names match what has been just set + */ + for (i = 0; names[i]; i++) { + if (strcmp(names[i], ptr)) + exit(EXIT_FAILURE); + ptr += strlen(ptr) + 1; + } + + /* + * Check contents of xattr + */ + for (i = 0; names[i]; i++) { + len = getxattr(argv[1], names[i], buffer, sizeof(buffer)); + if (len < 0) + exit(EXIT_FAILURE); + buffer[len] = '\0'; + + if (strcmp(values[i], buffer)) + exit(EXIT_FAILURE); + } + + /* + * Remove xattr + */ + for (i = 0; names[i]; i++) { + rc = removexattr(argv[1], names[i]); + if (rc < 0) + exit(EXIT_FAILURE); + } + + /* + * ..and there should be no xattrs left + */ + len = listxattr(argv[1], NULL, 0); + if (len != 0) + exit(EXIT_FAILURE); + + exit(EXIT_SUCCESS); +} |