• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
TEST_IMPL(platform_output)27 TEST_IMPL(platform_output) {
28 /* TODO(gengjiawen): Fix test on QEMU. */
29 #if defined(__QEMU__)
30   RETURN_SKIP("Test does not currently work in QEMU");
31 #endif
32 
33   char buffer[512];
34   size_t rss;
35   size_t size;
36   double uptime;
37   uv_pid_t pid;
38   uv_pid_t ppid;
39   uv_rusage_t rusage;
40   uv_cpu_info_t* cpus;
41   uv_interface_address_t* interfaces;
42   uv_passwd_t pwd;
43   uv_utsname_t uname;
44   unsigned par;
45   int count;
46   int i;
47   int err;
48 
49   err = uv_get_process_title(buffer, sizeof(buffer));
50   ASSERT(err == 0);
51   printf("uv_get_process_title: %s\n", buffer);
52 
53   size = sizeof(buffer);
54   err = uv_cwd(buffer, &size);
55   ASSERT(err == 0);
56   printf("uv_cwd: %s\n", buffer);
57 
58   err = uv_resident_set_memory(&rss);
59 #if defined(__MSYS__)
60   ASSERT(err == UV_ENOSYS);
61 #else
62   ASSERT(err == 0);
63   printf("uv_resident_set_memory: %llu\n", (unsigned long long) rss);
64 #endif
65 
66   err = uv_uptime(&uptime);
67 #if defined(__PASE__)
68   ASSERT(err == UV_ENOSYS);
69 #else
70   ASSERT(err == 0);
71   ASSERT(uptime > 0);
72   printf("uv_uptime: %f\n", uptime);
73 #endif
74 
75   err = uv_getrusage(&rusage);
76   ASSERT(err == 0);
77   ASSERT(rusage.ru_utime.tv_sec >= 0);
78   ASSERT(rusage.ru_utime.tv_usec >= 0);
79   ASSERT(rusage.ru_stime.tv_sec >= 0);
80   ASSERT(rusage.ru_stime.tv_usec >= 0);
81   printf("uv_getrusage:\n");
82   printf("  user: %llu sec %llu microsec\n",
83          (unsigned long long) rusage.ru_utime.tv_sec,
84          (unsigned long long) rusage.ru_utime.tv_usec);
85   printf("  system: %llu sec %llu microsec\n",
86          (unsigned long long) rusage.ru_stime.tv_sec,
87          (unsigned long long) rusage.ru_stime.tv_usec);
88   printf("  page faults: %llu\n", (unsigned long long) rusage.ru_majflt);
89   printf("  maximum resident set size: %llu\n",
90          (unsigned long long) rusage.ru_maxrss);
91 
92   par = uv_available_parallelism();
93   ASSERT_GE(par, 1);
94   printf("uv_available_parallelism: %u\n", par);
95 
96   err = uv_cpu_info(&cpus, &count);
97 #if defined(__CYGWIN__) || defined(__MSYS__)
98   ASSERT(err == UV_ENOSYS);
99 #else
100   ASSERT(err == 0);
101 
102   printf("uv_cpu_info:\n");
103   for (i = 0; i < count; i++) {
104     printf("  model: %s\n", cpus[i].model);
105     printf("  speed: %d\n", cpus[i].speed);
106     printf("  times.sys: %llu\n", (unsigned long long) cpus[i].cpu_times.sys);
107     printf("  times.user: %llu\n",
108            (unsigned long long) cpus[i].cpu_times.user);
109     printf("  times.idle: %llu\n",
110            (unsigned long long) cpus[i].cpu_times.idle);
111     printf("  times.irq: %llu\n",  (unsigned long long) cpus[i].cpu_times.irq);
112     printf("  times.nice: %llu\n",
113            (unsigned long long) cpus[i].cpu_times.nice);
114   }
115 #endif
116   uv_free_cpu_info(cpus, count);
117 
118   err = uv_interface_addresses(&interfaces, &count);
119   ASSERT(err == 0);
120 
121   printf("uv_interface_addresses:\n");
122   for (i = 0; i < count; i++) {
123     printf("  name: %s\n", interfaces[i].name);
124     printf("  internal: %d\n", interfaces[i].is_internal);
125     printf("  physical address: ");
126     printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
127            (unsigned char)interfaces[i].phys_addr[0],
128            (unsigned char)interfaces[i].phys_addr[1],
129            (unsigned char)interfaces[i].phys_addr[2],
130            (unsigned char)interfaces[i].phys_addr[3],
131            (unsigned char)interfaces[i].phys_addr[4],
132            (unsigned char)interfaces[i].phys_addr[5]);
133 
134     if (interfaces[i].address.address4.sin_family == AF_INET) {
135       uv_ip4_name(&interfaces[i].address.address4, buffer, sizeof(buffer));
136     } else if (interfaces[i].address.address4.sin_family == AF_INET6) {
137       uv_ip6_name(&interfaces[i].address.address6, buffer, sizeof(buffer));
138     }
139 
140     printf("  address: %s\n", buffer);
141 
142     if (interfaces[i].netmask.netmask4.sin_family == AF_INET) {
143       uv_ip4_name(&interfaces[i].netmask.netmask4, buffer, sizeof(buffer));
144       printf("  netmask: %s\n", buffer);
145     } else if (interfaces[i].netmask.netmask4.sin_family == AF_INET6) {
146       uv_ip6_name(&interfaces[i].netmask.netmask6, buffer, sizeof(buffer));
147       printf("  netmask: %s\n", buffer);
148     } else {
149       printf("  netmask: none\n");
150     }
151   }
152   uv_free_interface_addresses(interfaces, count);
153 
154   err = uv_os_get_passwd(&pwd);
155   ASSERT(err == 0);
156 
157   printf("uv_os_get_passwd:\n");
158   printf("  euid: %ld\n", pwd.uid);
159   printf("  gid: %ld\n", pwd.gid);
160   printf("  username: %s\n", pwd.username);
161   printf("  shell: %s\n", pwd.shell);
162   printf("  home directory: %s\n", pwd.homedir);
163   uv_os_free_passwd(&pwd);
164 
165   pid = uv_os_getpid();
166   ASSERT(pid > 0);
167   printf("uv_os_getpid: %d\n", (int) pid);
168   ppid = uv_os_getppid();
169   ASSERT(ppid > 0);
170   printf("uv_os_getppid: %d\n", (int) ppid);
171 
172   err = uv_os_uname(&uname);
173   ASSERT(err == 0);
174   printf("uv_os_uname:\n");
175   printf("  sysname: %s\n", uname.sysname);
176   printf("  release: %s\n", uname.release);
177   printf("  version: %s\n", uname.version);
178   printf("  machine: %s\n", uname.machine);
179 
180   return 0;
181 }
182