tests: drivers: move the maxim_ds3231 counter test to new ztest API
Migrate the testsuite tests/drivers/counter/maxim_ds3231_api to
the new ztest API.
Signed-off-by: Enjia Mai <enjia.mai@intel.com>
diff --git a/tests/drivers/counter/maxim_ds3231_api/prj.conf b/tests/drivers/counter/maxim_ds3231_api/prj.conf
index 7efb84a..ca17466 100644
--- a/tests/drivers/counter/maxim_ds3231_api/prj.conf
+++ b/tests/drivers/counter/maxim_ds3231_api/prj.conf
@@ -4,5 +4,6 @@
CONFIG_COUNTER_INIT_PRIORITY=65
CONFIG_BT=n
CONFIG_ZTEST=y
+CONFIG_ZTEST_NEW_API=y
CONFIG_TEST_USERSPACE=y
CONFIG_LOG=y
diff --git a/tests/drivers/counter/maxim_ds3231_api/src/test_counter.c b/tests/drivers/counter/maxim_ds3231_api/src/test_counter.c
index ccacfab..044aad3 100644
--- a/tests/drivers/counter/maxim_ds3231_api/src/test_counter.c
+++ b/tests/drivers/counter/maxim_ds3231_api/src/test_counter.c
@@ -333,13 +333,13 @@
set_top_value_capable(dev);
}
-void test_single_shot_alarm_notop(void)
+ZTEST(counter_callback, test_single_shot_alarm_notop)
{
test_all_instances(test_single_shot_alarm_notop_instance,
single_channel_alarm_capable);
}
-void test_single_shot_alarm_top(void)
+ZTEST(counter_callback, test_single_shot_alarm_top)
{
test_all_instances(test_single_shot_alarm_top_instance,
single_channel_alarm_and_custom_top_capable);
@@ -439,7 +439,7 @@
return false;
}
-void test_multiple_alarms(void)
+ZTEST(counter_callback, test_multiple_alarms)
{
/* Test not supported on DS3231 because second alarm resolution is
* more coarse than first alarm; code would have to be changed to
@@ -509,7 +509,7 @@
}
}
-void test_all_channels(void)
+ZTEST(counter_z, test_all_channels)
{
test_all_instances(test_all_channels_instance,
single_channel_alarm_capable);
@@ -620,12 +620,12 @@
return true;
}
-void test_late_alarm(void)
+ZTEST(counter_callback, test_late_alarm)
{
test_all_instances(test_late_alarm_instance, late_detection_capable);
}
-void test_late_alarm_error(void)
+ZTEST(counter_callback, test_late_alarm_error)
{
test_all_instances(test_late_alarm_error_instance,
late_detection_capable);
@@ -711,7 +711,7 @@
return ret;
}
-static void test_short_relative_alarm(void)
+ZTEST(counter_callback, test_short_relative_alarm)
{
test_all_instances(test_short_relative_alarm_instance,
short_relative_capable);
@@ -823,7 +823,7 @@
return false;
}
-void test_cancelled_alarm_does_not_expire(void)
+ZTEST(counter_callback, test_cancelled_alarm_does_not_expire)
{
test_all_instances(test_cancelled_alarm_does_not_expire_instance,
reliable_cancel_capable);
@@ -857,7 +857,7 @@
"%s: Sync operation failed: %d", dev->name, res);
}
-static void test_ds3231_get_syncpoint(void)
+static void ds3231_get_syncpoint(void)
{
const struct device *dev = devices[0];
struct maxim_ds3231_syncpoint syncpoint;
@@ -894,7 +894,20 @@
"%s: Syncpoint operation failed: %d\n", dev->name, rc);
}
-void test_main(void)
+ZTEST(counter_supervisor, test_ds3231_get_syncpoint)
+{
+ test_ds3231_synchronize();
+ ds3231_get_syncpoint();
+}
+
+ZTEST_USER(counter_user, test_ds3231_get_syncpoint)
+{
+ test_ds3231_req_syncpoint();
+ ds3231_get_syncpoint();
+}
+
+
+static void *counter_setup(void)
{
int i;
@@ -919,27 +932,17 @@
k_object_access_grant(devices[i], k_current_get());
}
- ztest_test_suite(test_counter,
- /* Uses callbacks, run in supervisor mode */
- ztest_unit_test(test_set_top_value_with_alarm),
- ztest_unit_test(test_single_shot_alarm_notop),
- ztest_unit_test(test_single_shot_alarm_top),
- ztest_unit_test(test_multiple_alarms),
- ztest_unit_test(test_late_alarm),
- ztest_unit_test(test_late_alarm_error),
- ztest_unit_test(test_short_relative_alarm),
- ztest_unit_test(test_cancelled_alarm_does_not_expire),
-
- /* Supervisor-mode driver-specific API */
- ztest_unit_test(test_ds3231_synchronize),
- ztest_unit_test(test_ds3231_get_syncpoint),
-
- /* User-mode-compatible driver-specific API*/
- ztest_unit_test(test_ds3231_req_syncpoint),
- ztest_user_unit_test(test_ds3231_get_syncpoint),
-
- /* Supervisor-mode test, takes 63 s so do it last */
- ztest_unit_test(test_all_channels)
- );
- ztest_run_test_suite(test_counter);
+ return NULL;
}
+
+/* Uses callbacks, run in supervisor mode */
+ZTEST_SUITE(counter_callback, NULL, counter_setup, NULL, NULL, NULL);
+
+/* Supervisor-mode driver-specific API */
+ZTEST_SUITE(counter_supervisor, NULL, NULL, NULL, NULL, NULL);
+
+/* User-mode-compatible driver-specific API*/
+ZTEST_SUITE(counter_user, NULL, NULL, NULL, NULL, NULL);
+
+/* Supervisor-mode test, takes 63 s so do it last */
+ZTEST_SUITE(counter_z, NULL, NULL, NULL, NULL, NULL);