-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathswt-test.py
More file actions
executable file
·123 lines (107 loc) · 3.59 KB
/
swt-test.py
File metadata and controls
executable file
·123 lines (107 loc) · 3.59 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python
import unittest
import libO2Alf
import time
import threading
class TestSwt(unittest.TestCase):
def test_init(self):
swt = libO2Alf.SwtInterface("#1", 0)
def test_init_fails(self):
with self.assertRaises(RuntimeError):
swt = libO2Alf.SwtInterface("#1", 42) # linkId out of range
def test_sc_reset(self):
swt = libO2Alf.SwtInterface("#1", 0)
swt.sc_reset()
def test_set_channel(self):
swt = libO2Alf.SwtInterface("#1", 0)
swt.set_channel(0)
def test_set_channel_fails(self):
swt = libO2Alf.SwtInterface("#1", 0)
with self.assertRaises(RuntimeError):
swt.set_channel(42) #linkId out of range
def test_write_read(self):
swt = libO2Alf.SwtInterface("#1", 0)
swt.sc_reset();
swt.write(0xdd)
words = swt.read()
self.assertEqual(words, [(0xdd)])
def test_write_reset_read(self):
swt = libO2Alf.SwtInterface("#1", 0)
swt.write(0xdd)
swt.sc_reset();
with self.assertRaises(RuntimeError):
words = swt.read()
def test_write_read_time(self):
swt = libO2Alf.SwtInterface("#1", 0)
swt.sc_reset();
swt.write(0xdd)
words = swt.read(20)
self.assertEqual(words, [(0xdd)])
def test_write_read_time_fails(self):
swt = libO2Alf.SwtInterface("#1", 0)
swt.write(0xdd)
swt.sc_reset()
start = time.time()
with self.assertRaises(RuntimeError):
words = swt.read(100)
end = time.time()
self.assertGreater(end-start, 0.1)
def test_sequence(self):
swt = libO2Alf.SwtInterface("#1", 0)
swt.sc_reset()
sequence = [("write", 0xdeadbeef),
("write", 0xcafecafe),
("read")];
out = swt.sequence(sequence)
self.assertEqual(out,
[("write", 0xdeadbeef),
("write", 0xcafecafe),
("read", 0xdeadbeef),
("read", 0xcafecafe)])
def test_sequence_wait(self):
swt = libO2Alf.SwtInterface("#1", 0)
swt.sc_reset()
sequence = [("write", 0xdeadbeef),
("wait", 100),
("read", 80)];
start = time.time()
out = swt.sequence(sequence)
end = time.time()
self.assertEqual(out,
[("write", 0xdeadbeef),
("wait", 100),
("read", 0xdeadbeef)])
self.assertGreater(end - start, 0.1)
def test_sequence_reset(self):
swt = libO2Alf.SwtInterface("#1", 0)
sequence = [("write", 0xdeadbeef),
("sc_reset"),
("write", 0xcafecafe),
("read", 80)];
out = swt.sequence(sequence)
self.assertEqual(out,
[("write", 0xdeadbeef),
("sc_reset", ""),
("write", 0xcafecafe),
("read", 0xcafecafe)])
def test_sequence_error(self):
swt = libO2Alf.SwtInterface("#1", 0)
sequence = [("write", 0xdeadbeef),
("sc_reset"),
("read", 80)];
out = swt.sequence(sequence)
self.assertEqual(out[2][0], "error")
def test_sequence_lock(self):
swt = libO2Alf.SwtInterface("#1", 0)
swt.sc_reset()
swt_w = libO2Alf.SwtInterface("#1", 1)
swt_w.sc_reset()
sequence = [("write", 0xdeadbeef),
("wait", 200),
("read", 80)];
t = threading.Thread(target=swt.sequence, args=(sequence, True))
t.start()
with self.assertRaises(RuntimeError):
time.sleep(0.05)
swt_w.sequence(sequence, True)
t.join()