Remove gunit.h EXPECT/ASSERT..WAIT macros

Bug: webrtc:381524905
Change-Id: I01dff16f7ec26fa4075a9ef659dee3f0844db041
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374881
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43785}
This commit is contained in:
Evan Shrubsole 2025-01-21 10:04:37 +00:00 committed by WebRTC LUCI CQ
parent f62fbe9eaf
commit 0bebca526a
8 changed files with 67 additions and 122 deletions

View File

@ -3204,7 +3204,10 @@ TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiToWifiConnection) {
// Create channels and let them go writable, as usual.
CreateChannels();
EXPECT_TRUE_WAIT_MARGIN(CheckConnected(ep1_ch1(), ep2_ch1()), 1000, 1000);
EXPECT_THAT(
webrtc::WaitUntil([&]() { return CheckConnected(ep1_ch1(), ep2_ch1()); },
IsTrue()),
webrtc::IsRtcOk());
// Need to wait to make sure the connections on both networks are writable.
EXPECT_THAT(webrtc::WaitUntil(
[&] {
@ -3234,9 +3237,13 @@ TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiOverCellularNetwork) {
// Create channels and let them go writable, as usual.
CreateChannels();
EXPECT_TRUE_WAIT_MARGIN(CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(),
cellular[0], wifi[1]),
1000, 1000);
EXPECT_THAT(webrtc::WaitUntil(
[&]() {
return CheckCandidatePairAndConnected(ep1_ch1(), ep2_ch1(),
cellular[0], wifi[1]);
},
IsTrue()),
webrtc::IsRtcOk());
DestroyChannels();
}
@ -3255,7 +3262,10 @@ TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) {
// Create channels and let them go writable, as usual.
CreateChannels();
EXPECT_TRUE_WAIT_MARGIN(CheckConnected(ep1_ch1(), ep2_ch1()), 1000, 1000);
EXPECT_THAT(
webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); },
IsTrue()),
webrtc::IsRtcOk());
int backup_ping_interval = 2000;
ep2_ch1()->SetIceConfig(
CreateIceConfig(2000, GATHER_ONCE, backup_ping_interval));
@ -3300,7 +3310,10 @@ TEST_F(P2PTransportChannelMultihomedTest, TestStableWritableRate) {
// Create channels and let them go writable, as usual.
CreateChannels();
EXPECT_TRUE_WAIT_MARGIN(CheckConnected(ep1_ch1(), ep2_ch1()), 1000, 1000);
EXPECT_THAT(
webrtc::WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); },
IsTrue()),
webrtc::IsRtcOk());
// Set a value larger than the default value of 2500 ms
int ping_interval_ms = 3456;
IceConfig config = CreateIceConfig(2 * ping_interval_ms, GATHER_ONCE);
@ -3428,8 +3441,11 @@ TEST_F(P2PTransportChannelMultihomedTest,
CreateChannels(continual_gathering_config, continual_gathering_config);
SetAllocatorFlags(0, kOnlyLocalPorts);
SetAllocatorFlags(1, kOnlyLocalPorts);
EXPECT_TRUE_WAIT_MARGIN(CheckConnected(ep1_ch1(), ep2_ch1()), kDefaultTimeout,
kDefaultTimeout);
EXPECT_THAT(
webrtc::WaitUntil(
[&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kDefaultTimeout)}),
webrtc::IsRtcOk());
// Add a new wifi interface on end point 2. We should expect a new connection
// to be created and the new one will be the best connection.

View File

