Slide 1

Slide 1 text

૊ ࠐ Έ ι ϑ τ ΢ Σ Ξ ج ૅ ݱ৔ϊ΢ϋ΢Λ஌Ζ͏ ςετۦಈ։ൃͷັྗΛޠΔ ʙ࣮૷ฤʙ 2023/2/16ʢ໦ʣ 19:30ʙ20:15 Twitterεϖʔε: https://twitter.com/i/spaces/1dRKZMXygnQxB

Slide 2

Slide 2 text

▪ύʔιϧΫϩεςΫϊϩδʔגࣜձࣾ ɹୈ1ٕज़։ൃຊ෦ɾ౦೔ຊ։ൃ෦ɹट౎ݍ2GɹѨ෦ɹߞೋʢ͋΂ɹ͜͏͡ʣ ▪ҩྍػث։ൃ ɾ૊ࠐΈιϑτ΢ΣΞ։ൃɻ ɾCݴޠɺϕΞϝλϧͷ։ൃۀ຿ܦݧ͕΄ͱΜͲɻ ࣗݾ঺հ 1 2

Slide 3

Slide 3 text

▪ٕज़ॻΛॻ͍ٕͯज़ॻయ13ʹࢀՃͨ͠Γɺ ɹ ▪ϚΠίϯͷίϯςετ(※)ʹࢀՃͨ͠Γɺ ɹ※SPRESENSE™ ׆༻ίϯςετ ɹ૊ࠐΈιϑτ΢ΣΞ։ൃ͕޷͖ͳ͓͡͞ΜͰ͢ɻ ɹΑΖ͓͘͠ئ͍͠·͢ɻ ▪LAPRASϙʔτϑΥϦΦɿhttps://lapras.com/public/k-abe ▪twitter: @juraruming ࣗݾ঺հ 2 3

Slide 4

Slide 4 text

ɾจࣈ௨ΓςετͰιϑτ΢Σ Ξ։ൃΛۦಈ(ਐΊ͍ͯ͘)͜ͱɻ ςετϑΝʔετͰΑΓྑ͍ઃܭ Λಋ͘ɻ ʲςετۦಈ։ൃ(Ҏ߱TDD) ͱ͸Կ?ʳ 4

Slide 5

Slide 5 text

1.ָ͍͠ 2.ෆ͕҆ݮΔ 3.ྑ͍ઃܭΛಋ͘ 4.ϋʔυ΢ΣΞ͕ͳͯ͘΋ςετ ΛਐΊΔํ๏࿦ֶ͕΂Δ ʲTDDֶशϝϦοτʳ 5

Slide 6

Slide 6 text

ɾϗετͱ͸? ɹ TDDΛ࣮ߦ͢Δ؀ڥͰɺ ϗετ → ϗετPCͰTDD͢Δɻ λʔήοτˠ૊ΈࠐΈ૷ஔͰTDD͢Δɻɹ ϗετɾλʔήοτͱ͸? 6 ϗετPC → ϗετ ૊ΈࠐΈ૷ஔ → λʔήοτ LED ▪ ϗετͰTDD͢Δಛ௃ ɾ૊ΈࠐΈ૷ஔʹςετϓϩάϥϜΛμ΢ ϯϩʔυ͠ͳͯ͘ྑ͍ͷͰૣ͘ςετͰ͖ Δɻ ɾϋʔυ΢ΣΞΛ੍ޚ͠ͳ͍ɻϋʔυ΢Σ ΞΛԾ૝తʹѻ͏ɻ ɾςετϑϨʔϜϫʔΫʹࣗ༝౓͕͋Δɻ ɹGoogleTest, CppUTest, Unity, ͦͷଞ ▪ λʔήοτ ɾϗετʹൺ΂ͯςετΛճ͢ʲεϐʔ υʳ͕஗͍(ϗετˠλʔήοτ΁ͷϓϩ άϥϜͷμ΢ϯϩʔυͳͲ)ɻ ɾϋʔυ΢ΣΞΛ੍ޚ͢Δɻϋʔυ΢ΣΞ ΛབྷΊͨςετ͕Ͱ͖Δɻ ɾ࢖͑ΔςετϑϨʔϜϫʔΫʹ੍ݶ͕Ͱ ͯ͘ΔɻϚΠίϯ͸RAM͕গͳ͍ͨΊɻ ɹCppUTest, Unity, ͦͷଞ

