Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/audit/file-attribute-access.c
Show All 30 Lines | |||||
#include <atf-c.h> | #include <atf-c.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include "utils.h" | #include "utils.h" | ||||
static struct pollfd fds[1]; | static struct pollfd fds[1]; | ||||
static mode_t mode = 0777; | static mode_t mode = 0777; | ||||
static int filedesc; | |||||
static char extregex[80]; | static char extregex[80]; | ||||
static struct stat statbuff; | static struct stat statbuff; | ||||
static const char *auclass = "fa"; | static const char *auclass = "fa"; | ||||
static const char *path = "fileforaudit"; | static const char *path = "fileforaudit"; | ||||
static const char *errpath = "dirdoesnotexist/fileforaudit"; | static const char *errpath = "dirdoesnotexist/fileforaudit"; | ||||
static const char *successreg = "fileforaudit.*return,success"; | static const char *successreg = "fileforaudit.*return,success"; | ||||
static const char *failurereg = "fileforaudit.*return,failure"; | static const char *failurereg = "fileforaudit.*return,failure"; | ||||
ATF_TC_WITH_CLEANUP(stat_success); | ATF_TC_WITH_CLEANUP(stat_success); | ||||
ATF_TC_HEAD(stat_success, tc) | ATF_TC_HEAD(stat_success, tc) | ||||
{ | { | ||||
atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " | atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " | ||||
"stat(2) call"); | "stat(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(stat_success, tc) | ATF_TC_BODY(stat_success, tc) | ||||
{ | { | ||||
/* File needs to exist to call stat(2) */ | /* File needs to exist to call stat(2) */ | ||||
ATF_REQUIRE(open(path, O_CREAT, mode) != -1); | ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
ATF_REQUIRE_EQ(0, stat(path, &statbuff)); | ATF_REQUIRE_EQ(0, stat(path, &statbuff)); | ||||
check_audit(fds, successreg, pipefd); | check_audit(fds, successreg, pipefd); | ||||
/* Close the file descriptor of path */ | |||||
asomers: A comment that simply repeats what the code does isn't a useful comment (except in assembly… | |||||
ATF_REQUIRE_EQ(0, close(filedesc)); | |||||
} | } | ||||
ATF_TC_CLEANUP(stat_success, tc) | ATF_TC_CLEANUP(stat_success, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
ATF_TC_HEAD(fstat_success, tc) | ATF_TC_HEAD(fstat_success, tc) | ||||
{ | { | ||||
atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " | atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " | ||||
"fstat(2) call"); | "fstat(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(fstat_success, tc) | ATF_TC_BODY(fstat_success, tc) | ||||
{ | { | ||||
int filedesc; | |||||
/* File needs to exist to call fstat(2) */ | /* File needs to exist to call fstat(2) */ | ||||
ATF_REQUIRE((filedesc = open(path, O_CREAT | O_RDWR, mode)) != -1); | ATF_REQUIRE((filedesc = open(path, O_CREAT | O_RDWR, mode)) != -1); | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
ATF_REQUIRE_EQ(0, fstat(filedesc, &statbuff)); | ATF_REQUIRE_EQ(0, fstat(filedesc, &statbuff)); | ||||
snprintf(extregex, sizeof(extregex), | snprintf(extregex, sizeof(extregex), | ||||
"fstat.*%jd.*return,success", (intmax_t)statbuff.st_ino); | "fstat.*%jd.*return,success", (intmax_t)statbuff.st_ino); | ||||
check_audit(fds, extregex, pipefd); | check_audit(fds, extregex, pipefd); | ||||
/* Close the file descriptor of path */ | |||||
ATF_REQUIRE_EQ(0, close(filedesc)); | |||||
asomersUnsubmitted Done Inline ActionsIt's usually a bad idea to put assertions in teardown code, because a failed assertion can prevent the rest of the teardown from running. In this case it doesn't matter, because there's only one teardown statement. Still, it would be conventional to omit the ATF_REQUIRE_EQ. asomers: It's usually a bad idea to put assertions in teardown code, because a failed assertion can… | |||||
} | } | ||||
ATF_TC_CLEANUP(fstat_success, tc) | ATF_TC_CLEANUP(fstat_success, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |
A comment that simply repeats what the code does isn't a useful comment (except in assembly programming, where the code is filled with stuff like VPCLMULQDQ). You should delete these comments, or replace them with something like "teardown".