From 456b69a4700b3aae07820ce8ba114060b538b744 Mon Sep 17 00:00:00 2001
From: Rene Milk <rene.milk@wwu.de>
Date: Fri, 21 Oct 2016 09:46:06 +0200
Subject: [PATCH] [cmake] adds prototype work dist script

---
 cmake/scripts/distribute_testing.py | 74 +++++++++++++++++++++++++++++
 dune/gdt/test/CMakeLists.txt        | 14 ++----
 2 files changed, 78 insertions(+), 10 deletions(-)
 create mode 100644 cmake/scripts/distribute_testing.py

diff --git a/cmake/scripts/distribute_testing.py b/cmake/scripts/distribute_testing.py
new file mode 100644
index 000000000..5ef273651
--- /dev/null
+++ b/cmake/scripts/distribute_testing.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python3
+
+import os
+import pickle
+import sys
+from pprint import pprint
+import subprocess
+import time
+from contextlib import contextmanager
+import binpacking
+
+MAXTIME = 45*60
+pickle_file = 'totals.pickle'
+
+
+@contextmanager
+def elapsed_timer():
+    clock = time.time
+    start = clock()
+    elapser = lambda: clock() - start
+    yield lambda: elapser()
+    end = clock()
+    elapser = lambda: end-start
+
+
+def redo_timings(argv):
+    builddir = argv[1]
+    builder_count = argv[2]
+    binaries = argv[3].split(';')
+    # list comes with a leading empty entry
+    testnames = argv[4].split('/')[1:]
+
+    os.chdir(builddir)
+    compiles = {}
+    testtimes = {}
+
+    testlimit = -1
+    binaries = binaries[:testlimit]
+    testnames = testnames[:testlimit]
+    totals = {}
+
+    for binary in binaries:
+        with elapsed_timer() as timer:
+            subprocess.check_call(['ninja', '-j1', binary])
+            compiles[binary] = timer()
+            totals[binary] = compiles[binary]
+    for binary, teststrings in zip(binaries, testnames):
+        testtimes[binary] = 0
+        pprint(teststrings.split('/'))
+        for test in teststrings.split('/'):
+            with elapsed_timer() as timer:
+                subprocess.check_call(['ctest', '-j1', '-R', test])
+                testtimes[binary] += timer()
+                totals[binary] = testtimes[binary]
+    print('compiles')
+    pprint(compiles)
+    print('testtimes')
+    pprint(testtimes)
+    print('totals')
+    pprint(totals)
+    pickle.dump(totals, open(os.path.join(builddir, pickle_file), 'wb'))
+    return totals
+
+
+try:
+    builddir = sys.argv[1]
+    totals = pickle.load(open(os.path.join(builddir, pickle_file), 'rb'))
+except FileNotFoundError:
+    totals = redo_timings(sys.argv)
+
+b = list(totals.values())
+bins = binpacking.to_constant_volume(b,MAXTIME)
+
+pprint(bins)
\ No newline at end of file
diff --git a/dune/gdt/test/CMakeLists.txt b/dune/gdt/test/CMakeLists.txt
index 4a7132d71..4d8baa847 100644
--- a/dune/gdt/test/CMakeLists.txt
+++ b/dune/gdt/test/CMakeLists.txt
@@ -17,18 +17,12 @@ set(DXT_TRAVIS_BUILDER 18)
 set(current_idx 0)
 
 foreach (target ${dxt_test_binaries})
-    math(EXPR list_idx "${current_idx} % ${DXT_TRAVIS_BUILDER}")
-    list(APPEND test_names_numbered_${list_idx} ${target})
-    foreach(testname ${dxt_test_names_${target}})
-        set_tests_properties(${testname} PROPERTIES LABELS "builder_${list_idx}")
-    endforeach()
-    MATH(EXPR current_idx "${current_idx}+1")
+    set(all_sorted_testnames "${all_sorted_testnames}/${dxt_test_names_${target}}")
 endforeach (target ${dxt_test_binaries})
+# message(STATUS "LL ${all_sorted_testnames}")
 
-MATH(EXPR max_idx "${DXT_TRAVIS_BUILDER}-1")
-foreach(idx RANGE 0 ${max_idx} 1)
-    add_custom_target(test_binaries_builder_${idx} DEPENDS ${test_names_numbered_${idx}})
-endforeach(idx RANGE 0 ${max_idx} 1)
+add_custom_target(refresh_test_timings python3 ${CMAKE_SOURCE_DIR}/cmake/scripts/distribute_testing.py
+    "${CMAKE_BINARY_DIR}" ${DXT_TRAVIS_BUILDER} "${dxt_test_binaries}" "${all_sorted_testnames}" VERBATIM)
 
 # link spe10 data file if present
 if (NOT ${SPE10MODEL1DATA} STREQUAL "SPE10MODEL1DATA-NOTFOUND")
-- 
GitLab