@ -39,62 +39,6 @@
} \
} while (0)
// The typical EXPECT_XXXX and ASSERT_XXXXs, but done until true or a timeout.
// One can add failure message by appending "<< msg".
#define EXPECT_TRUE_WAIT(ex, timeout) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (bool res = true) { \
WAIT_(ex, timeout, res); \
if (!res) \
goto GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__); \
} else \
GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__) : EXPECT_TRUE(ex)
#define EXPECT_EQ_WAIT(v1, v2, timeout) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (bool res = true) { \
WAIT_(v1 == v2, timeout, res); \
if (!res) \
goto GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__); \
} else \
GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__) : EXPECT_EQ(v1, v2)
#define ASSERT_TRUE_WAIT(ex, timeout) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (bool res = true) { \
WAIT_(ex, timeout, res); \
if (!res) \
goto GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__); \
} else \
GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__) : ASSERT_TRUE(ex)
#define ASSERT_EQ_WAIT(v1, v2, timeout) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (bool res = true) { \
WAIT_(v1 == v2, timeout, res); \
if (!res) \
goto GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__); \
} else \
GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__) : ASSERT_EQ(v1, v2)
// Version with a "soft" timeout and a margin. This logs if the timeout is
// exceeded, but it only fails if the expression still isn't true after the
// margin time passes.
#define EXPECT_TRUE_WAIT_MARGIN(ex, timeout, margin) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (bool res = true) { \
WAIT_(ex, timeout, res); \
if (res) \
break; \
RTC_LOG(LS_WARNING) << "Expression " << #ex << " still not true after " \
<< (timeout) << "ms; waiting an additional " << margin \
<< "ms"; \
WAIT_(ex, margin, res); \
if (!res) \
goto GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__); \
} else \
GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__) : EXPECT_TRUE(ex)
// Wait until "ex" is true, or "timeout" expires, using fake clock where
// messages are processed every millisecond.
// TODO(pthatcher): Allow tests to control how many milliseconds to advance.
@ -104,54 +48,4 @@
(clock).AdvanceTime(webrtc::TimeDelta::Millis(1)); \
}
// This returns the result of the test in res, so that we don't re-evaluate
// the expression in the XXXX_WAIT macros below, since that causes problems
// when the expression is only true the first time you check it.
#define SIMULATED_WAIT_(ex, timeout, res, clock) \
do { \
int64_t start = rtc::TimeMillis(); \
res = (ex); \
while (!res && rtc::TimeMillis() < start + (timeout)) { \
(clock).AdvanceTime(webrtc::TimeDelta::Millis(1)); \
res = (ex); \
} \
} while (0)
// The typical EXPECT_XXXX, but done until true or a timeout with a fake clock.
#define EXPECT_TRUE_SIMULATED_WAIT(ex, timeout, clock) \
do { \
bool res; \
SIMULATED_WAIT_(ex, timeout, res, clock); \
if (!res) { \
EXPECT_TRUE(ex); \
} \
} while (0)
#define EXPECT_EQ_SIMULATED_WAIT(v1, v2, timeout, clock) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (bool res = true) { \
SIMULATED_WAIT_(v1 == v2, timeout, res, clock); \
if (!res) \
goto GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__); \
} else \
GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__) : EXPECT_EQ(v1, v2)
#define ASSERT_TRUE_SIMULATED_WAIT(ex, timeout, clock) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (bool res = true) { \
SIMULATED_WAIT_(ex, timeout, res, clock); \
if (!res) \
goto GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__); \
} else \
GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__) : ASSERT_TRUE(ex)
#define ASSERT_EQ_SIMULATED_WAIT(v1, v2, timeout, clock) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (bool res = true) { \
SIMULATED_WAIT_(v1 == v2, timeout, res, clock); \
if (!res) \
goto GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__); \
} else \
GTEST_CONCAT_TOKEN_(gunit_label_, __LINE__) : ASSERT_EQ(v1, v2)
#endif // RTC_BASE_GUNIT_H_

View File

@ -82,11 +82,13 @@ if (rtc_enable_protobuf) {
deps = [
":network_tester",
"../../api:rtc_error_matchers",
"../../rtc_base:gunit_helpers",
"../../rtc_base:random",
"../../rtc_base:threading",
"../../test:fileutils",
"../../test:test_support",
"../../test:wait_until",
"//testing/gtest",
]

View File

@ -12,11 +12,13 @@
#include <string>
#include "rtc_base/gunit.h"
#include "api/test/rtc_error_matchers.h"
#include "rtc_base/random.h"
#include "rtc_tools/network_tester/test_controller.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/testsupport/file_utils.h"
#include "test/wait_until.h"
namespace webrtc {
@ -37,7 +39,10 @@ TEST(NetworkTesterTest, ServerClient) {
webrtc::test::ResourcePath("network_tester/server_config", "dat"),
webrtc::test::OutputPath() + "server_packet_log.dat");
client.SendConnectTo("127.0.0.1", port);
EXPECT_TRUE_WAIT(server.IsTestDone() && client.IsTestDone(), 2000);
EXPECT_THAT(
WaitUntil([&] { return server.IsTestDone() && client.IsTestDone(); },
::testing::IsTrue()),
IsRtcOk());
}
} // namespace webrtc

