diff --git a/rust/tests/BUILD.gn b/rust/tests/BUILD.gn index 133e473279aac8e9613abd7e2bac5ce744760e05..857cad2848e8101df7770cf311bd02debd2fd7dd 100644 --- a/rust/tests/BUILD.gn +++ b/rust/tests/BUILD.gn @@ -41,11 +41,11 @@ group("tests") { group("ohos_rust_xxxtest_tests") { testonly = true deps = [ - "test_rust_st:test_rust_st(${host_toolchain})", - "test_rust_ut:test_rust_ut(${host_toolchain})", + "rust_test_st:rust_test_st(${host_toolchain})", + "rust_test_ut:rust_test_ut(${host_toolchain})", + "//build/rust/tests/rust_test_st", + "//build/rust/tests/rust_test_ut", "//build/rust/tests/test_proc_macro_crate/test_derive_macro:test_derive_macro(${host_toolchain})", - "//build/rust/tests/test_rust_st", - "//build/rust/tests/test_rust_ut", ] } diff --git a/rust/tests/test_rust_st/BUILD.gn b/rust/tests/rust_test_st/BUILD.gn old mode 100644 new mode 100755 similarity index 90% rename from rust/tests/test_rust_st/BUILD.gn rename to rust/tests/rust_test_st/BUILD.gn index 84c0c1b6ab14f5de3139c38a64baea064be75f8c..93915738cf72e071391d16df46bd017f96377895 --- a/rust/tests/test_rust_st/BUILD.gn +++ b/rust/tests/rust_test_st/BUILD.gn @@ -14,8 +14,8 @@ import("//build/ohos.gni") import("//build/test.gni") -ohos_rust_systemtest("test_rust_st") { - module_out_path = "rust_build_test/test_rust_st" +ohos_rust_systemtest("rust_test_st") { + module_out_path = "rust_build_test/rust_test_st" sources = [ "test/test.rs" ] deps = [ ":test_rust_st_add" ] } diff --git a/rust/tests/test_rust_st/src/lib.rs b/rust/tests/rust_test_st/src/lib.rs similarity index 100% rename from rust/tests/test_rust_st/src/lib.rs rename to rust/tests/rust_test_st/src/lib.rs diff --git a/rust/tests/test_rust_st/test/test.rs b/rust/tests/rust_test_st/test/test.rs similarity index 100% rename from rust/tests/test_rust_st/test/test.rs rename to rust/tests/rust_test_st/test/test.rs diff --git a/rust/tests/test_rust_ut/BUILD.gn b/rust/tests/rust_test_ut/BUILD.gn similarity index 90% rename from rust/tests/test_rust_ut/BUILD.gn rename to rust/tests/rust_test_ut/BUILD.gn index 69c5ceef5f7735f053a3cdf88f9af954b7e16357..2e762ef77bf1eb7fa2553459a0e1c052aa3154b5 100644 --- a/rust/tests/test_rust_ut/BUILD.gn +++ b/rust/tests/rust_test_ut/BUILD.gn @@ -14,8 +14,8 @@ import("//build/ohos.gni") import("//build/test.gni") -ohos_rust_unittest("test_rust_ut") { - module_out_path = "rust_build_test/test_rust_ut" +ohos_rust_unittest("rust_test_ut") { + module_out_path = "rust_build_test/rust_test_ut" sources = [ "src/main.rs" ] deps = [ ":test_rust_ut_add" ] } diff --git a/rust/tests/test_rust_ut/src/main.rs b/rust/tests/rust_test_ut/src/main.rs similarity index 100% rename from rust/tests/test_rust_ut/src/main.rs rename to rust/tests/rust_test_ut/src/main.rs diff --git a/templates/rust/rust_template.gni b/templates/rust/rust_template.gni old mode 100644 new mode 100755 index efe36e9e6e160cb5a3dfff3cddb7604be9368c3d..2a58d21bfb92bc5e0264c80933aab9bf5b478b80 --- a/templates/rust/rust_template.gni +++ b/templates/rust/rust_template.gni @@ -142,6 +142,29 @@ template("rust_target") { if (!defined(output_name) || output_name == "") { output_name = crate_name } + if (!defined(cflags_cc)) { + cflags_cc = [] + } + if (use_clang_coverage == true) { + cflags_cc += [ "-DRUSTC_BOOTSTRAP=1" ] + rustflags += [ + "-C", + "instrument-coverage", + "--cfg=coverage_nightly", + "-Cllvm-args=-sanitizer-coverage-stack-depth", + "-Cdebug-assertions", + "-Cllvm-args=-sanitizer-coverage-inline-8bit-counters", + "-Cllvm-args=-sanitizer-coverage-pc-table", + "-Cllvm-args=-sanitizer-coverage-trace-compares", + "-Cpasses=sancov-module", + "-Clink-dead-code", + "-Cdebug-assertions", + "-Zprofile", + "-C", + "codegen-units=1", + "-Zpanic_abort_tests", + ] + } } } diff --git a/test.gni b/test.gni index 5ca121bd2b96c7334a32a6803182d331ad160bae..32ef5867a3d2568981101b93bcf557acd275f053 100755 --- a/test.gni +++ b/test.gni @@ -820,3 +820,61 @@ template("ohos_rust_systemtest") { ] } } + +template("ohos_rust_fuzztest") { + _target_name = target_name + ohos_fuzztest("$_target_name") { + forward_variables_from(invoker, "*") + if (!defined(invoker.crate_name)) { + crate_name = _target_name + } + crate_type = "bin" + if (defined(invoker.crate_type)) { + assert(invoker.crate_type == crate_type, + "crate_type should be $crate_type or use default value.") + } + if (!defined(rustflags)) { + rustflags = [] + } + if (!defined(cflags)) { + cflags = [] + } + cflags += [ "-DRUSTC_BOOTSTRAP=1" ] + rustflags += [ + "--cfg", + "feature=\"fuzzing\"", + ] + if (use_clang_coverage == true) { + rustflags += [ + "-C", + "instrument-coverage", + "--cfg=coverage_nightly", + "-Cllvm-args=-sanitizer-coverage-stack-depth", + "-Cdebug-assertions", + "-Cllvm-args=-sanitizer-coverage-inline-8bit-counters", + "-Cllvm-args=-sanitizer-coverage-pc-table", + "-Cllvm-args=-sanitizer-coverage-trace-compares", + "-Cllvm-args=-sanitizer-coverage-level=4", + "-Cpasses=sancov-module", + "-Clink-dead-code", + "-Cdebug-assertions", + "-C", + "codegen-units=1", + "-Zpanic_abort_tests", + ] + } + if (is_asan) { + rustflags += [ + "-C", + "sanitizer=address", + ] + } + if (use_libfuzzer) { + if (!defined(invoker.deps)) { + deps = [] + } else { + deps += [ "//third_party/rust/crates/libfuzzer:lib" ] + } + } + } +}