test.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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='''
  70. From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001
  71. From: Simon Glass <sjg@chromium.org>
  72. Date: Thu, 7 Apr 2011 10:14:41 -0700
  73. Subject: [PATCH 1/4] Add microsecond boot time measurement
  74. This defines the basics of a new boot time measurement feature. This allows
  75. logging of very accurate time measurements as the boot proceeds, by using
  76. an available microsecond counter.
  77. %s
  78. ---
  79. README | 11 ++++++++
  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/common/bootstage.c b/common/bootstage.c
  107. new file mode 100644
  108. index 0000000..2234c87
  109. --- /dev/null
  110. +++ b/common/bootstage.c
  111. @@ -0,0 +1,39 @@
  112. +/*
  113. + * Copyright (c) 2011, Google Inc. All rights reserved.
  114. + *
  115. + * SPDX-License-Identifier: GPL-2.0+
  116. + */
  117. +
  118. +
  119. +/*
  120. + * This module records the progress of boot and arbitrary commands, and
  121. + * permits accurate timestamping of each. The records can optionally be
  122. + * passed to kernel in the ATAGs
  123. + */
  124. +
  125. +#include <common.h>
  126. +
  127. +
  128. +struct bootstage_record {
  129. + uint32_t time_us;
  130. + const char *name;
  131. +};
  132. +
  133. +static struct bootstage_record record[BOOTSTAGE_COUNT];
  134. +
  135. +uint32_t bootstage_mark(enum bootstage_id id, const char *name)
  136. +{
  137. + struct bootstage_record *rec = &record[id];
  138. +
  139. + /* Only record the first event for each */
  140. +%sif (!rec->name) {
  141. + rec->time_us = (uint32_t)timer_get_us();
  142. + rec->name = name;
  143. + }
  144. + if (!rec->name &&
  145. + %ssomething_else) {
  146. + rec->time_us = (uint32_t)timer_get_us();
  147. + rec->name = name;
  148. + }
  149. +%sreturn rec->time_us;
  150. +}
  151. --
  152. 1.7.3.1
  153. '''
  154. signoff = 'Signed-off-by: Simon Glass <sjg@chromium.org>\n'
  155. tab = ' '
  156. indent = ' '
  157. if data_type == 'good':
  158. pass
  159. elif data_type == 'no-signoff':
  160. signoff = ''
  161. elif data_type == 'spaces':
  162. tab = ' '
  163. elif data_type == 'indent':
  164. indent = tab
  165. else:
  166. print('not implemented')
  167. return data % (signoff, tab, indent, tab)
  168. def SetupData(self, data_type):
  169. inhandle, inname = tempfile.mkstemp()
  170. infd = os.fdopen(inhandle, 'w')
  171. data = self.GetData(data_type)
  172. infd.write(data)
  173. infd.close()
  174. return inname
  175. def testGood(self):
  176. """Test checkpatch operation"""
  177. inf = self.SetupData('good')
  178. result = checkpatch.CheckPatch(inf)
  179. self.assertEqual(result.ok, True)
  180. self.assertEqual(result.problems, [])
  181. self.assertEqual(result.errors, 0)
  182. self.assertEqual(result.warnings, 0)
  183. self.assertEqual(result.checks, 0)
  184. self.assertEqual(result.lines, 56)
  185. os.remove(inf)
  186. def testNoSignoff(self):
  187. inf = self.SetupData('no-signoff')
  188. result = checkpatch.CheckPatch(inf)
  189. self.assertEqual(result.ok, False)
  190. self.assertEqual(len(result.problems), 1)
  191. self.assertEqual(result.errors, 1)
  192. self.assertEqual(result.warnings, 0)
  193. self.assertEqual(result.checks, 0)
  194. self.assertEqual(result.lines, 56)
  195. os.remove(inf)
  196. def testSpaces(self):
  197. inf = self.SetupData('spaces')
  198. result = checkpatch.CheckPatch(inf)
  199. self.assertEqual(result.ok, False)
  200. self.assertEqual(len(result.problems), 2)
  201. self.assertEqual(result.errors, 0)
  202. self.assertEqual(result.warnings, 2)
  203. self.assertEqual(result.checks, 0)
  204. self.assertEqual(result.lines, 56)
  205. os.remove(inf)
  206. def testIndent(self):
  207. inf = self.SetupData('indent')
  208. result = checkpatch.CheckPatch(inf)
  209. self.assertEqual(result.ok, False)
  210. self.assertEqual(len(result.problems), 1)
  211. self.assertEqual(result.errors, 0)
  212. self.assertEqual(result.warnings, 0)
  213. self.assertEqual(result.checks, 1)
  214. self.assertEqual(result.lines, 56)
  215. os.remove(inf)
  216. if __name__ == "__main__":
  217. unittest.main()
  218. gitutil.RunTests()