Skip to content

Add gpiod support for GPIO buzzer provider (BugFix)#2627

Open
baconYao wants to merge 1 commit into
mainfrom
support-gpiod-for-gpio-buzzer
Open

Add gpiod support for GPIO buzzer provider (BugFix)#2627
baconYao wants to merge 1 commit into
mainfrom
support-gpiod-for-gpio-buzzer

Conversation

@baconYao

@baconYao baconYao commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Description

Support GPIO buzzer testing with gpiod line-name resolution while
keeping compatibility with legacy numeric sysfs environments.

- Prefer gpiod when required tools are available, and resolve the GPIO
target by line name.
- Fall back to sysfs only when gpiod tools are unavailable, and require
a numeric port for that fallback path.
- Keep gpioset process lifecycle cleanup to avoid leaving stale line
requests after exit.
- Keep GPIO_BUZZER parsing compatible with 2-field and 3-field inputs,
preserve input order, and emit blank-line-separated records for
template job expansion.

Resolved issues

sysfs GPIO is not available for the target kernel path.

Documentation

No gpiofind command in 2.2.1-3 gpiod deb package

ubuntu@ubuntu:/var/tmp/checkbox-providers$ gpioinfo --version
gpioinfo (libgpiod) v2.2.1
Copyright (C) 2017-2023 Bartosz Golaszewski
License: GPL-2.0-or-later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

gpiod/resolute,now 2.2.1-3build1 arm64 [installed]
  Tools for interacting with Linux GPIO character device - binary

libgpiod3/resolute,now 2.2.1-3build1 arm64 [installed,automatic]
  C library for interacting with Linux GPIO device - shared libraries

ubuntu@ubuntu:/var/tmp/checkbox-providers$ gpio
gpiodetect  gpioget     gpioinfo    gpiomon     gpionotify  gpioset
flowchart TD
    A["Start buzzer_test.sh (GPIO mode)"] --> B["main -> setup_gpio_backend"]

    B --> C{"gpiod tools available?"}
    C -->|Yes| D{"resolve_gpio_by_name(port) success?"}
    D -->|No| D1["Fail: cannot resolve GPIO name"]
    D -->|Yes| E["Use gpiod backend (gpio_chip + gpio_offset)"]

    C -->|No| F["Fallback to sysfs GPIO export"]
    F --> G{"Port is numeric only?"}
    G -->|No| G1["Fail: GPIO name requires gpiod tools"]
    G -->|Yes| H{"sysfs /sys/class/gpio exists?"}
    H -->|No| H1["Fail: sysfs GPIO not available"]
    H -->|Yes| I["Use sysfs backend, export_gpio, set direction"]

    E --> J["Enable buzzer"]
    I --> J

    J --> K{"Backend is gpiod?"}
    K -->|Yes| L{"run_gpioset(enable) success?"}
    L -->|No| L1["Fail: unable to set GPIO"]
    L -->|Yes| M["Ask user: buzzer audible? (y/n)"]
    K -->|No| N["Write enable to sysfs value"]
    N --> M

    M --> O{"User answered y?"}
    O -->|No| O1["Result: FAILED"]
    O -->|Yes| P["Disable buzzer"]

    P --> Q{"Backend is gpiod?"}
    Q -->|Yes| R{"run_gpioset(disable) success?"}
    R -->|No| R1["Fail: unable to clear GPIO"]
    R -->|Yes| S["Ask user: buzzer stopped? (y/n)"]
    Q -->|No| T["Write disable to sysfs value"]
    T --> S

    S --> U{"User answered y?"}
    U -->|No| U1["Result: FAILED"]
    U -->|Yes| V["Result: PASSED"]

    D1 --> W["EXIT trap: cleanup_gpioset"]
    G1 --> W
    H1 --> W
    L1 --> W
    R1 --> W
    O1 --> W
    U1 --> W
    V --> W
    W --> END["End"]
Loading

Tests

Submission: https://certification.canonical.com/hardware/202605-38787/submission/498126/test-results/?term=gpio-buzzer

  • env: GPIO_BUZZER=BUZZER_EN:1 FAKE_TEST:1
    • BUZZER_EN is real gpio buzzer to prove the pass scenraio
    • FAKE_TEST is dummy buzzer to prove the failed scenraio
ubuntu@ubuntu:/sys/devices$ sudo gpioinfo -c gpiochip15
gpiochip15 - 16 lines:
	line   0:	"5V_GOOD"       	input
	line   1:	"LVD"           	input
	line   2:	"BUZZER_EN"     	output
	line   3:	"4G_RST"        	input
	line   4:	"4G_LED"        	input
	line   5:	"USER_LED"      	input
	line   6:	unnamed         	input
	line   7:	unnamed         	input
	line   8:	unnamed         	input
	line   9:	unnamed         	input
	line  10:	unnamed         	input
	line  11:	unnamed         	input
	line  12:	unnamed         	input
	line  13:	unnamed         	input
	line  14:	unnamed         	input
	line  15:	unnamed         	input

Copilot AI review requested due to automatic review settings June 30, 2026 05:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the CE-OEM buzzer provider to support running GPIO buzzer tests via libgpiod tools (gpioset/gpioget/gpioinfo) while preserving fallback behavior for legacy sysfs GPIO environments, and extends the GPIO_BUZZER resource format to support both global GPIO numbers and chip:line addressing.

Changes:

  • Extend GPIO_BUZZER resource parsing to accept both 3-field and 4-field formats, preserve entry order, and separate records with blank lines.
  • Add a gpiod-based backend to buzzer_test.sh, including chip/line resolution, global GPIO mapping, and gpioset lifecycle cleanup.
  • Update buzzer job templates to pass through chip:line ports to the test script.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/buzzer/jobs.pxu Extends GPIO_BUZZER parsing and formatting to emit multiple ordered resource records and support chip:line.
contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/buzzer_test.sh Adds gpiod backend selection + gpioset control with cleanup, and keeps sysfs fallback for legacy GPIO.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@baconYao
baconYao requested a review from a team June 30, 2026 05:09
Support GPIO buzzer testing with gpiod line-name resolution while
keeping compatibility with legacy numeric sysfs environments.

- Prefer gpiod when required tools are available, and resolve the GPIO
target by line name.
- Fall back to sysfs only when gpiod tools are unavailable, and require
a numeric port for that fallback path.
- Keep gpioset process lifecycle cleanup to avoid leaving stale line
requests after exit.
- Keep GPIO_BUZZER parsing compatible with 2-field and 3-field inputs,
preserve input order, and emit blank-line-separated records for
template job expansion.

Signed-off-by: baconYao <bacon735392@gmail.com>
@baconYao
baconYao force-pushed the support-gpiod-for-gpio-buzzer branch from 4bc89b1 to 8946a5f Compare July 1, 2026 08:40
@baconYao baconYao added the ce-oem The PR only contains to the ce-oem provider under the contrib area label Jul 2, 2026
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.83%. Comparing base (55dc4ff) to head (8946a5f).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2627   +/-   ##
=======================================
  Coverage   59.83%   59.83%           
=======================================
  Files         485      485           
  Lines       48736    48736           
  Branches     8728     8728           
=======================================
  Hits        29160    29160           
  Misses      18658    18658           
  Partials      918      918           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ce-oem The PR only contains to the ce-oem provider under the contrib area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants