Skip to content

Commit 96773db

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
[format] Apply auto-formatting
Bug: 430616180 Change-Id: I12f41e8c87913481f05f3bf350acdb88ac08c163 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/9155818 Commit-Queue: Matthias Liedtke <mliedtke@google.com> Reviewed-by: Michael Achenbach <machenbach@google.com>
1 parent c523132 commit 96773db

File tree

134 files changed

+20842
-13162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+20842
-13162
lines changed

Package.swift

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import PackageDescription
1919
let package = Package(
2020
name: "Fuzzilli",
2121
platforms: [
22-
.macOS(.v13),
22+
.macOS(.v13)
2323
],
2424
products: [
25-
.library(name: "Fuzzilli",targets: ["Fuzzilli"]),
25+
.library(name: "Fuzzilli", targets: ["Fuzzilli"])
2626
],
2727
dependencies: [
2828
// We use an exact version here as we also use this version to generate the .pb.swift to
@@ -31,62 +31,74 @@ let package = Package(
3131
// regenerated, whenever the version is bumped.
3232
.package(url: "https://github.com/apple/swift-protobuf.git", exact: "1.35.0"),
3333
.package(
34-
url: "https://github.com/apple/swift-collections.git",
35-
.upToNextMinor(from: "1.2.0")
34+
url: "https://github.com/apple/swift-collections.git",
35+
.upToNextMinor(from: "1.2.0")
3636
),
3737
],
3838
targets: [
39-
.target(name: "libsocket",
40-
dependencies: []),
39+
.target(
40+
name: "libsocket",
41+
dependencies: []),
4142

42-
.target(name: "libreprl",
43-
dependencies: []),
43+
.target(
44+
name: "libreprl",
45+
dependencies: []),
4446

45-
.target(name: "libcoverage",
46-
dependencies: [],
47-
cSettings: [.unsafeFlags(["-O3"])], // Using '-c release' when building uses '-O2', so '-O3' provides a performance gain
48-
linkerSettings: [.linkedLibrary("rt", .when(platforms: [.linux]))]),
47+
.target(
48+
name: "libcoverage",
49+
dependencies: [],
50+
cSettings: [.unsafeFlags(["-O3"])], // Using '-c release' when building uses '-O2', so '-O3' provides a performance gain
51+
linkerSettings: [.linkedLibrary("rt", .when(platforms: [.linux]))]),
4952

50-
.target(name: "Fuzzilli",
51-
dependencies: [
52-
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
53-
.product(name: "Collections", package: "swift-collections"),
54-
"libsocket",
55-
"libreprl",
56-
"libcoverage"],
57-
exclude: [
58-
"Protobuf/operations.proto",
59-
"Protobuf/program.proto",
60-
"Protobuf/sync.proto",
61-
"Protobuf/README.md",
62-
"Protobuf/gen_programproto.py"],
63-
resources: [
64-
// The ast.proto file is required by the node.js parser
65-
.copy("Protobuf/ast.proto"),
66-
.copy("Compiler/Parser")]),
53+
.target(
54+
name: "Fuzzilli",
55+
dependencies: [
56+
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
57+
.product(name: "Collections", package: "swift-collections"),
58+
"libsocket",
59+
"libreprl",
60+
"libcoverage",
61+
],
62+
exclude: [
63+
"Protobuf/operations.proto",
64+
"Protobuf/program.proto",
65+
"Protobuf/sync.proto",
66+
"Protobuf/README.md",
67+
"Protobuf/gen_programproto.py",
68+
],
69+
resources: [
70+
// The ast.proto file is required by the node.js parser
71+
.copy("Protobuf/ast.proto"),
72+
.copy("Compiler/Parser"),
73+
]),
6774

68-
.executableTarget(name: "REPRLRun",
69-
dependencies: ["libreprl"]),
75+
.executableTarget(
76+
name: "REPRLRun",
77+
dependencies: ["libreprl"]),
7078

71-
.executableTarget(name: "FuzzilliCli",
72-
dependencies: ["Fuzzilli"]),
79+
.executableTarget(
80+
name: "FuzzilliCli",
81+
dependencies: ["Fuzzilli"]),
7382

74-
.executableTarget(name: "FuzzILTool",
75-
dependencies: ["Fuzzilli"]),
83+
.executableTarget(
84+
name: "FuzzILTool",
85+
dependencies: ["Fuzzilli"]),
7686

7787
// Tool that runs d8 in Dumpling mode. First time it runs with Maglev
7888
// and Turbofan. Second time without. In both runs frames are dumped
7989
// in certain points to the files. The dumps are later compared for
8090
// equality. If they are not equal, it means that there's likely a bug
8191
// in V8.
82-
.executableTarget(name: "RelateTool",
83-
dependencies: ["Fuzzilli"]),
92+
.executableTarget(
93+
name: "RelateTool",
94+
dependencies: ["Fuzzilli"]),
8495

8596
.executableTarget(name: "FuzzilliDetectMissingBuiltins", dependencies: ["Fuzzilli"]),
8697

87-
.testTarget(name: "FuzzilliTests",
88-
dependencies: ["Fuzzilli"],
89-
resources: [.copy("CompilerTests")]),
98+
.testTarget(
99+
name: "FuzzilliTests",
100+
dependencies: ["Fuzzilli"],
101+
resources: [.copy("CompilerTests")]),
90102
],
91103
swiftLanguageVersions: [.v5]
92104
)

Sources/FuzzILTool/main.swift

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func loadProgram(from path: String) throws -> Program {
3333

3434
func loadAllPrograms(in dirPath: String) -> [(filename: String, program: Program)] {
3535
var isDir: ObjCBool = false
36-
if !FileManager.default.fileExists(atPath: dirPath, isDirectory:&isDir) || !isDir.boolValue {
36+
if !FileManager.default.fileExists(atPath: dirPath, isDirectory: &isDir) || !isDir.boolValue {
3737
print("\(dirPath) is not a directory!")
3838
exit(-1)
3939
}
@@ -56,7 +56,7 @@ func loadAllPrograms(in dirPath: String) -> [(filename: String, program: Program
5656
}
5757

5858
// Takes a program and lifts it to JavaScript.
59-
func liftToJS(_ jsLifter: JavaScriptLifter,_ prog: Program) -> String {
59+
func liftToJS(_ jsLifter: JavaScriptLifter, _ prog: Program) -> String {
6060
let res = jsLifter.lift(prog)
6161
return res.trimmingCharacters(in: .whitespacesAndNewlines)
6262
}
@@ -72,10 +72,13 @@ func liftToFuzzIL(_ prog: Program) -> String {
7272
func liftAllPrograms(in dirPath: String, with lifter: Lifter, fileExtension: String) -> Int {
7373
var numLiftedPrograms = 0
7474
for (filename, program) in loadAllPrograms(in: dirPath) {
75-
let newFilePath = "\(dirPath)/\(filename.dropLast(protoBufFileExtension.count))\(fileExtension)"
75+
let newFilePath =
76+
"\(dirPath)/\(filename.dropLast(protoBufFileExtension.count))\(fileExtension)"
7677
let content = lifter.lift(program)
7778
do {
78-
try content.write(to: URL(fileURLWithPath: newFilePath), atomically: false, encoding: String.Encoding.utf8)
79+
try content.write(
80+
to: URL(fileURLWithPath: newFilePath), atomically: false,
81+
encoding: String.Encoding.utf8)
7982
numLiftedPrograms += 1
8083
} catch {
8184
print("Failed to write file \(newFilePath): \(error)")
@@ -96,29 +99,32 @@ func loadProgramOrExit(from path: String) -> Program {
9699
let args = Arguments.parse(from: CommandLine.arguments)
97100

98101
if args["-h"] != nil || args["--help"] != nil || args.numPositionalArguments != 1 {
99-
print("""
100-
Usage:
101-
\(args.programName) options path
102-
103-
Options:
104-
--liftToFuzzIL : Lifts the given protobuf program to FuzzIL's text format and prints it
105-
--liftToJS : Lifts the given protobuf program to JS and prints it
106-
--liftCorpusToJS : Loads all .fzil files in a directory and lifts them to .js files in that same directory
107-
--dumpProtobuf : Dumps the raw content of the given protobuf file
108-
--dumpProgram : Dumps the internal representation of the program stored in the given protobuf file
109-
--checkCorpus : Attempts to load all .fzil files in a directory and checks if they are statically valid
110-
--compile : Compile the given JavaScript program to a FuzzIL program. Requires node.js
111-
--outputPathJS : If given, --compile will write the lifted JS file to the given path after compilation.
112-
--generate : Generate a random program using Fuzzilli's code generators and save it to the specified path.
113-
--forDifferentialFuzzing : Enable additional features for better support of external differential fuzzing.
114-
""")
102+
print(
103+
"""
104+
Usage:
105+
\(args.programName) options path
106+
107+
Options:
108+
--liftToFuzzIL : Lifts the given protobuf program to FuzzIL's text format and prints it
109+
--liftToJS : Lifts the given protobuf program to JS and prints it
110+
--liftCorpusToJS : Loads all .fzil files in a directory and lifts them to .js files in that same directory
111+
--dumpProtobuf : Dumps the raw content of the given protobuf file
112+
--dumpProgram : Dumps the internal representation of the program stored in the given protobuf file
113+
--checkCorpus : Attempts to load all .fzil files in a directory and checks if they are statically valid
114+
--compile : Compile the given JavaScript program to a FuzzIL program. Requires node.js
115+
--outputPathJS : If given, --compile will write the lifted JS file to the given path after compilation.
116+
--generate : Generate a random program using Fuzzilli's code generators and save it to the specified path.
117+
--forDifferentialFuzzing : Enable additional features for better support of external differential fuzzing.
118+
""")
115119
exit(0)
116120
}
117121

118122
let path = args[0]
119123

120124
let forDifferentialFuzzing = args.has("--forDifferentialFuzzing")
121-
let jsLifter = JavaScriptLifter(prefix: jsPrefix, suffix: jsSuffix, ecmaVersion: ECMAScriptVersion.es6, environment: JavaScriptEnvironment(), alwaysEmitVariables: forDifferentialFuzzing)
125+
let jsLifter = JavaScriptLifter(
126+
prefix: jsPrefix, suffix: jsSuffix, ecmaVersion: ECMAScriptVersion.es6,
127+
environment: JavaScriptEnvironment(), alwaysEmitVariables: forDifferentialFuzzing)
122128

123129
// Covert a single IL protobuf file to FuzzIL's text format and print to stdout
124130
if args.has("--liftToFuzzIL") {
@@ -134,7 +140,8 @@ else if args.has("--liftToJS") {
134140

135141
// Lift all protobuf programs to JavaScript
136142
else if args.has("--liftCorpusToJS") {
137-
let numLiftedPrograms = liftAllPrograms(in: path, with: jsLifter, fileExtension: jsFileExtension)
143+
let numLiftedPrograms = liftAllPrograms(
144+
in: path, with: jsLifter, fileExtension: jsFileExtension)
138145
print("Lifted \(numLiftedPrograms) programs to JS")
139146
}
140147

@@ -166,7 +173,9 @@ else if args.has("--compile") {
166173
exit(-1)
167174
}
168175
guard let parser = JavaScriptParser(executor: nodejs) else {
169-
print("The JavaScript parser does not appear to be working. See Sources/Fuzzilli/Compiler/Parser/README.md for instructions on how to set it up.")
176+
print(
177+
"The JavaScript parser does not appear to be working. See Sources/Fuzzilli/Compiler/Parser/README.md for instructions on how to set it up."
178+
)
170179
exit(-1)
171180
}
172181

@@ -194,7 +203,9 @@ else if args.has("--compile") {
194203
if let js_path = args["--outputPathJS"] {
195204
let content = ast.leadingComments + jsLifter.lift(program)
196205
do {
197-
try content.write(to: URL(fileURLWithPath: js_path), atomically: false, encoding: String.Encoding.utf8)
206+
try content.write(
207+
to: URL(fileURLWithPath: js_path), atomically: false, encoding: String.Encoding.utf8
208+
)
198209
} catch {
199210
print("Failed to write file \(js_path): \(error)")
200211
exit(-1)
@@ -205,7 +216,8 @@ else if args.has("--compile") {
205216
print(jsLifter.lift(program))
206217

207218
do {
208-
let outputPath = URL(fileURLWithPath: path).deletingPathExtension().appendingPathExtension("fzil")
219+
let outputPath = URL(fileURLWithPath: path).deletingPathExtension()
220+
.appendingPathExtension("fzil")
209221
try program.asProtobuf().serializedData().write(to: outputPath)
210222
print("FuzzIL program written to \(outputPath.relativePath)")
211223
} catch {
@@ -216,7 +228,9 @@ else if args.has("--compile") {
216228
}
217229

218230
else if args.has("--generate") {
219-
let fuzzer = makeMockFuzzer(config: Configuration(logLevel: .warning, enableInspection: true), environment: JavaScriptEnvironment())
231+
let fuzzer = makeMockFuzzer(
232+
config: Configuration(logLevel: .warning, enableInspection: true),
233+
environment: JavaScriptEnvironment())
220234
let b = fuzzer.makeBuilder()
221235
b.buildPrefix()
222236
b.build(n: 50, by: .generating)
@@ -225,7 +239,8 @@ else if args.has("--generate") {
225239
print(jsLifter.lift(program, withOptions: .includeComments))
226240

227241
do {
228-
let outputPath = URL(fileURLWithPath: path).deletingPathExtension().appendingPathExtension("fzil")
242+
let outputPath = URL(fileURLWithPath: path).deletingPathExtension().appendingPathExtension(
243+
"fzil")
229244
try program.asProtobuf().serializedData().write(to: outputPath)
230245
} catch {
231246
print("Failed to store output program to disk: \(error)")

Sources/Fuzzilli/Base/ContextGraph.swift

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,25 @@ public class ContextGraph {
7979
for i in 1..<generator.parts.count {
8080
let stub = generator.parts[i]
8181

82-
guard stub.requiredContext.matches(currentContext) ||
83-
(stub.requiredContext.isJavascript && currentContext.isEmpty) ||
84-
// If the requiredContext is more than two, we should never provide a context.
85-
// See `CodeGenerator` for details.
86-
(!stub.requiredContext.isSingle && currentContext.isEmpty) else {
82+
guard
83+
stub.requiredContext.matches(currentContext)
84+
|| (stub.requiredContext.isJavascript && currentContext.isEmpty)
85+
// If the requiredContext is more than two, we should never provide a context.
86+
// See `CodeGenerator` for details.
87+
|| (!stub.requiredContext.isSingle && currentContext.isEmpty)
88+
else {
8789
fatalError("Inconsistent requires/provides Contexts for \(generator.name)")
8890
}
8991

90-
currentContext = stub.providedContext.isEmpty ? currentContext : Context(stub.providedContext)
92+
currentContext =
93+
stub.providedContext.isEmpty ? currentContext : Context(stub.providedContext)
9194
}
9295
}
9396
}
9497

95-
private func warnOfSuspiciousContexts(in generators: WeightedList<CodeGenerator>, withLogger logger: Logger) {
98+
private func warnOfSuspiciousContexts(
99+
in generators: WeightedList<CodeGenerator>, withLogger logger: Logger
100+
) {
96101
// Technically we don't need any generator to emit the .javascript context, as this is provided by the toplevel.
97102
var providedContexts = Set<Context>([.javascript])
98103
var requiredContexts = Set<Context>()
@@ -107,15 +112,19 @@ public class ContextGraph {
107112
for generator in generators {
108113
// Now check which generators don't have providers
109114
if !providedContexts.contains(generator.requiredContext) {
110-
logger.warning("Generator \(generator.name) cannot be run as it doesn't have a Generator that can provide this context.")
115+
logger.warning(
116+
"Generator \(generator.name) cannot be run as it doesn't have a Generator that can provide this context."
117+
)
111118

112119
}
113120

114121
// All provided contexts must be required by some generator.
115122
if !generator.providedContexts.allSatisfy({
116123
requiredContexts.contains($0)
117124
}) {
118-
logger.warning("Generator \(generator.name) provides a context that is never required by another generator \(generator.providedContexts)")
125+
logger.warning(
126+
"Generator \(generator.name) provides a context that is never required by another generator \(generator.providedContexts)"
127+
)
119128
}
120129
}
121130
}
@@ -139,7 +148,8 @@ public class ContextGraph {
139148
}
140149

141150
// Get all possible edges from here on and push all of those to the queue.
142-
for edge in self.edges where edge.key.from == currentNode && !seenNodes.contains(edge.key.to) {
151+
for edge in self.edges
152+
where edge.key.from == currentNode && !seenNodes.contains(edge.key.to) {
143153
// Prevent cycles, we don't care about complicated paths, but rather simple direct paths.
144154
seenNodes.insert(edge.key.to)
145155
queue.append(currentPath + [edge.key.to])
@@ -155,7 +165,7 @@ public class ContextGraph {
155165
for path in paths {
156166
var edgePath: [EdgeKey] = []
157167
for i in 0..<(path.count - 1) {
158-
let edge = EdgeKey(from: path[i], to: path[i+1])
168+
let edge = EdgeKey(from: path[i], to: path[i + 1])
159169
edgePath.append(edge)
160170
}
161171
edgePaths.append(edgePath)
@@ -185,7 +195,8 @@ public class ContextGraph {
185195
var stillExploring = false
186196

187197
// Get all possible edges from here on and push all of those to the queue.
188-
for edge in self.edges where edge.key.from == currentNode && !seenNodes.contains(edge.key.to) {
198+
for edge in self.edges
199+
where edge.key.from == currentNode && !seenNodes.contains(edge.key.to) {
189200
// Prevent cycles, we don't care about complicated paths, but rather simple direct paths.
190201
stillExploring = true
191202
seenNodes.insert(edge.key.to)
@@ -220,9 +231,10 @@ public class ContextGraph {
220231
}
221232

222233
return paths.map { edges in
223-
Path(edges: edges.map { edge in
224-
self.edges[edge]!
225-
})
234+
Path(
235+
edges: edges.map { edge in
236+
self.edges[edge]!
237+
})
226238
}
227239
}
228240
}

Sources/Fuzzilli/Base/Contributor.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public class Contributor: Hashable {
9393
}
9494

9595
public var totalSamples: Int {
96-
return validSamples + interestingSamples + invalidSamples + timedOutSamples + crashingSamples + differentialSamples
96+
return validSamples + interestingSamples + invalidSamples + timedOutSamples
97+
+ crashingSamples + differentialSamples
9798
}
9899

99100
// If this is low, that means the CodeGenerator has dynamic requirements that are not met most of the time.

0 commit comments

Comments
 (0)