main.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. try {
  47. cout << endl << "*** Running WebRTC C API connectivity test..." << endl;
  48. test_capi_connectivity();
  49. cout << "*** Finished WebRTC C API connectivity test" << endl;
  50. } catch (const exception &e) {
  51. cerr << "WebRTC C API connectivity test failed: " << e.what() << endl;
  52. return -1;
  53. }
  54. #if RTC_ENABLE_MEDIA
  55. try {
  56. cout << endl << "*** Running WebRTC Track test..." << endl;
  57. test_track();
  58. cout << "*** Finished WebRTC Track test" << endl;
  59. } catch (const exception &e) {
  60. cerr << "WebRTC Track test failed: " << e.what() << endl;
  61. return -1;
  62. }
  63. try {
  64. cout << endl << "*** Running WebRTC C API track test..." << endl;
  65. test_capi_track();
  66. cout << "*** Finished WebRTC C API track test" << endl;
  67. } catch (const exception &e) {
  68. cerr << "WebRTC C API track test failed: " << e.what() << endl;
  69. return -1;
  70. }
  71. #endif
  72. #if RTC_ENABLE_WEBSOCKET
  73. try {
  74. cout << endl << "*** Running WebSocket test..." << endl;
  75. test_websocket();
  76. cout << "*** Finished WebSocket test" << endl;
  77. } catch (const exception &e) {
  78. cerr << "WebSocket test failed: " << e.what() << endl;
  79. return -1;
  80. }
  81. #endif
  82. try {
  83. cout << endl << "*** Running WebRTC benchmark..." << endl;
  84. test_benchmark();
  85. cout << "*** Finished WebRTC benchmark" << endl;
  86. } catch (const exception &e) {
  87. cerr << "WebRTC benchmark failed: " << e.what() << endl;
  88. std::this_thread::sleep_for(2s);
  89. return -1;
  90. }
  91. std::this_thread::sleep_for(2s);
  92. return 0;
  93. }