Software APIs
ibex_test.c
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 #include "sw/device/lib/crypto/drivers/ibex.h"
5 
8 #include "sw/device/lib/base/status.h"
10 #include "sw/device/lib/testing/test_framework/check.h"
13 
15 #include "rv_core_ibex_regs.h"
16 
17 enum {
19 };
20 
21 OTTF_DEFINE_TEST_CONFIG();
22 
23 static status_t ibex_entropy_test(void) {
24  uint32_t rnd_status;
25  uint32_t rnd_data[2];
26 
27  // Read the initial value of the RND_DATA CSR.
28  TRY(ibex_rnd_data_read(rnd_data));
29  // Wait for RND_DATA to be valid again and check if RND_STATUS is as expected.
30  TRY(ibex_wait_rnd_valid());
31  TRY(ibex_rnd_status_read(&rnd_status));
32  TRY_CHECK(bitfield_bit32_read(rnd_status,
33  RV_CORE_IBEX_RND_STATUS_RND_DATA_VALID_BIT));
34  // Read RND_DATA again and check if it changed.
35  TRY(ibex_rnd_data_read(&rnd_data[1]));
36  TRY_CHECK(rnd_data[0] != rnd_data[1]);
37 
38  return OK_STATUS();
39 }
40 
41 bool test_main(void) {
42  status_t result = OK_STATUS();
43  // Test RND_DATA and RND_STATUS CSR access.
44  EXECUTE_TEST(result, ibex_entropy_test);
45  return status_ok(result);
46 }