2
0

main.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. using namespace std;
  22. using namespace chrono_literals;
  23. void test_connectivity();
  24. void test_turn_connectivity();
  25. void test_track();
  26. void test_capi_connectivity();
  27. void test_capi_track();
  28. void test_websocket();
  29. void test_websocketserver();
  30. void test_capi_websocketserver();
  31. size_t benchmark(chrono::milliseconds duration);
  32. void test_benchmark() {
  33. size_t goodput = benchmark(10s);
  34. if (goodput == 0)
  35. throw runtime_error("No data received");
  36. const size_t threshold = 1000; // 1 MB/s;
  37. if (goodput < threshold)
  38. throw runtime_error("Goodput is too low");
  39. }
  40. int main(int argc, char **argv) {
  41. try {
  42. cout << endl << "*** Running WebRTC connectivity test..." << endl;
  43. test_connectivity();
  44. cout << "*** Finished WebRTC connectivity test" << endl;
  45. } catch (const exception &e) {
  46. cerr << "WebRTC connectivity test failed: " << e.what() << endl;
  47. return -1;
  48. }
  49. this_thread::sleep_for(1s);
  50. try {
  51. cout << endl << "*** Running WebRTC TURN connectivity test..." << endl;
  52. test_turn_connectivity();
  53. cout << "*** Finished WebRTC TURN connectivity test" << endl;
  54. } catch (const exception &e) {
  55. cerr << "WebRTC TURN connectivity test failed: " << e.what() << endl;
  56. return -1;
  57. }
  58. this_thread::sleep_for(1s);
  59. try {
  60. cout << endl << "*** Running WebRTC C API connectivity test..." << endl;
  61. test_capi_connectivity();
  62. cout << "*** Finished WebRTC C API connectivity test" << endl;
  63. } catch (const exception &e) {
  64. cerr << "WebRTC C API connectivity test failed: " << e.what() << endl;
  65. return -1;
  66. }
  67. #if RTC_ENABLE_MEDIA
  68. this_thread::sleep_for(1s);
  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. try {
  78. cout << endl << "*** Running WebRTC C API track test..." << endl;
  79. test_capi_track();
  80. cout << "*** Finished WebRTC C API track test" << endl;
  81. } catch (const exception &e) {
  82. cerr << "WebRTC C API track test failed: " << e.what() << endl;
  83. return -1;
  84. }
  85. #endif
  86. #if RTC_ENABLE_WEBSOCKET
  87. // TODO: Temporarily disabled as the echo service is unreliable
  88. /*
  89. this_thread::sleep_for(1s);
  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. try {
  108. cout << endl << "*** Running WebSocketServer C API test..." << endl;
  109. test_capi_websocketserver();
  110. cout << "*** Finished WebSocketServer C API test" << endl;
  111. } catch (const exception &e) {
  112. cerr << "WebSocketServer C API test failed: " << e.what() << endl;
  113. return -1;
  114. }
  115. #endif
  116. /*
  117. this_thread::sleep_for(1s);
  118. try {
  119. cout << endl << "*** Running WebRTC benchmark..." << endl;
  120. test_benchmark();
  121. cout << "*** Finished WebRTC benchmark" << endl;
  122. } catch (const exception &e) {
  123. cerr << "WebRTC benchmark failed: " << e.what() << endl;
  124. std::this_thread::sleep_for(2s);
  125. return -1;
  126. }
  127. */
  128. std::this_thread::sleep_for(1s);
  129. return 0;
  130. }