Bye Bye Moore

猫マンション建築の野望を胸に零細事業主として資本主義の荒波に漕ぎ出したアラサー男の技術メモ

CeedlingでUnityを更に便利にする(その1)

以前の記事で紹介したTDDフレームワークUnityですが、
それの強化発展版としてCeedlingというものがあります。
Sinatraにとってのpadrinoみたいなものですね。

前提

手順

$ gem install ceedling

で導入完了です。楽々。

それでは、早速サンプルを展開してみませう。

$ ceedling example temp_sensor
      create  temp_sensor/vendor/ceedling/docs/CeedlingPacket.pdf
      create  temp_sensor/vendor/ceedling/docs/CExceptionSummary.pdf
      create  temp_sensor/vendor/ceedling/docs/CMock Summary.pdf
      create  temp_sensor/vendor/ceedling/docs/Unity Summary.pdf
      create  temp_sensor/vendor/ceedling/plugins
...
      create  temp_sensor/test/support/UnityHelper.c
      create  temp_sensor/test/support/UnityHelper.h
      remove  temp_sensor/rakefile.rb
      remove  temp_sensor/project.yml
      create  temp_sensor/rakefile.rb
      create  temp_sensor/project.yml

Example project 'temp_sensor' created!
 - Tool documentation is located in vendor/ceedling/docs
 - Execute 'rake -T' to view available test & build tasks

ディレクトリ構造をみていくと……

$ ls -R
temp_sensor

./temp_sensor:
build		rakefile.rb	test
project.yml	src		vendor

./temp_sensor/build:

./temp_sensor/src:
AdcConductor.c				TimerConductor.h
AdcConductor.h				TimerConfigurator.c
AdcHardware.c				TimerConfigurator.h
AdcHardware.h				TimerHardware.c
AdcHardwareConfigurator.c		TimerHardware.h
AdcHardwareConfigurator.h		TimerInterruptConfigurator.c
AdcModel.c				TimerInterruptConfigurator.h
AdcModel.h				TimerInterruptHandler.c
AdcTemperatureSensor.c			TimerInterruptHandler.h
AdcTemperatureSensor.h			TimerModel.c
Executor.c				TimerModel.h
Executor.h				Types.h
IntrinsicsWrapper.c			UsartBaudRateRegisterCalculator.c
IntrinsicsWrapper.h			UsartBaudRateRegisterCalculator.h
Main.c					UsartConductor.c
Main.h					UsartConductor.h
Model.c					UsartConfigurator.c
Model.h					UsartConfigurator.h
ModelConfig.h				UsartHardware.c
TaskScheduler.c				UsartHardware.h
TaskScheduler.h				UsartModel.c
TemperatureCalculator.c			UsartModel.h
TemperatureCalculator.h			UsartPutChar.c
TemperatureFilter.c			UsartPutChar.h
TemperatureFilter.h			UsartTransmitBufferStatus.c
TimerConductor.c			UsartTransmitBufferStatus.h

./temp_sensor/test:
TestAdcConductor.c			TestTimerConductor.c
TestAdcHardware.c			TestTimerHardware.c
TestAdcModel.c				TestTimerModel.c
TestExecutor.c				TestUsartBaudRateRegisterCalculator.c
TestMain.c				TestUsartConductor.c
TestModel.c				TestUsartHardware.c
TestTaskScheduler.c			TestUsartModel.c
TestTemperatureCalculator.c		support
TestTemperatureFilter.c

./temp_sensor/test/support:
UnityHelper.c	UnityHelper.h

./temp_sensor/vendor:
ceedling

./temp_sensor/vendor/ceedling:
docs	lib	plugins	release	vendor

./temp_sensor/vendor/ceedling/docs:
CExceptionSummary.pdf	CeedlingPacket.pdf
CMock Summary.pdf	Unity Summary.pdf

