test_output_commands.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2021 Espressif Systems (Shanghai) CO LTD
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. import sys
  18. import unittest
  19. try:
  20. from output_commands import InputSectionDesc
  21. except ImportError:
  22. sys.path.append('../')
  23. from output_commands import InputSectionDesc
  24. from entity import Entity
  25. SECTIONS = ['.text', '.text.*', '.literal', '.literal.*']
  26. FREERTOS = Entity('libfreertos.a')
  27. CROUTINE = Entity('libfreertos.a', 'croutine')
  28. class InputSectionDescTest(unittest.TestCase):
  29. def test_output_00(self):
  30. # Test default (catch-all) command
  31. expected = '*(.literal .literal.* .text .text.*)'
  32. desc = InputSectionDesc(Entity(), SECTIONS)
  33. self.assertEqual(expected, str(desc))
  34. desc = InputSectionDesc(Entity(Entity.ALL), SECTIONS)
  35. self.assertEqual(expected, str(desc))
  36. def test_output_01(self):
  37. # Test library placement command
  38. expected = '*libfreertos.a:(.literal .literal.* .text .text.*)'
  39. desc = InputSectionDesc(Entity('libfreertos.a'), SECTIONS)
  40. self.assertEqual(expected, str(desc))
  41. desc = InputSectionDesc(Entity('libfreertos.a', Entity.ALL), SECTIONS)
  42. self.assertEqual(expected, str(desc))
  43. desc = InputSectionDesc(Entity('libfreertos.a', None, Entity.ALL), SECTIONS)
  44. self.assertEqual(expected, str(desc))
  45. desc = InputSectionDesc(Entity('libfreertos.a', Entity.ALL, Entity.ALL), SECTIONS)
  46. self.assertEqual(expected, str(desc))
  47. def test_output_02(self):
  48. # Test object placement command
  49. expected = '*libfreertos.a:croutine.*(.literal .literal.* .text .text.*)'
  50. desc = InputSectionDesc(Entity('libfreertos.a', 'croutine'), SECTIONS)
  51. self.assertEqual(expected, str(desc))
  52. desc = InputSectionDesc(Entity('libfreertos.a', 'croutine'), SECTIONS)
  53. self.assertEqual(expected, str(desc))
  54. desc = InputSectionDesc(Entity('libfreertos.a', 'croutine', Entity.ALL), SECTIONS)
  55. self.assertEqual(expected, str(desc))
  56. # Disambugated placement
  57. expected = '*libfreertos.a:croutine.c.*(.literal .literal.* .text .text.*)'
  58. desc = InputSectionDesc(Entity('libfreertos.a', 'croutine.c'), SECTIONS)
  59. self.assertEqual(expected, str(desc))
  60. def test_output_03(self):
  61. # Invalid entity specification
  62. with self.assertRaises(AssertionError):
  63. InputSectionDesc(Entity('libfreertos.a', 'croutine', 'prvCheckPendingReadyList'), SECTIONS)
  64. with self.assertRaises(AssertionError):
  65. InputSectionDesc(Entity('libfreertos.a', 'croutine'), SECTIONS, [Entity()])
  66. with self.assertRaises(AssertionError):
  67. InputSectionDesc(Entity('libfreertos.a', 'croutine'), SECTIONS, [Entity('libfreertos.a', 'croutine', 'prvCheckPendingReadyList')])
  68. def test_output_04(self):
  69. # Test exclusions
  70. # Library
  71. expected = ('*libfreertos.a:croutine.*'
  72. '(EXCLUDE_FILE(*libfreertos.a) '
  73. '.literal EXCLUDE_FILE(*libfreertos.a) '
  74. '.literal.* EXCLUDE_FILE(*libfreertos.a) '
  75. '.text EXCLUDE_FILE(*libfreertos.a) .text.*)')
  76. desc = InputSectionDesc(CROUTINE, SECTIONS, [FREERTOS])
  77. self.assertEqual(expected, str(desc))
  78. # Object
  79. expected = ('*libfreertos.a:croutine.*'
  80. '(EXCLUDE_FILE(*libfreertos.a:croutine.*) '
  81. '.literal EXCLUDE_FILE(*libfreertos.a:croutine.*) '
  82. '.literal.* EXCLUDE_FILE(*libfreertos.a:croutine.*) '
  83. '.text EXCLUDE_FILE(*libfreertos.a:croutine.*) .text.*)')
  84. desc = InputSectionDesc(CROUTINE, SECTIONS, [CROUTINE])
  85. self.assertEqual(expected, str(desc))
  86. # Multiple exclusions
  87. expected = ('*libfreertos.a:croutine.*'
  88. '(EXCLUDE_FILE(*libfreertos.a *libfreertos.a:croutine.*) '
  89. '.literal EXCLUDE_FILE(*libfreertos.a *libfreertos.a:croutine.*) '
  90. '.literal.* EXCLUDE_FILE(*libfreertos.a *libfreertos.a:croutine.*) '
  91. '.text EXCLUDE_FILE(*libfreertos.a *libfreertos.a:croutine.*) .text.*)')
  92. desc = InputSectionDesc(CROUTINE, SECTIONS, [FREERTOS, CROUTINE])
  93. self.assertEqual(expected, str(desc))
  94. # Disambugated exclusion
  95. expected = ('*libfreertos.a:croutine.*'
  96. '(EXCLUDE_FILE(*libfreertos.a:croutine.c.*) '
  97. '.literal EXCLUDE_FILE(*libfreertos.a:croutine.c.*) '
  98. '.literal.* EXCLUDE_FILE(*libfreertos.a:croutine.c.*) '
  99. '.text EXCLUDE_FILE(*libfreertos.a:croutine.c.*) .text.*)')
  100. desc = InputSectionDesc(CROUTINE, SECTIONS, [Entity('libfreertos.a', 'croutine.c')])
  101. self.assertEqual(expected, str(desc))
  102. def test_output_05(self):
  103. # Test empty sections
  104. expected = '*libfreertos.a:croutine.*( )'
  105. desc = InputSectionDesc(Entity('libfreertos.a', 'croutine'), [])
  106. self.assertEqual(expected, str(desc))
  107. if __name__ == '__main__':
  108. unittest.main()