annotate test/testsamples.py @ 358:5ef1cb1bb54f

Fix nosetests
author Windel Bouwman
date Fri, 14 Mar 2014 15:17:49 +0100
parents c2ddc8a36f5e
children c05ab629976a
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;
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
26 for (i=0;i<10;i++)
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
27 {
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
28 io.print("A");
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 """
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
32 self.do(snippet, "AAAAAAAAAA")
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
33
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
34
358
5ef1cb1bb54f Fix nosetests
Windel Bouwman
parents: 355
diff changeset
35 class TestSamplesOnVexpress(unittest.TestCase, Samples):
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
36 def do(self, src, expected_output):
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
37 runner = TaskRunner()
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
38 recipe_loader = RecipeLoader(runner)
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
39 return
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
40 # TODO: improve recipe loading??
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
41 recipe_loader.load_dict({
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
42 'link': {
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
43 'inputs': [
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
44 ],
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
45 'layout': {
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
46 'code': 0x60010000,
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
47 'data': 0x60020000
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
48 },
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
49 'output': 'tst.bin'
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
50 }
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
51 })
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
52 runner.add_task(Compile())
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
53 runner.run_tasks()
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
54 res = runQemu()
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
55 self.assertEqual(expected_output, res)
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
56