comparison test/testsamples.py @ 377:9667d78ba79e

Switched to xml for project description
author Windel Bouwman
date Fri, 11 Apr 2014 15:47:50 +0200
parents 19eacf4f7270
children 6df89163e114
comparison
equal deleted inserted replaced
376:1e951e71d3f1 377:9667d78ba79e
1 import unittest 1 import unittest
2 import os 2 import os
3 import io 3 import io
4 from testemulation import runQemu, has_qemu 4 from testemulation import runQemu, has_qemu
5 from testzcc import relpath 5 from testzcc import relpath
6 from ppci.tasks import TaskRunner 6 from ppci.buildfunctions import assemble, c3compile, link
7 from ppci.buildtasks import Assemble, Compile, Link
8 from ppci.objectfile import ObjectFile
9 7
10 startercode = """ 8 startercode = """
11 mov sp, 0x30000 ; setup stack pointer 9 mov sp, 0x30000 ; setup stack pointer
12 BL sample_start ; Branch to sample start 10 BL sample_start ; Branch to sample start
13 local_loop: 11 local_loop:
119 if not has_qemu(): 117 if not has_qemu():
120 self.skipTest('Not running qemu tests') 118 self.skipTest('Not running qemu tests')
121 119
122 def do(self, src, expected_output): 120 def do(self, src, expected_output):
123 # Construct binary file from snippet: 121 # Construct binary file from snippet:
124 o1 = ObjectFile() 122 o1 = assemble(io.StringIO(startercode), 'arm')
125 o2 = ObjectFile() 123 o2 = c3compile([
126 asmb = Assemble(io.StringIO(startercode), 'arm', o1)
127 comp = Compile([
128 relpath('..', 'kernel', 'src', 'io.c3'), 124 relpath('..', 'kernel', 'src', 'io.c3'),
129 relpath('..', 'kernel', 'arch', 'vexpressA9.c3'), 125 relpath('..', 'kernel', 'arch', 'vexpressA9.c3'),
130 io.StringIO(src)], [], 'arm', o2) 126 io.StringIO(src)], [], 'arm')
127 layout = {'code': 0x10000, 'data': 0x20000}
128 o3 = link([o1, o2], layout)
129
131 sample_filename = 'testsample.bin' 130 sample_filename = 'testsample.bin'
132 layout = {'code': 0x10000, 'data':0x20000} 131 with open(sample_filename, 'wb') as f:
133 link = Link([o1, o2], layout, sample_filename) 132 f.write(o3.get_section('code').data)
134 133
135 # Create task executor:
136 runner = TaskRunner()
137 runner.add_task(asmb)
138 runner.add_task(comp)
139 runner.add_task(link)
140 runner.run_tasks()
141 # Check bin file exists: 134 # Check bin file exists:
142 self.assertTrue(os.path.isfile(sample_filename)) 135 self.assertTrue(os.path.isfile(sample_filename))
143 136
144 # Run bin file in emulator: 137 # Run bin file in emulator:
145 res = runQemu(sample_filename, machine='vexpress-a9') 138 res = runQemu(sample_filename, machine='vexpress-a9')
147 self.assertEqual(expected_output, res) 140 self.assertEqual(expected_output, res)
148 141
149 142
150 if __name__ == '__main__': 143 if __name__ == '__main__':
151 unittest.main() 144 unittest.main()
145