Skip to content

Commit 0a8d521

Browse files
committed
add ASAN tesing workflow
This patch introduces a way to enable ASAN in our tests. Also special workflow is introduced. This patch is also catched heap-overflow buffer. Closes #67
1 parent c456878 commit 0a8d521

File tree

6 files changed

+91
-12
lines changed

6 files changed

+91
-12
lines changed

.github/workflows/asan_testing.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: fast_testing
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
linux:
10+
# We want to run on external PRs, but not on our own internal
11+
# PRs as they'll be run by the push to the branch.
12+
#
13+
# The main trick is described here:
14+
# https://github.com/Dart-Code/Dart-Code/pull/2375
15+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
16+
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/setup-python@v3
20+
with:
21+
python-version: '3.10'
22+
23+
- name: Clone the module
24+
uses: actions/checkout@v3
25+
with:
26+
submodules: true
27+
28+
- name: Start Kafka
29+
uses: 280780363/[email protected]
30+
with:
31+
kafka version: "latest"
32+
zookeeper version: "latest"
33+
kafka port: 9092
34+
auto create topic: "true"
35+
36+
- name: Install Python dependencies
37+
run: pip3 install -r tests/requirements.txt
38+
39+
- name: Build module
40+
run: |
41+
export MAKEFLAGS=-j8
42+
export CC=clang
43+
export CXX=clang++
44+
git clone https://github.com/tarantool/tarantool
45+
cd tarantool
46+
git checkout 2.10
47+
export LSAN_OPTIONS=suppressions=${PWD}/asan/lsan.supp
48+
cmake . -DENABLE_ASAN=ON -DENABLE_DIST=ON
49+
make -j16
50+
sudo make install
51+
cd ..
52+
tarantoolctl rocks STATIC_BUILD=ON ENABLE_ASAN=ON make
53+
54+
- name: Run tarantool application
55+
run: |
56+
export TT_LOG=tarantool.log
57+
export LSAN_OPTIONS=suppressions=${PWD}/tarantool/asan/lsan.supp
58+
tarantool tests/app.lua > output.log 2>&1 &
59+
60+
- name: Run test
61+
run: KAFKA_HOST=localhost:9092 pytest tests
62+
63+
- name: Print Tarantool logs
64+
if: always()
65+
run: |
66+
cat tarantool.log
67+
cat output.log

.github/workflows/fast_testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: fast_testing
1+
name: asan_testing
22

33
on:
44
push:

CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,24 @@ else()
2222
endif()
2323
message("Found OPENSSL version: ${OPENSSL_VERSION}")
2424

25+
option(ENABLE_ASAN OFF)
26+
if (ENABLE_ASAN)
27+
set(LIBRDKAFKA_C_FLAGS "-fsanitize=address")
28+
set(LIBRDKAFKA_CXX_FLAGS "-fsanitize=address")
29+
set(LIBRDKAFKA_FLAGS "--enable-devel")
30+
endif()
31+
2532
if(STATIC_BUILD)
2633
add_custom_command(
2734
OUTPUT ${CMAKE_BINARY_DIR}/librdkafka/lib/librdkafka.a
28-
COMMAND ./configure --enable-ssl --disable-zstd --prefix=${CMAKE_BINARY_DIR}/librdkafka
35+
COMMAND ./configure --enable-ssl
36+
--disable-zstd
37+
--prefix=${CMAKE_BINARY_DIR}/librdkafka
38+
${LIBRDKAFKA_FLAGS}
39+
--cc=${CMAKE_C_COMPILER}
40+
--cxx=${CMAKE_CXX_COMPILER}
41+
--CFLAGS=${LIBRDKAFKA_C_FLAGS}
42+
--CXXFLAGS=${LIBRDKAFKA_CXX_FLAGS}
2943
COMMAND $(MAKE) -j
3044
COMMAND $(MAKE) install
3145
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/librdkafka

kafka/consumer_msg.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,8 @@ lua_consumer_msg_tostring(struct lua_State *L) {
101101
if (msg->key_len <= 0 || msg->key == NULL) {
102102
memcpy(key, null_literal, sizeof(null_literal));
103103
} else {
104-
strncpy(key, msg->key, msg->key_len + 1);
105-
if (key[msg->key_len] != '\0') {
106-
key[msg->key_len] = '\0';
107-
}
104+
strncpy(key, msg->key, msg->key_len);
105+
key[msg->key_len] = '\0';
108106
}
109107

110108
size_t value_len = msg->value_len <= 0 ? sizeof(null_literal) : msg->value_len + 1;
@@ -113,10 +111,8 @@ lua_consumer_msg_tostring(struct lua_State *L) {
113111
if (msg->value_len <= 0 || msg->value == NULL) {
114112
memcpy(value, null_literal, sizeof(null_literal));
115113
} else {
116-
strncpy(value, msg->value, msg->value_len + 1);
117-
if (value[msg->value_len] != '\0') {
118-
value[msg->value_len] = '\0';
119-
}
114+
strncpy(value, msg->value, msg->value_len);
115+
value[msg->value_len] = '\0';
120116
}
121117

122118
lua_pushfstring(L,

tests/test_consumer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def create_consumer(server, *args):
4848

4949

5050
def write_into_kafka(topic, messages):
51-
loop = asyncio.get_event_loop()
51+
loop = asyncio.get_event_loop_policy().new_event_loop()
5252

5353
async def send():
5454
producer = AIOKafkaProducer(bootstrap_servers='localhost:9092')
@@ -74,6 +74,7 @@ async def send():
7474
await producer.stop()
7575

7676
loop.run_until_complete(send())
77+
loop.close()
7778

7879

7980
def test_consumer_should_consume_msgs():

tests/test_producer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_producer_should_produce_msgs():
3333
]
3434
server.call("producer.produce", [messages])
3535

36-
loop = asyncio.get_event_loop()
36+
loop = asyncio.get_event_loop_policy().new_event_loop()
3737

3838
async def test():
3939
kafka_output = []
@@ -73,6 +73,7 @@ async def consume():
7373
assert kafka_output == messages
7474

7575
loop.run_until_complete(test())
76+
loop.close()
7677

7778
server.call("producer.close", [])
7879

0 commit comments

Comments
 (0)