Add static analysis step
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
NADAL Jean-Baptiste
2020-01-22 10:19:58 +01:00
parent f1a4c5448b
commit 3c9f0c2f56
5 changed files with 47 additions and 11 deletions

View File

@@ -35,6 +35,12 @@ steps:
- cd domo-iot/build - cd domo-iot/build
- make gcovr - make gcovr
- name: static_analysis
image: registry.nadal-fr.com/buildroot_dev
commands:
- cd domo-iot/build
- make static_analysis
- name: send telegram notification - name: send telegram notification
image: appleboy/drone-telegram image: appleboy/drone-telegram
settings: settings:

View File

@@ -76,6 +76,7 @@ target_link_libraries (test_device
event event
event_pthreads event_pthreads
gcov gcov
curl
) )
endif(DOMO_BUILD_TEST) endif(DOMO_BUILD_TEST)

View File

@@ -28,7 +28,7 @@
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int my_test_handler(short event, restd_conn_t *conn, void *userdata) int my_error_handler(short event, restd_conn_t *conn, void *userdata)
{ {
restd_http_response(conn, 200, "application/json", "{\"status\":\"error\"}", 18); restd_http_response(conn, 200, "application/json", "{\"status\":\"error\"}", 18);
return RESTD_CLOSE; // Close connection. return RESTD_CLOSE; // Close connection.
@@ -36,6 +36,14 @@ int my_test_handler(short event, restd_conn_t *conn, void *userdata)
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int my_success_handler(short event, restd_conn_t *conn, void *userdata)
{
restd_http_response(conn, 200, "application/json", "{\"status\":\"ok\"}", 15);
return RESTD_CLOSE; // Close connection.
}
/*--------------------------------------------------------------------------*/
bool found_route(restd_server_t *server, const char *method, const char *path) bool found_route(restd_server_t *server, const char *method, const char *path)
{ {
qlist_t *hooks = server->hooks; qlist_t *hooks = server->hooks;
@@ -133,7 +141,7 @@ TEST("Rest - create free\t")
restd_server_set_option(rest_server, "server.port", "7777"); restd_server_set_option(rest_server, "server.port", "7777");
restd_server_register_hook_on_path(rest_server, "POST", "/api/v1/test", my_test_handler, NULL); restd_server_register_hook_on_path(rest_server, "POST", "/api/v1/test", my_error_handler, NULL);
restd_server_free(rest_server); restd_server_free(rest_server);
} }
@@ -149,20 +157,20 @@ TEST("Rest - create access regular route free\t")
restd_server_set_option(rest_server, "server.port", "7777"); restd_server_set_option(rest_server, "server.port", "7777");
restd_server_register_hook_on_path(rest_server, "POST", "/api/v1/test", my_test_handler, NULL); restd_server_register_hook_on_path(rest_server, "POST", "/api/v1/test", my_success_handler, NULL);
ASSERT_TRUE(found_route(rest_server, "POST", "/api/v1/test")); ASSERT_TRUE(found_route(rest_server, "POST", "/api/v1/test"));
ASSERT_FALSE(found_route(rest_server, "POST", "/api/v1/notfound")); ASSERT_FALSE(found_route(rest_server, "POST", "/api/v1/notfound"));
restd_server_register_hook_on_path(rest_server, "GET", "/api/v1/test", my_test_handler, NULL); restd_server_register_hook_on_path(rest_server, "GET", "/api/v1/test", my_success_handler, NULL);
ASSERT_TRUE(found_route(rest_server, "GET", "/api/v1/test")); ASSERT_TRUE(found_route(rest_server, "GET", "/api/v1/test"));
restd_server_register_hook_on_path(rest_server, "GET", "/api/v1/test", my_test_handler, NULL); restd_server_register_hook_on_path(rest_server, "GET", "/api/v1/test", my_success_handler, NULL);
ASSERT_TRUE(found_route(rest_server, "GET", "/api/v1/test")); ASSERT_TRUE(found_route(rest_server, "GET", "/api/v1/test"));
restd_server_register_hook_on_path(rest_server, "PUT", "/api/v1/test", my_test_handler, NULL); restd_server_register_hook_on_path(rest_server, "PUT", "/api/v1/test", my_success_handler, NULL);
ASSERT_TRUE(found_route(rest_server, "PUT", "/api/v1/test")); ASSERT_TRUE(found_route(rest_server, "PUT", "/api/v1/test"));
restd_server_register_hook_on_path(rest_server, "DELETE", "/api/v1/test", my_test_handler, NULL); restd_server_register_hook_on_path(rest_server, "DELETE", "/api/v1/test", my_success_handler, NULL);
ASSERT_TRUE(found_route(rest_server, "DELETE", "/api/v1/test")); ASSERT_TRUE(found_route(rest_server, "DELETE", "/api/v1/test"));
restd_server_free(rest_server); restd_server_free(rest_server);
@@ -177,9 +185,9 @@ TEST("Rest - create access route with param free\t")
rest_server = restd_server_new(); rest_server = restd_server_new();
ASSERT_NOT_NULL(rest_server); ASSERT_NOT_NULL(rest_server);
restd_server_register_hook_on_path(rest_server, "GET", "/api/v1/klong/:id", my_test_handler, NULL); restd_server_register_hook_on_path(rest_server, "GET", "/api/v1/klong/:id", my_success_handler, NULL);
restd_server_register_hook_on_path(rest_server, "GET", "/api/v1/donkey", my_test_handler, NULL); restd_server_register_hook_on_path(rest_server, "GET", "/api/v1/donkey", my_success_handler, NULL);
restd_server_register_hook_on_path(rest_server, "GET", "/api/v1/test/:id", my_test_handler, NULL); restd_server_register_hook_on_path(rest_server, "GET", "/api/v1/test/:id", my_success_handler, NULL);
ASSERT_FALSE(found_special_route(rest_server, "GET", "/api/v1/notfound/77", &id)); ASSERT_FALSE(found_special_route(rest_server, "GET", "/api/v1/notfound/77", &id));
@@ -202,7 +210,7 @@ TEST("Rest - create start free\t")
restd_server_set_option(rest_server, "server.port", "7777"); restd_server_set_option(rest_server, "server.port", "7777");
restd_server_set_option(rest_server, "server.thread", "1"); restd_server_set_option(rest_server, "server.thread", "1");
restd_server_register_hook_on_path(rest_server, "GET", "/api/v1/test/:id", my_test_handler, NULL); restd_server_register_hook_on_path(rest_server, "GET", "/api/v1/test/:id", my_success_handler, NULL);
ret = restd_server_start(rest_server); ret = restd_server_start(rest_server);
ASSERT_EQUAL_INT(ret, 0); ASSERT_EQUAL_INT(ret, 0);

4
tools/nats-pub.sh Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
go get github.com/nats-io/go-nats-examples/tools/nats-pub
${HOME}/go/bin/nats-pub -s nats://nats.nadal-fr.com:4222 "$1" "$2"

17
tools/static_analysis.sh Executable file
View File

@@ -0,0 +1,17 @@
#!/usr/bin/env bash
BUILD_DIR=$1
analyse_file () {
DIRNAME=`dirname $1`
echo "Analyse directory: $DIRNAME"
cd $DIRNAME
pvs-studio-analyzer analyze -o analyse.log --compiler gcc --compiler g++
plog-converter -a GA:1,2 -t tasklist -o report.tasks analyse.log
echo -e "\n**********************************\n"
cat report.tasks
echo -e "\n**********************************\n"
}
# Main
find ${BUILD_DIR} -name compile_commands.json | while read file; do analyse_file $file; done