From 7be470f6149c1536fd2a089ae20b58140484110d Mon Sep 17 00:00:00 2001
From: Yifan Zhao <yifanz16@illinois.edu>
Date: Thu, 25 Mar 2021 05:49:48 -0500
Subject: [PATCH] Reorganized test suites to welcome new ones

---
 hpvm/test/CMakeLists.txt                      |  4 +--
 hpvm/test/dnn_benchmarks/CMakeLists.txt       | 19 -----------
 .../test/dnn_benchmarks/hpvm-c/CMakeLists.txt | 33 ++++++++++++++-----
 .../dnn_benchmarks/{ => hpvm-c}/lit.cfg.py    |  0
 hpvm/test/dnn_benchmarks/lit.site.cfg.py.in   | 10 ------
 hpvm/test/hpvm_pass/CMakeLists.txt            |  2 +-
 hpvm/test/{hpvm_pass => }/lit.site.cfg.py.in  |  3 +-
 7 files changed, 29 insertions(+), 42 deletions(-)
 delete mode 100644 hpvm/test/dnn_benchmarks/CMakeLists.txt
 rename hpvm/test/dnn_benchmarks/{ => hpvm-c}/lit.cfg.py (100%)
 delete mode 100644 hpvm/test/dnn_benchmarks/lit.site.cfg.py.in
 rename hpvm/test/{hpvm_pass => }/lit.site.cfg.py.in (72%)

diff --git a/hpvm/test/CMakeLists.txt b/hpvm/test/CMakeLists.txt
index 3c41260c4b..a9098bb01d 100644
--- a/hpvm/test/CMakeLists.txt
+++ b/hpvm/test/CMakeLists.txt
@@ -1,3 +1,3 @@
 include(../cmake/TestFile.cmake)  # Generation of `.test` files in CMake
