test.py 8.6 KB

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