Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / sanitizer_common / TestCases / Posix / sysctl.cpp
blob38c34259bbae002562f16268dfd80784300e4345
1 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
2 //
3 // UNSUPPORTED: linux, target={{.*solaris.*}}
5 #include <sys/param.h>
6 #include <sys/types.h>
8 #include <sys/sysctl.h>
10 #include <assert.h>
11 #include <stdio.h>
12 #include <stdlib.h>
14 #ifndef __arraycount
15 #define __arraycount(a) (sizeof(a) / sizeof(a[0]))
16 #endif
18 void test_sysctl() {
19 char buf[100];
20 size_t len = sizeof(buf);
21 int mib[] = {CTL_KERN, KERN_OSTYPE};
22 int rv = sysctl(mib, __arraycount(mib), buf, &len, NULL, 0);
23 assert(!rv);
25 printf("sysctl: '%s' size: '%zu'\n", buf, len);
28 void test_sysctlbyname() {
29 char buf[100];
30 size_t len = sizeof(buf);
31 int rv = sysctlbyname("kern.ostype", buf, &len, NULL, 0);
32 assert(!rv);
34 printf("sysctlbyname: '%s' size: '%zu'\n", buf, len);
37 void test_sysctlnametomib() {
38 int mib[CTL_MAXNAME];
39 size_t mib_len = __arraycount(mib);
40 int rv = sysctlnametomib("kern.ostype", &mib[0], &mib_len);
41 assert(!rv);
43 char buf[100];
44 size_t len = sizeof(buf);
45 rv = sysctl(mib, mib_len, buf, &len, NULL, 0);
46 assert(!rv);
48 printf("sysctlnametomib: '%s' size: '%zu'\n", buf, len);
51 int main(void) {
52 printf("sysctl\n");
54 test_sysctl();
55 test_sysctlbyname();
56 test_sysctlnametomib();
58 // CHECK: sysctl
59 // CHECK: sysctl: '{{.*}}' size: '{{.*}}'
60 // CHECK: sysctlbyname: '{{.*}}' size: '{{.*}}'
61 // CHECK: sysctlnametomib: '{{.*}}' size: '{{.*}}'
63 return 0;