-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GreenBench implementation #1912
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
568ed2a
add greenbench poc implementation
jiradeto 0fa31d8
address PR feedbacks
jiradeto 6029962
add missing dispatcher attribute
jiradeto 4682309
reformat code
jiradeto 5daaec3
add micro_experiment as experiment config
jiradeto df53485
change seed condition in runner
jiradeto 4128796
fix typo
jiradeto 94c8f2c
fix condition typo
jiradeto 780d040
fix typo
jiradeto 1763e01
remove unused log
jiradeto 2b7a69c
fix format failure
jiradeto 60bf887
add missing space
jiradeto b65c5ac
make trail_group_id as optional param
jiradeto cd3aecd
update test experiment config
jiradeto 051cf85
make format and add micro_experiment flag in test_data
jiradeto b8ec5f9
fix failed test
jiradeto 2aef3a1
fix format
jiradeto c256908
reorder test output
jiradeto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Utility functions for micro-experiment run.""" | ||
|
||
import random | ||
import os | ||
import tempfile | ||
import multiprocessing | ||
import zipfile | ||
from typing import List | ||
|
||
from common import experiment_utils | ||
from common import filesystem | ||
from common import logs | ||
|
||
MAX_SOURCE_CORPUS_FILES = 1 | ||
CORPUS_ELEMENT_BYTES_LIMIT = 1 * 1024 * 1024 | ||
|
||
|
||
def initialize_random_corpus_fuzzing(benchmarks: List[str], num_trials: int): | ||
"""Prepare corpus for micro experiment.""" | ||
pool_args = () | ||
with multiprocessing.Pool(*pool_args) as pool: | ||
pool.starmap(prepare_benchmark_random_corpus, | ||
[(benchmark, num_trials) for benchmark in benchmarks]) | ||
logs.info('Done preparing corpus for micro experiment') | ||
|
||
|
||
# pylint: disable=too-many-locals | ||
def prepare_benchmark_random_corpus(benchmark: str, num_trials: int): | ||
"""Prepare corpus for given benchmark.""" | ||
# Temporary location to park corpus files before get picked randomly. | ||
benchmark_unarchived_corpora = os.path.join( | ||
experiment_utils.get_oss_fuzz_corpora_unarchived_path(), benchmark) | ||
filesystem.create_directory(benchmark_unarchived_corpora) | ||
|
||
# Unzip oss fuzz corpus. | ||
corpus_archive_filename = f'{benchmark}.zip' | ||
oss_fuzz_corpus_archive_path = os.path.join( | ||
experiment_utils.get_oss_fuzz_corpora_filestore_path(), | ||
corpus_archive_filename) | ||
with zipfile.ZipFile(oss_fuzz_corpus_archive_path) as zip_file: | ||
idx = 0 | ||
for seed_corpus_file in zip_file.infolist(): | ||
if seed_corpus_file.filename.endswith('/'): | ||
# Ignore directories. | ||
continue | ||
# Allow callers to opt-out of unpacking large files. | ||
if seed_corpus_file.file_size > CORPUS_ELEMENT_BYTES_LIMIT: | ||
continue | ||
output_filename = f'{idx:016d}' | ||
output_file_path = os.path.join(benchmark_unarchived_corpora, | ||
output_filename) | ||
zip_file.extract(seed_corpus_file, output_file_path) | ||
idx += 1 | ||
|
||
# Path used to store and feed seed corpus for benchmark runner | ||
# each trial group will have the same seed input(s). | ||
benchmark_random_corpora = os.path.join( | ||
experiment_utils.get_random_corpora_filestore_path(), benchmark) | ||
filesystem.create_directory(benchmark_random_corpora) | ||
|
||
with tempfile.TemporaryDirectory() as tmp_dir: | ||
all_corpus_files = [] | ||
for root, _, files in os.walk(benchmark_unarchived_corpora): | ||
for filename in files: | ||
file_path = os.path.join(root, filename) | ||
all_corpus_files.append(file_path) | ||
|
||
all_corpus_files.sort() | ||
trial_group_num = 0 | ||
# All trials in the same group will start with the same | ||
# set of randomly selected seed files. | ||
while trial_group_num < num_trials: | ||
trial_group_subdir = f'trial-group-{trial_group_num}' | ||
custom_corpus_trial_dir = os.path.join(benchmark_random_corpora, | ||
trial_group_subdir) | ||
src_dir = os.path.join(tmp_dir, 'source') | ||
filesystem.recreate_directory(src_dir) | ||
|
||
source_files = random.sample(all_corpus_files, | ||
MAX_SOURCE_CORPUS_FILES) | ||
for file in source_files: | ||
filesystem.copy(file, src_dir) | ||
|
||
# Copy only the src directory. | ||
filesystem.copytree(src_dir, custom_corpus_trial_dir) | ||
trial_group_num += 1 | ||
|
||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this has been plumbed through properly but I'm not 100% sure (no reason to think it's wrong). Sorry this setup isn't great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jonathanmetzman the
trial_group_num
field is used as an identifier of the group of trials and this idea of trial grouping is used to make sure that we provide the same set of seeds to certain trails (within the same group).For example, if in the config.yaml we set trials to 2 for the experiment so we have following trials in total (for fuzzer afl, libfuzzer and benchmark libjpeg):
so fuzzbench will generate following group (synthetically) and assign the same set initial seeds to trials within the same group:
Please let me know if it makes sense? also is there a way to only add/inject this
trial_group_num
field only when are running inMICRO_EXPERIMENT
mode?