|
10 | 10 | */ |
11 | 11 |
|
12 | 12 | #include <zephyr/kernel.h> |
| 13 | +#include <zephyr/audio/audio_caps.h> |
13 | 14 | #include <zephyr/audio/dmic.h> |
14 | 15 | #include <zephyr/ztest.h> |
15 | 16 |
|
@@ -291,4 +292,64 @@ ZTEST(dmic, test_bad_pair) |
291 | 292 | "non adjacent channels in map"); |
292 | 293 | } |
293 | 294 |
|
| 295 | +/** |
| 296 | + * @brief Test the dmic_get_caps API function |
| 297 | + * |
| 298 | + * This test validates the DMIC get_caps API functionality by testing both |
| 299 | + * successful operation and error handling scenarios. |
| 300 | + */ |
| 301 | +ZTEST(dmic, test_get_caps) |
| 302 | +{ |
| 303 | + int ret; |
| 304 | + struct audio_caps caps; |
| 305 | + |
| 306 | + zassert_true(device_is_ready(dmic_dev), "DMIC device is not ready"); |
| 307 | + |
| 308 | + /** |
| 309 | + * Test Case 1: Normal operation - Valid parameters |
| 310 | + * Expected: Function should return 0 (success) or -ENOSYS (not implemented) |
| 311 | + */ |
| 312 | + ret = dmic_get_caps(dmic_dev, &caps); |
| 313 | + |
| 314 | + /* Handle case where driver doesn't implement get_caps */ |
| 315 | + if (ret == -ENOSYS) { |
| 316 | + TC_PRINT("DMIC get_caps not implemented by driver\n"); |
| 317 | + ztest_test_skip(); |
| 318 | + return; |
| 319 | + } |
| 320 | + |
| 321 | + /* Verify successful execution */ |
| 322 | + zassert_equal(ret, 0, "dmic_get_caps should return 0, got %d", ret); |
| 323 | + |
| 324 | + /** |
| 325 | + * Test Case 2: Capability value validation |
| 326 | + * Verify that returned capability values are within reasonable ranges |
| 327 | + */ |
| 328 | + zassert_true(caps.min_total_channels >= 1, "min_total_channels should be >= 1, got %d", |
| 329 | + caps.min_total_channels); |
| 330 | + |
| 331 | + zassert_true(caps.max_total_channels >= caps.min_total_channels, |
| 332 | + "max_total_channels (%u) should be >= min_total_channels (%u)", |
| 333 | + caps.max_total_channels, caps.min_total_channels); |
| 334 | + |
| 335 | + zassert_not_equal(caps.supported_sample_rates, 0, "supported_sample_rates should not be 0"); |
| 336 | + |
| 337 | + zassert_not_equal(caps.supported_bit_widths, 0, "supported_bit_widths should not be 0"); |
| 338 | + |
| 339 | + zassert_true(caps.min_num_buffers >= 1, "min_num_buffers should be >= 1, got %u", |
| 340 | + caps.min_num_buffers); |
| 341 | + |
| 342 | + zassert_true(caps.max_frame_interval >= caps.min_frame_interval, |
| 343 | + "max_frame_interval (%u) should be >= min_frame_interval (%u)", |
| 344 | + caps.max_frame_interval, caps.min_frame_interval); |
| 345 | + |
| 346 | + /** |
| 347 | + * Test Case 3: Error handling - NULL caps pointer |
| 348 | + * Expected: Function should return -EINVAL for invalid parameter |
| 349 | + */ |
| 350 | + ret = dmic_get_caps(dmic_dev, NULL); |
| 351 | + zassert_equal(ret, -EINVAL, |
| 352 | + "dmic_get_caps should return -EINVAL for NULL caps pointer, got %d", ret); |
| 353 | +} |
| 354 | + |
294 | 355 | ZTEST_SUITE(dmic, NULL, NULL, NULL, NULL, NULL); |
0 commit comments