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

Commit b5287d7

Browse files
authored
Merge pull request #711 from HowJMay/flash_close
fix(test): Notify initialization by domain socket
2 parents 8a1171b + ab9d132 commit b5287d7

File tree

8 files changed

+96
-63
lines changed

8 files changed

+96
-63
lines changed

accelerator/config.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include "config.h"
1010
#include <errno.h>
1111
#include <limits.h>
12+
#include <sys/socket.h>
13+
#include <sys/types.h>
14+
#include <sys/un.h>
1215
#include "utils/macros.h"
1316
#include "yaml.h"
1417

@@ -517,3 +520,34 @@ void ta_core_destroy(ta_core_t* const core) {
517520
logger_destroy_json_serializer();
518521
br_logger_release();
519522
}
523+
524+
#define DOMAIN_SOCKET "/tmp/tangle-accelerator-socket"
525+
#define START_NOTIFICATION "TA-START"
526+
void notification_trigger() {
527+
int connect_fd;
528+
static struct sockaddr_un srv_addr;
529+
530+
// Create UNIX domain socket
531+
connect_fd = socket(PF_UNIX, SOCK_STREAM, 0);
532+
if (connect_fd < 0) {
533+
ta_log_error("Can't create communication socket.\n");
534+
goto done;
535+
}
536+
537+
srv_addr.sun_family = AF_UNIX;
538+
strncpy(srv_addr.sun_path, DOMAIN_SOCKET, strlen(DOMAIN_SOCKET));
539+
540+
// Connect to UNIX domain socket server
541+
if (connect(connect_fd, (struct sockaddr*)&srv_addr, sizeof(srv_addr)) == -1) {
542+
ta_log_error("Can't connect to UNIX domain socket server.\n");
543+
goto done;
544+
}
545+
546+
// Send notification to UNIX domain socket
547+
if (write(connect_fd, START_NOTIFICATION, strlen(START_NOTIFICATION)) == -1) {
548+
ta_log_error("Can't write message to UNIX domain socket server.\n");
549+
}
550+
551+
done:
552+
close(connect_fd);
553+
}

accelerator/config.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ typedef struct ta_core_s {
130130
} ta_core_t;
131131

132132
/**
133-
* Initializes configurations with default values
133+
* @brief Initializes configurations with default values
134134
*
135135
* @param[in] core Pointer to Tangle-accelerator core configuration structure
136136
*
@@ -152,7 +152,7 @@ static inline struct option* cli_build_options() {
152152
};
153153

154154
/**
155-
* Set configurations with command line inputs
155+
* @brief Set configurations with command line inputs
156156
*
157157
* @param[in] core Pointer to Tangle-accelerator core configuration structure
158158
* @param[in] key CLI command key
@@ -165,7 +165,7 @@ static inline struct option* cli_build_options() {
165165
status_t cli_core_set(ta_core_t* const core, int key, char* const value);
166166

167167
/**
168-
* Initializes configurations with configuration file
168+
* @brief Initializes configurations with configuration file
169169
*
170170
* @param[in] core Pointer to Tangle-accelerator core configuration structure
171171
* @param[in] argc Number of argument of CLI
@@ -178,7 +178,7 @@ status_t cli_core_set(ta_core_t* const core, int key, char* const value);
178178
status_t ta_core_file_init(ta_core_t* const core, int argc, char** argv);
179179

180180
/**
181-
* Initializes configurations with CLI values
181+
* @brief Initializes configurations with CLI values
182182
*
183183
* @param[in] core Pointer to Tangle-accelerator core configuration structure
184184
* @param[in] argc Number of argument of CLI
@@ -191,7 +191,7 @@ status_t ta_core_file_init(ta_core_t* const core, int argc, char** argv);
191191
status_t ta_core_cli_init(ta_core_t* const core, int argc, char** argv);
192192

193193
/**
194-
* Start services after configurations are set
194+
* @brief Start services after configurations are set
195195
*
196196
* @param[in] core Pointer to Tangle-accelerator core configuration structure
197197
*
@@ -210,7 +210,7 @@ status_t ta_core_set(ta_core_t* const core);
210210
void ta_core_destroy(ta_core_t* const core);
211211

212212
/**
213-
* Initializes iota_client_service
213+
* @brief Initializes iota_client_service
214214
*
215215
* @param[in] service IOTA client service
216216
* @param[in] host host of connecting service
@@ -224,6 +224,11 @@ void ta_core_destroy(ta_core_t* const core);
224224
status_t ta_set_iota_client_service(iota_client_service_t* service, char const* host, uint16_t port,
225225
char const* const ca_pem);
226226

227+
/**
228+
* @brief Notify other process with unix domain socket
229+
*/
230+
void notification_trigger();
231+
227232
#ifdef __cplusplus
228233
}
229234
#endif

accelerator/main.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ 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);
137+
// Once tangle-accelerator finished initializing, notify regression test script with unix domain socket
138+
notification_trigger();
140139

