Format /test folder

Formatting done via:

git ls-files | grep -E '^test\/.*\.(h|cc|mm)' | xargs clang-format -i

No-Iwyu: Includes didn't change and it isn't related to formatting
Bug: webrtc:42225392
Change-Id: I3a75019dee1ad9bef713d80a5f79cbc56adab472
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/373903
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43690}
This commit is contained in:
Boris Tsirkin 2025-01-08 06:00:52 -08:00 committed by WebRTC LUCI CQ
parent 825379f4dc
commit 557d387a2e
16 changed files with 128 additions and 108 deletions

View File

@ -40,8 +40,7 @@ bool FakeDecoder::Configure(const Settings& settings) {
return true;
}
int32_t FakeDecoder::Decode(const EncodedImage& input,
int64_t render_time_ms) {
int32_t FakeDecoder::Decode(const EncodedImage& input, int64_t render_time_ms) {
if (input._encodedWidth > 0 && input._encodedHeight > 0) {
width_ = input._encodedWidth;
height_ = input._encodedHeight;

View File

@ -34,8 +34,7 @@ class FakeDecoder : public VideoDecoder {
bool Configure(const Settings& settings) override;
int32_t Decode(const EncodedImage& input,
int64_t render_time_ms) override;
int32_t Decode(const EncodedImage& input, int64_t render_time_ms) override;
int32_t RegisterDecodeCompleteCallback(
DecodedImageCallback* callback) override;
@ -62,8 +61,7 @@ class FakeH264Decoder : public FakeDecoder {
public:
virtual ~FakeH264Decoder() {}
int32_t Decode(const EncodedImage& input,
int64_t render_time_ms) override;
int32_t Decode(const EncodedImage& input, int64_t render_time_ms) override;
};
} // namespace test

View File

@ -269,7 +269,7 @@ void FakeEncoder::SetRatesLocked(const RateControlParameters& parameters) {
uint32_t bitrate = current_rate_settings_.bitrate.GetBitrate(
spatial_idx, temporal_idx);
bitrate = static_cast<uint32_t>(
(bitrate* int64_t{max_target_bitrate_kbps_}) /
(bitrate * int64_t{max_target_bitrate_kbps_}) /
allocated_bitrate_kbps);
current_rate_settings_.bitrate.SetBitrate(spatial_idx, temporal_idx,
bitrate);

View File

@ -27,8 +27,7 @@ class FakeVp8Decoder : public VideoDecoder {
bool Configure(const Settings& settings) override;
int32_t Decode(const EncodedImage& input,
int64_t render_time_ms) override;
int32_t Decode(const EncodedImage& input, int64_t render_time_ms) override;
int32_t RegisterDecodeCompleteCallback(
DecodedImageCallback* callback) override;

View File

@ -15,7 +15,6 @@
namespace webrtc {
void FuzzOneInput(const uint8_t* data, size_t size) {
// Normally we'd check the integrity first, but those checks are
// fuzzed separately in stun_validator_fuzzer.cc. We still want to
// fuzz this target since the integrity checks could be forged by a

View File

@ -23,14 +23,16 @@ void ConfigureCoverageReportPath() {
dispatch_once(&once_token, ^{
// Writes the profraw file to the Documents directory, where the app has
// write rights.
NSArray* paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSArray* paths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documents_directory = [paths firstObject];
NSString* file_name = [documents_directory stringByAppendingPathComponent:@"coverage.profraw"];
NSString* file_name = [documents_directory
stringByAppendingPathComponent:@"coverage.profraw"];
// For documentation, see:
// http://clang.llvm.org/docs/SourceBasedCodeCoverage.html
__llvm_profile_set_filename([file_name cStringUsingEncoding:NSUTF8StringEncoding]);
__llvm_profile_set_filename(
[file_name cStringUsingEncoding:NSUTF8StringEncoding]);
// Print the path for easier retrieval.
NSLog(@"Coverage data at %@.", file_name);

View File

@ -29,7 +29,8 @@
self.continueAfterFailure = false;
id appDelegate = UIApplication.sharedApplication.delegate;
XCTAssertTrue([appDelegate conformsToProtocol:@protocol(GoogleTestRunnerDelegate)]);
XCTAssertTrue(
[appDelegate conformsToProtocol:@protocol(GoogleTestRunnerDelegate)]);
id<GoogleTestRunnerDelegate> runnerDelegate =
static_cast<id<GoogleTestRunnerDelegate>>(appDelegate);

View File

@ -38,7 +38,8 @@
// run in a row, this provides an indication of which one is currently running.
// If enabled, runs unittests using the XCTest test runner.
const char kEnableRunIOSUnittestsWithXCTest[] = "enable-run-ios-unittests-with-xctest";
const char kEnableRunIOSUnittestsWithXCTest[] =
"enable-run-ios-unittests-with-xctest";
static int (*g_test_suite)(void) = NULL;
static int g_argc;
@ -97,45 +98,57 @@ static std::optional<std::vector<std::string>> g_metrics_to_plot;
int exitStatus = g_test_suite();
NSArray<NSString *> *outputDirectories =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSArray<NSString *> *outputDirectories = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
std::vector<std::unique_ptr<webrtc::test::MetricsExporter>> exporters;
if (g_export_perf_results_new_api) {
exporters.push_back(std::make_unique<webrtc::test::StdoutMetricsExporter>());
exporters.push_back(
std::make_unique<webrtc::test::StdoutMetricsExporter>());
if (g_write_perf_output) {
// Stores data into a proto file under the app's document directory.
NSString *fileName = @"perftest-output.pb";
if ([outputDirectories count] != 0) {
NSString *outputPath = [outputDirectories[0] stringByAppendingPathComponent:fileName];
NSString *outputPath =
[outputDirectories[0] stringByAppendingPathComponent:fileName];
exporters.push_back(std::make_unique<webrtc::test::ChromePerfDashboardMetricsExporter>(
[NSString stdStringForString:outputPath]));
exporters.push_back(
std::make_unique<webrtc::test::ChromePerfDashboardMetricsExporter>(
[NSString stdStringForString:outputPath]));
}
}
if (!g_webrtc_test_metrics_output_path.empty()) {
RTC_CHECK_EQ(g_webrtc_test_metrics_output_path.find('/'), std::string::npos)
<< "On iOS, --webrtc_test_metrics_output_path must only be a file name.";
RTC_CHECK_EQ(g_webrtc_test_metrics_output_path.find('/'),
std::string::npos)
<< "On iOS, --webrtc_test_metrics_output_path must only be a file "
"name.";
if ([outputDirectories count] != 0) {
NSString *fileName = [NSString stringWithCString:g_webrtc_test_metrics_output_path.c_str()
encoding:[NSString defaultCStringEncoding]];
NSString *outputPath = [outputDirectories[0] stringByAppendingPathComponent:fileName];
exporters.push_back(std::make_unique<webrtc::test::MetricsSetProtoFileExporter>(
webrtc::test::MetricsSetProtoFileExporter::Options(
[NSString stdStringForString:outputPath])));
NSString *fileName = [NSString
stringWithCString:g_webrtc_test_metrics_output_path.c_str()
encoding:[NSString defaultCStringEncoding]];
NSString *outputPath =
[outputDirectories[0] stringByAppendingPathComponent:fileName];
exporters.push_back(
std::make_unique<webrtc::test::MetricsSetProtoFileExporter>(
webrtc::test::MetricsSetProtoFileExporter::Options(
[NSString stdStringForString:outputPath])));
}
}
} else {
exporters.push_back(std::make_unique<webrtc::test::PrintResultProxyMetricsExporter>());
exporters.push_back(
std::make_unique<webrtc::test::PrintResultProxyMetricsExporter>());
}
webrtc::test::ExportPerfMetric(*webrtc::test::GetGlobalMetricsLogger(), std::move(exporters));
webrtc::test::ExportPerfMetric(*webrtc::test::GetGlobalMetricsLogger(),
std::move(exporters));
if (!g_export_perf_results_new_api) {
if (g_write_perf_output) {
// Stores data into a proto file under the app's document directory.
NSString *fileName = @"perftest-output.pb";
if ([outputDirectories count] != 0) {
NSString *outputPath = [outputDirectories[0] stringByAppendingPathComponent:fileName];
NSString *outputPath =
[outputDirectories[0] stringByAppendingPathComponent:fileName];
if (!webrtc::test::WritePerfResults([NSString stdStringForString:outputPath])) {
if (!webrtc::test::WritePerfResults(
[NSString stdStringForString:outputPath])) {
return 1;
}
}

View File

@ -13,9 +13,11 @@
#include "test/run_test.h"
// Converting a C++ function pointer to an Objective-C block.
typedef void(^TestBlock)();
TestBlock functionToBlock(void(*function)()) {
return [^(void) { function(); } copy];
typedef void (^TestBlock)();
TestBlock functionToBlock(void (*function)()) {
return [^(void) {
function();
} copy];
}
// Class calling the test function on the platform specific thread.
@ -50,7 +52,7 @@ TestBlock functionToBlock(void(*function)()) {
namespace webrtc {
namespace test {
void RunTest(void(*test)()) {
void RunTest(void (*test)()) {
@autoreleasepool {
[NSApplication sharedApplication];
@ -63,8 +65,9 @@ void RunTest(void(*test)()) {
withObject:testBlock];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
while ([testRunner running] && [runLoop runMode:NSDefaultRunLoopMode
beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]])
while ([testRunner running] &&
[runLoop runMode:NSDefaultRunLoopMode
beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]])
;
}
}

View File

@ -31,8 +31,8 @@
@end
@implementation CocoaWindow
static NSInteger nextXOrigin_;
static NSInteger nextYOrigin_;
static NSInteger nextXOrigin_;
static NSInteger nextYOrigin_;
- (id)initWithTitle:(NSString *)title width:(int)width height:(int)height {
self = [super init];
@ -67,7 +67,8 @@
defer:NO];
NSRect viewFrame = NSMakeRect(0, 0, width_, height_);
NSOpenGLView *view = [[NSOpenGLView alloc] initWithFrame:viewFrame pixelFormat:nil];
NSOpenGLView *view = [[NSOpenGLView alloc] initWithFrame:viewFrame
pixelFormat:nil];
context_ = [view openGLContext];
[[window_ contentView] addSubview:view];
@ -84,10 +85,10 @@
namespace webrtc {
namespace test {
VideoRenderer* VideoRenderer::CreatePlatformRenderer(const char* window_title,
VideoRenderer *VideoRenderer::CreatePlatformRenderer(const char *window_title,
size_t width,
size_t height) {
MacRenderer* renderer = new MacRenderer();
MacRenderer *renderer = new MacRenderer();
if (!renderer->Init(window_title, width, height)) {
delete renderer;
return NULL;
@ -95,20 +96,18 @@ VideoRenderer* VideoRenderer::CreatePlatformRenderer(const char* window_title,
return renderer;
}
MacRenderer::MacRenderer()
: window_(NULL) {}
MacRenderer::MacRenderer() : window_(NULL) {}
MacRenderer::~MacRenderer() {
GlRenderer::Destroy();
}
bool MacRenderer::Init(const char* window_title, int width, int height) {
bool MacRenderer::Init(const char *window_title, int width, int height) {
window_ = [[CocoaWindow alloc]
initWithTitle:[NSString stringWithUTF8String:window_title]
width:width
height:height];
if (!window_)
return false;
width:width
height:height];
if (!window_) return false;
[window_ performSelectorOnMainThread:@selector(createWindow:)
withObject:nil
waitUntilDone:YES];
@ -119,10 +118,10 @@ bool MacRenderer::Init(const char* window_title, int width, int height) {
return true;
}
void MacRenderer::OnFrame(const VideoFrame& frame) {
void MacRenderer::OnFrame(const VideoFrame &frame) {
[window_ makeCurrentContext];
GlRenderer::OnFrame(frame);
}
} // test
} // webrtc
} // namespace test
} // namespace webrtc

View File

@ -15,7 +15,8 @@
#import "sdk/objc/native/api/video_capturer.h"
#import "sdk/objc/native/src/objc_frame_buffer.h"
@interface RTCTestVideoSourceAdapter : NSObject <RTC_OBJC_TYPE (RTCVideoCapturerDelegate)>
@interface RTCTestVideoSourceAdapter
: NSObject <RTC_OBJC_TYPE (RTCVideoCapturerDelegate)>
@property(nonatomic) webrtc::test::MacCapturer *capturer;
@end
@ -38,15 +39,18 @@
namespace {
AVCaptureDeviceFormat *SelectClosestFormat(AVCaptureDevice *device, size_t width, size_t height) {
AVCaptureDeviceFormat *SelectClosestFormat(AVCaptureDevice *device,
size_t width,
size_t height) {
NSArray<AVCaptureDeviceFormat *> *formats =
[RTC_OBJC_TYPE(RTCCameraVideoCapturer) supportedFormatsForDevice:device];
AVCaptureDeviceFormat *selectedFormat = nil;
int currentDiff = INT_MAX;
for (AVCaptureDeviceFormat *format in formats) {
CMVideoDimensions dimension = CMVideoFormatDescriptionGetDimensions(format.formatDescription);
int diff =
std::abs((int64_t)width - dimension.width) + std::abs((int64_t)height - dimension.height);
CMVideoDimensions dimension =
CMVideoFormatDescriptionGetDimensions(format.formatDescription);
int diff = std::abs((int64_t)width - dimension.width) +
std::abs((int64_t)height - dimension.height);
if (diff < currentDiff) {
selectedFormat = format;
currentDiff = diff;
@ -74,8 +78,8 @@ MacCapturer::MacCapturer(size_t width,
[[RTC_OBJC_TYPE(RTCCameraVideoCapturer) alloc] initWithDelegate:adapter];
capturer_ = (__bridge_retained void *)capturer;
AVCaptureDevice *device =
[[RTC_OBJC_TYPE(RTCCameraVideoCapturer) captureDevices] objectAtIndex:capture_device_index];
AVCaptureDevice *device = [[RTC_OBJC_TYPE(RTCCameraVideoCapturer)
captureDevices] objectAtIndex:capture_device_index];
AVCaptureDeviceFormat *format = SelectClosestFormat(device, width, height);
[capturer startCaptureWithDevice:device format:format fps:target_fps];
}
@ -90,7 +94,8 @@ MacCapturer *MacCapturer::Create(size_t width,
void MacCapturer::Destroy() {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
RTCTestVideoSourceAdapter *adapter = (__bridge_transfer RTCTestVideoSourceAdapter *)adapter_;
RTCTestVideoSourceAdapter *adapter =
(__bridge_transfer RTCTestVideoSourceAdapter *)adapter_;
RTC_OBJC_TYPE(RTCCameraVideoCapturer) *capturer =
(__bridge_transfer RTC_OBJC_TYPE(RTCCameraVideoCapturer) *)capturer_;
[capturer stopCapture];

View File

@ -113,7 +113,9 @@ class MockNetworkBehaviourInterface : public NetworkBehaviorInterface {
DequeueDeliverablePackets,
(int64_t),
(override));
MOCK_METHOD(std::optional<int64_t>, NextDeliveryTimeUs, (),
MOCK_METHOD(std::optional<int64_t>,
NextDeliveryTimeUs,
(),
(const, override));
MOCK_METHOD(void,
RegisterDeliveryTimeChangedCallback,

View File

@ -380,43 +380,43 @@ void PeerScenarioClient::SetSdpOfferAndGetAnswer(
std::function<void()> remote_description_set,
std::function<void(std::string)> answer_handler) {
if (!signaling_thread_->IsCurrent()) {
signaling_thread_->PostTask([this, remote_offer, remote_description_set,
answer_handler] {
SetSdpOfferAndGetAnswer(remote_offer, remote_description_set,
answer_handler);
});
signaling_thread_->PostTask(
[this, remote_offer, remote_description_set, answer_handler] {
SetSdpOfferAndGetAnswer(remote_offer, remote_description_set,
answer_handler);
});
return;
}
RTC_DCHECK_RUN_ON(signaling_thread_);
peer_connection_->SetRemoteDescription(
CreateSessionDescription(SdpType::kOffer, remote_offer),
rtc::make_ref_counted<
LambdaSetRemoteDescriptionObserver>([this, remote_description_set,
answer_handler](RTCError) {
RTC_DCHECK_RUN_ON(signaling_thread_);
if (remote_description_set) {
// Allow the caller to modify transceivers
// before creating the answer.
remote_description_set();
}
peer_connection_->CreateAnswer(
rtc::make_ref_counted<LambdaCreateSessionDescriptionObserver>(
[this, answer_handler](
std::unique_ptr<SessionDescriptionInterface> answer) {
RTC_DCHECK_RUN_ON(signaling_thread_);
std::string sdp_answer;
answer->ToString(&sdp_answer);
RTC_LOG(LS_INFO) << sdp_answer;
peer_connection_->SetLocalDescription(
std::move(answer),
rtc::make_ref_counted<LambdaSetLocalDescriptionObserver>(
[answer_handler, sdp_answer](RTCError) {
answer_handler(sdp_answer);
}));
})
.get(),
PeerConnectionInterface::RTCOfferAnswerOptions());
}));
rtc::make_ref_counted<LambdaSetRemoteDescriptionObserver>(
[this, remote_description_set, answer_handler](RTCError) {
RTC_DCHECK_RUN_ON(signaling_thread_);
if (remote_description_set) {
// Allow the caller to modify transceivers
// before creating the answer.
remote_description_set();
}
peer_connection_->CreateAnswer(
rtc::make_ref_counted<LambdaCreateSessionDescriptionObserver>(
[this, answer_handler](
std::unique_ptr<SessionDescriptionInterface> answer) {
RTC_DCHECK_RUN_ON(signaling_thread_);
std::string sdp_answer;
answer->ToString(&sdp_answer);
RTC_LOG(LS_INFO) << sdp_answer;
peer_connection_->SetLocalDescription(
std::move(answer),
rtc::make_ref_counted<
LambdaSetLocalDescriptionObserver>(
[answer_handler, sdp_answer](RTCError) {
answer_handler(sdp_answer);
}));
})
.get(),
PeerConnectionInterface::RTCOfferAnswerOptions());
}));
}
void PeerScenarioClient::SetSdpAnswer(

View File

@ -24,7 +24,8 @@ namespace test {
// For iOS, resource files are added to the application bundle in the root
// and not in separate folders as is the case for other platforms. This method
// therefore removes any prepended folders and uses only the actual file name.
std::string IOSResourcePath(absl::string_view name, absl::string_view extension) {
std::string IOSResourcePath(absl::string_view name,
absl::string_view extension) {
@autoreleasepool {
NSString* path = [NSString stringForAbslStringView:name];
NSString* fileName = path.lastPathComponent;
@ -46,11 +47,10 @@ std::string IOSRootPath() {
// For iOS, we don't have access to the output directory. Return the path to the
// temporary directory instead. This is mostly used by tests that need to write
// output files to disk.
std::string IOSOutputPath() {
std::string IOSOutputPath() {
@autoreleasepool {
NSString* tempDir = NSTemporaryDirectory();
if (tempDir == nil)
tempDir = @"/tmp";
if (tempDir == nil) tempDir = @"/tmp";
return [NSString stdStringForString:tempDir];
}
}

View File

@ -52,7 +52,7 @@ void SimulatedTaskQueue::RunReady(Timestamp at_time) {
}
CurrentTaskQueueSetter set_current(this);
while (!ready_tasks_.empty()) {
absl::AnyInvocable<void()&&> ready = std::move(ready_tasks_.front());
absl::AnyInvocable<void() &&> ready = std::move(ready_tasks_.front());
ready_tasks_.pop_front();
lock_.Unlock();
std::move(ready)();

View File

@ -1674,13 +1674,13 @@ VideoCodecTester::RunEncodeDecodeTest(
frame_settings.layers_settings.rbegin()->second;
VideoFrame source_frame = video_source.PullFrame(
timestamp_rtp, top_layer.resolution, top_layer.framerate);
encoder.Encode(source_frame, frame_settings,
[&decoders,
source_frame](const EncodedImage& encoded_frame) {
int sidx = encoded_frame.SpatialIndex().value_or(
encoded_frame.SimulcastIndex().value_or(0));
decoders.at(sidx)->Decode(encoded_frame, source_frame);
});
encoder.Encode(
source_frame, frame_settings,
[&decoders, source_frame](const EncodedImage& encoded_frame) {
int sidx = encoded_frame.SpatialIndex().value_or(
encoded_frame.SimulcastIndex().value_or(0));
decoders.at(sidx)->Decode(encoded_frame, source_frame);
});
}
encoder.Flush();