main.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_track();
  25. void test_capi_connectivity();
  26. void test_capi_track();
  27. void test_websocket();
  28. size_t benchmark(chrono::milliseconds duration);
  29. void test_benchmark() {
  30. size_t goodput = benchmark(10s);
  31. if (goodput == 0)
  32. throw runtime_error("No data received");
  33. const size_t threshold = 1000; // 1 MB/s;
  34. if (goodput < threshold)
  35. throw runtime_error("Goodput is too low");
  36. }
  37. int main(int argc, char **argv) {
  38. try {
  39. cout << endl << "*** Running WebRTC connectivity test..." << endl;
  40. test_connectivity();
  41. cout << "*** Finished WebRTC connectivity test" << endl;
  42. } catch (const exception &e) {
  43. cerr << "WebRTC connectivity test failed: " << e.what() << endl;
  44. return -1;
  45. }
  46. this_thread::sleep_for(1s);
  47. try {
  48. cout << endl << "*** Running WebRTC C API connectivity test..." << endl;
  49. test_capi_connectivity();
  50. cout << "*** Finished WebRTC C API connectivity test" << endl;
  51. } catch (const exception &e) {
  52. cerr << "WebRTC C API connectivity test failed: " << e.what() << endl;
  53. return -1;
  54. }
  55. #if RTC_ENABLE_MEDIA
  56. this_thread::sleep_for(1s);
  57. try {
  58. cout << endl << "*** Running WebRTC Track test..." << endl;
  59. test_track();
  60. cout << "*** Finished WebRTC Track test" << endl;
  61. } catch (const exception &e) {
  62. cerr << "WebRTC Track test failed: " << e.what() << endl;
  63. return -1;
  64. }
  65. try {
  66. cout << endl << "*** Running WebRTC C API track test..." << endl;
  67. test_capi_track();
  68. cout << "*** Finished WebRTC C API track test" << endl;
  69. } catch (const exception &e) {
  70. cerr << "WebRTC C API track test failed: " << e.what() << endl;
  71. return -1;
  72. }
  73. #endif
  74. #if RTC_ENABLE_WEBSOCKET
  75. this_thread::sleep_for(1s);
  76. try {
  77. cout << endl << "*** Running WebSocket test..." << endl;
  78. test_websocket();
  79. cout << "*** Finished WebSocket test" << endl;
  80. } catch (const exception &e) {
  81. cerr << "WebSocket test failed: " << e.what() << endl;
  82. return -1;
  83. }
  84. #endif
  85. this_thread::sleep_for(1s);
  86. try {
  87. cout << endl << "*** Running WebRTC benchmark..." << endl;
  88. test_benchmark();
  89. cout << "*** Finished WebRTC benchmark" << endl;
  90. } catch (const exception &e) {
  91. cerr << "WebRTC benchmark failed: " << e.what() << endl;
  92. std::this_thread::sleep_for(2s);
  93. return -1;
  94. }
  95. std::this_thread::sleep_for(2s);
  96. return 0;
  97. }