main.cpp 2.6 KB

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