Skip to content

Commit

Permalink
Add tests for store and atomic store
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Jowett <[email protected]>
  • Loading branch information
Alan Jowett committed Oct 17, 2024
1 parent 4c6cb0d commit c767e2a
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/assertions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class AssertExtractor {
res.emplace_back(TypeConstraint{ins.access.basereg, TypeGroup::pointer});
res.emplace_back(
ValidAccess{ins.access.basereg, ins.access.offset, Imm{static_cast<uint32_t>(ins.access.width)}, false});
res.emplace_back(TypeConstraint{ins.valreg, TypeGroup::number});
if (ins.op == Atomic::Op::CMPXCHG) {
// The memory contents pointed to by ins.access will be compared
// against the value of the ins.valreg register. Only numbers are
Expand Down
180 changes: 180 additions & 0 deletions test-data/uninit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,183 @@ post:
- "r0.svalue=r3.svalue"
- "r0.type=r3.type"
- "r0.uvalue=r3.uvalue"

---
test-case: Store uninitialized register to context - 8 bytes

pre:
- "r1.type=ctx"
- "r1.ctx_offset=0"

code:
<start>: |
*(u64 *)(r1 + 0) = r0
post:
- "r1.type=ctx"
- "r1.ctx_offset=0"

messages:
- "0: Only numbers can be stored to externally-visible regions (r1.type != stack -> r0.type == number)"

---
test-case: Store uninitialized register to context - 4 bytes

pre:
- "r1.type=ctx"
- "r1.ctx_offset=0"

code:
<start>: |
*(u32 *)(r1 + 0) = r0
post:
- "r1.type=ctx"
- "r1.ctx_offset=0"

messages:
- "0: Invalid type (r0.type == number)"

---
test-case: Store uninitialized register to context - 2 bytes

pre:
- "r1.type=ctx"
- "r1.ctx_offset=0"

code:
<start>: |
*(u16 *)(r1 + 0) = r0
post:
- "r1.type=ctx"
- "r1.ctx_offset=0"

messages:
- "0: Invalid type (r0.type == number)"

---
test-case: Store uninitialized register to context - 1 bytes

pre:
- "r1.type=ctx"
- "r1.ctx_offset=0"

code:
<start>: |
*(u8 *)(r1 + 0) = r0
post:
- "r1.type=ctx"
- "r1.ctx_offset=0"

messages:
- "0: Invalid type (r0.type == number)"

---
test-case: Atomic add uninitialized register to context

pre:
- "r1.type=ctx"
- "r1.ctx_offset=0"

code:
<start>: |
lock *(u64 *)(r1 + 0) += r5
post:
- "r1.type=ctx"
- "r1.ctx_offset=0"

messages:
- "0: Invalid type (r5.type == number)"

---
test-case: Atomic AND uninitialized register to context

pre:
- "r1.type=ctx"
- "r1.ctx_offset=0"

code:
<start>: |
lock *(u64 *)(r1 + 0) &= r5
post:
- "r1.type=ctx"
- "r1.ctx_offset=0"

messages:
- "0: Invalid type (r5.type == number)"

---
test-case: Atomic OR uninitialized register to context

pre:
- "r1.type=ctx"
- "r1.ctx_offset=0"

code:
<start>: |
lock *(u64 *)(r1 + 0) |= r5
post:
- "r1.type=ctx"
- "r1.ctx_offset=0"

messages:
- "0: Invalid type (r5.type == number)"

---
test-case: Atomic XOR uninitialized register to context

pre:
- "r1.type=ctx"
- "r1.ctx_offset=0"

code:
<start>: |
lock *(u64 *)(r1 + 0) |= r5
post:
- "r1.type=ctx"
- "r1.ctx_offset=0"

messages:
- "0: Invalid type (r5.type == number)"

---
test-case: Atomic XHNG uninitialized register to context

pre:
- "r1.type=ctx"
- "r1.ctx_offset=0"

code:
<start>: |
lock *(u64 *)(r1 + 0) x= r5
post:
- "r1.type=ctx"
- "r1.ctx_offset=0"

messages:
- "0: Invalid type (r5.type == number)"

---
test-case: Atomic CMPXCHG uninitialized register to context

pre:
- "r1.type=ctx"
- "r1.ctx_offset=0"

code:
<start>: |
lock *(u64 *)(r1 + 0) cx= r5
post:
- "r1.type=ctx"
- "r1.ctx_offset=0"

messages:
- "0: Invalid type (r5.type == number)"

0 comments on commit c767e2a

Please sign in to comment.