From 79c21b1bf51b949d76c6bce142e38b36659af5ba Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Mon, 5 Dec 2022 21:05:58 +0100 Subject: [PATCH] Ensure --webrtc_test_metrics_output_path is a file name on iOS. Bug: b/237982523 Change-Id: I5671e311fe14d7bcdd389626b6e11245d19d62c4 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/286425 Reviewed-by: Jeremy Leconte Commit-Queue: Mirko Bonadei Cr-Commit-Position: refs/heads/main@{#38819} --- test/ios/test_support.mm | 18 ++++++++++++------ test/test_flags.cc | 3 ++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/test/ios/test_support.mm b/test/ios/test_support.mm index 8586f4673f..bb8532b680 100644 --- a/test/ios/test_support.mm +++ b/test/ios/test_support.mm @@ -97,14 +97,14 @@ static absl::optional> g_metrics_to_plot; int exitStatus = g_test_suite(); + NSArray *outputDirectories = + NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); std::vector> exporters; if (g_export_perf_results_new_api) { exporters.push_back(std::make_unique()); if (g_write_perf_output) { // Stores data into a proto file under the app's document directory. NSString *fileName = @"perftest-output.pb"; - NSArray *outputDirectories = - NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); if ([outputDirectories count] != 0) { NSString *outputPath = [outputDirectories[0] stringByAppendingPathComponent:fileName]; @@ -113,8 +113,16 @@ static absl::optional> g_metrics_to_plot; } } if (!g_webrtc_test_metrics_output_path.empty()) { - exporters.push_back(std::make_unique( - webrtc::test::MetricsSetProtoFileExporter::Options(g_webrtc_test_metrics_output_path))); + RTC_CHECK_NE(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::Options( + [NSString stdStringForString:outputPath]))); + } } } else { exporters.push_back(std::make_unique()); @@ -124,8 +132,6 @@ static absl::optional> g_metrics_to_plot; if (g_write_perf_output) { // Stores data into a proto file under the app's document directory. NSString *fileName = @"perftest-output.pb"; - NSArray *outputDirectories = - NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); if ([outputDirectories count] != 0) { NSString *outputPath = [outputDirectories[0] stringByAppendingPathComponent:fileName]; diff --git a/test/test_flags.cc b/test/test_flags.cc index 5e8ba32e42..a0fff747fe 100644 --- a/test/test_flags.cc +++ b/test/test_flags.cc @@ -42,7 +42,8 @@ ABSL_FLAG(std::string, "", "Path where the test perf metrics should be stored using " "api/test/metrics/metric.proto proto format. File will contain " - "MetricsSet as a root proto"); + "MetricsSet as a root proto. On iOS, this MUST be a file name " + "and the file will be stored under NSDocumentDirectory."); ABSL_FLAG(bool, export_perf_results_new_api,