Skip to content

Commit 30dfcf7

Browse files
committed
fixes 5
1 parent 13bbba7 commit 30dfcf7

File tree

5 files changed

+146
-64
lines changed

5 files changed

+146
-64
lines changed

opt/Makefile

Lines changed: 38 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,37 @@ ROOT:=..
33
include readies/mk/main
44

55
MK.cmake:=1
6+
MK_CUSTOM_CMAKE_BUILD:=1
67
MK_CUSTOM_CLEAN:=1
78

89
MK_ALL_TARGETS=bindirs fetch build pack
910

11+
ifeq ($(COV),1)
12+
DEBUG ?= 1
13+
endif
14+
1015
#----------------------------------------------------------------------------------------------
1116

1217
define HELP
1318
make setup # install prerequisited (CAUTION: THIS WILL MODIFY YOUR SYSTEM)
1419
make fetch # download and prepare dependant modules
1520

16-
make build # compile and link
17-
DEBUG=1 # build for debugging
18-
VARIANT=name # build variant `name`
19-
WHY=1 # explain CMake decisions (into /tmp/cmake.why)
20-
make clean # remove build artifacts
21-
ALL=1 # remove entire artifacts directory
21+
make build # compile and link
22+
DEBUG=1 # build for debugging
23+
COV=1 # build for coverage analysis (implies DEBUG=1)
24+
VARIANT=name # build variant `name`
25+
WHY=1 # explain CMake decisions (into /tmp/cmake.why)
26+
make clean # remove build artifacts
27+
ALL=1 # remove entire artifacts directory
28+
make install # create ready-to-run scheme (module and engines)
2229

2330
make test # run tests
2431
TEST=test # run only test `test` with Redis output
2532
TEST_ARGS=args # add extra RLTest `args`
2633
VERBOSE=1 # verbose tests output
2734
COV=1 # perform coverage analysis
35+
VALGRIND|VGD=1 # test with Valgrind (implies DEBUG=1)
36+
CALLGRIND|CGD=1 # test with Callgrind (implies DEBUG=1)
2837
make cov-upload # upload coverage data to codecov.io (requires CODECOV_TOKEN)
2938

3039
make pack # create installation packages
@@ -33,6 +42,7 @@ make pack # create installation packages
3342
BRANCH=name # use `name` as branch name
3443
make deploy # copy packages to S3
3544
make release # release a version
45+
make docker # build docker image
3646

3747
fetch and build options:
3848
WITH_TF=0 # SKip TensofFlow
@@ -73,8 +83,6 @@ INSTALLED_TARGET=$(INSTALL_DIR)/redisai.so
7383

7484
BACKENDS_PATH ?= $(INSTALL_DIR)/backends
7585

76-
REDIS_VALGRIND_SUPRESS=$(ROOT)/opt/redis_valgrind.sup
77-
7886
#----------------------------------------------------------------------------------------------
7987

8088
CMAKE_FILES += \
@@ -114,24 +122,21 @@ include $(MK)/defs
114122

115123
#----------------------------------------------------------------------------------------------
116124

117-
.PHONY: deps prebuild fetch pack pack_ramp pack_deps test
125+
.PHONY: fetch deps pack pack_ramp pack_deps test
118126

119127
include $(MK)/rules
120128

121129
#----------------------------------------------------------------------------------------------
122130

123-
prebuild:
124-
$(SHOW)if [ ! -d $(DEPS_DIR) ]; then echo $$'Dependencies are not in place.\nPlease run \'make fetch\'.'; exit 1; fi
131+
#prebuild:
132+
# $(SHOW)if [ ! -d $(DEPS_DIR) ]; then echo $$'Dependencies are not in place.\nPlease run \'make fetch\'.'; exit 1; fi
125133

126-
$(info $(TARGET): $(MK_MAKEFILES) $(DEPS))
127-
$(TARGET): $(DEPS)
128-
$(SHOW)mkdir -p $(INSTALL_DIR)
134+
cmake-build $(TARGET): $(MK_MAKEFILES)
129135
$(SHOW)$(MAKE) -C $(BINDIR)
136+
$(SHOW)mkdir -p $(INSTALL_DIR)
130137
$(SHOW)$(MAKE) -C $(BINDIR) install
131-
# $(SHOW)cd $(ROOT) ;\
132-
# if [ ! -e install ]; then ln -sf install-$(DEVICE) install; fi
133138

134-
install:
139+
install $(INSTALLED_TARGET): $(TARGET)
135140
$(SHOW)mkdir -p $(INSTALL_DIR)
136141
$(SHOW)$(MAKE) -C $(BINDIR) install
137142

@@ -146,13 +151,18 @@ endif
146151

147152
#----------------------------------------------------------------------------------------------
148153

154+
setup:
155+
@echo Setting up system...
156+
$(SHOW)$(ROOT)/opt/readies/bin/getpy3
157+
$(SHOW)$(ROOT)/opt/system-setup.py
158+
149159
fetch deps:
150160
@echo Fetching dependencies...
151161
$(SHOW)VERBOSE=$(_SHOW) $(ROOT)/get_deps.sh $(DEPS_FLAGS)
152162

