-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrtm_test.go
49 lines (42 loc) · 946 Bytes
/
rtm_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package rtm
// test without abort
// test with abort
// test _xtest behaviour
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestXTestOutsideTransaction(t *testing.T) {
actualResult := TxTest()
assert.Equal(t, uint8(0), actualResult)
}
func TestXTestInsideTransaction(t *testing.T) {
TxBegin()
actualResult := TxTest()
TxEnd()
assert.Equal(t, uint8(1), actualResult)
}
func TestTransactionAbort(t *testing.T) {
a := 0
if status := TxBegin(); status == TxBeginStarted {
a += 6
TxAbort()
TxEnd()
t.Fail() // shouldn't get here
} else {
assert.Equal(t, uint32(0xf0000001), status)
assert.Equal(t, uint32(0x1), status&TxAbortExplicit)
assert.Equal(t, uint8(0xf0), GetImm(status))
assert.Equal(t, 0, a)
}
}
func TestTransactionCommit(t *testing.T) {
a := 0
if status := TxBegin(); status == TxBeginStarted {
a += 6
TxEnd()
} else {
t.Fail() // shouldn't get here
}
assert.Equal(t, 6, a)
}