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

Commit

Permalink
feat(test): Add sanitizer for router
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
howjmay committed Jul 9, 2020
1 parent c1b2138 commit c3c3942
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 6 deletions.
4 changes: 4 additions & 0 deletions accelerator/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ int main(int argc, char* argv[]) {
br_logger_init();
}

// Once tangle-accelerator finished initializing, return 'SIGUSR1' to parent process
pid_t pid = getppid();
kill(pid, SIGUSR1);

/* pause() cause TA to sleep until it catch a signal,
* also the return value and errno should be -1 and EINTR on success.
*/
Expand Down
2 changes: 1 addition & 1 deletion endpoint/platform/simulator/impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static status_t sec_init(void) {

static status_t sec_write(const char *name, const uint8_t *buf, size_t buf_size) {
uint8_t *data = malloc(buf_size);
if(data == NULL){
if (data == NULL) {
LE_ERROR("Cannot fetch enough memory");
return SC_OOM;
}
Expand Down
14 changes: 13 additions & 1 deletion endpoint/unit-test/driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,22 @@ function run_test_suite(){

function start_ta(){
# Create tangle-accelerator for unit-test
trap 'TA_INIT=1' USR1
bazel run accelerator &
TA=$!
TA_INIT=0

# Wait for tangle-acclerator build finish
sleep 20
while [ "$TA_INIT" -ne 1 ]; do
if ps -p $TA > /dev/null; then
echo "waiting for tangle-accelerator initialization"
sleep 1
continue
else
# pid does not exist
break
fi
done
}

echo "Start unit-test for endpoint"
Expand Down
11 changes: 11 additions & 0 deletions tests/regression/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ setup_build_opts() {
fail=()
}

# Set sanitizer options
setup_sanitizer_opts() {
SAN_OPTIONS=(
"--config=asan"
"--config=tsan"
"--config=ubsan"
)
success=()
fail=()
}

# Check environment variables
check_env() {
ENV_NAME=(
Expand Down
63 changes: 63 additions & 0 deletions tests/regression/router-sanitizer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

source tests/regression/common.sh

check_env
setup_sanitizer_opts

# Get command line arguments
# Current arguments parsed are <sleep_time> <remaining_args>
get_cli_args $@

# Install prerequisites
make
pip3 install --user -r tests/regression/requirements.txt

# FIXME: Check Redis status
redis-server &

# Iterate over all available build options
for (( i = 0; i < ${#SAN_OPTIONS[@]}; i++ )); do
option=${SAN_OPTIONS[${i}]}

trap 'TA_INIT=1' USR1
bazel run accelerator ${option} -c dbg -- --ta_port=${TA_PORT} &
TA=$!

TA_INIT=0
while [ "$TA_INIT" -ne 1 ]; do
if ps -p $TA > /dev/null; then
echo "waiting for tangle-accelerator initialization"
sleep 1
continue
else
# pid does not exist
break
fi
done

trap "kill -9 ${TA};" INT # Trap SIGINT from Ctrl-C to stop TA

python3 tests/regression/runner.py ${remaining_args} --url localhost:${TA_PORT}
rc=$?

if [ $rc -ne 0 ]
then
echo "Build sanitizer '${option}' failed"
fail+=("${option}")
else
success+=("${option}")
fi

bazel clean
wait $(kill -9 ${TA})
done

echo "--------- Successful build options ---------"
for (( i = 0; i < ${#success[@]}; i++ )); do echo ${success[${i}]}; done
echo "----------- Failed build options -----------"
for (( i = 0; i < ${#fail[@]}; i++ )); do echo ${fail[${i}]}; done

if [ ${#fail[@]} -gt 0 ]; then
exit 1
fi
17 changes: 15 additions & 2 deletions tests/regression/run-api-with-mqtt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ get_cli_args $@

# Install prerequisites
make MQTT
pip install --user -r tests/regression/requirements.txt
pip3 install --user -r tests/regression/requirements.txt

# FIXME: Check Redis status
redis-server &

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

trap 'TA_INIT=1' USR1
bazel run accelerator --define mqtt=enable ${build_arg} -- --quiet --ta_port=${TA_PORT} ${cli_arg} &
TA=$!
sleep ${sleep_time} # TA takes time to be built

TA_INIT=0
while [ "$TA_INIT" -ne 1 ]; do
echo "waiting for tangle-accelerator initialization"
sleep 1
done

trap "kill -9 ${TA};" INT # Trap SIGINT from Ctrl-C to stop TA

python3 tests/regression/runner.py ${remaining_args} --url "localhost" --mqtt
Expand All @@ -44,3 +53,7 @@ echo "--------- Successful build options ---------"
for (( i = 0; i < ${#success[@]}; i++ )); do echo ${success[${i}]}; done
echo "----------- Failed build options -----------"
for (( i = 0; i < ${#fail[@]}; i++ )); do echo ${fail[${i}]}; done

if [ ${#fail[@]} -gt 0 ]; then
exit 1
fi
23 changes: 21 additions & 2 deletions tests/regression/run-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ get_cli_args $@

# Install prerequisites
make
pip install --user -r tests/regression/requirements.txt
pip3 install --user -r tests/regression/requirements.txt

# FIXME: Check Redis status
redis-server &

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

trap 'TA_INIT=1' USR1
bazel run accelerator ${build_arg} -- --ta_port=${TA_PORT} ${cli_arg} &
TA=$!
sleep ${sleep_time} # TA takes time to be built

TA_INIT=0
while [ "$TA_INIT" -ne 1 ]; do
if ps -p $TA > /dev/null; then
echo "waiting for tangle-accelerator initialization"
sleep 1
continue
else
# pid does not exist
break
fi
done

trap "kill -9 ${TA};" INT # Trap SIGINT from Ctrl-C to stop TA

python3 tests/regression/runner.py ${remaining_args} --url localhost:${TA_PORT}
Expand All @@ -44,3 +59,7 @@ echo "--------- Successful build options ---------"
for (( i = 0; i < ${#success[@]}; i++ )); do echo ${success[${i}]}; done
echo "----------- Failed build options -----------"
for (( i = 0; i < ${#fail[@]}; i++ )); do echo ${fail[${i}]}; done

if [ ${#fail[@]} -gt 0 ]; then
exit 1
fi

0 comments on commit c3c3942

Please sign in to comment.