Guest User

Untitled

a guest
Aug 28th, 2015
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 75.95 KB | None | 0 0
  1.  
  2. From 1ee12f2da22b5ff4381f97fba0a53d283b65eb66 Mon Sep 17 00:00:00 2001
  3. From: Kyle Repinski <repinski23@gmail.com>
  4. Date: Thu, 21 Aug 2014 05:02:36 -0500
  5. Subject: [PATCH] Add memtester.
  6.  
  7. It's messy, but it works...
  8. ---
  9. tests/memtester/Android.mk | 18 ++
  10. tests/memtester/BUGS | 7 +
  11. tests/memtester/CHANGELOG | 130 ++++++++++
  12. tests/memtester/COPYING | 340 ++++++++++++++++++++++++++
  13. tests/memtester/Makefile | 84 +++++++
  14. tests/memtester/README | 126 ++++++++++
  15. tests/memtester/README.tests | 38 +++
  16. tests/memtester/conf-cc | 3 +
  17. tests/memtester/conf-ld | 3 +
  18. tests/memtester/extra-libs.sh | 16 ++
  19. tests/memtester/find-systype.sh | 144 +++++++++++
  20. tests/memtester/make-compile.sh | 1 +
  21. tests/memtester/make-load.sh | 2 +
  22. tests/memtester/make-makelib.sh | 16 ++
  23. tests/memtester/memtester.8 | 103 ++++++++
  24. tests/memtester/memtester.c | 403 ++++++++++++++++++++++++++++++
  25. tests/memtester/memtester.h | 22 ++
  26. tests/memtester/sizes.h | 38 +++
  27. tests/memtester/tests.c | 525 ++++++++++++++++++++++++++++++++++++++++
  28. tests/memtester/tests.h | 39 +++
  29. tests/memtester/trycpp.c | 7 +
  30. tests/memtester/types.h | 36 +++
  31. tests/memtester/warn-auto.sh | 2 +
  32. 23 files changed, 2103 insertions(+)
  33. create mode 100644 tests/memtester/Android.mk
  34. create mode 100644 tests/memtester/BUGS
  35. create mode 100644 tests/memtester/CHANGELOG
  36. create mode 100644 tests/memtester/COPYING
  37. create mode 100644 tests/memtester/Makefile
  38. create mode 100644 tests/memtester/README
  39. create mode 100644 tests/memtester/README.tests
  40. create mode 100644 tests/memtester/conf-cc
  41. create mode 100644 tests/memtester/conf-ld
  42. create mode 100755 tests/memtester/extra-libs.sh
  43. create mode 100755 tests/memtester/find-systype.sh
  44. create mode 100755 tests/memtester/make-compile.sh
  45. create mode 100755 tests/memtester/make-load.sh
  46. create mode 100755 tests/memtester/make-makelib.sh
  47. create mode 100644 tests/memtester/memtester.8
  48. create mode 100644 tests/memtester/memtester.c
  49. create mode 100644 tests/memtester/memtester.h
  50. create mode 100644 tests/memtester/sizes.h
  51. create mode 100644 tests/memtester/tests.c
  52. create mode 100644 tests/memtester/tests.h
  53. create mode 100644 tests/memtester/trycpp.c
  54. create mode 100644 tests/memtester/types.h
  55. create mode 100755 tests/memtester/warn-auto.sh
  56.  
  57. diff --git a/tests/memtester/Android.mk b/tests/memtester/Android.mk
  58. new file mode 100644
  59. index 0000000..8df8cc7
  60. --- /dev/null
  61. +++ b/tests/memtester/Android.mk
  62. @@ -0,0 +1,18 @@
  63. +LOCAL_PATH := $(call my-dir)
  64. +include $(CLEAR_VARS)
  65. +
  66. +LOCAL_SRC_FILES := \
  67. + memtester.c \
  68. + tests.c
  69. +
  70. +LOCAL_SHARED_LIBRARIES := libc libstlport
  71. +
  72. +LOCAL_MODULE := memtester
  73. +
  74. +LOCAL_MODULE_TAGS := optional
  75. +
  76. +## LOCAL_CFLAGS += -fstack-protector-all
  77. +LOCAL_CFLAGS += -fomit-frame-pointer -fno-strict-aliasing
  78. +LOCAL_C_INCLUDES += bionic external/stlport/stlport
  79. +
  80. +include $(BUILD_EXECUTABLE)
  81. diff --git a/tests/memtester/BUGS b/tests/memtester/BUGS
  82. new file mode 100644
  83. index 0000000..12cfa72
  84. --- /dev/null
  85. +++ b/tests/memtester/BUGS
  86. @@ -0,0 +1,7 @@
  87. +* On some platforms, a few of the initial output messages don't format
  88. + correctly, due to %llu or %tx not being a supported printf format. This
  89. + is harmless.
  90. +
  91. +If you spot any other bugs in the software or documentation, please ensure
  92. +you're using the latest version from http:/​/​pyropus​.​ca/​software/​memtester/​ ,
  93. +then email me at <charlesc-memtest-bugs@pyropus.ca> so that I can correct it.
  94. diff --git a/tests/memtester/CHANGELOG b/tests/memtester/CHANGELOG
  95. new file mode 100644
  96. index 0000000..5f1cec1
  97. --- /dev/null
  98. +++ b/tests/memtester/CHANGELOG
  99. @@ -0,0 +1,130 @@
  100. +Version 4.3.0
  101. +9 June 2012
  102. + -add ability to mmap a device other than /dev/mem, enabling easier testing
  103. + of memory for hardware engineers et al if their system's kernel exports the
  104. + memory they're interested in via /dev/mydevice or similar. Thanks:
  105. + Jean-Noël Avila.
  106. + -add ability to run only specified tests by setting the environment
  107. + variable MEMTESTER_TEST_MASK to a bitmask of the indexes of the tests to be
  108. + run. Thanks: Ian Alexander.
  109. +
  110. +Version 4.2.2
  111. +22 July 2011
  112. + -add progress message for one more errno value (EAGAIN) in response to failed
  113. + mlock; BSDs use this to indicate the lock failed due to being over a system
  114. + or process limit, much like ENOMEM.
  115. +
  116. + Version 4.2.1
  117. +3 October 2010
  118. + -fix offsets/addresses were not being reported correctly in test failure
  119. + messages. Thanks: Anton Sergeev.
  120. +
  121. +Version 4.2.0
  122. +30 July 2010
  123. + -define _FILE_OFFSET_BITS to 64 by default in conf-cc, which causes some
  124. + 32-bit systems with larger-than-32-bit address spaces to have a 64-bit off_t,
  125. + allowing testing of larger chunks of memory. Thanks to Steven A. Falco for
  126. + the suggestion. Let me know if this definition causes problems for anyone.
  127. + -add tests of 8-bit-wide and 16-bit-wide random writes, to enable verifying
  128. + the correct operation of hardware. Thanks: Dick Hollenbeck. If these tests
  129. + trigger unaligned access problems on your platform, you can eliminate these
  130. + tests by removing the -DTEST_NARROW_WRITES definition from the conf-cc file.
  131. +
  132. +Version 4.1.3
  133. +28 February 2010
  134. + -fix 64-bit data patterns with some versions of gcc. Thanks: Tony Battersby.
  135. + -clarify `make install` in readme. Thanks: Marc Lobelle.
  136. +
  137. +Version 4.1.2
  138. +28 July 2009
  139. + -fix portability issue with MAP_LOCKED flag. Thanks: Scott Haneda.
  140. + -remove debugging output accidentally left in v.4.1.0.
  141. + -cleanups
  142. +
  143. +Version 4.1.1
  144. +24 July 2009
  145. +
  146. + -memtester.h was missing from the 4.1.0 tarball; release update to fix that.
  147. + Thanks: Owen Leonard.
  148. +
  149. +Version 4.1.0
  150. +23 July 2009
  151. +
  152. + -added the ability to test a specific physical region of memory (by mmap'ing
  153. + /dev/mem) with the new -p option, which takes a hex starting address as a
  154. + value. This is mostly of use to developers trying to verify memory or I/O
  155. + mapped devices (on an embedded system, for instance). Thanks: Allon Stern.
  156. + -re-add the ability to set a suffix on the memory to allocate: "3G", "128K", etc,
  157. + mostly for use with the above new feature, where the "memory" to be tested is
  158. + less than a megabyte, but also useful for users wanting to test many gigabytes;
  159. + you no longer have to do the conversion-to-megs in your head.
  160. + -documentation updates and clarifications.
  161. +
  162. +Version 4.0.8
  163. +21 November 2007
  164. +
  165. + -add a startup check for amount of memory being greater than the possible
  166. + address space; prevents user confusion on 32-bit systems that use addressing
  167. + tricks to have >4GB total system memory. Thanks: Michael Kelly.
  168. + -documentation updates
  169. +
  170. +Version 4.0.7
  171. +13 May 2007
  172. +
  173. + -fix a bug in the align-to-page logic which may have prevented memtester
  174. + from mlock()ing the memory it was trying to test on some systems.
  175. + Thanks: Baif Chen.
  176. +
  177. +Version 4.0.6
  178. +15 November 2006
  179. +
  180. + -test algorithm improvement: the walking 0 bits test was only walking
  181. + the 0 bit in one direction, instead of walking it up and back down
  182. + the line the way it was intended to. Thanks: Tim Rule.
  183. + -formatting cleanups.
  184. +
  185. +Version 4.0.5
  186. +10 March 2005
  187. +
  188. + -change to the method of allocating and locking memory; if we get EPERM
  189. + when trying to mlock(), reset the amount of memory desired to the original
  190. + amount and try again without mlock(). The reason for this is that on many
  191. + systems, mlock() won't return EPERM until after having returned ENOMEM for
  192. + a larger amount. The new behaviour allows processes without mlock privileges
  193. + to still test the fully-specified amount or as much memory as can be
  194. + allocated. Thanks for the suggestion and testing to Dan Bradley.
  195. +
  196. +Version 4.0.4
  197. +26 August 2004
  198. +
  199. + -make memtester's exit code meaningful. See the manpage for its meaning.
  200. + Thanks to Wurzel Parsons-Keir, who sent a patch for the code, so I only had
  201. + to document it.
  202. +
  203. +Version 4.0.3
  204. +10 August 2004
  205. +
  206. + -small changes to enable building with dietlibc and a few other environments
  207. + that don't even attempt to provide the various Posix definitions.
  208. + -cosmetic fixes to output.
  209. + -restore the reduce-and-retry loop of memory locking from version 2.
  210. +
  211. +Version 4.0.2
  212. +9 August 2004
  213. +
  214. + -add manpage
  215. +
  216. +Version 4.0.1
  217. +8 August 2004
  218. +
  219. + -fix cosmetic bugs in output
  220. +
  221. +Version 4.0.0
  222. +7 August 2004
  223. +
  224. + -rewrite to clean up the code (previously an ugly hack), for 64-bit
  225. + cleanliness
  226. + -change build system to build on (hopefully) any platform. Previous
  227. + versions required hackery on some systems.
  228. +
  229. +Version 3 not publicly released.
  230. diff --git a/tests/memtester/COPYING b/tests/memtester/COPYING
  231. new file mode 100644
  232. index 0000000..60549be
  233. --- /dev/null
  234. +++ b/tests/memtester/COPYING
  235. @@ -0,0 +1,340 @@
  236. + GNU GENERAL PUBLIC LICENSE
  237. + Version 2, June 1991
  238. +
  239. + Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  240. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  241. + Everyone is permitted to copy and distribute verbatim copies
  242. + of this license document, but changing it is not allowed.
  243. +
  244. + Preamble
  245. +
  246. + The licenses for most software are designed to take away your
  247. +freedom to share and change it. By contrast, the GNU General Public
  248. +License is intended to guarantee your freedom to share and change free
  249. +software--to make sure the software is free for all its users. This
  250. +General Public License applies to most of the Free Software
  251. +Foundation's software and to any other program whose authors commit to
  252. +using it. (Some other Free Software Foundation software is covered by
  253. +the GNU Library General Public License instead.) You can apply it to
  254. +your programs, too.
  255. +
  256. + When we speak of free software, we are referring to freedom, not
  257. +price. Our General Public Licenses are designed to make sure that you
  258. +have the freedom to distribute copies of free software (and charge for
  259. +this service if you wish), that you receive source code or can get it
  260. +if you want it, that you can change the software or use pieces of it
  261. +in new free programs; and that you know you can do these things.
  262. +
  263. + To protect your rights, we need to make restrictions that forbid
  264. +anyone to deny you these rights or to ask you to surrender the rights.
  265. +These restrictions translate to certain responsibilities for you if you
  266. +distribute copies of the software, or if you modify it.
  267. +
  268. + For example, if you distribute copies of such a program, whether
  269. +gratis or for a fee, you must give the recipients all the rights that
  270. +you have. You must make sure that they, too, receive or can get the
  271. +source code. And you must show them these terms so they know their
  272. +rights.
  273. +
  274. + We protect your rights with two steps: (1) copyright the software, and
  275. +(2) offer you this license which gives you legal permission to copy,
  276. +distribute and/or modify the software.
  277. +
  278. + Also, for each author's protection and ours, we want to make certain
  279. +that everyone understands that there is no warranty for this free
  280. +software. If the software is modified by someone else and passed on, we
  281. +want its recipients to know that what they have is not the original, so
  282. +that any problems introduced by others will not reflect on the original
  283. +authors' reputations.
  284. +
  285. + Finally, any free program is threatened constantly by software
  286. +patents. We wish to avoid the danger that redistributors of a free
  287. +program will individually obtain patent licenses, in effect making the
  288. +program proprietary. To prevent this, we have made it clear that any
  289. +patent must be licensed for everyone's free use or not licensed at all.
  290. +
  291. + The precise terms and conditions for copying, distribution and
  292. +modification follow.
  293. +
  294. + GNU GENERAL PUBLIC LICENSE
  295. + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  296. +
  297. + 0. This License applies to any program or other work which contains
  298. +a notice placed by the copyright holder saying it may be distributed
  299. +under the terms of this General Public License. The "Program", below,
  300. +refers to any such program or work, and a "work based on the Program"
  301. +means either the Program or any derivative work under copyright law:
  302. +that is to say, a work containing the Program or a portion of it,
  303. +either verbatim or with modifications and/or translated into another
  304. +language. (Hereinafter, translation is included without limitation in
  305. +the term "modification".) Each licensee is addressed as "you".
  306. +
  307. +Activities other than copying, distribution and modification are not
  308. +covered by this License; they are outside its scope. The act of
  309. +running the Program is not restricted, and the output from the Program
  310. +is covered only if its contents constitute a work based on the
  311. +Program (independent of having been made by running the Program).
  312. +Whether that is true depends on what the Program does.
  313. +
  314. + 1. You may copy and distribute verbatim copies of the Program's
  315. +source code as you receive it, in any medium, provided that you
  316. +conspicuously and appropriately publish on each copy an appropriate
  317. +copyright notice and disclaimer of warranty; keep intact all the
  318. +notices that refer to this License and to the absence of any warranty;
  319. +and give any other recipients of the Program a copy of this License
  320. +along with the Program.
  321. +
  322. +You may charge a fee for the physical act of transferring a copy, and
  323. +you may at your option offer warranty protection in exchange for a fee.
  324. +
  325. + 2. You may modify your copy or copies of the Program or any portion
  326. +of it, thus forming a work based on the Program, and copy and
  327. +distribute such modifications or work under the terms of Section 1
  328. +above, provided that you also meet all of these conditions:
  329. +
  330. + a) You must cause the modified files to carry prominent notices
  331. + stating that you changed the files and the date of any change.
  332. +
  333. + b) You must cause any work that you distribute or publish, that in
  334. + whole or in part contains or is derived from the Program or any
  335. + part thereof, to be licensed as a whole at no charge to all third
  336. + parties under the terms of this License.
  337. +
  338. + c) If the modified program normally reads commands interactively
  339. + when run, you must cause it, when started running for such
  340. + interactive use in the most ordinary way, to print or display an
  341. + announcement including an appropriate copyright notice and a
  342. + notice that there is no warranty (or else, saying that you provide
  343. + a warranty) and that users may redistribute the program under
  344. + these conditions, and telling the user how to view a copy of this
  345. + License. (Exception: if the Program itself is interactive but
  346. + does not normally print such an announcement, your work based on
  347. + the Program is not required to print an announcement.)
  348. +
  349. +These requirements apply to the modified work as a whole. If
  350. +identifiable sections of that work are not derived from the Program,
  351. +and can be reasonably considered independent and separate works in
  352. +themselves, then this License, and its terms, do not apply to those
  353. +sections when you distribute them as separate works. But when you
  354. +distribute the same sections as part of a whole which is a work based
  355. +on the Program, the distribution of the whole must be on the terms of
  356. +this License, whose permissions for other licensees extend to the
  357. +entire whole, and thus to each and every part regardless of who wrote it.
  358. +
  359. +Thus, it is not the intent of this section to claim rights or contest
  360. +your rights to work written entirely by you; rather, the intent is to
  361. +exercise the right to control the distribution of derivative or
  362. +collective works based on the Program.
  363. +
  364. +In addition, mere aggregation of another work not based on the Program
  365. +with the Program (or with a work based on the Program) on a volume of
  366. +a storage or distribution medium does not bring the other work under
  367. +the scope of this License.
  368. +
  369. + 3. You may copy and distribute the Program (or a work based on it,
  370. +under Section 2) in object code or executable form under the terms of
  371. +Sections 1 and 2 above provided that you also do one of the following:
  372. +
  373. + a) Accompany it with the complete corresponding machine-readable
  374. + source code, which must be distributed under the terms of Sections
  375. + 1 and 2 above on a medium customarily used for software interchange; or,
  376. +
  377. + b) Accompany it with a written offer, valid for at least three
  378. + years, to give any third party, for a charge no more than your
  379. + cost of physically performing source distribution, a complete
  380. + machine-readable copy of the corresponding source code, to be
  381. + distributed under the terms of Sections 1 and 2 above on a medium
  382. + customarily used for software interchange; or,
  383. +
  384. + c) Accompany it with the information you received as to the offer
  385. + to distribute corresponding source code. (This alternative is
  386. + allowed only for noncommercial distribution and only if you
  387. + received the program in object code or executable form with such
  388. + an offer, in accord with Subsection b above.)
  389. +
  390. +The source code for a work means the preferred form of the work for
  391. +making modifications to it. For an executable work, complete source
  392. +code means all the source code for all modules it contains, plus any
  393. +associated interface definition files, plus the scripts used to
  394. +control compilation and installation of the executable. However, as a
  395. +special exception, the source code distributed need not include
  396. +anything that is normally distributed (in either source or binary
  397. +form) with the major components (compiler, kernel, and so on) of the
  398. +operating system on which the executable runs, unless that component
  399. +itself accompanies the executable.
  400. +
  401. +If distribution of executable or object code is made by offering
  402. +access to copy from a designated place, then offering equivalent
  403. +access to copy the source code from the same place counts as
  404. +distribution of the source code, even though third parties are not
  405. +compelled to copy the source along with the object code.
  406. +
  407. + 4. You may not copy, modify, sublicense, or distribute the Program
  408. +except as expressly provided under this License. Any attempt
  409. +otherwise to copy, modify, sublicense or distribute the Program is
  410. +void, and will automatically terminate your rights under this License.
  411. +However, parties who have received copies, or rights, from you under
  412. +this License will not have their licenses terminated so long as such
  413. +parties remain in full compliance.
  414. +
  415. + 5. You are not required to accept this License, since you have not
  416. +signed it. However, nothing else grants you permission to modify or
  417. +distribute the Program or its derivative works. These actions are
  418. +prohibited by law if you do not accept this License. Therefore, by
  419. +modifying or distributing the Program (or any work based on the
  420. +Program), you indicate your acceptance of this License to do so, and
  421. +all its terms and conditions for copying, distributing or modifying
  422. +the Program or works based on it.
  423. +
  424. + 6. Each time you redistribute the Program (or any work based on the
  425. +Program), the recipient automatically receives a license from the
  426. +original licensor to copy, distribute or modify the Program subject to
  427. +these terms and conditions. You may not impose any further
  428. +restrictions on the recipients' exercise of the rights granted herein.
  429. +You are not responsible for enforcing compliance by third parties to
  430. +this License.
  431. +
  432. + 7. If, as a consequence of a court judgment or allegation of patent
  433. +infringement or for any other reason (not limited to patent issues),
  434. +conditions are imposed on you (whether by court order, agreement or
  435. +otherwise) that contradict the conditions of this License, they do not
  436. +excuse you from the conditions of this License. If you cannot
  437. +distribute so as to satisfy simultaneously your obligations under this
  438. +License and any other pertinent obligations, then as a consequence you
  439. +may not distribute the Program at all. For example, if a patent
  440. +license would not permit royalty-free redistribution of the Program by
  441. +all those who receive copies directly or indirectly through you, then
  442. +the only way you could satisfy both it and this License would be to
  443. +refrain entirely from distribution of the Program.
  444. +
  445. +If any portion of this section is held invalid or unenforceable under
  446. +any particular circumstance, the balance of the section is intended to
  447. +apply and the section as a whole is intended to apply in other
  448. +circumstances.
  449. +
  450. +It is not the purpose of this section to induce you to infringe any
  451. +patents or other property right claims or to contest validity of any
  452. +such claims; this section has the sole purpose of protecting the
  453. +integrity of the free software distribution system, which is
  454. +implemented by public license practices. Many people have made
  455. +generous contributions to the wide range of software distributed
  456. +through that system in reliance on consistent application of that
  457. +system; it is up to the author/donor to decide if he or she is willing
  458. +to distribute software through any other system and a licensee cannot
  459. +impose that choice.
  460. +
  461. +This section is intended to make thoroughly clear what is believed to
  462. +be a consequence of the rest of this License.
  463. +
  464. + 8. If the distribution and/or use of the Program is restricted in
  465. +certain countries either by patents or by copyrighted interfaces, the
  466. +original copyright holder who places the Program under this License
  467. +may add an explicit geographical distribution limitation excluding
  468. +those countries, so that distribution is permitted only in or among
  469. +countries not thus excluded. In such case, this License incorporates
  470. +the limitation as if written in the body of this License.
  471. +
  472. + 9. The Free Software Foundation may publish revised and/or new versions
  473. +of the General Public License from time to time. Such new versions will
  474. +be similar in spirit to the present version, but may differ in detail to
  475. +address new problems or concerns.
  476. +
  477. +Each version is given a distinguishing version number. If the Program
  478. +specifies a version number of this License which applies to it and "any
  479. +later version", you have the option of following the terms and conditions
  480. +either of that version or of any later version published by the Free
  481. +Software Foundation. If the Program does not specify a version number of
  482. +this License, you may choose any version ever published by the Free Software
  483. +Foundation.
  484. +
  485. + 10. If you wish to incorporate parts of the Program into other free
  486. +programs whose distribution conditions are different, write to the author
  487. +to ask for permission. For software which is copyrighted by the Free
  488. +Software Foundation, write to the Free Software Foundation; we sometimes
  489. +make exceptions for this. Our decision will be guided by the two goals
  490. +of preserving the free status of all derivatives of our free software and
  491. +of promoting the sharing and reuse of software generally.
  492. +
  493. + NO WARRANTY
  494. +
  495. + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  496. +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
  497. +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  498. +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  499. +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  500. +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
  501. +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
  502. +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  503. +REPAIR OR CORRECTION.
  504. +
  505. + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  506. +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  507. +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  508. +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  509. +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  510. +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  511. +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  512. +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  513. +POSSIBILITY OF SUCH DAMAGES.
  514. +
  515. + END OF TERMS AND CONDITIONS
  516. +
  517. + How to Apply These Terms to Your New Programs
  518. +
  519. + If you develop a new program, and you want it to be of the greatest
  520. +possible use to the public, the best way to achieve this is to make it
  521. +free software which everyone can redistribute and change under these terms.
  522. +
  523. + To do so, attach the following notices to the program. It is safest
  524. +to attach them to the start of each source file to most effectively
  525. +convey the exclusion of warranty; and each file should have at least
  526. +the "copyright" line and a pointer to where the full notice is found.
  527. +
  528. + <one line to give the program's name and a brief idea of what it does.>
  529. + Copyright (C) 19yy <name of author>
  530. +
  531. + This program is free software; you can redistribute it and/or modify
  532. + it under the terms of the GNU General Public License as published by
  533. + the Free Software Foundation; either version 2 of the License, or
  534. + (at your option) any later version.
  535. +
  536. + This program is distributed in the hope that it will be useful,
  537. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  538. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  539. + GNU General Public License for more details.
  540. +
  541. + You should have received a copy of the GNU General Public License
  542. + along with this program; if not, write to the Free Software
  543. + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  544. +
  545. +
  546. +Also add information on how to contact you by electronic and paper mail.
  547. +
  548. +If the program is interactive, make it output a short notice like this
  549. +when it starts in an interactive mode:
  550. +
  551. + Gnomovision version 69, Copyright (C) 19yy name of author
  552. + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  553. + This is free software, and you are welcome to redistribute it
  554. + under certain conditions; type `show c' for details.
  555. +
  556. +The hypothetical commands `show w' and `show c' should show the appropriate
  557. +parts of the General Public License. Of course, the commands you use may
  558. +be called something other than `show w' and `show c'; they could even be
  559. +mouse-clicks or menu items--whatever suits your program.
  560. +
  561. +You should also get your employer (if you work as a programmer) or your
  562. +school, if any, to sign a "copyright disclaimer" for the program, if
  563. +necessary. Here is a sample; alter the names:
  564. +
  565. + Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  566. + `Gnomovision' (which makes passes at compilers) written by James Hacker.
  567. +
  568. + <signature of Ty Coon>, 1 April 1989
  569. + Ty Coon, President of Vice
  570. +
  571. +This General Public License does not permit incorporating your program into
  572. +proprietary programs. If your program is a subroutine library, you may
  573. +consider it more useful to permit linking proprietary applications with the
  574. +library. If this is what you want to do, use the GNU Library General
  575. +Public License instead of this License.
  576. diff --git a/tests/memtester/Makefile b/tests/memtester/Makefile
  577. new file mode 100644
  578. index 0000000..a271bf5
  579. --- /dev/null
  580. +++ b/tests/memtester/Makefile
  581. @@ -0,0 +1,84 @@
  582. +#
  583. +# Makefile for memtester by Charles Cazabon.
  584. +#
  585. +# Copyright (C) 1999 Simon Kirby.
  586. +# Copyright (C) 1999-2009 Charles Cazabon.
  587. +# Licensed under the GNU General Public License version 2. See the file
  588. +# COPYING for details.
  589. +#
  590. +
  591. +# You don't need to edit these; change the contents of the conf-cc and conf-ld
  592. +# files if you need to change the compile/link commands. See the README for
  593. +# more information.
  594. +CC = $(shell head -n 1 conf-cc)
  595. +LD = $(shell head -n 1 conf-ld)
  596. +
  597. +SOURCES = memtester.c tests.c
  598. +OBJECTS = $(SOURCES:.c=.o)
  599. +HEADERS = memtester.h
  600. +TARGETS = *.o compile load auto-ccld.sh find-systype make-compile make-load systype extra-libs
  601. +INSTALLPATH = /usr/local
  602. +
  603. +#
  604. +# Targets
  605. +#
  606. +all: memtester
  607. +
  608. +install: all
  609. + mkdir -m 755 -p $(INSTALLPATH)/{bin,man/man8}
  610. + install -m 755 memtester $(INSTALLPATH)/bin/
  611. + gzip -c memtester.8 >memtester.8.gz ; install -m 644 memtester.8.gz $(INSTALLPATH)/man/man8/
  612. +
  613. +auto-ccld.sh: \
  614. +conf-cc conf-ld warn-auto.sh
  615. + ( cat warn-auto.sh; \
  616. + echo CC=\'`head -1 conf-cc`\'; \
  617. + echo LD=\'`head -1 conf-ld`\' \
  618. + ) > auto-ccld.sh
  619. +
  620. +compile: \
  621. +make-compile warn-auto.sh systype
  622. + ( cat warn-auto.sh; ./make-compile "`cat systype`" ) > \
  623. + compile
  624. + chmod 755 compile
  625. +
  626. +find-systype: \
  627. +find-systype.sh auto-ccld.sh
  628. + cat auto-ccld.sh find-systype.sh > find-systype
  629. + chmod 755 find-systype
  630. +
  631. +make-compile: \
  632. +make-compile.sh auto-ccld.sh
  633. + cat auto-ccld.sh make-compile.sh > make-compile
  634. + chmod 755 make-compile
  635. +
  636. +make-load: \
  637. +make-load.sh auto-ccld.sh
  638. + cat auto-ccld.sh make-load.sh > make-load
  639. + chmod 755 make-load
  640. +
  641. +systype: \
  642. +find-systype trycpp.c
  643. + ./find-systype > systype
  644. +
  645. +extra-libs: \
  646. +extra-libs.sh systype
  647. + ./extra-libs.sh "`cat systype`" >extra-libs
  648. +
  649. +load: \
  650. +make-load warn-auto.sh systype
  651. + ( cat warn-auto.sh; ./make-load "`cat systype`" ) > load
  652. + chmod 755 load
  653. +
  654. +clean:
  655. + rm -f memtester $(TARGETS) $(OBJECTS) core
  656. +
  657. +memtester: \
  658. +$(OBJECTS) memtester.c tests.h tests.c tests.h conf-cc Makefile load extra-libs
  659. + ./load memtester tests.o `cat extra-libs`
  660. +
  661. +memtester.o: memtester.c tests.h conf-cc Makefile compile
  662. + ./compile memtester.c
  663. +
  664. +tests.o: tests.c tests.h conf-cc Makefile compile
  665. + ./compile tests.c
  666. diff --git a/tests/memtester/README b/tests/memtester/README
  667. new file mode 100644
  668. index 0000000..44003b1
  669. --- /dev/null
  670. +++ b/tests/memtester/README
  671. @@ -0,0 +1,126 @@
  672. + memtester
  673. +
  674. + Utility to test for faulty memory subsystem.
  675. +
  676. + by Charles Cazabon <charlesc-memtester@pyropus.ca>
  677. +
  678. + Copyright 1999 Simon Kirby.
  679. + Version 2 Copyright 1999 Charles Cazabon.
  680. + Version 3 not publicly released.
  681. + Version 4 rewrite:
  682. + Copyright 2004-2012 Charles Cazabon.
  683. + Licensed under the terms of the GNU General Public License version 2 (only).
  684. + See the file COPYING for details.
  685. +
  686. +
  687. + About memtester
  688. +
  689. + memtester is a utility for testing the memory subsystem in a computer to
  690. + determine if it is faulty. The original source was by Simon Kirby
  691. + <sim@stormix.com>. I have by this time completely rewritten the
  692. + original source, and added many additional tests to help catch
  693. + borderline memory. I also rewrote the original tests (which catch
  694. + mainly memory bits which are stuck permanently high or low) so that
  695. + they run approximately an order of magnitude faster.
  696. +
  697. + The version 4 rewrite was mainly to accomplish three things:
  698. +
  699. + (1) the previous code was basically a hack, and was ugly.
  700. + (2) to make the code more portable. The previous version required some
  701. + hackery to compile on some systems.
  702. + (3) to make the code fully 64-bit aware. The previous version worked
  703. + on 64-bit systems, but did not fully stress the memory subsystems
  704. + on them -- this version should be better at stress-testing 64-bit
  705. + systems.
  706. +
  707. + Building memtester
  708. +
  709. + memtester is currently only distributed in source-code form. Building
  710. + it, however, is simple -- just type `make`. There's no `configure` script
  711. + or anything like that.
  712. +
  713. + If you have a really strange system/toolchain, you might need to edit the
  714. + conf-cc or conf-ld files, but try to build it without changes first.
  715. + For example, if you want to cross-compile with `armgcc`, you would edit
  716. + conf-cc and conf-ld to use `armgcc` instead of `cc`. You can also change
  717. + the contents of these files for other reasons; for example, if your
  718. + compiler isn't in your PATH, you could change it to use `/path/to/cc` or
  719. + similar.
  720. +
  721. + You can run the resulting binary from anywhere, but if you want to install
  722. + it and the manpage to /usr/local/, `make install` will do that. Edit
  723. + INSTALLPATH in the makefile if you prefer a different location.
  724. +
  725. + I've successfully built and run memtester 4 on the following systems:
  726. +
  727. + HP Tru64 Unix 4.0g (Alpha)
  728. + HP Tru64 Unix 5.1b (Alpha)
  729. + HP-UX 11i 11.11 (PA-RISC)
  730. + HP-UX 11i 11.23 (64-bit Itanium)
  731. + Debian GNU/Linux 3.0 (various)
  732. + other 32-bit Linux (RedHat, SuSE, Ubuntu, etc) (various)
  733. + RedHat Enterprise Linux/CentOS (64-bit AMD Opteron)
  734. + FreeBSD 4.9 (32-bit Intel)
  735. + FreeBSD 5.1 (64-bit Alpha)
  736. + NetBSD 1.6 (32-bit Intel)
  737. + Darwin (OS X) 7.5.0 (32-bit PowerPC)
  738. + OS X Leopard/Panther/whatever -- 32- or 64-bit, PPC or x86
  739. +
  740. + It should, however, work on other Unix-like systems -- I simply don't
  741. + have access to systems running Solaris, AIX, etc. at the moment.
  742. + If you have trouble building memtester on your system, please report it
  743. + to me so I can fix this.
  744. +
  745. + Using memtester
  746. +
  747. + Usage is simple for the basic case. As root, run the resulting memtester
  748. + binary with the following commandline:
  749. +
  750. + memtester <memory> [runs]
  751. +
  752. + where <memory> is the amount of memory to test, in megabytes by default.
  753. + You can optionally include a suffix of B, K, M, or G (for bytes,
  754. + kilobytes, megabytes, and gigabytes respectively).
  755. + [runs] is an optional limit to the number of runs through all tests.
  756. +
  757. + An optional "-p physaddr" argument available to cause memtester to test
  758. + memory starting at a specific physical memory address (by mmap(2)ing
  759. + a device file representing physical memory (/dev/mem by default, but can
  760. + be specified with the "-d device" option) starting at an offset of
  761. + `physaddr`, which is given in hex).
  762. +
  763. + Note: the memory specified will be overwritten during testing; you
  764. + therefore *cannot* specify a region belonging to the kernel or other
  765. + applications without causing the other process or entire system to
  766. + crash). If you use this option, it is up to you to ensure the specified
  767. + memory is safe to overwrite. That makes this option mostly of use for
  768. + testing memory-mapped I/O devices and similar. Thanks to Allon Stern
  769. + for the idea behind this feature. For example, if you want to test a
  770. + bank of RAM or device which is 64kbytes in size and starts at physical
  771. + address 0x0C0000 through the normal /dev/mem, you would run memtester as
  772. + follows:
  773. +
  774. + memtester -p 0x0c0000 64k [runs]
  775. +
  776. + If instead that device presented its memory as /dev/foodev at offset
  777. + 0, you would run memtester instead as follows:
  778. +
  779. + memtester -p 0 -d /dev/foodev 64k [runs]
  780. +
  781. + Note that the "-d" option can only be specified in combination with "-p".
  782. +
  783. + memtester must run as user root so that it can lock its pages into
  784. + memory. If memtester fails to lock its pages, it will issue a warning and
  785. + continue regardless. Testing without the memory being locked is generally
  786. + very slow and not particularly accurate, as you'll end up testing the same
  787. + memory over and over as the system swaps the larger region.
  788. +
  789. + Current Version
  790. +
  791. + The current version of memtester should be available at
  792. + http:/​/​pyropus​.​ca/​software/​memtester/​
  793. +
  794. + Questions, comments, and feature requests should be
  795. + directed to me at <charlesc-memtester@pyropus.ca>. Read BUGS to report
  796. + bugs found in memtester.
  797. +
  798. diff --git a/tests/memtester/README.tests b/tests/memtester/README.tests
  799. new file mode 100644
  800. index 0000000..fd35b57
  801. --- /dev/null
  802. +++ b/tests/memtester/README.tests
  803. @@ -0,0 +1,38 @@
  804. +About the Tests
  805. +---------------
  806. +
  807. +The following tests are from the original version, updated simply for speed
  808. +and rewritten to fit the new framework of the program. These tests will
  809. +mainly catch memory errors due to bad bits which are permanently stuck high
  810. +or low:
  811. + Random value
  812. + XOR comparison
  813. + SUB comparison
  814. + MUL comparison
  815. + DIV comparison
  816. + OR comparison
  817. + AND comparison
  818. +
  819. +The following tests were implemented by me, and will do a slightly better job
  820. +of catching flaky bits, which may or may not hold a true value:
  821. + Sequential Increment
  822. + Block Sequential
  823. + Solid Bits
  824. +
  825. +The remaining tests were also implemented by me, and are designed to catch
  826. +bad bits which are dependent on the current values of surrounding bits in either
  827. +the same word32, or in the preceding and succeeding word32s.
  828. + Bit Flip
  829. + Checkerboard
  830. + Walking Ones
  831. + Walking Zeroes
  832. + Bit Spread
  833. +
  834. +There is also a test (Stuck Address) which is run first. It determines if the
  835. +memory locations the program attempts to access are addressed properly or not.
  836. +If this test reports errors, there is almost certainly a problem somewhere in
  837. +the memory subsystem. Results from the rest of the tests cannot be considered
  838. +accurate if this test fails:
  839. + Stuck Address
  840. +
  841. +Usage information is summarized in the file README, and in the man page.
  842. diff --git a/tests/memtester/conf-cc b/tests/memtester/conf-cc
  843. new file mode 100644
  844. index 0000000..404e5d3
  845. --- /dev/null
  846. +++ b/tests/memtester/conf-cc
  847. @@ -0,0 +1,3 @@
  848. +arm-linux-androideabi-gcc -O2 -DPOSIX -D_POSIX_C_SOURCE=200809L -D_FILE_OFFSET_BITS=64 -DTEST_NARROW_WRITES -c
  849. +
  850. +This will be used to compile .c files.
  851. diff --git a/tests/memtester/conf-ld b/tests/memtester/conf-ld
  852. new file mode 100644
  853. index 0000000..3b9dc52
  854. --- /dev/null
  855. +++ b/tests/memtester/conf-ld
  856. @@ -0,0 +1,3 @@
  857. +arm-linux-androideabi-gcc -s
  858. +
  859. +This will be used to link .o files into an executable.
  860. diff --git a/tests/memtester/extra-libs.sh b/tests/memtester/extra-libs.sh
  861. new file mode 100755
  862. index 0000000..d1bc718
  863. --- /dev/null
  864. +++ b/tests/memtester/extra-libs.sh
  865. @@ -0,0 +1,16 @@
  866. +#!/bin/sh
  867. +
  868. +case "$1" in
  869. +osf1-*)
  870. + # OSF/1 (Tru64) needs /usr/lib/librt.a for mlock()
  871. + echo /usr/lib/librt.a
  872. + ;;
  873. +unix_sv*) ;;
  874. +irix64-*) ;;
  875. +irix-*) ;;
  876. +dgux-*) ;;
  877. +hp-ux-*) ;;
  878. +sco*) ;;
  879. +*)
  880. + ;;
  881. +esac
  882. diff --git a/tests/memtester/find-systype.sh b/tests/memtester/find-systype.sh
  883. new file mode 100755
  884. index 0000000..16266d3
  885. --- /dev/null
  886. +++ b/tests/memtester/find-systype.sh
  887. @@ -0,0 +1,144 @@
  888. +# oper-:arch-:syst-:chip-:kern-
  889. +# oper = operating system type; e.g., sunos-4.1.4
  890. +# arch = machine language; e.g., sparc
  891. +# syst = which binaries can run; e.g., sun4
  892. +# chip = chip model; e.g., micro-2-80
  893. +# kern = kernel version; e.g., sun4m
  894. +# dependence: arch --- chip
  895. +# \ \
  896. +# oper --- syst --- kern
  897. +# so, for example, syst is interpreted in light of oper, but chip is not.
  898. +# anyway, no slashes, no extra colons, no uppercase letters.
  899. +# the point of the extra -'s is to ease parsing: can add hierarchies later.
  900. +# e.g., *:i386-*:*:pentium-*:* would handle pentium-100 as well as pentium,
  901. +# and i386-486 (486s do have more instructions, you know) as well as i386.
  902. +# the idea here is to include ALL useful available information.
  903. +
  904. +exec 2>/dev/null
  905. +sys="`uname -s | tr '/:[A-Z]' '..[a-z]'`"
  906. +if [ x"$sys" != x ]
  907. +then
  908. + unamer="`uname -r | tr /: ..`"
  909. + unamem="`uname -m | tr /: ..`"
  910. + unamev="`uname -v | tr /: ..`"
  911. +
  912. + case "$sys" in
  913. + bsd.os)
  914. + # in bsd 4.4, uname -v does not have useful info.
  915. + # in bsd 4.4, uname -m is arch, not chip.
  916. + oper="$sys-$unamer"
  917. + arch="$unamem"
  918. + syst=""
  919. + chip="`sysctl -n hw.model`"
  920. + kern=""
  921. + ;;
  922. + freebsd)
  923. + # see above about bsd 4.4
  924. + oper="$sys-$unamer"
  925. + arch="$unamem"
  926. + syst=""
  927. + chip="`sysctl -n hw.model`" # hopefully
  928. + kern=""
  929. + ;;
  930. + netbsd)
  931. + # see above about bsd 4.4
  932. + oper="$sys-$unamer"
  933. + arch="$unamem"
  934. + syst=""
  935. + chip="`sysctl -n hw.model`" # hopefully
  936. + kern=""
  937. + ;;
  938. + linux)
  939. + # as in bsd 4.4, uname -v does not have useful info.
  940. + oper="$sys-$unamer"
  941. + syst=""
  942. + chip="$unamem"
  943. + kern=""
  944. + case "$chip" in
  945. + i386|i486|i586|i686)
  946. + arch="i386"
  947. + ;;
  948. + alpha)
  949. + arch="alpha"
  950. + ;;
  951. + esac
  952. + ;;
  953. + aix)
  954. + # naturally IBM has to get uname -r and uname -v backwards. dorks.
  955. + oper="$sys-$unamev-$unamer"
  956. + arch="`arch | tr /: ..`"
  957. + syst=""
  958. + chip="$unamem"
  959. + kern=""
  960. + ;;
  961. + sunos)
  962. + oper="$sys-$unamer-$unamev"
  963. + arch="`(uname -p || mach) | tr /: ..`"
  964. + syst="`arch | tr /: ..`"
  965. + chip="$unamem" # this is wrong; is there any way to get the real info?
  966. + kern="`arch -k | tr /: ..`"
  967. + ;;
  968. + unix_sv)
  969. + oper="$sys-$unamer-$unamev"
  970. + arch="`uname -m`"
  971. + syst=""
  972. + chip="$unamem"
  973. + kern=""
  974. + ;;
  975. + *)
  976. + oper="$sys-$unamer-$unamev"
  977. + arch="`arch | tr /: ..`"
  978. + syst=""
  979. + chip="$unamem"
  980. + kern=""
  981. + ;;
  982. + esac
  983. +else
  984. + $CC -c trycpp.c
  985. + $LD -o trycpp trycpp.o
  986. + case `./trycpp` in
  987. + nextstep)
  988. + oper="nextstep-`hostinfo | sed -n 's/^[ ]*NeXT Mach \([^:]*\):.*$/\1/p'`"
  989. + arch="`hostinfo | sed -n 's/^Processor type: \(.*\) (.*)$/\1/p' | tr /: ..`"
  990. + syst=""
  991. + chip="`hostinfo | sed -n 's/^Processor type: .* (\(.*\))$/\1/p' | tr ' /:' '...'`"
  992. + kern=""
  993. + ;;
  994. + *)
  995. + oper="unknown"
  996. + arch=""
  997. + syst=""
  998. + chip=""
  999. + kern=""
  1000. + ;;
  1001. + esac
  1002. + rm -f trycpp.o trycpp
  1003. +fi
  1004. +
  1005. +case "$chip" in
  1006. +80486)
  1007. + # let's try to be consistent here. (BSD/OS)
  1008. + chip=i486
  1009. + ;;
  1010. +i486DX)
  1011. + # respect the hyphen hierarchy. (FreeBSD)
  1012. + chip=i486-dx
  1013. + ;;
  1014. +i486.DX2)
  1015. + # respect the hyphen hierarchy. (FreeBSD)
  1016. + chip=i486-dx2
  1017. + ;;
  1018. +Intel.586)
  1019. + # no, you nitwits, there is no such chip. (NeXTStep)
  1020. + chip=pentium
  1021. + ;;
  1022. +i586)
  1023. + # no, you nitwits, there is no such chip. (Linux)
  1024. + chip=pentium
  1025. + ;;
  1026. +i686)
  1027. + # STOP SAYING THAT! (Linux)
  1028. + chip=ppro
  1029. +esac
  1030. +
  1031. +echo "$oper-:$arch-:$syst-:$chip-:$kern-" | tr ' [A-Z]' '.[a-z]'
  1032. diff --git a/tests/memtester/make-compile.sh b/tests/memtester/make-compile.sh
  1033. new file mode 100755
  1034. index 0000000..a1eb501
  1035. --- /dev/null
  1036. +++ b/tests/memtester/make-compile.sh
  1037. @@ -0,0 +1 @@
  1038. +echo exec "$CC" -c '${1+"$@"}'
  1039. diff --git a/tests/memtester/make-load.sh b/tests/memtester/make-load.sh
  1040. new file mode 100755
  1041. index 0000000..de07d2e
  1042. --- /dev/null
  1043. +++ b/tests/memtester/make-load.sh
  1044. @@ -0,0 +1,2 @@
  1045. +echo 'main="$1"; shift'
  1046. +echo exec "$LD" '-o "$main" "$main".o ${1+"$@"}'
  1047. diff --git a/tests/memtester/make-makelib.sh b/tests/memtester/make-makelib.sh
  1048. new file mode 100755
  1049. index 0000000..d6b7c8c
  1050. --- /dev/null
  1051. +++ b/tests/memtester/make-makelib.sh
  1052. @@ -0,0 +1,16 @@
  1053. +echo 'main="$1"; shift'
  1054. +echo 'rm -f "$main"'
  1055. +echo 'ar cr "$main" ${1+"$@"}'
  1056. +
  1057. +case "$1" in
  1058. +sunos-5.*) ;;
  1059. +unix_sv*) ;;
  1060. +irix64-*) ;;
  1061. +irix-*) ;;
  1062. +dgux-*) ;;
  1063. +hp-ux-*) ;;
  1064. +sco*) ;;
  1065. +*)
  1066. + echo 'ranlib "$main"'
  1067. + ;;
  1068. +esac
  1069. diff --git a/tests/memtester/memtester.8 b/tests/memtester/memtester.8
  1070. new file mode 100644
  1071. index 0000000..fd80bc7
  1072. --- /dev/null
  1073. +++ b/tests/memtester/memtester.8
  1074. @@ -0,0 +1,103 @@
  1075. +.TH memtester "8" "June 2012" "memtester 4" "Maintenance Commands"
  1076. +.SH NAME
  1077. +memtester \- stress test to find memory subsystem faults.
  1078. +.SH SYNOPSIS
  1079. +.B memtester
  1080. +[\f -p PHYSADDR\fR [\f -d DEVICE\fR]]
  1081. +<\fIMEMORY\fR>
  1082. +[\fIITERATIONS\fR]
  1083. +.SH DESCRIPTION
  1084. +.\" Add any additional description here
  1085. +.PP
  1086. +memtester is an effective userspace tester for stress-testing the memory
  1087. +subsystem. It is very effective at finding intermittent and non-deterministic
  1088. +faults. Note that problems in other hardware areas (overheating CPU,
  1089. +out-of-specification power supply, etc.) can cause intermittent memory faults,
  1090. +so it is still up to you to determine where the fault lies through normal
  1091. +hardware diagnostic procedures; memtester just helps you determine whether
  1092. +a problem exists.
  1093. +.PP
  1094. +memtester will malloc(3) the amount of memory specified, if possible. If
  1095. +this fails, it will decrease the amount of memory requested until it succeeds.
  1096. +It will then attempt to mlock(3) this memory; if it cannot do so, testing
  1097. +will be slower and much less effective. Run memtester as root so that it
  1098. +can mlock the memory it tests.
  1099. +.PP
  1100. +Note that the maximum amount of memory that memtester can test will be less
  1101. +than the total amount of memory installed in the system; the operating system,
  1102. +libraries, and other system limits take some of the available memory.
  1103. +memtester is also limited to the amount of memory available to a single
  1104. +process; for example, on 32-bit machines with more than 4GB of memory,
  1105. +memtester is still limited to less than 4GB.
  1106. +.PP
  1107. +Note that it is up to you to know how much memory you can safely allocate
  1108. +for testing. If you attempt to allocate more memory than is available,
  1109. +memtester should figure that out, reduce the amount slightly, and try again.
  1110. +However, this can lead to memtester successfully allocating and mlocking
  1111. +essentially all free memory on the system -- if other programs are running,
  1112. +this can lead to excessive swapping and slowing the system down to the point
  1113. +that it is difficult to use. If the system allows allocation of more memory
  1114. +than is actually available (overcommit), it may lead to a deadlock, where
  1115. +the system halts. If the system has an out-of-memory process killer (like
  1116. +Linux), memtester or another process may be killed by the OOM killer.
  1117. +.PP
  1118. +So choose wisely.
  1119. +.PP
  1120. +.SH OPTIONS
  1121. +.TP
  1122. +\f -p PHYSADDR\fR
  1123. +tells memtester to test a specific region of memory starting at physical
  1124. +address PHYSADDR (given in hex), by mmap(2)ing a device specified by the
  1125. +-d option (below, or /dev/mem by default). This is mostly of use to hardware
  1126. +developers, for testing memory-mapped I/O devices and similar.
  1127. +Note that the memory region will be overwritten during testing, so it is not
  1128. +safe to specify memory which is allocated for the system or for other
  1129. +applications; doing so will cause them to crash. If you absolutely must test
  1130. +a particular region of actual physical memory, arrange to have that memory
  1131. +allocated by your test software, and hold it in this allocated state, then
  1132. +run memtester on it with this option.
  1133. +.TP
  1134. +\fIMEMORY\fR
  1135. +the amount of memory to allocate and test, in megabytes by default. You can
  1136. +include a suffix of B, K, M, or G to indicate bytes, kilobytes, megabytes, or
  1137. +gigabytes respectively.
  1138. +.TP
  1139. +\fIITERATIONS\fR
  1140. +(optional) number of loops to iterate through. Default is infinite.
  1141. +.SH ENVIRONMENT
  1142. +.PP
  1143. +If the environment variable MEMTESTER_TEST_MASK is set, memtester treats the
  1144. +value as a bitmask of which tests (other than the stuck address test) to run.
  1145. +The value can be specified in decimal, in octal (with a leading 0), or in
  1146. +hexadecimal (with a leading 0x). The specific bit values corresponding to
  1147. +particular tests may change from release to release; consult the list of tests
  1148. +in the source for the appropriate index values for the version of memtester you
  1149. +are running. Note that skipping some tests will reduce the time it takes for
  1150. +memtester to run, but also reduce memtester's effectiveness.
  1151. +.SH NOTE
  1152. +.PP
  1153. +memtester must be run with root privileges to mlock(3) its pages. Testing
  1154. +memory without locking the pages in place is mostly pointless and slow.
  1155. +.SH EXIT CODE
  1156. +.PP
  1157. +memtester's exit code is 0 when everything works properly. Otherwise,
  1158. +it is the logical OR of the following values:
  1159. +.TP
  1160. +\f0x01
  1161. +error allocating or locking memory, or invocation error
  1162. +.TP
  1163. +\f0x02
  1164. +error during stuck address test
  1165. +.TP
  1166. +\f0x04
  1167. +error during one of the other tests
  1168. +.SH AUTHOR
  1169. +Written by Charles Cazabon.
  1170. +.SH "REPORTING BUGS"
  1171. +Report bugs to <charlesc-memtester-bugs@pyropus.ca>.
  1172. +.PP
  1173. +.SH COPYRIGHT
  1174. +Copyright \(co 2001-2012 Charles Cazabon
  1175. +.br
  1176. +This is free software; see the file COPYING for copying conditions. There is NO
  1177. +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  1178. diff --git a/tests/memtester/memtester.c b/tests/memtester/memtester.c
  1179. new file mode 100644
  1180. index 0000000..3db2ad4
  1181. --- /dev/null
  1182. +++ b/tests/memtester/memtester.c
  1183. @@ -0,0 +1,403 @@
  1184. +/*
  1185. + * memtester version 4
  1186. + *
  1187. + * Very simple but very effective user-space memory tester.
  1188. + * Originally by Simon Kirby <sim@stormix.com> <sim@neato.org>
  1189. + * Version 2 by Charles Cazabon <charlesc-memtester@pyropus.ca>
  1190. + * Version 3 not publicly released.
  1191. + * Version 4 rewrite:
  1192. + * Copyright (C) 2004-2012 Charles Cazabon <charlesc-memtester@pyropus.ca>
  1193. + * Licensed under the terms of the GNU General Public License version 2 (only).
  1194. + * See the file COPYING for details.
  1195. + *
  1196. + */
  1197. +
  1198. +#define __version__ "4.3.0"
  1199. +
  1200. +#include <stddef.h>
  1201. +#include <stdlib.h>
  1202. +#include <stdio.h>
  1203. +#include <sys/types.h>
  1204. +#include <sys/stat.h>
  1205. +#include <sys/mman.h>
  1206. +#include <unistd.h>
  1207. +#include <fcntl.h>
  1208. +#include <string.h>
  1209. +#include <errno.h>
  1210. +
  1211. +#include "types.h"
  1212. +#include "sizes.h"
  1213. +#include "tests.h"
  1214. +
  1215. +#define EXIT_FAIL_NONSTARTER 0x01
  1216. +#define EXIT_FAIL_ADDRESSLINES 0x02
  1217. +#define EXIT_FAIL_OTHERTEST 0x04
  1218. +
  1219. +struct test tests[] = {
  1220. + { "Random Value", test_random_value },
  1221. + { "Compare XOR", test_xor_comparison },
  1222. + { "Compare SUB", test_sub_comparison },
  1223. + { "Compare MUL", test_mul_comparison },
  1224. + { "Compare DIV",test_div_comparison },
  1225. + { "Compare OR", test_or_comparison },
  1226. + { "Compare AND", test_and_comparison },
  1227. + { "Sequential Increment", test_seqinc_comparison },
  1228. + { "Solid Bits", test_solidbits_comparison },
  1229. + { "Block Sequential", test_blockseq_comparison },
  1230. + { "Checkerboard", test_checkerboard_comparison },
  1231. + { "Bit Spread", test_bitspread_comparison },
  1232. + { "Bit Flip", test_bitflip_comparison },
  1233. + { "Walking Ones", test_walkbits1_comparison },
  1234. + { "Walking Zeroes", test_walkbits0_comparison },
  1235. +#ifdef TEST_NARROW_WRITES
  1236. + { "8-bit Writes", test_8bit_wide_random },
  1237. + { "16-bit Writes", test_16bit_wide_random },
  1238. +#endif
  1239. + { NULL, NULL }
  1240. +};
  1241. +
  1242. +/* Sanity checks and portability helper macros. */
  1243. +#ifdef _SC_VERSION
  1244. +void check_posix_system(void) {
  1245. + if (sysconf(_SC_VERSION) < 198808L) {
  1246. + fprintf(stderr, "A POSIX system is required. Don't be surprised if "
  1247. + "this craps out.\n");
  1248. + fprintf(stderr, "_SC_VERSION is %lu\n", sysconf(_SC_VERSION));
  1249. + }
  1250. +}
  1251. +#else
  1252. +#define check_posix_system()
  1253. +#endif
  1254. +
  1255. +#ifdef _SC_PAGE_SIZE
  1256. +int memtester_pagesize(void) {
  1257. + int pagesize = sysconf(_SC_PAGE_SIZE);
  1258. + if (pagesize == -1) {
  1259. + perror("get page size failed");
  1260. + exit(EXIT_FAIL_NONSTARTER);
  1261. + }
  1262. + printf("pagesize is %ld\n", (long) pagesize);
  1263. + return pagesize;
  1264. +}
  1265. +#else
  1266. +int memtester_pagesize(void) {
  1267. + printf("sysconf(_SC_PAGE_SIZE) not supported; using pagesize of 8192\n");
  1268. + return 8192;
  1269. +}
  1270. +#endif
  1271. +
  1272. +/* Some systems don't define MAP_LOCKED. Define it to 0 here
  1273. + so it's just a no-op when ORed with other constants. */
  1274. +#ifndef MAP_LOCKED
  1275. + #define MAP_LOCKED 0
  1276. +#endif
  1277. +
  1278. +/* Function declarations */
  1279. +void usage(char *me);
  1280. +
  1281. +/* Global vars - so tests have access to this information */
  1282. +int use_phys = 0;
  1283. +off_t physaddrbase = 0;
  1284. +
  1285. +/* Function definitions */
  1286. +void usage(char *me) {
  1287. + fprintf(stderr, "\n"
  1288. + "Usage: %s [-p physaddrbase [-d device]] <mem>[B|K|M|G] [loops]\n",
  1289. + me);
  1290. + exit(EXIT_FAIL_NONSTARTER);
  1291. +}
  1292. +
  1293. +int main(int argc, char **argv) {
  1294. + ul loops, loop, i;
  1295. + size_t pagesize, wantraw, wantmb, wantbytes, wantbytes_orig, bufsize,
  1296. + halflen, count;
  1297. + char *memsuffix, *addrsuffix, *loopsuffix;
  1298. + ptrdiff_t pagesizemask;
  1299. + void volatile *buf, *aligned;
  1300. + ulv *bufa, *bufb;
  1301. + int do_mlock = 1, done_mem = 0;
  1302. + int exit_code = 0;
  1303. + int memfd, opt, memshift;
  1304. + size_t maxbytes = -1; /* addressable memory, in bytes */
  1305. + size_t maxmb = (maxbytes >> 20) + 1; /* addressable memory, in MB */
  1306. + /* Device to mmap memory from with -p, default is normal core */
  1307. + char *device_name = "/dev/mem";
  1308. + struct stat statbuf;
  1309. + int device_specified = 0;
  1310. + char *env_testmask = 0;
  1311. + ul testmask = 0;
  1312. +
  1313. + printf("memtester version " __version__ " (%d-bit)\n", UL_LEN);
  1314. + printf("Copyright (C) 2001-2012 Charles Cazabon.\n");
  1315. + printf("Licensed under the GNU General Public License version 2 (only).\n");
  1316. + printf("\n");
  1317. + check_posix_system();
  1318. + pagesize = memtester_pagesize();
  1319. + pagesizemask = (ptrdiff_t) ~(pagesize - 1);
  1320. + printf("pagesizemask is 0x%tx\n", pagesizemask);
  1321. +
  1322. + /* If MEMTESTER_TEST_MASK is set, we use its value as a mask of which
  1323. + tests we run.
  1324. + */
  1325. + if (env_testmask = getenv("MEMTESTER_TEST_MASK")) {
  1326. + errno = 0;
  1327. + testmask = strtoul(env_testmask, 0, 0);
  1328. + if (errno) {
  1329. + fprintf(stderr, "error parsing MEMTESTER_TEST_MASK %s: %s\n",
  1330. + env_testmask, strerror(errno));
  1331. + usage(argv[0]); /* doesn't return */
  1332. + }
  1333. + printf("using testmask 0x%lx\n", testmask);
  1334. + }
  1335. +
  1336. + while ((opt = getopt(argc, argv, "p:d:")) != -1) {
  1337. + switch (opt) {
  1338. + case 'p':
  1339. + errno = 0;
  1340. + physaddrbase = (off_t) strtoull(optarg, &addrsuffix, 16);
  1341. + if (errno != 0) {
  1342. + fprintf(stderr,
  1343. + "failed to parse physaddrbase arg; should be hex "
  1344. + "address (0x123...)\n");
  1345. + usage(argv[0]); /* doesn't return */
  1346. + }
  1347. + if (*addrsuffix != '\0') {
  1348. + /* got an invalid character in the address */
  1349. + fprintf(stderr,
  1350. + "failed to parse physaddrbase arg; should be hex "
  1351. + "address (0x123...)\n");
  1352. + usage(argv[0]); /* doesn't return */
  1353. + }
  1354. + if (physaddrbase & (pagesize - 1)) {
  1355. + fprintf(stderr,
  1356. + "bad physaddrbase arg; does not start on page "
  1357. + "boundary\n");
  1358. + usage(argv[0]); /* doesn't return */
  1359. + }
  1360. + /* okay, got address */
  1361. + use_phys = 1;
  1362. + break;
  1363. + case 'd':
  1364. + if (stat(optarg,&statbuf)) {
  1365. + fprintf(stderr, "can not use %s as device: %s\n", optarg,
  1366. + strerror(errno));
  1367. + usage(argv[0]); /* doesn't return */
  1368. + } else {
  1369. + if (!S_ISCHR(statbuf.st_mode)) {
  1370. + fprintf(stderr, "can not mmap non-char device %s\n",
  1371. + optarg);
  1372. + usage(argv[0]); /* doesn't return */
  1373. + } else {
  1374. + device_name = optarg;
  1375. + device_specified = 1;
  1376. + }
  1377. + }
  1378. + break;
  1379. + default: /* '?' */
  1380. + usage(argv[0]); /* doesn't return */
  1381. + }
  1382. + }
  1383. +
  1384. + if (device_specified && !use_phys) {
  1385. + fprintf(stderr,
  1386. + "for mem device, physaddrbase (-p) must be specified\n");
  1387. + usage(argv[0]); /* doesn't return */
  1388. + }
  1389. +
  1390. + if (optind >= argc) {
  1391. + fprintf(stderr, "need memory argument, in MB\n");
  1392. + usage(argv[0]); /* doesn't return */
  1393. + }
  1394. +
  1395. + errno = 0;
  1396. + wantraw = (size_t) strtoul(argv[optind], &memsuffix, 0);
  1397. + if (errno != 0) {
  1398. + fprintf(stderr, "failed to parse memory argument");
  1399. + usage(argv[0]); /* doesn't return */
  1400. + }
  1401. + switch (*memsuffix) {
  1402. + case 'G':
  1403. + case 'g':
  1404. + memshift = 30; /* gigabytes */
  1405. + break;
  1406. + case 'M':
  1407. + case 'm':
  1408. + memshift = 20; /* megabytes */
  1409. + break;
  1410. + case 'K':
  1411. + case 'k':
  1412. + memshift = 10; /* kilobytes */
  1413. + break;
  1414. + case 'B':
  1415. + case 'b':
  1416. + memshift = 0; /* bytes*/
  1417. + break;
  1418. + case '\0': /* no suffix */
  1419. + memshift = 20; /* megabytes */
  1420. + break;
  1421. + default:
  1422. + /* bad suffix */
  1423. + usage(argv[0]); /* doesn't return */
  1424. + }
  1425. + wantbytes_orig = wantbytes = ((size_t) wantraw << memshift);
  1426. + wantmb = (wantbytes_orig >> 20);
  1427. + optind++;
  1428. + if (wantmb > maxmb) {
  1429. + fprintf(stderr, "This system can only address %llu MB.\n", (ull) maxmb);
  1430. + exit(EXIT_FAIL_NONSTARTER);
  1431. + }
  1432. + if (wantbytes < pagesize) {
  1433. + fprintf(stderr, "bytes %ld < pagesize %ld -- memory argument too large?\n",
  1434. + wantbytes, pagesize);
  1435. + exit(EXIT_FAIL_NONSTARTER);
  1436. + }
  1437. +
  1438. + if (optind >= argc) {
  1439. + loops = 0;
  1440. + } else {
  1441. + errno = 0;
  1442. + loops = strtoul(argv[optind], &loopsuffix, 0);
  1443. + if (errno != 0) {
  1444. + fprintf(stderr, "failed to parse number of loops");
  1445. + usage(argv[0]); /* doesn't return */
  1446. + }
  1447. + if (*loopsuffix != '\0') {
  1448. + fprintf(stderr, "loop suffix %c\n", *loopsuffix);
  1449. + usage(argv[0]); /* doesn't return */
  1450. + }
  1451. + }
  1452. +
  1453. + printf("want %lluMB (%llu bytes)\n", (ull) wantmb, (ull) wantbytes);
  1454. + buf = NULL;
  1455. +
  1456. + if (use_phys) {
  1457. + memfd = open(device_name, O_RDWR | O_SYNC);
  1458. + if (memfd == -1) {
  1459. + fprintf(stderr, "failed to open %s for physical memory: %s\n",
  1460. + device_name, strerror(errno));
  1461. + exit(EXIT_FAIL_NONSTARTER);
  1462. + }
  1463. + buf = (void volatile *) mmap(0, wantbytes, PROT_READ | PROT_WRITE,
  1464. + MAP_SHARED | MAP_LOCKED, memfd,
  1465. + physaddrbase);
  1466. + if (buf == MAP_FAILED) {
  1467. + fprintf(stderr, "failed to mmap %s for physical memory: %s\n",
  1468. + device_name, strerror(errno));
  1469. + exit(EXIT_FAIL_NONSTARTER);
  1470. + }
  1471. +
  1472. + if (mlock((void *) buf, wantbytes) < 0) {
  1473. + fprintf(stderr, "failed to mlock mmap'ed space\n");
  1474. + do_mlock = 0;
  1475. + }
  1476. +
  1477. + bufsize = wantbytes; /* accept no less */
  1478. + aligned = buf;
  1479. + done_mem = 1;
  1480. + }
  1481. +
  1482. + while (!done_mem) {
  1483. + while (!buf && wantbytes) {
  1484. + buf = (void volatile *) malloc(wantbytes);
  1485. + if (!buf) wantbytes -= pagesize;
  1486. + }
  1487. + bufsize = wantbytes;
  1488. + printf("got %lluMB (%llu bytes)", (ull) wantbytes >> 20,
  1489. + (ull) wantbytes);
  1490. + fflush(stdout);
  1491. + if (do_mlock) {
  1492. + printf(", trying mlock ...");
  1493. + fflush(stdout);
  1494. + if ((size_t) buf % pagesize) {
  1495. + /* printf("aligning to page -- was 0x%tx\n", buf); */
  1496. + aligned = (void volatile *) ((size_t) buf & pagesizemask) + pagesize;
  1497. + /* printf(" now 0x%tx -- lost %d bytes\n", aligned,
  1498. + * (size_t) aligned - (size_t) buf);
  1499. + */
  1500. + bufsize -= ((size_t) aligned - (size_t) buf);
  1501. + } else {
  1502. + aligned = buf;
  1503. + }
  1504. + /* Try mlock */
  1505. + if (mlock((void *) aligned, bufsize) < 0) {
  1506. + switch(errno) {
  1507. + case EAGAIN: /* BSDs */
  1508. + printf("over system/pre-process limit, reducing...\n");
  1509. + free((void *) buf);
  1510. + buf = NULL;
  1511. + wantbytes -= pagesize;
  1512. + break;
  1513. + case ENOMEM:
  1514. + printf("too many pages, reducing...\n");
  1515. + free((void *) buf);
  1516. + buf = NULL;
  1517. + wantbytes -= pagesize;
  1518. + break;
  1519. + case EPERM:
  1520. + printf("insufficient permission.\n");
  1521. + printf("Trying again, unlocked:\n");
  1522. + do_mlock = 0;
  1523. + free((void *) buf);
  1524. + buf = NULL;
  1525. + wantbytes = wantbytes_orig;
  1526. + break;
  1527. + default:
  1528. + printf("failed for unknown reason.\n");
  1529. + do_mlock = 0;
  1530. + done_mem = 1;
  1531. + }
  1532. + } else {
  1533. + printf("locked.\n");
  1534. + done_mem = 1;
  1535. + }
  1536. + } else {
  1537. + done_mem = 1;
  1538. + printf("\n");
  1539. + }
  1540. + }
  1541. +
  1542. + if (!do_mlock) fprintf(stderr, "Continuing with unlocked memory; testing "
  1543. + "will be slower and less reliable.\n");
  1544. +
  1545. + halflen = bufsize / 2;
  1546. + count = halflen / sizeof(ul);
  1547. + bufa = (ulv *) aligned;
  1548. + bufb = (ulv *) ((size_t) aligned + halflen);
  1549. +
  1550. + for(loop=1; ((!loops) || loop <= loops); loop++) {
  1551. + printf("Loop %lu", loop);
  1552. + if (loops) {
  1553. + printf("/%lu", loops);
  1554. + }
  1555. + printf(":\n");
  1556. + printf(" %-20s: ", "Stuck Address");
  1557. + fflush(stdout);
  1558. + if (!test_stuck_address(aligned, bufsize / sizeof(ul))) {
  1559. + printf("ok\n");
  1560. + } else {
  1561. + exit_code |= EXIT_FAIL_ADDRESSLINES;
  1562. + }
  1563. + for (i=0;;i++) {
  1564. + if (!tests[i].name) break;
  1565. + /* If using a custom testmask, only run this test if the
  1566. + bit corresponding to this test was set by the user.
  1567. + */
  1568. + if (testmask && (!((1 << i) & testmask))) {
  1569. + continue;
  1570. + }
  1571. + printf(" %-20s: ", tests[i].name);
  1572. + if (!tests[i].fp(bufa, bufb, count)) {
  1573. + printf("ok\n");
  1574. + } else {
  1575. + exit_code |= EXIT_FAIL_OTHERTEST;
  1576. + }
  1577. + fflush(stdout);
  1578. + }
  1579. + printf("\n");
  1580. + fflush(stdout);
  1581. + }
  1582. + if (do_mlock) munlock((void *) aligned, bufsize);
  1583. + printf("Done.\n");
  1584. + fflush(stdout);
  1585. + exit(exit_code);
  1586. +}
  1587. diff --git a/tests/memtester/memtester.h b/tests/memtester/memtester.h
  1588. new file mode 100644
  1589. index 0000000..229bca3
  1590. --- /dev/null
  1591. +++ b/tests/memtester/memtester.h
  1592. @@ -0,0 +1,22 @@
  1593. +/*
  1594. + * Very simple (yet, for some reason, very effective) memory tester.
  1595. + * Originally by Simon Kirby <sim@stormix.com> <sim@neato.org>
  1596. + * Version 2 by Charles Cazabon <charlesc-memtester@pyropus.ca>
  1597. + * Version 3 not publicly released.
  1598. + * Version 4 rewrite:
  1599. + * Copyright (C) 2004-2012 Charles Cazabon <charlesc-memtester@pyropus.ca>
  1600. + * Licensed under the terms of the GNU General Public License version 2 (only).
  1601. + * See the file COPYING for details.
  1602. + *
  1603. + * This file contains the declarations for external variables from the main file.
  1604. + * See other comments in that file.
  1605. + *
  1606. + */
  1607. +
  1608. +#include <sys/types.h>
  1609. +
  1610. +/* extern declarations. */
  1611. +
  1612. +extern int use_phys;
  1613. +extern off_t physaddrbase;
  1614. +
  1615. diff --git a/tests/memtester/sizes.h b/tests/memtester/sizes.h
  1616. new file mode 100644
  1617. index 0000000..cd1c3ad
  1618. --- /dev/null
  1619. +++ b/tests/memtester/sizes.h
  1620. @@ -0,0 +1,38 @@
  1621. +/*
  1622. + * Very simple but very effective user-space memory tester.
  1623. + * Originally by Simon Kirby <sim@stormix.com> <sim@neato.org>
  1624. + * Version 2 by Charles Cazabon <charlesc-memtester@pyropus.ca>
  1625. + * Version 3 not publicly released.
  1626. + * Version 4 rewrite:
  1627. + * Copyright (C) 2004-2012 Charles Cazabon <charlesc-memtester@pyropus.ca>
  1628. + * Licensed under the terms of the GNU General Public License version 2 (only).
  1629. + * See the file COPYING for details.
  1630. + *
  1631. + * This file contains some macro definitions for handling 32/64 bit platforms.
  1632. + *
  1633. + */
  1634. +
  1635. +#include <limits.h>
  1636. +
  1637. +#define rand32() ((unsigned int) rand() | ( (unsigned int) rand() << 16))
  1638. +
  1639. +#if (ULONG_MAX == 4294967295UL)
  1640. + #define rand_ul() rand32()
  1641. + #define UL_ONEBITS 0xffffffff
  1642. + #define UL_LEN 32
  1643. + #define CHECKERBOARD1 0x55555555
  1644. + #define CHECKERBOARD2 0xaaaaaaaa
  1645. + #define UL_BYTE(x) ((x | x << 8 | x << 16 | x << 24))
  1646. +#elif (ULONG_MAX == 18446744073709551615ULL)
  1647. + #define rand64() (((ul) rand32()) << 32 | ((ul) rand32()))
  1648. + #define rand_ul() rand64()
  1649. + #define UL_ONEBITS 0xffffffffffffffffUL
  1650. + #define UL_LEN 64
  1651. + #define CHECKERBOARD1 0x5555555555555555
  1652. + #define CHECKERBOARD2 0xaaaaaaaaaaaaaaaa
  1653. + #define UL_BYTE(x) (((ul)x | (ul)x<<8 | (ul)x<<16 | (ul)x<<24 | (ul)x<<32 | (ul)x<<40 | (ul)x<<48 | (ul)x<<56))
  1654. +#else
  1655. + #error long on this platform is not 32 or 64 bits
  1656. +#endif
  1657. +
  1658. +
  1659. diff --git a/tests/memtester/tests.c b/tests/memtester/tests.c
  1660. new file mode 100644
  1661. index 0000000..be1b350
  1662. --- /dev/null
  1663. +++ b/tests/memtester/tests.c
  1664. @@ -0,0 +1,525 @@
  1665. +/*
  1666. + * Very simple but very effective user-space memory tester.
  1667. + * Originally by Simon Kirby <sim@stormix.com> <sim@neato.org>
  1668. + * Version 2 by Charles Cazabon <charlesc-memtester@pyropus.ca>
  1669. + * Version 3 not publicly released.
  1670. + * Version 4 rewrite:
  1671. + * Copyright (C) 2004-2012 Charles Cazabon <charlesc-memtester@pyropus.ca>
  1672. + * Licensed under the terms of the GNU General Public License version 2 (only).
  1673. + * See the file COPYING for details.
  1674. + *
  1675. + * This file contains the functions for the actual tests, called from the
  1676. + * main routine in memtester.c. See other comments in that file.
  1677. + *
  1678. + */
  1679. +
  1680. +#include <sys/types.h>
  1681. +#include <stdio.h>
  1682. +#include <stdlib.h>
  1683. +#include <limits.h>
  1684. +
  1685. +#include "types.h"
  1686. +#include "sizes.h"
  1687. +#include "memtester.h"
  1688. +
  1689. +char progress[] = "-\\|/";
  1690. +#define PROGRESSLEN 4
  1691. +#define PROGRESSOFTEN 2500
  1692. +#define ONE 0x00000001L
  1693. +
  1694. +/* Function definitions. */
  1695. +
  1696. +int compare_regions(ulv *bufa, ulv *bufb, size_t count) {
  1697. + int r = 0;
  1698. + size_t i;
  1699. + ulv *p1 = bufa;
  1700. + ulv *p2 = bufb;
  1701. + off_t physaddr;
  1702. +
  1703. + for (i = 0; i < count; i++, p1++, p2++) {
  1704. + if (*p1 != *p2) {
  1705. + if (use_phys) {
  1706. + physaddr = physaddrbase + (i * sizeof(ul));
  1707. + fprintf(stderr,
  1708. + "FAILURE: 0x%08lx != 0x%08lx at physical address "
  1709. + "0x%08lx.\n",
  1710. + (ul) *p1, (ul) *p2, physaddr);
  1711. + } else {
  1712. + fprintf(stderr,
  1713. + "FAILURE: 0x%08lx != 0x%08lx at offset 0x%08lx.\n",
  1714. + (ul) *p1, (ul) *p2, (ul) (i * sizeof(ul)));
  1715. + }
  1716. + /* printf("Skipping to next test..."); */
  1717. + r = -1;
  1718. + }
  1719. + }
  1720. + return r;
  1721. +}
  1722. +
  1723. +int test_stuck_address(ulv *bufa, size_t count) {
  1724. + ulv *p1 = bufa;
  1725. + unsigned int j;
  1726. + size_t i;
  1727. + off_t physaddr;
  1728. +
  1729. + printf(" ");
  1730. + fflush(stdout);
  1731. + for (j = 0; j < 16; j++) {
  1732. + printf("\b\b\b\b\b\b\b\b\b\b\b");
  1733. + p1 = (ulv *) bufa;
  1734. + printf("setting %3u", j);
  1735. + fflush(stdout);
  1736. + for (i = 0; i < count; i++) {
  1737. + *p1 = ((j + i) % 2) == 0 ? (ul) p1 : ~((ul) p1);
  1738. + *p1++;
  1739. + }
  1740. + printf("\b\b\b\b\b\b\b\b\b\b\b");
  1741. + printf("testing %3u", j);
  1742. + fflush(stdout);
  1743. + p1 = (ulv *) bufa;
  1744. + for (i = 0; i < count; i++, p1++) {
  1745. + if (*p1 != (((j + i) % 2) == 0 ? (ul) p1 : ~((ul) p1))) {
  1746. + if (use_phys) {
  1747. + physaddr = physaddrbase + (i * sizeof(ul));
  1748. + fprintf(stderr,
  1749. + "FAILURE: possible bad address line at physical "
  1750. + "address 0x%08lx.\n",
  1751. + physaddr);
  1752. + } else {
  1753. + fprintf(stderr,
  1754. + "FAILURE: possible bad address line at offset "
  1755. + "0x%08lx.\n",
  1756. + (ul) (i * sizeof(ul)));
  1757. + }
  1758. + printf("Skipping to next test...\n");
  1759. + fflush(stdout);
  1760. + return -1;
  1761. + }
  1762. + }
  1763. + }
  1764. + printf("\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b");
  1765. + fflush(stdout);
  1766. + return 0;
  1767. +}
  1768. +
  1769. +int test_random_value(ulv *bufa, ulv *bufb, size_t count) {
  1770. + ulv *p1 = bufa;
  1771. + ulv *p2 = bufb;
  1772. + ul j = 0;
  1773. + size_t i;
  1774. +
  1775. + putchar(' ');
  1776. + fflush(stdout);
  1777. + for (i = 0; i < count; i++) {
  1778. + *p1++ = *p2++ = rand_ul();
  1779. + if (!(i % PROGRESSOFTEN)) {
  1780. + putchar('\b');
  1781. + putchar(progress[++j % PROGRESSLEN]);
  1782. + fflush(stdout);
  1783. + }
  1784. + }
  1785. + printf("\b \b");
  1786. + fflush(stdout);
  1787. + return compare_regions(bufa, bufb, count);
  1788. +}
  1789. +
  1790. +int test_xor_comparison(ulv *bufa, ulv *bufb, size_t count) {
  1791. + ulv *p1 = bufa;
  1792. + ulv *p2 = bufb;
  1793. + size_t i;
  1794. + ul q = rand_ul();
  1795. +
  1796. + for (i = 0; i < count; i++) {
  1797. + *p1++ ^= q;
  1798. + *p2++ ^= q;
  1799. + }
  1800. + return compare_regions(bufa, bufb, count);
  1801. +}
  1802. +
  1803. +int test_sub_comparison(ulv *bufa, ulv *bufb, size_t count) {
  1804. + ulv *p1 = bufa;
  1805. + ulv *p2 = bufb;
  1806. + size_t i;
  1807. + ul q = rand_ul();
  1808. +
  1809. + for (i = 0; i < count; i++) {
  1810. + *p1++ -= q;
  1811. + *p2++ -= q;
  1812. + }
  1813. + return compare_regions(bufa, bufb, count);
  1814. +}
  1815. +
  1816. +int test_mul_comparison(ulv *bufa, ulv *bufb, size_t count) {
  1817. + ulv *p1 = bufa;
  1818. + ulv *p2 = bufb;
  1819. + size_t i;
  1820. + ul q = rand_ul();
  1821. +
  1822. + for (i = 0; i < count; i++) {
  1823. + *p1++ *= q;
  1824. + *p2++ *= q;
  1825. + }
  1826. + return compare_regions(bufa, bufb, count);
  1827. +}
  1828. +
  1829. +int test_div_comparison(ulv *bufa, ulv *bufb, size_t count) {
  1830. + ulv *p1 = bufa;
  1831. + ulv *p2 = bufb;
  1832. + size_t i;
  1833. + ul q = rand_ul();
  1834. +
  1835. + for (i = 0; i < count; i++) {
  1836. + if (!q) {
  1837. + q++;
  1838. + }
  1839. + *p1++ /= q;
  1840. + *p2++ /= q;
  1841. + }
  1842. + return compare_regions(bufa, bufb, count);
  1843. +}
  1844. +
  1845. +int test_or_comparison(ulv *bufa, ulv *bufb, size_t count) {
  1846. + ulv *p1 = bufa;
  1847. + ulv *p2 = bufb;
  1848. + size_t i;
  1849. + ul q = rand_ul();
  1850. +
  1851. + for (i = 0; i < count; i++) {
  1852. + *p1++ |= q;
  1853. + *p2++ |= q;
  1854. + }
  1855. + return compare_regions(bufa, bufb, count);
  1856. +}
  1857. +
  1858. +int test_and_comparison(ulv *bufa, ulv *bufb, size_t count) {
  1859. + ulv *p1 = bufa;
  1860. + ulv *p2 = bufb;
  1861. + size_t i;
  1862. + ul q = rand_ul();
  1863. +
  1864. + for (i = 0; i < count; i++) {
  1865. + *p1++ &= q;
  1866. + *p2++ &= q;
  1867. + }
  1868. + return compare_regions(bufa, bufb, count);
  1869. +}
  1870. +
  1871. +int test_seqinc_comparison(ulv *bufa, ulv *bufb, size_t count) {
  1872. + ulv *p1 = bufa;
  1873. + ulv *p2 = bufb;
  1874. + size_t i;
  1875. + ul q = rand_ul();
  1876. +
  1877. + for (i = 0; i < count; i++) {
  1878. + *p1++ = *p2++ = (i + q);
  1879. + }
  1880. + return compare_regions(bufa, bufb, count);
  1881. +}
  1882. +
  1883. +int test_solidbits_comparison(ulv *bufa, ulv *bufb, size_t count) {
  1884. + ulv *p1 = bufa;
  1885. + ulv *p2 = bufb;
  1886. + unsigned int j;
  1887. + ul q;
  1888. + size_t i;
  1889. +
  1890. + printf(" ");
  1891. + fflush(stdout);
  1892. + for (j = 0; j < 64; j++) {
  1893. + printf("\b\b\b\b\b\b\b\b\b\b\b");
  1894. + q = (j % 2) == 0 ? UL_ONEBITS : 0;
  1895. + printf("setting %3u", j);
  1896. + fflush(stdout);
  1897. + p1 = (ulv *) bufa;
  1898. + p2 = (ulv *) bufb;
  1899. + for (i = 0; i < count; i++) {
  1900. + *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
  1901. + }
  1902. + printf("\b\b\b\b\b\b\b\b\b\b\b");
  1903. + printf("testing %3u", j);
  1904. + fflush(stdout);
  1905. + if (compare_regions(bufa, bufb, count)) {
  1906. + return -1;
  1907. + }
  1908. + }
  1909. + printf("\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b");
  1910. + fflush(stdout);
  1911. + return 0;
  1912. +}
  1913. +
  1914. +int test_checkerboard_comparison(ulv *bufa, ulv *bufb, size_t count) {
  1915. + ulv *p1 = bufa;
  1916. + ulv *p2 = bufb;
  1917. + unsigned int j;
  1918. + ul q;
  1919. + size_t i;
  1920. +
  1921. + printf(" ");
  1922. + fflush(stdout);
  1923. + for (j = 0; j < 64; j++) {
  1924. + printf("\b\b\b\b\b\b\b\b\b\b\b");
  1925. + q = (j % 2) == 0 ? CHECKERBOARD1 : CHECKERBOARD2;
  1926. + printf("setting %3u", j);
  1927. + fflush(stdout);
  1928. + p1 = (ulv *) bufa;
  1929. + p2 = (ulv *) bufb;
  1930. + for (i = 0; i < count; i++) {
  1931. + *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
  1932. + }
  1933. + printf("\b\b\b\b\b\b\b\b\b\b\b");
  1934. + printf("testing %3u", j);
  1935. + fflush(stdout);
  1936. + if (compare_regions(bufa, bufb, count)) {
  1937. + return -1;
  1938. + }
  1939. + }
  1940. + printf("\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b");
  1941. + fflush(stdout);
  1942. + return 0;
  1943. +}
  1944. +
  1945. +int test_blockseq_comparison(ulv *bufa, ulv *bufb, size_t count) {
  1946. + ulv *p1 = bufa;
  1947. + ulv *p2 = bufb;
  1948. + unsigned int j;
  1949. + size_t i;
  1950. +
  1951. + printf(" ");
  1952. + fflush(stdout);
  1953. + for (j = 0; j < 256; j++) {
  1954. + printf("\b\b\b\b\b\b\b\b\b\b\b");
  1955. + p1 = (ulv *) bufa;
  1956. + p2 = (ulv *) bufb;
  1957. + printf("setting %3u", j);
  1958. + fflush(stdout);
  1959. + for (i = 0; i < count; i++) {
  1960. + *p1++ = *p2++ = (ul) UL_BYTE(j);
  1961. + }
  1962. + printf("\b\b\b\b\b\b\b\b\b\b\b");
  1963. + printf("testing %3u", j);
  1964. + fflush(stdout);
  1965. + if (compare_regions(bufa, bufb, count)) {
  1966. + return -1;
  1967. + }
  1968. + }
  1969. + printf("\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b");
  1970. + fflush(stdout);
  1971. + return 0;
  1972. +}
  1973. +
  1974. +int test_walkbits0_comparison(ulv *bufa, ulv *bufb, size_t count) {
  1975. + ulv *p1 = bufa;
  1976. + ulv *p2 = bufb;
  1977. + unsigned int j;
  1978. + size_t i;
  1979. +
  1980. + printf(" ");
  1981. + fflush(stdout);
  1982. + for (j = 0; j < UL_LEN * 2; j++) {
  1983. + printf("\b\b\b\b\b\b\b\b\b\b\b");
  1984. + p1 = (ulv *) bufa;
  1985. + p2 = (ulv *) bufb;
  1986. + printf("setting %3u", j);
  1987. + fflush(stdout);
  1988. + for (i = 0; i < count; i++) {
  1989. + if (j < UL_LEN) { /* Walk it up. */
  1990. + *p1++ = *p2++ = ONE << j;
  1991. + } else { /* Walk it back down. */
  1992. + *p1++ = *p2++ = ONE << (UL_LEN * 2 - j - 1);
  1993. + }
  1994. + }
  1995. + printf("\b\b\b\b\b\b\b\b\b\b\b");
  1996. + printf("testing %3u", j);
  1997. + fflush(stdout);
  1998. + if (compare_regions(bufa, bufb, count)) {
  1999. + return -1;
  2000. + }
  2001. + }
  2002. + printf("\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b");
  2003. + fflush(stdout);
  2004. + return 0;
  2005. +}
  2006. +
  2007. +int test_walkbits1_comparison(ulv *bufa, ulv *bufb, size_t count) {
  2008. + ulv *p1 = bufa;
  2009. + ulv *p2 = bufb;
  2010. + unsigned int j;
  2011. + size_t i;
  2012. +
  2013. + printf(" ");
  2014. + fflush(stdout);
  2015. + for (j = 0; j < UL_LEN * 2; j++) {
  2016. + printf("\b\b\b\b\b\b\b\b\b\b\b");
  2017. + p1 = (ulv *) bufa;
  2018. + p2 = (ulv *) bufb;
  2019. + printf("setting %3u", j);
  2020. + fflush(stdout);
  2021. + for (i = 0; i < count; i++) {
  2022. + if (j < UL_LEN) { /* Walk it up. */
  2023. + *p1++ = *p2++ = UL_ONEBITS ^ (ONE << j);
  2024. + } else { /* Walk it back down. */
  2025. + *p1++ = *p2++ = UL_ONEBITS ^ (ONE << (UL_LEN * 2 - j - 1));
  2026. + }
  2027. + }
  2028. + printf("\b\b\b\b\b\b\b\b\b\b\b");
  2029. + printf("testing %3u", j);
  2030. + fflush(stdout);
  2031. + if (compare_regions(bufa, bufb, count)) {
  2032. + return -1;
  2033. + }
  2034. + }
  2035. + printf("\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b");
  2036. + fflush(stdout);
  2037. + return 0;
  2038. +}
  2039. +
  2040. +int test_bitspread_comparison(ulv *bufa, ulv *bufb, size_t count) {
  2041. + ulv *p1 = bufa;
  2042. + ulv *p2 = bufb;
  2043. + unsigned int j;
  2044. + size_t i;
  2045. +
  2046. + printf(" ");
  2047. + fflush(stdout);
  2048. + for (j = 0; j < UL_LEN * 2; j++) {
  2049. + printf("\b\b\b\b\b\b\b\b\b\b\b");
  2050. + p1 = (ulv *) bufa;
  2051. + p2 = (ulv *) bufb;
  2052. + printf("setting %3u", j);
  2053. + fflush(stdout);
  2054. + for (i = 0; i < count; i++) {
  2055. + if (j < UL_LEN) { /* Walk it up. */
  2056. + *p1++ = *p2++ = (i % 2 == 0)
  2057. + ? (ONE << j) | (ONE << (j + 2))
  2058. + : UL_ONEBITS ^ ((ONE << j)
  2059. + | (ONE << (j + 2)));
  2060. + } else { /* Walk it back down. */
  2061. + *p1++ = *p2++ = (i % 2 == 0)
  2062. + ? (ONE << (UL_LEN * 2 - 1 - j)) | (ONE << (UL_LEN * 2 + 1 - j))
  2063. + : UL_ONEBITS ^ (ONE << (UL_LEN * 2 - 1 - j)
  2064. + | (ONE << (UL_LEN * 2 + 1 - j)));
  2065. + }
  2066. + }
  2067. + printf("\b\b\b\b\b\b\b\b\b\b\b");
  2068. + printf("testing %3u", j);
  2069. + fflush(stdout);
  2070. + if (compare_regions(bufa, bufb, count)) {
  2071. + return -1;
  2072. + }
  2073. + }
  2074. + printf("\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b");
  2075. + fflush(stdout);
  2076. + return 0;
  2077. +}
  2078. +
  2079. +int test_bitflip_comparison(ulv *bufa, ulv *bufb, size_t count) {
  2080. + ulv *p1 = bufa;
  2081. + ulv *p2 = bufb;
  2082. + unsigned int j, k;
  2083. + ul q;
  2084. + size_t i;
  2085. +
  2086. + printf(" ");
  2087. + fflush(stdout);
  2088. + for (k = 0; k < UL_LEN; k++) {
  2089. + q = ONE << k;
  2090. + for (j = 0; j < 8; j++) {
  2091. + printf("\b\b\b\b\b\b\b\b\b\b\b");
  2092. + q = ~q;
  2093. + printf("setting %3u", k * 8 + j);
  2094. + fflush(stdout);
  2095. + p1 = (ulv *) bufa;
  2096. + p2 = (ulv *) bufb;
  2097. + for (i = 0; i < count; i++) {
  2098. + *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
  2099. + }
  2100. + printf("\b\b\b\b\b\b\b\b\b\b\b");
  2101. + printf("testing %3u", k * 8 + j);
  2102. + fflush(stdout);
  2103. + if (compare_regions(bufa, bufb, count)) {
  2104. + return -1;
  2105. + }
  2106. + }
  2107. + }
  2108. + printf("\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b");
  2109. + fflush(stdout);
  2110. + return 0;
  2111. +}
  2112. +
  2113. +#ifdef TEST_NARROW_WRITES
  2114. +int test_8bit_wide_random(ulv* bufa, ulv* bufb, size_t count) {
  2115. + u8v *p1, *t;
  2116. + ulv *p2;
  2117. + int attempt;
  2118. + unsigned int b, j = 0;
  2119. + size_t i;
  2120. +
  2121. + putchar(' ');
  2122. + fflush(stdout);
  2123. + for (attempt = 0; attempt < 2; attempt++) {
  2124. + if (attempt & 1) {
  2125. + p1 = (u8v *) bufa;
  2126. + p2 = bufb;
  2127. + } else {
  2128. + p1 = (u8v *) bufb;
  2129. + p2 = bufa;
  2130. + }
  2131. + for (i = 0; i < count; i++) {
  2132. + t = mword8.bytes;
  2133. + *p2++ = mword8.val = rand_ul();
  2134. + for (b=0; b < UL_LEN/8; b++) {
  2135. + *p1++ = *t++;
  2136. + }
  2137. + if (!(i % PROGRESSOFTEN)) {
  2138. + putchar('\b');
  2139. + putchar(progress[++j % PROGRESSLEN]);
  2140. + fflush(stdout);
  2141. + }
  2142. + }
  2143. + if (compare_regions(bufa, bufb, count)) {
  2144. + return -1;
  2145. + }
  2146. + }
  2147. + printf("\b \b");
  2148. + fflush(stdout);
  2149. + return 0;
  2150. +}
  2151. +
  2152. +int test_16bit_wide_random(ulv* bufa, ulv* bufb, size_t count) {
  2153. + u16v *p1, *t;
  2154. + ulv *p2;
  2155. + int attempt;
  2156. + unsigned int b, j = 0;
  2157. + size_t i;
  2158. +
  2159. + putchar( ' ' );
  2160. + fflush( stdout );
  2161. + for (attempt = 0; attempt < 2; attempt++) {
  2162. + if (attempt & 1) {
  2163. + p1 = (u16v *) bufa;
  2164. + p2 = bufb;
  2165. + } else {
  2166. + p1 = (u16v *) bufb;
  2167. + p2 = bufa;
  2168. + }
  2169. + for (i = 0; i < count; i++) {
  2170. + t = mword16.u16s;
  2171. + *p2++ = mword16.val = rand_ul();
  2172. + for (b = 0; b < UL_LEN/16; b++) {
  2173. + *p1++ = *t++;
  2174. + }
  2175. + if (!(i % PROGRESSOFTEN)) {
  2176. + putchar('\b');
  2177. + putchar(progress[++j % PROGRESSLEN]);
  2178. + fflush(stdout);
  2179. + }
  2180. + }
  2181. + if (compare_regions(bufa, bufb, count)) {
  2182. + return -1;
  2183. + }
  2184. + }
  2185. + printf("\b \b");
  2186. + fflush(stdout);
  2187. + return 0;
  2188. +}
  2189. +#endif
  2190. diff --git a/tests/memtester/tests.h b/tests/memtester/tests.h
  2191. new file mode 100644
  2192. index 0000000..eccd47c
  2193. --- /dev/null
  2194. +++ b/tests/memtester/tests.h
  2195. @@ -0,0 +1,39 @@
  2196. +/*
  2197. + * Very simple yet very effective memory tester.
  2198. + * Originally by Simon Kirby <sim@stormix.com> <sim@neato.org>
  2199. + * Version 2 by Charles Cazabon <charlesc-memtester@pyropus.ca>
  2200. + * Version 3 not publicly released.
  2201. + * Version 4 rewrite:
  2202. + * Copyright (C) 2004-2012 Charles Cazabon <charlesc-memtester@pyropus.ca>
  2203. + * Licensed under the terms of the GNU General Public License version 2 (only).
  2204. + * See the file COPYING for details.
  2205. + *
  2206. + * This file contains the declarations for the functions for the actual tests,
  2207. + * called from the main routine in memtester.c. See other comments in that
  2208. + * file.
  2209. + *
  2210. + */
  2211. +
  2212. +/* Function declaration. */
  2213. +
  2214. +int test_stuck_address(unsigned long volatile *bufa, size_t count);
  2215. +int test_random_value(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2216. +int test_xor_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2217. +int test_sub_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2218. +int test_mul_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2219. +int test_div_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2220. +int test_or_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2221. +int test_and_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2222. +int test_seqinc_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2223. +int test_solidbits_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2224. +int test_checkerboard_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2225. +int test_blockseq_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2226. +int test_walkbits0_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2227. +int test_walkbits1_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2228. +int test_bitspread_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2229. +int test_bitflip_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2230. +#ifdef TEST_NARROW_WRITES
  2231. +int test_8bit_wide_random(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2232. +int test_16bit_wide_random(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
  2233. +#endif
  2234. +
  2235. diff --git a/tests/memtester/trycpp.c b/tests/memtester/trycpp.c
  2236. new file mode 100644
  2237. index 0000000..d7d83ad
  2238. --- /dev/null
  2239. +++ b/tests/memtester/trycpp.c
  2240. @@ -0,0 +1,7 @@
  2241. +void main()
  2242. +{
  2243. +#ifdef NeXT
  2244. + printf("nextstep\n"); exit(0);
  2245. +#endif
  2246. + printf("unknown\n"); exit(0);
  2247. +}
  2248. diff --git a/tests/memtester/types.h b/tests/memtester/types.h
  2249. new file mode 100644
  2250. index 0000000..ad7ce73
  2251. --- /dev/null
  2252. +++ b/tests/memtester/types.h
  2253. @@ -0,0 +1,36 @@
  2254. +/*
  2255. + * Very simple but very effective user-space memory tester.
  2256. + * Originally by Simon Kirby <sim@stormix.com> <sim@neato.org>
  2257. + * Version 2 by Charles Cazabon <charlesc-memtester@pyropus.ca>
  2258. + * Version 3 not publicly released.
  2259. + * Version 4 rewrite:
  2260. + * Copyright (C) 2004-2010 Charles Cazabon <charlesc-memtester@pyropus.ca>
  2261. + * Licensed under the terms of the GNU General Public License version 2 (only).
  2262. + * See the file COPYING for details.
  2263. + *
  2264. + * This file contains typedefs, structure, and union definitions.
  2265. + *
  2266. + */
  2267. +
  2268. +#include "sizes.h"
  2269. +
  2270. +typedef unsigned long ul;
  2271. +typedef unsigned long long ull;
  2272. +typedef unsigned long volatile ulv;
  2273. +typedef unsigned char volatile u8v;
  2274. +typedef unsigned short volatile u16v;
  2275. +
  2276. +struct test {
  2277. + char *name;
  2278. + int (*fp)();
  2279. +};
  2280. +
  2281. +union {
  2282. + unsigned char bytes[UL_LEN/8];
  2283. + ul val;
  2284. +} mword8;
  2285. +
  2286. +union {
  2287. + unsigned short u16s[UL_LEN/16];
  2288. + ul val;
  2289. +} mword16;
  2290. diff --git a/tests/memtester/warn-auto.sh b/tests/memtester/warn-auto.sh
  2291. new file mode 100755
  2292. index 0000000..36d2313
  2293. --- /dev/null
  2294. +++ b/tests/memtester/warn-auto.sh
  2295. @@ -0,0 +1,2 @@
  2296. +#!/bin/sh
  2297. +# WARNING: This file was auto-generated. Do not edit!
Add Comment
Please, Sign In to add comment