test.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #
  2. # Copyright (c) 2011 The Chromium OS Authors.
  3. #
  4. # SPDX-License-Identifier: GPL-2.0+
  5. #
  6. import os
  7. import tempfile
  8. import unittest
  9. import checkpatch
  10. import gitutil
  11. import patchstream
  12. import series
  13. class TestPatch(unittest.TestCase):
  14. """Test this program
  15. TODO: Write tests for the rest of the functionality
  16. """
  17. def testBasic(self):
  18. """Test basic filter operation"""
  19. data='''
  20. From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001
  21. From: Simon Glass <sjg@chromium.org>
  22. Date: Thu, 28 Apr 2011 09:58:51 -0700
  23. Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support
  24. This adds functions to enable/disable clocks and reset to on-chip peripherals.
  25. BUG=chromium-os:13875
  26. TEST=build U-Boot for Seaboard, boot
  27. Change-Id: I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413
  28. Review URL: http://codereview.chromium.org/6900006
  29. Signed-off-by: Simon Glass <sjg@chromium.org>
  30. ---
  31. arch/arm/cpu/armv7/tegra2/Makefile | 2 +-
  32. arch/arm/cpu/armv7/tegra2/ap20.c | 57 ++----
  33. arch/arm/cpu/armv7/tegra2/clock.c | 163 +++++++++++++++++
  34. '''
  35. expected='''
  36. From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001
  37. From: Simon Glass <sjg@chromium.org>
  38. Date: Thu, 28 Apr 2011 09:58:51 -0700
  39. Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support
  40. This adds functions to enable/disable clocks and reset to on-chip peripherals.
  41. Signed-off-by: Simon Glass <sjg@chromium.org>
  42. ---
  43. arch/arm/cpu/armv7/tegra2/Makefile | 2 +-
  44. arch/arm/cpu/armv7/tegra2/ap20.c | 57 ++----
  45. arch/arm/cpu/armv7/tegra2/clock.c | 163 +++++++++++++++++
  46. '''
  47. out = ''
  48. inhandle, inname = tempfile.mkstemp()
  49. infd = os.fdopen(inhandle, 'w')
  50. infd.write(data)
  51. infd.close()
  52. exphandle, expname = tempfile.mkstemp()
  53. expfd = os.fdopen(exphandle, 'w')
  54. expfd.write(expected)
  55. expfd.close()
  56. patchstream.FixPatch(None, inname, series.Series(), None)
  57. rc = os.system('diff -u %s %s' % (inname, expname))
  58. self.assertEqual(rc, 0)
  59. os.remove(inname)
  60. os.remove(expname)
  61. def GetData(self, data_type):
  62. data='''
  63. From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001
  64. From: Simon Glass <sjg@chromium.org>
  65. Date: Thu, 7 Apr 2011 10:14:41 -0700
  66. Subject: [PATCH 1/4] Add microsecond boot time measurement
  67. This defines the basics of a new boot time measurement feature. This allows
  68. logging of very accurate time measurements as the boot proceeds, by using
  69. an available microsecond counter.
  70. %s
  71. ---
  72. README | 11 ++++++++
  73. common/bootstage.c | 50 ++++++++++++++++++++++++++++++++++++
  74. include/bootstage.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++
  75. include/common.h | 8 ++++++
  76. 5 files changed, 141 insertions(+), 0 deletions(-)
  77. create mode 100644 common/bootstage.c
  78. create mode 100644 include/bootstage.h
  79. diff --git a/README b/README
  80. index 6f3748d..f9e4e65 100644
  81. --- a/README
  82. +++ b/README
  83. @@ -2026,6 +2026,17 @@ The following options need to be configured:
  84. example, some LED's) on your board. At the moment,
  85. the following checkpoints are implemented:
  86. +- Time boot progress
  87. + CONFIG_BOOTSTAGE
  88. +
  89. + Define this option to enable microsecond boot stage timing
  90. + on supported platforms. For this to work your platform
  91. + needs to define a function timer_get_us() which returns the
  92. + number of microseconds since reset. This would normally
  93. + be done in your SOC or board timer.c file.
  94. +
  95. + You can add calls to bootstage_mark() to set time markers.
  96. +
  97. - Standalone program support:
  98. CONFIG_STANDALONE_LOAD_ADDR
  99. diff --git a/common/bootstage.c b/common/bootstage.c
  100. new file mode 100644
  101. index 0000000..2234c87
  102. --- /dev/null
  103. +++ b/common/bootstage.c
  104. @@ -0,0 +1,39 @@
  105. +/*
  106. + * Copyright (c) 2011, Google Inc. All rights reserved.
  107. + *
  108. + * SPDX-License-Identifier: GPL-2.0+
  109. + */
  110. +
  111. +
  112. +/*
  113. + * This module records the progress of boot and arbitrary commands, and
  114. + * permits accurate timestamping of each. The records can optionally be
  115. + * passed to kernel in the ATAGs
  116. + */
  117. +
  118. +#include <common.h>
  119. +
  120. +
  121. +struct bootstage_record {
  122. + uint32_t time_us;
  123. + const char *name;
  124. +};
  125. +
  126. +static struct bootstage_record record[BOOTSTAGE_COUNT];
  127. +
  128. +uint32_t bootstage_mark(enum bootstage_id id, const char *name)
  129. +{
  130. + struct bootstage_record *rec = &record[id];
  131. +
  132. + /* Only record the first event for each */
  133. +%sif (!rec->name) {
  134. + rec->time_us = (uint32_t)timer_get_us();
  135. + rec->name = name;
  136. + }
  137. + if (!rec->name &&
  138. + %ssomething_else) {
  139. + rec->time_us = (uint32_t)timer_get_us();
  140. + rec->name = name;
  141. + }
  142. +%sreturn rec->time_us;
  143. +}
  144. --
  145. 1.7.3.1
  146. '''
  147. signoff = 'Signed-off-by: Simon Glass <sjg@chromium.org>\n'
  148. tab = ' '
  149. indent = ' '
  150. if data_type == 'good':
  151. pass
  152. elif data_type == 'no-signoff':
  153. signoff = ''
  154. elif data_type == 'spaces':
  155. tab = ' '
  156. elif data_type == 'indent':
  157. indent = tab
  158. else:
  159. print('not implemented')
  160. return data % (signoff, tab, indent, tab)
  161. def SetupData(self, data_type):
  162. inhandle, inname = tempfile.mkstemp()
  163. infd = os.fdopen(inhandle, 'w')
  164. data = self.GetData(data_type)
  165. infd.write(data)
  166. infd.close()
  167. return inname
  168. def testGood(self):
  169. """Test checkpatch operation"""
  170. inf = self.SetupData('good')
  171. result = checkpatch.CheckPatch(inf)
  172. self.assertEqual(result.ok, True)
  173. self.assertEqual(result.problems, [])
  174. self.assertEqual(result.errors, 0)
  175. self.assertEqual(result.warnings, 0)
  176. self.assertEqual(result.checks, 0)
  177. self.assertEqual(result.lines, 56)
  178. os.remove(inf)
  179. def testNoSignoff(self):
  180. inf = self.SetupData('no-signoff')
  181. result = checkpatch.CheckPatch(inf)
  182. self.assertEqual(result.ok, False)
  183. self.assertEqual(len(result.problems), 1)
  184. self.assertEqual(result.errors, 1)
  185. self.assertEqual(result.warnings, 0)
  186. self.assertEqual(result.checks, 0)
  187. self.assertEqual(result.lines, 56)
  188. os.remove(inf)
  189. def testSpaces(self):
  190. inf = self.SetupData('spaces')
  191. result = checkpatch.CheckPatch(inf)
  192. self.assertEqual(result.ok, False)
  193. self.assertEqual(len(result.problems), 2)
  194. self.assertEqual(result.errors, 0)
  195. self.assertEqual(result.warnings, 2)
  196. self.assertEqual(result.checks, 0)
  197. self.assertEqual(result.lines, 56)
  198. os.remove(inf)
  199. def testIndent(self):
  200. inf = self.SetupData('indent')
  201. result = checkpatch.CheckPatch(inf)
  202. self.assertEqual(result.ok, False)
  203. self.assertEqual(len(result.problems), 1)
  204. self.assertEqual(result.errors, 0)
  205. self.assertEqual(result.warnings, 0)
  206. self.assertEqual(result.checks, 1)
  207. self.assertEqual(result.lines, 56)
  208. os.remove(inf)
  209. if __name__ == "__main__":
  210. unittest.main()
  211. gitutil.RunTests()