[sw/testing] Add aon_timer_testutils

Create aon_timer_wakeup_config in aon_timer_testutils.
Change pwrmgr_smoketest to use testutils.

Signed-off-by: Guillermo Maturana <maturana@google.com>
diff --git a/sw/device/lib/testing/aon_timer_testutils.c b/sw/device/lib/testing/aon_timer_testutils.c
new file mode 100644
index 0000000..c735f7b
--- /dev/null
+++ b/sw/device/lib/testing/aon_timer_testutils.c
@@ -0,0 +1,31 @@
+// Copyright lowRISC contributors.
+// Licensed under the Apache License, Version 2.0, see LICENSE for details.
+// SPDX-License-Identifier: Apache-2.0
+
+#include "sw/device/lib/testing/aon_timer_testutils.h"
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "sw/device/lib/base/mmio.h"
+#include "sw/device/lib/dif/dif_aon_timer.h"
+#include "sw/device/lib/testing/check.h"
+
+#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
+
+void aon_timer_testutils_wakeup_config(dif_aon_timer_t *aon_timer,
+                                       uint32_t cycles) {
+  // Make sure that wake-up timer is stopped.
+  CHECK(dif_aon_timer_wakeup_stop(aon_timer) == kDifAonTimerOk);
+
+  // Make sure the wake-up IRQ is cleared to avoid false positive.
+  CHECK(dif_aon_timer_irq_acknowledge(
+            aon_timer, kDifAonTimerIrqWakeupThreshold) == kDifAonTimerOk);
+
+  bool is_pending;
+  CHECK(dif_aon_timer_irq_is_pending(aon_timer, kDifAonTimerIrqWakeupThreshold,
+                                     &is_pending) == kDifAonTimerOk);
+  CHECK(!is_pending);
+
+  CHECK(dif_aon_timer_wakeup_start(aon_timer, cycles, 0) == kDifAonTimerOk);
+}
diff --git a/sw/device/lib/testing/aon_timer_testutils.h b/sw/device/lib/testing/aon_timer_testutils.h
new file mode 100644
index 0000000..d439cd7
--- /dev/null
+++ b/sw/device/lib/testing/aon_timer_testutils.h
@@ -0,0 +1,19 @@
+// Copyright lowRISC contributors.
+// Licensed under the Apache License, Version 2.0, see LICENSE for details.
+// SPDX-License-Identifier: Apache-2.0
+
+#ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_AON_TIMER_TESTUTILS_H_
+#define OPENTITAN_SW_DEVICE_LIB_TESTING_AON_TIMER_TESTUTILS_H_
+
+#include <stdint.h>
+
+#include "sw/device/lib/dif/dif_aon_timer.h"
+
+/**
+ * Set an aon timer for a number of AON clock cycles.
+ * @param cycles The number of AON clock cycles.
+ */
+void aon_timer_testutils_wakeup_config(dif_aon_timer_t *aon_timer,
+                                       uint32_t cycles);
+
+#endif  // OPENTITAN_SW_DEVICE_LIB_TESTING_AON_TIMER_TESTUTILS_H_
diff --git a/sw/device/lib/testing/meson.build b/sw/device/lib/testing/meson.build
index 7ecbe27..cd44d5a 100644
--- a/sw/device/lib/testing/meson.build
+++ b/sw/device/lib/testing/meson.build
@@ -7,7 +7,22 @@
   link_with: static_library(
     'sw_lib_testing_rand_testutils',
     sources: ['rand_testutils.c'],
-  )
+  ),
+)
+
+# aon_timer test utilities.
+sw_lib_testing_aon_timer_testutils = declare_dependency(
+  link_with: static_library(
+    'sw_lib_testing_aon_timer_testutils',
+    sources: [
+      'aon_timer_testutils.c'
+    ],
+    dependencies: [
+      sw_lib_mmio,
+      sw_lib_dif_aon_timer,
+      top_earlgrey,
+    ],
+  ),
 )
 
 # hardware entropy complex (entropy_src, csrng, edn) test utilities.
