minyue | 939df96 | 2017-04-19 08:58:38 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
minyue | 939df96 | 2017-04-19 08:58:38 | [diff] [blame] | 11 | #ifdef WEBRTC_NETWORK_TESTER_TEST_ENABLED |
| 12 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 13 | #include <string> |
minyue | 939df96 | 2017-04-19 08:58:38 | [diff] [blame] | 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 15 | #include "rtc_base/gunit.h" |
Liad Rubin | a88a4b7 | 2023-10-18 13:44:01 | [diff] [blame] | 16 | #include "rtc_base/random.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 17 | #include "rtc_tools/network_tester/test_controller.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 18 | #include "test/gtest.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 19 | #include "test/testsupport/file_utils.h" |
minyue | 939df96 | 2017-04-19 08:58:38 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | |
| 23 | TEST(NetworkTesterTest, ServerClient) { |
Liad Rubin | a88a4b7 | 2023-10-18 13:44:01 | [diff] [blame] | 24 | // Use a unique port rather than a hard-coded one to avoid collision when |
| 25 | // running the test in parallel in stress runs. Skipping all reserved ports. |
| 26 | const int MIN_PORT = 49152; |
| 27 | const int MAX_PORT = 65535; |
| 28 | int port = webrtc::Random(rtc::TimeMicros()).Rand(MIN_PORT, MAX_PORT); |
| 29 | |
Byoungchan Lee | c931f70 | 2022-07-03 08:20:17 | [diff] [blame] | 30 | rtc::AutoThread main_thread; |
Liad Rubin | a88a4b7 | 2023-10-18 13:44:01 | [diff] [blame] | 31 | |
minyue | 939df96 | 2017-04-19 08:58:38 | [diff] [blame] | 32 | TestController client( |
michaelt | fcea39d | 2017-04-20 12:39:30 | [diff] [blame] | 33 | 0, 0, webrtc::test::ResourcePath("network_tester/client_config", "dat"), |
| 34 | webrtc::test::OutputPath() + "client_packet_log.dat"); |
minyue | 939df96 | 2017-04-19 08:58:38 | [diff] [blame] | 35 | TestController server( |
Liad Rubin | a88a4b7 | 2023-10-18 13:44:01 | [diff] [blame] | 36 | port, port, |
michaelt | fcea39d | 2017-04-20 12:39:30 | [diff] [blame] | 37 | webrtc::test::ResourcePath("network_tester/server_config", "dat"), |
| 38 | webrtc::test::OutputPath() + "server_packet_log.dat"); |
Liad Rubin | a88a4b7 | 2023-10-18 13:44:01 | [diff] [blame] | 39 | client.SendConnectTo("127.0.0.1", port); |
minyue | 939df96 | 2017-04-19 08:58:38 | [diff] [blame] | 40 | EXPECT_TRUE_WAIT(server.IsTestDone() && client.IsTestDone(), 2000); |
| 41 | } |
| 42 | |
| 43 | } // namespace webrtc |
| 44 | |
| 45 | #endif // WEBRTC_NETWORK_TESTER_TEST_ENABLED |