From 32300303cc5f28aabeffc48154f936a0417bff65 Mon Sep 17 00:00:00 2001
From: Simon Hudon <simonhudon@google.com>
Date: Mon, 17 May 2021 12:50:46 -0400
Subject: [PATCH] Add test case for Xchg

---
 tests/heap_lang.ref | 31 +++++++++++++++++++++++++++++++
 tests/heap_lang.v   | 26 +++++++++++++++++++++++++-
 2 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/tests/heap_lang.ref b/tests/heap_lang.ref
index 64e373820..e61cca8e1 100644
--- a/tests/heap_lang.ref
+++ b/tests/heap_lang.ref
@@ -267,6 +267,37 @@ goal 2 is:
 --------------------------------------∗
 WP #() #() @ E ∖ ↑N {{ _, |={E ∖ ↑N}=> ▷ P ∗ True }}
 
+"xchg_example"
+     : string
+1 goal
+  
+  Σ : gFunctors
+  heapG0 : heapG Σ
+  l : loc
+  v₁, v₂ : val
+  Φ : val → iPropI Σ
+  ============================
+  "Hl" : l ↦ v₂
+  "HΦ" : l ↦ v₂ -∗ Φ v₁
+  --------------------------------------∗
+  |={⊤}=> Φ v₁
+  
+1 goal
+  
+  Σ : gFunctors
+  heapG0 : heapG Σ
+  N : namespace
+  l : loc
+  v : val
+  Φ : language.val heap_lang → iPropI Σ
+  v' : val
+  ============================
+  "HΦ" : ∀ v'0 : language.val heap_lang, True -∗ Φ v'0
+  "Hl" : l ↦ v
+  "Hclose" : ▷ (∃ v0 : val, l ↦ v0) ={⊤ ∖ ↑N,⊤}=∗ emp
+  --------------------------------------∗
+  |={⊤ ∖ ↑N,⊤}=> Φ v'
+  
 1 goal
   
   Σ : gFunctors
diff --git a/tests/heap_lang.v b/tests/heap_lang.v
index a05b855a2..458755ade 100644
--- a/tests/heap_lang.v
+++ b/tests/heap_lang.v
@@ -333,7 +333,7 @@ Section mapsto_tests.
   (* Loading from the general mapsto for any [dfrac]. *)
   Lemma general_mapsto dq l v :
     [[{ l ↦{dq} v }]] ! #l [[{ RET v; True }]].
-  Proof. 
+  Proof.
     iIntros (Φ) "Hl HΦ". Show. wp_load. by iApply "HΦ".
   Qed.
 
@@ -382,6 +382,30 @@ Section atomic.
     (* Test if a side-condition for [Atomic] is generated *)
     iIntros (?) "H". iInv "H" as "H". Show.
   Abort.
+
+  Check "xchg_example".
+
+  Lemma xchg_example l (v₁ v₂ : val) :
+    {{{ l ↦ v₁ }}}
+      Xchg #l vâ‚‚
+    {{{ RET v₁; l ↦ v₂ }}}.
+  Proof.
+    iIntros (Φ) "Hl HΦ".
+    wp_xchg.
+    Show.
+  Abort.
+
+  Lemma xchg_inv_example N l (v : val) :
+    {{{ inv N (∃ v, l ↦ v) }}}
+      Xchg #l v
+    {{{ v', RET v'; True }}}.
+  Proof.
+    iIntros (Φ) "Hl HΦ".
+    iInv "Hl" as (v') "Hl" "Hclose".
+    wp_xchg.
+    Show.
+  Abort.
+
 End atomic.
 
 Section printing_tests.
-- 
GitLab