Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / sanitizer_common / TestCases / FreeBSD / capsicum.cpp
blob1bfb6f8d945c9b7e1602ae0199a516eee7072b8a
1 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
3 #include <sys/capsicum.h>
4 #include <sys/ioctl.h>
6 #include <assert.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <termios.h>
11 #include <unistd.h>
13 void test_cap_ioctls() {
14 cap_rights_t rights;
15 unsigned long ncmds[] = {TIOCGETA, TIOCGWINSZ, FIODTYPE};
16 unsigned long rcmds = 0;
17 cap_rights_t *rptr = cap_rights_init(&rights, CAP_IOCTL, CAP_READ);
18 assert(rptr);
20 int rv = cap_rights_limit(STDIN_FILENO, &rights);
21 assert(rv == 0);
22 rv = cap_ioctls_limit(STDIN_FILENO, ncmds, 3);
23 assert(rv == 0);
24 ssize_t rz = cap_ioctls_get(STDIN_FILENO, &rcmds, 3);
25 assert(rz == 3);
26 printf("ioctls test: %ld commands authorized\n", rz);
29 void test_cap_rights() {
30 cap_rights_t rights, little, remove, grights;
31 cap_rights_t *rptr = cap_rights_init(&rights, CAP_IOCTL, CAP_READ);
32 assert(rptr);
33 cap_rights_t *gptr = cap_rights_init(&remove, CAP_IOCTL);
34 assert(gptr);
35 cap_rights_t *sptr = cap_rights_init(&little, CAP_READ);
36 assert(sptr);
37 bool hasit = cap_rights_contains(rptr, sptr);
38 assert(hasit == true);
39 cap_rights_t *pptr = cap_rights_remove(&rights, gptr);
40 hasit = cap_rights_contains(pptr, sptr);
41 assert(hasit == true);
42 cap_rights_t *aptr = cap_rights_merge(&rights, gptr);
43 assert(aptr);
44 bool correct = cap_rights_is_valid(&rights);
45 assert(correct == true);
47 int rv = cap_rights_limit(STDIN_FILENO, &rights);
48 assert(rv == 0);
49 rv = cap_rights_get(STDIN_FILENO, &grights);
50 assert(rv == 0);
51 assert(memcmp(&grights, &rights, sizeof(grights)) == 0);
52 cap_rights_t *iptr = cap_rights_set(&rights, CAP_IOCTL);
53 assert(iptr);
54 cap_rights_t *eptr = cap_rights_clear(&rights, CAP_READ);
55 assert(eptr);
56 hasit = cap_rights_is_set(&rights, CAP_IOCTL);
57 assert(hasit == true);
58 printf("rights test: %d\n", rv);
61 int main(void) {
62 test_cap_ioctls();
64 test_cap_rights();
66 // CHECK: ioctls test: {{.*}} commands authorized
67 // CHECK: rights test: {{.*}}