Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit c3c3942

Browse files
committed
feat(test): Add sanitizer for router
Building tangle-accelerator with sanitizer, and run regression test with the just built tangle-accelerator. With this procedure, we can test router with sanitizers. Now once tangle-accelerator has been initialized, tangle-accelerator will send SIGUSR1 to the parent bash script. The bash script will wait for the signal, then run the Python script.
1 parent c1b2138 commit c3c3942

File tree

7 files changed

+128
-6
lines changed

7 files changed

+128
-6
lines changed

accelerator/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ int main(int argc, char* argv[]) {
134134
br_logger_init();
135135
}
136136

137+
// Once tangle-accelerator finished initializing, return 'SIGUSR1' to parent process
138+
pid_t pid = getppid();
139+
kill(pid, SIGUSR1);
140+
137141
/* pause() cause TA to sleep until it catch a signal,
138142
* also the return value and errno should be -1 and EINTR on success.
139143
*/

endpoint/platform/simulator/impl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static status_t sec_init(void) {
8686

8787
static status_t sec_write(const char *name, const uint8_t *buf, size_t buf_size) {
8888
uint8_t *data = malloc(buf_size);
89-
if(data == NULL){
89+
if (data == NULL) {
9090
LE_ERROR("Cannot fetch enough memory");
9191
return SC_OOM;
9292
}

endpoint/unit-test/driver.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,22 @@ function run_test_suite(){
3434

3535
function start_ta(){
3636
# Create tangle-accelerator for unit-test
37+
trap 'TA_INIT=1' USR1
3738
bazel run accelerator &
3839
TA=$!
40+
TA_INIT=0
41+
3942
# Wait for tangle-acclerator build finish
40-
sleep 20
43+
while [ "$TA_INIT" -ne 1 ]; do
44+
if ps -p $TA > /dev/null; then
45+
echo "waiting for tangle-accelerator initialization"
46+
sleep 1
47+
continue
48+
else
49+
# pid does not exist
50+
break
51+
fi
52+
done
4153
}
4254

4355
echo "Start unit-test for endpoint"

tests/regression/common.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ setup_build_opts() {
1818
fail=()
1919
}
2020

21+
# Set sanitizer options
22+
setup_sanitizer_opts() {
23+
SAN_OPTIONS=(
24+
"--config=asan"
25+
"--config=tsan"
26+
"--config=ubsan"
27+
)
28+
success=()
29+
fail=()
30+
}
31+
2132
# Check environment variables
2233
check_env() {
2334
ENV_NAME=(

tests/regression/router-sanitizer.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
3+
source tests/regression/common.sh
4+
5+
check_env
6+
setup_sanitizer_opts
7+
8+
# Get command line arguments
9+
# Current arguments parsed are <sleep_time> <remaining_args>
10+
get_cli_args $@
11+
12+
# Install prerequisites
13+
make
14+
pip3 install --user -r tests/regression/requirements.txt
15+
16+
# FIXME: Check Redis status
17+
redis-server &
18+
19+
# Iterate over all available build options
20+
for (( i = 0; i < ${#SAN_OPTIONS[@]}; i++ )); do
21+
option=${SAN_OPTIONS[${i}]}
22+
23+
trap 'TA_INIT=1' USR1
24+
bazel run accelerator ${option} -c dbg -- --ta_port=${TA_PORT} &
25+
TA=$!
26+
27+
TA_INIT=0
28+
while [ "$TA_INIT" -ne 1 ]; do
29+
if ps -p $TA > /dev/null; then
30+
echo "waiting for tangle-accelerator initialization"
31+
sleep 1
32+
continue
33+
else
34+
# pid does not exist
35+
break
36+
fi
37+
done
38+
39+
trap "kill -9 ${TA};" INT # Trap SIGINT from Ctrl-C to stop TA
40+
41+
python3 tests/regression/runner.py ${remaining_args} --url localhost:${TA_PORT}
42+
rc=$?
43+
44+
if [ $rc -ne 0 ]
45+
then
46+
echo "Build sanitizer '${option}' failed"
47+
fail+=("${option}")
48+
else
49+
success+=("${option}")
50+
fi
51+
52+
bazel clean
53+
wait $(kill -9 ${TA})
54+
done
55+
56+
echo "--------- Successful build options ---------"
57+
for (( i = 0; i < ${#success[@]}; i++ )); do echo ${success[${i}]}; done
58+
echo "----------- Failed build options -----------"
59+
for (( i = 0; i < ${#fail[@]}; i++ )); do echo ${fail[${i}]}; done
60+
61+
if [ ${#fail[@]} -gt 0 ]; then
62+
exit 1
63+
fi

tests/regression/run-api-with-mqtt.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ get_cli_args $@
1111

1212
# Install prerequisites
1313
make MQTT
14-
pip install --user -r tests/regression/requirements.txt
14+
pip3 install --user -r tests/regression/requirements.txt
15+
16+
# FIXME: Check Redis status
1517
redis-server &
1618

1719
# Iterate over all available build options
@@ -20,9 +22,16 @@ for (( i = 0; i < ${#OPTIONS[@]}; i++ )); do
2022
cli_arg=${option} | cut -d '|' -f 1
2123
build_arg=${option} | cut -d '|' -f 2
2224

25+
trap 'TA_INIT=1' USR1
2326
bazel run accelerator --define mqtt=enable ${build_arg} -- --quiet --ta_port=${TA_PORT} ${cli_arg} &
2427
TA=$!
25-
sleep ${sleep_time} # TA takes time to be built
28+
29+
TA_INIT=0
30+
while [ "$TA_INIT" -ne 1 ]; do
31+
echo "waiting for tangle-accelerator initialization"
32+
sleep 1
33+
done
34+
2635
trap "kill -9 ${TA};" INT # Trap SIGINT from Ctrl-C to stop TA
2736

2837
python3 tests/regression/runner.py ${remaining_args} --url "localhost" --mqtt
@@ -44,3 +53,7 @@ echo "--------- Successful build options ---------"
4453
for (( i = 0; i < ${#success[@]}; i++ )); do echo ${success[${i}]}; done
4554
echo "----------- Failed build options -----------"
4655
for (( i = 0; i < ${#fail[@]}; i++ )); do echo ${fail[${i}]}; done
56+
57+
if [ ${#fail[@]} -gt 0 ]; then
58+
exit 1
59+
fi

tests/regression/run-api.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ get_cli_args $@
1111

1212
# Install prerequisites
1313
make
14-
pip install --user -r tests/regression/requirements.txt
14+
pip3 install --user -r tests/regression/requirements.txt
15+
16+
# FIXME: Check Redis status
1517
redis-server &
1618

1719
# Iterate over all available build options
@@ -20,9 +22,22 @@ for (( i = 0; i < ${#OPTIONS[@]}; i++ )); do
2022
cli_arg=$(echo ${option} | cut -d '|' -f 2)
2123
build_arg=$(echo ${option} | cut -d '|' -f 1)
2224

25+
trap 'TA_INIT=1' USR1
2326
bazel run accelerator ${build_arg} -- --ta_port=${TA_PORT} ${cli_arg} &
2427
TA=$!
25-
sleep ${sleep_time} # TA takes time to be built
28+
29+
TA_INIT=0
30+
while [ "$TA_INIT" -ne 1 ]; do
31+
if ps -p $TA > /dev/null; then
32+
echo "waiting for tangle-accelerator initialization"
33+
sleep 1
34+
continue
35+
else
36+
# pid does not exist
37+
break
38+
fi
39+
done
40+
2641
trap "kill -9 ${TA};" INT # Trap SIGINT from Ctrl-C to stop TA
2742

2843
python3 tests/regression/runner.py ${remaining_args} --url localhost:${TA_PORT}
@@ -44,3 +59,7 @@ echo "--------- Successful build options ---------"
4459
for (( i = 0; i < ${#success[@]}; i++ )); do echo ${success[${i}]}; done
4560
echo "----------- Failed build options -----------"
4661
for (( i = 0; i < ${#fail[@]}; i++ )); do echo ${fail[${i}]}; done
62+
63+
if [ ${#fail[@]} -gt 0 ]; then
64+
exit 1
65+
fi

0 commit comments

Comments
 (0)