main.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /**
  2. * Copyright (c) 2019 Paul-Louis Ageneau
  3. *
  4. * This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  7. */
  8. #include <chrono>
  9. #include <iostream>
  10. #include <thread>
  11. #include <rtc/rtc.hpp>
  12. using namespace std;
  13. using namespace chrono_literals;
  14. void test_connectivity(bool signal_wrong_fingerprint);
  15. void test_negotiated();
  16. void test_reliability();
  17. void test_turn_connectivity();
  18. void test_track();
  19. void test_capi_connectivity();
  20. void test_capi_track();
  21. void test_websocket();
  22. void test_websocketserver();
  23. void test_capi_websocketserver();
  24. size_t benchmark(chrono::milliseconds duration);
  25. void test_benchmark() {
  26. size_t goodput = benchmark(10s);
  27. if (goodput == 0)
  28. throw runtime_error("No data received");
  29. const size_t threshold = 1000; // 1 MB/s;
  30. if (goodput < threshold)
  31. throw runtime_error("Goodput is too low");
  32. }
  33. int main(int argc, char **argv) {
  34. // C++ API tests
  35. try {
  36. cout << endl << "*** Running WebRTC connectivity test..." << endl;
  37. test_connectivity(false);
  38. cout << "*** Finished WebRTC connectivity test" << endl;
  39. } catch (const exception &e) {
  40. cerr << "WebRTC connectivity test failed: " << e.what() << endl;
  41. return -1;
  42. }
  43. try {
  44. cout << endl << "*** Running WebRTC broken fingerprint test..." << endl;
  45. test_connectivity(true);
  46. cerr << "WebRTC connectivity test failed to detect broken fingerprint" << endl;
  47. return -1;
  48. } catch (const exception &) {
  49. }
  50. // TODO: Temporarily disabled as the Open Relay TURN server is unreliable
  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. */
  61. try {
  62. cout << endl << "*** Running WebRTC negotiated DataChannel test..." << endl;
  63. test_negotiated();
  64. cout << "*** Finished WebRTC negotiated DataChannel test" << endl;
  65. } catch (const exception &e) {
  66. cerr << "WebRTC negotiated DataChannel test failed: " << e.what() << endl;
  67. return -1;
  68. }
  69. try {
  70. cout << endl << "*** Running WebRTC reliability mode test..." << endl;
  71. test_reliability();
  72. cout << "*** Finished WebRTC reliaility mode test" << endl;
  73. } catch (const exception &e) {
  74. cerr << "WebRTC reliability test failed: " << e.what() << endl;
  75. return -1;
  76. }
  77. #if RTC_ENABLE_MEDIA
  78. try {
  79. cout << endl << "*** Running WebRTC Track test..." << endl;
  80. test_track();
  81. cout << "*** Finished WebRTC Track test" << endl;
  82. } catch (const exception &e) {
  83. cerr << "WebRTC 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. try {
  91. cout << endl << "*** Running WebSocket test..." << endl;
  92. test_websocket();
  93. cout << "*** Finished WebSocket test" << endl;
  94. } catch (const exception &e) {
  95. cerr << "WebSocket test failed: " << e.what() << endl;
  96. return -1;
  97. }
  98. */
  99. try {
  100. cout << endl << "*** Running WebSocketServer test..." << endl;
  101. test_websocketserver();
  102. cout << "*** Finished WebSocketServer test" << endl;
  103. } catch (const exception &e) {
  104. cerr << "WebSocketServer test failed: " << e.what() << endl;
  105. return -1;
  106. }
  107. #endif
  108. try {
  109. // Every created object must have been destroyed, otherwise the wait will block
  110. cout << endl << "*** Running cleanup..." << endl;
  111. if(rtc::Cleanup().wait_for(10s) == future_status::timeout)
  112. throw std::runtime_error("Timeout");
  113. cout << "*** Finished cleanup..." << endl;
  114. } catch (const exception &e) {
  115. cerr << "Cleanup failed: " << e.what() << endl;
  116. return -1;
  117. }
  118. // C API tests
  119. try {
  120. cout << endl << "*** Running WebRTC C API connectivity test..." << endl;
  121. test_capi_connectivity();
  122. cout << "*** Finished WebRTC C API connectivity test" << endl;
  123. } catch (const exception &e) {
  124. cerr << "WebRTC C API connectivity test failed: " << e.what() << endl;
  125. return -1;
  126. }
  127. #if RTC_ENABLE_MEDIA
  128. try {
  129. cout << endl << "*** Running WebRTC C API track test..." << endl;
  130. test_capi_track();
  131. cout << "*** Finished WebRTC C API track test" << endl;
  132. } catch (const exception &e) {
  133. cerr << "WebRTC C API track test failed: " << e.what() << endl;
  134. return -1;
  135. }
  136. #endif
  137. #if RTC_ENABLE_WEBSOCKET
  138. try {
  139. cout << endl << "*** Running WebSocketServer C API test..." << endl;
  140. test_capi_websocketserver();
  141. cout << "*** Finished WebSocketServer C API test" << endl;
  142. } catch (const exception &e) {
  143. cerr << "WebSocketServer C API test failed: " << e.what() << endl;
  144. return -1;
  145. }
  146. #endif
  147. try {
  148. cout << endl << "*** Running C API cleanup..." << endl;
  149. rtcCleanup();
  150. cout << "*** Finished C API cleanup..." << endl;
  151. } catch (const exception &e) {
  152. cerr << "C API cleanup failed: " << e.what() << endl;
  153. return -1;
  154. }
  155. /*
  156. // Benchmark
  157. try {
  158. cout << endl << "*** Running WebRTC benchmark..." << endl;
  159. test_benchmark();
  160. cout << "*** Finished WebRTC benchmark" << endl;
  161. } catch (const exception &e) {
  162. cerr << "WebRTC benchmark failed: " << e.what() << endl;
  163. std::this_thread::sleep_for(2s);
  164. return -1;
  165. }
  166. */
  167. return 0;
  168. }