-add_subdirectory(hpvm_pass)
-add_subdirectory(dnn_benchmarks)
+add_subdirectory(hpvm_pass)  # Passes test suite
+add_subdirectory(dnn_benchmarks/hpvm-c)  # DNN accuracy test suite
diff --git a/hpvm/test/dnn_benchmarks/CMakeLists.txt b/hpvm/test/dnn_benchmarks/CMakeLists.txt
deleted file mode 100644
index 58bcd17470..0000000000
--- a/hpvm/test/dnn_benchmarks/CMakeLists.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-# --[ llvm-lit test setup
-# lit.cfg.py looks for tests in CMAKE_CURRENT_BINARY_DIR (see lit.cfg.py)
-# as most of the tests require some kind of compilation / generation
-# which is best done over there.
-configure_lit_site_cfg(
-  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
-  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
-  MAIN_CONFIG
-  ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
-)
-
-add_subdirectory(hpvm-c)
-set(HPVM_TEST_DEPENDS dnn_benchmarks)  # Compile all dnn benchmarks to run them
-
-add_lit_testsuite(check-hpvm-dnn "Running HPVM DNNs"
-  ${CMAKE_CURRENT_BINARY_DIR}
-  DEPENDS ${HPVM_TEST_DEPENDS}
-  ARGS "-j1"  # Run DNN benchmarks sequentially
-)
diff --git a/hpvm/test/dnn_benchmarks/hpvm-c/CMakeLists.txt b/hpvm/test/dnn_benchmarks/hpvm-c/CMakeLists.txt
index a9384956b7..3a0c6534e0 100644
--- a/hpvm/test/dnn_benchmarks/hpvm-c/CMakeLists.txt
+++ b/hpvm/test/dnn_benchmarks/hpvm-c/CMakeLists.txt
@@ -13,6 +13,30 @@ configure_file(
 # and we'll give this to approxhpvm.py
 set(CONFIG_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/include")
 
+# --[ llvm-lit test setup
+# lit.cfg.py looks for tests in CMAKE_CURRENT_BINARY_DIR (see lit.cfg.py)
+# as most of the tests require some kind of compilation / generation
+# which is best done over there.
+configure_lit_site_cfg(
+  ../../lit.site.cfg.py.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
+  MAIN_CONFIG
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
+)
+add_lit_testsuite(check-hpvm-dnn "Running HPVM DNNs"
+  ${CMAKE_CURRENT_BINARY_DIR}
+  DEPENDS dnn_benchmarks  # Compile all dnn benchmarks to run them
+  ARGS "-j1"  # Run DNN benchmarks sequentially
+)
+# Install an accuracy comparator under build/bin
+set(BIN_DIR ${LLVM_BINARY_DIR}/${LLVM_TOOLS_INSTALL_DIR})
+add_custom_command(
+  OUTPUT ${BIN_DIR}/check_dnn_acc.py
+  COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/check_dnn_acc.py ${BIN_DIR}
+  COMMAND chmod +x ${BIN_DIR}/check_dnn_acc.py
+  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/check_dnn_acc.py
+)
+
 set(test_compile_targets "")
 function(compile_hpvm_c bin_filename src_filepath codegen_target)
   add_custom_command(
@@ -26,15 +50,6 @@ function(compile_hpvm_c bin_filename src_filepath codegen_target)
   set(test_compile_targets ${test_compile_targets} ${bin_filename} PARENT_SCOPE)
 endfunction(compile_hpvm_c)
 
-# Install an accuracy comparator under build/bin
-set(BIN_DIR ${LLVM_BINARY_DIR}/${LLVM_TOOLS_INSTALL_DIR})
-add_custom_command(
-  OUTPUT ${BIN_DIR}/check_dnn_acc.py
-  COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/check_dnn_acc.py ${BIN_DIR}
-  COMMAND chmod +x ${BIN_DIR}/check_dnn_acc.py
-  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/check_dnn_acc.py
-)
-
 function(hpvm_add_dnn_test benchmark_target)
   # llvm_test_run* composes a .test file with the RUN line needed by llvm-lit
   # No need to give binary path yet;
diff --git a/hpvm/test/dnn_benchmarks/lit.cfg.py b/hpvm/test/dnn_benchmarks/hpvm-c/lit.cfg.py
similarity index 100%
rename from hpvm/test/dnn_benchmarks/lit.cfg.py
rename to hpvm/test/dnn_benchmarks/hpvm-c/lit.cfg.py
diff --git a/hpvm/test/dnn_benchmarks/lit.site.cfg.py.in b/hpvm/test/dnn_benchmarks/lit.site.cfg.py.in
deleted file mode 100644
index a30a803ca6..0000000000
--- a/hpvm/test/dnn_benchmarks/lit.site.cfg.py.in
+++ /dev/null
@@ -1,10 +0,0 @@
-config.llvm_src_root = "@LLVM_SOURCE_DIR@"
-config.llvm_obj_root = "@LLVM_BINARY_DIR@"
-config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
-config.llvm_lib_dir = "@LLVM_LIBRARY_DIR@"
-
-import lit.llvm
-lit.llvm.initialize(lit_config, config)
-
-# Let the main config do the real work.
-lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg.py")
diff --git a/hpvm/test/hpvm_pass/CMakeLists.txt b/hpvm/test/hpvm_pass/CMakeLists.txt
index 527406f3ce..fe929f4d63 100644
--- a/hpvm/test/hpvm_pass/CMakeLists.txt
+++ b/hpvm/test/hpvm_pass/CMakeLists.txt
@@ -1,5 +1,5 @@
 configure_lit_site_cfg(
-  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
+  ../lit.site.cfg.py.in
   ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
   MAIN_CONFIG
   ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
diff --git a/hpvm/test/hpvm_pass/lit.site.cfg.py.in b/hpvm/test/lit.site.cfg.py.in
similarity index 72%
rename from hpvm/test/hpvm_pass/lit.site.cfg.py.in
rename to hpvm/test/lit.site.cfg.py.in
index 17dff330d0..0ed68ccfa0 100644
--- a/hpvm/test/hpvm_pass/lit.site.cfg.py.in
+++ b/hpvm/test/lit.site.cfg.py.in
@@ -1,4 +1,5 @@
-from lit.llvm import llvm_config
+# This file is shared between test suites.
+# It's repeatedly generated into build directory with different CMAKE_CURRENT_SOURCE_DIR.
 
 config.llvm_src_root = "@LLVM_SOURCE_DIR@"
 config.llvm_obj_root = "@LLVM_BINARY_DIR@"
-- 
GitLab