1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. |
2 | * |
3 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
4 | * of this software and associated documentation files (the "Software"), to |
5 | * deal in the Software without restriction, including without limitation the |
6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
7 | * sell copies of the Software, and to permit persons to whom the Software is |
8 | * furnished to do so, subject to the following conditions: |
9 | * |
10 | * The above copyright notice and this permission notice shall be included in |
11 | * all copies or substantial portions of the Software. |
12 | * |
13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
19 | * IN THE SOFTWARE. |
20 | */ |
21 | |
22 | #include "uv.h" |
23 | #include "task.h" |
24 | #include <string.h> |
25 | |
26 | |
27 | TEST_IMPL(platform_output) { |
28 | char buffer[512]; |
29 | size_t ; |
30 | size_t size; |
31 | double uptime; |
32 | uv_pid_t pid; |
33 | uv_pid_t ppid; |
34 | uv_rusage_t rusage; |
35 | uv_cpu_info_t* cpus; |
36 | uv_interface_address_t* interfaces; |
37 | uv_passwd_t pwd; |
38 | uv_utsname_t uname; |
39 | int count; |
40 | int i; |
41 | int err; |
42 | |
43 | err = uv_get_process_title(buffer, sizeof(buffer)); |
44 | ASSERT(err == 0); |
45 | printf("uv_get_process_title: %s\n" , buffer); |
46 | |
47 | size = sizeof(buffer); |
48 | err = uv_cwd(buffer, &size); |
49 | ASSERT(err == 0); |
50 | printf("uv_cwd: %s\n" , buffer); |
51 | |
52 | err = uv_resident_set_memory(&rss); |
53 | #if defined(__MSYS__) |
54 | ASSERT(err == UV_ENOSYS); |
55 | #else |
56 | ASSERT(err == 0); |
57 | printf("uv_resident_set_memory: %llu\n" , (unsigned long long) rss); |
58 | #endif |
59 | |
60 | err = uv_uptime(&uptime); |
61 | ASSERT(err == 0); |
62 | ASSERT(uptime > 0); |
63 | printf("uv_uptime: %f\n" , uptime); |
64 | |
65 | err = uv_getrusage(&rusage); |
66 | ASSERT(err == 0); |
67 | ASSERT(rusage.ru_utime.tv_sec >= 0); |
68 | ASSERT(rusage.ru_utime.tv_usec >= 0); |
69 | ASSERT(rusage.ru_stime.tv_sec >= 0); |
70 | ASSERT(rusage.ru_stime.tv_usec >= 0); |
71 | printf("uv_getrusage:\n" ); |
72 | printf(" user: %llu sec %llu microsec\n" , |
73 | (unsigned long long) rusage.ru_utime.tv_sec, |
74 | (unsigned long long) rusage.ru_utime.tv_usec); |
75 | printf(" system: %llu sec %llu microsec\n" , |
76 | (unsigned long long) rusage.ru_stime.tv_sec, |
77 | (unsigned long long) rusage.ru_stime.tv_usec); |
78 | printf(" page faults: %llu\n" , (unsigned long long) rusage.ru_majflt); |
79 | printf(" maximum resident set size: %llu\n" , |
80 | (unsigned long long) rusage.ru_maxrss); |
81 | |
82 | err = uv_cpu_info(&cpus, &count); |
83 | #if defined(__CYGWIN__) || defined(__MSYS__) |
84 | ASSERT(err == UV_ENOSYS); |
85 | #else |
86 | ASSERT(err == 0); |
87 | |
88 | printf("uv_cpu_info:\n" ); |
89 | for (i = 0; i < count; i++) { |
90 | printf(" model: %s\n" , cpus[i].model); |
91 | printf(" speed: %d\n" , cpus[i].speed); |
92 | printf(" times.sys: %llu\n" , (unsigned long long) cpus[i].cpu_times.sys); |
93 | printf(" times.user: %llu\n" , |
94 | (unsigned long long) cpus[i].cpu_times.user); |
95 | printf(" times.idle: %llu\n" , |
96 | (unsigned long long) cpus[i].cpu_times.idle); |
97 | printf(" times.irq: %llu\n" , (unsigned long long) cpus[i].cpu_times.irq); |
98 | printf(" times.nice: %llu\n" , |
99 | (unsigned long long) cpus[i].cpu_times.nice); |
100 | } |
101 | #endif |
102 | uv_free_cpu_info(cpus, count); |
103 | |
104 | err = uv_interface_addresses(&interfaces, &count); |
105 | ASSERT(err == 0); |
106 | |
107 | printf("uv_interface_addresses:\n" ); |
108 | for (i = 0; i < count; i++) { |
109 | printf(" name: %s\n" , interfaces[i].name); |
110 | printf(" internal: %d\n" , interfaces[i].is_internal); |
111 | printf(" physical address: " ); |
112 | printf("%02x:%02x:%02x:%02x:%02x:%02x\n" , |
113 | (unsigned char)interfaces[i].phys_addr[0], |
114 | (unsigned char)interfaces[i].phys_addr[1], |
115 | (unsigned char)interfaces[i].phys_addr[2], |
116 | (unsigned char)interfaces[i].phys_addr[3], |
117 | (unsigned char)interfaces[i].phys_addr[4], |
118 | (unsigned char)interfaces[i].phys_addr[5]); |
119 | |
120 | if (interfaces[i].address.address4.sin_family == AF_INET) { |
121 | uv_ip4_name(&interfaces[i].address.address4, buffer, sizeof(buffer)); |
122 | } else if (interfaces[i].address.address4.sin_family == AF_INET6) { |
123 | uv_ip6_name(&interfaces[i].address.address6, buffer, sizeof(buffer)); |
124 | } |
125 | |
126 | printf(" address: %s\n" , buffer); |
127 | |
128 | if (interfaces[i].netmask.netmask4.sin_family == AF_INET) { |
129 | uv_ip4_name(&interfaces[i].netmask.netmask4, buffer, sizeof(buffer)); |
130 | printf(" netmask: %s\n" , buffer); |
131 | } else if (interfaces[i].netmask.netmask4.sin_family == AF_INET6) { |
132 | uv_ip6_name(&interfaces[i].netmask.netmask6, buffer, sizeof(buffer)); |
133 | printf(" netmask: %s\n" , buffer); |
134 | } else { |
135 | printf(" netmask: none\n" ); |
136 | } |
137 | } |
138 | uv_free_interface_addresses(interfaces, count); |
139 | |
140 | err = uv_os_get_passwd(&pwd); |
141 | ASSERT(err == 0); |
142 | |
143 | printf("uv_os_get_passwd:\n" ); |
144 | printf(" euid: %ld\n" , pwd.uid); |
145 | printf(" gid: %ld\n" , pwd.gid); |
146 | printf(" username: %s\n" , pwd.username); |
147 | printf(" shell: %s\n" , pwd.shell); |
148 | printf(" home directory: %s\n" , pwd.homedir); |
149 | |
150 | pid = uv_os_getpid(); |
151 | ASSERT(pid > 0); |
152 | printf("uv_os_getpid: %d\n" , (int) pid); |
153 | ppid = uv_os_getppid(); |
154 | ASSERT(ppid > 0); |
155 | printf("uv_os_getppid: %d\n" , (int) ppid); |
156 | |
157 | err = uv_os_uname(&uname); |
158 | ASSERT(err == 0); |
159 | printf("uv_os_uname:\n" ); |
160 | printf(" sysname: %s\n" , uname.sysname); |
161 | printf(" release: %s\n" , uname.release); |
162 | printf(" version: %s\n" , uname.version); |
163 | printf(" machine: %s\n" , uname.machine); |
164 | |
165 | return 0; |
166 | } |
167 | |