Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Circuits.GPIOはいかにテストされているか
Search
pojiro
July 23, 2022
Technology
170
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Circuits.GPIOはいかにテストされているか
pojiro
July 23, 2022
More Decks by pojiro
See All by pojiro
Elixir で IoT 開発、 Nerves なら簡単にできる!?
pojiro
1
770
分野に潜むツールの紹介
pojiro
1
730
Raspberry Pi Mouse を Nerves で動かしてみた
pojiro
0
1.4k
Raspberry Pi で試す 組み込みLinux⼊⾨ Nerves の場合
pojiro
2
550
おいでよ! Nerves JP!
pojiro
1
360
描画ライブラリScenic紹介
pojiro
0
200
Nerves tips, /bin/sh & nerves_heart
pojiro
0
110
Elixir/NervesでどこまでできるのIoT?
pojiro
1
450
『推し』で仕事をする
pojiro
1
170
Other Decks in Technology
See All in Technology
業務でAWSをあまり使っていない私が、AWSへのモチベを保つ方法
smt7174
0
130
[re:Invent2026事前勉強会(有志開催)]続きは、ラスベガスの廊下で / continue-in-the-vegas-hallway
sh_fk2
0
520
AI時代に求められる優秀なTechLeadの振る舞い
pospome
9
12k
Strands Decider 2BでAWSアップデートの目利きをしてみた
sato4mi
1
120
企画からFlutter実装まで、1つの機能を一貫して開発したプロセスと成果物
khiroyuki1003
1
150
E2Eってつらくないですか?E2Eの管理コストを下げる手段とその実践
akaboshinit
6
3k
Claude Codeで作ったアプリを安全に公開する/Built with Claude Japan 2026
yoshidashingo
0
160
AI時代のエンジニアの情報発信〜個人の発信を組織の力に変える〜
ryo_kawamata
1
7.3k
攻撃 3 時間 vs 復旧 10 時間。アクセスキー流出の非対称性を体感するために CTF を作った話
kazzpapa3
1
140
超⼩型・多⾔語検索モデル Bekko Embedding
hotchpotch
1
110
2026 Apache Flink Community Checkpoint
rmetzger
0
180
渡米前の準備を制す!re:Invent 2026徹底準備術 / The Ultimate Preparation Guide for re:Invent 2026
yuj1osm
1
540
Featured
See All Featured
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
The agentic SEO stack - context over prompts
schlessera
0
1k
Faster Mobile Websites
deanohume
310
32k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
330
Evolving SEO for Evolving Search Engines
ryanjones
0
350
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
800
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
610
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
290
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
590
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
ラッコキーワード サービス紹介資料
rakko
5
5.7M
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
970
Transcript
Circuits.GPIOは いかにテストされているか 2022/07/23 NervesJP #27
What’s Circuits.GPIO? • Linux のGPIO(General-purpose input/output), 汎用入出力ピンを 操作するElixirのライブラリ • NervesでLチカをやったことがあれば使ったことがあるはず
◦ だけど、Nerves 専用のライブラリというわけではなく、 LinuxのGPIOを持ったマシンであれば、ピュア Elixirプロジェクトからも使用することができます。 iex> alias Circuits.GPIO iex> {:ok, pin} = GPIO.open(1, :output) iex> :ok = GPIO.write(pin, 1)
Circuits.GPIOの構成 • lib/gpio.ex ◦ ユーザ向けAPI用モジュール • lib/gpio_nif.ex ◦ nif用モジュール •
src/* ◦ gpio操作の低レイヤ実装 • test/cicuits_gpio_test.exs ◦ テスト用モジュール、 mix test で実行される ◦ ユーザ向けAPI用モジュールのテストを行う ちょっとだけ中身をのぞこう(時間あるかな?
Circuits.GPIOをテストするには? • Linuxマシン固有のテストは 実機でなければできない なので、 - 実機でなければテストできない部分 - 実機でなくてもテストできる部分 に分けてやれば、
後者はどんな環境でもテストを回すことができる どのように分け、後者のテストをしているか興味あり!!
ユーザのAPIコールからGPIO操作までの流れ Circuit.GPIO Circuit.GPIO.Nif gpio_nif.c gpio_nif.h hal_sysfs.c /sys/class/gpio/* を操作 iex> alias
Circuits.GPIO # /sys/class/gpio/1/direction を “out” iex> {:ok, pin} = GPIO.open(1, :output) # /sys/class/gpio/1/value を “1” iex> :ok = GPIO.write(pin, 1)
/sys/class/gpio/* なしでテストするために Circuit.GPIO Circuit.GPIO.Nif gpio_nif.c gpio_nif.h hal_sysfs.c hal_stab.c テスト用実装
ポイント Circuit.GPIO Circuit.GPIO.Nif gpio_nif.c gpio_nif.h hal_sysfs.c hal_stab.c テスト用実装 インタフェースを定 義
sysfs非依存の ロジックを実装 sysfsをシミュレートするので はなく、テストに必要な応答 のみをする薄い実装にする テスト範囲は ユーザ向けAPIの関数から、 インタフェース関数の呼び出しま で 操作実装の切り替えは Makefileで
このパターンは?見覚えが、、 • そう、Moxでやることと同じ ◦ Mox: Elixir のテストサポートライブラリ https://github.com/dashbitco/mox NervesJP.Behabiour NervesJP.Impl
NervesJP.Mock ビヘイビアで各関数の入出力、 インタフェースを定義する OSのファイル操作や外部のWeb APIなど 応答をコントロールできない関数を まとめたモジュール 応答をコントロール可能なMockに切り替え、 このインタフェースを呼び出す ロジックのテストを可能にする
まとめ • Circuits.GPIOがどのようにテストされているかを紹介しました • POINT: インタフェースを定義して、 その内部実装を切り替える方法はテストに限らず有効!なことを理解しました ◦ Cならヘッダファイルがインタフェースとして使える ◦
ElixirならBehaviourがインタフェースとして使える Have nice Nerves days!!! Thank you!!