main.cpp 2.3 KB

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