diff --git a/ylong_runtime/BUILD.gn b/ylong_runtime/BUILD.gn index 67f92e4e93127842e454831d8438ed5df5e1ff4e..eb12d70cb6b395a787b36368dec3f7e23f20a8dd 100644 --- a/ylong_runtime/BUILD.gn +++ b/ylong_runtime/BUILD.gn @@ -37,7 +37,7 @@ ohos_rust_shared_library("ylong_runtime") { ] } -ohos_rust_unittest("unittest") { +ohos_rust_unittest("rust_ylong_runtime_test_ut") { module_out_path = "ylong_runtime/ylong_runtime" rustflags = [ @@ -56,7 +56,7 @@ ohos_rust_unittest("unittest") { ] } -ohos_rust_systemtest("sdvtest") { +ohos_rust_systemtest("rust_ylong_runtime_test_sdv") { module_out_path = "ylong_runtime/ylong_runtime" rustflags = [ @@ -71,3 +71,13 @@ ohos_rust_systemtest("sdvtest") { sources = [ "tests/entry.rs" ] deps = [ ":ylong_runtime" ] } + +group("unittest") { + testonly = true + deps = [ ":rust_ylong_runtime_test_ut" ] +} + +group("sdvtest") { + testonly = true + deps = [ ":rust_ylong_runtime_test_sdv" ] +} diff --git a/ylong_runtime/tests/async_buf_read.rs b/ylong_runtime/tests/async_buf_read.rs index b9862cc34a5b0c2267ceb929d2ab64013c17cc92..fc809d0acc135b966b548c961d1ff788ff5b3365 100644 --- a/ylong_runtime/tests/async_buf_read.rs +++ b/ylong_runtime/tests/async_buf_read.rs @@ -196,7 +196,6 @@ 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; @@ -206,7 +205,7 @@ fn sdv_buf_reader_seek() { 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 mut file = File::create("buf_reader_seek_file").await.unwrap(); let buf = "lorem-ipsum-dolor".as_bytes(); let res = file.write(buf).await.unwrap(); assert_eq!(res, 17); @@ -214,7 +213,7 @@ fn sdv_buf_reader_seek() { ylong_runtime::block_on(handle).unwrap(); let handle1 = ylong_runtime::spawn(async move { - let file = File::open("./tests/buf_reader_seek_file").await.unwrap(); + let file = File::open("buf_reader_seek_file").await.unwrap(); let mut buf_reader = AsyncBufReader::new(file); let mut res = vec![]; let ret = buf_reader.read_until(b'-', &mut res).await.unwrap(); @@ -243,5 +242,5 @@ fn sdv_buf_reader_seek() { assert_eq!(buf, "dolor".as_bytes()); }); ylong_runtime::block_on(handle1).unwrap(); - assert!(fs::remove_file("./tests/buf_reader_seek_file").is_ok()); + assert!(fs::remove_file("buf_reader_seek_file").is_ok()); } diff --git a/ylong_runtime/tests/async_buf_write.rs b/ylong_runtime/tests/async_buf_write.rs index cb0bbd58f0ac6de20e6a50b25a4924acee167f44..63cba494e6164fd3a52060aa0e3d12116f7e0238 100644 --- a/ylong_runtime/tests/async_buf_write.rs +++ b/ylong_runtime/tests/async_buf_write.rs @@ -105,7 +105,6 @@ 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; @@ -115,7 +114,7 @@ fn sdv_buf_writer_seek() { 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 mut file = File::create("buf_writer_seek_file").await.unwrap(); let buf = "lorem-ipsum-dolor".as_bytes(); let res = file.write(buf).await.unwrap(); assert_eq!(res, 17); @@ -123,7 +122,7 @@ fn sdv_buf_writer_seek() { ylong_runtime::block_on(handle).unwrap(); let handle1 = ylong_runtime::spawn(async move { - let file = File::open("./tests/buf_writer_seek_file").await.unwrap(); + let file = File::open("buf_writer_seek_file").await.unwrap(); let mut buf_writer = AsyncBufWriter::new(file); let seek = buf_writer.seek(SeekFrom::Start(5)).await.unwrap(); @@ -149,5 +148,5 @@ fn sdv_buf_writer_seek() { assert_eq!(buf, "dolor".as_bytes()); }); ylong_runtime::block_on(handle1).unwrap(); - assert!(fs::remove_file("./tests/buf_writer_seek_file").is_ok()); + assert!(fs::remove_file("buf_writer_seek_file").is_ok()); } diff --git a/ylong_runtime/tests/async_dir.rs b/ylong_runtime/tests/async_dir.rs index 3226235ecca95e210140ddf542e0c090198eb358..e670dee4834c1236c8c3cfaa6e35e540363f8c8f 100644 --- a/ylong_runtime/tests/async_dir.rs +++ b/ylong_runtime/tests/async_dir.rs @@ -11,9 +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. @@ -26,10 +26,14 @@ use ylong_runtime::fs::{create_dir, create_dir_all, read_dir, remove_dir, remove #[test] fn sdv_async_dir() { let handle = ylong_runtime::spawn(async move { - let _ = create_dir("./tests/dir_test").await; - File::create("./tests/dir_test/test1.txt").await.unwrap(); - File::create("./tests/dir_test/test2.txt").await.unwrap(); - let mut dir = read_dir("./tests/dir_test").await.unwrap(); + let _ = create_dir("dir_test").await; + File::create("dir_test/test1.txt") + .await + .unwrap(); + File::create("dir_test/test2.txt") + .await + .unwrap(); + let mut dir = read_dir("dir_test").await.unwrap(); let entry = dir.next().await.unwrap().unwrap(); assert!(!entry.file_type().await.unwrap().is_dir()); assert!(entry.file_type().await.unwrap().is_file()); @@ -40,7 +44,7 @@ fn sdv_async_dir() { assert!(!entry.metadata().await.unwrap().permissions().readonly()); assert!(entry.file_name().into_string().unwrap().contains("test")); assert!(dir.next().await.unwrap().is_none()); - assert!(remove_dir_all("./tests/dir_test").await.is_ok()); + assert!(remove_dir_all("dir_test").await.is_ok()); }); ylong_runtime::block_on(handle).unwrap(); } @@ -61,19 +65,19 @@ fn sdv_async_dir() { #[test] fn sdv_async_dir_create_remove() { let handle = ylong_runtime::spawn(async move { - assert!(create_dir("./tests/dir_test1").await.is_ok()); - assert!(create_dir("./tests/dir_test1").await.is_err()); - assert!(create_dir("./tests/dir_test2/dir_test_child") + assert!(create_dir("dir_test1").await.is_ok()); + assert!(create_dir("dir_test1").await.is_err()); + assert!(create_dir("dir_test2/dir_test_child") .await .is_err()); - assert!(create_dir_all("./tests/dir_test2/dir_test_child") + assert!(create_dir_all("dir_test2/dir_test_child") .await .is_ok()); - assert!(remove_dir("./tests/dir_test1").await.is_ok()); - assert!(remove_dir("./tests/dir_test1").await.is_err()); - assert!(remove_dir("./tests/async_dir").await.is_err()); - assert!(remove_dir("./tests/dir_test2").await.is_err()); - assert!(remove_dir_all("./tests/dir_test2").await.is_ok()); + assert!(remove_dir("dir_test1").await.is_ok()); + assert!(remove_dir("dir_test1").await.is_err()); + assert!(remove_dir("async_dir").await.is_err()); + assert!(remove_dir("dir_test2").await.is_err()); + assert!(remove_dir_all("dir_test2").await.is_ok()); }); ylong_runtime::block_on(handle).unwrap(); } diff --git a/ylong_runtime/tests/async_fs.rs b/ylong_runtime/tests/async_fs.rs index 62396c347f1223e49a65dc0f6c267c1818ca50a2..44e15452fb265a7f1ad47fc63a021effe6c98d7f 100644 --- a/ylong_runtime/tests/async_fs.rs +++ b/ylong_runtime/tests/async_fs.rs @@ -13,8 +13,8 @@ #![cfg(feature = "fs")] -use std::fs; use std::io::SeekFrom; +use std::{fs}; use ylong_runtime::fs::{File, OpenOptions}; use ylong_runtime::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt}; @@ -28,7 +28,7 @@ use ylong_runtime::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt}; #[test] fn sdv_async_fs_write() { let handle = ylong_runtime::spawn(async move { - let mut file = File::create("./tests/tmp_file").await.unwrap(); + let mut file = File::create("tmp_file").await.unwrap(); let buf = "hello".as_bytes().to_vec(); let res = file.write(&buf).await.unwrap(); assert_eq!(res, 5); @@ -37,14 +37,14 @@ fn sdv_async_fs_write() { ylong_runtime::block_on(handle).unwrap(); let handle1 = ylong_runtime::spawn(async move { - let mut file = File::open("./tests/tmp_file").await.unwrap(); + let mut file = File::open("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()); }); ylong_runtime::block_on(handle1).unwrap(); - fs::remove_file("./tests/tmp_file").unwrap(); + fs::remove_file("tmp_file").unwrap(); } /// SDV test cases for asynchronous file reading @@ -56,13 +56,13 @@ fn sdv_async_fs_write() { #[test] fn sdv_async_fs_read() { let handle = ylong_runtime::spawn(async move { - let mut file = File::create("./tests/tmp_file2").await.unwrap(); + let mut file = File::create("tmp_file2").await.unwrap(); let buf = vec![1, 2, 3, 4, 5]; let res = file.write(&buf).await.unwrap(); assert_eq!(res, 5); file.sync_all().await.unwrap(); - let mut file = File::open("./tests/tmp_file2").await.unwrap(); + let mut file = File::open("tmp_file2").await.unwrap(); let mut buf = [0; 5]; let res = file.read(&mut buf).await.unwrap(); assert_eq!(res, 5); @@ -71,14 +71,14 @@ fn sdv_async_fs_read() { ylong_runtime::block_on(handle).unwrap(); let handle2 = ylong_runtime::spawn(async move { - let mut file = File::open("./tests/tmp_file2").await.unwrap(); + let mut file = File::open("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]); }); ylong_runtime::block_on(handle2).unwrap(); - fs::remove_file("./tests/tmp_file2").unwrap(); + fs::remove_file("tmp_file2").unwrap(); } /// SDV test cases for asynchronous file multi-threaded read and write @@ -90,14 +90,14 @@ fn sdv_async_fs_read() { #[test] fn sdv_async_fs_rw() { let handle = ylong_runtime::spawn(async move { - let _ = File::create("./tests/tmp_file3").await.unwrap(); + let _ = File::create("tmp_file3").await.unwrap(); }); ylong_runtime::block_on(handle).unwrap(); let handle = ylong_runtime::spawn(async move { let mut file = OpenOptions::new() .append(true) - .open("./tests/tmp_file3") + .open("tmp_file3") .await .unwrap(); let buf = vec![45, 46, 47, 48, 49]; @@ -115,9 +115,9 @@ fn sdv_async_fs_rw() { ylong_runtime::block_on(handle).unwrap(); let handle2 = ylong_runtime::spawn(async move { - let mut file = File::open("./tests/tmp_file3").await; + let mut file = File::open("tmp_file3").await; while file.is_err() { - file = File::open("./tests/tmp_file3").await; + file = File::open("tmp_file3").await; } let mut file = file.unwrap(); @@ -145,7 +145,7 @@ fn sdv_async_fs_rw() { assert_eq!(&buf, &buf2); }); ylong_runtime::block_on(handle2).unwrap(); - fs::remove_file("./tests/tmp_file3").unwrap(); + fs::remove_file("tmp_file3").unwrap(); } /// SDV test cases for Asynchronous file multi-threaded read and write @@ -157,20 +157,20 @@ fn sdv_async_fs_rw() { #[test] fn sdv_async_fs_read_to_end() { let handle = ylong_runtime::spawn(async move { - let mut file = File::create("./tests/tmp_file7").await.unwrap(); + let mut file = File::create("tmp_file7").await.unwrap(); let buf = [2; 40000]; file.write_all(&buf).await.unwrap(); file.sync_all().await.unwrap(); }); 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 file = File::open("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); }); ylong_runtime::block_on(handle1).unwrap(); - fs::remove_file("./tests/tmp_file7").unwrap(); + fs::remove_file("tmp_file7").unwrap(); } /// SDV test cases for asynchronous file Seek @@ -182,7 +182,7 @@ fn sdv_async_fs_read_to_end() { #[test] fn sdv_async_fs_seek() { let handle = ylong_runtime::spawn(async move { - let mut file = File::create("./tests/tmp_file4").await.unwrap(); + let mut file = File::create("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); @@ -191,7 +191,7 @@ fn sdv_async_fs_seek() { ylong_runtime::block_on(handle).unwrap(); let handle2 = ylong_runtime::spawn(async move { - let mut file = File::open("./tests/tmp_file4").await.unwrap(); + let mut file = File::open("tmp_file4").await.unwrap(); let ret = file.seek(SeekFrom::Current(3)).await.unwrap(); assert_eq!(ret, 3); @@ -232,7 +232,7 @@ fn sdv_async_fs_seek() { }); ylong_runtime::block_on(handle2).unwrap(); - fs::remove_file("./tests/tmp_file4").unwrap(); + fs::remove_file("tmp_file4").unwrap(); } /// SDV test cases for Asynchronous file set permission @@ -244,7 +244,7 @@ fn sdv_async_fs_seek() { #[test] fn sdv_async_fs_set_permission() { let handle = ylong_runtime::spawn(async move { - let file = File::create("./tests/tmp_file5").await.unwrap(); + let file = File::create("tmp_file5").await.unwrap(); let mut perms = file.metadata().await.unwrap().permissions(); perms.set_readonly(true); let ret = file.set_permissions(perms).await; @@ -256,7 +256,7 @@ fn sdv_async_fs_set_permission() { assert!(ret.is_ok()); }); ylong_runtime::block_on(handle).unwrap(); - fs::remove_file("./tests/tmp_file5").unwrap(); + fs::remove_file("tmp_file5").unwrap(); } /// SDV test cases for asynchronous file sync @@ -267,7 +267,7 @@ fn sdv_async_fs_set_permission() { #[test] fn sdv_async_fs_sync_all() { let handle = ylong_runtime::spawn(async move { - let mut file = File::create("./tests/tmp_file6").await.unwrap(); + let mut file = File::create("tmp_file6").await.unwrap(); let buf = [2; 20000]; let ret = file.write_all(&buf).await; assert!(ret.is_ok()); @@ -281,5 +281,5 @@ fn sdv_async_fs_sync_all() { assert!(ret.is_ok()); }); ylong_runtime::block_on(handle).unwrap(); - fs::remove_file("./tests/tmp_file6").unwrap(); + fs::remove_file("tmp_file6").unwrap(); } diff --git a/ylong_runtime/tests/mpsc_test.rs b/ylong_runtime/tests/mpsc_test.rs index e3b4f2c1229c0616903b398b319f759223e78eac..ade4213af04a4748044c4bb1da5c0e5a8cb2805c 100644 --- a/ylong_runtime/tests/mpsc_test.rs +++ b/ylong_runtime/tests/mpsc_test.rs @@ -229,7 +229,6 @@ 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;