Add SystemC test bazel targets

Test .bin artifacts with SystemC core_sim binary

Change-Id: I54ef143c84f8c81576cc76f6f587b78937f190db
diff --git a/build_tools/BUILD b/build_tools/BUILD
index d53f03c..bdc0ccd 100644
--- a/build_tools/BUILD
+++ b/build_tools/BUILD
@@ -1,5 +1,6 @@
 package(default_visibility = ["//visibility:public"])
 
 exports_files([
+    "core_sim_test_runner.sh",
     "test_runner.sh",
 ])
diff --git a/build_tools/bazel/kelvin.bzl b/build_tools/bazel/kelvin.bzl
index e6fb102..bdbe612 100644
--- a/build_tools/bazel/kelvin.bzl
+++ b/build_tools/bazel/kelvin.bzl
@@ -192,15 +192,20 @@
 
 def kelvin_test(
         name,
-        size = "small",
+        hw_test_size = "medium",
+        hw_test_tags = [],
+        iss_test_size = "small",
         **kwargs):
     """A sh_test wrapper for kelvin binaries
 
-    A wrapper to build kelvin_binary and test it against build_tools/test_runner.sh
+    A wrapper to build kelvin_binary and test it against build_tools/*test_runner.sh
+    on both ISS and HW SystemC simulations.
 
     Args:
       name: The name of this rule.
-      size: Test size. Default to small.
+      iss_test_size: ISS test size. Default to small.
+      hw_test_size: Tests size for SystemC test, default to medium.
+      hw_test_tags: Test tags passed to System test.
       **kwargs: Agruments that will be forwarded to kelvin_binary
     """
 
@@ -210,9 +215,10 @@
         **kwargs
     )
 
+    iss_test = "{}_iss".format(name)
     native.sh_test(
-        name = name,
-        size = size,
+        name = iss_test,
+        size = iss_test_size,
         srcs = [
             "//build_tools:test_runner.sh",
         ],
@@ -224,6 +230,28 @@
         ],
     )
 
+    hw_test = "{}_hw".format(name)
+    native.sh_test(
+        name = hw_test,
+        size = hw_test_size,
+        srcs = ["//build_tools:core_sim_test_runner.sh"],
+        args = [
+            "$(location %s.bin)" % kelvin_elf,
+        ],
+        data = [
+            "{}.bin".format(kelvin_elf),
+        ],
+        tags = hw_test_tags,
+    )
+
+    native.test_suite(
+        name = name,
+        tests = [
+            iss_test,
+            hw_test,
+        ],
+    )
+
 # From @tflite-micro//tensorflow/lite/micro/build_def.bzl, and paths
 # modified to point to the external repo.
 def generate_cc_arrays(name, src, out, visibility = None, tags = []):
diff --git a/build_tools/core_sim_test_runner.sh b/build_tools/core_sim_test_runner.sh
new file mode 100755
index 0000000..946d578
--- /dev/null
+++ b/build_tools/core_sim_test_runner.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+# Test runner for SystemC simulator. Note the input should be the .bin file.
+
+function print_usage {
+  echo "Usage: core_sim_test_runner.sh <bin location> [extra flags]"
+}
+
+if [[ $1 == "--help" ]]; then
+  print_usage
+fi
+
+if [[ -z ${ROOTDIR} ]]; then
+  echo "Please run \"source build/setup.sh\" first"
+  exit 1
+fi
+
+CORE_SIM="${ROOTDIR}/out/kelvin/hw/bazel_out/core_sim"
+
+if [[ ! -f ${CORE_SIM} ]]; then
+  echo "Please run \"m kelvin_hw_sim\" first"
+  exit 1
+fi
+
+if (( $# != 1 )); then
+  print_usage
+  exit 1
+fi
+
+BIN_FILE=$(realpath $1)
+shift 1
+SIM_OUT=$(${CORE_SIM} "${BIN_FILE}" $@)
+RESULT=$?
+echo "${SIM_OUT}"
+
+exit ${RESULT}
diff --git a/tests/kelvin_isa/BUILD b/tests/kelvin_isa/BUILD
index 01f88d7..2be5c10 100644
--- a/tests/kelvin_isa/BUILD
+++ b/tests/kelvin_isa/BUILD
@@ -38,6 +38,7 @@
     srcs = [
         "vpadd.cc",
     ],
+    hw_test_size = "small",
     deps = [
         ":kelvin_test",
     ],
diff --git a/tests/riscv-tests/BUILD b/tests/riscv-tests/BUILD
index 2b8f273..aa188bd 100644
--- a/tests/riscv-tests/BUILD
+++ b/tests/riscv-tests/BUILD
@@ -74,6 +74,7 @@
     defines = [
         "RVTEST_RV64U=RVTEST_RV32U",
     ],
+    hw_test_size = "small",
     is_riscv_test = True,
     deps = [
         ":riscv_tests_base",
@@ -101,6 +102,7 @@
         "-Iexternal/riscv-tests/isa/macros/scalar",
         "-Wno-variadic-macros",
     ],
+    hw_test_size = "small",
     is_riscv_test = True,
     deps = [
         ":riscv_tests_base",
@@ -112,6 +114,7 @@
     srcs = [
         "branch_modulo_test.cc",
     ],
+    hw_test_size = "small",
     deps = [
         "//crt:crt_header",
     ],
@@ -122,6 +125,7 @@
     srcs = [
         "branch_div_test.cc",
     ],
+    hw_test_size = "small",
     deps = [
         "//crt:crt_header",
     ],
diff --git a/tests/tflm/BUILD b/tests/tflm/BUILD
index 05c196b..aeb826e 100644
--- a/tests/tflm/BUILD
+++ b/tests/tflm/BUILD
@@ -7,6 +7,8 @@
     srcs = [
         "@tflite-micro//tensorflow/lite/micro/kernels:add_test.cc",
     ],
+    # TODO(b/295921340): Re-enable HW test.
+    hw_test_tags = ["broken"],
     deps = [
         "//crt:crt_header",
         "@tflite-micro//tensorflow/lite/c:common",
@@ -39,6 +41,7 @@
     srcs = [
         "@tflite-micro//tensorflow/lite/micro/kernels:reshape_test.cc",
     ],
+    hw_test_size = "large",
     deps = [
         "//crt:crt_header",
         "@tflite-micro//tensorflow/lite/c:common",