Slide 7

Slide 7 text

ʲϗετʳ ▪ϗετPC: macOS Monterey όʔδϣϯ 12.6 ▪ςετϑϨʔϜϫʔΫ: CppUTest 4.0 ▪ίϯύΠϥ: Apple clang version 11.0.0 (clang-1100.0.33.8) ▪ςετର৅ϓϩάϥϛϯάݴޠ: C ▪ϏϧυγεςϜ: cmake 3.21.1 ʲλʔήοτʳ ※λʔήοτ͸ಈ࡞֬ೝͰ͖·ͤΜͰͨ͠ɻߏ૝ͷΈɻ ɾSTM32CubeIDE Version: 1.11.0 ɾςετϑϨʔϜϫʔΫ: CppUTest 4.0(ϗετͱಉ͡) ʲࠓճͷ؀ڥʹ͍ͭͯʳ 7

Slide 8

Slide 8 text

ϗετฤͷҰ࿈ͷखॱ͸࣍ͷࢿྉʹॻ͖·ͨ͠ɻ Α͚Ε͹ࢀর͍ͯͩ͘͠͞ɻ ϗετฤࢿྉɿ ૊ΈࠐΈιϑτ΢ΣΞجૅ_ʲ࿈ଓߨ࠲ #6ʳTDD#2 LED ド ϥΠ バ (ϗ ετPCฤ)_slide https://www.docswell.com/s/juraruming/ 5G31LZ-2022-10-31-220730 ιʔείʔυ͸ͪ͜Βɻ https://github.com/grace2riku/evkart_tdd/tree/LedDriver_221031 ʲϗετฤͷςετίʔυ࣮૷ʳ 8

Slide 9

Slide 9 text

΍Δ͜ͱ ɾςετϦετ࡞੒ ɾςετ؀ڥͭ͘Δ ɾςετΛॻ͘ ʲϗετฤͷςετίʔυ࣮૷ʳ 9

Slide 10

Slide 10 text

▪ςετϦετ࡞੒ ɾςετ͢Δ͜ͱΛϦετԽ͢Δɻ૊ࠐΈTDDຊͷखॱΛਅࣅͨ͠ɻ ྫ) LedDriverςετϦετ https://github.com/grace2riku/evkart_tdd/tree/LedDriver_221031 ʲϗετฤͷςετίʔυ࣮૷ʳ 10

Slide 11

Slide 11 text

▪ςετ؀ڥΛͭ͘Δ ɹCppUTestͷ৔߹ɺ࣍ͷεΫϦϓτ࣮ߦͰTDD؀ڥͷ਽ܗ͕ͭ͘ΕΔɻ $ NewPackageDirs HallSensorLedDriver creating src/HallSensorLedDriver creating include/HallSensorLedDriver creating tests/HallSensorLedDriver $ NewCModule.sh HallSensorLedDriver HallSensorLedDriver creating include/HallSensorLedDriver/HallSensorLedDriver.h creating src/HallSensorLedDriver/HallSensorLedDriver.c creating tests/HallSensorLedDriver/HallSensorLedDriverTest.cpp ਽ܗͷιʔείʔυΛϏϧυର৅ʹ௥Ճ͠ɺςετΛॻ͍͍ͯ͘ɻ ϗετฤࢿྉͷp28Λࢀরɻ ʲϗετฤͷςετίʔυ࣮૷ʳ 11

Slide 12

Slide 12 text