153163
#----------------------------------------------------------------------------------------------
154164

155-
pack:
165+
pack: $(INSTALLED_TARGET)
156166
ifneq ($(PACK_DEPS),0)
157167
$(SHOW)DEVICE=$(DEVICE) BINDIR=$(BINROOT) INSTALL_DIR=$(INSTALL_DIR) BRANCH=$(BRANCH) INTO=$(INTO) DEPS=1 ./pack.sh
158168
else
@@ -165,15 +175,9 @@ export GEN ?= 1
165175
export SLAVES ?= 1
166176
export AOF ?= 1
167177

168-
define VALGRIND_TEST_CMD
169-
$(TEST_CMD) \
170-
--no-output-catch \
171-
--use-valgrind \
172-
--vg-no-fail-on-errors \
173-
--vg-verbose
174-
--vg-options "$(VALGRIND_OPTIONS)" \
175-
--vg-suppressions $(realpath $(REDIS_VALGRIND_SUPRESS))
176-
endef
178+
ifneq ($(VGD),)
179+
VALGRIND=$(VGD)
180+
endif
177181

178182
test:
179183
ifeq ($(COV),1)
@@ -183,34 +187,19 @@ endif
183187
DEVICE=$(DEVICE) \
184188
MODULE=$(INSTALLED_TARGET) \
185189
GEN=$(GEN) AOF=$(AOF) SLAVES=$(SLAVES) \
190+
VALGRIND=$(VALGRIND) \
186191
$(ROOT)/test/tests.sh
187192
ifeq ($(COV),1)
188193
$(COVERAGE_COLLECT_REPORT)
189194
endif
190195

191-
#----------------------------------------------------------------------------------------------
196+
valgrind:
197+
$(SHOW)$(ROOT)/test/valgrind.sh $(realpath $(INSTALLED_TARGET))
192198

193-
docker:
194-
$(SHOW)docker build -t redisai --build-arg TEST=1 --build-arg PACK=1 ..
199+
callgrind:
200+
$(SHOW)CALLGRIND=1 $(ROOT)/test/valgrind.sh $(realpath $(INSTALLED_TARGET))
195201

196202
#----------------------------------------------------------------------------------------------
197203

198-
VALGRIND_ARGS=\
199-
$(VALGRIND_OPTIONS) \
200-
--suppressions=$(realpath $(REDIS_VALGRIND_SUPRESS)) \
201-
-v redis-server --protected-mode no --save "" --appendonly no
202-
203-
valgrind: $(TARGET)
204-
$(SHOW)valgrind $(VALGRIND_ARGS) --loadmodule $(realpath $(INSTALLED_TARGET))
205-
206-
CALLGRIND_ARGS=\
207-
--tool=callgrind \
208-
--dump-instr=yes \
209-
--simulate-cache=no \
210-
--collect-jumps=no \
211-
--collect-atstart=yes \
212-
--instr-atstart=yes \
213-
-v redis-server --protected-mode no --save "" --appendonly no
214-
215-
callgrind: $(TARGET)
216-
$(SHOW)valgrind $(CALLGRIND_ARGS) --loadmodule $(realpath $(INSTALLED_TARGET))
204+
docker:
205+
$(SHOW)docker build -t redisai --build-arg TEST=1 --build-arg PACK=1 ..

opt/readies/mk/cmake.defs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11

22
ifneq ($(MK.cmake),)
33

4+
MK_CMAKE_FILES ?= $(SRCDIR)/CMakeLists.txt
5+
46
MK_MAKEFILES += $(BINDIR)/Makefile
7+
DEFAULT_TARGETS += cmake-build
58

69
ifeq ($(DEBUG),1)
710
CMAKE_FLAGS += -DCMAKE_BUILD_TYPE=Debug

opt/readies/mk/cmake.rules

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

22
ifneq ($(MK.cmake),)
33

4-
MK_CMAKE_FILES ?= $(SRCDIR)/CMakeLists.txt
5-
6-
# bindirs
74
$(BINDIR)/Makefile : $(MK_CMAKE_FILES)
85
$(SHOW)if [ ! -d $(BINDIR) ]; then echo "CMake: $(BINDIR) does not exist."; exit 1; fi
96
$(SHOW)cd $(BINDIR); cmake $(CMAKE_WHY) $(CMAKE_FLAGS) $(abspath $(SRCDIR)) $(CMAKE_SINK)
107

11-
# $(SHOW)cd $(BINDIR); \
12-
# CMAKE_REL_ROOT=`python -c "import os; print os.path.relpath('$(SRCDIR)', '$$PWD')"` \
13-
# cmake $(CMAKE_FLAGS) $$CMAKE_REL_ROOT
8+
ifneq ($(MK_CUSTOM_CMAKE_BUILD),1)
9+
10+
cmake-build $(TARGET): $(MK_MAKEFILES)
11+
$(SHOW)$(MAKE) -C $(BINDIR)
12+
13+
endif
1414

1515
endif # MK.cmake

test/tests.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
[[ $IGNERR == 1 ]] || set -e
55

