You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2266 lines
84 KiB

11 months ago
  1. [All code is copyright © 2010-2021 Ceedling Project
  2. by Mike Karlesky, Mark VanderVoord, and Greg Williams.
  3. This Documentation Is Released Under a
  4. Creative Commons 3.0 Attribution Share-Alike License]
  5. What the What?
  6. Assembling build environments for C projects - especially with
  7. automated unit tests - is a pain. Whether it's Make or Rake or Premake
  8. or what-have-you, set up with an all-purpose build environment
  9. tool is tedious and requires considerable glue code to pull together
  10. the necessary tools and libraries. Ceedling allows you to generate
  11. an entire test and build environment for a C project from a single
  12. YAML configuration file. Ceedling is written in Ruby and works
  13. with the Rake build tool plus other goodness like Unity and CMock —
  14. the unit testing and mocking frameworks for C. Ceedling and
  15. its complementary tools can support the tiniest of embedded
  16. processors, the beefiest 64 bit power houses available, and
  17. everything in between.
  18. For a build project including unit tests and using the default
  19. toolchain gcc, the configuration file could be as simple as this:
  20. ```yaml
  21. :project:
  22. :build_root: project/build/
  23. :release_build: TRUE
  24. :paths:
  25. :test:
  26. - tests/**
  27. :source:
  28. - source/**
  29. ```
  30. From the command line, to build the release version of your project,
  31. you would simply run `ceedling release`. To run all your unit tests,
  32. you would run `ceedling test:all`. That's it!
  33. Of course, many more advanced options allow you to configure
  34. your project with a variety of features to meet a variety of needs.
  35. Ceedling can work with practically any command line toolchain
  36. and directory structure – all by way of the configuration file.
  37. Further, because Ceedling piggy backs on Rake, you can add your
  38. own Rake tasks to accomplish project tasks outside of testing
  39. and release builds. A facility for plugins also allows you to
  40. extend Ceedling's capabilities for needs such as custom code
  41. metrics reporting and coverage testing.
  42. What's with this Name?
  43. Glad you asked. Ceedling is tailored for unit tested C projects
  44. and is built upon / around Rake (Rake is a Make replacement implemented
  45. in the Ruby scripting language). So, we've got C, our Rake, and
  46. the fertile soil of a build environment in which to grow and tend
  47. your project and its unit tests. Ta da - _Ceedling_.
  48. What Do You Mean "tailored for unit tested C projects"?
  49. Well, we like to write unit tests for our C code to make it lean and
  50. mean (that whole [Test-Driven Development][tdd]
  51. thing). Along the way, this style of writing C code spawned two
  52. tools to make the job easier: a unit test framework for C called
  53. _Unity_ and a mocking library called _CMock_. And, though it's
  54. not directly related to testing, a C framework for exception
  55. handling called _CException_ also came along.
  56. [tdd]: http://en.wikipedia.org/wiki/Test-driven_development
  57. These tools and frameworks are great, but they require quite
  58. a bit of environment support to pull them all together in a convenient,
  59. usable fashion. We started off with Rakefiles to assemble everything.
  60. These ended up being quite complicated and had to be hand-edited
  61. or created anew for each new project. Ceedling replaces all that
  62. tedium and rework with a configuration file that ties everything
  63. together.
  64. Though Ceedling is tailored for unit testing, it can also go right ahead
  65. and build your final binary release artifact for you as well. Or,
  66. Ceedling and your tests can live alongside your existing release build
  67. setup. That said, Ceedling is more powerful as a unit test build
  68. environment than it is a general purpose release build environment;
  69. complicated projects including separate bootloaders or multiple library
  70. builds, etc. are not its strong suit.
  71. Hold on. Back up. Ruby? Rake? YAML? Unity? CMock? CException?
  72. Seem overwhelming? It's not bad at all, and for the benefits tests
  73. bring us, it's all worth it.
  74. [Ruby][] is a handy scripting
  75. language like Perl or Python. It's a modern, full featured language
  76. that happens to be quite handy for accomplishing tasks like code
  77. generation or automating one's workflow while developing in
  78. a compiled language such as C.
  79. [Ruby]: http://www.ruby-lang.org/en/
  80. [Rake][] is a utility written in Ruby
  81. for accomplishing dependency tracking and task automation
  82. common to building software. It's a modern, more flexible replacement
  83. for [Make][]).
  84. Rakefiles are Ruby files, but they contain build targets similar
  85. in nature to that of Makefiles (but you can also run Ruby code in
  86. your Rakefile).
  87. [Rake]: http://rubyrake.org/
  88. [Make]: http://en.wikipedia.org/wiki/Make_(software)
  89. [YAML][] is a "human friendly data serialization standard for all
  90. programming languages." It's kinda like a markup language, but don't
  91. call it that. With a YAML library, you can [serialize][] data structures
  92. to and from the file system in a textual, human readable form. Ceedling
  93. uses a serialized data structure as its configuration input.
  94. [YAML]: http://en.wikipedia.org/wiki/Yaml
  95. [serialize]: http://en.wikipedia.org/wiki/Serialization
  96. [Unity] is a [unit test framework][test] for C. It provides facilities
  97. for test assertions, executing tests, and collecting / reporting test
  98. results. Unity derives its name from its implementation in a single C
  99. source file (plus two C header files) and from the nature of its
  100. implementation - Unity will build in any C toolchain and is configurable
  101. for even the very minimalist of processors.
  102. [Unity]: http://github.com/ThrowTheSwitch/Unity
  103. [test]: http://en.wikipedia.org/wiki/Unit_testing
  104. [CMock] is a tool written in Ruby able to generate entire
  105. [mock functions][mock] in C code from a given C header file. Mock
  106. functions are invaluable in [interaction-based unit testing][ut].
  107. CMock's generated C code uses Unity.
  108. [CMock]: http://github.com/ThrowTheSwitch/CMock
  109. [mock]: http://en.wikipedia.org/wiki/Mock_object
  110. [ut]: http://martinfowler.com/articles/mocksArentStubs.html
  111. [CException] is a C source and header file that provide a simple
  112. [exception mechanism][exn] for C by way of wrapping up the
  113. [setjmp / longjmp][setjmp] standard library calls. Exceptions are a much
  114. cleaner and preferable alternative to managing and passing error codes
  115. up your return call trace.
  116. [CException]: http://github.com/ThrowTheSwitch/CException
  117. [exn]: http://en.wikipedia.org/wiki/Exception_handling
  118. [setjmp]: http://en.wikipedia.org/wiki/Setjmp.h
  119. Notes
  120. -----
  121. * YAML support is included with Ruby - requires no special installation
  122. or configuration.
  123. * Unity, CMock, and CException are bundled with Ceedling, and
  124. Ceedling is designed to glue them all together for your project
  125. as seamlessly as possible.
  126. Installation & Setup: What Exactly Do I Need to Get Started?
  127. ------------------------------------------------------------
  128. As a [Ruby gem](http://docs.rubygems.org/read/chapter/1):
  129. 1. [Download and install Ruby](http://www.ruby-lang.org/en/downloads/)
  130. 2. Use Ruby's command line gem package manager to install Ceedling:
  131. `gem install ceedling`
  132. (Unity, CMock, and CException come along with Ceedling for free)
  133. 3. Execute Ceedling at command line to create example project
  134. or an empty Ceedling project in your filesystem (executing
  135. `ceedling help` first is, well, helpful).
  136. Gem install notes:
  137. 1. Steps 1-2 are a one time affair for your local environment.
  138. When steps 1-2 are completed once, only step 3 is needed for
  139. each new project.
  140. Getting Started after Ceedling is installed:
  141. 1. Once Ceedling is installed, you'll want to start to integrate it with new
  142. and old projects alike. If you wanted to start to work on a new project
  143. named `foo`, Ceedling can create the skeleton of the project using `ceedling
  144. new foo`. Likewise if you already have a project named `bar` and you want to
  145. integrate Ceedling into it, you would run `ceedling new bar` and Ceedling
  146. will create any files and directories it needs to run.
  147. 2. Now that you have Ceedling integrated with a project, you can start using it.
  148. A good starting point to get use to Ceedling either in a new project or an
  149. existing project is creating a new module to get use to Ceedling by issuing
  150. the command `ceedling module:create[unicorn]`.
  151. General notes:
  152. 1. Certain advanced features of Ceedling rely on gcc and cpp
  153. as preprocessing tools. In most linux systems, these tools
  154. are already available. For Windows environments, we recommend
  155. the [mingw project](http://www.mingw.org/) (Minimalist
  156. GNU for Windows). This represents an optional, additional
  157. setup / installation step to complement the list above. Upon
  158. installing mingw ensure your system path is updated or set
  159. [:environment][:path] in your `project.yml` file (see
  160. environment section later in this document).
  161. 2. To use a project file name other than the default `project.yml`
  162. or place the project file in a directory other than the one
  163. in which you'll run Rake, create an environment variable
  164. `CEEDLING_MAIN_PROJECT_FILE` with your desired project
  165. file path.
  166. 3. To better understand Rake conventions, Rake execution,
  167. and Rakefiles, consult the [Rake tutorial, examples, and
  168. user guide](http://rubyrake.org/).
  169. 4. When using Ceedling in Windows environments, a test file name may
  170. not include the sequences “patch” or “setup”. The Windows Installer
  171. Detection Technology (part of UAC), requires administrator
  172. privileges to execute file names with these strings.
  173. Now What? How Do I Make It GO?
  174. ------------------------------
  175. We're getting a little ahead of ourselves here, but it's good
  176. context on how to drive this bus. Everything is done via the command
  177. line. We'll cover conventions and how to actually configure
  178. your project in later sections.
  179. To run tests, build your release artifact, etc., you will be interacting
  180. with Rake on the command line. Ceedling works with Rake to present
  181. you with named tasks that coordinate the file generation and
  182. build steps needed to accomplish something useful. You can also
  183. add your own independent Rake tasks or create plugins to extend
  184. Ceedling (more on this later).
  185. * `ceedling [no arguments]`:
  186. Run the default Rake task (conveniently recognized by the name default
  187. by Rake). Neither Rake nor Ceedling provide a default task. Rake will
  188. abort if run without arguments when no default task is defined. You can
  189. conveniently define a default task in the Rakefile discussed in the
  190. preceding setup & installation section of this document.
  191. * `ceedling -T`:
  192. List all available Rake tasks with descriptions (Rake tasks without
  193. descriptions are not listed). -T is a command line switch for Rake and
  194. not the same as tasks that follow.
  195. * `ceedling <tasks...> --trace`:
  196. For advanced users troubleshooting a confusing build error, debug
  197. Ceedling or a plugin, --trace provides a stack trace of dependencies
  198. walked during task execution and any Ruby failures along the way. Note
  199. that --trace is a command line switch for Rake and is not the same as
  200. tasks that follow.
  201. * `ceedling environment`:
  202. List all configured environment variable names and string values. This
  203. task is helpful in verifying the evaluation of any Ruby expressions in
  204. the [:environment] section of your config file. *: Note: Ceedling may
  205. set some convenience environment variables by default.*
  206. * `ceedling paths:*`:
  207. List all paths collected from [:paths] entries in your YAML config
  208. file where * is the name of any section contained in [:paths]. This
  209. task is helpful in verifying the expansion of path wildcards / globs
  210. specified in the [:paths] section of your config file.
  211. * `ceedling files:assembly`
  212. * `ceedling files:include`
  213. * `ceedling files:source`
  214. * `ceedling files:support`
  215. * `ceedling files:test`
  216. List all files and file counts collected from the relevant search
  217. paths specified by the [:paths] entries of your YAML config file. The
  218. files:assembly task will only be available if assembly support is
  219. enabled in the [:release_build] section of your configuration file.
  220. * `ceedling options:*`:
  221. Load and merge configuration settings into the main project
  222. configuration. Each task is named after a `*.yml` file found in the
  223. configured options directory. See documentation for the configuration
  224. setting [:project][:options_paths] and for options files in advanced
  225. topics.
  226. * `ceedling test:all`:
  227. Run all unit tests (rebuilding anything that's changed along the way).
  228. * `ceedling test:build_only`:
  229. Build all unit tests, object files and executable but not run them.
  230. * `ceedling test:delta`:
  231. Run only those unit tests for which the source or test files have
  232. changed (i.e. incremental build). Note: with the
  233. [:project][:use_test_preprocessor] configuration file option set,
  234. runner files are always regenerated limiting the total efficiency this
  235. text execution option can afford.
  236. * `ceedling test:*`:
  237. Execute the named test file or the named source file that has an
  238. accompanying test. No path. Examples: ceedling test:foo.c or ceedling
  239. test:test_foo.c
  240. * `ceedling test:pattern[*]`:
  241. Execute any tests whose name and/or path match the regular expression
  242. pattern (case sensitive). Example: ceedling "test:pattern[(I|i)nit]" will
  243. execute all tests named for initialization testing. Note: quotes may
  244. be necessary around the ceedling parameter to distinguish regex characters
  245. from command line operators.
  246. * `ceedling test:path[*]`:
  247. Execute any tests whose path contains the given string (case
  248. sensitive). Example: ceedling test:path[foo/bar] will execute all tests
  249. whose path contains foo/bar. Note: both directory separator characters
  250. / and \ are valid.
  251. * `ceedling release`:
  252. Build all source into a release artifact (if the release build option
  253. is configured).
  254. * `ceedling release:compile:*`:
  255. Sometimes you just need to compile a single file dagnabit. Example:
  256. ceedling release:compile:foo.c
  257. * `ceedling release:assemble:*`:
  258. Sometimes you just need to assemble a single file doggonit. Example:
  259. ceedling release:assemble:foo.s
  260. * `ceedling module:create[Filename]`:
  261. * `ceedling module:create[<Path:>Filename]`:
  262. It's often helpful to create a file automatically. What's better than
  263. that? Creating a source file, a header file, and a corresponding test
  264. file all in one step!
  265. There are also patterns which can be specified to automatically generate
  266. a bunch of files. Try `ceedling module:create[Poodles,mch]` for example!
  267. The module generator has several options you can configure.
  268. F.e. Generating the source/header/test file in a subdirectory (by adding <Path> when calling module:create).
  269. For more info, refer to the [Module Generator](https://github.com/ThrowTheSwitch/Ceedling/blob/master/docs/CeedlingPacket.md#module-generator) section.
  270. * `ceedling module:stub[Filename]`:
  271. * `ceedling module:stub[<Path:>Filename]`:
  272. So what happens if you've created your API in your header (maybe even using
  273. TDD to do so?) and now you need to start to implement the corresponding C
  274. module? Why not get a head start by using `ceedilng module:stub[headername]`
  275. to automatically create a function skeleton for every function declared in
  276. that header? Better yet, you can call this again whenever you add new functions
  277. to that header to add just the new functions, leaving the old ones alone!
  278. * `ceedling logging <tasks...>`:
  279. Enable logging to <build path>/logs. Must come before test and release
  280. tasks to log their steps and output. Log names are a concatenation of
  281. project, user, and option files loaded. User and option files are
  282. documented in the advanced topics section of this document.
  283. * `ceedling verbosity[x] <tasks...>`:
  284. Change the default verbosity level. [x] ranges from 0 (quiet) to 4
  285. (obnoxious). Level [3] is the default. The verbosity task must precede
  286. all tasks in the command line list for which output is desired to be
  287. seen. Verbosity settings are generally most meaningful in conjunction
  288. with test and release tasks.
  289. * `ceedling summary`:
  290. If plugins are enabled, this task will execute the summary method of
  291. any plugins supporting it. This task is intended to provide a quick
  292. roundup of build artifact metrics without re-running any part of the
  293. build.
  294. * `ceedling clean`:
  295. Deletes all toolchain binary artifacts (object files, executables),
  296. test results, and any temporary files. Clean produces no output at the
  297. command line unless verbosity has been set to an appreciable level.
  298. * `ceedling clobber`:
  299. Extends clean task's behavior to also remove generated files: test
  300. runners, mocks, preprocessor output. Clobber produces no output at the
  301. command line unless verbosity has been set to an appreciable level.
  302. * `ceedling options:export`:
  303. This allows you to export a snapshot of your current tool configuration
  304. as a yaml file. You can specify the name of the file in brackets `[blah.yml]`
  305. or let it default to `tools.yml`. In either case, the produced file can be
  306. used as the tool configuration for you project if desired, and modified as you
  307. wish.
  308. To better understand Rake conventions, Rake execution, and
  309. Rakefiles, consult the [Rake tutorial, examples, and user guide][guide].
  310. [guide]: http://rubyrake.org/
  311. At present, none of Ceedling's commands provide persistence.
  312. That is, they must each be specified at the command line each time
  313. they are needed. For instance, Ceedling's verbosity command
  314. only affects output at the time it's run.
  315. Individual test and release file tasks
  316. are not listed in `-T` output. Because so many files may be present
  317. it's unwieldy to list them all.
  318. Multiple rake tasks can be executed at the command line (order
  319. is executed as provided). For example, `ceed
  320. clobber test:all release` will removed all generated files;
  321. build and run all tests; and then build all source - in that order.
  322. If any Rake task fails along the way, execution halts before the
  323. next task.
  324. The `clobber` task removes certain build directories in the
  325. course of deleting generated files. In general, it's best not
  326. to add to source control any Ceedling generated directories
  327. below the root of your top-level build directory. That is, leave
  328. anything Ceedling & its accompanying tools generate out of source
  329. control (but go ahead and add the top-level build directory that
  330. holds all that stuff). Also, since Ceedling is pretty smart about
  331. what it rebuilds and regenerates, you needn't clobber often.
  332. Important Conventions
  333. =====================
  334. Directory Structure, Filenames & Extensions
  335. -------------------------------------------
  336. Much of Ceedling's functionality is driven by collecting files
  337. matching certain patterns inside the paths it's configured
  338. to search. See the documentation for the [:extension] section
  339. of your configuration file (found later in this document) to
  340. configure the file extensions Ceedling uses to match and collect
  341. files. Test file naming is covered later in this section.
  342. Test files and source files must be segregated by directories.
  343. Any directory structure will do. Tests can be held in subdirectories
  344. within source directories, or tests and source directories
  345. can be wholly separated at the top of your project's directory
  346. tree.
  347. Search Path Order
  348. -----------------
  349. When Ceedling searches for files (e.g. looking for header files
  350. to mock) or when it provides search paths to any of the default
  351. gcc toolchain executables, it organizes / prioritizes its search
  352. paths. The order is always: test paths, support paths, source
  353. paths, and then include paths. This can be useful, for instance,
  354. in certain testing scenarios where we desire Ceedling or a compiler
  355. to find a stand-in header file in our support directory before
  356. the actual source header file of the same name.
  357. This convention only holds when Ceedling is using its default
  358. tool configurations and / or when tests are involved. If you define
  359. your own tools in the configuration file (see the [:tools] section
  360. documented later in this here document), you have complete control
  361. over what directories are searched and in what order. Further,
  362. test and support directories are only searched when appropriate.
  363. That is, when running a release build, test and support directories
  364. are not used at all.
  365. Source Files & Binary Release Artifacts
  366. ---------------------------------------
  367. Your binary release artifact results from the compilation and
  368. linking of all source files Ceedling finds in the specified source
  369. directories. At present only source files with a single (configurable)
  370. extension are recognized. That is, `*.c` and `*.cc` files will not
  371. both be recognized - only one or the other. See the configuration
  372. options and defaults in the documentation for the [:extension]
  373. sections of your configuration file (found later in this document).
  374. Test Files & Executable Test Fixtures
  375. -------------------------------------
  376. Ceedling builds each individual test file with its accompanying
  377. source file(s) into a single, monolithic test fixture executable.
  378. Test files are recognized by a naming convention: a (configurable)
  379. prefix such as "`test_`" in the file name with the same file extension
  380. as used by your C source files. See the configuration options
  381. and defaults in the documentation for the [:project] and [:extension]
  382. sections of your configuration file (found later in this document).
  383. Depending on your configuration options, Ceedling can recognize
  384. a variety of test file naming patterns in your test search paths.
  385. For example: `test_some_super_functionality.c`, `TestYourSourceFile.cc`,
  386. or `testing_MyAwesomeCode.C` could each be valid test file
  387. names. Note, however, that Ceedling can recognize only one test
  388. file naming convention per project.
  389. Ceedling knows what files to compile and link into each individual
  390. test executable by way of the #include list contained in each
  391. test file. Any C source files in the configured search directories
  392. that correspond to the header files included in a test file will
  393. be compiled and linked into the resulting test fixture executable.
  394. From this same #include list, Ceedling knows which files to mock
  395. and compile and link into the test executable (if you use mocks
  396. in your tests). That was a lot of clauses and information in a very
  397. few sentences; the example that follows in a bit will make it clearer.
  398. By naming your test functions according to convention, Ceedling
  399. will extract and collect into a runner C file calls to all your
  400. test case functions. This runner file handles all the execution
  401. minutiae so that your test file can be quite simple and so that
  402. you never forget to wire up a test function to be executed. In this
  403. generated runner lives the `main()` entry point for the resulting
  404. test executable. There are no configuration options for the
  405. naming convention of your test case functions. A test case function
  406. signature must have these three elements: void return, void
  407. parameter list, and the function name prepended with lowercase
  408. "`test`". In other words, a test function signature should look
  409. like this: `void test``[any name you like]``(void)`.
  410. A commented sample test file follows on the next page. Also, see
  411. the sample project contained in the Ceedling documentation
  412. bundle.
  413. ```c
  414. // test_foo.c -----------------------------------------------
  415. #include "unity.h" // compile/link in Unity test framework
  416. #include "types.h" // header file with no *.c file -- no compilation/linking
  417. #include "foo.h" // source file foo.c under test
  418. #include "mock_bar.h" // bar.h will be found and mocked as mock_bar.c + compiled/linked in;
  419. // foo.c includes bar.h and uses functions declared in it
  420. #include "mock_baz.h" // baz.h will be found and mocked as mock_baz.c + compiled/linked in
  421. // foo.c includes baz.h and uses functions declared in it
  422. void setUp(void) {} // every test file requires this function;
  423. // setUp() is called by the generated runner before each test case function
  424. void tearDown(void) {} // every test file requires this function;
  425. // tearDown() is called by the generated runner after each test case function
  426. // a test case function
  427. void test_Foo_Function1_should_Call_Bar_AndGrill(void)
  428. {
  429. Bar_AndGrill_Expect(); // setup function from mock_bar.c that instructs our
  430. // framework to expect Bar_AndGrill() to be called once
  431. TEST_ASSERT_EQUAL(0xFF, Foo_Function1()); // assertion provided by Unity
  432. // Foo_Function1() calls Bar_AndGrill() & returns a byte
  433. }
  434. // another test case function
  435. void test_Foo_Function2_should_Call_Baz_Tec(void)
  436. {
  437. Baz_Tec_ExpectAnd_Return(1); // setup function provided by mock_baz.c that instructs our
  438. // framework to expect Baz_Tec() to be called once and return 1
  439. TEST_ASSERT_TRUE(Foo_Function2()); // assertion provided by Unity
  440. }
  441. // end of test_foo.c ----------------------------------------
  442. ```
  443. From the test file specified above Ceedling will generate `test_foo_runner.c`;
  444. this runner file will contain `main()` and call both of the example
  445. test case functions.
  446. The final test executable will be `test_foo.exe` (for Windows
  447. machines or `test_foo.out` for linux systems - depending on default
  448. or configured file extensions). Based on the #include list above,
  449. the test executable will be the output of the linker having processed
  450. `unity.o`, `foo.o`, `mock_bar.o`, `mock_baz.o`, `test_foo.o`,
  451. and `test_foo_runner.o`. Ceedling finds the files, generates
  452. mocks, generates a runner, compiles all the files, and links
  453. everything into the test executable. Ceedling will then run
  454. the test executable and collect test results from it to be reported
  455. to the developer at the command line.
  456. For more on the assertions and mocks shown, consult the documentation
  457. for Unity and CMock.
  458. The Magic of Dependency Tracking
  459. --------------------------------
  460. Ceedling is pretty smart in using Rake to build up your project's
  461. dependencies. This means that Ceedling automagically rebuilds
  462. all the appropriate files in your project when necessary: when
  463. your configuration changes, Ceedling or any of the other tools
  464. are updated, or your source or test files change. For instance,
  465. if you modify a header file that is mocked, Ceedling will ensure
  466. that the mock is regenerated and all tests that use that mock are
  467. rebuilt and re-run when you initiate a relevant testing task.
  468. When you see things rebuilding, it's for a good reason. Ceedling
  469. attempts to regenerate and rebuild only what's needed for a given
  470. execution of a task. In the case of large projects, assembling
  471. dependencies and acting upon them can cause some delay in executing
  472. tasks.
  473. With one exception, the trigger to rebuild or regenerate a file
  474. is always a disparity in timestamps between a target file and
  475. its source - if an input file is newer than its target dependency,
  476. the target is rebuilt or regenerated. For example, if the C source
  477. file from which an object file is compiled is newer than that object
  478. file on disk, recompilation will occur (of course, if no object
  479. file exists on disk, compilation will always occur). The one
  480. exception to this dependency behavior is specific to your input
  481. configuration. Only if your logical configuration changes
  482. will a system-wide rebuild occur. Reorganizing your input configuration
  483. or otherwise updating its file timestamp without modifying
  484. the values within the file will not trigger a rebuild. This behavior
  485. handles the various ways in which your input configuration can
  486. change (discussed later in this document) without having changed
  487. your actual project YAML file.
  488. Ceedling needs a bit of help to accomplish its magic with deep
  489. dependencies. Shallow dependencies are straightforward:
  490. a mock is dependent on the header file from which it's generated,
  491. a test file is dependent upon the source files it includes (see
  492. the preceding conventions section), etc. Ceedling handles
  493. these "out of the box." Deep dependencies are specifically a
  494. C-related phenomenon and occur as a consequence of include statements
  495. within C source files. Say a source file includes a header file
  496. and that header file in turn includes another header file which
  497. includes still another header file. A change to the deepest header
  498. file should trigger a recompilation of the source file, a relinking
  499. of all the object files comprising a test fixture, and a new execution
  500. of that test fixture.
  501. Ceedling can handle deep dependencies but only with the help
  502. of a C preprocessor. Ceedling is quite capable, but a full C preprocessor
  503. it ain't. Your project can be configured to use a C preprocessor
  504. or not. Simple projects or large projects constructed so as to
  505. be quite flat in their include structure generally don't need
  506. deep dependency preprocessing - and can enjoy the benefits of
  507. faster execution. Legacy code, on the other hand, will almost
  508. always want to be tested with deep preprocessing enabled. Set
  509. up of the C preprocessor is covered in the documentation for the
  510. [:project] and [:tools] section of the configuration file (later
  511. in this document). Ceedling contains all the configuration
  512. necessary to use the gcc preprocessor by default. That is, as
  513. long as gcc is in your system search path, deep preprocessing
  514. of deep dependencies is available to you by simply enabling it
  515. in your project configuration file.
  516. Ceedling's Build Output
  517. -----------------------
  518. Ceedling requires a top-level build directory for all the stuff
  519. that it, the accompanying test tools, and your toolchain generate.
  520. That build directory's location is configured in the [:project]
  521. section of your configuration file (discussed later). There
  522. can be a ton of generated files. By and large, you can live a full
  523. and meaningful life knowing absolutely nothing at all about
  524. the files and directories generated below the root build directory.
  525. As noted already, it's good practice to add your top-level build
  526. directory to source control but nothing generated beneath it.
  527. You'll spare yourself headache if you let Ceedling delete and
  528. regenerate files and directories in a non-versioned corner
  529. of your project's filesystem beneath the top-level build directory.
  530. The `artifacts` directory is the one and only directory you may
  531. want to know about beneath the top-level build directory. The
  532. subdirectories beneath `artifacts` will hold your binary release
  533. target output (if your project is configured for release builds)
  534. and will serve as the conventional location for plugin output.
  535. This directory structure was chosen specifically because it
  536. tends to work nicely with Continuous Integration setups that
  537. recognize and list build artifacts for retrieval / download.
  538. The Almighty Project Configuration File (in Glorious YAML)
  539. ----------------------------------------------------------
  540. Please consult YAML documentation for the finer points of format
  541. and to understand details of our YAML-based configuration file.
  542. We recommend [Wikipedia's entry on YAML](http://en.wikipedia.org/wiki/Yaml)
  543. for this. A few highlights from that reference page:
  544. * YAML streams are encoded using the set of printable Unicode
  545. characters, either in UTF-8 or UTF-16
  546. * Whitespace indentation is used to denote structure; however
  547. tab characters are never allowed as indentation
  548. * Comments begin with the number sign ( # ), can start anywhere
  549. on a line, and continue until the end of the line unless enclosed
  550. by quotes
  551. * List members are denoted by a leading hyphen ( - ) with one member
  552. per line, or enclosed in square brackets ( [ ] ) and separated
  553. by comma space ( , )
  554. * Hashes are represented using the colon space ( : ) in the form
  555. key: value, either one per line or enclosed in curly braces
  556. ( { } ) and separated by comma space ( , )
  557. * Strings (scalars) are ordinarily unquoted, but may be enclosed
  558. in double-quotes ( " ), or single-quotes ( ' )
  559. * YAML requires that colons and commas used as list separators
  560. be followed by a space so that scalar values containing embedded
  561. punctuation can generally be represented without needing
  562. to be enclosed in quotes
  563. * Repeated nodes are initially denoted by an ampersand ( & ) and
  564. thereafter referenced with an asterisk ( * )
  565. Notes on what follows:
  566. * Each of the following sections represent top-level entries
  567. in the YAML configuration file.
  568. * Unless explicitly specified in the configuration file, default
  569. values are used by Ceedling.
  570. * These three settings, at minimum, must be specified:
  571. * [:project][:build_root]
  572. * [:paths][:source]
  573. * [:paths][:test]
  574. * As much as is possible, Ceedling validates your settings in
  575. properly formed YAML.
  576. * Improperly formed YAML will cause a Ruby error when the YAML
  577. is parsed. This is usually accompanied by a complaint with
  578. line and column number pointing into the project file.
  579. * Certain advanced features rely on gcc and cpp as preprocessing
  580. tools. In most linux systems, these tools are already available.
  581. For Windows environments, we recommend the [mingw project](http://www.mingw.org/)
  582. (Minimalist GNU for Windows).
  583. * Ceedling is primarily meant as a build tool to support automated
  584. unit testing. All the heavy lifting is involved there. Creating
  585. a simple binary release build artifact is quite trivial in
  586. comparison. Consequently, most default options and the construction
  587. of Ceedling itself is skewed towards supporting testing though
  588. Ceedling can, of course, build your binary release artifact
  589. as well. Note that complex binary release artifacts (e.g.
  590. application + bootloader or multiple libraries) are beyond
  591. Ceedling's release build ability.
  592. Conventions / features of Ceedling-specific YAML:
  593. * Any second tier setting keys anywhere in YAML whose names end
  594. in `_path` or `_paths` are automagically processed like all
  595. Ceedling-specific paths in the YAML to have consistent directory
  596. separators (i.e. "/") and to take advantage of inline Ruby
  597. string expansion (see [:environment] setting below for further
  598. explanation of string expansion).
  599. **Let's Be Careful Out There:** Ceedling performs validation
  600. on the values you set in your configuration file (this assumes
  601. your YAML is correct and will not fail format parsing, of course).
  602. That said, validation is limited to only those settings Ceedling
  603. uses and those that can be reasonably validated. Ceedling does
  604. not limit what can exist within your configuration file. In this
  605. way, you can take full advantage of YAML as well as add sections
  606. and values for use in your own custom plugins (documented later).
  607. The consequence of this is simple but important. A misspelled
  608. configuration section name or value name is unlikely to cause
  609. Ceedling any trouble. Ceedling will happily process that section
  610. or value and simply use the properly spelled default maintained
  611. internally - thus leading to unexpected behavior without warning.
  612. project: global project settings
  613. * `build_root`:
  614. Top level directory into which generated path structure and files are
  615. placed. Note: this is one of the handful of configuration values that
  616. must be set. The specified path can be absolute or relative to your
  617. working directory.
  618. **Default**: (none)
  619. * `use_exceptions`:
  620. Configures the build environment to make use of CException. Note that
  621. if you do not use exceptions, there's no harm in leaving this as its
  622. default value.
  623. **Default**: TRUE
  624. * `use_mocks`:
  625. Configures the build environment to make use of CMock. Note that if
  626. you do not use mocks, there's no harm in leaving this setting as its
  627. default value.
  628. **Default**: TRUE
  629. * `use_test_preprocessor`:
  630. This option allows Ceedling to work with test files that contain
  631. conditional compilation statements (e.g. #ifdef) and header files you
  632. wish to mock that contain conditional preprocessor statements and/or
  633. macros.
  634. Ceedling and CMock are advanced tools with sophisticated parsers.
  635. However, they do not include entire C language preprocessors.
  636. Consequently, with this option enabled, Ceedling will use gcc's
  637. preprocessing mode and the cpp preprocessor tool to strip down /
  638. expand test files and headers to their applicable content which can
  639. then be processed by Ceedling and CMock.
  640. With this option enabled, the gcc & cpp tools must exist in an
  641. accessible system search path and test runner files are always
  642. regenerated.
  643. **Default**: FALSE
  644. * `use_preprocessor_directives`:
  645. After standard preprocessing when `use_test_preprocessor` is used
  646. macros are fully expanded to C code. Some features, for example
  647. TEST_CASE() or TEST_RANGE() from Unity require not-fully preprocessed
  648. file to be detected by Ceedling. To do this gcc directives-only
  649. option is used to expand only conditional compilation statements,
  650. handle directives, but do not expand macros preprocessor and leave
  651. the other content of file untouched.
  652. With this option enabled, `use_test_preprocessor` must be also enabled
  653. and gcc must exist in an accessible system search path. For other
  654. compilers behavior can be changed by `test_file_preprocessor_directives`
  655. compiler tool.
  656. **Default**: FALSE
  657. * `use_deep_dependencies`:
  658. The base rules and tasks that Ceedling creates using Rake capture most
  659. of the dependencies within a standard project (e.g. when the source
  660. file accompanying a test file changes, the corresponding test fixture
  661. executable will be rebuilt when tests are re-run). However, deep
  662. dependencies cannot be captured this way. If a typedef or macro
  663. changes in a header file three levels of #include statements deep,
  664. this option allows the appropriate incremental build actions to occur
  665. for both test execution and release builds.
  666. This is accomplished by using the dependencies discovery mode of gcc.
  667. With this option enabled, gcc must exist in an accessible system
  668. search path.
  669. **Default**: FALSE
  670. * `generate_deep_dependencies`:
  671. When `use_deep_dependencies` is set to TRUE, Ceedling will run a separate
  672. build step to generate the deep dependencies. If you are using gcc as your
  673. primary compiler, or another compiler that can generate makefile rules as
  674. a side effect of compilation, then you can set this to FALSE to avoid the
  675. extra build step but still use the deep dependencies data when deciding
  676. which source files to rebuild.
  677. **Default**: TRUE
  678. * `test_file_prefix`:
  679. Ceedling collects test files by convention from within the test file
  680. search paths. The convention includes a unique name prefix and a file
  681. extension matching that of source files.
  682. Why not simply recognize all files in test directories as test files?
  683. By using the given convention, we have greater flexibility in what we
  684. do with C files in the test directories.
  685. **Default**: "test_"
  686. * `options_paths`:
  687. Just as you may have various build configurations for your source
  688. codebase, you may need variations of your project configuration.
  689. By specifying options paths, Ceedling will search for other project
  690. YAML files, make command line tasks available (ceedling options:variation
  691. for a variation.yml file), and merge the project configuration of
  692. these option files in with the main project file at runtime. See
  693. advanced topics.
  694. Note these Rake tasks at the command line - like verbosity or logging
  695. control - must come before the test or release task they are meant to
  696. modify.
  697. **Default**: `[]` (empty)
  698. * `release_build`:
  699. When enabled, a release Rake task is exposed. This configuration
  700. option requires a corresponding release compiler and linker to be
  701. defined (gcc is used as the default).
  702. More release configuration options are available in the release_build
  703. section.
  704. **Default**: FALSE
  705. Example `[:project]` YAML blurb
  706. ```yaml
  707. :project:
  708. :build_root: project_awesome/build
  709. :use_exceptions: FALSE
  710. :use_test_preprocessor: TRUE
  711. :use_deep_dependencies: TRUE
  712. :options_paths:
  713. - project/options
  714. - external/shared/options
  715. :release_build: TRUE
  716. ```
  717. Ceedling is primarily concerned with facilitating the somewhat
  718. complicated mechanics of automating unit tests. The same mechanisms
  719. are easily capable of building a final release binary artifact
  720. (i.e. non test code; the thing that is your final working software
  721. that you execute on target hardware).
  722. * `output`:
  723. The name of your release build binary artifact to be found in <build
  724. path>/artifacts/release. Ceedling sets the default artifact file
  725. extension to that as is explicitly specified in the [:extension]
  726. section or as is system specific otherwise.
  727. **Default**: `project.exe` or `project.out`
  728. * `use_assembly`:
  729. If assembly code is present in the source tree, this option causes
  730. Ceedling to create appropriate build directories and use an assembler
  731. tool (default is the GNU tool as - override available in the [:tools]
  732. section.
  733. **Default**: FALSE
  734. * `artifacts`:
  735. By default, Ceedling copies to the <build path>/artifacts/release
  736. directory the output of the release linker and (optionally) a map
  737. file. Many toolchains produce other important output files as well.
  738. Adding a file path to this list will cause Ceedling to copy that file
  739. to the artifacts directory. The artifacts directory is helpful for
  740. organizing important build output files and provides a central place
  741. for tools such as Continuous Integration servers to point to build
  742. output. Selectively copying files prevents incidental build cruft from
  743. needlessly appearing in the artifacts directory. Note that inline Ruby
  744. string replacement is available in the artifacts paths (see discussion
  745. in the [:environment] section).
  746. **Default**: `[]` (empty)
  747. Example `[:release_build]` YAML blurb
  748. ```yaml
  749. :release_build:
  750. :output: top_secret.bin
  751. :use_assembly: TRUE
  752. :artifacts:
  753. - build/release/out/c/top_secret.s19
  754. ```
  755. **paths**: options controlling search paths for source and header
  756. (and assembly) files
  757. * `test`:
  758. All C files containing unit test code. Note: this is one of the
  759. handful of configuration values that must be set.
  760. **Default**: `[]` (empty)
  761. * `source`:
  762. All C files containing release code (code to be tested). Note: this is
  763. one of the handful of configuration values that must be set.
  764. **Default**: `[]` (empty)
  765. * `support`:
  766. Any C files you might need to aid your unit testing. For example, on
  767. occasion, you may need to create a header file containing a subset of
  768. function signatures matching those elsewhere in your code (e.g. a
  769. subset of your OS functions, a portion of a library API, etc.). Why?
  770. To provide finer grained control over mock function substitution or
  771. limiting the size of the generated mocks.
  772. **Default**: `[]` (empty)
  773. * `include`:
  774. Any header files not already in the source search path. Note there's
  775. no practical distinction between this search path and the source
  776. search path; it's merely to provide options or to support any
  777. peculiar source tree organization.
  778. **Default**: `[]` (empty)
  779. * `test_toolchain_include`:
  780. System header files needed by the test toolchain - should your
  781. compiler be unable to find them, finds the wrong system include search
  782. path, or you need a creative solution to a tricky technical problem.
  783. Note that if you configure your own toolchain in the [:tools] section,
  784. this search path is largely meaningless to you. However, this is a
  785. convenient way to control the system include path should you rely on
  786. the default gcc tools.
  787. **Default**: `[]` (empty)
  788. * `release_toolchain_include`:
  789. Same as preceding albeit related to the release toolchain.
  790. **Default**: `[]` (empty)
  791. * `<custom>`
  792. Any paths you specify for custom list. List is available to tool
  793. configurations and/or plugins. Note a distinction. The preceding names
  794. are recognized internally to Ceedling and the path lists are used to
  795. build collections of files contained in those paths. A custom list is
  796. just that - a custom list of paths.
  797. Notes on path grammar within the [:paths] section:
  798. * Order of search paths listed in [:paths] is preserved when used by an
  799. entry in the [:tools] section
  800. * Wherever multiple path lists are combined for use Ceedling prioritizes
  801. path groups as follows:
  802. test paths, support paths, source paths, include paths.
  803. This can be useful, for instance, in certain testing scenarios where
  804. we desire Ceedling or the compiler to find a stand-in header file before
  805. the actual source header file of the same name.
  806. * Paths:
  807. 1. can be absolute or relative
  808. 2. can be singly explicit - a single fully specified path
  809. 3. can include a glob operator (more on this below)
  810. 4. can use inline Ruby string replacement (see [:environment]
  811. section for more)
  812. 5. default as an addition to a specific search list (more on this
  813. in the examples)
  814. 6. can act to subtract from a glob included in the path list (more
  815. on this in the examples)
  816. [Globs](http://ruby.about.com/od/beginningruby/a/dir2.htm)
  817. as used by Ceedling are wildcards for specifying directories
  818. without the need to list each and every required search path.
  819. Ceedling globs operate just as Ruby globs except that they are
  820. limited to matching directories and not files. Glob operators
  821. include the following * ** ? [-] {,} (note: this list is space separated
  822. and not comma separated as commas are used within the bracket
  823. operators).
  824. * `*`:
  825. All subdirectories of depth 1 below the parent path and including the
  826. parent path
  827. * `**`:
  828. All subdirectories recursively discovered below the parent path and
  829. including the parent path
  830. * `?`:
  831. Single alphanumeric character wildcard
  832. * `[x-y]`:
  833. Single alphanumeric character as found in the specified range
  834. * `{x,y}`:
  835. Single alphanumeric character from the specified list
  836. Example [:paths] YAML blurbs
  837. ```yaml
  838. :paths:
  839. :source: #together the following comprise all source search paths
  840. - project/source/* #expansion yields all subdirectories of depth 1 plus parent directory
  841. - project/lib #single path
  842. :test: #all test search paths
  843. - project/**/test? #expansion yields any subdirectory found anywhere in the project that
  844. #begins with "test" and contains 5 characters
  845. :paths:
  846. :source: #all source search paths
  847. - +:project/source/** #all subdirectories recursively discovered plus parent directory
  848. - -:project/source/os/generated #subtract os/generated directory from expansion of above glob
  849. #note that '+:' notation is merely aesthetic; default is to add
  850. :test: #all test search paths
  851. - project/test/bootloader #explicit, single search paths (searched in the order specified)
  852. - project/test/application
  853. - project/test/utilities
  854. :custom: #custom path list
  855. - "#{PROJECT_ROOT}/other" #inline Ruby string expansion
  856. ```
  857. Globs and inline Ruby string expansion can require trial and
  858. error to arrive at your intended results. Use the `ceedling paths:*`
  859. command line options (documented in preceding section) to verify
  860. your settings.
  861. Ceedling relies on file collections automagically assembled
  862. from paths, globs, and file extensions. File collections greatly
  863. simplify project set up. However, sometimes you need to remove
  864. from or add individual files to those collections.
  865. * `test`:
  866. Modify the collection of unit test C files.
  867. **Default**: `[]` (empty)
  868. * `source`:
  869. Modify the collection of all source files used in unit test builds and release builds.
  870. **Default**: `[]` (empty)
  871. * `assembly`:
  872. Modify the (optional) collection of assembly files used in release builds.
  873. **Default**: `[]` (empty)
  874. * `include`:
  875. Modify the collection of all source header files used in unit test builds (e.g. for mocking) and release builds.
  876. **Default**: `[]` (empty)
  877. * `support`:
  878. Modify the collection of supporting C files available to unit tests builds.
  879. **Default**: `[]` (empty)
  880. * `libraries`:
  881. Add a collection of library paths to be included when linking.
  882. **Default**: `[]` (empty)
  883. Note: All path grammar documented in [:paths] section applies
  884. to [:files] path entries - albeit at the file path level and not
  885. the directory level.
  886. Example [:files] YAML blurb
  887. ```yaml
  888. :files:
  889. :source:
  890. - callbacks/comm.c # entry defaults to file addition
  891. - +:callbacks/comm*.c # add all comm files matching glob pattern
  892. - -:source/board/atm134.c # not our board
  893. :test:
  894. - -:test/io/test_output_manager.c # remove unit tests from test build
  895. ```
  896. **environment:** inserts environment variables into the shell
  897. instance executing configured tools
  898. Ceedling creates environment variables from any key / value
  899. pairs in the environment section. Keys become an environment
  900. variable name in uppercase. The values are strings assigned
  901. to those environment variables. These value strings are either
  902. simple string values in YAML or the concatenation of a YAML array.
  903. Ceedling is able to execute inline Ruby string substitution
  904. code to set environment variables. This evaluation occurs when
  905. the project file is first processed for any environment pair's
  906. value string including the Ruby string substitution pattern
  907. `#{…}`. Note that environment value strings that _begin_ with
  908. this pattern should always be enclosed in quotes. YAML defaults
  909. to processing unquoted text as a string; quoting text is optional.
  910. If an environment pair's value string begins with the Ruby string
  911. substitution pattern, YAML will interpret the string as a Ruby
  912. comment (because of the `#`). Enclosing each environment value
  913. string in quotes is a safe practice.
  914. [:environment] entries are processed in the configured order
  915. (later entries can reference earlier entries).
  916. Special case: PATH handling
  917. In the specific case of specifying an environment key named _path_,
  918. an array of string values will be concatenated with the appropriate
  919. platform-specific path separation character (e.g. ':' on linux,
  920. ';' on Windows). All other instances of environment keys assigned
  921. YAML arrays use simple concatenation.
  922. Example [:environment] YAML blurb
  923. ```yaml
  924. :environment:
  925. - :license_server: gizmo.intranet #LICENSE_SERVER set with value "gizmo.intranet"
  926. - :license: "#{`license.exe`}" #LICENSE set to string generated from shelling out to
  927. #execute license.exe; note use of enclosing quotes
  928. - :path: #concatenated with path separator (see special case above)
  929. - Tools/gizmo/bin #prepend existing PATH with gizmo path
  930. - "#{ENV['PATH']}" #pattern #{…} triggers ruby evaluation string substitution
  931. #note: value string must be quoted because of '#'
  932. - :logfile: system/logs/thingamabob.log #LOGFILE set with path for a log file
  933. ```
  934. **extension**: configure file name extensions used to collect lists of files searched in [:paths]
  935. * `header`:
  936. C header files
  937. **Default**: .h
  938. * `source`:
  939. C code files (whether source or test files)
  940. **Default**: .c
  941. * `assembly`:
  942. Assembly files (contents wholly assembly instructions)
  943. **Default**: .s
  944. * `object`:
  945. Resulting binary output of C code compiler (and assembler)
  946. **Default**: .o
  947. * `executable`:
  948. Binary executable to be loaded and executed upon target hardware
  949. **Default**: .exe or .out (Win or linux)
  950. * `testpass`:
  951. Test results file (not likely to ever need a new value)
  952. **Default**: .pass
  953. * `testfail`:
  954. Test results file (not likely to ever need a new value)
  955. **Default**: .fail
  956. * `dependencies`:
  957. File containing make-style dependency rules created by gcc preprocessor
  958. **Default**: .d
  959. Example [:extension] YAML blurb
  960. :extension:
  961. :source: .cc
  962. :executable: .bin
  963. **defines**: command line defines used in test and release compilation by configured tools
  964. * `test`:
  965. Defines needed for testing. Useful for:
  966. 1. test files containing conditional compilation statements (i.e.
  967. tests active in only certain contexts)
  968. 2. testing legacy source wherein the isolation of source under test
  969. afforded by Ceedling and its complementary tools leaves certain
  970. symbols unset when source files are compiled in isolation
  971. **Default**: `[]` (empty)
  972. * `test_preprocess`:
  973. If [:project][:use_test_preprocessor] or
  974. [:project][:use_deep_dependencies] is set and code is structured in a
  975. certain way, the gcc preprocessor may need symbol definitions to
  976. properly preprocess files to extract function signatures for mocking
  977. and extract deep dependencies for incremental builds.
  978. **Default**: `[]` (empty)
  979. * `<test_name>`:
  980. Replace standard `test` definitions for specified `<test_name>`definitions. For example:
  981. ```yaml
  982. :defines:
  983. :test:
  984. - FOO_STANDARD_CONFIG
  985. :test_foo_config:
  986. - FOO_SPECIFIC_CONFIG
  987. ```
  988. `ceedling test:foo_config` will now have `FOO_SPECIFIC_CONFIG` defined instead of
  989. `FOO_STANDARD_CONFIG`. None of the other tests will have `FOO_SPECIFIC_SPECIFIC`.
  990. **Default**: `[]` (empty)
  991. * `release`:
  992. Defines needed for the release build binary artifact.
  993. **Default**: `[]` (empty)
  994. * `release_preprocess`:
  995. If [:project][:use_deep_dependencies] is set and code is structured in
  996. a certain way, the gcc preprocessor may need symbol definitions to
  997. properly preprocess files for incremental release builds due to deep
  998. dependencies.
  999. **Default**: `[]` (empty)
  1000. * `use_test_definition`:
  1001. When this option is used the `-D<test_name>` flag is added to the build option.
  1002. **Default**: FALSE
  1003. Example [:defines] YAML blurb
  1004. ```yaml
  1005. :defines:
  1006. :test:
  1007. - UNIT_TESTING #for select cases in source to allow testing with a changed behavior or interface
  1008. - OFF=0
  1009. - ON=1
  1010. - FEATURE_X=ON
  1011. :source:
  1012. - FEATURE_X=ON
  1013. ```
  1014. **libraries**: command line defines used in test and release compilation by configured tools
  1015. Ceedling allows you to pull in specific libraries for the purpose of release and test builds.
  1016. It has a few levels of support for this. Start by adding a :libraries main section in your
  1017. configuration. In this section, you can optionally have the following subsections:
  1018. * `test`:
  1019. Library files that should be injected into your tests when linking occurs.
  1020. These can be specified as either relative or absolute paths. These files MUST
  1021. exist when the test attempts to build.
  1022. * `release`:
  1023. Library files that should be injected into your release when linking occurs. These
  1024. can be specified as either relative or absolute paths. These files MUST exist when
  1025. the release attempts to build UNLESS you are using the subprojects plugin. In that
  1026. case, it will attempt to build that library for you as a dynamic dependency.
  1027. * `system`:
  1028. These libraries are assumed to be in the tool path somewhere and shouldn't need to be
  1029. specified. The libraries added here will be injected into releases and tests. For example
  1030. if you specify `-lm` you can include the math library. The `-l` portion is only necessary
  1031. if the `:flag` prefix below doesn't specify it already for you other libraries.
  1032. * `flag`:
  1033. This is the method of adding an argument for each library. For example, gcc really likes
  1034. it when you specify “-l${1}”
  1035. * `path_flag`:
  1036. This is the method of adding an path argument for each library path. For example, gcc really
  1037. likes it when you specify “-L \"${1}\"”
  1038. Notes:
  1039. * If you've specified your own link step, you are going to want to add ${4} to your argument
  1040. list in the place where library files should be added to the command call. For gcc, this is
  1041. often the very end. Other tools may vary.
  1042. **flags**: configure per-file compilation and linking flags
  1043. Ceedling tools (see later [:tools] section) are used to configure
  1044. compilation and linking of test and source files. These tool
  1045. configurations are a one-size-fits-all approach. Should individual files
  1046. require special compilation or linking flags, the settings in the
  1047. [:flags] section work in conjunction with tool definitions by way of
  1048. argument substitution to achieve this.
  1049. * `release`:
  1050. [:compile] or [:link] flags for release build
  1051. * `test`:
  1052. [:compile] or [:link] flags for test build
  1053. Notes:
  1054. * Ceedling works with the [:release] and [:test] build contexts
  1055. as-is; plugins can add additional contexts
  1056. * Only [:compile] and [:link] are recognized operations beneath
  1057. a context
  1058. * File specifiers do not include a path or file extension
  1059. * File specifiers are case sensitive (must match original file
  1060. name)
  1061. * File specifiers do support regular expressions if encased in quotes
  1062. * '`*`' is a special (optional) file specifier to provide flags
  1063. to all files not otherwise specified
  1064. Example [:flags] YAML blurb
  1065. ```yaml
  1066. :flags:
  1067. :release:
  1068. :compile:
  1069. :main: # add '-Wall' to compilation of main.c
  1070. - -Wall
  1071. :fan: # add '--O2' to compilation of fan.c
  1072. - --O2
  1073. :'test_.+': # add '-pedantic' to all test-files
  1074. - -pedantic
  1075. :*: # add '-foo' to compilation of all files not main.c or fan.c
  1076. - -foo
  1077. :test:
  1078. :compile:
  1079. :main: # add '--O1' to compilation of main.c as part of test builds including main.c
  1080. - --O1
  1081. :link:
  1082. :test_main: # add '--bar --baz' to linking of test_main.exe
  1083. - --bar
  1084. - --baz
  1085. ```
  1086. **import**: Load additional config files
  1087. In some cases it is nice to have config files (project.yml, options files) which can
  1088. load other config files, for commonly re-used definitions (target processor,
  1089. common code modules, etc).
  1090. These can be recursively nested, the included files can include other files.
  1091. To import config files, either provide an array of files to import, or use hashes to set imports. The former is useful if you do not anticipate needing to replace a given file for different configurations (project: or options:). If you need to replace/remove imports based on different configuration files, use the hashed version. The two methods cannot be mixed in the same .yml.
  1092. Example [:import] YAML blurb using array
  1093. ```yaml
  1094. :import:
  1095. - path/to/config.yml
  1096. - path/to/another/config.yml
  1097. ```
  1098. Example [:import] YAML blurb using hashes
  1099. ```yaml
  1100. :import:
  1101. :configA: path/to/config.yml
  1102. :configB: path/to/another/config.yml
  1103. ```
  1104. Ceedling sets values for a subset of CMock settings. All CMock
  1105. options are available to be set, but only those options set by
  1106. Ceedling in an automated fashion are documented below. See CMock
  1107. documentation.
  1108. **cmock**: configure CMock's code generation options and set symbols used to modify CMock's compiled features
  1109. Ceedling sets values for a subset of CMock settings. All CMock options are available to be set, but only those options set by Ceedling in an automated fashion are documented below. See CMock documentation.
  1110. * `enforce_strict_ordering`:
  1111. Tests fail if expected call order is not same as source order
  1112. **Default**: TRUE
  1113. * `mock_path`:
  1114. Path for generated mocks
  1115. **Default**: <build path>/tests/mocks
  1116. * `defines`:
  1117. List of conditional compilation symbols used to configure CMock's
  1118. compiled features. See CMock documentation to understand available
  1119. options. No symbols must be set unless defaults are inappropriate for
  1120. your specific environment. All symbols are used only by Ceedling to
  1121. compile CMock C code; contents of [:defines] are ignored by CMock's
  1122. Ruby code when instantiated.
  1123. **Default**: `[]` (empty)
  1124. * `verbosity`:
  1125. If not set, defaults to Ceedling's verbosity level
  1126. * `plugins`:
  1127. If [:project][:use_exceptions] is enabled, the internal plugins list is pre-populated with 'cexception'.
  1128. Whether or not you have included [:cmock][:plugins] in your
  1129. configuration file, Ceedling automatically adds 'cexception' to the
  1130. plugin list if exceptions are enabled. To add to the list Ceedling
  1131. provides CMock, simply add [:cmock][:plugins] to your configuration
  1132. and specify your desired additional plugins.
  1133. Each of the plugins have their own additional documentation.
  1134. * `includes`:
  1135. If [:cmock][:unity_helper] set, pre-populated with unity_helper file
  1136. name (no path).
  1137. The [:cmock][:includes] list works identically to the plugins list
  1138. above with regard to adding additional files to be inserted within
  1139. mocks as #include statements.
  1140. The last four settings above are directly tied to other Ceedling
  1141. settings; hence, why they are listed and explained here. The
  1142. first setting above, [:enforce_strict_ordering], defaults
  1143. to FALSE within CMock. It is set to TRUE by default in Ceedling
  1144. as our way of encouraging you to use strict ordering. It's a teeny
  1145. bit more expensive in terms of code generated, test execution
  1146. time, and complication in deciphering test failures. However,
  1147. it's good practice. And, of course, you can always disable it
  1148. by overriding the value in the Ceedling YAML configuration file.
  1149. **cexception**: configure symbols used to modify CException's compiled features
  1150. * `defines`:
  1151. List of conditional compilation symbols used to configure CException's
  1152. features in its source and header files. See CException documentation
  1153. to understand available options. No symbols must be set unless the
  1154. defaults are inappropriate for your specific environment.
  1155. **Default**: `[]` (empty)
  1156. **unity**: configure symbols used to modify Unity's compiled features
  1157. * `defines`:
  1158. List of conditional compilation symbols used to configure Unity's
  1159. features in its source and header files. See Unity documentation to
  1160. understand available options. No symbols must be set unless the
  1161. defaults are inappropriate for your specific environment. Most Unity
  1162. defines can be easily configured through the YAML file.
  1163. **Default**: `[]` (empty)
  1164. Example [:unity] YAML blurbs
  1165. ```yaml
  1166. :unity: #itty bitty processor & toolchain with limited test execution options
  1167. :defines:
  1168. - UNITY_INT_WIDTH=16 #16 bit processor without support for 32 bit instructions
  1169. - UNITY_EXCLUDE_FLOAT #no floating point unit
  1170. :unity: #great big gorilla processor that grunts and scratches
  1171. :defines:
  1172. - UNITY_SUPPORT_64 #big memory, big counters, big registers
  1173. - UNITY_LINE_TYPE=\"unsigned int\" #apparently we're using really long test files,
  1174. - UNITY_COUNTER_TYPE=\"unsigned int\" #and we've got a ton of test cases in those test files
  1175. - UNITY_FLOAT_TYPE=\"double\" #you betcha
  1176. ```
  1177. Notes on Unity configuration:
  1178. * **Verification** - Ceedling does no verification of your configuration
  1179. values. In a properly configured setup, your Unity configuration
  1180. values are processed, collected together with any test define symbols
  1181. you specify elsewhere, and then passed to your toolchain during test
  1182. compilation. Unity's conditional compilation statements, your
  1183. toolchain's preprocessor, and/or your toolchain's compiler will
  1184. complain appropriately if your specified configuration values are
  1185. incorrect, incomplete, or incompatible.
  1186. * **Routing $stdout** - Unity defaults to using `putchar()` in C's
  1187. standard library to display test results. For more exotic environments
  1188. than a desktop with a terminal (e.g. running tests directly on a
  1189. non-PC target), you have options. For example, you could create a
  1190. routine that transmits a character via RS232 or USB. Once you have
  1191. that routine, you can replace `putchar()` calls in Unity by overriding
  1192. the function-like macro `UNITY_OUTPUT_CHAR`. Consult your toolchain
  1193. and shell documentation. Eventhough this can also be defined in the YAML file
  1194. most shell environments do not handle parentheses as command line arguments
  1195. very well. To still be able to add this functionality all necessary
  1196. options can be defined in the `unity_config.h`. Unity needs to be told to look for
  1197. the `unity_config.h` in the YAML file, though.
  1198. Example [:unity] YAML blurbs
  1199. ```yaml
  1200. :unity:
  1201. :defines:
  1202. - UNITY_INCLUDE_CONFIG_H
  1203. ```
  1204. Example unity_config.h
  1205. ```
  1206. #ifndef UNITY_CONFIG_H
  1207. #define UNITY_CONFIG_H
  1208. #include "uart_output.h" //Helper library for your custom environment
  1209. #define UNITY_INT_WIDTH 16
  1210. #define UNITY_OUTPUT_START() uart_init(F_CPU, BAUD) //Helperfunction to init UART
  1211. #define UNITY_OUTPUT_CHAR(a) uart_putchar(a) //Helperfunction to forward char via UART
  1212. #define UNITY_OUTPUT_COMPLETE() uart_complete() //Helperfunction to inform that test has ended
  1213. #endif
  1214. ```
  1215. **tools**: a means for representing command line tools for use under
  1216. Ceedling's automation framework
  1217. Ceedling requires a variety of tools to work its magic. By default,
  1218. the GNU toolchain (`gcc`, `cpp`, `as`) are configured and ready for
  1219. use with no additions to the project configuration YAML file.
  1220. However, as most work will require a project-specific toolchain,
  1221. Ceedling provides a generic means for specifying / overriding
  1222. tools.
  1223. * `test_compiler`:
  1224. Compiler for test & source-under-test code
  1225. - `${1}`: input source
  1226. - `${2}`: output object
  1227. - `${3}`: optional output list
  1228. - `${4}`: optional output dependencies file
  1229. **Default**: `gcc`
  1230. * `test_linker`:
  1231. Linker to generate test fixture executables
  1232. - `${1}`: input objects
  1233. - `${2}`: output binary
  1234. - `${3}`: optional output map
  1235. - `${4}`: optional library list
  1236. - `${5}`: optional library path list
  1237. **Default**: `gcc`
  1238. * `test_fixture`:
  1239. Executable test fixture
  1240. - `${1}`: simulator as executable with`${1}` as input binary file argument or native test executable
  1241. **Default**: `${1}`
  1242. * `test_includes_preprocessor`:
  1243. Extractor of #include statements
  1244. - `${1}`: input source file
  1245. **Default**: `cpp`
  1246. * `test_file_preprocessor`:
  1247. Preprocessor of test files (macros, conditional compilation statements)
  1248. - `${1}`: input source file
  1249. - `${2}`: preprocessed output source file
  1250. **Default**: `gcc`
  1251. * `test_file_preprocessor_directives`:
  1252. Preprocessor of test files to expand only conditional compilation statements,
  1253. handle directives, but do not expand macros
  1254. - `${1}`: input source file
  1255. - `${2}`: not-fully preprocessed output source file
  1256. **Default**: `gcc`
  1257. * `test_dependencies_generator`:
  1258. Discovers deep dependencies of source & test (for incremental builds)
  1259. - `${1}`: input source file
  1260. - `${2}`: compiled object filepath
  1261. - `${3}`: output dependencies file
  1262. **Default**: `gcc`
  1263. * `release_compiler`:
  1264. Compiler for release source code
  1265. - `${1}`: input source
  1266. - `${2}`: output object
  1267. - `${3}`: optional output list
  1268. - `${4}`: optional output dependencies file
  1269. **Default**: `gcc`
  1270. * `release_assembler`:
  1271. Assembler for release assembly code
  1272. - `${1}`: input assembly source file
  1273. - `${2}`: output object file
  1274. **Default**: `as`
  1275. * `release_linker`:
  1276. Linker for release source code
  1277. - `${1}`: input objects
  1278. - `${2}`: output binary
  1279. - `${3}`: optional output map
  1280. - `${4}`: optional library list
  1281. - `${5}`: optional library path list
  1282. **Default**: `gcc`
  1283. * `release_dependencies_generator`:
  1284. Discovers deep dependencies of source files (for incremental builds)
  1285. - `${1}`: input source file
  1286. - `${2}`: compiled object filepath
  1287. - `${3}`: output dependencies file
  1288. **Default**: `gcc`
  1289. A Ceedling tool has a handful of configurable elements:
  1290. 1. [:executable] - Command line executable (required)
  1291. 2. [:arguments] - List of command line arguments
  1292. and substitutions (required)
  1293. 3. [:name] - Simple name (e.g. "nickname") of tool beyond its
  1294. executable name (if not explicitly set then Ceedling will
  1295. form a name from the tool's YAML entry name)
  1296. 4. [:stderr_redirect] - Control of capturing $stderr messages
  1297. {:none, :auto, :win, :unix, :tcsh}.
  1298. Defaults to :none if unspecified; create a custom entry by
  1299. specifying a simple string instead of any of the available
  1300. symbols.
  1301. 5. [:background_exec] - Control execution as background process
  1302. {:none, :auto, :win, :unix}.
  1303. Defaults to :none if unspecified.
  1304. 6. [:optional] - By default a tool is required for operation, which
  1305. means tests will be aborted if the tool is not present. However,
  1306. you can set this to `TRUE` if it's not needed for testing.
  1307. Tool Element Runtime Substitution
  1308. ---------------------------------
  1309. To accomplish useful work on multiple files, a configured tool will most
  1310. often require that some number of its arguments or even the executable
  1311. itself change for each run. Consequently, every tool's argument list and
  1312. executable field possess two means for substitution at runtime. Ceedling
  1313. provides two kinds of inline Ruby execution and a notation for
  1314. populating elements with dynamically gathered values within the build
  1315. environment.
  1316. Tool Element Runtime Substitution: Inline Ruby Execution
  1317. --------------------------------------------------------
  1318. In-line Ruby execution works similarly to that demonstrated for the
  1319. [:environment] section except that substitution occurs as the tool is
  1320. executed and not at the time the configuration file is first scanned.
  1321. * `#{...}`:
  1322. Ruby string substitution pattern wherein the containing string is
  1323. expanded to include the string generated by Ruby code between the
  1324. braces. Multiple instances of this expansion can occur within a single
  1325. tool element entry string. Note that if this string substitution
  1326. pattern occurs at the very beginning of a string in the YAML
  1327. configuration the entire string should be enclosed in quotes (see the
  1328. [:environment] section for further explanation on this point).
  1329. * `{...} `:
  1330. If an entire tool element string is enclosed with braces, it signifies
  1331. that Ceedling should execute the Ruby code contained within those
  1332. braces. Say you have a collection of paths on disk and some of those
  1333. paths include spaces. Further suppose that a single tool that must use
  1334. those paths requires those spaces to be escaped, but all other uses of
  1335. those paths requires the paths to remain unchanged. You could use this
  1336. Ceedling feature to insert Ruby code that iterates those paths and
  1337. escapes those spaces in the array as used by the tool of this example.
  1338. Tool Element Runtime Substitution: Notational Substitution
  1339. ----------------------------------------------------------
  1340. A Ceedling tool's other form of dynamic substitution relies on a '$'
  1341. notation. These '$' operators can exist anywhere in a string and can be
  1342. decorated in any way needed. To use a literal '$', escape it as '\\$'.
  1343. * `$`:
  1344. Simple substitution for value(s) globally available within the runtime
  1345. (most often a string or an array).
  1346. * `${#}`:
  1347. When a Ceedling tool's command line is expanded from its configured
  1348. representation and used within Ceedling Ruby code, certain calls to
  1349. that tool will be made with a parameter list of substitution values.
  1350. Each numbered substitution corresponds to a position in a parameter
  1351. list. Ceedling Ruby code expects that configured compiler and linker
  1352. tools will contain ${1} and ${2} replacement arguments. In the case of
  1353. a compiler ${1} will be a C code file path, and ${2} will be the file
  1354. path of the resulting object file. For a linker ${1} will be an array
  1355. of object files to link, and ${2} will be the resulting binary
  1356. executable. For an executable test fixture ${1} is either the binary
  1357. executable itself (when using a local toolchain such as gcc) or a
  1358. binary input file given to a simulator in its arguments.
  1359. Example [:tools] YAML blurbs
  1360. ```yaml
  1361. :tools:
  1362. :test_compiler:
  1363. :executable: compiler #exists in system search path
  1364. :name: 'acme test compiler'
  1365. :arguments:
  1366. - -I"$": COLLECTION_PATHS_TEST_TOOLCHAIN_INCLUDE #expands to -I search paths
  1367. - -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR #expands to -I search paths
  1368. - -D$: COLLECTION_DEFINES_TEST_AND_VENDOR #expands to all -D defined symbols
  1369. - --network-license #simple command line argument
  1370. - -optimize-level 4 #simple command line argument
  1371. - "#{`args.exe -m acme.prj`}" #in-line ruby sub to shell out & build string of arguments
  1372. - -c ${1} #source code input file (Ruby method call param list sub)
  1373. - -o ${2} #object file output (Ruby method call param list sub)
  1374. :test_linker:
  1375. :executable: /programs/acme/bin/linker.exe #absolute file path
  1376. :name: 'acme test linker'
  1377. :arguments:
  1378. - ${1} #list of object files to link (Ruby method call param list sub)
  1379. - -l$-lib: #inline yaml array substitution to link in foo-lib and bar-lib
  1380. - foo
  1381. - bar
  1382. - -o ${2} #executable file output (Ruby method call param list sub)
  1383. :test_fixture:
  1384. :executable: tools/bin/acme_simulator.exe #relative file path to command line simulator
  1385. :name: 'acme test fixture'
  1386. :stderr_redirect: :win #inform Ceedling what model of $stderr capture to use
  1387. :arguments:
  1388. - -mem large #simple command line argument
  1389. - -f "${1}" #binary executable input file to simulator (Ruby method call param list sub)
  1390. ```
  1391. Resulting command line constructions from preceding example [:tools] YAML blurbs
  1392. > compiler -I"/usr/include” -I”project/tests”
  1393. -I"project/tests/support” -I”project/source” -I”project/include”
  1394. -DTEST -DLONG_NAMES -network-license -optimize-level 4 arg-foo
  1395. arg-bar arg-baz -c project/source/source.c -o
  1396. build/tests/out/source.o
  1397. [notes: (1.) "arg-foo arg-bar arg-baz" is a fabricated example
  1398. string collected from $stdout as a result of shell execution
  1399. of args.exe
  1400. (2.) the -c and -o arguments are
  1401. fabricated examples simulating a single compilation step for
  1402. a test; ${1} & ${2} are single files]
  1403. > \programs\acme\bin\linker.exe thing.o unity.o
  1404. test_thing_runner.o test_thing.o mock_foo.o mock_bar.o -lfoo-lib
  1405. -lbar-lib -o build\tests\out\test_thing.exe
  1406. [note: in this scenario ${1} is an array of all the object files
  1407. needed to link a test fixture executable]
  1408. > tools\bin\acme_simulator.exe -mem large -f "build\tests\out\test_thing.bin 2>&1”
  1409. [note: (1.) :executable could have simply been ${1} - if we were compiling
  1410. and running native executables instead of cross compiling (2.) we're using
  1411. $stderr redirection to allow us to capture simulator error messages to
  1412. $stdout for display at the run's conclusion]
  1413. Notes:
  1414. * The upper case names are Ruby global constants that Ceedling
  1415. builds
  1416. * "COLLECTION_" indicates that Ceedling did some work to assemble
  1417. the list. For instance, expanding path globs, combining multiple
  1418. path globs into a convenient summation, etc.
  1419. * At present, $stderr redirection is primarily used to capture
  1420. errors from test fixtures so that they can be displayed at the
  1421. conclusion of a test run. For instance, if a simulator detects
  1422. a memory access violation or a divide by zero error, this notice
  1423. might go unseen in all the output scrolling past in a terminal.
  1424. * The preprocessing tools can each be overridden with non-gcc
  1425. equivalents. However, this is an advanced feature not yet
  1426. documented and requires that the replacement toolchain conform
  1427. to the same conventions used by gcc.
  1428. **Ceedling Collection Used in Compilation**:
  1429. * `COLLECTION_PATHS_TEST`:
  1430. All test paths
  1431. * `COLLECTION_PATHS_SOURCE`:
  1432. All source paths
  1433. * `COLLECTION_PATHS_INCLUDE`:
  1434. All include paths
  1435. * `COLLECTION_PATHS_SUPPORT`:
  1436. All test support paths
  1437. * `COLLECTION_PATHS_SOURCE_AND_INCLUDE`:
  1438. All source and include paths
  1439. * `COLLECTION_PATHS_SOURCE_INCLUDE_VENDOR`:
  1440. All source and include paths + applicable vendor paths (e.g.
  1441. CException's source path if exceptions enabled)
  1442. * `COLLECTION_PATHS_TEST_TOOLCHAIN_INCLUDE`:
  1443. All test toolchain include paths
  1444. * `COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE`:
  1445. All test, source, and include paths
  1446. * `COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR`:
  1447. All test, source, include, and applicable vendor paths (e.g. Unity's
  1448. source path plus CMock and CException's source paths if mocks and
  1449. exceptions are enabled)
  1450. * `COLLECTION_PATHS_RELEASE_TOOLCHAIN_INCLUDE`:
  1451. All release toolchain include paths
  1452. * `COLLECTION_DEFINES_TEST_AND_VENDOR`:
  1453. All symbols specified in [:defines][:test] + symbols defined for
  1454. enabled vendor tools - e.g. [:unity][:defines], [:cmock][:defines],
  1455. and [:cexception][:defines]
  1456. * `COLLECTION_DEFINES_RELEASE_AND_VENDOR`:
  1457. All symbols specified in [:defines][:release] plus symbols defined by
  1458. [:cexception][:defines] if exceptions are enabled
  1459. Notes:
  1460. * Other collections exist within Ceedling. However, they are
  1461. only useful for advanced features not yet documented.
  1462. * Wherever multiple path lists are combined for use Ceedling prioritizes
  1463. path groups as follows: test paths, support paths, source paths, include
  1464. paths.
  1465. This can be useful, for instance, in certain testing scenarios
  1466. where we desire Ceedling or the compiler to find a stand-in header file
  1467. before the actual source header file of the same name.
  1468. **plugins**: Ceedling extensions
  1469. * `load_paths`:
  1470. Base paths to search for plugin subdirectories or extra ruby functionalit
  1471. **Default**: `[]` (empty)
  1472. * `enabled`:
  1473. List of plugins to be used - a plugin's name is identical to the
  1474. subdirectory that contains it (and the name of certain files within
  1475. that subdirectory)
  1476. **Default**: `[]` (empty)
  1477. Plugins can provide a variety of added functionality to Ceedling. In
  1478. general use, it's assumed that at least one reporting plugin will be
  1479. used to format test results. However, if no reporting plugins are
  1480. specified, Ceedling will print to `$stdout` the (quite readable) raw
  1481. test results from all test fixtures executed.
  1482. Example [:plugins] YAML blurb
  1483. ```yaml
  1484. :plugins:
  1485. :load_paths:
  1486. - project/tools/ceedling/plugins #home to your collection of plugin directories
  1487. - project/support #maybe home to some ruby code your custom plugins share
  1488. :enabled:
  1489. - stdout_pretty_tests_report #nice test results at your command line
  1490. - our_custom_code_metrics_report #maybe you needed line count and complexity metrics, so you
  1491. #created a plugin to scan all your code and collect that info
  1492. ```
  1493. * `stdout_pretty_tests_report`:
  1494. Prints to $stdout a well-formatted list of ignored and failed tests,
  1495. final test counts, and any extraneous output (e.g. printf statements
  1496. or simulator memory errors) collected from executing the test
  1497. fixtures. Meant to be used with runs at the command line.
  1498. * `stdout_ide_tests_report`:
  1499. Prints to $stdout simple test results formatted such that an IDE
  1500. executing test-related Rake tasks can recognize file paths and line
  1501. numbers in test failures, etc. Thus, you can click a test result in
  1502. your IDE's execution window and jump to the failure (or ignored test)
  1503. in your test file (obviously meant to be used with an [IDE like
  1504. Eclipse][ide], etc).
  1505. [ide]: http://throwtheswitch.org/white-papers/using-with-ides.html
  1506. * `xml_tests_report`:
  1507. Creates an XML file of test results in the xUnit format (handy for
  1508. Continuous Integration build servers or as input to other reporting
  1509. tools). Produces a file report.xml in <build root>/artifacts/tests.
  1510. * `bullseye`:
  1511. Adds additional Rake tasks to execute tests with the commercial code
  1512. coverage tool provided by [Bullseye][]. See readme.txt inside the bullseye
  1513. plugin directory for configuration and use instructions. Note:
  1514. Bullseye only works with certain compilers and linkers (healthy list
  1515. of supported toolchains though).
  1516. [bullseye]: http://www.bullseye.com
  1517. * `gcov`:
  1518. Adds additional Rake tasks to execute tests with the GNU code coverage
  1519. tool [gcov][]. See readme.txt inside the gcov directory for configuration
  1520. and use instructions. Only works with GNU compiler and linker.
  1521. [gcov]: http://gcc.gnu.org/onlinedocs/gcc/Gcov.html
  1522. * `warnings_report`:
  1523. Scans compiler and linker `$stdout / $stderr` output for the word
  1524. 'warning' (case insensitive). All code warnings (or tool warnings) are
  1525. logged to a file warnings.log in the appropriate `<build
  1526. root>/artifacts` directory (e.g. test/ for test tasks, `release/` for a
  1527. release build, or even `bullseye/` for bullseye runs).
  1528. Module Generator
  1529. ========================
  1530. Ceedling includes a plugin called module_generator that will create a source, header and test file for you.
  1531. There are several possibilities to configure this plugin through your project.yml to suit your project's needs.
  1532. Directory Structure
  1533. -------------------------------------------
  1534. The default configuration for directory/project structure is:
  1535. ```yaml
  1536. :module_generator:
  1537. :project_root: ./
  1538. :source_root: src/
  1539. :test_root: test/
  1540. ```
  1541. You can change these variables in your project.yml file to comply with your project's directory structure.
  1542. If you call `ceedling module:create`, it will create three files:
  1543. 1. A source file in the source_root
  1544. 2. A header file in the source_root
  1545. 3. A test file in the test_root
  1546. If you want your header file to be in another location,
  1547. you can specify the ':inc_root:" in your project.yml file:
  1548. ```yaml
  1549. :module_generator:
  1550. :inc_root: inc/
  1551. ```
  1552. The module_generator will then create the header file in your defined ':inc_root:'.
  1553. By default, ':inc_root:' is not defined so the module_generator will use the source_root.
  1554. Sometimes, your project can't be divided into a single src, inc, and test folder. You have several directories
  1555. with sources/..., something like this for example:
  1556. <project_root>
  1557. - myDriver
  1558. - src
  1559. - inc
  1560. - test
  1561. - myOtherDriver
  1562. - src
  1563. - inc
  1564. - test
  1565. - ...
  1566. Don't worry, you don't have to manually create the source/header/test files.
  1567. The module_generator can accept a path to create a source_root/inc_root/test_root folder with your files:
  1568. `ceedling module:create[<module_root_path>:<module_name>]`
  1569. F.e., applied to the above project structure:
  1570. `ceedling module:create[myOtherDriver:driver]`
  1571. This will make the module_generator run in the subdirectory 'myOtherDriver' and generate the module files
  1572. for you in that directory. So, this command will generate the following files:
  1573. 1. A source file 'driver.c' in <project_root>/myOtherDriver/<source_root>
  1574. 2. A header file 'driver.h' in <project_root>/myOtherDriver/<source_root> (or <inc_root> if specified)
  1575. 3. A test file 'test_driver.c' in <project_root>/myOtherDriver/<test_root>
  1576. Naming
  1577. -------------------------------------------
  1578. By default, the module_generator will generate your files in lowercase.
  1579. `ceedling module:create[mydriver]` and `ceedling module:create[myDriver]`(note the uppercase) will generate the same files:
  1580. 1. mydriver.c
  1581. 2. mydriver.h
  1582. 3. test_mydriver.c
  1583. You can configure the module_generator to use a differect naming mechanism through the project.yml:
  1584. ```yaml
  1585. :module_generator:
  1586. :naming: "camel"
  1587. ```
  1588. There are other possibilities as well (bumpy, camel, snake, caps).
  1589. Refer to the unity module generator for more info (the unity module generator is used under the hood by module_generator).
  1590. Boilerplate header
  1591. -------------------------------------------
  1592. There are two ways of adding a boilerplate header comment to your generated files:
  1593. * With a defined string in the project.yml file:
  1594. ```yaml
  1595. :module_generator:
  1596. :boilerplates:
  1597. :src: '/* This is Boilerplate code. */'
  1598. ```
  1599. Using the command **ceedling module:create[foo]** it creates the source module as follows:
  1600. ```c
  1601. /* This is Boilerplate code. */
  1602. #include "foo.h"
  1603. ```
  1604. It would be the same for **:tst:** and **:inc:** adding its respective options.
  1605. * Defining an external file with boileplate code:
  1606. ```yml
  1607. :module_generator:
  1608. :boilerplate_files:
  1609. :src: '<template_folder>\src_boilerplate.txt'
  1610. :inc: '<template_folder>\inc_boilerplate.txt'
  1611. :tst: '<template_folder>\tst_boilerplate.txt'
  1612. ```
  1613. For whatever file names in whichever folder you desire.
  1614. Advanced Topics (Coming)
  1615. ========================
  1616. Modifying Your Configuration without Modifying Your Project File: Option Files & User Files
  1617. -------------------------------------------------------------------------------------------
  1618. Modifying your project file without modifying your project file
  1619. Debugging and/or printf()
  1620. -------------------------
  1621. When you gotta get your hands dirty...
  1622. Ceedling Plays Nice with Others - Using Ceedling for Tests Alongside Another Release Build Setup
  1623. ------------------------------------------------------------------------------------------------
  1624. You've got options.
  1625. Adding Handy Rake Tasks for Your Project (without Fancy Pants Custom Plugins)
  1626. -----------------------------------------------------------------------------
  1627. Add a file `rakefile.rb` at the root of your project that loads Ceedling. This
  1628. differs whether you are using the gem version or a local Ceedling version.
  1629. Gem Version:
  1630. ```ruby
  1631. require('Ceedling')
  1632. Ceedling.load_project
  1633. ```
  1634. Local Ceedling Version (assuming local ceedling is in `vendor/ceedling`):
  1635. ```ruby
  1636. PROJECT_CEEDLING_ROOT = "vendor/ceedling"
  1637. load "#{PROJECT_CEEDLING_ROOT}/lib/ceedling.rb"
  1638. Ceedling.load_project
  1639. ```
  1640. Now you simply add your rake task to the file e.g.:
  1641. ```ruby
  1642. desc "Print hello world in sh" # Only tasks with description are listed by ceedling -T
  1643. task :hello_world do
  1644. sh "echo Hello World!"
  1645. end
  1646. ```
  1647. The task can now be called with: `ceedling hello_world`
  1648. Working with Non-Desktop Testing Environments
  1649. ---------------------------------------------
  1650. For those crazy platforms lacking command line simulators and for which
  1651. cross-compiling on the desktop just ain't gonna get it done.
  1652. Creating Custom Plugins
  1653. -----------------------
  1654. Oh boy. This is going to take some explaining.