▪ςετΛॻ͘ ɹςετίʔυɿ // υϥΠόΛॳظԽͨ͠Βɺ͢΂ͯͷLED͕ফ౮͍ͯ͠Δ TEST(HallSensorLedDriver, LedsOffAfterCreate) { unsigned char virtualLeds = 0xff; // ফ౮֬ೝͷͨΊʹLEDΦϯʹॳظԽ HallSensorLedDriver_Create(&virtualLeds); // υϥΠόॳظԽ BYTES_EQUAL(0, virtualLeds); // ॳظԽޙʹ0(LEDΦϑ)͔֬ೝ } ιʔείʔυɿ https://github.com/grace2riku/evkart_tdd/blob/LedDriver_221031/tests/ HallSensorLedDriver/HallSensorLedDriverTest.cpp ʲϗετฤͷςετίʔυ࣮૷ʳ 12

Slide 13

Slide 13 text

▪ςετΛॻ͘ ɹϓϩμΫτίʔυɿ υϥΠόΛॳظԽ(͢΂ͯͷLEDΛOFF͢Δ) static unsigned char* hallSensorLedsAddress; void HallSensorLedDriver_Create(unsigned char* address) { hallSensorLedsAddress = address; *hallSensorLedsAddress = 0; } ιʔείʔυɿ https://github.com/grace2riku/evkart_tdd/blob/LedDriver_221031/ src/HallSensorLedDriver/HallSensorLedDriver.c ʲϗετฤͷςετίʔυ࣮૷ʳ 13

Slide 14

Slide 14 text

ɾLedDriverͷTDD͸ಈ࡞֬ೝʹࢸΓ·ͤΜͰͨ͠ɻ ɹ˞LedDriverͷϕʔεʹ͠Α͏ͱͨ͠ޙड़ͷ͓ࢼ͠ίʔυ͕ಈ͔ͳ͘ͳΓݪҼௐࠪதɾɾɾ(ϗε τPCͷOS΋͘͠͸STM32CubeIDEͷόʔδϣϯΞοϓ͕ݪҼ͔ͱਪଌ)ɻ ɹ࣮૷ͷߏ૝͸ͪ͜Βͷࢿྉʹ·ͱΊ·ͨ͠ɻ ɹhttps://www.docswell.com/s/juraruming/KN4MW5-2022-12-15-210619 ɾҎલɺ؆୯ͳ͓ࢼ͠ίʔυͰSTM32ϚΠίϯͰTDDͨ࣌͠ͷ࿩Λ͍ͨ͠ͱࢥ͍·͢ɻ ɹQiitaهࣄ͸ͪ͜ΒͰ͢ɻ ɹSTM32CubeIDEʹCppUTestΛ؀ڥߏங͠ɺSTM32ϚΠίϯͰTDD͢Δ ɹhttps://qiita.com/juraruming/items/1f91db17ba93b40d3730 ɹιʔείʔυ͸ͪ͜ΒͰ͢ɻ ɹhttps://github.com/grace2riku/hello_stm32_cpputestɹ ʲλʔήοτฤͷςετίʔυ࣮૷ʳ 14

Slide 15

Slide 15 text

ςετίʔυ͸ͪ͜Β(ςετࣗମʹҙຯ͸ͳ͍Ͱ͢) https://github.com/grace2riku/hello_stm32_cpputest/blob/main/446re_test/Core/Src/ test_src.cpp #include "CppUTest/TestHarness.h" TEST_GROUP(FirstTestGroup) { }; TEST(FirstTestGroup, FirstTest) // ඞࣦͣഊ͢Δςετ { FAIL("FAIL: FirstTestGroup, FirstTest\n"); } TEST(FirstTestGroup, SecondTest) // ඞͣ੒ޭ͢Δςετ Ҿ਺ʹ0Λ༩͍͑ͯΔ͔Β { CHECK_EQUAL_ZERO(0); } TEST(FirstTestGroup, IntSize) // ੒ޭ͢Δςετ STM32ϚΠίϯ͸32bitͰint͸4byteͷͨΊ { LONGS_EQUAL(4, sizeof(int)); } ʲλʔήοτฤͷςετίʔυ࣮૷ʳ 15

Slide 16

Slide 16 text

