# @name Jailhouse basic
# @desc Jailhouse functional tests
# @requires
# @setup_requires

JAILHOUSE_S_FUNC_ENABLE source 'functions.sh'; check_jailhouse; jailhouse disable &> /dev/null || true; cell_prefix=`get_cell_name_prefix.sh`; jailhouse enable /usr/share/jailhouse/cells/${cell_prefix}.cell || die "Could not enable jailhouse using ${cell_prefix}.cell "

JAILHOUSE_S_FUNC_DISABLE source 'functions.sh'; check_jailhouse; jailhouse disable &> /dev/null || true; cell_prefix=`get_cell_name_prefix.sh`; jailhouse enable /usr/share/jailhouse/cells/${cell_prefix}.cell || die "Could not enable jailhouse using ${cell_prefix}.cell"; jailhouse disable || die "Could not disable jailhouse"

JAILHOUSE_S_FUNC_LINUX_INMATE source 'functions.sh'; check_jailhouse; jailhouse disable &> /dev/null || true; inmate_cell_prefix=`get_inmate_cell_name_prefix.sh`; /usr/share/jailhouse/linux-demo.sh || die "Could not start linux-demo inmate"; sleep 2; jailhouse cell list | grep ${inmate_cell_prefix} | grep running || die "linux-demo inmate is not running"

JAILHOUSE_S_FUNC_LINUX_INMATE_DESTROY source 'functions.sh'; check_jailhouse; jailhouse disable &> /dev/null || true; inmate_cell_prefix=`get_inmate_cell_name_prefix.sh`; /usr/share/jailhouse/linux-demo.sh || die "Could not start linux-demo inmate"; sleep 2; jailhouse cell list | grep  ${inmate_cell_prefix} | grep running || die "linux-demo inmate is not running"; jailhouse cell shutdown ${inmate_cell_prefix} || die "Could not shutdown j721e-evm-linux-demo"; jailhouse cell destroy ${inmate_cell_prefix} || die "Could not destroy j721e-evm-linux-demo"

JAILHOUSE_S_FUNC_GIC_DEMO source 'functions.sh'; check_jailhouse; jailhouse disable &> /dev/null || true; cell_prefix=`get_cell_name_prefix.sh`; demo_arch_prefix=`get_demo_arch_name_prefix.sh`; jailhouse enable /usr/share/jailhouse/cells/${cell_prefix}.cell || die "Could not enable jailhouse using ${cell_prefix}.cell"; sleep 2; jailhouse cell create /usr/share/jailhouse/cells/${demo_arch_prefix}-inmate-demo.cell || die "Could not create ${demo_arch_prefix}-inmate-demo.cell"; jailhouse cell load inmate-demo /usr/share/jailhouse/inmates/gic-demo.bin || die "Could not load gic-demo.bin on cell inmate-demo"; jailhouse cell start inmate-demo || die "Could not start inmate-demo cell"; jailhouse cell list | grep inmate-demo | grep running || die "inmate-demo cell is not running"; jailhouse cell shutdown inmate-demo || die "Could not shutdown inmate-demo"; jailhouse cell destroy inmate-demo || die "Could not destroy inmate-demo"

JAILHOUSE_S_FUNC_UART_DEMO source 'functions.sh'; check_jailhouse; jailhouse disable &> /dev/null || true; cell_prefix=`get_cell_name_prefix.sh`; demo_arch_prefix=`get_demo_arch_name_prefix.sh`; jailhouse enable /usr/share/jailhouse/cells/${cell_prefix}.cell || die "Could not enable jailhouse using ${cell_prefix}.cell"; sleep 2; jailhouse cell create /usr/share/jailhouse/cells/${demo_arch_prefix}-inmate-demo.cell || die "Could not create ${demo_arch_prefix}-inmate-demo.cell"; jailhouse cell load inmate-demo /usr/share/jailhouse/inmates/uart-demo.bin || die "Could not load uart-demo.bin on cell inmate-demo"; jailhouse cell start inmate-demo || die "Could not start inmate-demo cell"; jailhouse cell list | grep inmate-demo | grep running || die "inmate-demo cell is not running"; jailhouse cell shutdown inmate-demo || die "Could not shutdown inmate-demo"; jailhouse cell destroy inmate-demo || die "Could not destroy inmate-demo"

JAILHOUSE_S_FUNC_STATS_LINUX_INMATE source 'functions.sh'; check_jailhouse; jailhouse disable &> /dev/null || true; inmate_cell_prefix=`get_inmate_cell_name_prefix.sh`; /usr/share/jailhouse/linux-demo.sh || die "Could not start linux-demo inmate"; sleep 2; jailhouse cell list | grep ${inmate_cell_prefix} | grep running || die "linux-demo inmate is not running";  cat /sys/devices/jailhouse/cells/0/statistics/cpu0/* || die "Could not read cell0 cpu0 stats";  cat /sys/devices/jailhouse/cells/1/statistics/cpu1/* || die "Could not read cell cell 1 cpu1 stats"

JAILHOUSE_S_FUNC_LINUX_INMATE_PCIe_BARS source 'functions.sh'; check_jailhouse; jailhouse disable &> /dev/null || true; inmate_cell_prefix=`get_inmate_cell_name_prefix.sh`; /usr/share/jailhouse/linux-demo.sh || die "Could not start linux-demo inmate"; jailhouse cell list | grep ${inmate_cell_prefix} | grep running || die "linux-demo inmate is not running"; do_cmd pcie_ep_funcs.sh -n 1 -s -b -d /dev/pci-endpoint-test.0;jailhouse cell shutdown ${inmate_cell_prefix} || die "Could not shutdown linux-demo inmate"; jailhouse cell destroy ${inmate_cell_prefix} || die "Could not destroy linux-demo inmate"

JAILHOUSE_S_FUNC_LINUX_INMATE_PCIe_MULTIFUNC_MSIX source 'functions.sh'; check_jailhouse; jailhouse disable &> /dev/null || true; inmate_cell_prefix=`get_inmate_cell_name_prefix.sh`; /usr/share/jailhouse/linux-demo.sh || die "Could not start linux-demo inmate"; jailhouse cell list | grep ${inmate_cell_prefix} | grep running || die "linux-demo inmate is not running"; do_cmd pcie_ep_funcs.sh -n 1 -x -f -d /dev/pci-endpoint-test.0 -d /dev/pci-endpoint-test.1; jailhouse cell shutdown ${inmate_cell_prefix} || die "Could not shutdown linux-demo inmate"; jailhouse cell destroy ${inmate_cell_prefix} || die "Could not destroy linux-demo inmate"

JAILHOUSE_S_FUNC_LINUX_INMATE_PCIe_VIRTFNC_MSIX source 'functions.sh'; check_jailhouse; jailhouse disable &> /dev/null || true; /usr/share/jailhouse/linux-demo.sh || die "Could not start linux-demo inmate"; jailhouse cell list | grep ${inmate_cell_prefix} | grep running || die "linux-demo inmate is not running"; do_cmd pcie_ep_funcs.sh -n 1 -x -v -d /dev/pci-endpoint-test.0 -d /dev/pci-endpoint-test.1 -d /dev/pci-endpoint-test.2; jailhouse cell shutdown ${inmate_cell_prefix} || die "Could not shutdown linux-demo inmate"; jailhouse cell destroy ${inmate_cell_prefix} || die "Could not destroy linux-demo inmate"