./temp_sensor/vendor/ceedling/lib:
build_invoker_utils.rb
cacheinator.rb
cacheinator_helper.rb
ceedling
ceedling.rb
cmock_builder.rb
configurator.rb
configurator_builder.rb
configurator_plugins.rb
configurator_setup.rb
configurator_validator.rb
constants.rb
defaults.rb
dependinator.rb
erb_wrapper.rb
file_finder.rb
file_finder_helper.rb
file_path_utils.rb
file_system_utils.rb
file_system_wrapper.rb
file_wrapper.rb
flaginator.rb
generator.rb
generator_helper.rb
generator_test_results.rb
generator_test_results_sanity_checker.rb
generator_test_runner.rb
loginator.rb
makefile.rb
objects.yml
par_map.rb
plugin.rb
plugin_builder.rb
plugin_manager.rb
plugin_manager_helper.rb
plugin_reportinator.rb
plugin_reportinator_helper.rb
preprocessinator.rb
preprocessinator_extractor.rb
preprocessinator_file_handler.rb
preprocessinator_helper.rb
preprocessinator_includes_handler.rb
project_config_manager.rb
project_file_loader.rb
rake_utils.rb
rake_wrapper.rb
rakefile.rb
release_invoker.rb
release_invoker_helper.rb
reportinator.rb
rules_cmock.rake
rules_preprocess.rake
rules_release.rake
rules_release_deep_dependencies.rake
rules_tests.rake
rules_tests_deep_dependencies.rake
setupinator.rb
stream_wrapper.rb
streaminator.rb
streaminator_helper.rb
system_utils.rb
system_wrapper.rb
target_loader.rb
task_invoker.rb
tasks_base.rake
tasks_filesystem.rake
tasks_release.rake
tasks_release_deep_dependencies.rake
tasks_tests.rake
tasks_tests_deep_dependencies.rake
tasks_vendor.rake
test_includes_extractor.rb
test_invoker.rb
test_invoker_helper.rb
tool_executor.rb
tool_executor_helper.rb
verbosinator.rb
yaml_wrapper.rb

./temp_sensor/vendor/ceedling/lib/ceedling:
version.rb	version.rb.erb

./temp_sensor/vendor/ceedling/plugins:
bullseye			stdout_pretty_tests_report
gcov				warnings_report
module_generator		xml_tests_report
stdout_ide_tests_report

./temp_sensor/vendor/ceedling/plugins/bullseye:
assets		bullseye.rake	config		lib		readme.txt

./temp_sensor/vendor/ceedling/plugins/bullseye/assets:
template.erb

./temp_sensor/vendor/ceedling/plugins/bullseye/config:
defaults.yml

./temp_sensor/vendor/ceedling/plugins/bullseye/lib:
bullseye.rb

./temp_sensor/vendor/ceedling/plugins/gcov:
defaults.yml	gcov.rake	gcov.rb		readme.txt	template.erb

./temp_sensor/vendor/ceedling/plugins/module_generator:
config			lib			module_generator.rake

./temp_sensor/vendor/ceedling/plugins/module_generator/config:
module_generator.yml

./temp_sensor/vendor/ceedling/plugins/module_generator/lib:
module_generator.rb

./temp_sensor/vendor/ceedling/plugins/stdout_ide_tests_report:
config	lib

./temp_sensor/vendor/ceedling/plugins/stdout_ide_tests_report/config:
stdout_ide_tests_report.yml

./temp_sensor/vendor/ceedling/plugins/stdout_ide_tests_report/lib:
stdout_ide_tests_report.rb

./temp_sensor/vendor/ceedling/plugins/stdout_pretty_tests_report:
assets	config	lib

./temp_sensor/vendor/ceedling/plugins/stdout_pretty_tests_report/assets:
template.erb

./temp_sensor/vendor/ceedling/plugins/stdout_pretty_tests_report/config:
stdout_pretty_tests_report.yml

./temp_sensor/vendor/ceedling/plugins/stdout_pretty_tests_report/lib:
stdout_pretty_tests_report.rb

./temp_sensor/vendor/ceedling/plugins/warnings_report:
warnings_report.rb

./temp_sensor/vendor/ceedling/plugins/xml_tests_report:
xml_tests_report.rb

./temp_sensor/vendor/ceedling/release:
build.info	version.info

./temp_sensor/vendor/ceedling/vendor:
c_exception	constructor	diy
cmock		deep_merge	unity

