diff --git a/README.md b/README.md index 09761331b1bc5a8c7043ac89f70b12afcc5f2c29..a1732630136813e76d05d64630ff145b2f11b4be 100644 --- a/README.md +++ b/README.md @@ -53,24 +53,18 @@ This capability of asynchronous interfaces is achieved through the `Reactor` and ylong_runtime = { git = "https://gitee.com/openharmony-sig/commonlibrary_rust_ylong_runtime.git", features = ["full"]} ``` ### Use gn -1. add `ylong_runtime_mod` in bundle.json +1. add `ylong_runtime` in bundle.json ``` - "deps": { - "components": ["ylong_runtime_mod"] - } +"deps": { + "components": ["ylong_runtime"] +} ``` -2. add `ylong_runtime_mod:lib` in `BUILD.gn` +2. add `ylong_runtime:ylong_runtime` in `BUILD.gn` ``` -external_deps += ["ylong_runtime_mod:lib"] -``` - -3. Currently you need to add `inner` when using `ylong_runtime` via gn compilation. - -``` -use ylong_runtime_inner +external_deps = ["ylong_runtime:ylong_runtime"] ``` ## Directory diff --git a/README_zh.md b/README_zh.md index 534918d2d9e190e841ca27830ac55a9520720b29..a1ebc9808e1ff8c7791bb38f721d32685d4cd4b4 100644 --- a/README_zh.md +++ b/README_zh.md @@ -96,19 +96,15 @@ ylong_runtime = { git = "https://gitee.com/openharmony-sig/commonlibrary_rust_yl ``` ### 使用gn编译 -1. 在`bundle.json`中添加`ylong_runtime_mod` +1. 在`bundle.json`中添加`ylong_runtime` ``` - "deps": { - "components": ["ylong_runtime_mod"] - } +"deps": { + "components": ["ylong_runtime"] +} ``` -2. 在`BUILD.gn`中添加`ylong_runtime_mod:lib` +2. 在`BUILD.gn`中添加`ylong_runtime:ylong_runtime` ``` -external_deps += ["ylong_runtime_mod:lib"] -``` -3. 目前通过gn编译使用ylong_runtime时需要加上inner -``` -use ylong_runtime_inner +external_deps = ["ylong_runtime:ylong_runtime"] ``` ## 用户指南 diff --git a/bundle.json b/bundle.json index f932123fad3250468a06f995e76069e04d5dccb4..4a72b1644127ea90e6f54f6323817444611ce537 100644 --- a/bundle.json +++ b/bundle.json @@ -1,40 +1,50 @@ { - "name": "@ohos/rust_ylong_runtime", - "description": "Rust runtime implementation", + "name": "@ohos/ylong_runtime", "version": "4.0", - "license": "MIT", + "description": "Rust runtime implementation", "publishAs": "code-segment", - "dirs": {}, - "scripts": {}, + "homePage": "https://gitee.com/openharmony", + "repository": "https://gitee.com/openharmony/commonlibrary_rust_ylong_runtime", + "license": "Apache License 2.0", + "language": "Rust", + "segment": { + "destPath": "commonlibrary/rust/ylong_runtime" + }, "licensePath": "COPYING", "readmePath": { "en": "README.md", "zh": "README_zh.md" }, "component": { - "name": "ylong_runtime_mod", + "name": "ylong_runtime", "subsystem": "commonlibrary", - "syscap": [], "features": [], - "adapted_system_type": [], - "rom": "1500KB", - "ram": "5000KB", + "adapted_system_type": [ + "standard" + ], + "rom": "100KB", + "ram": "~200KB", "deps": { "components": [], "third_party": [] }, "build": { - "sub_component": [], + "sub_component": [ + "//commonlibrary/rust/ylong_runtime/ylong_io:ylong_io" + ], "inner_kits": [ { - "name": "//commonlibrary/rust/ylong_runtime/ylong_runtime:lib", + "name": "//commonlibrary/rust/ylong_runtime/ylong_runtime:ylong_runtime", "header": { "header_base": [], "header_files": [] } } ], - "test": [] + "test": [ + "//commonlibrary/rust/ylong_runtime/ylong_runtime:unittest", + "//commonlibrary/rust/ylong_runtime/ylong_runtime:sdvtest" + ] } } } \ No newline at end of file diff --git a/ylong_io/BUILD.gn b/ylong_io/BUILD.gn index 93e33d169332274dbaa174bcc20f7977ca41a14c..0cab989b44e5f4c18d4775e14af395dff1ef4010 100644 --- a/ylong_io/BUILD.gn +++ b/ylong_io/BUILD.gn @@ -14,17 +14,17 @@ import("//build/ohos.gni") ohos_rust_static_library("ylong_io") { + part_name = "ylong_runtime" + subsystem_name = "commonlibrary" + crate_name = "ylong_io" - crate_root = "src/lib.rs" edition = "2021" - part_name = "ylong_runtime_mod" - subsystem_name = "commonlibrary" - - sources = [ "src/lib.rs" ] - deps = [ "//third_party/rust/crates/libc:lib" ] features = [ "tcp", "udp", ] + + sources = [ "src/lib.rs" ] + deps = [ "//third_party/rust/crates/libc:lib" ] } diff --git a/ylong_runtime/BUILD.gn b/ylong_runtime/BUILD.gn index f910933ae655044dba81a77504c0603849c7f2e6..67f92e4e93127842e454831d8438ed5df5e1ff4e 100644 --- a/ylong_runtime/BUILD.gn +++ b/ylong_runtime/BUILD.gn @@ -14,13 +14,20 @@ import("//build/ohos.gni") import("//build/test.gni") -ohos_rust_shared_library("lib") { - crate_name = "ylong_runtime_inner" +ohos_rust_shared_library("ylong_runtime") { + part_name = "ylong_runtime" + subsystem_name = "commonlibrary" + + crate_name = "ylong_runtime" edition = "2021" - crate_root = "src/lib.rs" - part_name = "ylong_runtime_mod" - subsystem_name = "commonlibrary" + features = [ + "fs", + "macros", + "net", + "sync", + "time", + ] sources = [ "src/lib.rs" ] deps = [ @@ -28,29 +35,39 @@ ohos_rust_shared_library("lib") { "../ylong_runtime_macros:ylong_runtime_macros(${host_toolchain})", "//third_party/rust/crates/libc:lib", ] - features = [ - "net", - "macros", - "sync", - "fs", - "time", - ] } -ohos_rust_unittest("rust_ylong_runtime_unit_test") { - module_out_path = "commonlibrary/rust/ylong_runtime" +ohos_rust_unittest("unittest") { + module_out_path = "ylong_runtime/ylong_runtime" + + rustflags = [ + "--cfg=feature=\"fs\"", + "--cfg=feature=\"macros\"", + "--cfg=feature=\"net\"", + "--cfg=feature=\"sync\"", + "--cfg=feature=\"time\"", + ] + sources = [ "src/lib.rs" ] deps = [ - ":lib", "../ylong_io:ylong_io", + "../ylong_runtime_macros:ylong_runtime_macros(${host_toolchain})", "//third_party/rust/crates/libc:lib", ] - clippy_lints = "none" +} + +ohos_rust_systemtest("sdvtest") { + module_out_path = "ylong_runtime/ylong_runtime" rustflags = [ - "--cfg=feature=\"time\"", - "--cfg=feature=\"sync\"", + "--cfg=gn_test", "--cfg=feature=\"fs\"", + "--cfg=feature=\"macros\"", "--cfg=feature=\"net\"", + "--cfg=feature=\"sync\"", + "--cfg=feature=\"time\"", ] + + sources = [ "tests/entry.rs" ] + deps = [ ":ylong_runtime" ] } diff --git a/ylong_runtime/Cargo.toml b/ylong_runtime/Cargo.toml index be239267f3522679760f56471314d91cd8c37ed8..fe3016c0fa525b6f2e7bbc79db6464cd18f2e45f 100644 --- a/ylong_runtime/Cargo.toml +++ b/ylong_runtime/Cargo.toml @@ -143,78 +143,3 @@ required-features = ["multi_instance_runtime"] name = "ylong_runtime_timer_sleep" path = "examples/ylong_runtime_timer_sleep.rs" required-features = ["time", "multi_instance_runtime"] - -[[test]] -name = "tcp_test" -path = "tests/tcp_test.rs" -required-features = ["net"] - -[[test]] -name = "udp_test" -path = "tests/udp_test.rs" -required-features = ["net"] - -[[test]] -name = "async_dir" -path = "tests/async_dir.rs" -required-features = ["fs"] - -[[test]] -name = "async_fs" -path = "tests/async_fs.rs" -required-features = ["fs", "multi_instance_runtime"] - -[[test]] -name = "async_read" -path = "tests/async_read.rs" -required-features = ["net"] - -[[test]] -name = "spawn_blocking" -path = "tests/spawn_blocking.rs" -required-features = ["multi_instance_runtime"] - -[[test]] -name = "async_pool" -path = "tests/async_pool.rs" -required-features = ["multi_instance_runtime"] - -[[test]] -name = "builder" -path = "tests/builder.rs" -required-features = ["multi_instance_runtime"] - -[[test]] -name = "sync" -path = "tests/sync.rs" -required-features = ["sync", "multi_instance_runtime"] - -[[test]] -name = "block_on" -path = "tests/block_on.rs" -required-features = ["multi_instance_runtime"] - -[[test]] -name = "spawn" -path = "tests/spawn.rs" -required-features = ["multi_instance_runtime"] - -[[test]] -name = "timer_test" -path = "tests/timer_test.rs" -required-features = ["time", "sync"] - -[[test]] -name = "mpsc_test" -path = "tests/mpsc_test.rs" -required-features = ["sync", "time"] - -[[test]] -name = "async_buf_read" -path = "tests/async_buf_read.rs" -required-features = ["fs", "net"] - -[[test]] -name = "async_buf_write" -path = "tests/async_buf_write.rs" -required-features = ["fs", "net"] diff --git a/ylong_runtime/src/util/bit.rs b/ylong_runtime/src/util/bit.rs index 4fb476fda4438fae4d351c8abf1463035a2787ec..a14a85b15bbe2e82d89a9b4e4d5cec51ac9a0fff 100644 --- a/ylong_runtime/src/util/bit.rs +++ b/ylong_runtime/src/util/bit.rs @@ -267,394 +267,390 @@ impl Bit { /// UT test cases for mask new function /// /// # Brief -/// 1. Get the current machine word length. -/// 2. Call the new function according to the machine word length, pass in the -/// parameters, and create the Mask. -/// 3. Check return value. +/// 1. pass in the parameters, and create the Mask. +/// 2. Check return value. +#[cfg(target_pointer_width = "32")] #[test] -fn ut_mask_new() { - const USIZE_LEN: u32 = 0usize.wrapping_sub(1).count_ones(); +fn ut_mask_new_bit32() { + assert_eq!( + Mask::new(0, 0), + Mask { + mask: 0x0, + shift: 0 + } + ); + assert_eq!( + Mask::new(0, 16), + Mask { + mask: 0x0, + shift: 0 + } + ); + assert_eq!( + Mask::new(0, 32), + Mask { + mask: 0x0, + shift: 0 + } + ); + assert_eq!( + Mask::new(0, 64), + Mask { + mask: 0x0, + shift: 0 + } + ); + assert_eq!( + Mask::new(1, 0), + Mask { + mask: 0x1, + shift: 0 + } + ); + assert_eq!( + Mask::new(1, 16), + Mask { + mask: 0x1_0000, + shift: 16 + } + ); + assert_eq!( + Mask::new(1, 31), + Mask { + mask: 0x8000_0000, + shift: 31 + } + ); + assert_eq!( + Mask::new(1, 32), + Mask { + mask: 0x8000_0000, + shift: 31 + } + ); + assert_eq!( + Mask::new(1, 128), + Mask { + mask: 0x8000_0000, + shift: 31 + } + ); + assert_eq!( + Mask::new(4, 0), + Mask { + mask: 0xf, + shift: 0 + } + ); + assert_eq!( + Mask::new(4, 16), + Mask { + mask: 0xf_0000, + shift: 16 + } + ); + assert_eq!( + Mask::new(4, 28), + Mask { + mask: 0xf000_0000, + shift: 28 + } + ); + assert_eq!( + Mask::new(4, 32), + Mask { + mask: 0xf000_0000, + shift: 28 + } + ); + assert_eq!( + Mask::new(4, 64), + Mask { + mask: 0xf000_0000, + shift: 28 + } + ); + assert_eq!( + Mask::new(16, 0), + Mask { + mask: 0xffff, + shift: 0 + } + ); + assert_eq!( + Mask::new(16, 16), + Mask { + mask: 0xffff_0000, + shift: 16 + } + ); + assert_eq!( + Mask::new(16, 32), + Mask { + mask: 0xffff_0000, + shift: 16 + } + ); + assert_eq!( + Mask::new(16, 64), + Mask { + mask: 0xffff_0000, + shift: 16 + } + ); + assert_eq!( + Mask::new(32, 0), + Mask { + mask: 0xffff_ffff, + shift: 0 + } + ); + assert_eq!( + Mask::new(32, 16), + Mask { + mask: 0xffff_ffff, + shift: 0 + } + ); + assert_eq!( + Mask::new(32, 32), + Mask { + mask: 0xffff_ffff, + shift: 0 + } + ); + assert_eq!( + Mask::new(32, 64), + Mask { + mask: 0xffff_ffff, + shift: 0 + } + ); + assert_eq!( + Mask::new(64, 0), + Mask { + mask: 0xffff_ffff, + shift: 0 + } + ); + assert_eq!( + Mask::new(64, 16), + Mask { + mask: 0xffff_ffff, + shift: 0 + } + ); + assert_eq!( + Mask::new(64, 32), + Mask { + mask: 0xffff_ffff, + shift: 0 + } + ); + assert_eq!( + Mask::new(64, 64), + Mask { + mask: 0xffff_ffff, + shift: 0 + } + ); +} - match USIZE_LEN { - 32 => ut_mask_new_bit32(), - 64 => ut_mask_new_bit64(), - _ => {} - } +/// UT test cases for mask new function +/// +/// # Brief +/// 1. pass in the parameters, and create the Mask. +/// 2. Check return value. +#[cfg(target_pointer_width = "64")] +#[test] +fn ut_mask_new_bit64() { + assert_eq!( + Mask::new(0, 0), + Mask { + mask: 0x0, + shift: 0 + } + ); + assert_eq!( + Mask::new(0, 32), + Mask { + mask: 0x0, + shift: 0 + } + ); + assert_eq!( + Mask::new(0, 64), + Mask { + mask: 0x0, + shift: 0 + } + ); + assert_eq!( + Mask::new(0, 128), + Mask { + mask: 0x0, + shift: 0 + } + ); - fn ut_mask_new_bit32() { - assert_eq!( - Mask::new(0, 0), - Mask { - mask: 0x0, - shift: 0 - } - ); - assert_eq!( - Mask::new(0, 16), - Mask { - mask: 0x0, - shift: 0 - } - ); - assert_eq!( - Mask::new(0, 32), - Mask { - mask: 0x0, - shift: 0 - } - ); - assert_eq!( - Mask::new(0, 64), - Mask { - mask: 0x0, - shift: 0 - } - ); - assert_eq!( - Mask::new(1, 0), - Mask { - mask: 0x1, - shift: 0 - } - ); - assert_eq!( - Mask::new(1, 16), - Mask { - mask: 0x1_0000, - shift: 16 - } - ); - assert_eq!( - Mask::new(1, 31), - Mask { - mask: 0x8000_0000, - shift: 31 - } - ); - assert_eq!( - Mask::new(1, 32), - Mask { - mask: 0x8000_0000, - shift: 31 - } - ); - assert_eq!( - Mask::new(1, 128), - Mask { - mask: 0x8000_0000, - shift: 31 - } - ); - assert_eq!( - Mask::new(4, 0), - Mask { - mask: 0xf, - shift: 0 - } - ); - assert_eq!( - Mask::new(4, 16), - Mask { - mask: 0xf_0000, - shift: 16 - } - ); - assert_eq!( - Mask::new(4, 28), - Mask { - mask: 0xf000_0000, - shift: 28 - } - ); - assert_eq!( - Mask::new(4, 32), - Mask { - mask: 0xf000_0000, - shift: 28 - } - ); - assert_eq!( - Mask::new(4, 64), - Mask { - mask: 0xf000_0000, - shift: 28 - } - ); - assert_eq!( - Mask::new(16, 0), - Mask { - mask: 0xffff, - shift: 0 - } - ); - assert_eq!( - Mask::new(16, 16), - Mask { - mask: 0xffff_0000, - shift: 16 - } - ); - assert_eq!( - Mask::new(16, 32), - Mask { - mask: 0xffff_0000, - shift: 16 - } - ); - assert_eq!( - Mask::new(16, 64), - Mask { - mask: 0xffff_0000, - shift: 16 - } - ); - assert_eq!( - Mask::new(32, 0), - Mask { - mask: 0xffff_ffff, - shift: 0 - } - ); - assert_eq!( - Mask::new(32, 16), - Mask { - mask: 0xffff_ffff, - shift: 0 - } - ); - assert_eq!( - Mask::new(32, 32), - Mask { - mask: 0xffff_ffff, - shift: 0 - } - ); - assert_eq!( - Mask::new(32, 64), - Mask { - mask: 0xffff_ffff, - shift: 0 - } - ); - assert_eq!( - Mask::new(64, 0), - Mask { - mask: 0xffff_ffff, - shift: 0 - } - ); - assert_eq!( - Mask::new(64, 16), - Mask { - mask: 0xffff_ffff, - shift: 0 - } - ); - assert_eq!( - Mask::new(64, 32), - Mask { - mask: 0xffff_ffff, - shift: 0 - } - ); - assert_eq!( - Mask::new(64, 64), - Mask { - mask: 0xffff_ffff, - shift: 0 - } - ); - } + assert_eq!( + Mask::new(1, 0), + Mask { + mask: 0x1, + shift: 0 + } + ); + assert_eq!( + Mask::new(1, 32), + Mask { + mask: 0x1_0000_0000, + shift: 32 + } + ); + assert_eq!( + Mask::new(1, 63), + Mask { + mask: 0x8000_0000_0000_0000, + shift: 63 + } + ); + assert_eq!( + Mask::new(1, 64), + Mask { + mask: 0x8000_0000_0000_0000, + shift: 63 + } + ); + assert_eq!( + Mask::new(1, 128), + Mask { + mask: 0x8000_0000_0000_0000, + shift: 63 + } + ); - fn ut_mask_new_bit64() { - assert_eq!( - Mask::new(0, 0), - Mask { - mask: 0x0, - shift: 0 - } - ); - assert_eq!( - Mask::new(0, 32), - Mask { - mask: 0x0, - shift: 0 - } - ); - assert_eq!( - Mask::new(0, 64), - Mask { - mask: 0x0, - shift: 0 - } - ); - assert_eq!( - Mask::new(0, 128), - Mask { - mask: 0x0, - shift: 0 - } - ); - - assert_eq!( - Mask::new(1, 0), - Mask { - mask: 0x1, - shift: 0 - } - ); - assert_eq!( - Mask::new(1, 32), - Mask { - mask: 0x1_0000_0000, - shift: 32 - } - ); - assert_eq!( - Mask::new(1, 63), - Mask { - mask: 0x8000_0000_0000_0000, - shift: 63 - } - ); - assert_eq!( - Mask::new(1, 64), - Mask { - mask: 0x8000_0000_0000_0000, - shift: 63 - } - ); - assert_eq!( - Mask::new(1, 128), - Mask { - mask: 0x8000_0000_0000_0000, - shift: 63 - } - ); - - assert_eq!( - Mask::new(4, 0), - Mask { - mask: 0xf, - shift: 0 - } - ); - assert_eq!( - Mask::new(4, 32), - Mask { - mask: 0xf_0000_0000, - shift: 32 - } - ); - assert_eq!( - Mask::new(4, 60), - Mask { - mask: 0xf000_0000_0000_0000, - shift: 60 - } - ); - assert_eq!( - Mask::new(4, 64), - Mask { - mask: 0xf000_0000_0000_0000, - shift: 60 - } - ); - assert_eq!( - Mask::new(4, 128), - Mask { - mask: 0xf000_0000_0000_0000, - shift: 60 - } - ); - - assert_eq!( - Mask::new(32, 0), - Mask { - mask: 0xffff_ffff, - shift: 0 - } - ); - assert_eq!( - Mask::new(32, 32), - Mask { - mask: 0xffff_ffff_0000_0000, - shift: 32 - } - ); - assert_eq!( - Mask::new(32, 64), - Mask { - mask: 0xffff_ffff_0000_0000, - shift: 32 - } - ); - assert_eq!( - Mask::new(32, 128), - Mask { - mask: 0xffff_ffff_0000_0000, - shift: 32 - } - ); - - assert_eq!( - Mask::new(64, 0), - Mask { - mask: 0xffff_ffff_ffff_ffff, - shift: 0 - } - ); - assert_eq!( - Mask::new(64, 32), - Mask { - mask: 0xffff_ffff_ffff_ffff, - shift: 0 - } - ); - assert_eq!( - Mask::new(64, 64), - Mask { - mask: 0xffff_ffff_ffff_ffff, - shift: 0 - } - ); - assert_eq!( - Mask::new(64, 128), - Mask { - mask: 0xffff_ffff_ffff_ffff, - shift: 0 - } - ); - - assert_eq!( - Mask::new(128, 0), - Mask { - mask: 0xffff_ffff_ffff_ffff, - shift: 0 - } - ); - assert_eq!( - Mask::new(128, 32), - Mask { - mask: 0xffff_ffff_ffff_ffff, - shift: 0 - } - ); - assert_eq!( - Mask::new(128, 64), - Mask { - mask: 0xffff_ffff_ffff_ffff, - shift: 0 - } - ); - assert_eq!( - Mask::new(128, 128), - Mask { - mask: 0xffff_ffff_ffff_ffff, - shift: 0 - } - ); - } + assert_eq!( + Mask::new(4, 0), + Mask { + mask: 0xf, + shift: 0 + } + ); + assert_eq!( + Mask::new(4, 32), + Mask { + mask: 0xf_0000_0000, + shift: 32 + } + ); + assert_eq!( + Mask::new(4, 60), + Mask { + mask: 0xf000_0000_0000_0000, + shift: 60 + } + ); + assert_eq!( + Mask::new(4, 64), + Mask { + mask: 0xf000_0000_0000_0000, + shift: 60 + } + ); + assert_eq!( + Mask::new(4, 128), + Mask { + mask: 0xf000_0000_0000_0000, + shift: 60 + } + ); + + assert_eq!( + Mask::new(32, 0), + Mask { + mask: 0xffff_ffff, + shift: 0 + } + ); + assert_eq!( + Mask::new(32, 32), + Mask { + mask: 0xffff_ffff_0000_0000, + shift: 32 + } + ); + assert_eq!( + Mask::new(32, 64), + Mask { + mask: 0xffff_ffff_0000_0000, + shift: 32 + } + ); + assert_eq!( + Mask::new(32, 128), + Mask { + mask: 0xffff_ffff_0000_0000, + shift: 32 + } + ); + + assert_eq!( + Mask::new(64, 0), + Mask { + mask: 0xffff_ffff_ffff_ffff, + shift: 0 + } + ); + assert_eq!( + Mask::new(64, 32), + Mask { + mask: 0xffff_ffff_ffff_ffff, + shift: 0 + } + ); + assert_eq!( + Mask::new(64, 64), + Mask { + mask: 0xffff_ffff_ffff_ffff, + shift: 0 + } + ); + assert_eq!( + Mask::new(64, 128), + Mask { + mask: 0xffff_ffff_ffff_ffff, + shift: 0 + } + ); + + assert_eq!( + Mask::new(128, 0), + Mask { + mask: 0xffff_ffff_ffff_ffff, + shift: 0 + } + ); + assert_eq!( + Mask::new(128, 32), + Mask { + mask: 0xffff_ffff_ffff_ffff, + shift: 0 + } + ); + assert_eq!( + Mask::new(128, 64), + Mask { + mask: 0xffff_ffff_ffff_ffff, + shift: 0 + } + ); + assert_eq!( + Mask::new(128, 128), + Mask { + mask: 0xffff_ffff_ffff_ffff, + shift: 0 + } + ); } /// UT test cases for bit from_usize function @@ -741,159 +737,158 @@ fn ut_bit_clear() { /// 1. Create a Bit instance, create a Mask instance. /// 2. Call set_by_mask(). /// 3. Verify the Bit instance. +#[cfg(target_pointer_width = "32")] #[test] -fn ut_bit_set_by_mask() { - const USIZE_LEN: u32 = 0usize.wrapping_sub(1).count_ones(); - - match USIZE_LEN { - 32 => ut_bit_set_by_mask_bit32(), - 64 => ut_bit_set_by_mask_bit64(), - _ => {} - } - - fn ut_bit_set_by_mask_bit32() { - let val = 0x0usize; - let mut bit = Bit::from_usize(val); - bit.set_by_mask(Mask::new(0, 0), 0x0); - assert_eq!(bit, Bit::from_usize(0x0)); - - bit.clear(); - bit.set_by_mask(Mask::new(4, 0), 0xf); - assert_eq!(bit, Bit::from_usize(0xf)); - - bit.clear(); - bit.set_by_mask(Mask::new(8, 0), 0xff); - assert_eq!(bit, Bit::from_usize(0xff)); - - bit.clear(); - bit.set_by_mask(Mask::new(4, 4), 0xf); - assert_eq!(bit, Bit::from_usize(0xf0)); - - bit.clear(); - bit.set_by_mask(Mask::new(4, 28), 0xf); - assert_eq!(bit, Bit::from_usize(0xf000_0000)); - - bit.clear(); - bit.set_by_mask(Mask::new(0, 0), 0xffff_ffff); - assert_eq!(bit, Bit::from_usize(0x0)); - - bit.clear(); - bit.set_by_mask(Mask::new(4, 0), 0xffff_ffff); - assert_eq!(bit, Bit::from_usize(0xf)); - - bit.clear(); - bit.set_by_mask(Mask::new(4, 4), 0xffff_ffff); - assert_eq!(bit, Bit::from_usize(0xf0)); - - let val = 0xffff_ffff; - let mut bit = Bit::from_usize(val); - bit.set_by_mask(Mask::new(0, 0), 0x0); - assert_eq!(bit, Bit::from_usize(0xffff_ffff)); - - bit.set(val); - bit.set_by_mask(Mask::new(4, 0), 0x0); - assert_eq!(bit, Bit::from_usize(0xffff_fff0)); - - bit.set(val); - bit.set_by_mask(Mask::new(4, 4), 0x0); - assert_eq!(bit, Bit::from_usize(0xffff_ff0f)); - - bit.set(val); - bit.set_by_mask(Mask::new(4, 8), 0x0); - assert_eq!(bit, Bit::from_usize(0xffff_f0ff)); - - bit.set(val); - bit.set_by_mask(Mask::new(4, 0), 0xabcd); - assert_eq!(bit, Bit::from_usize(0xffff_fffd)); - - bit.set(val); - bit.set_by_mask(Mask::new(8, 0), 0xabcd); - assert_eq!(bit, Bit::from_usize(0xffff_ffcd)); - - bit.set(val); - bit.set_by_mask(Mask::new(16, 0), 0xabcd); - assert_eq!(bit, Bit::from_usize(0xffff_abcd)); - - bit.set(val); - bit.set_by_mask(Mask::new(16, 16), 0xabcd); - assert_eq!(bit, Bit::from_usize(0xabcd_ffff)); - - bit.set(val); - bit.set_by_mask(Mask::new(32, 0), 0xabcd); - assert_eq!(bit, Bit::from_usize(0x0000_abcd)); - } - - fn ut_bit_set_by_mask_bit64() { - let val = 0x0usize; - let mut bit = Bit::from_usize(val); - bit.set_by_mask(Mask::new(0, 0), 0x0); - assert_eq!(bit, Bit::from_usize(0x0)); - - bit.clear(); - bit.set_by_mask(Mask::new(4, 0), 0xf); - assert_eq!(bit, Bit::from_usize(0xf)); - - bit.clear(); - bit.set_by_mask(Mask::new(8, 0), 0xff); - assert_eq!(bit, Bit::from_usize(0xff)); - - bit.clear(); - bit.set_by_mask(Mask::new(4, 4), 0xf); - assert_eq!(bit, Bit::from_usize(0xf0)); - - bit.clear(); - bit.set_by_mask(Mask::new(4, 32), 0xf); - assert_eq!(bit, Bit::from_usize(0xf_0000_0000)); - - bit.clear(); - bit.set_by_mask(Mask::new(4, 0), 0xffff_ffff_ffff_ffff); - assert_eq!(bit, Bit::from_usize(0xf)); - - bit.clear(); - bit.set_by_mask(Mask::new(4, 4), 0xffff_ffff_ffff_ffff); - assert_eq!(bit, Bit::from_usize(0xf0)); - - bit.clear(); - bit.set_by_mask(Mask::new(0, 0), 0xffff_ffff_ffff_ffff); - assert_eq!(bit, Bit::from_usize(0)); - - let val = 0xffff_ffff_ffff_ffffusize; - let mut bit = Bit::from_usize(val); - bit.set_by_mask(Mask::new(0, 0), 0x0); - assert_eq!(bit, Bit::from_usize(0xffff_ffff_ffff_ffff)); - - bit.set(0xffff_ffff_ffff_ffff); - bit.set_by_mask(Mask::new(4, 0), 0x0); - assert_eq!(bit, Bit::from_usize(0xffff_ffff_ffff_fff0)); - - bit.set(0xffff_ffff_ffff_ffff); - bit.set_by_mask(Mask::new(4, 4), 0x0); - assert_eq!(bit, Bit::from_usize(0xffff_ffff_ffff_ff0f)); - - bit.set(0xffff_ffff_ffff_ffff); - bit.set_by_mask(Mask::new(4, 32), 0x0); - assert_eq!(bit, Bit::from_usize(0xffff_fff0_ffff_ffff)); - - bit.set(0xffff_ffff_ffff_ffff); - bit.set_by_mask(Mask::new(4, 60), 0x0); - assert_eq!(bit, Bit::from_usize(0x0fff_ffff_ffff_ffff)); - - bit.set(0xffff_ffff_ffff_ffff); - bit.set_by_mask(Mask::new(16, 0), 0xabcd); - assert_eq!(bit, Bit::from_usize(0xffff_ffff_ffff_abcd)); - - bit.set(0xffff_ffff_ffff_ffff); - bit.set_by_mask(Mask::new(32, 0), 0xabcd); - assert_eq!(bit, Bit::from_usize(0xffff_ffff_0000_abcd)); - - bit.set(0xffff_ffff_ffff_ffff); - bit.set_by_mask(Mask::new(12, 0), 0xabcd); - assert_eq!(bit, Bit::from_usize(0xffff_ffff_ffff_fbcd)); +fn ut_bit_set_by_mask_bit32() { + let val = 0x0usize; + let mut bit = Bit::from_usize(val); + bit.set_by_mask(Mask::new(0, 0), 0x0); + assert_eq!(bit, Bit::from_usize(0x0)); + + bit.clear(); + bit.set_by_mask(Mask::new(4, 0), 0xf); + assert_eq!(bit, Bit::from_usize(0xf)); + + bit.clear(); + bit.set_by_mask(Mask::new(8, 0), 0xff); + assert_eq!(bit, Bit::from_usize(0xff)); + + bit.clear(); + bit.set_by_mask(Mask::new(4, 4), 0xf); + assert_eq!(bit, Bit::from_usize(0xf0)); + + bit.clear(); + bit.set_by_mask(Mask::new(4, 28), 0xf); + assert_eq!(bit, Bit::from_usize(0xf000_0000)); + + bit.clear(); + bit.set_by_mask(Mask::new(0, 0), 0xffff_ffff); + assert_eq!(bit, Bit::from_usize(0x0)); + + bit.clear(); + bit.set_by_mask(Mask::new(4, 0), 0xffff_ffff); + assert_eq!(bit, Bit::from_usize(0xf)); + + bit.clear(); + bit.set_by_mask(Mask::new(4, 4), 0xffff_ffff); + assert_eq!(bit, Bit::from_usize(0xf0)); + + let val = 0xffff_ffff; + let mut bit = Bit::from_usize(val); + bit.set_by_mask(Mask::new(0, 0), 0x0); + assert_eq!(bit, Bit::from_usize(0xffff_ffff)); + + bit.set(val); + bit.set_by_mask(Mask::new(4, 0), 0x0); + assert_eq!(bit, Bit::from_usize(0xffff_fff0)); + + bit.set(val); + bit.set_by_mask(Mask::new(4, 4), 0x0); + assert_eq!(bit, Bit::from_usize(0xffff_ff0f)); + + bit.set(val); + bit.set_by_mask(Mask::new(4, 8), 0x0); + assert_eq!(bit, Bit::from_usize(0xffff_f0ff)); + + bit.set(val); + bit.set_by_mask(Mask::new(4, 0), 0xabcd); + assert_eq!(bit, Bit::from_usize(0xffff_fffd)); + + bit.set(val); + bit.set_by_mask(Mask::new(8, 0), 0xabcd); + assert_eq!(bit, Bit::from_usize(0xffff_ffcd)); + + bit.set(val); + bit.set_by_mask(Mask::new(16, 0), 0xabcd); + assert_eq!(bit, Bit::from_usize(0xffff_abcd)); + + bit.set(val); + bit.set_by_mask(Mask::new(16, 16), 0xabcd); + assert_eq!(bit, Bit::from_usize(0xabcd_ffff)); + + bit.set(val); + bit.set_by_mask(Mask::new(32, 0), 0xabcd); + assert_eq!(bit, Bit::from_usize(0x0000_abcd)); +} - bit.set(0xffff_ffff_ffff_ffff); - bit.set_by_mask(Mask::new(16, 8), 0xabcd); - assert_eq!(bit, Bit::from_usize(0xffff_ffff_ffab_cdff)); - } +/// UT test cases for bit set_by_mask function +/// +/// # Brief +/// 1. Create a Bit instance, create a Mask instance. +/// 2. Call set_by_mask(). +/// 3. Verify the Bit instance. +#[cfg(target_pointer_width = "64")] +#[test] +fn ut_bit_set_by_mask_bit64() { + let val = 0x0usize; + let mut bit = Bit::from_usize(val); + bit.set_by_mask(Mask::new(0, 0), 0x0); + assert_eq!(bit, Bit::from_usize(0x0)); + + bit.clear(); + bit.set_by_mask(Mask::new(4, 0), 0xf); + assert_eq!(bit, Bit::from_usize(0xf)); + + bit.clear(); + bit.set_by_mask(Mask::new(8, 0), 0xff); + assert_eq!(bit, Bit::from_usize(0xff)); + + bit.clear(); + bit.set_by_mask(Mask::new(4, 4), 0xf); + assert_eq!(bit, Bit::from_usize(0xf0)); + + bit.clear(); + bit.set_by_mask(Mask::new(4, 32), 0xf); + assert_eq!(bit, Bit::from_usize(0xf_0000_0000)); + + bit.clear(); + bit.set_by_mask(Mask::new(4, 0), 0xffff_ffff_ffff_ffff); + assert_eq!(bit, Bit::from_usize(0xf)); + + bit.clear(); + bit.set_by_mask(Mask::new(4, 4), 0xffff_ffff_ffff_ffff); + assert_eq!(bit, Bit::from_usize(0xf0)); + + bit.clear(); + bit.set_by_mask(Mask::new(0, 0), 0xffff_ffff_ffff_ffff); + assert_eq!(bit, Bit::from_usize(0)); + + let val = 0xffff_ffff_ffff_ffffusize; + let mut bit = Bit::from_usize(val); + bit.set_by_mask(Mask::new(0, 0), 0x0); + assert_eq!(bit, Bit::from_usize(0xffff_ffff_ffff_ffff)); + + bit.set(0xffff_ffff_ffff_ffff); + bit.set_by_mask(Mask::new(4, 0), 0x0); + assert_eq!(bit, Bit::from_usize(0xffff_ffff_ffff_fff0)); + + bit.set(0xffff_ffff_ffff_ffff); + bit.set_by_mask(Mask::new(4, 4), 0x0); + assert_eq!(bit, Bit::from_usize(0xffff_ffff_ffff_ff0f)); + + bit.set(0xffff_ffff_ffff_ffff); + bit.set_by_mask(Mask::new(4, 32), 0x0); + assert_eq!(bit, Bit::from_usize(0xffff_fff0_ffff_ffff)); + + bit.set(0xffff_ffff_ffff_ffff); + bit.set_by_mask(Mask::new(4, 60), 0x0); + assert_eq!(bit, Bit::from_usize(0x0fff_ffff_ffff_ffff)); + + bit.set(0xffff_ffff_ffff_ffff); + bit.set_by_mask(Mask::new(16, 0), 0xabcd); + assert_eq!(bit, Bit::from_usize(0xffff_ffff_ffff_abcd)); + + bit.set(0xffff_ffff_ffff_ffff); + bit.set_by_mask(Mask::new(32, 0), 0xabcd); + assert_eq!(bit, Bit::from_usize(0xffff_ffff_0000_abcd)); + + bit.set(0xffff_ffff_ffff_ffff); + bit.set_by_mask(Mask::new(12, 0), 0xabcd); + assert_eq!(bit, Bit::from_usize(0xffff_ffff_ffff_fbcd)); + + bit.set(0xffff_ffff_ffff_ffff); + bit.set_by_mask(Mask::new(16, 8), 0xabcd); + assert_eq!(bit, Bit::from_usize(0xffff_ffff_ffab_cdff)); } /// UT test cases for bit get_by_mask function @@ -902,90 +897,89 @@ fn ut_bit_set_by_mask() { /// 1. Create a Bit instance, create a Mask instance. /// 2. Call get_by_mask(). /// 3. Check return value. +#[cfg(target_pointer_width = "32")] #[test] -fn ut_bit_get_by_mask() { - const USIZE_LEN: u32 = 0usize.wrapping_sub(1).count_ones(); - - match USIZE_LEN { - 32 => ut_bit_get_by_mask_bit32(), - 64 => ut_bit_get_by_mask_bit64(), - _ => {} - } - - fn ut_bit_get_by_mask_bit32() { - let val = 0x0usize; - let bit = Bit::from_usize(val); - assert_eq!(bit.get_by_mask(Mask::new(0, 0)), 0x0); - assert_eq!(bit.get_by_mask(Mask::new(1, 0)), 0x0); - assert_eq!(bit.get_by_mask(Mask::new(16, 0)), 0x0); - assert_eq!(bit.get_by_mask(Mask::new(32, 0)), 0x0); - - let val = 0xffff_ffffusize; - let bit = Bit::from_usize(val); - assert_eq!(bit.get_by_mask(Mask::new(0, 0)), 0x0); - assert_eq!(bit.get_by_mask(Mask::new(1, 0)), 0x1); - assert_eq!(bit.get_by_mask(Mask::new(16, 0)), 0xffff); - assert_eq!(bit.get_by_mask(Mask::new(32, 0)), 0xffff_ffff); - - let val = 0x1234_cdefusize; - let bit = Bit::from_usize(val); - assert_eq!(bit.get_by_mask(Mask::new(0, 0)), 0x0); - assert_eq!(bit.get_by_mask(Mask::new(4, 0)), 0xf); - assert_eq!(bit.get_by_mask(Mask::new(8, 0)), 0xef); - assert_eq!(bit.get_by_mask(Mask::new(12, 0)), 0xdef); - assert_eq!(bit.get_by_mask(Mask::new(16, 0)), 0xcdef); - assert_eq!(bit.get_by_mask(Mask::new(32, 0)), 0x1234_cdef); - assert_eq!(bit.get_by_mask(Mask::new(4, 4)), 0xe); - assert_eq!(bit.get_by_mask(Mask::new(8, 4)), 0xde); - assert_eq!(bit.get_by_mask(Mask::new(12, 4)), 0xcde); - assert_eq!(bit.get_by_mask(Mask::new(4, 16)), 0x4); - assert_eq!(bit.get_by_mask(Mask::new(8, 16)), 0x34); - assert_eq!(bit.get_by_mask(Mask::new(12, 16)), 0x234); - assert_eq!(bit.get_by_mask(Mask::new(3, 0)), 0x7); - assert_eq!(bit.get_by_mask(Mask::new(3, 4)), 0x6); - assert_eq!(bit.get_by_mask(Mask::new(3, 8)), 0x5); - assert_eq!(bit.get_by_mask(Mask::new(3, 16)), 0x4); - assert_eq!(bit.get_by_mask(Mask::new(3, 20)), 0x3); - assert_eq!(bit.get_by_mask(Mask::new(3, 24)), 0x2); - assert_eq!(bit.get_by_mask(Mask::new(3, 1)), 0x7); - assert_eq!(bit.get_by_mask(Mask::new(3, 5)), 0x7); - assert_eq!(bit.get_by_mask(Mask::new(3, 9)), 0x6); - } +fn ut_bit_get_by_mask_bit32() { + let val = 0x0usize; + let bit = Bit::from_usize(val); + assert_eq!(bit.get_by_mask(Mask::new(0, 0)), 0x0); + assert_eq!(bit.get_by_mask(Mask::new(1, 0)), 0x0); + assert_eq!(bit.get_by_mask(Mask::new(16, 0)), 0x0); + assert_eq!(bit.get_by_mask(Mask::new(32, 0)), 0x0); + + let val = 0xffff_ffffusize; + let bit = Bit::from_usize(val); + assert_eq!(bit.get_by_mask(Mask::new(0, 0)), 0x0); + assert_eq!(bit.get_by_mask(Mask::new(1, 0)), 0x1); + assert_eq!(bit.get_by_mask(Mask::new(16, 0)), 0xffff); + assert_eq!(bit.get_by_mask(Mask::new(32, 0)), 0xffff_ffff); + + let val = 0x1234_cdefusize; + let bit = Bit::from_usize(val); + assert_eq!(bit.get_by_mask(Mask::new(0, 0)), 0x0); + assert_eq!(bit.get_by_mask(Mask::new(4, 0)), 0xf); + assert_eq!(bit.get_by_mask(Mask::new(8, 0)), 0xef); + assert_eq!(bit.get_by_mask(Mask::new(12, 0)), 0xdef); + assert_eq!(bit.get_by_mask(Mask::new(16, 0)), 0xcdef); + assert_eq!(bit.get_by_mask(Mask::new(32, 0)), 0x1234_cdef); + assert_eq!(bit.get_by_mask(Mask::new(4, 4)), 0xe); + assert_eq!(bit.get_by_mask(Mask::new(8, 4)), 0xde); + assert_eq!(bit.get_by_mask(Mask::new(12, 4)), 0xcde); + assert_eq!(bit.get_by_mask(Mask::new(4, 16)), 0x4); + assert_eq!(bit.get_by_mask(Mask::new(8, 16)), 0x34); + assert_eq!(bit.get_by_mask(Mask::new(12, 16)), 0x234); + assert_eq!(bit.get_by_mask(Mask::new(3, 0)), 0x7); + assert_eq!(bit.get_by_mask(Mask::new(3, 4)), 0x6); + assert_eq!(bit.get_by_mask(Mask::new(3, 8)), 0x5); + assert_eq!(bit.get_by_mask(Mask::new(3, 16)), 0x4); + assert_eq!(bit.get_by_mask(Mask::new(3, 20)), 0x3); + assert_eq!(bit.get_by_mask(Mask::new(3, 24)), 0x2); + assert_eq!(bit.get_by_mask(Mask::new(3, 1)), 0x7); + assert_eq!(bit.get_by_mask(Mask::new(3, 5)), 0x7); + assert_eq!(bit.get_by_mask(Mask::new(3, 9)), 0x6); +} - fn ut_bit_get_by_mask_bit64() { - let val = 0x0usize; - let bit = Bit::from_usize(val); - assert_eq!(bit.get_by_mask(Mask::new(0, 0)), 0x0); - assert_eq!(bit.get_by_mask(Mask::new(1, 0)), 0x0); - assert_eq!(bit.get_by_mask(Mask::new(32, 0)), 0x0); - assert_eq!(bit.get_by_mask(Mask::new(64, 0)), 0x0); - - let val = 0xffff_ffff_ffff_ffffusize; - let bit = Bit::from_usize(val); - assert_eq!(bit.get_by_mask(Mask::new(0, 0)), 0x0); - assert_eq!(bit.get_by_mask(Mask::new(1, 0)), 0x1); - assert_eq!(bit.get_by_mask(Mask::new(32, 0)), 0xffff_ffff); - assert_eq!(bit.get_by_mask(Mask::new(64, 0)), 0xffff_ffff_ffff_ffff); - - let val = 0x0123_4567_89ab_cdefusize; - let bit = Bit::from_usize(val); - assert_eq!(bit.get_by_mask(Mask::new(0, 0)), 0x0); - assert_eq!(bit.get_by_mask(Mask::new(4, 0)), 0xf); - assert_eq!(bit.get_by_mask(Mask::new(8, 0)), 0xef); - assert_eq!(bit.get_by_mask(Mask::new(32, 0)), 0x89ab_cdef); - assert_eq!(bit.get_by_mask(Mask::new(64, 0)), 0x0123_4567_89ab_cdef); - assert_eq!(bit.get_by_mask(Mask::new(4, 4)), 0xe); - assert_eq!(bit.get_by_mask(Mask::new(8, 4)), 0xde); - assert_eq!(bit.get_by_mask(Mask::new(12, 4)), 0xcde); - assert_eq!(bit.get_by_mask(Mask::new(60, 4)), 0x0012_3456_789a_bcde); - assert_eq!(bit.get_by_mask(Mask::new(4, 32)), 0x7); - assert_eq!(bit.get_by_mask(Mask::new(8, 32)), 0x67); - assert_eq!(bit.get_by_mask(Mask::new(12, 32)), 0x567); - assert_eq!(bit.get_by_mask(Mask::new(3, 0)), 0x7); - assert_eq!(bit.get_by_mask(Mask::new(3, 4)), 0x6); - assert_eq!(bit.get_by_mask(Mask::new(3, 8)), 0x5); - assert_eq!(bit.get_by_mask(Mask::new(3, 1)), 0x7); - assert_eq!(bit.get_by_mask(Mask::new(3, 5)), 0x7); - assert_eq!(bit.get_by_mask(Mask::new(3, 9)), 0x6); - } +/// UT test cases for bit get_by_mask function +/// +/// # Brief +/// 1. Create a Bit instance, create a Mask instance. +/// 2. Call get_by_mask(). +/// 3. Check return value. +#[cfg(target_pointer_width = "64")] +#[test] +fn ut_bit_get_by_mask_bit64() { + let val = 0x0usize; + let bit = Bit::from_usize(val); + assert_eq!(bit.get_by_mask(Mask::new(0, 0)), 0x0); + assert_eq!(bit.get_by_mask(Mask::new(1, 0)), 0x0); + assert_eq!(bit.get_by_mask(Mask::new(32, 0)), 0x0); + assert_eq!(bit.get_by_mask(Mask::new(64, 0)), 0x0); + + let val = 0xffff_ffff_ffff_ffffusize; + let bit = Bit::from_usize(val); + assert_eq!(bit.get_by_mask(Mask::new(0, 0)), 0x0); + assert_eq!(bit.get_by_mask(Mask::new(1, 0)), 0x1); + assert_eq!(bit.get_by_mask(Mask::new(32, 0)), 0xffff_ffff); + assert_eq!(bit.get_by_mask(Mask::new(64, 0)), 0xffff_ffff_ffff_ffff); + + let val = 0x0123_4567_89ab_cdefusize; + let bit = Bit::from_usize(val); + assert_eq!(bit.get_by_mask(Mask::new(0, 0)), 0x0); + assert_eq!(bit.get_by_mask(Mask::new(4, 0)), 0xf); + assert_eq!(bit.get_by_mask(Mask::new(8, 0)), 0xef); + assert_eq!(bit.get_by_mask(Mask::new(32, 0)), 0x89ab_cdef); + assert_eq!(bit.get_by_mask(Mask::new(64, 0)), 0x0123_4567_89ab_cdef); + assert_eq!(bit.get_by_mask(Mask::new(4, 4)), 0xe); + assert_eq!(bit.get_by_mask(Mask::new(8, 4)), 0xde); + assert_eq!(bit.get_by_mask(Mask::new(12, 4)), 0xcde); + assert_eq!(bit.get_by_mask(Mask::new(60, 4)), 0x0012_3456_789a_bcde); + assert_eq!(bit.get_by_mask(Mask::new(4, 32)), 0x7); + assert_eq!(bit.get_by_mask(Mask::new(8, 32)), 0x67); + assert_eq!(bit.get_by_mask(Mask::new(12, 32)), 0x567); + assert_eq!(bit.get_by_mask(Mask::new(3, 0)), 0x7); + assert_eq!(bit.get_by_mask(Mask::new(3, 4)), 0x6); + assert_eq!(bit.get_by_mask(Mask::new(3, 8)), 0x5); + assert_eq!(bit.get_by_mask(Mask::new(3, 1)), 0x7); + assert_eq!(bit.get_by_mask(Mask::new(3, 5)), 0x7); + assert_eq!(bit.get_by_mask(Mask::new(3, 9)), 0x6); } diff --git a/ylong_runtime/tests/async_buf_read.rs b/ylong_runtime/tests/async_buf_read.rs index 3e0b336430e238d8f107c1354caac63f9465bead..b9862cc34a5b0c2267ceb929d2ab64013c17cc92 100644 --- a/ylong_runtime/tests/async_buf_read.rs +++ b/ylong_runtime/tests/async_buf_read.rs @@ -11,13 +11,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::fs; -use std::io::SeekFrom; +#![cfg(all(feature = "fs", feature = "net"))] -use ylong_runtime::fs::File; -use ylong_runtime::io::{ - AsyncBufReadExt, AsyncBufReader, AsyncReadExt, AsyncSeekExt, AsyncWriteExt, -}; +use ylong_runtime::io::{AsyncBufReadExt, AsyncBufReader, AsyncReadExt, AsyncWriteExt}; use ylong_runtime::net::{TcpListener, TcpStream}; /// SDV test cases for AsyncBufReader `read_util` @@ -200,8 +196,15 @@ fn sdv_buf_reader_lines() { /// 2. Open the file and call `read_until` with a delimiter '-'. /// 3. Seek to three different positions in the file and read data. /// 4. Check the read buf. +#[cfg(not(gn_test))] #[test] fn sdv_buf_reader_seek() { + use std::fs; + use std::io::SeekFrom; + + use ylong_runtime::fs::File; + use ylong_runtime::io::AsyncSeekExt; + let handle = ylong_runtime::spawn(async move { let mut file = File::create("./tests/buf_reader_seek_file").await.unwrap(); let buf = "lorem-ipsum-dolor".as_bytes(); diff --git a/ylong_runtime/tests/async_buf_write.rs b/ylong_runtime/tests/async_buf_write.rs index 5a0c62753aba5e175f2b1039ec429ea8238d00fa..cb0bbd58f0ac6de20e6a50b25a4924acee167f44 100644 --- a/ylong_runtime/tests/async_buf_write.rs +++ b/ylong_runtime/tests/async_buf_write.rs @@ -11,11 +11,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::fs; -use std::io::{IoSlice, SeekFrom}; +#![cfg(all(feature = "fs", feature = "net"))] +use std::io::IoSlice; -use ylong_runtime::fs::File; -use ylong_runtime::io::{AsyncBufWriter, AsyncReadExt, AsyncSeekExt, AsyncWriteExt}; +use ylong_runtime::io::{AsyncBufWriter, AsyncReadExt, AsyncWriteExt}; use ylong_runtime::net::{TcpListener, TcpStream}; /// SDV test cases for AsyncBufWriter `write` @@ -106,8 +105,15 @@ fn sdv_buf_writer_write_vectored() { /// 2. Open the file, seek to three different positions in the file and read /// data. /// 3. Check the read buf. +#[cfg(not(gn_test))] #[test] fn sdv_buf_writer_seek() { + use std::fs; + use std::io::SeekFrom; + + use ylong_runtime::fs::File; + use ylong_runtime::io::AsyncSeekExt; + let handle = ylong_runtime::spawn(async move { let mut file = File::create("./tests/buf_writer_seek_file").await.unwrap(); let buf = "lorem-ipsum-dolor".as_bytes(); diff --git a/ylong_runtime/tests/async_dir.rs b/ylong_runtime/tests/async_dir.rs index 2722c9de82de0e5aabe370ab10c45f6b4f796c14..3226235ecca95e210140ddf542e0c090198eb358 100644 --- a/ylong_runtime/tests/async_dir.rs +++ b/ylong_runtime/tests/async_dir.rs @@ -11,6 +11,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![cfg(not(gn_test))] +#![cfg(feature = "fs")] + use ylong_runtime::fs::{create_dir, create_dir_all, read_dir, remove_dir, remove_dir_all, File}; /// SDV test cases for directory operations. diff --git a/ylong_runtime/tests/async_fs.rs b/ylong_runtime/tests/async_fs.rs index 2b4477f331148749c9f3066244053a615a474d68..e37995398d29d6d40db4700650a48d27fa564e44 100644 --- a/ylong_runtime/tests/async_fs.rs +++ b/ylong_runtime/tests/async_fs.rs @@ -11,6 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![cfg(feature = "fs")] + use std::fs; use std::io::SeekFrom; @@ -26,28 +28,28 @@ use ylong_runtime::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt}; /// 3. Start another task to read and write the same data as you read. #[test] fn sdv_async_fs_write() { - let runtime = RuntimeBuilder::new_multi_thread() + RuntimeBuilder::new_multi_thread() .worker_num(1) .blocking_permanent_thread_num(1) - .build() + .build_global() .unwrap(); - let handle = runtime.spawn(async move { + let handle = ylong_runtime::spawn(async move { let mut file = File::create("./tests/tmp_file").await.unwrap(); let buf = "hello".as_bytes().to_vec(); let res = file.write(&buf).await.unwrap(); assert_eq!(res, 5); file.sync_all().await.unwrap(); }); - runtime.block_on(handle).unwrap(); + ylong_runtime::block_on(handle).unwrap(); - let handle1 = runtime.spawn(async move { + let handle1 = ylong_runtime::spawn(async move { let mut file = File::open("./tests/tmp_file").await.unwrap(); let mut buf = [0; 5]; let res = file.read(&mut buf).await.unwrap(); assert_eq!(res, 5); assert_eq!(&buf, "hello".as_bytes()); }); - runtime.block_on(handle1).unwrap(); + ylong_runtime::block_on(handle1).unwrap(); fs::remove_file("./tests/tmp_file").unwrap(); } @@ -59,12 +61,12 @@ fn sdv_async_fs_write() { /// 3. Start two tasks to read, write and read the same data. #[test] fn sdv_async_fs_read() { - let runtime = RuntimeBuilder::new_multi_thread() + RuntimeBuilder::new_multi_thread() .worker_num(1) .blocking_permanent_thread_num(1) - .build() + .build_global() .unwrap(); - let handle = runtime.spawn(async move { + let handle = ylong_runtime::spawn(async move { let mut file = File::create("./tests/tmp_file2").await.unwrap(); let buf = vec![1, 2, 3, 4, 5]; let res = file.write(&buf).await.unwrap(); @@ -77,16 +79,16 @@ fn sdv_async_fs_read() { assert_eq!(res, 5); assert_eq!(buf, [1, 2, 3, 4, 5]); }); - runtime.block_on(handle).unwrap(); + ylong_runtime::block_on(handle).unwrap(); - let handle2 = runtime.spawn(async move { + let handle2 = ylong_runtime::spawn(async move { let mut file = File::open("./tests/tmp_file2").await.unwrap(); let mut buf = [0; 5]; let res = file.read(&mut buf).await.unwrap(); assert_eq!(res, 5); assert_eq!(buf, [1, 2, 3, 4, 5]); }); - runtime.block_on(handle2).unwrap(); + ylong_runtime::block_on(handle2).unwrap(); fs::remove_file("./tests/tmp_file2").unwrap(); } @@ -98,18 +100,18 @@ fn sdv_async_fs_read() { /// 3. Start another task to perform a read operation. #[test] fn sdv_async_fs_rw() { - let runtime = RuntimeBuilder::new_multi_thread() + RuntimeBuilder::new_multi_thread() .worker_num(2) .blocking_permanent_thread_num(2) - .build() + .build_global() .unwrap(); - let handle = runtime.spawn(async move { + let handle = ylong_runtime::spawn(async move { let _ = File::create("./tests/tmp_file3").await.unwrap(); }); - runtime.block_on(handle).unwrap(); + ylong_runtime::block_on(handle).unwrap(); - let handle = runtime.spawn(async move { + let handle = ylong_runtime::spawn(async move { let mut file = OpenOptions::new() .append(true) .open("./tests/tmp_file3") @@ -127,9 +129,9 @@ fn sdv_async_fs_rw() { assert!(ret.is_ok()); file.sync_all().await.unwrap(); }); - runtime.block_on(handle).unwrap(); + ylong_runtime::block_on(handle).unwrap(); - let handle2 = runtime.spawn(async move { + let handle2 = ylong_runtime::spawn(async move { let mut file = File::open("./tests/tmp_file3").await; while file.is_err() { file = File::open("./tests/tmp_file3").await; @@ -159,7 +161,7 @@ fn sdv_async_fs_rw() { } assert_eq!(&buf, &buf2); }); - runtime.block_on(handle2).unwrap(); + ylong_runtime::block_on(handle2).unwrap(); fs::remove_file("./tests/tmp_file3").unwrap(); } @@ -171,21 +173,20 @@ fn sdv_async_fs_rw() { /// 3. Start another task for reading large amounts of data. #[test] fn sdv_async_fs_read_to_end() { - let runtime = RuntimeBuilder::new_multi_thread().build().unwrap(); - let handle = runtime.spawn(async move { + let handle = ylong_runtime::spawn(async move { let mut file = File::create("./tests/tmp_file7").await.unwrap(); let buf = [2; 40000]; file.write_all(&buf).await.unwrap(); file.sync_all().await.unwrap(); }); - runtime.block_on(handle).unwrap(); - let handle1 = runtime.spawn(async move { + ylong_runtime::block_on(handle).unwrap(); + let handle1 = ylong_runtime::spawn(async move { let mut file = File::open("./tests/tmp_file7").await.unwrap(); let mut vec_buf = Vec::new(); let ret = file.read_to_end(&mut vec_buf).await.unwrap(); assert_eq!(ret, 40000); }); - runtime.block_on(handle1).unwrap(); + ylong_runtime::block_on(handle1).unwrap(); fs::remove_file("./tests/tmp_file7").unwrap(); } @@ -197,21 +198,21 @@ fn sdv_async_fs_read_to_end() { /// 3. Start another task for seek and read operations. #[test] fn sdv_async_fs_seek() { - let runtime = RuntimeBuilder::new_multi_thread() + RuntimeBuilder::new_multi_thread() .worker_num(2) .blocking_permanent_thread_num(2) - .build() + .build_global() .unwrap(); - let handle = runtime.spawn(async move { + let handle = ylong_runtime::spawn(async move { let mut file = File::create("./tests/tmp_file4").await.unwrap(); let buf = vec![65, 66, 67, 68, 69, 70, 71, 72, 73]; let res = file.write(&buf).await.unwrap(); assert_eq!(res, 9); file.sync_all().await.unwrap(); }); - runtime.block_on(handle).unwrap(); + ylong_runtime::block_on(handle).unwrap(); - let handle2 = runtime.spawn(async move { + let handle2 = ylong_runtime::spawn(async move { let mut file = File::open("./tests/tmp_file4").await.unwrap(); let ret = file.seek(SeekFrom::Current(3)).await.unwrap(); assert_eq!(ret, 3); @@ -252,7 +253,7 @@ fn sdv_async_fs_seek() { assert_eq!(buf, [73, 0]); }); - runtime.block_on(handle2).unwrap(); + ylong_runtime::block_on(handle2).unwrap(); fs::remove_file("./tests/tmp_file4").unwrap(); } @@ -264,13 +265,13 @@ fn sdv_async_fs_seek() { /// 3. Change the permission to read only, set it to this file. #[test] fn sdv_async_fs_set_permission() { - let runtime = RuntimeBuilder::new_multi_thread() + RuntimeBuilder::new_multi_thread() .worker_num(1) .blocking_permanent_thread_num(1) - .build() + .build_global() .unwrap(); - let handle = runtime.spawn(async move { + let handle = ylong_runtime::spawn(async move { let file = File::create("./tests/tmp_file5").await.unwrap(); let mut perms = file.metadata().await.unwrap().permissions(); perms.set_readonly(true); @@ -282,7 +283,7 @@ fn sdv_async_fs_set_permission() { let ret = file.set_permissions(perms).await; assert!(ret.is_ok()); }); - runtime.block_on(handle).unwrap(); + ylong_runtime::block_on(handle).unwrap(); fs::remove_file("./tests/tmp_file5").unwrap(); } @@ -293,13 +294,13 @@ fn sdv_async_fs_set_permission() { /// 2. Call sync_all and sync_data after asynchronous write. #[test] fn sdv_async_fs_sync_all() { - let runtime = RuntimeBuilder::new_multi_thread() + RuntimeBuilder::new_multi_thread() .worker_num(1) .blocking_permanent_thread_num(1) - .build() + .build_global() .unwrap(); - let handle = runtime.spawn(async move { + let handle = ylong_runtime::spawn(async move { let mut file = File::create("./tests/tmp_file6").await.unwrap(); let buf = [2; 20000]; let ret = file.write_all(&buf).await; @@ -313,6 +314,6 @@ fn sdv_async_fs_sync_all() { let ret = file.sync_data().await; assert!(ret.is_ok()); }); - runtime.block_on(handle).unwrap(); + ylong_runtime::block_on(handle).unwrap(); fs::remove_file("./tests/tmp_file6").unwrap(); } diff --git a/ylong_runtime/tests/async_pool.rs b/ylong_runtime/tests/async_pool.rs index 96928a0a66b4efa214d5b03cab30c3382bf83994..34ab705b20bddda7698361620c290528b4f98548 100644 --- a/ylong_runtime/tests/async_pool.rs +++ b/ylong_runtime/tests/async_pool.rs @@ -10,8 +10,13 @@ // 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. -#![cfg(target_os = "linux")] -#![cfg(not(feature = "ffrt"))] + +#![cfg(all( + target_os = "linux", + not(feature = "ffrt"), + feature = "multi_instance_runtime" +))] + use std::ffi::OsString; use std::fs; diff --git a/ylong_runtime/tests/async_read.rs b/ylong_runtime/tests/async_read.rs index b7813a2ba40e7988bd9b8ba4e0cb6f89eac947b7..2df46c07e942ee25c03ba6611c417b5e8dcb47a2 100644 --- a/ylong_runtime/tests/async_read.rs +++ b/ylong_runtime/tests/async_read.rs @@ -11,6 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![cfg(feature = "net")] + extern crate core; use ylong_runtime::io::{AsyncBufReader, AsyncReadExt, AsyncWriteExt}; diff --git a/ylong_runtime/tests/block_on.rs b/ylong_runtime/tests/block_on.rs index bc04168918d425f017e4066fec84dbf17c7e0fe3..910027ebea8a48e5b7cd823e8c26ae99c2a9321e 100644 --- a/ylong_runtime/tests/block_on.rs +++ b/ylong_runtime/tests/block_on.rs @@ -11,6 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![cfg(feature = "multi_instance_runtime")] + use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; diff --git a/ylong_runtime/tests/builder.rs b/ylong_runtime/tests/builder.rs index 60a1471cd75cee087b66388f45fc821459cbabda..d2b128de15467d59d67685440108e57affe5f62e 100644 --- a/ylong_runtime/tests/builder.rs +++ b/ylong_runtime/tests/builder.rs @@ -11,6 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![cfg(feature = "multi_instance_runtime")] + use std::sync::{Arc, Mutex}; use ylong_runtime::builder::RuntimeBuilder; diff --git a/ylong_runtime/tests/helpers/mod.rs b/ylong_runtime/tests/entry.rs similarity index 60% rename from ylong_runtime/tests/helpers/mod.rs rename to ylong_runtime/tests/entry.rs index 1d18b44f244a447f8c5713f1079800130b784c22..7142db3939596c898285872ae57b069e131ceccd 100644 --- a/ylong_runtime/tests/helpers/mod.rs +++ b/ylong_runtime/tests/entry.rs @@ -11,17 +11,30 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub async fn test_future(num: usize) -> usize { - num -} +#![cfg(gn_test)] -pub async fn test_multi_future_in_async(i: usize, j: usize) -> (usize, usize) { - let result_one = test_future(i).await; - let result_two = test_future(j).await; - - (result_one, result_two) -} - -pub async fn test_async_in_async(i: usize, j: usize) -> (usize, usize) { - test_multi_future_in_async(i, j).await -} +mod async_buf_read; +mod async_buf_write; +mod async_dir; +mod async_fs; +mod async_pool; +mod async_read; +mod block_on; +mod builder; +mod core_affinity; +mod join_set; +mod mpsc_test; +mod mutex; +mod num_cpus; +mod par_iter; +mod semaphore_test; +mod singleton_runtime; +mod slab; +mod slots; +mod spawn; +mod spawn_blocking; +mod sync; +mod task_cancel; +mod tcp_test; +mod timer_test; +mod udp_test; diff --git a/ylong_runtime/tests/mpsc_test.rs b/ylong_runtime/tests/mpsc_test.rs index 4739b7957fa554f9708e8bf5445106894f761257..e3b4f2c1229c0616903b398b319f759223e78eac 100644 --- a/ylong_runtime/tests/mpsc_test.rs +++ b/ylong_runtime/tests/mpsc_test.rs @@ -11,11 +11,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![cfg(all(feature = "time", feature = "sync"))] + use std::time::Duration; use ylong_runtime::sync::error::{RecvError, RecvTimeoutError, TryRecvError, TrySendError}; use ylong_runtime::sync::mpsc::{bounded_channel, unbounded_channel}; -use ylong_runtime::task::JoinHandle; /// SDV test cases for `UnboundedSender`. /// @@ -228,8 +229,11 @@ fn sdv_mpsc_len() { /// 2. Send and receive for many times. /// 3. Create a bounded mpsc channel with capacity. /// 4. Send and receive for many times. +#[cfg(not(gn_test))] #[test] fn sdv_multi_send_recv_test() { + use ylong_runtime::task::JoinHandle; + let (tx, mut rx) = unbounded_channel(); let mut tasks: Vec> = Vec::new(); for i in 0..1000 { diff --git a/ylong_runtime/tests/singleton_runtime.rs b/ylong_runtime/tests/singleton_runtime.rs index 4d76adb61b703bcc35c46eb6746dca68082815ea..3d49fc21d10b5a14203d10dd98a31cde65f356f5 100644 --- a/ylong_runtime/tests/singleton_runtime.rs +++ b/ylong_runtime/tests/singleton_runtime.rs @@ -11,8 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -mod helpers; -use helpers::*; use ylong_runtime::builder::RuntimeBuilder; use ylong_runtime::task::TaskBuilder; #[cfg(feature = "time")] @@ -20,6 +18,21 @@ use ylong_runtime::time; const SPAWN_NUM: usize = 100; const THREAD_NUM: usize = 10; +async fn test_future(num: usize) -> usize { + num +} + +async fn test_multi_future_in_async(i: usize, j: usize) -> (usize, usize) { + let result_one = test_future(i).await; + let result_two = test_future(j).await; + + (result_one, result_two) +} + +async fn test_async_in_async(i: usize, j: usize) -> (usize, usize) { + test_multi_future_in_async(i, j).await +} + /// SDV test cases for concurrently spawning tasks on the singleton runtime, /// through runtime instance. /// diff --git a/ylong_runtime/tests/spawn.rs b/ylong_runtime/tests/spawn.rs index 372db399787ad177124affeec7363d1216c53f60..d5a408acbba51dcff649e3a02a61e73476acdd3c 100644 --- a/ylong_runtime/tests/spawn.rs +++ b/ylong_runtime/tests/spawn.rs @@ -13,28 +13,39 @@ use ylong_runtime::builder::RuntimeBuilder; -mod helpers; -use helpers::*; +async fn test_future(num: usize) -> usize { + num +} + +async fn test_multi_future_in_async(i: usize, j: usize) -> (usize, usize) { + let result_one = test_future(i).await; + let result_two = test_future(j).await; + (result_one, result_two) +} + +async fn test_async_in_async(i: usize, j: usize) -> (usize, usize) { + test_multi_future_in_async(i, j).await +} // One Core Test #[test] fn sdv_one_core_test() { let core_pool_size = 1; let num = 1000; - let runtime = RuntimeBuilder::new_multi_thread() + RuntimeBuilder::new_multi_thread() .worker_num(core_pool_size) - .build() + .build_global() .unwrap(); let mut handles = Vec::with_capacity(num); for i in 0..num { - handles.push(runtime.spawn(test_future(i))); + handles.push(ylong_runtime::spawn(test_future(i))); } for (times, handle) in handles.into_iter().enumerate() { - let ret = runtime.block_on(handle); + let ret = ylong_runtime::block_on(handle); assert_eq!(ret.unwrap(), times); } } @@ -45,19 +56,19 @@ fn sdv_two_core_test() { let core_pool_size = 2; let num = 1000; - let runtime = RuntimeBuilder::new_multi_thread() + RuntimeBuilder::new_multi_thread() .worker_num(core_pool_size) - .build() + .build_global() .unwrap(); let mut handles = Vec::with_capacity(num); for i in 0..num { - handles.push(runtime.spawn(test_future(i))); + handles.push(ylong_runtime::spawn(test_future(i))); } for (times, handle) in handles.into_iter().enumerate() { - let ret = runtime.block_on(handle); + let ret = ylong_runtime::block_on(handle); assert_eq!(ret.unwrap(), times); } } @@ -68,19 +79,19 @@ fn sdv_three_core_test() { let core_pool_size = 3; let num = 1000; - let runtime = RuntimeBuilder::new_multi_thread() + RuntimeBuilder::new_multi_thread() .worker_num(core_pool_size) - .build() + .build_global() .unwrap(); let mut handles = Vec::with_capacity(num); for i in 0..num { - handles.push(runtime.spawn(test_future(i))); + handles.push(ylong_runtime::spawn(test_future(i))); } for (times, handle) in handles.into_iter().enumerate() { - let ret = runtime.block_on(handle); + let ret = ylong_runtime::block_on(handle); assert_eq!(ret.unwrap(), times); } } @@ -91,19 +102,19 @@ fn sdv_four_core_test() { let core_pool_size = 4; let num = 1000; - let runtime = RuntimeBuilder::new_multi_thread() + RuntimeBuilder::new_multi_thread() .worker_num(core_pool_size) - .build() + .build_global() .unwrap(); let mut handles = Vec::with_capacity(num); for i in 0..num { - handles.push(runtime.spawn(test_future(i))); + handles.push(ylong_runtime::spawn(test_future(i))); } for (times, handle) in handles.into_iter().enumerate() { - let ret = runtime.block_on(handle); + let ret = ylong_runtime::block_on(handle); assert_eq!(ret.unwrap(), times); } } @@ -114,19 +125,19 @@ fn sdv_eight_core_test() { let core_pool_size = 8; let num = 1000; - let runtime = RuntimeBuilder::new_multi_thread() + RuntimeBuilder::new_multi_thread() .worker_num(core_pool_size) - .build() + .build_global() .unwrap(); let mut handles = Vec::with_capacity(num); for i in 0..num { - handles.push(runtime.spawn(test_future(i))); + handles.push(ylong_runtime::spawn(test_future(i))); } for (times, handle) in handles.into_iter().enumerate() { - let ret = runtime.block_on(handle); + let ret = ylong_runtime::block_on(handle); assert_eq!(ret.unwrap(), times); } } @@ -137,19 +148,19 @@ fn sdv_max_core_test() { let core_pool_size = 64; let num = 1000; - let runtime = RuntimeBuilder::new_multi_thread() + RuntimeBuilder::new_multi_thread() .worker_num(core_pool_size) - .build() + .build_global() .unwrap(); let mut handles = Vec::with_capacity(num); for i in 0..num { - handles.push(runtime.spawn(test_future(i))); + handles.push(ylong_runtime::spawn(test_future(i))); } for (times, handle) in handles.into_iter().enumerate() { - let ret = runtime.block_on(handle); + let ret = ylong_runtime::block_on(handle); assert_eq!(ret.unwrap(), times); } } @@ -160,19 +171,19 @@ fn sdv_multi_future_in_async() { let core_pool_size = 4; let num = 1000; - let runtime = RuntimeBuilder::new_multi_thread() + RuntimeBuilder::new_multi_thread() .worker_num(core_pool_size) - .build() + .build_global() .unwrap(); let mut handles = Vec::with_capacity(num); for i in 0..num { - handles.push(runtime.spawn(test_multi_future_in_async(i, i + 1))); + handles.push(ylong_runtime::spawn(test_multi_future_in_async(i, i + 1))); } for (times, handle) in handles.into_iter().enumerate() { - let ret = runtime.block_on(handle); + let ret = ylong_runtime::block_on(handle); assert_eq!(ret.unwrap(), (times, times + 1)); } } @@ -184,19 +195,19 @@ fn sdv_multi_async_in_async() { let core_pool_size = 4; let num = 1000; - let runtime = RuntimeBuilder::new_multi_thread() + RuntimeBuilder::new_multi_thread() .worker_num(core_pool_size) - .build() + .build_global() .unwrap(); let mut handles = Vec::with_capacity(num); for i in 0..num { - handles.push(runtime.spawn(test_async_in_async(i, i + 1))); + handles.push(ylong_runtime::spawn(test_async_in_async(i, i + 1))); } for (times, handle) in handles.into_iter().enumerate() { - let ret = runtime.block_on(handle); + let ret = ylong_runtime::block_on(handle); assert_eq!(ret.unwrap(), (times, times + 1)); } } diff --git a/ylong_runtime/tests/spawn_blocking.rs b/ylong_runtime/tests/spawn_blocking.rs index f6a7297eea72e6035340a8638c6adc4024591078..af8005b1dfb11ac35c01aeaf0193f7e509a8fd89 100644 --- a/ylong_runtime/tests/spawn_blocking.rs +++ b/ylong_runtime/tests/spawn_blocking.rs @@ -11,6 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![cfg(feature = "multi_instance_runtime")] + use std::thread::sleep; use std::time; diff --git a/ylong_runtime/tests/sync.rs b/ylong_runtime/tests/sync.rs index bc8f3da033cce8ceeac917cd868bff2825e9ad94..c603d74347f46a896253fb175dee7efbb1f05a8e 100644 --- a/ylong_runtime/tests/sync.rs +++ b/ylong_runtime/tests/sync.rs @@ -11,6 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![cfg(feature = "sync")] + use std::future::Future; use std::pin::Pin; use std::sync::atomic::AtomicUsize; diff --git a/ylong_runtime/tests/tcp_test.rs b/ylong_runtime/tests/tcp_test.rs index dbbc7bf8eb8ab24718d1f02fd8b45db73ab8b0a9..9972dd4ab77a51414cf0a31225cd749a8e5e85c9 100644 --- a/ylong_runtime/tests/tcp_test.rs +++ b/ylong_runtime/tests/tcp_test.rs @@ -11,6 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![cfg(feature = "net")] + use std::thread; use ylong_runtime::io::{AsyncReadExt, AsyncWriteExt}; diff --git a/ylong_runtime/tests/timer_test.rs b/ylong_runtime/tests/timer_test.rs index d4966d32f742ffee87d9ea6e02451f18d61202e7..b3af6885dc0dc29c1e8d4ff7eb34e9842ed3fb07 100644 --- a/ylong_runtime/tests/timer_test.rs +++ b/ylong_runtime/tests/timer_test.rs @@ -11,6 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![cfg(all(feature = "time", feature = "sync"))] + use std::collections::HashMap; use std::sync::Arc; use std::time::Duration; diff --git a/ylong_runtime/tests/udp_test.rs b/ylong_runtime/tests/udp_test.rs index 53bea765711ddc4c2ec52038782a9d8ced6c42bf..3572c230eeed8d1ba71d1ba76c04967c960633a1 100644 --- a/ylong_runtime/tests/udp_test.rs +++ b/ylong_runtime/tests/udp_test.rs @@ -11,6 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![cfg(feature = "net")] + use std::{io, thread}; use ylong_runtime::net::UdpSocket; diff --git a/ylong_runtime_macros/BUILD.gn b/ylong_runtime_macros/BUILD.gn index e2958a54812109c39f90edd2199d37cf07c4be43..a90330345cbb5b009457b681d993aa4a52d1a3b8 100644 --- a/ylong_runtime_macros/BUILD.gn +++ b/ylong_runtime_macros/BUILD.gn @@ -14,11 +14,11 @@ import("//build/ohos.gni") ohos_rust_proc_macro("ylong_runtime_macros") { + part_name = "ylong_runtime" + subsystem_name = "commonlibrary" + crate_name = "ylong_runtime_macros" edition = "2021" - part_name = "ylong_runtime_mod" - subsystem_name = "commonlibrary" - sources = [ "src/lib.rs" ] } diff --git a/ylong_runtime_macros/src/lib.rs b/ylong_runtime_macros/src/lib.rs index 44e11c17ca630f0e8b2ef79cc500fae6b9f5abde..b0bf60abc2686e2dfb3589f21892dfc0dd0f8364 100644 --- a/ylong_runtime_macros/src/lib.rs +++ b/ylong_runtime_macros/src/lib.rs @@ -59,4 +59,4 @@ pub fn tuple_form(input: TokenStream) -> TokenStream { let tuple = Group::new(Delimiter::Parenthesis, group_inner); TokenStream::from(TokenTree::from(tuple)) -} \ No newline at end of file +}