test.py 7.6 KB

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