diff options
Diffstat (limited to 'test/sanitizer_common/TestCases/Linux')
9 files changed, 261 insertions, 0 deletions
diff --git a/test/sanitizer_common/TestCases/Linux/aligned_alloc.c b/test/sanitizer_common/TestCases/Linux/aligned_alloc.c new file mode 100644 index 000000000000..12af18dd32a1 --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/aligned_alloc.c @@ -0,0 +1,8 @@ +// RUN: %clang -std=c11 -O0 %s -o %t && %run %t +#include <stdlib.h> +extern void *aligned_alloc (size_t alignment, size_t size); +int main() { + volatile void *p = aligned_alloc(128, 1024); + free((void*)p); + return 0; +} diff --git a/test/sanitizer_common/TestCases/Linux/clock_gettime.c b/test/sanitizer_common/TestCases/Linux/clock_gettime.c new file mode 100644 index 000000000000..ec1386ef2414 --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/clock_gettime.c @@ -0,0 +1,11 @@ +// RUN: %clang %s -Wl,-as-needed -o %t && %run %t +// Regression test for PR15823 +// (http://llvm.org/bugs/show_bug.cgi?id=15823). +#include <stdio.h> +#include <time.h> + +int main() { + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + return 0; +} diff --git a/test/sanitizer_common/TestCases/Linux/getpass.cc b/test/sanitizer_common/TestCases/Linux/getpass.cc new file mode 100644 index 000000000000..c9a2276cc248 --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/getpass.cc @@ -0,0 +1,32 @@ +// RUN: %clangxx -O0 -g %s -lutil -o %t && %run %t | FileCheck %s +#include <assert.h> +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <pty.h> + +int +main (int argc, char** argv) +{ + int master; + int pid = forkpty(&master, NULL, NULL, NULL); + + if(pid == -1) { + fprintf(stderr, "forkpty failed\n"); + return 1; + } else if (pid > 0) { + char buf[1024]; + int res = read(master, buf, sizeof(buf)); + write(1, buf, res); + write(master, "password\n", 9); + while ((res = read(master, buf, sizeof(buf))) > 0) write(1, buf, res); + } else { + char *s = getpass("prompt"); + assert(strcmp(s, "password") == 0); + write(1, "done\n", 5); + } + return 0; +} + +// CHECK: prompt +// CHECK: done diff --git a/test/sanitizer_common/TestCases/Linux/getpwnam_r_invalid_user.cc b/test/sanitizer_common/TestCases/Linux/getpwnam_r_invalid_user.cc new file mode 100644 index 000000000000..a8b51d7a99c0 --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/getpwnam_r_invalid_user.cc @@ -0,0 +1,19 @@ +// Regression test for a crash in getpwnam_r and similar interceptors. +// RUN: %clangxx -O0 -g %s -o %t && %run %t + +#include <assert.h> +#include <pwd.h> +#include <signal.h> +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> + +int main(void) { + struct passwd pwd; + struct passwd *pwdres; + char buf[10000]; + int res = getpwnam_r("no-such-user", &pwd, buf, sizeof(buf), &pwdres); + assert(res == 0); + assert(pwdres == 0); + return 0; +} diff --git a/test/sanitizer_common/TestCases/Linux/lit.local.cfg b/test/sanitizer_common/TestCases/Linux/lit.local.cfg new file mode 100644 index 000000000000..57271b8078a4 --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/lit.local.cfg @@ -0,0 +1,9 @@ +def getRoot(config): + if not config.parent: + return config + return getRoot(config.parent) + +root = getRoot(config) + +if root.host_os not in ['Linux']: + config.unsupported = True diff --git a/test/sanitizer_common/TestCases/Linux/mlock_test.cc b/test/sanitizer_common/TestCases/Linux/mlock_test.cc new file mode 100644 index 000000000000..69ea7cb91c4f --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/mlock_test.cc @@ -0,0 +1,13 @@ +// RUN: %clang %s -o %t && %run %t +// XFAIL: lsan + +#include <assert.h> +#include <sys/mman.h> + +int main() { + assert(0 == mlockall(MCL_CURRENT)); + assert(0 == mlock((void *)0x12345, 0x5678)); + assert(0 == munlockall()); + assert(0 == munlock((void *)0x987, 0x654)); +} + diff --git a/test/sanitizer_common/TestCases/Linux/open_memstream.cc b/test/sanitizer_common/TestCases/Linux/open_memstream.cc new file mode 100644 index 000000000000..6abe0bfb1483 --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/open_memstream.cc @@ -0,0 +1,57 @@ +// RUN: %clangxx -m64 -O0 -g -xc++ %s -o %t && %run %t +// RUN: %clangxx -m64 -O3 -g -xc++ %s -o %t && %run %t + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#ifndef __has_feature +#define __has_feature(x) 0 +#endif + +#if __has_feature(memory_sanitizer) +#include <sanitizer/msan_interface.h> +static void check_mem_is_good(void *p, size_t s) { + __msan_check_mem_is_initialized(p, s); +} +#elif __has_feature(address_sanitizer) +#include <sanitizer/asan_interface.h> +static void check_mem_is_good(void *p, size_t s) { + assert(__asan_region_is_poisoned(p, s) == 0); +} +#else +static void check_mem_is_good(void *p, size_t s) {} +#endif + +static void run(void) { + char *buf; + size_t buf_len; + fprintf(stderr, " &buf %p, &buf_len %p\n", &buf, &buf_len); + FILE *fp = open_memstream(&buf, &buf_len); + fprintf(fp, "hello"); + fflush(fp); + check_mem_is_good(&buf, sizeof(buf)); + check_mem_is_good(&buf_len, sizeof(buf_len)); + check_mem_is_good(buf, buf_len); + + char *p = new char[1024]; + memset(p, 'a', 1023); + p[1023] = 0; + for (int i = 0; i < 100; ++i) + fprintf(fp, "%s", p); + delete[] p; + fflush(fp); + fprintf(stderr, " %p addr %p, len %zu\n", &buf, buf, buf_len); + check_mem_is_good(&buf, sizeof(buf)); + check_mem_is_good(&buf_len, sizeof(buf_len)); + check_mem_is_good(buf, buf_len); + fclose(fp); + free(buf); +} + +int main(void) { + for (int i = 0; i < 100; ++i) + run(); + return 0; +} diff --git a/test/sanitizer_common/TestCases/Linux/ptrace.cc b/test/sanitizer_common/TestCases/Linux/ptrace.cc new file mode 100644 index 000000000000..2bf0fd2f0f35 --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/ptrace.cc @@ -0,0 +1,60 @@ +// RUN: %clangxx -O0 %s -o %t && %run %t + +#include <assert.h> +#include <signal.h> +#include <stdio.h> +#include <sys/ptrace.h> +#include <sys/types.h> +#include <sys/user.h> +#include <sys/wait.h> +#include <unistd.h> + +int main(void) { + pid_t pid; + pid = fork(); + if (pid == 0) { // child + ptrace(PTRACE_TRACEME, 0, NULL, NULL); + execl("/bin/true", "true", NULL); + } else { + wait(NULL); + int res; + +#if __x86_64__ + user_regs_struct regs; + res = ptrace(PTRACE_GETREGS, pid, NULL, ®s); + assert(!res); + if (regs.rip) + printf("%zx\n", regs.rip); + + user_fpregs_struct fpregs; + res = ptrace(PTRACE_GETFPREGS, pid, NULL, &fpregs); + assert(!res); + if (fpregs.mxcsr) + printf("%x\n", fpregs.mxcsr); +#endif // __x86_64__ + +#if __powerpc64__ + struct pt_regs regs; + res = ptrace((enum __ptrace_request)PTRACE_GETREGS, pid, NULL, ®s); + assert(!res); + if (regs.nip) + printf("%lx\n", regs.nip); + + elf_fpregset_t fpregs; + res = ptrace((enum __ptrace_request)PTRACE_GETFPREGS, pid, NULL, &fpregs); + assert(!res); + if ((elf_greg_t)fpregs[32]) // fpscr + printf("%lx\n", (elf_greg_t)fpregs[32]); +#endif // __powerpc64__ + + siginfo_t siginfo; + res = ptrace(PTRACE_GETSIGINFO, pid, NULL, &siginfo); + assert(!res); + assert(siginfo.si_pid == pid); + + ptrace(PTRACE_CONT, pid, NULL, NULL); + + wait(NULL); + } + return 0; +} diff --git a/test/sanitizer_common/TestCases/Linux/timerfd.cc b/test/sanitizer_common/TestCases/Linux/timerfd.cc new file mode 100644 index 000000000000..e7613bb1d111 --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/timerfd.cc @@ -0,0 +1,52 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t | FileCheck %s +#include <assert.h> +#include <stdio.h> +#include <string.h> +#include <time.h> +#include <sys/timerfd.h> +#include <unistd.h> + +int main (int argc, char** argv) +{ + int fd = timerfd_create(CLOCK_REALTIME, 0); + assert(fd >= 0); + + struct itimerspec its; + its.it_value.tv_sec = 0; + its.it_value.tv_nsec = 1000000; + its.it_interval.tv_sec = its.it_value.tv_sec; + its.it_interval.tv_nsec = its.it_value.tv_nsec; + + int res = timerfd_settime(fd, 0, &its, NULL); + assert(res != -1); + + struct itimerspec its2; + res = timerfd_settime(fd, 0, &its, &its2); + assert(res != -1); + assert(its2.it_interval.tv_sec == its.it_interval.tv_sec); + assert(its2.it_interval.tv_nsec == its.it_interval.tv_nsec); + assert(its2.it_value.tv_sec <= its.it_value.tv_sec); + assert(its2.it_value.tv_nsec <= its.it_value.tv_nsec); + + struct itimerspec its3; + res = timerfd_gettime(fd, &its3); + assert(res != -1); + assert(its3.it_interval.tv_sec == its.it_interval.tv_sec); + assert(its3.it_interval.tv_nsec == its.it_interval.tv_nsec); + assert(its3.it_value.tv_sec <= its.it_value.tv_sec); + assert(its3.it_value.tv_nsec <= its.it_value.tv_nsec); + + + unsigned long long buf; + res = read(fd, &buf, sizeof(buf)); + assert(res == 8); + assert(buf >= 1); + + res = close(fd); + assert(res != -1); + + printf("DONE\n"); + // CHECK: DONE + + return 0; +} |