View File

@ -1195,6 +1195,7 @@ if (is_ios || is_mac) {
":videosource_objc",
":videotoolbox_objc",
"../api:libjingle_peerconnection_api",
"../api:rtc_error_matchers",
"../api:scoped_refptr",
"../api/audio:audio_device",
"../api/audio:audio_processing",
@ -1215,6 +1216,8 @@ if (is_ios || is_mac) {
"../rtc_base:rtc_event",
"../rtc_base/system:unused",
"../system_wrappers",
"../test:test_support",
"../test:wait_until",
"//third_party/libyuv",
]

View File

@ -12,10 +12,12 @@
#import <XCTest/XCTest.h>
#include "api/test/rtc_error_matchers.h"
#include "rtc_base/gunit.h"
#include "test/gmock.h"
#include "test/wait_until.h"
NSString *const kTestFileName = @"foreman.mp4";
static const int kTestTimeoutMs = 5 * 1000; // 5secs.
@interface MockCapturerDelegate
: NSObject <RTC_OBJC_TYPE (RTCVideoCapturerDelegate)>
@ -66,7 +68,12 @@ NS_CLASS_AVAILABLE_IOS(10)
[self.capturer startCapturingFromFileNamed:@"not_in_bundle.mov"
onError:errorBlock];
ASSERT_TRUE_WAIT(errorOccured, kTestTimeoutMs);
EXPECT_THAT(webrtc::WaitUntil(
^() {
return errorOccured;
},
::testing::IsTrue()),
webrtc::IsRtcOk());
}
- (void)testSecondStartCaptureCallFails {
@ -87,7 +94,12 @@ NS_CLASS_AVAILABLE_IOS(10)
[self.capturer startCapturingFromFileNamed:kTestFileName
onError:secondErrorBlock];
ASSERT_TRUE_WAIT(secondError, kTestTimeoutMs);
EXPECT_THAT(webrtc::WaitUntil(
^() {
return secondError;
},
::testing::IsTrue()),
webrtc::IsRtcOk());
}
- (void)testStartStopCapturer {
@ -111,7 +123,12 @@ NS_CLASS_AVAILABLE_IOS(10)
[self.capturer stopCapture];
done = YES;
});
WAIT(done, kTestTimeoutMs);
EXPECT_THAT(webrtc::WaitUntil(
^() {
return done;
},
::testing::IsTrue()),
webrtc::IsRtcOk());
capturedFramesAfterStop = self.mockDelegate.capturedFramesCount;
ASSERT_TRUE(capturedFrames != -1);

View File

@ -461,7 +461,9 @@ if (!build_with_chromium) {
webrtc_fuzzer_test("sdp_integration_fuzzer") {
sources = [ "sdp_integration_fuzzer.cc" ]
deps = [
"..:wait_until",
"../../api:libjingle_peerconnection_api",
"../../api:rtc_error_matchers",
"../../pc:integration_test_helpers",
"../../pc:libjingle_peerconnection",
"../../test:test_support",

View File

@ -12,7 +12,9 @@
#include <stdint.h>
#include "absl/strings/string_view.h"
#include "api/test/rtc_error_matchers.h"
#include "pc/test/integration_test_helpers.h"
#include "test/wait_until.h"
namespace webrtc {
@ -35,14 +37,18 @@ class FuzzerTest : public PeerConnectionIntegrationBaseTest {
caller()->pc()->SetRemoteDescription(std::move(sdp), srd_observer);
// Wait a short time for observer to be called. Timeout is short
// because the fuzzer should be trying many branches.
EXPECT_TRUE_WAIT(srd_observer->called(), 100);
EXPECT_THAT(
WaitUntil([&] { return srd_observer->called(); }, ::testing::IsTrue()),
IsRtcOk());
// If set-remote-description was successful, try to answer.
auto sld_observer =
rtc::make_ref_counted<FakeSetLocalDescriptionObserver>();
if (srd_observer->error().ok()) {
caller()->pc()->SetLocalDescription(sld_observer);
EXPECT_TRUE_WAIT(sld_observer->called(), 100);
EXPECT_THAT(WaitUntil([&] { return sld_observer->called(); },
::testing::IsTrue()),
IsRtcOk());
}
// If there is an EXPECT failure, die here.
RTC_CHECK(!HasFailure());