Skip to content
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

feat: fuzz test support read from .env by different services #2824

Merged
merged 4 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions core/fuzz/build.sh
dqhl76 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

# build fuzz targets
cd $SRC/opendal/core
cargo +nightly fuzz build -O --debug-assertions

# copy fuzz targets to $OUT

cp ../target/x86_64-unknown-linux-gnu/release/fuzz_reader $OUT/fuzz_reader_fs
cp ../target/x86_64-unknown-linux-gnu/release/fuzz_reader $OUT/fuzz_writer_fs

cp ../target/x86_64-unknown-linux-gnu/release/fuzz_reader $OUT/fuzz_reader_mem
cp ../target/x86_64-unknown-linux-gnu/release/fuzz_reader $OUT/fuzz_writer_mem

# .options files will be used by oss-fuzz to append arguments to the fuzz targets
echo -e "[libfuzzer]\nOPENDAL_FS_TEST=on\nOPENDAL_FS_ROOT=/tmp" > $SRC/opendal/fuzz_reader_fs.options
echo -e "[libfuzzer]\nOPENDAL_MEMORY_TEST=on\n" > $SRC/opendal/fuzz_reader_mem.options

echo -e "[libfuzzer]\nOPENDAL_FS_TEST=on\nOPENDAL_FS_ROOT=/tmp" > $SRC/opendal/fuzz_writer_fs.options
echo -e "[libfuzzer]\nOPENDAL_MEMORY_TEST=on\n" > $SRC/opendal/fuzz_writer_mem.options

# copy .options files to $OUT
cp $SRC/opendal/fuzz_reader*.options $OUT/
cp $SRC/opendal/fuzz_writer*.options $OUT/
2 changes: 2 additions & 0 deletions core/fuzz/fuzz_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ async fn fuzz_reader(op: Operator, input: FuzzInput) -> Result<()> {
fuzz_target!(|input: FuzzInput| {
let _ = dotenvy::dotenv();

utils::apply_args_to_env();

let runtime = tokio::runtime::Runtime::new().expect("init runtime must succeed");

for op in utils::init_services() {
Expand Down
2 changes: 2 additions & 0 deletions core/fuzz/fuzz_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ async fn fuzz_writer(op: Operator, input: FuzzInput) -> Result<()> {
fuzz_target!(|input: FuzzInput| {
let _ = dotenvy::dotenv();

utils::apply_args_to_env();

let runtime = tokio::runtime::Runtime::new().expect("init runtime must succeed");

for op in utils::init_services() {
Expand Down
13 changes: 13 additions & 0 deletions core/fuzz/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ use std::env;
use opendal::Operator;
use opendal::Scheme;

pub fn apply_args_to_env() {
Xuanwo marked this conversation as resolved.
Show resolved Hide resolved
// for oss-fuzz integration, set envs from args
// example: -opendal_fs_test=on -> OPENDAL_FS_TEST=on
dqhl76 marked this conversation as resolved.
Show resolved Hide resolved
let args: Vec<String> = env::args().collect();

for arg in &args[1..] {
let parts: Vec<&str> = arg[1..].split('=').collect();
if parts.len() == 2 {
env::set_var(parts[0].to_uppercase(), parts[1]);
}
}
}

fn service(scheme: Scheme) -> Option<Operator> {
let test_key = format!("opendal_{}_test", scheme).to_uppercase();
if env::var(test_key).unwrap_or_default() != "on" {
Expand Down