[dv/chip] Move a checking to common testutils file

This PR moves the `check_lc_state_transition_count` task to the common
`lc_ctrl_testuitls` file so that it can be used by other tests.

Signed-off-by: Cindy Chen <chencindy@opentitan.org>
diff --git a/sw/device/lib/testing/lc_ctrl_testutils.c b/sw/device/lib/testing/lc_ctrl_testutils.c
index e36756c..f1d8040 100644
--- a/sw/device/lib/testing/lc_ctrl_testutils.c
+++ b/sw/device/lib/testing/lc_ctrl_testutils.c
@@ -30,3 +30,14 @@
       return false;
   }
 }
+
+void lc_ctrl_testutils_check_transition_count(const dif_lc_ctrl_t *lc_ctrl,
+                                              uint8_t exp_lc_count) {
+  LOG_INFO("Read LC count and check with expect_val=%0d", exp_lc_count);
+  uint8_t lc_count;
+  CHECK(dif_lc_ctrl_get_attempts(lc_ctrl, &lc_count) == kDifOk,
+        "Read lc_count register failed!");
+  CHECK(lc_count == exp_lc_count,
+        "LC_count error, expected %0d but actual count is %0d", exp_lc_count,
+        lc_count);
+}
diff --git a/sw/device/lib/testing/lc_ctrl_testutils.h b/sw/device/lib/testing/lc_ctrl_testutils.h
index d6564dd..9aa2fe1 100644
--- a/sw/device/lib/testing/lc_ctrl_testutils.h
+++ b/sw/device/lib/testing/lc_ctrl_testutils.h
@@ -18,4 +18,13 @@
  */
 bool lc_ctrl_testutils_debug_func_enabled(const dif_lc_ctrl_t *lc_ctrl);
 
+/**
+ * Check if Lifecycle Controller count number is expected.
+ *
+ * This function will read out lc_transition_cnt register and check the value
+ * against exp_lc_count value.
+ */
+void lc_ctrl_testutils_check_transition_count(const dif_lc_ctrl_t *lc_ctrl,
+                                              uint8_t exp_lc_count);
+
 #endif  // OPENTITAN_SW_DEVICE_LIB_TESTING_LC_CTRL_TESTUTILS_H_
diff --git a/sw/device/tests/sim_dv/BUILD b/sw/device/tests/sim_dv/BUILD
index 077558a..d2feb26 100644
--- a/sw/device/tests/sim_dv/BUILD
+++ b/sw/device/tests/sim_dv/BUILD
@@ -114,6 +114,7 @@
         "//sw/device/lib/base:mmio",
         "//sw/device/lib/dif:lc_ctrl",
         "//sw/device/lib/runtime:log",
+        "//sw/device/lib/testing:lc_ctrl_testutils",
         "//sw/device/lib/testing/test_framework:check",
     ],
 )
diff --git a/sw/device/tests/sim_dv/lc_ctrl_transition_impl.c b/sw/device/tests/sim_dv/lc_ctrl_transition_impl.c
index 4fa895f..7a26946 100644
--- a/sw/device/tests/sim_dv/lc_ctrl_transition_impl.c
+++ b/sw/device/tests/sim_dv/lc_ctrl_transition_impl.c
@@ -10,6 +10,7 @@
 #include "sw/device/lib/base/mmio.h"
 #include "sw/device/lib/dif/dif_lc_ctrl.h"
 #include "sw/device/lib/runtime/log.h"
+#include "sw/device/lib/testing/lc_ctrl_testutils.h"
 #include "sw/device/lib/testing/test_framework/check.h"
 
 #include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
@@ -38,16 +39,6 @@
     0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
 };
 
