Skip to content
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

[Backport v3.7.99-ncs1-branch] tests: drivers: adc: add adc_error_cases tests. #2206

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

static const struct device *dev_adc = DEVICE_DT_GET(DT_ALIAS(adc));
#define BUFFER_LEN 8
uint16_t m_sample_buffer[BUFFER_LEN];
static uint16_t m_sample_buffer[BUFFER_LEN];

static struct adc_channel_cfg valid_channel_cfg = {
static const struct adc_channel_cfg valid_channel_cfg = {
.gain = ADC_GAIN_1,
.channel_id = 0,
.reference = ADC_REF_INTERNAL,
Expand All @@ -22,13 +22,13 @@
#ifdef CONFIG_ADC_CONFIGURABLE_INPUTS
.input_positive = 1,
#endif
};

Check notice on line 25 in tests/drivers/adc/adc_error_cases/src/adc_error_cases.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/drivers/adc/adc_error_cases/src/adc_error_cases.c:25 - #ifdef CONFIG_ADC_CONFIGURABLE_INPUTS +#ifdef CONFIG_ADC_CONFIGURABLE_INPUTS .input_positive = 1, - #endif +#endif

static struct adc_sequence valid_seq = {
static const struct adc_sequence valid_seq = {
.buffer = m_sample_buffer,
.buffer_size = BUFFER_LEN * sizeof(uint16_t),
.buffer_size = BUFFER_LEN * sizeof(m_sample_buffer),
.options = NULL,
.resolution = 8,
.resolution = 10,
.oversampling = 0,
.channels = 1,
};
Expand Down Expand Up @@ -57,7 +57,7 @@
" got unexpected value of %d",
ret
);
}

Check notice on line 60 in tests/drivers/adc/adc_error_cases/src/adc_error_cases.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/drivers/adc/adc_error_cases/src/adc_error_cases.c:60 - zassert_true( - ret == -EINVAL, - "adc_read() should return -EINVAL," - " got unexpected value of %d", - ret - ); + zassert_true(ret == -EINVAL, + "adc_read() should return -EINVAL," + " got unexpected value of %d", + ret);

/**
* @brief test adc_read() with invalid resolution value
Expand All @@ -83,7 +83,7 @@
" got unexpected value of %d",
ret
);
}

Check notice on line 86 in tests/drivers/adc/adc_error_cases/src/adc_error_cases.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/drivers/adc/adc_error_cases/src/adc_error_cases.c:86 - zassert_true( - ret == -EINVAL, - "adc_read() should return -EINVAL," - " got unexpected value of %d", - ret - ); + zassert_true(ret == -EINVAL, + "adc_read() should return -EINVAL," + " got unexpected value of %d", + ret);

/**
* @brief test adc_read() with invalid channels value
Expand All @@ -109,7 +109,7 @@
" got unexpected value of %d",
ret
);
}

Check notice on line 112 in tests/drivers/adc/adc_error_cases/src/adc_error_cases.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/drivers/adc/adc_error_cases/src/adc_error_cases.c:112 - zassert_true( - ret == -EINVAL, - "adc_read() should return -EINVAL," - " got unexpected value of %d", - ret - ); + zassert_true(ret == -EINVAL, + "adc_read() should return -EINVAL," + " got unexpected value of %d", + ret);

/**
* @brief test adc_read() with not configured channel
Expand All @@ -125,7 +125,7 @@

struct adc_sequence invalid_seq = valid_seq;
/* Set channels configuration to use not configured channel */
invalid_seq.channels = 2;
invalid_seq.channels = BIT(1);

ret = adc_read(dev_adc, &invalid_seq);

Expand All @@ -135,7 +135,7 @@
" got unexpected value of %d",
ret
);
}

Check notice on line 138 in tests/drivers/adc/adc_error_cases/src/adc_error_cases.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/drivers/adc/adc_error_cases/src/adc_error_cases.c:138 - zassert_true( - ret == -EINVAL, - "adc_read() should return -EINVAL," - " got unexpected value of %d", - ret - ); + zassert_true(ret == -EINVAL, + "adc_read() should return -EINVAL," + " got unexpected value of %d", + ret);

/**
* @brief test adc_read() with invalid buffer length
Expand All @@ -161,7 +161,7 @@
" got unexpected value of %d",
ret
);
}

Check notice on line 164 in tests/drivers/adc/adc_error_cases/src/adc_error_cases.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/drivers/adc/adc_error_cases/src/adc_error_cases.c:164 - zassert_true( - ret == -ENOMEM, - "adc_read() should return -ENOMEM," - " got unexpected value of %d", - ret - ); + zassert_true(ret == -ENOMEM, + "adc_read() should return -ENOMEM," + " got unexpected value of %d", + ret);

/**
* @brief test adc_channel_setup() with invalid reference value
Expand All @@ -185,7 +185,7 @@
" got unexpected value of %d",
ret
);
}

Check notice on line 188 in tests/drivers/adc/adc_error_cases/src/adc_error_cases.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/drivers/adc/adc_error_cases/src/adc_error_cases.c:188 - zassert_true( - ret == -EINVAL, - "adc_channel_setup() should return -EINVAL," - " got unexpected value of %d", - ret - ); + zassert_true(ret == -EINVAL, + "adc_channel_setup() should return -EINVAL," + " got unexpected value of %d", + ret);

/**
* @brief test adc_read() with invalid gain value
Expand All @@ -207,32 +207,8 @@
" got unexpected value of %d",
ret
);
}

Check notice on line 210 in tests/drivers/adc/adc_error_cases/src/adc_error_cases.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/drivers/adc/adc_error_cases/src/adc_error_cases.c:210 - zassert_true( - ret == -EINVAL, - "adc_channel_setup() should return -EINVAL," - " got unexpected value of %d", - ret - ); + zassert_true(ret == -EINVAL, + "adc_channel_setup() should return -EINVAL," + " got unexpected value of %d", + ret);

/**
* @brief test adc_read() with invalid acquisition time
*
* function should return -EINVAL
*/

ZTEST(adc_error_cases, test_adc_setup_invalid_acquisition_time)
{
int ret;

struct adc_channel_cfg invalid_channel_cfg = valid_channel_cfg;
/* set invalid acquisition_time value */
invalid_channel_cfg.acquisition_time = 16384;

ret = adc_channel_setup(dev_adc, &invalid_channel_cfg);

zassert_true(
ret == -EINVAL,
"adc_channel_setup() should return -EINVAL,"
" got unexpected value of %d",
ret
);
}

static void *suite_setup(void)
{
TC_PRINT("Test executed on %s\n", CONFIG_BOARD_TARGET);
Expand Down
6 changes: 1 addition & 5 deletions tests/drivers/adc/adc_error_cases/testcase.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
common:
tags:
- adc
- drivers
tests:
drivers.adc_error_cases:
depends_on: adc
platform_allow:
- nrf52840dk/nrf52840
- nrf54l15pdk/nrf54l15/cpuapp
- nrf54l15dk/nrf54l15/cpuapp
- nrf54h20dk/nrf54h20/cpuapp
Loading