Repository: apache/tvm

Issue:
Exercise TVM under minimal configuration in CI
We have seen a couple bugs due to microTVM being presumed-ON in config.cmake. Namely, you get python errors importing TVM right now when USE_MICRO is OFF. We should have a regression test that verifies basic functionality with everything (or nearly everything) OFF.

Context: apache/tvm#9617
And another micro-related issue of the same kind, which i don't have handy right now.

cc @gigiblender 


Discussion:

Resolving patch:
diff --git a/ci/jenkins/generate.py b/ci/jenkins/generate.py
--- a/ci/jenkins/generate.py
+++ b/ci/jenkins/generate.py
@@ -40,6 +40,10 @@
             "name": "ci_cpu",
             "platform": "CPU",
         },
+        {
+            "name": "ci_minimal",
+            "platform": "CPU",
+        },
         {
             "name": "ci_gpu",
             "platform": "CPU",


Test patch:
diff --git a/ci/jenkins/Test.groovy.j2 b/ci/jenkins/Test.groovy.j2
--- a/ci/jenkins/Test.groovy.j2
+++ b/ci/jenkins/Test.groovy.j2
@@ -211,6 +211,19 @@
   )
 {% endcall %}
 
+def run_unittest_minimal() {
+  {% call m.test_step_body(
+      name="unittest: CPU MINIMAL",
+      node="CPU-SMALL",
+      ws="tvm/ut-python-cpu-minimal",
+      platform="minimal",
+      docker_image="ci_minimal",
+    ) %}
+      {{ m.download_artifacts(tag='cpu-minimal', filenames=tvm_lib) }}
+      cpp_unittest(ci_minimal)
+      python_unittest(ci_minimal)
+  {% endcall %}
+}
 
 def test() {
 stage('Test') {
@@ -223,6 +236,9 @@ stage('Test') {
     {{ method_name }}()
   },
   {% endfor %}
+  'unittest: CPU MINIMAL': {
+    run_unittest_minimal()
+  },
   {% call m.test_step(
     name="unittest: CPU",
     node="CPU-SMALL",
diff --git a/tests/python/ci/test_ci.py b/tests/python/ci/test_ci.py
--- a/tests/python/ci/test_ci.py
+++ b/tests/python/ci/test_ci.py
@@ -914,6 +914,7 @@ def test_open_docker_update_pr(
         "ci_lint",
         "ci_gpu",
         "ci_cpu",
+        "ci_minimal",
         "ci_wasm",
         "ci_i386",
         "ci_cortexm",
diff --git a/tests/python/unittest/test_meta_schedule_task_scheduler.py b/tests/python/unittest/test_meta_schedule_task_scheduler.py
--- a/tests/python/unittest/test_meta_schedule_task_scheduler.py
+++ b/tests/python/unittest/test_meta_schedule_task_scheduler.py
@@ -23,6 +23,7 @@
 import pytest
 import tvm
 import tvm.testing
+from tvm.support import libinfo
 from tvm import meta_schedule as ms
 from tvm._ffi.base import TVMError
 from tvm.meta_schedule.testing.dummy_object import DummyBuilder, DummyRunner
diff --git a/tests/scripts/ci.py b/tests/scripts/ci.py
--- a/tests/scripts/ci.py
+++ b/tests/scripts/ci.py
@@ -595,6 +595,19 @@ def add_subparser(
             "frontend": ("run frontend tests", ["./tests/scripts/task_python_frontend_cpu.sh"]),
         },
     ),
+    generate_command(
+        name="minimal",
+        help="Run minimal CPU build and test(s)",
+        options={
+            "cpp": CPP_UNITTEST,
+            "unittest": (
+                "run unit tests",
+                [
+                    "./tests/scripts/task_python_unittest.sh",
+                ],
+            ),
+        },
+    ),
     generate_command(
         name="i386",
         help="Run i386 build and test(s)",
diff --git a/tests/scripts/task_config_build_minimal.sh b/tests/scripts/task_config_build_minimal.sh
new file mode 100755
--- /dev/null
+++ b/tests/scripts/task_config_build_minimal.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+set -euxo pipefail
+
+BUILD_DIR=$1
+mkdir -p "$BUILD_DIR"
+cd "$BUILD_DIR"
+cp ../cmake/config.cmake .
+
+echo set\(USE_SORT ON\) >> config.cmake
+echo set\(USE_LLVM llvm-config\) >> config.cmake
+echo set\(USE_RELAY_DEBUG ON\) >> config.cmake
+echo set\(CMAKE_BUILD_TYPE=Debug\) >> config.cmake
+echo set\(CMAKE_CXX_FLAGS \"-Werror -Wp,-D_GLIBCXX_ASSERTIONS\"\) >> config.cmake
+echo set\(HIDE_PRIVATE_SYMBOLS ON\) >> config.cmake
+echo set\(USE_LIBBACKTRACE ON\) >> config.cmake
+echo set\(USE_CCACHE OFF\) >> config.cmake
+echo set\(SUMMARIZE ON\) >> config.cmake
diff --git a/tests/scripts/task_cpp_unittest.sh b/tests/scripts/task_cpp_unittest.sh
--- a/tests/scripts/task_cpp_unittest.sh
+++ b/tests/scripts/task_cpp_unittest.sh
@@ -45,20 +45,22 @@ python3 tests/scripts/task_build.py \
     --cmake-target cpptest \
     --build-dir "${BUILD_DIR}"
 
-# crttest requires USE_MICRO to be enabled, which is currently the case
-# with all CI configs
-pushd "${BUILD_DIR}"
-ninja crttest
-popd
-
+# crttest requries USE_MICRO to be enabled.
+if grep -Fq "USE_MICRO ON" ${BUILD_DIR}/TVMBuildOptions.txt; then
+  pushd "${BUILD_DIR}"
+  ninja crttest
+  popd
+fi
 
 pushd "${BUILD_DIR}"
 ctest --gtest_death_test_style=threadsafe
 popd
 
-# Test MISRA-C runtime
-pushd apps/bundle_deploy
-rm -rf build
-make test_dynamic test_static
-popd
+# Test MISRA-C runtime. It requires USE_MICRO to be enabled.
+if grep -Fq "USE_MICRO ON" ${BUILD_DIR}/TVMBuildOptions.txt; then
+  pushd apps/bundle_deploy
+  rm -rf build
+  make test_dynamic test_static
+  popd
+fi