Skip to content

Commit 5d9b275

Browse files
committed
[spack] Add test support
1 parent 5f8afe0 commit 5d9b275

File tree

2 files changed

+108
-10
lines changed

2 files changed

+108
-10
lines changed

spack/package.py

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
55

66
from spack import *
7+
import glob
78

89

910
class Genn(PythonPackage):
@@ -16,22 +17,32 @@ class Genn(PythonPackage):
1617
version('4.6.0', sha256='5e5ca94fd3a56b5b963a4911ea1b2130df6fa7dcdde3b025bd8cb85d4c2d3236')
1718

1819
conflicts('%gcc@:4.9.3')
19-
depends_on('gmake', type='build')
20+
depends_on('gmake', type='build')
21+
depends_on('googletest', type=('build', 'run', 'test'))
22+
depends_on('lcov', type=('build', 'run', 'test'))
2023

2124
variant('cuda', default=True, description='Enable CUDA support')
2225
depends_on('cuda', when='+cuda')
2326

2427
variant('python', default=True, description='Enable PyGeNN')
2528
extends('python', when='+python')
26-
depends_on('[email protected]:', when='+python')
27-
depends_on('[email protected]:', when='+python')
28-
depends_on('py-six', when='+python')
29-
depends_on('py-deprecated', when='+python')
30-
depends_on('py-psutil', when='+python')
31-
depends_on('[email protected]:', when='+python')
32-
depends_on('swig', when='+python')
29+
depends_on('[email protected]:', when='+python', type=('build', 'run', 'test'))
30+
depends_on('[email protected]:', when='+python', type=('build', 'run', 'test'))
31+
depends_on('py-six', when='+python', type=('build', 'run', 'test'))
32+
depends_on('py-deprecated', when='+python', type=('build', 'run', 'test'))
33+
depends_on('py-psutil', when='+python', type=('build', 'run', 'test'))
34+
depends_on('[email protected]:', when='+python', type=('build', 'run', 'test'))
35+
depends_on('swig', when='+python', type=('build', 'run', 'test'))
3336

3437
patch('include_path.patch')
38+
patch('tests_gtest.patch')
39+
40+
def patch(self):
41+
files = set(glob.glob("tests/**/Makefile", recursive=True))
42+
filter_file('\$\(GTEST_DIR\)/src/gtest-all\.cc',
43+
'-L$(GTEST_DIR)/lib -lgtest', *files)
44+
filter_file('\$\(GTEST_DIR\)/src/gtest_main\.cc',
45+
'-L$(GTEST_DIR)/lib -lgtest_main', *files)
3546

3647
def build(self, spec, prefix):
3748
make('PREFIX={}'.format(prefix), 'install')
@@ -42,8 +53,10 @@ def build(self, spec, prefix):
4253
def install(self, spec, prefix):
4354
install_tree('bin', prefix.bin)
4455
install_tree('include', prefix.include)
45-
mkdirp(prefix.src.genn)
46-
install_tree('src/genn', prefix.src.genn)
56+
mkdirp(prefix.src)
57+
install_tree('src', prefix.src)
58+
install_tree('tests', prefix.tests)
59+
install('version.txt', prefix)
4760
if '+python' in self.spec:
4861
super(Genn, self).install(spec, prefix)
4962

@@ -53,3 +66,20 @@ def setup_run_environment(self, env):
5366
env.append_path('CUDA_PATH', self.spec['cuda'].prefix)
5467
if '+python' in self.spec:
5568
super(Genn, self).setup_run_environment(env)
69+
70+
def test(self):
71+
env['CC'] = self.compiler.cc
72+
env['CXX'] = self.compiler.cxx
73+
# workaround for https://github.com/spack/spack/issues/20553
74+
env['GTEST_DIR'] = self.spec['googletest'].prefix
75+
env['LD_LIBRARY_PATH'] = self.spec['googletest'].prefix.lib
76+
env['PATH'] = '{}:{}'.format(self.spec['lcov'].prefix.bin, env['PATH'])
77+
# overriding automatic python testing
78+
with working_dir(self.prefix.tests):
79+
# FIXME:
80+
# * expects a non-zero return code for errors
81+
# * also too slow for a simple install test?
82+
# ⇒ provide another simple install test?
83+
self.run_test('run_tests.sh')
84+
if '+python' in self.spec:
85+
super(Genn, self).test()