141140
/* pause() cause TA to sleep until it catch a signal,
142141
* also the return value and errno should be -1 and EINTR on success.

endpoint/unit-test/driver.sh

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,18 @@ function run_test_suite(){
3434

3535
function start_ta(){
3636
# Create tangle-accelerator for unit-test
37-
trap 'TA_INIT=1' USR1
3837
bazel run accelerator &
3938
TA=$!
40-
TA_INIT=0
41-
42-
# Wait for tangle-acclerator build finish
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
39+
# Wait until tangle-accelerator has been initialized
40+
echo "==============Wait for TA starting=============="
41+
while read -r line
42+
do
43+
if [[ "$line" == "TA-START" ]]
44+
then
45+
echo "$line"
46+
fi
47+
done <<< $(nc -U -l $socket | tr '\0' '\n')
48+
echo "==============TA has successfully started=============="
5349
}
5450

5551
echo "Start unit-test for endpoint"

tests/regression/common.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ check_env() {
5959

6060
# Parse command line arguments
6161
get_cli_args () {
62-
sleep_time=$1
62+
socket=$1
6363
shift
6464
remaining_args=$@ # Get the remaining arguments
6565
}
66+
67+
start_notification="TA-START"

tests/regression/router-sanitizer.sh

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ check_env
66
setup_sanitizer_opts
77

88
# Get command line arguments
9-
# Current arguments parsed are <sleep_time> <remaining_args>
9+
# Current arguments parsed are <socket name> <remaining_args>
1010
get_cli_args $@
1111

1212
# Install prerequisites
@@ -20,24 +20,21 @@ redis-server &
2020
for (( i = 0; i < ${#SAN_OPTIONS[@]}; i++ )); do
2121
option=${SAN_OPTIONS[${i}]}
2222

23-
trap 'TA_INIT=1' USR1
2423
bazel run accelerator ${option} -c dbg -- --ta_port=${TA_PORT} &
2524
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-
3925
trap "kill -9 ${TA};" INT # Trap SIGINT from Ctrl-C to stop TA
4026

27+
# Wait until tangle-accelerator has been initialized
28+
echo "==============Wait for TA starting=============="
29+
while read -r line
30+
do
31+
if [[ "$line" == "$start_notification" ]]
32+
then
33+
echo "$line"
34+
fi
35+
done <<< $(nc -U -l $socket | tr '\0' '\n')
36+
echo "==============TA has successfully started=============="
37+
4138
python3 tests/regression/runner.py ${remaining_args} --url localhost:${TA_PORT}
4239
rc=$?
4340

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ check_env
66
setup_build_opts
77

88
# Get command line arguments
9-
# Current arguments parsed are <sleep_time> <remaining_args>
9+
# Current arguments parsed are <socket name> <remaining_args>
1010
get_cli_args $@
1111

1212
# Install prerequisites
@@ -22,18 +22,21 @@ for (( i = 0; i < ${#OPTIONS[@]}; i++ )); do
2222
cli_arg=${option} | cut -d '|' -f 1
2323
build_arg=${option} | cut -d '|' -f 2
2424

25-
trap 'TA_INIT=1' USR1
2625
bazel run accelerator --define mqtt=enable ${build_arg} -- --quiet --ta_port=${TA_PORT} ${cli_arg} &
2726
TA=$!
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-
3527
trap "kill -9 ${TA};" INT # Trap SIGINT from Ctrl-C to stop TA
3628

29+
# Wait until tangle-accelerator has been initialized
30+
echo "==============Wait for TA starting=============="
31+
while read -r line
32+
do
33+
if [[ "$line" == "$start_notification" ]]
34+
then
35+
echo "$line"
36+
fi
37+
done <<< $(nc -U -l $socket | tr '\0' '\n')
38+
echo "==============TA has successfully started=============="
39+
3740
python3 tests/regression/runner.py ${remaining_args} --url "localhost" --mqtt
3841
rc=$?
3942

tests/regression/run-api.sh

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ check_env
66
setup_build_opts
77

88
# Get command line arguments
9-
# Current arguments parsed are <sleep_time> <remaining_args>
9+
# Current arguments parsed are <socket name> <remaining_args>
1010
get_cli_args $@
1111

1212
# Install prerequisites
@@ -22,24 +22,21 @@ for (( i = 0; i < ${#OPTIONS[@]}; i++ )); do
2222
cli_arg=$(echo ${option} | cut -d '|' -f 2)
2323
build_arg=$(echo ${option} | cut -d '|' -f 1)
2424

25-
trap 'TA_INIT=1' USR1
2625
bazel run accelerator ${build_arg} -- --ta_port=${TA_PORT} ${cli_arg} &
2726
TA=$!
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-
4127
trap "kill -9 ${TA};" INT # Trap SIGINT from Ctrl-C to stop TA
4228

29+
# Wait until tangle-accelerator has been initialized
30+
echo "==============Wait for TA starting=============="
31+
while read -r line
32+
do
33+
if [[ "$line" == "$start_notification" ]]
34+
then
35+
echo "$line"
36+
fi
37+
done <<< $(nc -U -l $socket | tr '\0' '\n')
38+
echo "==============TA has successfully started=============="
39+
4340
python3 tests/regression/runner.py ${remaining_args} --url localhost:${TA_PORT}
4441
rc=$?
4542

0 commit comments

Comments
 (0)