Skip to content

Commit 8525944

Browse files
Niranjhana Nnashif
authored andcommitted
tests: power: refactor power_states test
Refactored test to work with ztest framework and to calculate and display time in milliseconds for each power state. Signed-off-by: Niranjhana N <niranjhana.n@intel.com>
1 parent e21e6c1 commit 8525944

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

tests/power/power_states/prj.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
CONFIG_TEST=y
1+
CONFIG_ZTEST=y
2+
CONFIG_ARC_INIT=n
23
CONFIG_SYS_POWER_MANAGEMENT=y
34
CONFIG_SYS_POWER_DEEP_SLEEP=y
45
CONFIG_SYS_POWER_LOW_POWER_STATE=y

tests/power/power_states/prj_socwatch.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
CONFIG_TEST=y
1+
CONFIG_ZTEST=y
2+
CONFIG_ARC_INIT=n
23
CONFIG_SYS_POWER_MANAGEMENT=y
34
CONFIG_SYS_POWER_DEEP_SLEEP=n
45
CONFIG_SYS_POWER_LOW_POWER_STATE=y

tests/power/power_states/src/main.c

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <gpio.h>
1313
#include <counter.h>
1414
#include <aio_comparator.h>
15-
15+
#include <ztest.h>
1616
#include <power.h>
1717
#include <soc_power.h>
1818
#include <string.h>
@@ -51,6 +51,7 @@ static struct device *suspend_devices[MAX_SUSPEND_DEVICE_COUNT];
5151
static int suspend_device_count;
5252
static unsigned int current_state = NB_STATES - 1;
5353
static int post_ops_done = 1;
54+
static s64_t start_time, milliseconds_spent;
5455
static int test_complete;
5556

5657
static enum power_states get_next_state(void)
@@ -121,10 +122,8 @@ static void setup_counter(void)
121122

122123
counter_dev = device_get_binding("AON_TIMER");
123124

124-
if (!counter_dev) {
125-
printk("Timer device not found\n");
126-
return;
127-
}
125+
/* TESTPOINT: Check timer device binding */
126+
zassert_true(counter_dev, "timer device not found.");
128127

129128
counter_start(counter_dev);
130129

@@ -153,10 +152,9 @@ static struct device *gpio_dev;
153152
static void setup_aon_gpio(void)
154153
{
155154
gpio_dev = device_get_binding("GPIO_1");
156-
if (!gpio_dev) {
157-
printk("gpio device not found.\n");
158-
return;
159-
}
155+
156+
/* TESTPOINT: Check gpio device binding */
157+
zassert_true(gpio_dev, "gpio device not found.");
160158

161159
gpio_pin_configure(gpio_dev, GPIO_INTERRUPT_PIN,
162160
GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
@@ -171,10 +169,9 @@ static void setup_aon_comparator(void)
171169
volatile u32_t delay = 0;
172170

173171
cmp_dev = device_get_binding("AIO_CMP_0");
174-
if (!cmp_dev) {
175-
printk("comparator device not found.\n");
176-
return;
177-
}
172+
173+
/* TESTPOINT: Check comparator device binding */
174+
zassert_true(cmp_dev, "comparator device not found.");
178175

179176
/* Wait for the comparator to be grounded. */
180177
printk("USER_ACTION: Ground the comparator pin.\n");
@@ -250,6 +247,7 @@ int _sys_soc_suspend(s32_t ticks)
250247
{
251248
enum power_states state;
252249
int pm_operation = SYS_PM_NOT_HANDLED;
250+
253251
post_ops_done = 0;
254252

255253
if ((ticks != K_FOREVER) && (ticks < MIN_TIME_TO_SUSPEND)) {
@@ -258,7 +256,7 @@ int _sys_soc_suspend(s32_t ticks)
258256
return SYS_PM_NOT_HANDLED;
259257
}
260258

261-
/* If test is comepleted then do not enter LPS states */
259+
/* If test is completed then do not enter LPS states */
262260
if (test_complete) {
263261
return SYS_PM_NOT_HANDLED;
264262
}
@@ -361,12 +359,12 @@ static void build_suspend_device_list(void)
361359
struct device *devices;
362360

363361
device_list_get(&devices, &devcount);
364-
if (devcount > MAX_SUSPEND_DEVICE_COUNT) {
365-
printk("Error: List of devices exceeds what we can track "
366-
"for suspend. Built: %d, Max: %d\n",
367-
devcount, MAX_SUSPEND_DEVICE_COUNT);
368-
return;
369-
}
362+
363+
/* TESTPOINT: Check if device list is in tracking range */
364+
zassert_false((devcount > MAX_SUSPEND_DEVICE_COUNT),
365+
"Error: List of devices exceeds what we can track "
366+
"for suspend. Built: %d, Max: %d",
367+
devcount, MAX_SUSPEND_DEVICE_COUNT);
370368

371369
#if (CONFIG_X86)
372370
suspend_device_count = 3;
@@ -396,9 +394,10 @@ static void build_suspend_device_list(void)
396394
#endif
397395
}
398396

399-
void main(void)
397+
void test_power_state(void)
400398
{
401399
int i;
400+
402401
printk("Quark SE(%s): Power Management sample application\n",
403402
CONFIG_ARCH);
404403

@@ -421,10 +420,19 @@ void main(void)
421420
* triggers the suspend operation.
422421
*/
423422
for (i = 0; i < MAX_SYS_PM_STATES; i++) {
423+
start_time = k_uptime_get();
424424
k_sleep(TIMEOUT * 1000);
425-
printk("Back to the application\n");
425+
milliseconds_spent = k_uptime_delta(&start_time);
426+
printk("Time elapsed from suspend to resume is %lld milliseconds\n",
427+
milliseconds_spent);
428+
printk("Back to the application\n\n");
426429
}
427430
test_complete = 1;
431+
}
428432

429-
printk("**Power States test complete**\n");
433+
void test_main(void)
434+
{
435+
ztest_test_suite(test_power_states,
436+
ztest_unit_test(test_power_state));
437+
ztest_run_test_suite(test_power_states);
430438
}

0 commit comments

Comments
 (0)