2
0

main.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * Copyright (c) 2019 Paul-Louis Ageneau
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <chrono>
  19. #include <iostream>
  20. #include <thread>
  21. #include <rtc/rtc.hpp>
  22. using namespace std;
  23. using namespace chrono_literals;
  24. void test_connectivity();
  25. void test_turn_connectivity();
  26. void test_track();
  27. void test_capi_connectivity();
  28. void test_capi_track();
  29. void test_websocket();
  30. void test_websocketserver();
  31. void test_capi_websocketserver();
  32. size_t benchmark(chrono::milliseconds duration);
  33. void test_benchmark() {
  34. size_t goodput = benchmark(10s);
  35. if (goodput == 0)
  36. throw runtime_error("No data received");
  37. const size_t threshold = 1000; // 1 MB/s;
  38. if (goodput < threshold)
  39. throw runtime_error("Goodput is too low");
  40. }
  41. int main(int argc, char **argv) {
  42. try {
  43. cout << endl << "*** Running WebRTC connectivity test..." << endl;
  44. test_connectivity();
  45. cout << "*** Finished WebRTC connectivity test" << endl;
  46. } catch (const exception &e) {
  47. cerr << "WebRTC connectivity test failed: " << e.what() << endl;
  48. return -1;
  49. }
  50. this_thread::sleep_for(1s);
  51. try {
  52. cout << endl << "*** Running WebRTC TURN connectivity test..." << endl;
  53. test_turn_connectivity();
  54. cout << "*** Finished WebRTC TURN connectivity test" << endl;
  55. } catch (const exception &e) {
  56. cerr << "WebRTC TURN connectivity test failed: " << e.what() << endl;
  57. return -1;
  58. }
  59. this_thread::sleep_for(1s);
  60. try {
  61. cout << endl << "*** Running WebRTC C API connectivity test..." << endl;
  62. test_capi_connectivity();
  63. cout << "*** Finished WebRTC C API connectivity test" << endl;
  64. } catch (const exception &e) {
  65. cerr << "WebRTC C API connectivity test failed: " << e.what() << endl;
  66. return -1;
  67. }
  68. #if RTC_ENABLE_MEDIA
  69. this_thread::sleep_for(1s);
  70. try {
  71. cout << endl << "*** Running WebRTC Track test..." << endl;
  72. test_track();
  73. cout << "*** Finished WebRTC Track test" << endl;
  74. } catch (const exception &e) {
  75. cerr << "WebRTC Track test failed: " << e.what() << endl;
  76. return -1;
  77. }
  78. try {
  79. cout << endl << "*** Running WebRTC C API track test..." << endl;
  80. test_capi_track();
  81. cout << "*** Finished WebRTC C API track test" << endl;
  82. } catch (const exception &e) {
  83. cerr << "WebRTC C API track test failed: " << e.what() << endl;
  84. return -1;
  85. }
  86. #endif
  87. #if RTC_ENABLE_WEBSOCKET
  88. // TODO: Temporarily disabled as the echo service is unreliable
  89. /*
  90. this_thread::sleep_for(1s);
  91. try {
  92. cout << endl << "*** Running WebSocket test..." << endl;
  93. test_websocket();
  94. cout << "*** Finished WebSocket test" << endl;
  95. } catch (const exception &e) {
  96. cerr << "WebSocket test failed: " << e.what() << endl;
  97. return -1;
  98. }
  99. */
  100. try {
  101. cout << endl << "*** Running WebSocketServer test..." << endl;
  102. test_websocketserver();
  103. cout << "*** Finished WebSocketServer test" << endl;
  104. } catch (const exception &e) {
  105. cerr << "WebSocketServer test failed: " << e.what() << endl;
  106. return -1;
  107. }
  108. try {
  109. cout << endl << "*** Running WebSocketServer C API test..." << endl;
  110. test_capi_websocketserver();
  111. cout << "*** Finished WebSocketServer C API test" << endl;
  112. } catch (const exception &e) {
  113. cerr << "WebSocketServer C API test failed: " << e.what() << endl;
  114. return -1;
  115. }
  116. #endif
  117. /*
  118. this_thread::sleep_for(1s);
  119. try {
  120. cout << endl << "*** Running WebRTC benchmark..." << endl;
  121. test_benchmark();
  122. cout << "*** Finished WebRTC benchmark" << endl;
  123. } catch (const exception &e) {
  124. cerr << "WebRTC benchmark failed: " << e.what() << endl;
  125. std::this_thread::sleep_for(2s);
  126. return -1;
  127. }
  128. */
  129. try {
  130. cout << endl << "*** Running cleanup..." << endl;
  131. if(rtc::Cleanup().wait_for(10s) == future_status::timeout)
  132. throw std::runtime_error("Timeout");
  133. } catch (const exception &e) {
  134. cerr << "Cleanup failed: " << e.what() << endl;
  135. return -1;
  136. }
  137. return 0;
  138. }