-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add fuzz test for create table (#3441)
* feat: add create table fuzz test * chore: add ci cfg for fuzz tests * refactor: remove redundant nightly config * chore: run fuzz test in debug mode * chore: use ubuntu-latest * fix: close connection * chore: add cache in fuzz test ci * chore: apply suggestion from CR * chore: apply suggestion from CR * chore: refactor the fuzz test action
- Loading branch information
Showing
14 changed files
with
328 additions
and
6 deletions.
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,13 @@ | ||
name: Fuzz Test | ||
description: 'Fuzz test given setup and service' | ||
inputs: | ||
target: | ||
description: "The fuzz target to test" | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Run Fuzz Test | ||
shell: bash | ||
run: cargo fuzz run ${{ inputs.target }} --fuzz-dir tests-fuzz -D -s none -- -max_total_time=120 | ||
env: | ||
GT_MYSQL_ADDR: 127.0.0.1:4002 |
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 |
---|---|---|
|
@@ -46,3 +46,7 @@ benchmarks/data | |
*.code-workspace | ||
|
||
venv/ | ||
|
||
# Fuzz tests | ||
tests-fuzz/artifacts/ | ||
tests-fuzz/corpus/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,41 @@ | ||
# Fuzz Test for GreptimeDB | ||
|
||
## Setup | ||
1. Install the [fuzz](https://rust-fuzz.github.io/book/cargo-fuzz/setup.html) cli first. | ||
```bash | ||
cargo install cargo-fuzz | ||
``` | ||
|
||
2. Start GreptimeDB | ||
3. Copy the `.env.example`, which is at project root, to `.env` and change the values on need. | ||
|
||
## Run | ||
1. List all fuzz targets | ||
```bash | ||
cargo fuzz list --fuzz-dir tests-fuzz | ||
``` | ||
|
||
2. Run a fuzz target. | ||
```bash | ||
cargo fuzz run fuzz_create_table --fuzz-dir tests-fuzz | ||
``` | ||
|
||
## Crash Reproduction | ||
If you want to reproduce a crash, you first need to obtain the Base64 encoded code, which usually appears at the end of a crash report, and store it in a file. | ||
|
||
Alternatively, if you already have the crash file, you can skip this step. | ||
|
||
```bash | ||
echo "Base64" > .crash | ||
``` | ||
Print the `std::fmt::Debug` output for an input. | ||
|
||
```bash | ||
cargo fuzz fmt fuzz_target .crash --fuzz-dir tests-fuzz | ||
``` | ||
Rerun the fuzz test with the input. | ||
|
||
```bash | ||
cargo fuzz run fuzz_target .crash --fuzz-dir tests-fuzz | ||
``` | ||
For more details, visit [cargo fuzz](https://rust-fuzz.github.io/book/cargo-fuzz/tutorial.html) or run the command `cargo fuzz --help`. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2023 Greptime Team | ||
// | ||
// 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. | ||
|
||
use std::env; | ||
|
||
use common_telemetry::info; | ||
use sqlx::mysql::MySqlPoolOptions; | ||
use sqlx::{MySql, Pool}; | ||
|
||
pub struct Connections { | ||
pub mysql: Option<Pool<MySql>>, | ||
} | ||
|
||
const GT_MYSQL_ADDR: &str = "GT_MYSQL_ADDR"; | ||
|
||
pub async fn init_greptime_connections() -> Connections { | ||
let _ = dotenv::dotenv(); | ||
let mysql = if let Ok(addr) = env::var(GT_MYSQL_ADDR) { | ||
Some( | ||
MySqlPoolOptions::new() | ||
.connect(&format!("mysql://{addr}/public")) | ||
.await | ||
.unwrap(), | ||
) | ||
} else { | ||
info!("GT_MYSQL_ADDR is empty, ignores test"); | ||
None | ||
}; | ||
|
||
Connections { mysql } | ||
} |
Oops, something went wrong.