Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code-coverage script #134

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ option(CODE_COVERAGE "Enable code coverage" OFF)
if(CODE_COVERAGE)
# GCC/Clang
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage -lgcov -DEXIT_USING_FILE")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage -fprofile-arcs -ftest-coverage -lgcov ")
endif()
endif()

Expand Down Expand Up @@ -100,6 +100,9 @@ if((${DISTRO_ID} MATCHES "amzn") OR (${DISTRO_ID} MATCHES "ubuntu"))
"[Unit]\n"
"Description=credentials-fetcher systemd service unit file.\n\n"
"[Service]\n"
"StandardError=journal\n"
"StandardOutput=journal\n"
"StandardInput=null\n"
"ExecStartPre=mkdir -p ${CF_KRB_DIR} ${CF_UNIX_DOMAIN_SOCKET_DIR} ${CF_LOGGING_DIR}\n"
"ExecStartPre=chgrp ec2-user /var/credentials-fetcher ${CF_KRB_DIR} ${CF_UNIX_DOMAIN_SOCKET_DIR} ${CF_LOGGING_DIR}\n"
"ExecStartPre=chmod 755 /var/credentials-fetcher ${CF_KRB_DIR} ${CF_UNIX_DOMAIN_SOCKET_DIR} ${CF_LOGGING_DIR}\n"
Expand All @@ -119,6 +122,9 @@ else()
"[Unit]\n"
"Description=credentials-fetcher systemd service unit file.\n\n"
"[Service]\n"
"StandardError=journal\n"
"StandardOutput=journal\n"
"StandardInput=null\n"
"ExecStartPre=mkdir -p ${CF_KRB_DIR} ${CF_UNIX_DOMAIN_SOCKET_DIR} ${CF_LOGGING_DIR}\n"
"ExecStart=/usr/sbin/credentials-fetcherd\n"
"Environment=\"CREDENTIALS_FETCHERD_STARTED_BY_SYSTEMD=1\"\n"
Expand Down
24 changes: 24 additions & 0 deletions code_coverage_using_gcov.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
#
mkdir -p build && cd build
if [ $? -ne 0 ]; then
echo "ERROR: Failed at creating build dir"
exit 1
fi
cmake3 .. -DCODE_COVERAGE=ON && make
if [ $? -ne 0 ]; then
echo "ERROR: Failed at build"
exit 1
fi

echo "Start running the credentials-fetcher daemon"
echo "After running gRPC clients, you must exit the credentials-fetcher daemon using 'touch /tmp/credentials_fetcher_exit.txt'"
echo "Note: If you use ctrl-c or sigkill, the gcda files will not get created"

echo "Run the following in the build directory:"

echo "\tpip install gcovr"
echo "\tgcovr --html-details coverage.html -r .."
echo "\ttar cvfz coverage.tar.gz *.html"
echo "To view code coverage, extract coverage.tar.gz and start browsing at coverage.html"
exit 0
15 changes: 14 additions & 1 deletion daemon/src/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ static const char* grpc_thread_name = "grpc_thread";

static void systemd_shutdown_signal_catcher( int signo )
{
printf("Credentials-fetcher shutdown: Caught signo %d\n", signo);
cf_daemon.got_systemd_shutdown_signal = 1;
}

Expand Down Expand Up @@ -232,7 +233,9 @@ int main( int argc, const char* argv[] )
cf_daemon.got_systemd_shutdown_signal = 0;
memset( &sa, 0, sizeof( struct sigaction ) );
sa.sa_handler = &systemd_shutdown_signal_catcher;
if ( sigaction( SIGTERM, &sa, NULL ) == -1 )
if ( ( sigaction( SIGTERM, &sa, NULL ) == -1 ) ||
( sigaction( SIGINT, &sa, NULL ) == -1 ) ||
( sigaction( SIGHUP, &sa, NULL ) == -1 ) )
{
perror( "sigaction" );
return EXIT_FAILURE;
Expand Down Expand Up @@ -322,6 +325,16 @@ int main( int argc, const char* argv[] )
sd_notifyf( 0, "STATUS=Watchdog notify count = %d",
i ); // TBD: Remove later, visible in systemctl status
++i;
#ifdef EXIT_USING_FILE
struct stat st;
if ( lstat( "/tmp/credentials_fetcher_exit.txt", &st ) != -1 )
{
if (S_ISREG(st.st_mode))
{
cf_daemon.got_systemd_shutdown_signal = 1;
}
}
#endif
}

return EXIT_SUCCESS;
Expand Down
Loading