You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2023/10/18 13:25:45 UTC
[incubator-opendal] branch fix-fuzz created (now 7bb17bf04)
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a change to branch fix-fuzz
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
at 7bb17bf04 refactor(core/fuzz): Migrate to OPENDANL_TEST
This branch includes the following new commits:
new 7bb17bf04 refactor(core/fuzz): Migrate to OPENDANL_TEST
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[incubator-opendal] 01/01: refactor(core/fuzz): Migrate to OPENDANL_TEST
Posted by xu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch fix-fuzz
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
commit 7bb17bf04f9288a8a71b503c7f0d8bb75429d795
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Wed Oct 18 21:25:22 2023 +0800
refactor(core/fuzz): Migrate to OPENDANL_TEST
Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
core/fuzz/README.md | 4 ++--
core/fuzz/fuzz_reader.rs | 2 +-
core/fuzz/fuzz_writer.rs | 2 +-
core/fuzz/utils.rs | 24 ++++++++----------------
4 files changed, 12 insertions(+), 20 deletions(-)
diff --git a/core/fuzz/README.md b/core/fuzz/README.md
index a5b9add79..fc7d33b58 100644
--- a/core/fuzz/README.md
+++ b/core/fuzz/README.md
@@ -11,14 +11,14 @@ To run the fuzz tests, please copy the `.env.example`, which is at project root,
Take `fs` for example, we need to change to enable fuzz test on `fs` on `/tmp`.
```dotenv
-OPENDAL_FS_TEST=false
+OPENDAL_TEST=fs
OPENDAL_FS_ROOT=/path/to/dir
```
into
```dotenv
-OPENDAL_FS_TEST=on
+OPENDAL_TEST=fs
OPENDAL_FS_ROOT=/tmp
```
diff --git a/core/fuzz/fuzz_reader.rs b/core/fuzz/fuzz_reader.rs
index 7b13207bf..d6eb19c1c 100644
--- a/core/fuzz/fuzz_reader.rs
+++ b/core/fuzz/fuzz_reader.rs
@@ -257,7 +257,7 @@ fuzz_target!(|input: FuzzInput| {
let runtime = tokio::runtime::Runtime::new().expect("init runtime must succeed");
- for op in utils::init_services() {
+ if let Some(op) = utils::init_service() {
runtime.block_on(async {
fuzz_reader(op, input.clone())
.await
diff --git a/core/fuzz/fuzz_writer.rs b/core/fuzz/fuzz_writer.rs
index ff1eb0bdb..edd25ac26 100644
--- a/core/fuzz/fuzz_writer.rs
+++ b/core/fuzz/fuzz_writer.rs
@@ -128,7 +128,7 @@ fuzz_target!(|input: FuzzInput| {
let runtime = tokio::runtime::Runtime::new().expect("init runtime must succeed");
- for op in utils::init_services() {
+ if let Some(op) = utils::init_service() {
runtime.block_on(async {
fuzz_writer(op, input.clone())
.await
diff --git a/core/fuzz/utils.rs b/core/fuzz/utils.rs
index 8a6501843..37598fdb3 100644
--- a/core/fuzz/utils.rs
+++ b/core/fuzz/utils.rs
@@ -16,12 +16,18 @@
// under the License.
use std::env;
+use std::str::FromStr;
use opendal::Operator;
use opendal::Scheme;
-fn service(scheme: Scheme) -> Option<Operator> {
- let test_key = format!("opendal_{}_test", scheme).to_uppercase();
+pub fn init_service() -> Option<Operator> {
+ let scheme = if let Ok(v) = env::var("OPENDAL_TEST") {
+ v
+ } else {
+ return None;
+ };
+ let scheme = Scheme::from_str(&scheme).unwrap();
let args: Vec<String> = env::args().collect();
if args[0].ends_with(&scheme.to_string()) {
@@ -29,10 +35,6 @@ fn service(scheme: Scheme) -> Option<Operator> {
let _ = dotenvy::from_filename_override(format!(".{scheme}.env"));
}
- if env::var(test_key).unwrap_or_default() != "on" {
- return None;
- }
-
let prefix = format!("opendal_{}_", scheme);
let envs = env::vars()
.filter_map(move |(k, v)| {
@@ -44,13 +46,3 @@ fn service(scheme: Scheme) -> Option<Operator> {
Some(Operator::via_map(scheme, envs).unwrap_or_else(|_| panic!("init {} must succeed", scheme)))
}
-
-pub fn init_services() -> Vec<Operator> {
- let ops = vec![
- service(Scheme::Memory),
- service(Scheme::Fs),
- service(Scheme::S3),
- ];
-
- ops.into_iter().flatten().collect()
-}