about summary refs log tree commit diff
path: root/tests/coverage-map/status-quo/async2.rs
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2023-08-14 21:29:41 +1000
committerZalathar <Zalathar@users.noreply.github.com>2023-09-05 11:55:34 +1000
commit3141177995f52fc3cbb64d66cf0a98ea0f754fca (patch)
tree59c3eb121dbfee7c2793e0b85037a05e1198d74d /tests/coverage-map/status-quo/async2.rs
parent004db4728bc6ccc62416f93ba6473b144def7fe8 (diff)
downloadrust-3141177995f52fc3cbb64d66cf0a98ea0f754fca.tar.gz
rust-3141177995f52fc3cbb64d66cf0a98ea0f754fca.zip
Copy most of `tests/run-coverage` into `tests/coverage-map/status-quo`
The output of these tests is too complicated to comfortably verify by hand, but
we can still use them to observe changes to the underlying mappings produced by
codegen/LLVM.

If these tests fail due to non-coverage changes (e.g. in HIR-to-MIR lowering or
MIR optimizations), it should usually be OK to just `--bless` them, as long as
the `run-coverage` test suite still works.
Diffstat (limited to 'tests/coverage-map/status-quo/async2.rs')
-rw-r--r--tests/coverage-map/status-quo/async2.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/coverage-map/status-quo/async2.rs b/tests/coverage-map/status-quo/async2.rs
new file mode 100644
index 00000000000..2884ff297af
--- /dev/null
+++ b/tests/coverage-map/status-quo/async2.rs
@@ -0,0 +1,57 @@
+// compile-flags: --edition=2018
+
+fn non_async_func() {
+    println!("non_async_func was covered");
+    let b = true;
+    if b {
+        println!("non_async_func println in block");
+    }
+}
+
+async fn async_func() {
+    println!("async_func was covered");
+    let b = true;
+    if b {
+        println!("async_func println in block");
+    }
+}
+
+async fn async_func_just_println() {
+    println!("async_func_just_println was covered");
+}
+
+fn main() {
+    println!("codecovsample::main");
+
+    non_async_func();
+
+    executor::block_on(async_func());
+    executor::block_on(async_func_just_println());
+}
+
+mod executor {
+    use core::{
+        future::Future,
+        pin::Pin,
+        task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
+    };
+
+    pub fn block_on<F: Future>(mut future: F) -> F::Output {
+        let mut future = unsafe { Pin::new_unchecked(&mut future) };
+        use std::hint::unreachable_unchecked;
+        static VTABLE: RawWakerVTable = RawWakerVTable::new(
+            |_| unsafe { unreachable_unchecked() }, // clone
+            |_| unsafe { unreachable_unchecked() }, // wake
+            |_| unsafe { unreachable_unchecked() }, // wake_by_ref
+            |_| (),
+        );
+        let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
+        let mut context = Context::from_waker(&waker);
+
+        loop {
+            if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
+                break val;
+            }
+        }
+    }
+}