mainؔ਺͔Βςετ࣮ߦ͠·͢ɻ https://github.com/grace2riku/hello_stm32_cpputest/blob/main/446re_test/Core/Src/main.cpp int main(void) { const char* empty[] = {}; const char* command_v[] = {"cpputest", "-v"}; printf("\n----- RunAllTests(0, empty) -----\n"); CommandLineTestRunner::RunAllTests(0, empty); printf("\n----- RunAllTests(2, command_v) -----\n"); CommandLineTestRunner::RunAllTests(2, command_v); while (1) { } } ʲλʔήοτฤͷςετίʔυ࣮૷ʳ 16

Slide 17

Slide 17 text

ςετͷ࣮ߦ݁Ռ #include "CppUTest/TestHarness.h" TEST_GROUP(FirstTestGroup) { }; TEST(FirstTestGroup, FirstTest) // ඞࣦͣഊ͢Δςετ { FAIL("FAIL: FirstTestGroup, FirstTest\n"); } TEST(FirstTestGroup, SecondTest) // ඞͣ੒ޭ͢Δςετ Ҿ਺ʹ0Λ༩͍͑ͯΔ͔Β { CHECK_EQUAL_ZERO(0); } TEST(FirstTestGroup, IntSize) // ੒ޭ͢Δςετ STM32ϚΠίϯ͸32bitͰint͸4byteͷͨΊ { LONGS_EQUAL(4, sizeof(int)); } ಈը͸ͪ͜Βˠhttps://youtu.be/8rb3picKkjw ʲλʔήοτฤͷςετίʔυ࣮૷ʳ 17

Slide 18

Slide 18 text

▪ςετ͸ࢿ࢈ɻΘ͔Γ΍໋໊͍͢Λ ▪λʔήοτͰTDD͢Δࡍ͸ඞཁϦιʔε Λ೺Ѳ͢Δɻ ʲϗετฤɾλʔήοτฤͷ࣮૷ϙΠϯτʳ 18

Slide 19

Slide 19 text

▪ςετ͸ࢿ࢈ɻΘ͔Γ΍໋໊͍͢Λ ●ςετ͸܁Γฦ͠࢖͏͜ͱʹͳΔͱࢥ͏ɻޙ Ͱ࢖͏ͱ͖ʹΘ͔Γ΍͍͢ςετ໊ʹ͓ͯ͠ ͘ɻ ●ςετ໊ͱςετ಺༰͕ෆҰகɺςετͷத ͰԿ߲໨΋ςετ͍ͯ͠ΔͳͲɺςετͷ඼ ࣭ɾΘ͔Γ΍͢͞΋ॏཁͩͱࢥ͏ɻ ʲϗετฤɾλʔήοτฤͷ࣮૷ϙΠϯτʳ 19

Slide 20

Slide 20 text

▪λʔήοτͰTDD͢Δࡍ͸ඞཁϦιʔεΛ೺Ѳ͢Δɻ ੍໿ͷݫ͍͠૊ࠐΈͰTDD͢Δ৔߹ɺςετϑϨʔϜϫʔΫ͕ͲΕ͘ Β͍RAMΛফඅ͢Δ͔೺Ѳ͓ͯ͘͠ɻ ςετͰ͖·ͨ͠ɺ͔͠͠ΞϓϦέʔγϣϯ૊ΈࠐΊ·ͤΜɺͰ͸͓ ࿩͠ʹͳΒͳ͍ɾɾɾɻ ※STM32ϚΠίϯʹCppUTestΛ૊ΈࠐΜͩͱ͖ͷϝϞϦ࢖༻ྔ͸͜ ͪΒͰ͢ɻࢀߟ·Ͱʹɻ STM32CubeIDEʹCppUTestΛ؀ڥߏங͠ɺSTM32ϚΠίϯͰTDD͢Δ -> ϝϞϦ࢖༻ྔ https://qiita.com/juraruming/items/1f91db17ba93b40d3730 ʲϗετฤɾλʔήοτฤͷ࣮૷ϙΠϯτʳ 20

Slide 21

Slide 21 text

͝੩ௌ͋Γ͕ͱ͏ ͍͟͝·ͨ͠ɻ ऴΘΓ 21