-static void check_lc_state_transition_count(uint8_t exp_lc_count) {
-  LOG_INFO("Read LC count and check with expect_val=%0d", exp_lc_count);
-  uint8_t lc_count;
-  CHECK(dif_lc_ctrl_get_attempts(&lc, &lc_count) == kDifOk,
-        "Read lc_count register failed!");
-  CHECK(lc_count == exp_lc_count,
-        "LC_count error, expected %0d but actual count is %0d", exp_lc_count,
-        lc_count);
-}
-
 /**
  * Tests the state transition request handshake between LC_CTRL and OTP_CTRL.
  *
@@ -89,7 +80,7 @@
   if (curr_state == kDifLcCtrlStateTestUnlocked2) {
     // LC TestUnlocked2 is the intial test state for this sequence.
     // The sequence will check if lc_count matches the preload value.
-    check_lc_state_transition_count(kLcStateTransitionCount);
+    lc_ctrl_testutils_check_transition_count(&lc, kLcStateTransitionCount);
 
     // Request lc_state transfer to Dev state.
     dif_lc_ctrl_token_t token;
@@ -112,7 +103,7 @@
     // Once the sequence checks current state and count via CSRs, the test can
     // exit successfully.
     CHECK(curr_state == kDifLcCtrlStateDev, "State transition failed!");
-    check_lc_state_transition_count(kLcStateTransitionCount + 1);
+    lc_ctrl_testutils_check_transition_count(&lc, kLcStateTransitionCount + 1);
     return true;
   }
 
diff --git a/sw/device/tests/sim_dv/lc_walkthrough_test.c b/sw/device/tests/sim_dv/lc_walkthrough_test.c
index 85b9dec..bc6eab0 100644
--- a/sw/device/tests/sim_dv/lc_walkthrough_test.c
+++ b/sw/device/tests/sim_dv/lc_walkthrough_test.c
@@ -44,16 +44,6 @@
     0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
 };
 
-static void check_lc_state_transition_count(uint8_t exp_lc_count) {
-  LOG_INFO("Read LC count and check with expect_val=%0d", exp_lc_count);
-  uint8_t lc_count;
-  CHECK_DIF_OK(dif_lc_ctrl_get_attempts(&lc, &lc_count),
-               "Read lc_count register failed!");
-  CHECK(lc_count == exp_lc_count,
-        "LC_count error, expected %0d but actual count is %0d", exp_lc_count,
-        lc_count);
-}
-
 /**
  * Walkthrough LC state: RAW -> TestUnlock0 -> Destination state.
  *
@@ -86,7 +76,7 @@
   CHECK_DIF_OK(dif_lc_ctrl_get_state(&lc, &curr_state));
 
   if (curr_state == kDifLcCtrlStateTestUnlocked0) {
-    check_lc_state_transition_count(1);
+    lc_ctrl_testutils_check_transition_count(&lc, 1);
     bool secret0_locked;
     CHECK_DIF_OK(dif_otp_ctrl_is_digest_computed(
         &otp, kDifOtpCtrlPartitionSecret0, &secret0_locked));
@@ -154,7 +144,7 @@
       CHECK_DIF_OK(dif_lc_ctrl_mutex_try_acquire(&lc));
       dif_lc_ctrl_settings_t settings;
       // TODO: randomize using external or internal clock.
-      settings.clock_select = kDifLcCtrlExternalClockEn;
+      settings.clock_select = kDifLcCtrlInternalClockEn;
       CHECK_DIF_OK(dif_lc_ctrl_transition(&lc, kDestState, &token, &settings),
                    "LC_transition failed!");
 
@@ -164,7 +154,7 @@
   } else {
     // Check LC enters ProdEnd state.
     CHECK(curr_state == kDestState);
-    check_lc_state_transition_count(2);
+    lc_ctrl_testutils_check_transition_count(&lc, 2);
     return true;
   }
 }
diff --git a/sw/device/tests/sim_dv/meson.build b/sw/device/tests/sim_dv/meson.build
index 9e90694..029bb2d 100644
--- a/sw/device/tests/sim_dv/meson.build
+++ b/sw/device/tests/sim_dv/meson.build
@@ -119,6 +119,7 @@
       sw_lib_mmio,
       sw_lib_runtime_hart,
       sw_lib_runtime_log,
+      sw_lib_testing_lc_ctrl_testutils,
       top_earlgrey,
     ],
   ),