test.py 7.6 KB

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