main.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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_negotiated();
  25. void test_connectivity();
  26. void test_turn_connectivity();
  27. void test_track();
  28. void test_capi_connectivity();
  29. void test_capi_track();
  30. void test_websocket();
  31. void test_websocketserver();
  32. void test_capi_websocketserver();
  33. size_t benchmark(chrono::milliseconds duration);
  34. void test_benchmark() {
  35. size_t goodput = benchmark(10s);
  36. if (goodput == 0)
  37. throw runtime_error("No data received");
  38. const size_t threshold = 1000; // 1 MB/s;
  39. if (goodput < threshold)
  40. throw runtime_error("Goodput is too low");
  41. }
  42. int main(int argc, char **argv) {
  43. // C++ API tests
  44. try {
  45. cout << endl << "*** Running WebRTC connectivity test..." << endl;
  46. test_connectivity();
  47. cout << "*** Finished WebRTC connectivity test" << endl;
  48. } catch (const exception &e) {
  49. cerr << "WebRTC connectivity test failed: " << e.what() << endl;
  50. return -1;
  51. }
  52. try {
  53. cout << endl << "*** Running WebRTC TURN connectivity test..." << endl;
  54. test_turn_connectivity();
  55. cout << "*** Finished WebRTC TURN connectivity test" << endl;
  56. } catch (const exception &e) {
  57. cerr << "WebRTC TURN connectivity test failed: " << e.what() << endl;
  58. return -1;
  59. }
  60. try {
  61. cout << endl << "*** Running WebRTC negotiated DataChannel test..." << endl;
  62. test_negotiated();
  63. cout << "*** Finished WebRTC negotiated DataChannel test" << endl;
  64. } catch (const exception &e) {
  65. cerr << "WebRTC negotiated DataChannel test failed: " << e.what() << endl;
  66. return -1;
  67. }
  68. #if RTC_ENABLE_MEDIA
  69. try {
  70. cout << endl << "*** Running WebRTC Track test..." << endl;
  71. test_track();
  72. cout << "*** Finished WebRTC Track test" << endl;
  73. } catch (const exception &e) {
  74. cerr << "WebRTC Track test failed: " << e.what() << endl;
  75. return -1;
  76. }
  77. #endif
  78. #if RTC_ENABLE_WEBSOCKET
  79. // TODO: Temporarily disabled as the echo service is unreliable
  80. /*
  81. try {
  82. cout << endl << "*** Running WebSocket test..." << endl;
  83. test_websocket();
  84. cout << "*** Finished WebSocket test" << endl;
  85. } catch (const exception &e) {
  86. cerr << "WebSocket test failed: " << e.what() << endl;
  87. return -1;
  88. }
  89. */
  90. try {
  91. cout << endl << "*** Running WebSocketServer test..." << endl;
  92. test_websocketserver();
  93. cout << "*** Finished WebSocketServer test" << endl;
  94. } catch (const exception &e) {
  95. cerr << "WebSocketServer test failed: " << e.what() << endl;
  96. return -1;
  97. }
  98. #endif
  99. try {
  100. // Every created object must have been destroyed, otherwise the wait will block
  101. cout << endl << "*** Running cleanup..." << endl;
  102. if(rtc::Cleanup().wait_for(10s) == future_status::timeout)
  103. throw std::runtime_error("Timeout");
  104. cout << "*** Finished cleanup..." << endl;
  105. } catch (const exception &e) {
  106. cerr << "Cleanup failed: " << e.what() << endl;
  107. return -1;
  108. }
  109. // C API tests
  110. try {
  111. cout << endl << "*** Running WebRTC C API connectivity test..." << endl;
  112. test_capi_connectivity();
  113. cout << "*** Finished WebRTC C API connectivity test" << endl;
  114. } catch (const exception &e) {
  115. cerr << "WebRTC C API connectivity test failed: " << e.what() << endl;
  116. return -1;
  117. }
  118. #if RTC_ENABLE_MEDIA
  119. try {
  120. cout << endl << "*** Running WebRTC C API track test..." << endl;
  121. test_capi_track();
  122. cout << "*** Finished WebRTC C API track test" << endl;
  123. } catch (const exception &e) {
  124. cerr << "WebRTC C API track test failed: " << e.what() << endl;
  125. return -1;
  126. }
  127. #endif
  128. #if RTC_ENABLE_WEBSOCKET
  129. try {
  130. cout << endl << "*** Running WebSocketServer C API test..." << endl;
  131. test_capi_websocketserver();
  132. cout << "*** Finished WebSocketServer C API test" << endl;
  133. } catch (const exception &e) {
  134. cerr << "WebSocketServer C API test failed: " << e.what() << endl;
  135. return -1;
  136. }
  137. #endif
  138. try {
  139. cout << endl << "*** Running C API cleanup..." << endl;
  140. rtcCleanup();
  141. cout << "*** Finished C API cleanup..." << endl;
  142. } catch (const exception &e) {
  143. cerr << "C API cleanup failed: " << e.what() << endl;
  144. return -1;
  145. }
  146. /*
  147. // Benchmark
  148. try {
  149. cout << endl << "*** Running WebRTC benchmark..." << endl;
  150. test_benchmark();
  151. cout << "*** Finished WebRTC benchmark" << endl;
  152. } catch (const exception &e) {
  153. cerr << "WebRTC benchmark failed: " << e.what() << endl;
  154. std::this_thread::sleep_for(2s);
  155. return -1;
  156. }
  157. */
  158. return 0;
  159. }