annotate test/testsamples.py @ 362:c05ab629976a

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