66
error() {
7-
echo "There are errors."
7+
echo "There are errors:"
8+
gawk 'NR>L-4 && NR<L+4 { printf "%-5d%4s%s\n",NR,(NR==L?">>> ":""),$0 }' L=$1 $0
89
exit 1
910
}
1011

11-
trap error ERR
12+
[[ -z $_Dbg_DEBUGGER_LEVEL ]] && trap 'error $LINENO' ERR
1213

1314
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
1415
. $HERE/../opt/readies/shibumi/functions
1516

17+
export ROOT=$(realpath $HERE/..)
18+
1619
#----------------------------------------------------------------------------------------------
1720

1821
help() {
@@ -57,20 +60,19 @@ check_redis_server() {
5760
#----------------------------------------------------------------------------------------------
5861

5962
valgrind_config() {
60-
VALGRIND_OPTIONS="\
63+
export VG_OPTIONS="
6164
-q \
6265
--leak-check=full \
6366
--show-reachable=no \
6467
--show-possibly-lost=no"
6568

6669
VALGRIND_SUPRESSIONS=$ROOT/opt/redis_valgrind.sup
6770

68-
RLTEST_ARGS+=" \
71+
RLTEST_ARGS+="\
6972
--no-output-catch \
7073
--use-valgrind \
7174
--vg-no-fail-on-errors \
72-
--vg-verbose
73-
--vg-options \"$VALGRIND_OPTIONS\" \
75+
--vg-verbose \
7476
--vg-suppressions $VALGRIND_SUPRESSIONS"
7577
}
7678

@@ -84,6 +86,8 @@ run_tests() {
8486

8587
#----------------------------------------------------------------------------------------------
8688

89+
[[ $1 == --help || $1 == help ]] && { help; exit 0; }
90+
8791
DEVICE=${DEVICE:-cpu}
8892

8993
GEN=${GEN:-1}
@@ -111,9 +115,6 @@ fi
111115

112116
#----------------------------------------------------------------------------------------------
113117

114-
[[ $1 == --help || $1 == help ]] && { help; exit 0; }
115-
116-
ROOT=$(realpath $HERE/..)
117118
cd $ROOT/test
118119

119120
install_git_lfs

test/valgrind.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
3+
[[ $VERBOSE == 1 ]] && set -x
4+
[[ $IGNERR == 1 ]] || set -e
5+
6+
error() {
7+
echo "There are errors."
8+
exit 1
9+
}
10+
11+
# trap error ERR
12+
13+
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
14+
. $HERE/../opt/readies/shibumi/functions
15+
16+
export ROOT=$(realpath $HERE/..)
17+
18+
#----------------------------------------------------------------------------------------------
19+
20+
help() {
21+
cat <<-END
22+
Run Valgrind/Callgrind on RedisAI.
23+
24+
[ARGVARS...] valgrind.sh [--help|help] [<module-so-path>]
25+
26+
Argument variables:
27+
VERBOSE=1 Print commands
28+
IGNERR=1 Do not abort on error
29+
30+
CALLGRIND|CGD=1 Run with Callgrind
31+
32+
END
33+
}
34+
35+
#----------------------------------------------------------------------------------------------
36+
37+
check_redis_server() {
38+
if ! command -v redis-server > /dev/null; then
39+
echo "Cannot find redis-server. Aborting."
40+
exit 1
41+
fi
42+
}
43+
44+
#----------------------------------------------------------------------------------------------
45+
46+
valgrind_config() {
47+
VALGRIND_SUPRESSIONS=$ROOT/opt/redis_valgrind.sup
48+
49+
if [[ $CALLGRIND == 1 ]]; then
50+
51+
VALGRIND_OPTIONS+="\
52+
--tool=callgrind \
53+
--dump-instr=yes \
54+
--simulate-cache=no \
55+
--collect-jumps=no \
56+
--collect-atstart=yes \
57+
--instr-atstart=yes \
58+
--callgrind-out-file=$MODULE.call"
59+
else
60+
VALGRIND_OPTIONS+="\
61+
-q \
62+
--leak-check=full \
63+
--show-reachable=no \
64+
--show-possibly-lost=no \
65+
--show-leak-kinds=all"
66+
fi
67+
68+
VALGRIND_OPTIONS+=" -v"
69+
}
70+
71+
#----------------------------------------------------------------------------------------------
72+
73+
[[ $1 == --help || $1 == help ]] && { help; exit 0; }
74+
75+
OP=""
76+
[[ $NOP == 1 ]] && OP="echo"
77+
78+
MODULE=${MODULE:-$1}
79+
[[ -z $MODULE || ! -f $MODULE ]] && { echo "Module not found. Aborting."; exit 1; }
80+
81+
VALGRIND_OPTIONS=""
82+
valgrind_config
83+
84+
#----------------------------------------------------------------------------------------------
85+
86+
cd $ROOT/test
87+
88+
check_redis_server
89+
$OP valgrind $(echo "$VALGRIND_OPTIONS") redis-server --protected-mode no --save '' --appendonly no --loadmodule $MODULE

0 commit comments

Comments
 (0)