main.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. // C++ API tests
  43. try {
  44. cout << endl << "*** Running WebRTC connectivity test..." << endl;
  45. test_connectivity();
  46. cout << "*** Finished WebRTC connectivity test" << endl;
  47. } catch (const exception &e) {
  48. cerr << "WebRTC connectivity test failed: " << e.what() << endl;
  49. return -1;
  50. }
  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. #if RTC_ENABLE_MEDIA
  60. try {
  61. cout << endl << "*** Running WebRTC Track test..." << endl;
  62. test_track();
  63. cout << "*** Finished WebRTC Track test" << endl;
  64. } catch (const exception &e) {
  65. cerr << "WebRTC Track test failed: " << e.what() << endl;
  66. return -1;
  67. }
  68. #endif
  69. #if RTC_ENABLE_WEBSOCKET
  70. // TODO: Temporarily disabled as the echo service is unreliable
  71. /*
  72. try {
  73. cout << endl << "*** Running WebSocket test..." << endl;
  74. test_websocket();
  75. cout << "*** Finished WebSocket test" << endl;
  76. } catch (const exception &e) {
  77. cerr << "WebSocket test failed: " << e.what() << endl;
  78. return -1;
  79. }
  80. */
  81. try {
  82. cout << endl << "*** Running WebSocketServer test..." << endl;
  83. test_websocketserver();
  84. cout << "*** Finished WebSocketServer test" << endl;
  85. } catch (const exception &e) {
  86. cerr << "WebSocketServer test failed: " << e.what() << endl;
  87. return -1;
  88. }
  89. #endif
  90. try {
  91. // Every created object must have been destroyed, otherwise the wait will block
  92. cout << endl << "*** Running cleanup..." << endl;
  93. if(rtc::Cleanup().wait_for(10s) == future_status::timeout)
  94. throw std::runtime_error("Timeout");
  95. cout << "*** Finished cleanup..." << endl;
  96. } catch (const exception &e) {
  97. cerr << "Cleanup failed: " << e.what() << endl;
  98. return -1;
  99. }
  100. // C API tests
  101. try {
  102. cout << endl << "*** Running WebRTC C API connectivity test..." << endl;
  103. test_capi_connectivity();
  104. cout << "*** Finished WebRTC C API connectivity test" << endl;
  105. } catch (const exception &e) {
  106. cerr << "WebRTC C API connectivity test failed: " << e.what() << endl;
  107. return -1;
  108. }
  109. #if RTC_ENABLE_MEDIA
  110. try {
  111. cout << endl << "*** Running WebRTC C API track test..." << endl;
  112. test_capi_track();
  113. cout << "*** Finished WebRTC C API track test" << endl;
  114. } catch (const exception &e) {
  115. cerr << "WebRTC C API track test failed: " << e.what() << endl;
  116. return -1;
  117. }
  118. #endif
  119. #if RTC_ENABLE_WEBSOCKET
  120. try {
  121. cout << endl << "*** Running WebSocketServer C API test..." << endl;
  122. test_capi_websocketserver();
  123. cout << "*** Finished WebSocketServer C API test" << endl;
  124. } catch (const exception &e) {
  125. cerr << "WebSocketServer C API test failed: " << e.what() << endl;
  126. return -1;
  127. }
  128. #endif
  129. try {
  130. cout << endl << "*** Running C API cleanup..." << endl;
  131. rtcCleanup();
  132. cout << "*** Finished C API cleanup..." << endl;
  133. } catch (const exception &e) {
  134. cerr << "C API cleanup failed: " << e.what() << endl;
  135. return -1;
  136. }
  137. /*
  138. // Benchmark
  139. try {
  140. cout << endl << "*** Running WebRTC benchmark..." << endl;
  141. test_benchmark();
  142. cout << "*** Finished WebRTC benchmark" << endl;
  143. } catch (const exception &e) {
  144. cerr << "WebRTC benchmark failed: " << e.what() << endl;
  145. std::this_thread::sleep_for(2s);
  146. return -1;
  147. }
  148. */
  149. return 0;
  150. }