-
Notifications
You must be signed in to change notification settings - Fork 612
i/builtin: add gpio-chardev interface #15172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i/builtin: add gpio-chardev interface #15172
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #15172 +/- ##
===========================================
- Coverage 78.09% 0 -78.10%
===========================================
Files 1190 0 -1190
Lines 158458 0 -158458
===========================================
- Hits 123746 0 -123746
+ Misses 27017 0 -27017
+ Partials 7695 0 -7695
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Wed Mar 26 18:47:33 UTC 2025 Failures:Preparing:
Executing:
Restoring:
|
interfaces/builtin/gpio_chardev.go
Outdated
return lines, nil | ||
} | ||
|
||
func validateLines(linesAttr string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be made a helper in strutil, e.g.:
// RangeSpan represents a span of numbers inside a range. A span with
// equal Start and Stop describes a span of a single number.
type RangeSpan struct {
Start, Stop uint
}
// Range of discrete numbers represented as set of non overlapping spans.
type Range struct {
// Spans within the range, ordered by Start.
Spans []RangeSpan
}
// ParseRange parses a range represented as a string. The entries are
// joining them with a comma: n[,m] or as a range: n-m or a combination
// of both, assuming the ranges do not overlap, e.g.: n,m,x-y.
func ParseRange(in str, expectedMax uint) (Range, error) {
...
}
and then you can reuse it in the helper. Separately I'd add something to the gadget package, or a subpackage there to convert range to a sequence of lines, which should be quite trivial at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this now could easily be shared with the helper command, about converting a range into a sequence of lines, I don't think we really need this as the kernel in fact accepts this exact format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks reasonable to me
strutil/range.go
Outdated
} | ||
|
||
func parseRangeSpan(in string) (RangeSpan, error) { | ||
hasNegativeStart := strings.HasPrefix(in, "-") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need the negative range support?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not at all, I discussed dropping it with @ZeyadYasser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched to using uints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, couple of small things, question for @bboozzoo
strutil/range.go
Outdated
// ParseRange parses a range represented as a string. The entries are joining | ||
// them with a comma: n[,m] or as a range: n-m or a combination of both, assuming | ||
// the ranges are non-negative and do not overlap, e.g.: n,m,x-y. | ||
func ParseRange(in string) (Range, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: s/in/input/ or s/in/s/
strutil/range.go
Outdated
// Parse range e.g. 2-5 | ||
tokens := strings.SplitN(in, "-", 2) | ||
if len(tokens) != 2 { | ||
return RangeSpan{}, fmt.Errorf("invalid range span %q", in) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this error is not tested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is not reachable since input that doesn't contain -
will have already been parsed as a single number, and doing SplitN
on a string that has -
will always have exactly two tokens.
The check is redundant, but good to have in case SplitN
was swapped to Split
for any reason or by mistake.
interfaces/builtin/gpio_chardev.go
Outdated
return nil | ||
} | ||
|
||
// XXX: What should be the limit on max range. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bboozzoo any suggestion here? is there a limit in the kernel? otherwise we should just remove the XXX
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can set it to 512, which would still be very high and unlikely to ever be reached in practice.
71b8a46
to
7c6db0b
Compare
I had to rebase to resolve conflicts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the improvements. I did a longer pass.
I have some small fixes/improvements to the range code and some questions and comments to the interface code. Please see inline.
"strings" | ||
) | ||
|
||
// RangeSpan represents a span of numbers inside a range. A span with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick. I tried to make sense of the naming of RangeSpan
and Range
but I keep feeling those are off. Could this be just Span
and the other one Spans
? Feel free to ignore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"github.com/snapcore/snapd/strutil" | ||
) | ||
|
||
// TODO: Snapd should validate the correctness of slot declarations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the plan to implement this after this PR lands?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, It is tracked as https://warthogs.atlassian.net/browse/SNAPDENG-31777
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM, my main remaining question is the TODO up top in gpio_chardev.go
. I have some concerns about reexec on old snapd. Deferring my vote until those two are answered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
For awareness, I found a stupid bug where the slot name was used as the plug name for the symlink generation, I fixed it in b80228a and updated the unit tests to catch it. |
Signed-off-by: Zeyad Gouda <[email protected]>
This implements the gpio-chardev interface (spec SD129) which is currently hidden behind an experimental feature flag until kernel improvements to the gpio-aggreagtor lands. Signed-off-by: Zeyad Gouda <[email protected]>
Signed-off-by: Zeyad Gouda <[email protected]>
Signed-off-by: Zeyad Gouda <[email protected]>
Signed-off-by: Zeyad Gouda <[email protected]>
- strutil: fix range helper typo s/Intersets/Intersects - strutil: only support positive numbers in ParseRange - strutil: sort range spans in ParseRange - i/builtin/gpio-chardev: error message improvements - i/builtin/gpio-chardev: remove unnesaccery non-negative validation Signed-off-by: Zeyad Gouda <[email protected]>
Signed-off-by: Zeyad Gouda <[email protected]>
Signed-off-by: Zeyad Gouda <[email protected]>
Signed-off-by: Zeyad Gouda <[email protected]>
Signed-off-by: Zeyad Gouda <[email protected]>
Signed-off-by: Zeyad Gouda <[email protected]>
Signed-off-by: Zeyad Gouda <[email protected]>
Signed-off-by: Zeyad Gouda <[email protected]>
Signed-off-by: Zeyad Gouda <[email protected]>
b80228a
to
96e9663
Compare
* i/systemd: support Wants/WantedBy/After/Before directives Signed-off-by: Zeyad Gouda <[email protected]> * i/builtin: add gpio-chardev interface This implements the gpio-chardev interface (spec SD129) which is currently hidden behind an experimental feature flag until kernel improvements to the gpio-aggreagtor lands. Signed-off-by: Zeyad Gouda <[email protected]> * strutil: add range parsing helper Signed-off-by: Zeyad Gouda <[email protected]> * fixup! i/builtin: use strutil.ParseRange helper Signed-off-by: Zeyad Gouda <[email protected]> * fixup! i/builtin: add source-chip validation Signed-off-by: Zeyad Gouda <[email protected]> * fixup! many: address review comments - strutil: fix range helper typo s/Intersets/Intersects - strutil: only support positive numbers in ParseRange - strutil: sort range spans in ParseRange - i/builtin/gpio-chardev: error message improvements - i/builtin/gpio-chardev: remove unnesaccery non-negative validation Signed-off-by: Zeyad Gouda <[email protected]> * fixup! strutil: typo fix and test coverage improvement Signed-off-by: Zeyad Gouda <[email protected]> * fixup! i/builtin: use dirs.DistroLibExecDir instead of fixed path Signed-off-by: Zeyad Gouda <[email protected]> * fixup! i/builtin: fix release info mocking order Signed-off-by: Zeyad Gouda <[email protected]> * tests: exclude gpio-chardev interface from document-interfaces-url Signed-off-by: Zeyad Gouda <[email protected]> * fixup! address review comments Signed-off-by: Zeyad Gouda <[email protected]> * fixup! strutil: simplify Range into a slice of RangeSpan Signed-off-by: Zeyad Gouda <[email protected]> * fixup! many: address review comments Signed-off-by: Zeyad Gouda <[email protected]> * fixup! i/builtin: fix typo of plug name using slot name Signed-off-by: Zeyad Gouda <[email protected]> --------- Signed-off-by: Zeyad Gouda <[email protected]>
* i/systemd: support Wants/WantedBy/After/Before directives Signed-off-by: Zeyad Gouda <[email protected]> * i/builtin: add gpio-chardev interface This implements the gpio-chardev interface (spec SD129) which is currently hidden behind an experimental feature flag until kernel improvements to the gpio-aggreagtor lands. Signed-off-by: Zeyad Gouda <[email protected]> * strutil: add range parsing helper Signed-off-by: Zeyad Gouda <[email protected]> * fixup! i/builtin: use strutil.ParseRange helper Signed-off-by: Zeyad Gouda <[email protected]> * fixup! i/builtin: add source-chip validation Signed-off-by: Zeyad Gouda <[email protected]> * fixup! many: address review comments - strutil: fix range helper typo s/Intersets/Intersects - strutil: only support positive numbers in ParseRange - strutil: sort range spans in ParseRange - i/builtin/gpio-chardev: error message improvements - i/builtin/gpio-chardev: remove unnesaccery non-negative validation Signed-off-by: Zeyad Gouda <[email protected]> * fixup! strutil: typo fix and test coverage improvement Signed-off-by: Zeyad Gouda <[email protected]> * fixup! i/builtin: use dirs.DistroLibExecDir instead of fixed path Signed-off-by: Zeyad Gouda <[email protected]> * fixup! i/builtin: fix release info mocking order Signed-off-by: Zeyad Gouda <[email protected]> * tests: exclude gpio-chardev interface from document-interfaces-url Signed-off-by: Zeyad Gouda <[email protected]> * fixup! address review comments Signed-off-by: Zeyad Gouda <[email protected]> * fixup! strutil: simplify Range into a slice of RangeSpan Signed-off-by: Zeyad Gouda <[email protected]> * fixup! many: address review comments Signed-off-by: Zeyad Gouda <[email protected]> * fixup! i/builtin: fix typo of plug name using slot name Signed-off-by: Zeyad Gouda <[email protected]> --------- Signed-off-by: Zeyad Gouda <[email protected]>
This implements the
gpio-chardev
interface according to the SD129 spec which is currently hidden behind an experimental feature flag until kernel improvements to thegpio-aggreagtor
lands.Also, I had to extend the systemd backend to support specifying Wants/WantedBy/After/Before directives 44562bb.