diff --git a/.github/workflows/ci-preemptive.sh b/.github/workflows/ci-preemptive.sh index 1a244eaf..88172a60 100644 --- a/.github/workflows/ci-preemptive.sh +++ b/.github/workflows/ci-preemptive.sh @@ -17,20 +17,20 @@ export RUST_BACKTRACE=1 # test open-coroutine-core mod cd "${PROJECT_DIR}"/core -"${CARGO}" test --target "${TARGET}" --features preemptive -"${CARGO}" test --target "${TARGET}" --features preemptive --release +"${CARGO}" test --target "${TARGET}" --features preemptive,ci +"${CARGO}" test --target "${TARGET}" --features preemptive,ci --release # test open-coroutine cd "${PROJECT_DIR}"/open-coroutine -"${CARGO}" test --target "${TARGET}" --features preemptive -"${CARGO}" test --target "${TARGET}" --features preemptive --release +"${CARGO}" test --target "${TARGET}" --features preemptive,ci +"${CARGO}" test --target "${TARGET}" --features preemptive,ci --release # test io_uring if [ "${TARGET}" = "x86_64-unknown-linux-gnu" ]; then cd "${PROJECT_DIR}"/core - "${CARGO}" test --target "${TARGET}" --no-default-features --features io_uring,preemptive - "${CARGO}" test --target "${TARGET}" --no-default-features --features io_uring,preemptive --release + "${CARGO}" test --target "${TARGET}" --no-default-features --features io_uring,preemptive,ci + "${CARGO}" test --target "${TARGET}" --no-default-features --features io_uring,preemptive,ci --release cd "${PROJECT_DIR}"/open-coroutine - "${CARGO}" test --target "${TARGET}" --no-default-features --features io_uring,preemptive - "${CARGO}" test --target "${TARGET}" --no-default-features --features io_uring,preemptive --release + "${CARGO}" test --target "${TARGET}" --no-default-features --features io_uring,preemptive,ci + "${CARGO}" test --target "${TARGET}" --no-default-features --features io_uring,preemptive,ci --release fi diff --git a/.github/workflows/ci.sh b/.github/workflows/ci.sh index 47b5a23c..5e291dd2 100644 --- a/.github/workflows/ci.sh +++ b/.github/workflows/ci.sh @@ -17,20 +17,20 @@ export RUST_BACKTRACE=1 # test open-coroutine-core mod cd "${PROJECT_DIR}"/core -"${CARGO}" test --target "${TARGET}" -"${CARGO}" test --target "${TARGET}" --release +"${CARGO}" test --target "${TARGET}" --features ci +"${CARGO}" test --target "${TARGET}" --features ci --release # test open-coroutine cd "${PROJECT_DIR}"/open-coroutine -"${CARGO}" test --target "${TARGET}" -"${CARGO}" test --target "${TARGET}" --release +"${CARGO}" test --target "${TARGET}" --features ci +"${CARGO}" test --target "${TARGET}" --features ci --release # test io_uring if [ "${TARGET}" = "x86_64-unknown-linux-gnu" ]; then cd "${PROJECT_DIR}"/core - "${CARGO}" test --target "${TARGET}" --no-default-features --features io_uring - "${CARGO}" test --target "${TARGET}" --no-default-features --features io_uring --release + "${CARGO}" test --target "${TARGET}" --no-default-features --features io_uring,ci + "${CARGO}" test --target "${TARGET}" --no-default-features --features io_uring,ci --release cd "${PROJECT_DIR}"/open-coroutine - "${CARGO}" test --target "${TARGET}" --no-default-features --features io_uring - "${CARGO}" test --target "${TARGET}" --no-default-features --features io_uring --release + "${CARGO}" test --target "${TARGET}" --no-default-features --features io_uring,ci + "${CARGO}" test --target "${TARGET}" --no-default-features --features io_uring,ci --release fi diff --git a/core/Cargo.toml b/core/Cargo.toml index af54b320..bc058abf 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -35,13 +35,13 @@ crossbeam-utils = { workspace = true, optional = true } psm.workspace = true [target.'cfg(unix)'.dependencies] -libc.workspace = true -nix = { workspace = true, features = ["signal"] } mio = { workspace = true, features = [ "net", "os-poll", "os-ext", ], default-features = false, optional = true } +nix = { workspace = true, features = ["signal"] } +libc.workspace = true [target.'cfg(target_os = "linux")'.dependencies] io-uring = { workspace = true, optional = true } @@ -72,10 +72,15 @@ slab.workspace = true backtrace.workspace = true [features] +default = ["log", "syscall"] + # Print some help log. # Enable for default. log = ["tracing", "tracing-subscriber", "time"] +# This feature only used in open-coroutine inner, don't use it in your project. +ci = [] + # low-level raw coroutine korosensei = ["corosensei", "uuid", "nix/pthread", "educe"] @@ -91,5 +96,3 @@ io_uring = ["net", "io-uring"] # Provide syscall implementation. syscall = ["net"] - -default = ["log", "syscall"] \ No newline at end of file diff --git a/core/src/common/ci.rs b/core/src/common/ci.rs new file mode 100644 index 00000000..28d02550 --- /dev/null +++ b/core/src/common/ci.rs @@ -0,0 +1,8 @@ +/// just for CI +pub fn init() { + let _ = std::thread::spawn(|| { + // exit after 600 seconds, just for CI + std::thread::sleep(std::time::Duration::from_secs(600)); + std::process::exit(-1); + }); +} diff --git a/core/src/common/mod.rs b/core/src/common/mod.rs index 0e7aff9d..44150798 100644 --- a/core/src/common/mod.rs +++ b/core/src/common/mod.rs @@ -3,6 +3,10 @@ use std::ffi::c_int; use std::sync::atomic::{AtomicUsize, Ordering}; use std::time::{Duration, SystemTime, UNIX_EPOCH}; +/// CI tools. +#[cfg(feature = "ci")] +pub mod ci; + /// Constants. pub mod constants; diff --git a/core/src/net/mod.rs b/core/src/net/mod.rs index b512a39a..5b811d8a 100644 --- a/core/src/net/mod.rs +++ b/core/src/net/mod.rs @@ -60,6 +60,8 @@ impl EventLoops { /// Init the `EventLoops`. pub fn init(config: &Config) { _ = INSTANCE.get_or_init(|| { + #[cfg(feature = "ci")] + crate::common::ci::init(); let loops = Self::new( config.event_loop_size(), config.stack_size(), diff --git a/hook/Cargo.toml b/hook/Cargo.toml index 47c4f4a5..e1c324cc 100644 --- a/hook/Cargo.toml +++ b/hook/Cargo.toml @@ -30,10 +30,15 @@ windows-sys = { workspace = true, features = [ minhook.workspace = true [features] +default = ["open-coroutine-core/default"] + # Print some help log. # Enable for default. log = ["open-coroutine-core/log"] +# This feature only used in open-coroutine inner, don't use it in your project. +ci = ["open-coroutine-core/ci"] + # Provide preemptive scheduling implementation. # Enable for default. preemptive = ["open-coroutine-core/preemptive"] @@ -47,7 +52,5 @@ io_uring = ["open-coroutine-core/io_uring"] # Provide syscall implementation. syscall = ["open-coroutine-core/syscall"] -default = ["open-coroutine-core/default"] - [lib] crate-type = ["cdylib"] diff --git a/open-coroutine/Cargo.toml b/open-coroutine/Cargo.toml index 8dacd906..5f63daaa 100644 --- a/open-coroutine/Cargo.toml +++ b/open-coroutine/Cargo.toml @@ -45,6 +45,9 @@ default = ["open-coroutine-hook/default", "open-coroutine-core/default"] # Enable for default. log = ["open-coroutine-hook/log", "open-coroutine-core/log"] +# This feature only used in open-coroutine inner, don't use it in your project. +ci = ["open-coroutine-hook/ci", "open-coroutine-core/ci"] + # Provide preemptive scheduling implementation. # Enable for default. preemptive = ["open-coroutine-hook/preemptive", "open-coroutine-core/preemptive"] diff --git a/open-coroutine/src/lib.rs b/open-coroutine/src/lib.rs index 0fbb9151..7aca001e 100644 --- a/open-coroutine/src/lib.rs +++ b/open-coroutine/src/lib.rs @@ -92,6 +92,8 @@ pub fn init(config: Config) { unsafe { open_coroutine_init(config) }, "open-coroutine init failed !" ); + #[cfg(feature = "ci")] + open_coroutine_core::common::ci::init(); } /// Shutdown the open-coroutine.