Skip to content

Commit 1204148

Browse files
cjx10jimch0i
andauthored
Change JCC error log location and upload (google#11789)
Upload `JCC`'s error log to assist `OSS-Fuzz-Gen` analyzing and classifying build errors: 1. Change JCC `err.log` location, because`/out` was removed before `compile` by default and `err.log` cannot be saved there. 2. Add a step in `target_experiment.py` to upload `err.log` to gcloud bucket. --------- Co-authored-by: Jim Choi <[email protected]>
1 parent c2c0632 commit 1204148

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

infra/base-images/base-builder/jcc/jcc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ func WriteStdErrOut(outstr string, errstr string) {
357357
// Prints |outstr| to stdout, prints |errstr| to stderr, and saves |errstr| to err.log.
358358
fmt.Print(outstr)
359359
fmt.Fprint(os.Stderr, errstr)
360-
AppendStringToFile("/out/err.log", errstr)
360+
AppendStringToFile("/workspace/err.log", errstr)
361361
}
362362

363363
func main() {

infra/build/functions/target_experiment.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
JCC_DIR = '/usr/local/bin'
2929

3030

31-
def run_experiment(project_name, target_name, args, output_path,
31+
def run_experiment(project_name, target_name, args, output_path, errlog_path,
3232
build_output_path, upload_corpus_path, upload_coverage_path,
3333
experiment_name, upload_reproducer_path):
3434
config = build_project.Config(testing=True,
@@ -72,6 +72,7 @@ def run_experiment(project_name, target_name, args, output_path,
7272

7373
build = build_project.Build('libfuzzer', 'address', 'x86_64')
7474
local_output_path = '/workspace/output.log'
75+
local_jcc_err_path = '/workspace/err.log' # From jcc.go:360.
7576
local_corpus_path_base = '/workspace/corpus'
7677
local_corpus_path = os.path.join(local_corpus_path_base, target_name)
7778
default_target_path = os.path.join(build.out, target_name)
@@ -81,6 +82,24 @@ def run_experiment(project_name, target_name, args, output_path,
8182
local_stacktrace_path = os.path.join(build.out, 'stacktrace/')
8283
fuzzer_args = ' '.join(args + [f'-artifact_prefix={local_artifact_path}'])
8384

85+
# Upload JCC's err.log.
86+
if errlog_path:
87+
compile_step_index = -1
88+
for i, step in enumerate(steps):
89+
step_args = step.get('args', [])
90+
if '&& compile' in ' '.join(step_args):
91+
compile_step_index = i
92+
break
93+
if compile_step_index == -1:
94+
print('Cannot find compile step.')
95+
else:
96+
# Insert the upload step right after compile step.
97+
upload_jcc_err_step = {
98+
'name': 'gcr.io/cloud-builders/gsutil',
99+
'args': ['cp', local_jcc_err_path, errlog_path]
100+
}
101+
steps.insert(compile_step_index + 1, upload_jcc_err_step)
102+
84103
env = build_project.get_env(project_yaml['language'], build)
85104
env.append('RUN_FUZZER_MODE=batch')
86105
env.append('CORPUS_DIR=' + local_corpus_path)
@@ -268,6 +287,10 @@ def main():
268287
parser.add_argument('--upload_build_log',
269288
required=True,
270289
help='GCS build log location.')
290+
parser.add_argument('--upload_err_log',
291+
required=False,
292+
default='',
293+
help='GCS JCC error log location.')
271294
parser.add_argument('--upload_output_log',
272295
required=True,
273296
help='GCS log location.')
@@ -287,7 +310,7 @@ def main():
287310
args = parser.parse_args()
288311

289312
run_experiment(args.project, args.target, args.args, args.upload_output_log,
290-
args.upload_build_log, args.upload_corpus,
313+
args.upload_err_log, args.upload_build_log, args.upload_corpus,
291314
args.upload_coverage, args.experiment_name,
292315
args.upload_reproducer)
293316

0 commit comments

Comments
 (0)