Debian Codegraph @

extra_tests/cffi_tests/embedding/test_thread.py

raw symbols SCIP
1 # Generated by pypy/tool/import_cffi.py
2 from extra_tests.cffi_tests.embedding.test_basic import EmbeddingTests
3
4
5 class TestThread(EmbeddingTests):
6 def test_first_calls_in_parallel(self):
7 add1_cffi = self.prepare_module('add1')
8 self.compile('thread1-test', [add1_cffi], threads=True)
9 for i in range(20):
10 output = self.execute('thread1-test')
11 assert output == ("starting\n"
12 "preparing...\n" +
13 "adding 40 and 2\n" * 10 +
14 "done\n")
15
16 def _take_out(self, text, content):
17 assert content in text
18 i = text.index(content)
19 return text[:i] + text[i+len(content):]
20
21 def test_init_different_modules_in_different_threads(self):
22 add1_cffi = self.prepare_module('add1')
23 add2_cffi = self.prepare_module('add2')
24 self.compile('thread2-test', [add1_cffi, add2_cffi], threads=True)
25 for i in range(3):
26 output = self.execute('thread2-test')
27 print('='*79)
28 print(output)
29 print('='*79)
30 output = self._take_out(output, "preparing")
31 output = self._take_out(output, ".")
32 output = self._take_out(output, ".")
33 # at least the 3rd dot should be after everything from ADD2
34 assert output == ("starting\n"
35 "prepADD2\n"
36 "adding 1000 and 200 and 30\n"
37 ".\n"
38 "adding 40 and 2\n"
39 "done\n")
40
41 def test_alt_issue(self):
42 add1_cffi = self.prepare_module('add1')
43 add2_cffi = self.prepare_module('add2')
44 self.compile('thread2-test', [add1_cffi, add2_cffi],
45 threads=True, defines={'T2TEST_AGAIN_ADD1': '1'})
46 output = self.execute('thread2-test')
47 output = self._take_out(output, "adding 40 and 2\n")
48 assert output == ("starting\n"
49 "preparing...\n"
50 "adding -1 and -1\n"
51 "prepADD2\n"
52 "adding 1000 and 200 and 30\n"
53 "done\n")
54
55 def test_load_in_parallel_more(self):
56 add2_cffi = self.prepare_module('add2')
57 add3_cffi = self.prepare_module('add3')
58 self.compile('thread3-test', [add2_cffi, add3_cffi], threads=True)
59 for i in range(150):
60 output = self.execute('thread3-test')
61 for j in range(10):
62 output = self._take_out(output, "adding 40 and 2 and 100\n")
63 output = self._take_out(output, "adding 1000, 200, 30, 4\n")
64 assert output == ("starting\n"
65 "prepADD2\n"
66 "done\n")