test.py 8.1 KB

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