diff --git a/sw/device/tests/meson.build b/sw/device/tests/meson.build
index 9680374..514ba5d 100644
--- a/sw/device/tests/meson.build
+++ b/sw/device/tests/meson.build
@@ -293,7 +293,7 @@
     dependencies: [
       sw_lib_dif_pwrmgr,
       sw_lib_dif_rstmgr,
-      sw_lib_dif_aon_timer,
+      sw_lib_testing_aon_timer_testutils,
       sw_lib_mmio,
       sw_lib_runtime_log,
     ],
diff --git a/sw/device/tests/pwrmgr_smoketest.c b/sw/device/tests/pwrmgr_smoketest.c
index be81b5f..958f3ed 100644
--- a/sw/device/tests/pwrmgr_smoketest.c
+++ b/sw/device/tests/pwrmgr_smoketest.c
@@ -3,10 +3,10 @@
 // SPDX-License-Identifier: Apache-2.0
 
 #include "sw/device/lib/base/mmio.h"
-#include "sw/device/lib/dif/dif_aon_timer.h"
 #include "sw/device/lib/dif/dif_pwrmgr.h"
 #include "sw/device/lib/dif/dif_rstmgr.h"
 #include "sw/device/lib/runtime/log.h"
+#include "sw/device/lib/testing/aon_timer_testutils.h"
 #include "sw/device/lib/testing/check.h"
 #include "sw/device/lib/testing/test_framework/test_main.h"
 
@@ -30,28 +30,9 @@
          lhs->request_sources == rhs->request_sources;
 }
 
-void aon_timer_wakeup_config(dif_aon_timer_t *aon_timer,
-                             uint32_t wakeup_threshold) {
-  // Make sure that wake-up timer is stopped.
-  CHECK(dif_aon_timer_wakeup_stop(aon_timer) == kDifAonTimerOk);
-
-  // Make sure the wake-up IRQ is cleared to avoid false positive.
-  CHECK(dif_aon_timer_irq_acknowledge(
-            aon_timer, kDifAonTimerIrqWakeupThreshold) == kDifAonTimerOk);
-
-  bool is_pending;
-  CHECK(dif_aon_timer_irq_is_pending(aon_timer, kDifAonTimerIrqWakeupThreshold,
-                                     &is_pending) == kDifAonTimerOk);
-  CHECK(!is_pending);
-
-  CHECK(dif_aon_timer_wakeup_start(aon_timer, wakeup_threshold, 0) ==
-        kDifAonTimerOk);
-}
-
 bool test_main(void) {
   dif_pwrmgr_t pwrmgr;
   dif_rstmgr_t rstmgr;
-  dif_aon_timer_t aon_timer;
 
   // Initialize pwrmgr
   CHECK(dif_pwrmgr_init(
@@ -82,13 +63,6 @@
     // Clear reset_info.
     CHECK_DIF_OK(dif_rstmgr_reset_info_clear(&rstmgr));
 
-    // Initialize aon_timer
-    dif_aon_timer_params_t params = {
-        .base_addr =
-            mmio_region_from_addr(TOP_EARLGREY_AON_TIMER_AON_BASE_ADDR),
-    };
-    CHECK(dif_aon_timer_init(params, &aon_timer) == kDifAonTimerOk);
-
     // Issue a wakeup signal in ~150us through the AON timer.
     //
     // At 200kHz, threshold of 30 is equal to 150us. There is an additional
@@ -102,7 +76,14 @@
     if (kDeviceType == kDeviceSimVerilator) {
       wakeup_threshold = 300;
     }
-    aon_timer_wakeup_config(&aon_timer, wakeup_threshold);
+    dif_aon_timer_t aon_timer;
+    CHECK(dif_aon_timer_init(
+              (dif_aon_timer_params_t){
+                  .base_addr = mmio_region_from_addr(
+                      TOP_EARLGREY_AON_TIMER_AON_BASE_ADDR),
+              },
+              &aon_timer) == kDifAonTimerOk);
+    aon_timer_testutils_wakeup_config(&aon_timer, wakeup_threshold);
 
     // Enable low power on the next WFI with default settings.
     // All clocks and power domains are turned off during low power.