-
Notifications
You must be signed in to change notification settings - Fork 25
/
Makefile
608 lines (527 loc) · 23 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
# BSD 2-Clause License
#
# Copyright (c) 2021-2024, Hewlett Packard Enterprise
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# General settings
MAKEFLAGS += --no-print-directory
SHELL:=/bin/bash
CWD := $(shell pwd)
# Build variables
NPROC := $(shell nproc 2>/dev/null || python -c "import multiprocessing as mp; print (mp.cpu_count())" 2>/dev/null || echo 4)
INSTALL_PREFIX := $(CWD)/install
TEST_PREFIX := $(CWD)/tests
EXAMPLES_PREFIX := $(CWD)/examples/bin
BUILD_FORTRAN := OFF
BUILD_PYTHON := OFF
BUILD_TYPE := Release
LINK_TYPE := shared
PEDANTIC := OFF
# Test dependencies
REDIS_URL := https://github.com/redis/redis.git
REDIS_VER := 7.2.4
REDISAI_URL := https://github.com/RedisAI/RedisAI.git
CATCH2_URL := https://github.com/catchorg/Catch2.git
CATCH2_VER := v2.13.6
LCOV_URL := https://github.com/linux-test-project/lcov.git
LCOV_VER := v2.0
# Test variables
DEP_CC := gcc
DEP_CXX := g++
COV_FLAGS :=
SR_TEST_REDIS_MODE := Clustered
SR_TEST_UDS_FILE := /tmp/redis.sock
SR_TEST_PORT := 6379
SR_TEST_NODES := 3
SR_TEST_REDISAI_VER := v1.2.7
SR_TEST_DEVICE := cpu
SR_TEST_DEVICE_UPPER := $(shell echo $(SR_TEST_DEVICE) | tr '[:lower:]' '[:upper:]')
SR_TEST_PYTEST_FLAGS := -vv -s
ifeq ($(LINK_TYPE), shared)
BUILD_SHARED_LIBS=on
else
BUILD_SHARED_LIBS=off
endif
SR_TEST_INSTALL_PREFIX = $(CWD)/install/$(BUILD_TYPE)/$(LINK_TYPE)
LIBTORCH_CPU_URL = https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.3.1%2Bcpu.zip
LIBTORCH_CUDA11_URL = https://download.pytorch.org/libtorch/cu118/libtorch-cxx11-abi-shared-with-deps-2.3.1%2Bcu118.zip
TORCH_CPU_PIP = pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cpu
TORCH_CUDA11_PIP = pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cu118
# Do not remove this block. It is used by the 'help' rule when
# constructing the help output.
# help:
# help: SmartRedis Makefile help
# help:
# help: help - display this makefile's help information
.PHONY: help
help:
@grep "^# help\:" Makefile | grep -v grep | sed 's/\# help\: //' | sed 's/\# help\://'
# help:
# help: Build variables
# help: ---------------
# help:
# help: These variables affect the way that the SmartRedis library is built. Each
# help: has several options; the first listed is the default. Use by appending
# help: the variable name and setting after the make target, e.g.
# help: make lib BUILD_TYPE=Debug Static BUILD_FORTRAN=ON
# help:
# help: BUILD_TYPE {Release, Debug, Coverage} -- optimization level for the build
# help: LINK_TYPE {shared, static} -- type of linking for the smartredis libraries
# help: PEDANTIC {OFF, ON} -- GNU only; enable pickiest compiler settings,
# help: currently fails due to warnings on newer GNU versions
# help: BUILD_FORTRAN {OFF, ON} -- Enable/disable build of Fortran library
# help: BUILD_PYTHON {OFF, ON} -- Enable/disable build of Python library
# help:
# help: Test variables
# help: --------------
# help:
# help: These variables affect the way that the SmartRedis library is tested. Each
# help: has several options; the first listed is the default. Use by appending
# help: the variable name and setting after the make target, e.g.
# help: make test BUILD_TYPE=Debug BUILD_SHARED_LIBS=off BUILD_FORTRAN=ON
# help:
# help: SR_TEST_REDIS_MODE {Clustered, Standalone} -- type of Redis backend launched for tests
# help: SR_TEST_PORT (Default: 6379) -- first port for Redis server(s)
# help: SR_TEST_NODES (Default: 3) Number of shards to intantiate for a clustered Redis database
# help: SR_TEST_REDISAI_VER {v1.2.7} -- version of RedisAI to use for tests
# help: SR_TEST_DEVICE {cpu, gpu} -- device type to test on. Warning, this variable is CASE SENSITIVE!
# help: SR_TEST_PYTEST_FLAGS (default: "-vv -s"): Verbosity flags to use with pytest
# help:
# help: Build targets
# help: -------------
# help: lib - Build SmartRedis C/C++/Python clients into a dynamic library
.PHONY: lib
lib:
lib:
@cmake -S . -B build/$(BUILD_TYPE) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) \
-DPEDANTIC=$(PEDANTIC) -DBUILD_FORTRAN=$(BUILD_FORTRAN) -DBUILD_PYTHON=$(BUILD_PYTHON) \
-DCMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX)
@cmake --build build/$(BUILD_TYPE) -- -j $(NPROC)
@cmake --install build/$(BUILD_TYPE)
# help: lib-with-fortran - Build SmartRedis C/C++/Python and Fortran clients into a dynamic library
.PHONY: lib-with-fortran
lib-with-fortran: BUILD_FORTRAN=ON
lib-with-fortran: lib
# help: test-lib - Build SmartRedis clients into a dynamic library with least permissive compiler settings
.PHONY: test-lib
test-lib: PEDANTIC=OFF # Re-enable after warnings fixed
test-lib: lib
# help: test-lib-with-fortran - Build SmartRedis clients into a dynamic library with least permissive compiler settings
.PHONY: test-lib-with-fortran
test-lib-with-fortran: PEDANTIC=off
test-lib-with-fortran: lib-with-fortran
# help: test-deps - Make SmartRedis testing dependencies
.PHONY: test-deps
test-deps: redis
test-deps: redisAI
test-deps: lcov
# help: test-deps-gpu - Make SmartRedis GPU testing dependencies
.PHONY: test-deps-gpu
test-deps-gpu: SR_TEST_DEVICE=gpu
test-deps-gpu: test-deps
# help: build-tests - build all tests (C, C++, Fortran)
.PHONY: build-tests
build-tests: test-lib-with-fortran
build-tests: build-unit-test-cpp
build-tests: build-test-cpp
build-tests: build-test-c
build-tests: build-test-fortran
# help: build-test-cpp - build the C++ tests
.PHONY: build-test-cpp
build-test-cpp: test-lib
build-test-cpp: catch2
@cmake -S tests/cpp -B build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/cpp \
-DBUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis \
-DCMAKE_INSTALL_PREFIX=$(TEST_PREFIX)/cpp
@cmake --build build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/cpp -- -j $(NPROC)
@cmake --install build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/cpp
# help: build-unit-test-cpp - build the C++ unit tests
.PHONY: build-unit-test-cpp
build-unit-test-cpp: test-lib
build-unit-test-cpp: catch2
@cmake -S tests/cpp/unit-tests -B build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/cpp/unit-tests \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) \
-DCMAKE_INSTALL_PREFIX=$(TEST_PREFIX)/cpp \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis
@cmake --build build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/cpp/unit-tests -- -j $(NPROC)
@cmake --install build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/cpp/unit-tests
# help: build-test-c - build the C tests
.PHONY: build-test-c
build-test-c: test-lib
@cmake -S tests/c -B build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/c \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis \
-DCMAKE_INSTALL_PREFIX=$(TEST_PREFIX)/c
@cmake --build build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/c -- -j $(NPROC)
@cmake --install build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/c
# help: build-test-fortran - build the Fortran tests
.PHONY: build-test-fortran
build-test-fortran: BUILD_FORTRAN=ON
build-test-fortran: test-lib-with-fortran
@cmake -S tests/fortran -B build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/fortran \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) \
-DCMAKE_INSTALL_PREFIX=$(TEST_PREFIX)/fortran \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis \
-Dsmartredis-fortran_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis-fortran
@cmake --build build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/fortran -- -j $(NPROC)
@cmake --install build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/fortran
# help: build-examples - build all examples (serial, parallel)
.PHONY: build-examples
build-examples: lib
@cmake -S examples -B build/$(BUILD_TYPE)/examples/$(LINK_TYPE) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -DBUILD_FORTRAN=$(BUILD_FORTRAN) \
-DCMAKE_INSTALL_PREFIX=$(EXAMPLES_PREFIX) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis \
-Dsmartredis-fortran_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis-fortran
@cmake --build build/$(BUILD_TYPE)/examples/$(LINK_TYPE) -- -j $(NPROC)
@cmake --install build/$(BUILD_TYPE)/examples/$(LINK_TYPE)/
# help: build-example-serial - buld serial examples
.PHONY: build-example-serial
build-example-serial: lib
@cmake -S examples/serial -B build/$(BUILD_TYPE)/examples/$(LINK_TYPE)/serial \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -DBUILD_FORTRAN=$(BUILD_FORTRAN) \
-DCMAKE_INSTALL_PREFIX=$(EXAMPLES_PREFIX) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis \
-Dsmartredis-fortran_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis-fortran
@cmake --build build/$(BUILD_TYPE)/examples/$(LINK_TYPE)/serial
# help: build-example-parallel - build parallel examples (requires MPI)
.PHONY: build-example-parallel
build-example-parallel: lib
@cmake -S examples/parallel -B build/$(BUILD_TYPE)/examples/$(LINK_TYPE)/parallel \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -DBUILD_FORTRAN=$(BUILD_FORTRAN) \
-DCMAKE_INSTALL_PREFIX=$(EXAMPLES_PREFIX) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis \
-Dsmartredis-fortran_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis-fortran
@cmake --build build/$(BUILD_TYPE)/examples/$(LINK_TYPE)/parallel
# help: clean-deps - remove third-party deps
.PHONY: clean-deps
clean-deps:
@rm -rf ./third-party ./install/lib/libhiredis.a ./install/lib/libredis++.a
# help: clean - remove builds, pyc files
.PHONY: clean
clean:
@git clean -X -f -d
rm -rf build
# help: clobber - clean, remove deps, builds, (be careful)
.PHONY: clobber
clobber: clean clean-deps
# help:
# help: Style targets
# help: -------------
# help: style - Sort imports and format with black
.PHONY: style
style: sort-imports format
# help: check-style - check code style compliance
.PHONY: check-style
check-style: check-sort-imports check-format
# help: format - perform code style format
.PHONY: format
format:
@black ./src/python/module/smartredis ./tests/python/
# help: check-format - check code format compliance
.PHONY: check-format
check-format:
@black --check ./src/python/module/smartredis ./tests/python/
# help: sort-imports - apply import sort ordering
.PHONY: sort-imports
sort-imports:
@isort ./src/python/module/smartredis ./tests/python/ --profile black
# help: check-sort-imports - check imports are sorted
.PHONY: check-sort-imports
check-sort-imports:
@isort ./src/python/module/smartredis ./tests/python/ --check-only --profile black
# help: check-lint - run static analysis checks
.PHONY: check-lint
check-lint:
@pylint --rcfile=.pylintrc ./src/python/module/smartredis
# help:
# help: Documentation targets
# help: ---------------------
# help: docs - generate project documentation
.PHONY: docs
docs:
@cd doc; make html
# help: cov - generate html coverage report for Python client
.PHONY: cov
cov:
@coverage html
@echo if data was present, coverage report is in htmlcov/index.html
# help:
# help: Test targets
# help: ------------
# Build Pytest flags to skip various subsets of the tests
ifeq ($(BUILD_PYTHON),OFF)
SKIP_PYTHON = --ignore ./tests/python
endif
ifeq ($(BUILD_FORTRAN),OFF)
SKIP_FORTRAN = --ignore ./tests/fortran
endif
SKIP_DOCKER := --ignore ./tests/docker
# Build SSDB string for clustered database
SSDB_STRING := 127.0.0.1:$(SR_TEST_PORT)
PORT_RANGE := $(shell seq `expr $(SR_TEST_PORT) + 1` 1 `expr $(SR_TEST_PORT) + $(SR_TEST_NODES) - 1`)
SSDB_STRING += $(foreach P,$(PORT_RANGE),",127.0.0.1:$(P)")
SSDB_STRING := $(shell echo $(SSDB_STRING) | tr -d " ")
# Run test cases with a freshly instantiated standalone Redis server
# Parameters:
# 1: the test directory in which to run tests
define run_smartredis_tests_with_standalone_server
echo "Launching standalone Redis server" && \
export SR_TEST_DEVICE=$(SR_TEST_DEVICE) SR_DB_TYPE=Standalone && \
export SSDB=127.0.0.1:$(SR_TEST_PORT) && \
python utils/launch_redis.py --port $(SR_TEST_PORT) --nodes 1 \
--rai $(SR_TEST_REDISAI_VER) --device $(SR_TEST_DEVICE) && \
echo "Running standalone tests" && \
PYTHONFAULTHANDLER=1 python -m pytest $(SR_TEST_PYTEST_FLAGS) $(COV_FLAGS) \
$(SKIP_DOCKER) $(SKIP_PYTHON) $(SKIP_FORTRAN) \
--bin-path $(2) --build-fortran $(BUILD_FORTRAN) $(1) ; \
(testresult=$$?; \
echo "Shutting down standalone Redis server" && \
python utils/launch_redis.py --port $(SR_TEST_PORT) --nodes 1 --stop && \
test $$testresult -eq 0 || cat *.log; exit $$testresult) && \
echo "Standalone tests complete"
endef
# Run test cases with a freshly instantiated clustered Redis server
# Parameters:
# 1: the test directory in which to run tests
define run_smartredis_tests_with_clustered_server
echo "Launching clustered Redis server" && \
export SR_TEST_DEVICE=$(SR_TEST_DEVICE) SR_DB_TYPE=Clustered && \
export SSDB=$(SSDB_STRING) && \
python utils/launch_redis.py --port $(SR_TEST_PORT) --nodes $(SR_TEST_NODES) \
--rai $(SR_TEST_REDISAI_VER) --device $(SR_TEST_DEVICE) && \
echo "Running clustered tests" && \
PYTHONFAULTHANDLER=1 python -s -m pytest $(SR_TEST_PYTEST_FLAGS) $(COV_FLAGS) \
$(SKIP_DOCKER) $(SKIP_PYTHON) $(SKIP_FORTRAN) \
--bin-path $(2) --build-fortran $(BUILD_FORTRAN) $(1) ; \
(testresult=$$?; \
echo "Shutting down clustered Redis server" && \
python utils/launch_redis.py --port $(SR_TEST_PORT) \
--nodes $(SR_TEST_NODES) --stop; \
test $$testresult -eq 0 || cat *.log; exit $$testresult) && \
echo "Clustered tests complete"
endef
# Run test cases with a freshly instantiated standalone Redis server
# connected via a Unix Domain Socket
# Parameters:
# 1: the test directory in which to run tests
define run_smartredis_tests_with_uds_server
echo "Launching standalone Redis server with Unix Domain Socket support"
export SR_TEST_DEVICE=$(SR_TEST_DEVICE) SR_DB_TYPE=Standalone && \
export SSDB=unix://$(SR_TEST_UDS_FILE) && \
python utils/launch_redis.py --port $(SR_TEST_PORT) --nodes 1 \
--rai $(SR_TEST_REDISAI_VER) --device $(SR_TEST_DEVICE) \
--udsport $(SR_TEST_UDS_FILE) && \
echo "Running standalone tests with Unix Domain Socket connection" && \
PYTHONFAULTHANDLER=1 python -m pytest $(SR_TEST_PYTEST_FLAGS) $(COV_FLAGS) \
$(SKIP_DOCKER) $(SKIP_PYTHON) $(SKIP_FORTRAN) \
--bin-path $(2) --build-fortran $(BUILD_FORTRAN) $(1) ; \
(testresult=$$?; \
echo "Shutting down standalone Redis server with Unix Domain Socket support" && \
python utils/launch_redis.py --port $(SR_TEST_PORT) --nodes 1 \
--udsport $(SR_TEST_UDS_FILE) --stop; \
test $$testresult -eq 0 || cat *.log; exit $$testresult) && \
echo "UDS tests complete"
endef
# Run test cases with freshly instantiated Redis servers
# Parameters:
# 1: the test directory in which to run tests
define run_smartredis_tests_with_server
$(if $(or $(filter $(SR_TEST_REDIS_MODE),Standalone),
$(filter $(SR_TEST_REDIS_MODE),All)),
$(call run_smartredis_tests_with_standalone_server,$(1),$(2))
)
$(if $(or $(filter $(SR_TEST_REDIS_MODE),Clustered),
$(filter $(SR_TEST_REDIS_MODE),All)),
$(call run_smartredis_tests_with_clustered_server,$(1),$(2))
)
$(if $(or $(filter $(SR_TEST_REDIS_MODE),UDS),
$(filter $(SR_TEST_REDIS_MODE),All)),
$(if $(filter-out $(shell uname -s),Darwin),
$(call run_smartredis_tests_with_uds_server,$(1),$(2)),
@echo "Skipping: Unix Domain Socket is not supported on MacOS"
)
)
endef
# help: test - Build and run all tests (C, C++, Fortran, Python)
.PHONY: test
test: test-deps
test: build-tests
test: SR_TEST_PYTEST_FLAGS := -vv
test:
@$(call run_smartredis_tests_with_server,./tests, $(TEST_PREFIX))
# help: test-verbose - Build and run all tests [verbosely]
.PHONY: test-verbose
test-verbose: test-deps
test-verbose: build-tests
test-verbose: SR_TEST_PYTEST_FLAGS := -vv -s
test-verbose:
@$(call run_smartredis_tests_with_server,./tests, $(TEST_PREFIX))
# help: test-verbose-with-coverage - Build and run all tests [verbose-with-coverage]
.PHONY: test-verbose-with-coverage
test-verbose-with-coverage: BUILD_TYPE := Coverage
test-verbose-with-coverage: test-deps
test-verbose-with-coverage: build-tests
test-verbose-with-coverage: SR_TEST_PYTEST_FLAGS := -vv -s
test-verbose-with-coverage:
@$(call run_smartredis_tests_with_server,./tests, $(TEST_PREFIX))
# help: test-c - Build and run all C tests
.PHONY: test-c
test-c: build-test-c
test-c: SR_TEST_PYTEST_FLAGS := -vv -s
test-c:
@$(call run_smartredis_tests_with_server,./tests/c, $(TEST_PREFIX))
# help: test-cpp - Build and run all C++ tests
.PHONY: test-cpp
test-cpp: build-test-cpp
test-cpp: build-unit-test-cpp
test-cpp: SR_TEST_PYTEST_FLAGS := -vv -s
test-cpp:
@$(call run_smartredis_tests_with_server,./tests/cpp, $(TEST_PREFIX))
# help: unit-test-cpp - Build and run unit tests for C++
.PHONY: unit-test-cpp
unit-test-cpp: build-unit-test-cpp
unit-test-cpp: SR_TEST_PYTEST_FLAGS := -vv -s
unit-test-cpp:
@$(call run_smartredis_tests_with_server,./tests/cpp/unit-tests, $(TEST_PREFIX))
# help: test-py - run python tests
.PHONY: test-py
test-py: test-deps
test-py: BUILD_PYTHON := ON
test-py: lib
test-py: SR_TEST_PYTEST_FLAGS := -vv
test-py:
@$(call run_smartredis_tests_with_server,./tests/python, $(TEST_PREFIX))
# help: test-fortran - run fortran tests
.PHONY: test-fortran
test-fortran: BUILD_FORTRAN := ON
test-fortran: build-test-fortran
test-fortran: SR_TEST_PYTEST_FLAGS := -vv -s
test-fortran:
@$(call run_smartredis_tests_with_server,./tests/fortran, $(TEST_PREFIX))
# help: testpy-cov - run python tests with coverage
.PHONY: testpy-cov
testpy-cov: test-deps
testpy-cov: BUILD_PYTHON := ON
testpy-cov: SR_TEST_PYTEST_FLAGS := -vv
testpy-cov: COV_FLAGS := --cov=./src/python/module/smartredis/
testpy-cov:
@$(call run_smartredis_tests_with_server,./tests/python, $(TEST_PREFIX))
# help: test-examples - Build and run all examples
.PHONY: test-examples
test-examples: test-deps
test-examples: build-examples
testpy-cov: SR_TEST_PYTEST_FLAGS := -vv -s
test-examples:
@$(call run_smartredis_tests_with_server,./examples,$(EXAMPLES_PREFIX))
############################################################################
# hidden build targets for third-party software
# cudnn-check (hidden test target)
# checks cuda dependencies for GPU build
.PHONY: cudnn-check
cudnn-check:
ifeq ($(SR_TEST_DEVICE),gpu)
ifndef CUDA_HOME
$(error ERROR: CUDA_HOME is not set)
endif
ifndef CUDNN_INCLUDE_DIR
$(error ERROR: CUDNN_INCLUDE_DIR is not set)
endif
ifeq (,$(wildcard $(CUDNN_INCLUDE_DIR)/cudnn.h))
$(error ERROR: could not find cudnn.h at $(CUDNN_INCLUDE_DIR))
endif
ifndef CUDNN_LIBRARY
$(error ERROR: CUDNN_LIBRARY is not set)
endif
ifeq (,$(wildcard $(CUDNN_LIBRARY)/libcudnn.so))
$(error ERROR: could not find libcudnn.so at $(CUDNN_LIBRARY))
endif
endif
# Redis (hidden test target)
.PHONY: redis
third-party/redis:
@mkdir -p third-party
@cd third-party && \
git clone $(REDIS_URL) redis --branch $(REDIS_VER) --depth=1
redis: third-party/redis/src/redis-server
third-party/redis/src/redis-server: third-party/redis
@cd third-party/redis && \
make CC=$(DEP_CC) CXX=$(DEP_CXX) MALLOC=libc -j $(NPROC) && \
echo "Finished installing redis"
# RedisAI (hidden test target)
third-party/RedisAI:
@mkdir -p third-party
@cd third-party && \
rm -rf RedisAI/$(SR_TEST_REDISAI_VER) && \
GIT_LFS_SKIP_SMUDGE=1 git clone $(REDISAI_URL) RedisAI/$(SR_TEST_REDISAI_VER) \
--branch $(SR_TEST_REDISAI_VER) --depth=1
.PHONY: redisAI
redisAI: cudnn-check
redisAI: pytorch
redisAI: dlpack
redisAI: third-party/RedisAI/$(SR_TEST_REDISAI_VER)/install-$(SR_TEST_DEVICE)/redisai.so
third-party/RedisAI/$(SR_TEST_REDISAI_VER)/install-$(SR_TEST_DEVICE)/redisai.so: third-party/RedisAI
@cd third-party/RedisAI/$(SR_TEST_REDISAI_VER) && \
mkdir -p build-$(SR_TEST_DEVICE) && cd build-$(SR_TEST_DEVICE) && \
sed -E -i "s/CXX_STANDARD (11|14)/CXX_STANDARD 17/g" ../src/backends/libtorch_c/CMakeLists.txt && \
cmake -DBUILD_TF=0 -DBUILD_ORT=0 -DBUILD_TORCH=1 -DBUILD_TFLITE=0 \
-DDEPS_PATH=$(CWD)/third-party/backends \
-DDEVICE=$(SR_TEST_DEVICE) \
-DINSTALL_PATH=../install-$(SR_TEST_DEVICE) \
-DCMAKE_C_COMPILER=$(DEP_CC) \
-DCMAKE_CXX_COMPILER=$(DEP_CXX) ../ && \
make -j install && \
chmod +x ../install-$(SR_TEST_DEVICE)/redisai.so
echo "Finished installing RedisAI"
# Catch2 (hidden test target)
.PHONY: catch2
catch2: third-party/catch/single_include/catch2/catch.hpp
third-party/catch/single_include/catch2/catch.hpp:
@mkdir -p third-party
@cd third-party && \
git clone $(CATCH2_URL) catch --branch $(CATCH2_VER) --depth=1
@echo "Finished installing Catch2"
# LCOV (hidden test target)
.PHONY: lcov
lcov: third-party/lcov/install/bin/lcov
third-party/lcov/install/bin/lcov:
@echo Installing LCOV
@mkdir -p third-party
@cd third-party && \
git clone $(LCOV_URL) lcov --branch $(LCOV_VER) --depth=1
@cd third-party/lcov && \
mkdir -p install && \
make CC=$(DEP_CC) CXX=$(DEP_CXX) PREFIX=$(CWD)/third-party/lcov/install/ install && \
echo "Finished installing LCOV"
.PHONY: dlpack
dlpack: third-party/backends/dlpack
third-party/backends/dlpack:
git clone --branch v0.5_RAI https://github.com/RedisAI/dlpack.git $@
.PHONY: pytorch
pytorch: third-party/backends/libtorch
third-party/backends/libtorch:
@mkdir -p third-party/backends
wget -O third-party/backends/libtorch.zip $(LIBTORCH_$(SR_TEST_DEVICE_UPPER)_URL)
cd third-party/backends && unzip libtorch.zip && rm libtorch.zip
$(TORCH_$(SR_TEST_DEVICE_UPPER)_PIP)