Skip to content

Commit 3d0c97e

Browse files
authored
Manage configuration for benchmarks and fuzz tests and fix them (#3335)
* Fix leveldb benchmarks ... which apparently haven't been built in a while * Manage configuration for Benchmarks and FuzzTests * Suppress warnings in LibFuzzer * Add a Firestore_Benchmarks_iOS scheme * xcodeproj: Remove manual configuration for Fuzzer and Benchmarks * Update LibFuzzer build for recent clangs Builds are currently failing with this on standard out: -fsanitize-coverage=trace-pc-guard is no longer supported by libFuzzer. Please either migrate to a compiler that supports -fsanitize=fuzzer or use an older version of libFuzzer
1 parent 9e0d8f4 commit 3d0c97e

File tree

5 files changed

+148
-139
lines changed

5 files changed

+148
-139
lines changed

Firestore/Example/Benchmarks/FSTLevelDBBenchmarkTests.mm

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,23 @@
2727
#include "Firestore/core/src/firebase/firestore/local/leveldb_transaction.h"
2828
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
2929
#include "Firestore/core/src/firebase/firestore/model/types.h"
30+
#include "Firestore/core/src/firebase/firestore/util/filesystem.h"
31+
#include "Firestore/core/src/firebase/firestore/util/path.h"
3032
#include "Firestore/core/src/firebase/firestore/util/string_format.h"
3133
#include "benchmark/benchmark.h"
3234

3335
NS_ASSUME_NONNULL_BEGIN
3436

37+
namespace util = firebase::firestore::util;
38+
using firebase::firestore::local::LevelDbDocumentTargetKey;
3539
using firebase::firestore::local::LevelDbRemoteDocumentKey;
3640
using firebase::firestore::local::LevelDbTargetDocumentKey;
3741
using firebase::firestore::local::LevelDbTransaction;
3842
using firebase::firestore::model::DatabaseId;
3943
using firebase::firestore::model::DocumentKey;
4044
using firebase::firestore::model::TargetId;
4145
using firebase::firestore::util::StringFormat;
46+
using firebase::firestore::util::Path;
4247

4348
namespace {
4449

@@ -53,33 +58,20 @@
5358
return std::string(documentSize, 'b');
5459
}
5560

56-
NSString *LevelDBDir() {
57-
NSFileManager *files = [NSFileManager defaultManager];
58-
NSString *dir =
59-
[NSTemporaryDirectory() stringByAppendingPathComponent:@"FSTPersistenceTestHelpers"];
60-
if ([files fileExistsAtPath:dir]) {
61-
// Delete the directory first to ensure isolation between runs.
62-
NSError *error;
63-
BOOL success = [files removeItemAtPath:dir error:&error];
64-
if (!success) {
65-
[NSException raise:NSInternalInconsistencyException
66-
format:@"Failed to clean up leveldb path %@: %@", dir, error];
67-
}
68-
}
69-
return dir;
70-
}
71-
7261
FSTLevelDB *LevelDBPersistence() {
73-
NSString *dir = LevelDBDir();
74-
auto remoteSerializer = [[FSTSerializerBeta alloc] initWithDatabaseID:DatabaseId("p", "d")];
62+
DatabaseId db_id("p", "d");
63+
auto remoteSerializer = [[FSTSerializerBeta alloc] initWithDatabaseID:db_id];
7564
auto serializer = [[FSTLocalSerializer alloc] initWithRemoteSerializer:remoteSerializer];
76-
auto db = [[FSTLevelDB alloc] initWithDirectory:dir serializer:serializer];
7765

78-
NSError *error;
79-
BOOL success = [db start:&error];
80-
if (!success) {
66+
FSTLevelDB *db;
67+
Path path = util::TempDir().AppendUtf8("FSTLevelDBBenchmarkTests");
68+
util::Status status = [FSTLevelDB dbWithDirectory:std::move(path)
69+
serializer:serializer
70+
lruParams:local::LruParams::Disabled()
71+
ptr:&db];
72+
if (!status.ok()) {
8173
[NSException raise:NSInternalInconsistencyException
82-
format:@"Failed to create leveldb path %@: %@", dir, error];
74+
format:@"Failed to open DB: %s", status.ToString().c_str()];
8375
}
8476

8577
return db;
@@ -94,6 +86,7 @@ void SetUp(benchmark::State &state) override {
9486
}
9587

9688
void TearDown(benchmark::State &state) override {
89+
[db_ shutdown];
9790
db_ = nil;
9891
}
9992

@@ -133,7 +126,7 @@ void WriteIndex(LevelDbTransaction *txn, const DocumentKey &docKey) {
133126
int64_t documentSize = state.range(1);
134127
int64_t docsToUpdate = state.range(2);
135128
std::string documentUpdate = UpdatedDocumentData(documentSize);
136-
for (const auto &_ : state) {
129+
for (auto _ : state) {
137130
LevelDbTransaction txn(db_.ptr, "benchmark");
138131
for (int i = 0; i < docsToUpdate; i++) {
139132
auto docKey = DocumentKey::FromPathString(StringFormat("docs/doc_%i", i));

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -4107,55 +4107,8 @@
41074107
DEVELOPMENT_TEAM = EQHXZ8M8AV;
41084108
GCC_PRECOMPILE_PREFIX_HEADER = YES;
41094109
GCC_PREFIX_HEADER = "";
4110-
GCC_PREPROCESSOR_DEFINITIONS = (
4111-
"$(inherited)",
4112-
"COCOAPODS=1",
4113-
"GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1",
4114-
);
4115-
INFOPLIST_FILE = Benchmarks/Info.plist;
4116-
OTHER_CFLAGS = (
4117-
"$(inherited)",
4118-
"-iquote",
4119-
"\"${PODS_CONFIGURATION_BUILD_DIR}/GoogleTest/GoogleTest.framework/Headers\"",
4120-
"-iquote",
4121-
"\"${PODS_CONFIGURATION_BUILD_DIR}/OCMock/OCMock.framework/Headers\"",
4122-
"-iquote",
4123-
"\"${PODS_CONFIGURATION_BUILD_DIR}/ProtobufCpp/ProtobufCpp.framework/Headers\"",
4124-
"-iquote",
4125-
"\"${PODS_CONFIGURATION_BUILD_DIR}/leveldb-library/leveldb.framework/Headers\"",
4126-
"$(inherited)",
4127-
"-iquote",
4128-
"\"${PODS_CONFIGURATION_BUILD_DIR}/BoringSSL/openssl.framework/Headers\"",
4129-
"-iquote",
4130-
"\"${PODS_CONFIGURATION_BUILD_DIR}/FirebaseAuth/FirebaseAuth.framework/Headers\"",
4131-
"-iquote",
4132-
"\"${PODS_CONFIGURATION_BUILD_DIR}/FirebaseCore/FirebaseCore.framework/Headers\"",
4133-
"-iquote",
4134-
"\"${PODS_CONFIGURATION_BUILD_DIR}/FirebaseFirestore/FirebaseFirestore.framework/Headers\"",
4135-
"-iquote",
4136-
"\"${PODS_CONFIGURATION_BUILD_DIR}/GTMSessionFetcher/GTMSessionFetcher.framework/Headers\"",
4137-
"-iquote",
4138-
"\"${PODS_CONFIGURATION_BUILD_DIR}/GoogleToolboxForMac/GoogleToolboxForMac.framework/Headers\"",
4139-
"-iquote",
4140-
"\"${PODS_CONFIGURATION_BUILD_DIR}/Protobuf/Protobuf.framework/Headers\"",
4141-
"-iquote",
4142-
"\"${PODS_CONFIGURATION_BUILD_DIR}/leveldb-library/leveldb.framework/Headers\"",
4143-
"-iquote",
4144-
"\"${PODS_CONFIGURATION_BUILD_DIR}/nanopb/nanopb.framework/Headers\"",
4145-
"-isystem",
4146-
"\"${PODS_ROOT}/Headers/Public\"",
4147-
"-isystem",
4148-
"\"${PODS_ROOT}/Headers/Public/Firebase\"",
4149-
"-isystem",
4150-
"\"${PODS_ROOT}/Headers/Public/FirebaseAnalytics\"",
4151-
"-isystem",
4152-
"\"${PODS_ROOT}/Headers/Public/FirebaseInstanceID\"",
4153-
"-DPB_FIELD_32BIT",
4154-
"-DPB_NO_PACKED_STRUCTS=1",
4155-
);
41564110
PRODUCT_BUNDLE_IDENTIFIER = "Firebase.Firestore-Benchmarks-iOS";
41574111
PRODUCT_NAME = "$(TARGET_NAME)";
4158-
SYSTEM_HEADER_SEARCH_PATHS = "\"${PODS_ROOT}/nanopb\"";
41594112
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Firestore_Example_iOS.app/Firestore_Example_iOS";
41604113
};
41614114
name = Debug;
@@ -4168,55 +4121,8 @@
41684121
DEVELOPMENT_TEAM = EQHXZ8M8AV;
41694122
GCC_PRECOMPILE_PREFIX_HEADER = YES;
41704123
GCC_PREFIX_HEADER = "";
4171-
GCC_PREPROCESSOR_DEFINITIONS = (
4172-
"$(inherited)",
4173-
"COCOAPODS=1",
4174-
"GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1",
4175-
);
4176-
INFOPLIST_FILE = Benchmarks/Info.plist;
4177-
OTHER_CFLAGS = (
4178-
"$(inherited)",
4179-
"-iquote",
4180-
"\"${PODS_CONFIGURATION_BUILD_DIR}/GoogleTest/GoogleTest.framework/Headers\"",
4181-
"-iquote",
4182-
"\"${PODS_CONFIGURATION_BUILD_DIR}/OCMock/OCMock.framework/Headers\"",
4183-
"-iquote",
4184-
"\"${PODS_CONFIGURATION_BUILD_DIR}/ProtobufCpp/ProtobufCpp.framework/Headers\"",
4185-
"-iquote",
4186-
"\"${PODS_CONFIGURATION_BUILD_DIR}/leveldb-library/leveldb.framework/Headers\"",
4187-
"$(inherited)",
4188-
"-iquote",
4189-
"\"${PODS_CONFIGURATION_BUILD_DIR}/BoringSSL/openssl.framework/Headers\"",
4190-
"-iquote",
4191-
"\"${PODS_CONFIGURATION_BUILD_DIR}/FirebaseAuth/FirebaseAuth.framework/Headers\"",
4192-
"-iquote",
4193-
"\"${PODS_CONFIGURATION_BUILD_DIR}/FirebaseCore/FirebaseCore.framework/Headers\"",
4194-
"-iquote",
4195-
"\"${PODS_CONFIGURATION_BUILD_DIR}/FirebaseFirestore/FirebaseFirestore.framework/Headers\"",
4196-
"-iquote",
4197-
"\"${PODS_CONFIGURATION_BUILD_DIR}/GTMSessionFetcher/GTMSessionFetcher.framework/Headers\"",
4198-
"-iquote",
4199-
"\"${PODS_CONFIGURATION_BUILD_DIR}/GoogleToolboxForMac/GoogleToolboxForMac.framework/Headers\"",
4200-
"-iquote",
4201-
"\"${PODS_CONFIGURATION_BUILD_DIR}/Protobuf/Protobuf.framework/Headers\"",
4202-
"-iquote",
4203-
"\"${PODS_CONFIGURATION_BUILD_DIR}/leveldb-library/leveldb.framework/Headers\"",
4204-
"-iquote",
4205-
"\"${PODS_CONFIGURATION_BUILD_DIR}/nanopb/nanopb.framework/Headers\"",
4206-
"-isystem",
4207-
"\"${PODS_ROOT}/Headers/Public\"",
4208-
"-isystem",
4209-
"\"${PODS_ROOT}/Headers/Public/Firebase\"",
4210-
"-isystem",
4211-
"\"${PODS_ROOT}/Headers/Public/FirebaseAnalytics\"",
4212-
"-isystem",
4213-
"\"${PODS_ROOT}/Headers/Public/FirebaseInstanceID\"",
4214-
"-DPB_FIELD_32BIT",
4215-
"-DPB_NO_PACKED_STRUCTS=1",
4216-
);
42174124
PRODUCT_BUNDLE_IDENTIFIER = "Firebase.Firestore-Benchmarks-iOS";
42184125
PRODUCT_NAME = "$(TARGET_NAME)";
4219-
SYSTEM_HEADER_SEARCH_PATHS = "\"${PODS_ROOT}/nanopb\"";
42204126
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Firestore_Example_iOS.app/Firestore_Example_iOS";
42214127
};
42224128
name = Release;
@@ -4501,16 +4407,6 @@
45014407
DEVELOPMENT_TEAM = EQHXZ8M8AV;
45024408
GCC_PRECOMPILE_PREFIX_HEADER = YES;
45034409
GCC_PREFIX_HEADER = "";
4504-
GCC_PREPROCESSOR_DEFINITIONS = (
4505-
"$(inherited)",
4506-
"COCOAPODS=1",
4507-
"GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1",
4508-
);
4509-
INFOPLIST_FILE = "FuzzTests/Firestore_FuzzTests_iOS-Info.plist";
4510-
OTHER_CFLAGS = (
4511-
"$(inherited)",
4512-
"-fsanitize-coverage=trace-pc-guard",
4513-
);
45144410
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}";
45154411
PRODUCT_NAME = "$(TARGET_NAME)";
45164412
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Firestore_Example_iOS.app/Firestore_Example_iOS";
@@ -4526,16 +4422,6 @@
45264422
DEVELOPMENT_TEAM = EQHXZ8M8AV;
45274423
GCC_PRECOMPILE_PREFIX_HEADER = YES;
45284424
GCC_PREFIX_HEADER = "";
4529-
GCC_PREPROCESSOR_DEFINITIONS = (
4530-
"$(inherited)",
4531-
"COCOAPODS=1",
4532-
"GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1",
4533-
);
4534-
INFOPLIST_FILE = "FuzzTests/Firestore_FuzzTests_iOS-Info.plist";
4535-
OTHER_CFLAGS = (
4536-
"$(inherited)",
4537-
"-fsanitize-coverage=trace-pc-guard",
4538-
);
45394425
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}";
45404426
PRODUCT_NAME = "$(TARGET_NAME)";
45414427
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Firestore_Example_iOS.app/Firestore_Example_iOS";
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1010"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "NO"
12+
buildForProfiling = "NO"
13+
buildForArchiving = "NO"
14+
buildForAnalyzing = "NO">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "6003F589195388D20070C39A"
18+
BuildableName = "Firestore_Example_iOS.app"
19+
BlueprintName = "Firestore_Example_iOS"
20+
ReferencedContainer = "container:Firestore.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
<BuildActionEntry
24+
buildForTesting = "YES"
25+
buildForRunning = "YES"
26+
buildForProfiling = "YES"
27+
buildForArchiving = "YES"
28+
buildForAnalyzing = "YES">
29+
<BuildableReference
30+
BuildableIdentifier = "primary"
31+
BlueprintIdentifier = "5CAE131820FFFED600BE9A4A"
32+
BuildableName = "Firestore_Benchmarks_iOS.xctest"
33+
BlueprintName = "Firestore_Benchmarks_iOS"
34+
ReferencedContainer = "container:Firestore.xcodeproj">
35+
</BuildableReference>
36+
</BuildActionEntry>
37+
</BuildActionEntries>
38+
</BuildAction>
39+
<TestAction
40+
buildConfiguration = "Debug"
41+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
42+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
43+
shouldUseLaunchSchemeArgsEnv = "YES">
44+
<Testables>
45+
<TestableReference
46+
skipped = "NO">
47+
<BuildableReference
48+
BuildableIdentifier = "primary"
49+
BlueprintIdentifier = "5CAE131820FFFED600BE9A4A"
50+
BuildableName = "Firestore_Benchmarks_iOS.xctest"
51+
BlueprintName = "Firestore_Benchmarks_iOS"
52+
ReferencedContainer = "container:Firestore.xcodeproj">
53+
</BuildableReference>
54+
</TestableReference>
55+
</Testables>
56+
<MacroExpansion>
57+
<BuildableReference
58+
BuildableIdentifier = "primary"
59+
BlueprintIdentifier = "5CAE131820FFFED600BE9A4A"
60+
BuildableName = "Firestore_Benchmarks_iOS.xctest"
61+
BlueprintName = "Firestore_Benchmarks_iOS"
62+
ReferencedContainer = "container:Firestore.xcodeproj">
63+
</BuildableReference>
64+
</MacroExpansion>
65+
<AdditionalOptions>
66+
</AdditionalOptions>
67+
</TestAction>
68+
<LaunchAction
69+
buildConfiguration = "Debug"
70+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
71+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
72+
launchStyle = "0"
73+
useCustomWorkingDirectory = "NO"
74+
ignoresPersistentStateOnLaunch = "NO"
75+
debugDocumentVersioning = "YES"
76+
debugServiceExtension = "internal"
77+
allowLocationSimulation = "YES">
78+
<MacroExpansion>
79+
<BuildableReference
80+
BuildableIdentifier = "primary"
81+
BlueprintIdentifier = "5CAE131820FFFED600BE9A4A"
82+
BuildableName = "Firestore_Benchmarks_iOS.xctest"
83+
BlueprintName = "Firestore_Benchmarks_iOS"
84+
ReferencedContainer = "container:Firestore.xcodeproj">
85+
</BuildableReference>
86+
</MacroExpansion>
87+
<AdditionalOptions>
88+
</AdditionalOptions>
89+
</LaunchAction>
90+
<ProfileAction
91+
buildConfiguration = "Release"
92+
shouldUseLaunchSchemeArgsEnv = "YES"
93+
savedToolIdentifier = ""
94+
useCustomWorkingDirectory = "NO"
95+
debugDocumentVersioning = "YES">
96+
<MacroExpansion>
97+
<BuildableReference
98+
BuildableIdentifier = "primary"
99+
BlueprintIdentifier = "5CAE131820FFFED600BE9A4A"
100+
BuildableName = "Firestore_Benchmarks_iOS.xctest"
101+
BlueprintName = "Firestore_Benchmarks_iOS"
102+
ReferencedContainer = "container:Firestore.xcodeproj">
103+
</BuildableReference>
104+
</MacroExpansion>
105+
</ProfileAction>
106+
<AnalyzeAction
107+
buildConfiguration = "Debug">
108+
</AnalyzeAction>
109+
<ArchiveAction
110+
buildConfiguration = "Release"
111+
revealArchiveInOrganizer = "YES">
112+
</ArchiveAction>
113+
</Scheme>

Firestore/Example/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ target 'Firestore_Example_iOS' do
6565
inherit! :search_paths
6666
platform :ios, '9.0'
6767

68-
pod 'LibFuzzer', :podspec => 'LibFuzzer.podspec'
68+
pod 'LibFuzzer', :podspec => 'LibFuzzer.podspec', :inhibit_warnings => true
6969
pod '!ProtoCompiler'
7070
end
7171
end

scripts/sync_project.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,23 @@ def sync_firestore(test_only)
188188
t.xcconfig = xcconfig_objc + xcconfig_swift
189189
end
190190

191+
s.target 'Firestore_Benchmarks_iOS' do |t|
192+
t.xcconfig = xcconfig_objc + {
193+
'INFOPLIST_FILE' => '${SRCROOT}/Benchmarks/Info.plist',
194+
}
195+
end
196+
197+
s.target 'Firestore_FuzzTests_iOS' do |t|
198+
t.xcconfig = xcconfig_objc + {
199+
'INFOPLIST_FILE' =>
200+
'${SRCROOT}/FuzzTests/Firestore_FuzzTests_iOS-Info.plist',
201+
'OTHER_CFLAGS' => [
202+
'-fsanitize=fuzzer',
203+
]
204+
}
205+
206+
end
207+
191208
s.target 'Firestore_SwiftTests_iOS' do |t|
192209
t.xcconfig = xcconfig_objc + xcconfig_swift
193210
end

0 commit comments

Comments
 (0)