./temp_sensor/vendor/ceedling/vendor/c_exception:
lib	release

./temp_sensor/vendor/ceedling/vendor/c_exception/lib:
CException.c	CException.h

./temp_sensor/vendor/ceedling/vendor/c_exception/release:
build.info	version.info

./temp_sensor/vendor/ceedling/vendor/cmock:
config	lib	release	src

./temp_sensor/vendor/ceedling/vendor/cmock/config:
production_environment.rb	test_environment.rb

./temp_sensor/vendor/ceedling/vendor/cmock/lib:
cmock.rb				cmock_generator_plugin_expect.rb
cmock_config.rb				cmock_generator_plugin_ignore.rb
cmock_file_writer.rb			cmock_generator_utils.rb
cmock_generator.rb			cmock_header_parser.rb
cmock_generator_plugin_array.rb		cmock_plugin_manager.rb
cmock_generator_plugin_callback.rb	cmock_unityhelper_parser.rb
cmock_generator_plugin_cexception.rb

./temp_sensor/vendor/ceedling/vendor/cmock/release:
build.info	version.info

./temp_sensor/vendor/ceedling/vendor/cmock/src:
cmock.c	cmock.h

./temp_sensor/vendor/ceedling/vendor/constructor:
lib

./temp_sensor/vendor/ceedling/vendor/constructor/lib:
constructor.rb		constructor_struct.rb

./temp_sensor/vendor/ceedling/vendor/deep_merge:
lib

./temp_sensor/vendor/ceedling/vendor/deep_merge/lib:
deep_merge.rb

./temp_sensor/vendor/ceedling/vendor/diy:
lib

./temp_sensor/vendor/ceedling/vendor/diy/lib:
diy	diy.rb

./temp_sensor/vendor/ceedling/vendor/diy/lib/diy:
factory.rb

./temp_sensor/vendor/ceedling/vendor/unity:
auto	release	src

./temp_sensor/vendor/ceedling/vendor/unity/auto:
colour_prompt.rb	generate_module.rb	unity_test_summary.rb
colour_reporter.rb	generate_test_runner.rb
generate_config.yml	test_file_filter.rb

./temp_sensor/vendor/ceedling/vendor/unity/release:
build.info	version.info

./temp_sensor/vendor/ceedling/vendor/unity/src:
unity.c			unity.h			unity_internals.h

とまあ、色々と生成されます。
UnityやCMockのリファレンスも同時に生成されます。
便利ですね。

最初のテスト実行

本記事のまとめとして、お試しでテストを通してみます。

$ rake test:all
/User/hogehoge/temp_sensor/vendor/ceedling/lib/system_wrapper.rb:25: warning: Insecure world writable dir /usr/local/Cellar in PATH, mode 040777


Test 'TestAdcConductor.c'
-------------------------
Creating mock for AdcHardware...
Creating mock for AdcModel...
Generating runner for TestAdcConductor.c...
Compiling TestAdcConductor_runner.c...
Compiling TestAdcConductor.c...
Compiling MockAdcHardware.c...
Compiling MockAdcModel.c...
Compiling AdcConductor.c...
Compiling UnityHelper.c...
Compiling unity.c...
Compiling cmock.c...
Linking TestAdcConductor.out...
Running TestAdcConductor.out...

...

Test 'TestUsartModel.c'
-----------------------
Creating mock for UsartBaudRateRegisterCalculator...
Generating runner for TestUsartModel.c...
Compiling TestUsartModel_runner.c...
Compiling TestUsartModel.c...
Compiling MockUsartBaudRateRegisterCalculator.c...
Compiling UsartModel.c...
Linking TestUsartModel.out...
Running TestUsartModel.out...

-------------------------
OVERALL UNIT TEST SUMMARY
-------------------------
TESTED:  47
PASSED:  47
FAILED:   0
IGNORED:  0

デフォでは全てのテストが通るようになっています。
次回以降のコンパイルではoutファイルからテストを起こします。

$ rake test:delta

で差分のみコンパイルというオプションもあります。*1

次回の記事ではこれをベースに実際の運用法を見て行く事にします。

*1:後々の記事で紹介する予定です