Skip to content

Introduced new test suite for PWM protocol- basic test#90

Open
CPPavithra wants to merge 2 commits intobeagleboard:mainfrom
CPPavithra:edge-testcases
Open

Introduced new test suite for PWM protocol- basic test#90
CPPavithra wants to merge 2 commits intobeagleboard:mainfrom
CPPavithra:edge-testcases

Conversation

@CPPavithra
Copy link
Contributor

This PR adds the initial integration test infrastructure for the PWM protocol.
-> Uses native_sim board target.
-> Uses the vnd,pwm (Vendor PWM) driver instead of pwm_fake to avoid linker dependency issues with the FFF library on Zephyr 4.2.0.
-> Validates the control protocol version handshake.
-> Validates that the Greybus stack correctly routes GB_PWM_TYPE_PWM_COUNT to the driver and returns a response on the correct CPort.
-> Target: native_sim
-> Command: west build -p always -b native_sim tests/greybus/integration/pwm -t run
-> Result: PROJECT EXECUTION SUCCESSFUL

if (resp.msg == NULL) {
zassert_not_null(resp.msg, "Greybus stack did not respond on CPort %d", pwm_cport);
}
zassert_equal(resp.cport, pwm_cport, "Response received on wrong CPort");
Copy link
Member

Choose a reason for hiding this comment

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

This test doesn't really test anything. Should check the response.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. I have updated the test to explicitly verify the payload.

Note: The vnd,pwm driver on native_sim reports 0 channels by default. I added an assertion for count >= 0 and GB_OP_SUCCESS. This proves the stack correctly routed the request and packed the response structure, satisfying the integration test requirements.

integration_platforms:
- native_sim
tags: test_framework
tags: greybus pwm
Copy link
Member

Choose a reason for hiding this comment

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

Why these random tags?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. I've standardized the tags to just greybus. I must have missed that from my testing setup.

@CPPavithra CPPavithra force-pushed the edge-testcases branch 2 times, most recently from 492f9c3 to 3aa096f Compare February 5, 2026 18:58

zassert_equal(resp.cport, pwm_cport, "Response received on wrong CPort");

zassert_equal(resp.msg->header.type, GB_PWM_TYPE_PWM_COUNT | GB_TYPE_RESPONSE_FLAG,
Copy link
Member

Choose a reason for hiding this comment

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

There is a helper macro GB_RESPONSE. Use that.


/*The vnd,pwm driver on native_sim might report 0 channels depending on the overlay
* configuration. We verify that the value is readable (>=0).*/
printk("PWM Driver reported %d channels\n", pwm_resp->count);
Copy link
Member

Choose a reason for hiding this comment

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

Better to use Logs rather than normal print

@CPPavithra CPPavithra force-pushed the edge-testcases branch 2 times, most recently from a904c73 to 0b16d94 Compare February 7, 2026 10:34
#include <zephyr/sys/byteorder.h>
#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(greybus_pwm_test, LOG_LEVEL_INF);
Copy link
Member

Choose a reason for hiding this comment

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

I would just use the CONFIG_GREYBUS_LOG_LEVEL instead of hardcoding to info.

resp = gb_transport_get_message();
zassert_not_null(resp.msg, "No version response received");

zassert_equal(resp.msg->header.result, GB_OP_SUCCESS, "Version handshake failed");
Copy link
Member

Choose a reason for hiding this comment

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

Use gb_message_is_success helper function that already exists.

zassert_equal(resp.msg->header.result, GB_OP_SUCCESS, "Operation failed with error: %d",
resp.msg->header.result);

struct gb_pwm_count_response *pwm_resp = (struct gb_pwm_count_response *)resp.msg->payload;
Copy link
Member

Choose a reason for hiding this comment

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

Probably make this a const. Also, I prefer forward declaration.

zassert_not_null(resp.msg, "No enable response received");
zassert_equal(resp.msg->header.type, GB_RESPONSE(GB_PWM_TYPE_ENABLE), "Wrong Type");

if (resp.msg->header.result != GB_OP_SUCCESS) {
Copy link
Member

Choose a reason for hiding this comment

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

No need. Just make anything you want to print part of zassert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated the assertions as requested (removed the conditional logic).

CI Status- The enable and disable tests are now showing as Failed (Red) in the CI.
This is as per expected. The test is correctly catching that the driver returns error 254 because ofIssue #55(Driver reports 0 channels).
This confirms the test suite is working and successfully reproducing the driver issue.

The rest of the feedback has also been implemented.

Copy link
Member

Choose a reason for hiding this comment

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

No, the curret issue is that driver will report 1 channel, not 0 (

static struct gb_pwm_channel_data gb_pwm_channel_data_arr_##_idx[1]; \
). This might be some other bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, the curret issue is that driver will report 1 channel, not 0 (

static struct gb_pwm_channel_data gb_pwm_channel_data_arr_##_idx[1]; \

). This might be some other bug.

Oh, I see, so i think this definitely points to a functional bug in the simulation backend or binding.
Since this test is correctly catching that bug, CI is now failing (red), which prevents merging.

So how would you prefer I handle this?
-> Should I mark the enable/disable tests as ZTEST_SKIP() for now (with a comment linking to the bug) so we can merge the test infrastructure?
-> Or should I leave this PR open and try to debug/fix the native_sim driver issue as part of this PR?

Copy link
Member

@Ayush1325 Ayush1325 Feb 8, 2026

Choose a reason for hiding this comment

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

You fix the issue as part of this PR, just a separate commit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just tried using debug logs in the pwm-protocols, and running the test again for much better clarity. It returns -95 (EOPNOTSUPP) (when i cross-referenced it with the docs)
I think this confirms that the existing native_sim driver I used (vnd,pwm) does not fully support enable/disable operations requested.

Screenshot from 2026-02-08 16-34-31

Since vnd,pwm is part of the core Zephyr tree (not this repo), fixing the driver would require an upstream PR to Zephyr, which is outside the scope of this PR. I can probably dive deeper into the issue and I can open a follow-up PR later to add a custom Mock PWM driver if we really need full coverage.

image

Copy link
Member

Choose a reason for hiding this comment

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

Doing a bit of grepping, I think you want to use zephyr,fake-pwm instead of vnd,pwm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doing a bit of grepping, I think you want to use zephyr,fake-pwm instead of vnd,pwm.

The zephyr,fake-pwm edit worked :) I have implemented the fix in a separate commit as requested.
Changes:
-> Replaced vnd,pwm with the upstream zephyr,fake-pwm driver in the overlay.
-> Enabled CONFIG_PWM_FAKE and FFF to correctly mock the hardware response on native_sim.

Signed-off-by: CPPavithra <cppavithra05@gmail.com>
Signed-off-by: CPPavithra <cppavithra05@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants