355
|
1 import unittest
|
|
2 from testemulation import runQemu
|
|
3 from ppci.recipe import RecipeLoader
|
|
4 from ppci.tasks import TaskRunner
|
|
5
|
|
6
|
358
|
7 class Samples:
|
355
|
8 def testPrint(self):
|
|
9 snippet = """
|
|
10 module testsample;
|
|
11 import io;
|
|
12 function void start()
|
|
13 {
|
|
14 io.print("Hello world");
|
|
15 }
|
|
16 """
|
|
17 self.do(snippet, "Hello world")
|
|
18
|
|
19 def testForLoopPrint(self):
|
|
20 snippet = """
|
|
21 module testsample;
|
|
22 import io;
|
|
23 function void start()
|
|
24 {
|
|
25 var int i;
|
362
|
26 for (i=0; i<10; i++)
|
355
|
27 {
|
362
|
28 io.print2("A = ", i);
|
355
|
29 }
|
|
30 }
|
|
31 """
|
362
|
32 res = "".join("A = 0x{0:08X}\n".format(a) for a in range(10))
|
|
33 self.do(snippet, res)
|
355
|
34
|
|
35
|
358
|
36 class TestSamplesOnVexpress(unittest.TestCase, Samples):
|
355
|
37 def do(self, src, expected_output):
|
|
38 runner = TaskRunner()
|
|
39 recipe_loader = RecipeLoader(runner)
|
362
|
40 print(expected_output)
|
355
|
41 return
|
|
42 # TODO: improve recipe loading??
|
|
43 recipe_loader.load_dict({
|
|
44 'link': {
|
|
45 'inputs': [
|
|
46 ],
|
|
47 'layout': {
|
|
48 'code': 0x60010000,
|
|
49 'data': 0x60020000
|
|
50 },
|
|
51 'output': 'tst.bin'
|
|
52 }
|
|
53 })
|
|
54 runner.add_task(Compile())
|
|
55 runner.run_tasks()
|
|
56 res = runQemu()
|
|
57 self.assertEqual(expected_output, res)
|
|
58
|
362
|
59 if __name__ == '__main__':
|
|
60 unittest.main()
|