From: Cyril H. <ch...@su...> - 2012-01-19 18:00:02
|
Hi! > +#include "config.h" > +#include <sys/types.h> > +#include <sys/stat.h> > +#include <sys/wait.h> > +#include <errno.h> > +#include <fcntl.h> > +#include <unistd.h> > +#include <signal.h> > +#include <stdio.h> > +#include <stdlib.h> > +#include <string.h> > +#ifdef HAVE_ATTR_XATTR_H > +#include <attr/xattr.h> > +#endif > +#include "test.h" > +#include "usctest.h" > + > +char *TCID = "getxattr03"; > + > +#ifdef HAVE_ATTR_XATTR_H > +#define XATTR_TEST_KEY "user.testkey" > +#define XATTR_TEST_VALUE "test value" > +#define TESTFILE "getxattr03testfile" > + > +static void setup(void); > +static void cleanup(void); > + > +int TST_TOTAL = 1; > + > +int main(int argc, char *argv[]) > +{ > + int lc; > + char *msg; > + > + msg = parse_opts(argc, argv, NULL, NULL); > + if (msg != NULL) > + tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg); > + > + setup(); > + > + for (lc = 0; TEST_LOOPING(lc); lc++) { > + Tst_count = 0; > + > + TEST(getxattr(TESTFILE, XATTR_TEST_KEY, NULL, 0)); > + > + if (TEST_RETURN == strlen(XATTR_TEST_VALUE)) You could use sizeof(XATTR_TEST_VALUE) - 1, which would be computed at compile time. > + tst_resm(TPASS, "getxattr(2) returned correct value"); > + else > + tst_resm(TFAIL | TTERRNO, "getxattr(2) failed"); > + } > + > + cleanup(); > + tst_exit(); > +} > + > +static void setup(void) > +{ > + int fd; > + > + tst_require_root(NULL); > + > + tst_tmpdir(); > + > + /* Test for xattr support and set attr value */ > + fd = creat(TESTFILE, 0644); > + if (fd == -1) > + tst_brkm(TBROK | TERRNO, cleanup, "Create %s failed", TESTFILE); > + close(fd); > + > + if (setxattr(TESTFILE, XATTR_TEST_KEY, XATTR_TEST_VALUE, > + strlen(XATTR_TEST_VALUE), XATTR_CREATE) == -1) { Here too. > + if (errno == ENOTSUP) > + tst_brkm(TCONF, cleanup, "No xattr support in fs or " > + "mount without user_xattr option"); Should rather say ... of fs mounted without ... > + else > + tst_brkm(TBROK | TERRNO, cleanup, "setxattr %s failed", > + TESTFILE); > + } > + > + TEST_PAUSE; > +} > + > +static void cleanup(void) > +{ > + TEST_CLEANUP; > + tst_rmdir(); > +} > +#else /* HAVE_ATTR_XATTR_H */ > +int main(int argc, char *argv[]) > +{ > + tst_brkm(TCONF, NULL, "<attr/xattr.h> does not exist."); > +} > +#endif -- Cyril Hrubis ch...@su... |