spack/tests_gtest.patch

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
diff --git i/tests/spineml/generator/Makefile w/tests/spineml/generator/Makefile
2+
index 25e240349..6d0c7aa71 100644
3+
--- i/tests/spineml/generator/Makefile
4+
+++ w/tests/spineml/generator/Makefile
5+
@@ -17,8 +17,7 @@ include ../../../src/genn/MakefileCommon
6+
# Get simulate SpineML path i.e. directory of this Makefile
7+
SPINEML_GEN_TEST_PATH :=$(GENN_DIR)/tests/spineml/generator
8+
9+
-TEST_SOURCES := $(GTEST_DIR)/src/gtest-all.cc $(GTEST_DIR)/src/gtest_main.cc
10+
-TEST_SOURCES += $(SPINEML_GEN_TEST_PATH)/*.cc
11+
+TEST_SOURCES := $(SPINEML_GEN_TEST_PATH)/*.cc
12+
TEST_SOURCES += $(GENN_DIR)/src/spineml/generator/modelCommon.cc
13+
14+
# Add compiler and linker flags to link SpineML simulator and common libraries; and pthreads
15+
@@ -33,7 +32,7 @@ TEST :=$(SPINEML_GEN_TEST_PATH)/test$(GENN_PREFIX)
16+
all: $(TEST)
17+
18+
$(TEST): $(TEST_SOURCES) genn spineml_common
19+
- $(CXX) -std=c++11 $(CXXFLAGS) $(TEST_SOURCES) -o $@ $(LDFLAGS)
20+
+ $(CXX) -std=c++11 $(CXXFLAGS) $(TEST_SOURCES) -L$(GTEST_DIR)/lib -lgtest -lgtest_main -o $@ $(LDFLAGS)
21+
22+
genn:
23+
$(MAKE) -C $(GENN_DIR)/src/genn/genn
24+
diff --git i/tests/spineml/simulator/Makefile w/tests/spineml/simulator/Makefile
25+
index 326e2340b..9c4019e78 100644
26+
--- i/tests/spineml/simulator/Makefile
27+
+++ w/tests/spineml/simulator/Makefile
28+
@@ -17,8 +17,7 @@ include ../../../src/genn/MakefileCommon
29+
# Get simulate SpineML path i.e. directory of this Makefile
30+
SPINEML_SIM_TEST_PATH :=$(GENN_DIR)/tests/spineml/simulator
31+
32+
-TEST_SOURCES := $(GTEST_DIR)/src/gtest-all.cc $(GTEST_DIR)/src/gtest_main.cc
33+
-TEST_SOURCES += $(SPINEML_SIM_TEST_PATH)/*.cc
34+
+TEST_SOURCES := $(SPINEML_SIM_TEST_PATH)/*.cc
35+
36+
# Add compiler and linker flags to link SpineML simulator and common libraries; and pthreads
37+
LDFLAGS += -L$(GENN_DIR)/lib -lspineml_simulator$(GENN_PREFIX) -lspineml_common$(GENN_PREFIX) -lpthread
38+
@@ -32,7 +31,7 @@ TEST :=$(SPINEML_SIM_TEST_PATH)/test$(GENN_PREFIX)
39+
all: $(TEST)
40+
41+
$(TEST): $(TEST_SOURCES) spineml_common spineml_simulator
42+
- $(CXX) -std=c++11 $(CXXFLAGS) $(TEST_SOURCES) -o $@ $(LDFLAGS)
43+
+ $(CXX) -std=c++11 $(CXXFLAGS) $(TEST_SOURCES) -L$(GTEST_DIR)/lib -lgtest -lgtest_main -o $@ $(LDFLAGS)
44+
45+
spineml_common:
46+
$(MAKE) -C $(GENN_DIR)/src/spineml/common
47+
diff --git c/tests/unit/Makefile w/tests/unit/Makefile
48+
index 8376deadf..f3a6445b5 100644
49+
--- c/tests/unit/Makefile
50+
+++ w/tests/unit/Makefile
51+
@@ -5,7 +5,7 @@ include ../../src/genn/MakefileCommon
52+
UNIT_TEST_PATH :=$(GENN_DIR)/tests/unit
53+
OBJECT_DIRECTORY :=$(OBJECT_DIRECTORY)/tests/unit
54+
55+
-SOURCES :=$(GTEST_DIR)/src/gtest-all.cc $(GTEST_DIR)/src/gtest_main.cc $(wildcard *.cc)
56+
+SOURCES :=$(wildcard *.cc)
57+
OBJECTS :=$(SOURCES:%.cc=$(OBJECT_DIRECTORY)/%.o)
58+
DEPS :=$(OBJECTS:.o=.d)
59+
60+
@@ -21,7 +21,7 @@ TEST :=$(UNIT_TEST_PATH)/test$(GENN_PREFIX)
61+
all: $(TEST)
62+
63+
$(TEST): $(OBJECTS) libgenn backend
64+
- $(CXX) $(CXXFLAGS) $(OBJECTS) -o $@ $(LDFLAGS)
65+
+ $(CXX) $(CXXFLAGS) $(OBJECTS) -L$(GTEST_DIR)/lib -lgtest -lgtest_main -o $@ $(LDFLAGS)
66+
67+
-include $(DEPS)
68+

0 commit comments

Comments
 (0)