| /* |
| * Copyright 2023 Google LLC |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| |
| #include "hw/top_matcha/sw/autogen/top_matcha.h" |
| #include "sw/device/lib/arch/device.h" |
| #include "sw/device/lib/dif/dif_uart.h" |
| #include "sw/device/lib/runtime/hart.h" |
| #include "sw/device/lib/runtime/log.h" |
| #include "sw/device/lib/runtime/print.h" |
| #include "sw/device/lib/testing/test_framework/check.h" |
| #include "sw/device/lib/testing/test_framework/ottf_test_config.h" |
| #include "sw/device/lib/testing/test_framework/status.h" |
| #include "sw/device/lib/testing/test_framework/test_util.h" |
| |
| OTTF_DEFINE_TEST_CONFIG(); |
| |
| static dif_uart_t uart; |
| |
| void _ottf_main(void) { |
| uint32_t mem_val; |
| |
| // Initialize the UART to enable logging for non-DV simulation platforms. |
| if (kDeviceType != kDeviceSimDV) { |
| init_uart(TOP_MATCHA_UART0_BASE_ADDR, &uart); |
| } |
| LOG_INFO("Hello Shodan! Let's do memory test!"); |
| |
| // Start testing SMC SRAM |
| test_status_set(kTestStatusInTest); |
| |
| mmio_region_t base_addr = mmio_region_from_addr(TOP_MATCHA_RAM_SMC_BASE_ADDR); |
| |
| mmio_region_write32(base_addr, 0x0, 0x55aa55aa); |
| mem_val = mmio_region_read32(base_addr, 0x0); |
| CHECK(mem_val == 0x55aa55aa, |
| "ram_smc read out: expected : 0x55aa55aa | actual: %x", mem_val); |
| |
| mmio_region_write32(base_addr, 0x4, 0x12345678); |
| mem_val = mmio_region_read32(base_addr, 0x4); |
| CHECK(mem_val == 0x12345678, |
| "ram_smc read out: expected : 0x12345678 | actual: %x", mem_val); |
| |
| mmio_region_write32(base_addr, (TOP_MATCHA_RAM_SMC_SIZE_BYTES - 4), |
| 0xaa55aa55); |
| mem_val = mmio_region_read32(base_addr, (TOP_MATCHA_RAM_SMC_SIZE_BYTES - 4)); |
| CHECK(mem_val == 0xaa55aa55, |
| "ram_smc read out: expected : 0xaa55aa55 | actual: %x", mem_val); |
| |
| // Start testing ML_TOP_DMEM |
| mmio_region_t ml_dmem_base_addr = |
| mmio_region_from_addr(TOP_MATCHA_ML_TOP_DMEM_BASE_ADDR); |
| |
| mmio_region_write32(ml_dmem_base_addr, 0x0, 0x55aa55aa); |
| mmio_region_write32(ml_dmem_base_addr, 0x4, 0x12345678); |
| mmio_region_write32(ml_dmem_base_addr, 0x8, 0x55aa55aa); |
| mmio_region_write32(ml_dmem_base_addr, 0xc, 0x12345678); |
| mmio_region_write32(ml_dmem_base_addr, 0x10, 0x55aa55aa); |
| mmio_region_write32(ml_dmem_base_addr, 0x14, 0x12345678); |
| mmio_region_write32(ml_dmem_base_addr, 0x18, 0x55aa55aa); |
| mmio_region_write32(ml_dmem_base_addr, 0x1c, 0x12345678); |
| mmio_region_write32(ml_dmem_base_addr, 0x20, 0x55aa55aa); |
| mmio_region_write32(ml_dmem_base_addr, 0x2c, 0x12345678); |
| |
| mem_val = mmio_region_read32(ml_dmem_base_addr, 0x0); |
| CHECK(mem_val == 0x55aa55aa, |
| "ml_dmem read out: expected : 0x55aa55aa | actual: %x", mem_val); |
| |
| mem_val = mmio_region_read32(ml_dmem_base_addr, 0x4); |
| CHECK(mem_val == 0x12345678, |
| "ml_dmem read out: expected : 0x12345678 | actual: %x", mem_val); |
| |
| mem_val = mmio_region_read32(ml_dmem_base_addr, 0x8); |
| CHECK(mem_val == 0x55aa55aa, |
| "ml_dmem read out: expected : 0x55aa55aa | actual: %x", mem_val); |
| |
| mem_val = mmio_region_read32(ml_dmem_base_addr, 0xc); |
| CHECK(mem_val == 0x12345678, |
| "ml_dmem read out: expected : 0x12345678 | actual: %x", mem_val); |
| |
| mem_val = mmio_region_read32(ml_dmem_base_addr, 0x10); |
| CHECK(mem_val == 0x55aa55aa, |
| "ml_dmem read out: expected : 0x55aa55aa | actual: %x", mem_val); |
| |
| mem_val = mmio_region_read32(ml_dmem_base_addr, 0x14); |
| CHECK(mem_val == 0x12345678, |
| "ml_dmem read out: expected : 0x12345678 | actual: %x", mem_val); |
| |
| mem_val = mmio_region_read32(ml_dmem_base_addr, 0x18); |
| CHECK(mem_val == 0x55aa55aa, |
| "ml_dmem read out: expected : 0x55aa55aa | actual: %x", mem_val); |
| |
| mem_val = mmio_region_read32(ml_dmem_base_addr, 0x1c); |
| CHECK(mem_val == 0x12345678, |
| "ml_dmem read out: expected : 0x12345678 | actual: %x", mem_val); |
| |
| mem_val = mmio_region_read32(ml_dmem_base_addr, 0x20); |
| CHECK(mem_val == 0x55aa55aa, |
| "ml_dmem read out: expected : 0x12345678 | actual: %x", mem_val); |
| |
| mem_val = mmio_region_read32(ml_dmem_base_addr, 0x2c); |
| CHECK(mem_val == 0x12345678, |
| "ml_dmem read out: expected : 0x12345678 | actual: %x", mem_val); |
| |
| mmio_region_write32(ml_dmem_base_addr, |
| (TOP_MATCHA_ML_TOP_DMEM_SIZE_BYTES - 32), 0xaa55aa55); |
| mem_val = mmio_region_read32(ml_dmem_base_addr, |
| (TOP_MATCHA_ML_TOP_DMEM_SIZE_BYTES - 32)); |
| CHECK(mem_val == 0xaa55aa55, |
| "ml_dmem read out: expected : 0xaa55aa55 | actual: %x", mem_val); |
| |
| mmio_region_write32(ml_dmem_base_addr, |
| (TOP_MATCHA_ML_TOP_DMEM_SIZE_BYTES - 4), 0x12345678); |
| mem_val = mmio_region_read32(ml_dmem_base_addr, |
| (TOP_MATCHA_ML_TOP_DMEM_SIZE_BYTES - 4)); |
| CHECK(mem_val == 0x12345678, |
| "ml_dmem read out: expected : 0xaa55aa55 | actual: %x", mem_val); |
| |
| mmio_region_write32(ml_dmem_base_addr, 0x0, 0x55aa55aa); |
| mmio_region_write32(ml_dmem_base_addr, 0x100000, 0x12345678); |
| mmio_region_write32(ml_dmem_base_addr, 0x200000, 0xaa55aa55); |
| mmio_region_write32(ml_dmem_base_addr, 0x300000, 0x87654321); |
| |
| mem_val = mmio_region_read32(ml_dmem_base_addr, 0x0); |
| CHECK(mem_val == 0x55aa55aa, |
| "ml_dmem read out: expected : 0x55aa55aa | actual: %x", mem_val); |
| |
| mem_val = mmio_region_read32(ml_dmem_base_addr, 0x100000); |
| CHECK(mem_val == 0x12345678, |
| "ml_dmem read out: expected : 0x12345678 | actual: %x", mem_val); |
| |
| mem_val = mmio_region_read32(ml_dmem_base_addr, 0x200000); |
| CHECK(mem_val == 0xaa55aa55, |
| "ml_dmem read out: expected : 0xaa55aa55 | actual: %x", mem_val); |
| |
| mem_val = mmio_region_read32(ml_dmem_base_addr, 0x300000); |
| CHECK(mem_val == 0x87654321, |
| "ml_dmem read out: expected : 0x87654321 | actual: %x", mem_val); |
| |
| test_status_set(kTestStatusPassed); |
| } |