main.cpp 2.4 KB

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