[Msan] Fix tests reading /proc files on FreeBSD
Differential Revision: http://reviews.llvm.org/D6926 llvm-svn: 225686
This commit is contained in:
parent
ac3128d901
commit
6aba5098fd
|
@ -73,6 +73,13 @@
|
||||||
# include <immintrin.h>
|
# include <immintrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// On FreeBSD procfs is not enabled by default.
|
||||||
|
#if defined(__FreeBSD__)
|
||||||
|
# define FILE_TO_READ "/bin/cat"
|
||||||
|
#else
|
||||||
|
# define FILE_TO_READ "/proc/self/stat"
|
||||||
|
#endif
|
||||||
|
|
||||||
static const size_t kPageSize = 4096;
|
static const size_t kPageSize = 4096;
|
||||||
|
|
||||||
typedef unsigned char U1;
|
typedef unsigned char U1;
|
||||||
|
@ -564,7 +571,7 @@ TEST(MemorySanitizer, strerror_r) {
|
||||||
|
|
||||||
TEST(MemorySanitizer, fread) {
|
TEST(MemorySanitizer, fread) {
|
||||||
char *x = new char[32];
|
char *x = new char[32];
|
||||||
FILE *f = fopen("/proc/self/stat", "r");
|
FILE *f = fopen(FILE_TO_READ, "r");
|
||||||
ASSERT_TRUE(f != NULL);
|
ASSERT_TRUE(f != NULL);
|
||||||
fread(x, 1, 32, f);
|
fread(x, 1, 32, f);
|
||||||
EXPECT_NOT_POISONED(x[0]);
|
EXPECT_NOT_POISONED(x[0]);
|
||||||
|
@ -576,7 +583,7 @@ TEST(MemorySanitizer, fread) {
|
||||||
|
|
||||||
TEST(MemorySanitizer, read) {
|
TEST(MemorySanitizer, read) {
|
||||||
char *x = new char[32];
|
char *x = new char[32];
|
||||||
int fd = open("/proc/self/stat", O_RDONLY);
|
int fd = open(FILE_TO_READ, O_RDONLY);
|
||||||
ASSERT_GT(fd, 0);
|
ASSERT_GT(fd, 0);
|
||||||
int sz = read(fd, x, 32);
|
int sz = read(fd, x, 32);
|
||||||
ASSERT_EQ(sz, 32);
|
ASSERT_EQ(sz, 32);
|
||||||
|
@ -589,7 +596,7 @@ TEST(MemorySanitizer, read) {
|
||||||
|
|
||||||
TEST(MemorySanitizer, pread) {
|
TEST(MemorySanitizer, pread) {
|
||||||
char *x = new char[32];
|
char *x = new char[32];
|
||||||
int fd = open("/proc/self/stat", O_RDONLY);
|
int fd = open(FILE_TO_READ, O_RDONLY);
|
||||||
ASSERT_GT(fd, 0);
|
ASSERT_GT(fd, 0);
|
||||||
int sz = pread(fd, x, 32, 0);
|
int sz = pread(fd, x, 32, 0);
|
||||||
ASSERT_EQ(sz, 32);
|
ASSERT_EQ(sz, 32);
|
||||||
|
@ -607,7 +614,7 @@ TEST(MemorySanitizer, readv) {
|
||||||
iov[0].iov_len = 5;
|
iov[0].iov_len = 5;
|
||||||
iov[1].iov_base = buf + 10;
|
iov[1].iov_base = buf + 10;
|
||||||
iov[1].iov_len = 2000;
|
iov[1].iov_len = 2000;
|
||||||
int fd = open("/proc/self/stat", O_RDONLY);
|
int fd = open(FILE_TO_READ, O_RDONLY);
|
||||||
ASSERT_GT(fd, 0);
|
ASSERT_GT(fd, 0);
|
||||||
int sz = readv(fd, iov, 2);
|
int sz = readv(fd, iov, 2);
|
||||||
ASSERT_GE(sz, 0);
|
ASSERT_GE(sz, 0);
|
||||||
|
@ -631,7 +638,7 @@ TEST(MemorySanitizer, preadv) {
|
||||||
iov[0].iov_len = 5;
|
iov[0].iov_len = 5;
|
||||||
iov[1].iov_base = buf + 10;
|
iov[1].iov_base = buf + 10;
|
||||||
iov[1].iov_len = 2000;
|
iov[1].iov_len = 2000;
|
||||||
int fd = open("/proc/self/stat", O_RDONLY);
|
int fd = open(FILE_TO_READ, O_RDONLY);
|
||||||
ASSERT_GT(fd, 0);
|
ASSERT_GT(fd, 0);
|
||||||
int sz = preadv(fd, iov, 2, 3);
|
int sz = preadv(fd, iov, 2, 3);
|
||||||
ASSERT_GE(sz, 0);
|
ASSERT_GE(sz, 0);
|
||||||
|
@ -662,10 +669,9 @@ TEST(MemorySanitizer, readlink) {
|
||||||
delete [] x;
|
delete [] x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(MemorySanitizer, stat) {
|
TEST(MemorySanitizer, stat) {
|
||||||
struct stat* st = new struct stat;
|
struct stat* st = new struct stat;
|
||||||
int res = stat("/proc/self/stat", st);
|
int res = stat(FILE_TO_READ, st);
|
||||||
ASSERT_EQ(0, res);
|
ASSERT_EQ(0, res);
|
||||||
EXPECT_NOT_POISONED(st->st_dev);
|
EXPECT_NOT_POISONED(st->st_dev);
|
||||||
EXPECT_NOT_POISONED(st->st_mode);
|
EXPECT_NOT_POISONED(st->st_mode);
|
||||||
|
|
Loading…
Reference in New Issue