Skip to content

Commit 225f7d7

Browse files
author
whitequark
committedJan 10, 2016
Commit missing parts of 9366a29.
1 parent 1be9e75 commit 225f7d7

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed
 

Diff for: ‎artiq/coredevice/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def cache_get(key: TStr) -> TList(TInt32):
4242
raise NotImplementedError("syscall not simulated")
4343

4444
@syscall
45-
def cache_put(key: TStr, value: TList(TInt32)):
45+
def cache_put(key: TStr, value: TList(TInt32)) -> TNone:
4646
raise NotImplementedError("syscall not simulated")
4747

4848
class Core:

Diff for: ‎artiq/runtime/session.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -940,9 +940,12 @@ static int process_kmsg(struct msg_base *umsg)
940940
case MESSAGE_TYPE_FINISHED:
941941
out_packet_empty(REMOTEMSG_TYPE_KERNEL_FINISHED);
942942

943+
for(struct cache_row *iter = cache; iter; iter = iter->next)
944+
iter->borrowed = 0;
945+
943946
kloader_stop();
944947
user_kernel_state = USER_KERNEL_LOADED;
945-
mailbox_acknowledge();
948+
946949
break;
947950

948951
case MESSAGE_TYPE_EXCEPTION: {
@@ -1031,9 +1034,11 @@ static int process_kmsg(struct msg_base *umsg)
10311034
}
10321035

10331036
if(!row) {
1034-
struct cache_row *row = calloc(1, sizeof(struct cache_row));
1037+
row = calloc(1, sizeof(struct cache_row));
10351038
row->key = calloc(strlen(request->key) + 1, 1);
10361039
strcpy(row->key, request->key);
1040+
row->next = cache;
1041+
cache = row;
10371042
}
10381043

10391044
if(!row->borrowed) {

Diff for: ‎artiq/test/coredevice/cache.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from artiq.language import *
2+
from artiq.coredevice.exceptions import *
3+
from artiq.test.hardware_testbench import ExperimentCase
4+
5+
6+
class _Cache(EnvExperiment):
7+
def build(self):
8+
self.setattr_device("core")
9+
self.print = lambda x: print(x)
10+
11+
@kernel
12+
def get(self, key):
13+
return self.core.get_cache(key)
14+
15+
@kernel
16+
def put(self, key, value):
17+
self.core.put_cache(key, value)
18+
19+
@kernel
20+
def get_put(self, key, value):
21+
self.get(key)
22+
self.put(key, value)
23+
24+
class CacheTest(ExperimentCase):
25+
def test_get_empty(self):
26+
exp = self.create(_Cache)
27+
self.assertEqual(exp.get("x1"), [])
28+
29+
def test_put_get(self):
30+
exp = self.create(_Cache)
31+
exp.put("x2", [1, 2, 3])
32+
self.assertEqual(exp.get("x2"), [1, 2, 3])
33+
34+
def test_replace(self):
35+
exp = self.create(_Cache)
36+
exp.put("x3", [1, 2, 3])
37+
exp.put("x3", [1, 2, 3, 4, 5])
38+
self.assertEqual(exp.get("x3"), [1, 2, 3, 4, 5])
39+
40+
def test_borrow(self):
41+
exp = self.create(_Cache)
42+
exp.put("x4", [1, 2, 3])
43+
with self.assertRaises(CacheError):
44+
exp.get_put("x4", [])

0 commit comments

Comments
 (0)
Please sign in to comment.