test-platform-output.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include "uv.h"
  22. #include "task.h"
  23. #include <string.h>
  24. TEST_IMPL(platform_output) {
  25. char buffer[512];
  26. size_t rss;
  27. double uptime;
  28. uv_cpu_info_t* cpus;
  29. uv_interface_address_t* interfaces;
  30. int count;
  31. int i;
  32. int err;
  33. err = uv_get_process_title(buffer, sizeof(buffer));
  34. ASSERT(err == 0);
  35. printf("uv_get_process_title: %s\n", buffer);
  36. err = uv_resident_set_memory(&rss);
  37. ASSERT(err == 0);
  38. printf("uv_resident_set_memory: %llu\n", (unsigned long long) rss);
  39. err = uv_uptime(&uptime);
  40. ASSERT(err == 0);
  41. ASSERT(uptime > 0);
  42. printf("uv_uptime: %f\n", uptime);
  43. err = uv_cpu_info(&cpus, &count);
  44. ASSERT(err == 0);
  45. printf("uv_cpu_info:\n");
  46. for (i = 0; i < count; i++) {
  47. printf(" model: %s\n", cpus[i].model);
  48. printf(" speed: %d\n", cpus[i].speed);
  49. printf(" times.sys: %llu\n", (unsigned long long) cpus[i].cpu_times.sys);
  50. printf(" times.user: %llu\n",
  51. (unsigned long long) cpus[i].cpu_times.user);
  52. printf(" times.idle: %llu\n",
  53. (unsigned long long) cpus[i].cpu_times.idle);
  54. printf(" times.irq: %llu\n", (unsigned long long) cpus[i].cpu_times.irq);
  55. printf(" times.nice: %llu\n",
  56. (unsigned long long) cpus[i].cpu_times.nice);
  57. }
  58. uv_free_cpu_info(cpus, count);
  59. err = uv_interface_addresses(&interfaces, &count);
  60. ASSERT(err == 0);
  61. printf("uv_interface_addresses:\n");
  62. for (i = 0; i < count; i++) {
  63. printf(" name: %s\n", interfaces[i].name);
  64. printf(" internal: %d\n", interfaces[i].is_internal);
  65. printf(" physical address: ");
  66. printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
  67. (unsigned char)interfaces[i].phys_addr[0],
  68. (unsigned char)interfaces[i].phys_addr[1],
  69. (unsigned char)interfaces[i].phys_addr[2],
  70. (unsigned char)interfaces[i].phys_addr[3],
  71. (unsigned char)interfaces[i].phys_addr[4],
  72. (unsigned char)interfaces[i].phys_addr[5]);
  73. if (interfaces[i].address.address4.sin_family == AF_INET) {
  74. uv_ip4_name(&interfaces[i].address.address4, buffer, sizeof(buffer));
  75. } else if (interfaces[i].address.address4.sin_family == AF_INET6) {
  76. uv_ip6_name(&interfaces[i].address.address6, buffer, sizeof(buffer));
  77. }
  78. printf(" address: %s\n", buffer);
  79. if (interfaces[i].netmask.netmask4.sin_family == AF_INET) {
  80. uv_ip4_name(&interfaces[i].netmask.netmask4, buffer, sizeof(buffer));
  81. } else if (interfaces[i].netmask.netmask4.sin_family == AF_INET6) {
  82. uv_ip6_name(&interfaces[i].netmask.netmask6, buffer, sizeof(buffer));
  83. }
  84. printf(" netmask: %s\n", buffer);
  85. }
  86. uv_free_interface_addresses(interfaces, count);
  87. return 0;
  88. }