import os
import shutil

from imc_utils.build_config.cortex_m33 import BuildConfigM33
from imc_utils.build_config.test_env import TestEnv

WORKSPACE_ROOT = "/home/ybkim/workspace/imc/imc_freertos_app_m33"
NVM_RESET_BIN = f"{WORKSPACE_ROOT}/imc/utils/nvm_reset.elf"
OPENOCD_SCRIPT = f"{WORKSPACE_ROOT}/imc_freertos_app_m33.cfg"
BUILD_DIR = f"{WORKSPACE_ROOT}/build"

config = BuildConfigM33()
config.bench_name = "vBasicMath"
config.insert_compiler_checkpoints = False
config.enable_extension = True
config.use_checkpoint_pass_counter = False
config.use_checkpoint_voltage_check = False
config.bench_infinite_loop = False

env = TestEnv(WORKSPACE_ROOT, NVM_RESET_BIN, OPENOCD_SCRIPT)

if os.path.exists(BUILD_DIR):
    shutil.rmtree(BUILD_DIR)

os.mkdir(BUILD_DIR)

env.build_binary(config, BUILD_DIR)