blob: b08cf359ef2e2b838048512e321783499cefa01c [file] [log] [blame]
Varun Sharma708d38c2021-04-29 09:03:12 -07001#!/usr/bin/env python3
2# Copyright 2021 The Pigweed Authors
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may not
5# use this file except in compliance with the License. You may obtain a copy of
6# the License at
7#
8# https://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations under
14# the License.
15"""Finds files for a given product."""
16
17import unittest
18
19from pw_stm32cube_build import inject_init
20
21
22class AddPreMainInitTest(unittest.TestCase):
23 """add_pre_main_init tests."""
24 def test_spaces(self):
25 startup = '\n'.join([
26 '/* Call the clock system intitialization function.*/',
27 ' bl SystemInit ',
28 '/* Call static constructors */',
29 ' bl __libc_init_array',
30 '/* Call the application\'s entry point.*/',
31 ' bl main',
32 ' bx lr ',
33 '.size Reset_Handler, .-Reset_Handler',
34 ])
35
36 new_startup = inject_init.add_pre_main_init(startup)
37
38 self.assertEqual(
39 new_startup, '\n'.join([
40 '/* Call the clock system intitialization function.*/',
41 ' bl SystemInit ',
42 '/* Call static constructors */',
43 ' bl __libc_init_array',
44 '/* Call the application\'s entry point.*/',
45 'bl pw_stm32cube_Init',
46 ' bl main',
47 ' bx lr ',
48 '.size Reset_Handler, .-Reset_Handler',
49 ]))
50
51 def test_tabs(self):
52 startup = '\n'.join([
53 'LoopFillZerobss:',
54 ' ldr r3, = _ebss',
55 ' cmp r2, r3',
56 ' bcc FillZerobss',
57 ''
58 '/* Call static constructors */',
59 ' bl __libc_init_array',
60 '/* Call the application\'s entry point.*/',
61 ' bl main',
62 '',
63 'LoopForever:',
64 ' b LoopForever',
65 ])
66
67 new_startup = inject_init.add_pre_main_init(startup)
68
69 self.assertEqual(
70 new_startup, '\n'.join([
71 'LoopFillZerobss:',
72 ' ldr r3, = _ebss',
73 ' cmp r2, r3',
74 ' bcc FillZerobss',
75 ''
76 '/* Call static constructors */',
77 ' bl __libc_init_array',
78 '/* Call the application\'s entry point.*/',
79 'bl pw_stm32cube_Init',
80 ' bl main',
81 '',
82 'LoopForever:',
83 ' b LoopForever',
84 ]))
85
86 def test_main_not_found(self):
87 startup = '\n'.join([
88 '/* Call the clock system intitialization function.*/',
89 ' bl SystemInit ',
90 '/* Call static constructors */',
91 ' bl __libc_init_array',
92 '/* Call the application\'s entry point.*/',
93 ' bl application_entry',
94 ' bx lr ',
95 '.size Reset_Handler, .-Reset_Handler',
96 ])
97
98 with self.assertRaises(ValueError):
99 inject_init.add_pre_main_init(startup)
100
101
102if __name__ == '__main__':
103 unittest.main()