ci-test-each-commit-exec.py raw

   1  #!/usr/bin/env python3
   2  # Copyright (c) The Bitcoin Core developers
   3  # Distributed under the MIT software license, see the accompanying
   4  # file COPYING or https://opensource.org/license/mit/.
   5  
   6  import subprocess
   7  import sys
   8  import shlex
   9  
  10  
  11  def run(cmd, **kwargs):
  12      print("+ " + shlex.join(cmd), flush=True)
  13      kwargs.setdefault("check", True)
  14      try:
  15          return subprocess.run(cmd, **kwargs)
  16      except Exception as e:
  17          sys.exit(str(e))
  18  
  19  
  20  def main():
  21      print("Running tests on commit ...")
  22      run(["git", "log", "-1"])
  23  
  24      num_procs = int(run(["nproc"], stdout=subprocess.PIPE).stdout)
  25      build_dir = "ci_build"
  26  
  27      run([
  28          "cmake",
  29          "-B",
  30          build_dir,
  31          "-Werror=dev",
  32          # Use clang++, because it is a bit faster and uses less memory than g++
  33          "-DCMAKE_C_COMPILER=clang",
  34          "-DCMAKE_CXX_COMPILER=clang++",
  35          # Use mold, because it is faster than the default linker
  36          "-DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=mold",
  37          # Use Debug build type for more debug checks, but enable optimizations
  38          "-DAPPEND_CXXFLAGS='-O3 -g2'",
  39          "-DAPPEND_CFLAGS='-O3 -g2'",
  40          "-DCMAKE_BUILD_TYPE=Debug",
  41          "-DCMAKE_COMPILE_WARNING_AS_ERROR=ON",
  42          "--preset=dev-mode",
  43          # Tolerate unused (member) functions in intermediate commits in a pull request
  44          "-DCMAKE_CXX_FLAGS=-Wno-error=unused-member-function -Wno-error=unused-function",
  45      ])
  46  
  47      if run(["cmake", "--build", build_dir, "-j", str(num_procs)], check=False).returncode != 0:
  48          print("Build failure. Verbose build follows.")
  49          run(["cmake", "--build", build_dir, "-j1", "--verbose"])
  50  
  51      run([
  52          "ctest",
  53          "--output-on-failure",
  54          "--stop-on-failure",
  55          "--test-dir",
  56          build_dir,
  57          "-j",
  58          str(num_procs),
  59      ])
  60      run([
  61          sys.executable,
  62          f"./{build_dir}/test/functional/test_runner.py",
  63          "-j",
  64          str(num_procs * 2),
  65          "--failfast",
  66          "--combinedlogslen=99999999",
  67      ])
  68  
  69  
  70  if __name__ == "__main__":
  71      main()
  72