forked from OSchip/llvm-project
[sanitizer_common] Rewrite more Posix tests to use asserts
Rewrite the tests for Posix functions that silently 'return 1' or 'exit(1)' on error, to instead verbosely report the error using assert. This is based on requests made in review of D56136. Differential Revision: https://reviews.llvm.org/D56149 llvm-svn: 350227
This commit is contained in:
parent
a3429b3981
commit
7341d0a92d
|
@ -1,6 +1,7 @@
|
|||
// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
|
||||
// UNSUPPORTED: linux, solaris
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -9,11 +10,8 @@ int main(void) {
|
|||
struct stat st;
|
||||
char *name;
|
||||
|
||||
if (stat("/dev/null", &st))
|
||||
exit(1);
|
||||
|
||||
if (!(name = devname(st.st_rdev, S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK)))
|
||||
exit(1);
|
||||
assert(!stat("/dev/null", &st));
|
||||
assert((name = devname(st.st_rdev, S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK)));
|
||||
|
||||
printf("%s\n", name);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <sys/cdefs.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -12,17 +13,14 @@ int main(void) {
|
|||
char name[100];
|
||||
mode_t type;
|
||||
|
||||
if (stat("/dev/null", &st))
|
||||
exit(1);
|
||||
assert(!stat("/dev/null", &st));
|
||||
|
||||
type = S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK;
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
if (devname_r(st.st_rdev, type, name, sizeof(name)))
|
||||
exit(1);
|
||||
assert(!devname_r(st.st_rdev, type, name, sizeof(name)));
|
||||
#else
|
||||
if (!devname_r(st.st_rdev, type, name, sizeof(name)))
|
||||
exit(1);
|
||||
assert(devname_r(st.st_rdev, type, name, sizeof(name)));
|
||||
#endif
|
||||
|
||||
printf("%s\n", name);
|
||||
|
|
|
@ -1,24 +1,20 @@
|
|||
// RUN: %clangxx -O0 -g %s -o %t && %run %t
|
||||
// UNSUPPORTED: linux
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
FILE *fp;
|
||||
FILE *fp = fopen("/etc/hosts", "r");
|
||||
assert(fp);
|
||||
|
||||
size_t len;
|
||||
char *s;
|
||||
|
||||
fp = fopen("/etc/hosts", "r");
|
||||
if (!fp)
|
||||
exit(1);
|
||||
|
||||
s = fgetln(fp, &len);
|
||||
char *s = fgetln(fp, &len);
|
||||
|
||||
printf("%.*s\n", (int)len, s);
|
||||
|
||||
if (fclose(fp) == EOF)
|
||||
exit(1);
|
||||
assert(!fclose(fp));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
// RUN: %clangxx -g %s -o %t && %run %t
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
FILE *fp;
|
||||
FILE *fp = fopen(argv[0], "r");
|
||||
assert(fp);
|
||||
|
||||
char buf[2];
|
||||
char *s;
|
||||
char *s = fgets(buf, sizeof(buf), fp);
|
||||
assert(s);
|
||||
|
||||
fp = fopen(argv[0], "r");
|
||||
if (!fp)
|
||||
return 1;
|
||||
|
||||
s = fgets(buf, sizeof(buf), fp);
|
||||
if (!s)
|
||||
return 2;
|
||||
|
||||
fclose(fp);
|
||||
assert(!fclose(fp));
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,18 +1,12 @@
|
|||
// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
|
||||
// CHECK: {{^foobar$}}
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int r;
|
||||
|
||||
r = fputs("foo", stdout);
|
||||
if (r < 0)
|
||||
return 1;
|
||||
|
||||
r = puts("bar");
|
||||
if (r < 0)
|
||||
return 1;
|
||||
assert(fputs("foo", stdout) >= 0);
|
||||
assert(puts("bar") >= 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
// RUN: %clangxx -O0 -g %s -o %t && %run %t
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
int main(void) {
|
||||
struct stat st;
|
||||
|
||||
if (lstat("/dev/null", &st))
|
||||
exit(1);
|
||||
|
||||
if (!S_ISCHR(st.st_mode))
|
||||
exit(1);
|
||||
assert(!lstat("/dev/null", &st));
|
||||
assert(S_ISCHR(st.st_mode));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue