Skip to content

Commit

Permalink
Fixed an omission in the pcp::pmda::init_dso function - needed to be …
Browse files Browse the repository at this point in the history
…calling pdmaDSO; also updated the examples to build DSO shared objects in addition to the daemons they already build, and add some functional tests to prove it all.
  • Loading branch information
pcolby committed May 13, 2014
1 parent 767c804 commit 54fbd03
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 2.6)

set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})

add_subdirectory(simple)
add_subdirectory(simplecpu)
Expand Down
2 changes: 2 additions & 0 deletions example/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ include_directories ("${PROJECT_SOURCE_DIR}/../../include")

add_executable("pmda${PROJECT_NAME}" "${PROJECT_NAME}.cpp")
add_executable("pmda${PROJECT_NAME}-noboost" "${PROJECT_NAME}.cpp")
add_library("pmda_${PROJECT_NAME}" SHARED "${PROJECT_NAME}.cpp")

find_package(Boost COMPONENTS program_options REQUIRED)

target_link_libraries("pmda${PROJECT_NAME}" pcp pcp_pmda ${Boost_PROGRAM_OPTIONS_LIBRARY})
target_link_libraries("pmda${PROJECT_NAME}-noboost" pcp pcp_pmda)
target_link_libraries("pmda_${PROJECT_NAME}" pcp pcp_pmda ${Boost_PROGRAM_OPTIONS_LIBRARY})

set_property(
TARGET "pmda${PROJECT_NAME}-noboost"
Expand Down
2 changes: 1 addition & 1 deletion example/simple/simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class simple : public pcp::pmda {
};

// DSO entry point.
extern "C" void trivial_init(pmdaInterface *interface)
extern "C" void simple_init(pmdaInterface *interface)
{
pcp::pmda::init_dso<simple>(interface);
}
Expand Down
2 changes: 2 additions & 0 deletions example/simplecpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ include_directories ("${PROJECT_SOURCE_DIR}/../../include")

add_executable("pmda${PROJECT_NAME}" "${PROJECT_NAME}.cpp")
add_executable("pmda${PROJECT_NAME}-noboost" "${PROJECT_NAME}.cpp")
add_library("pmda_${PROJECT_NAME}" SHARED "${PROJECT_NAME}.cpp")

find_package(Boost COMPONENTS program_options REQUIRED)

target_link_libraries("pmda${PROJECT_NAME}" pcp pcp_pmda ${Boost_PROGRAM_OPTIONS_LIBRARY})
target_link_libraries("pmda${PROJECT_NAME}-noboost" pcp pcp_pmda)
target_link_libraries("pmda_${PROJECT_NAME}" pcp pcp_pmda ${Boost_PROGRAM_OPTIONS_LIBRARY})

set_property(
TARGET "pmda${PROJECT_NAME}-noboost"
Expand Down
2 changes: 2 additions & 0 deletions example/trivial/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ include_directories ("${PROJECT_SOURCE_DIR}/../../include")

add_executable("pmda${PROJECT_NAME}" "${PROJECT_NAME}.cpp")
add_executable("pmda${PROJECT_NAME}-noboost" "${PROJECT_NAME}.cpp")
add_library("pmda_${PROJECT_NAME}" SHARED "${PROJECT_NAME}.cpp")

find_package(Boost COMPONENTS program_options REQUIRED)

target_link_libraries("pmda${PROJECT_NAME}" pcp pcp_pmda ${Boost_PROGRAM_OPTIONS_LIBRARY})
target_link_libraries("pmda${PROJECT_NAME}-noboost" pcp pcp_pmda)
target_link_libraries("pmda_${PROJECT_NAME}" pcp pcp_pmda ${Boost_PROGRAM_OPTIONS_LIBRARY})

set_property(
TARGET "pmda${PROJECT_NAME}-noboost"
Expand Down
8 changes: 6 additions & 2 deletions include/pcp-cpp/pmda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ class pmda {
static void init_dso(pmdaInterface * const interface)
{
try {
set_instance(new Agent);
get_instance()->initialize_pmda(*interface);
Agent * agent = new Agent;
set_instance(agent); //< @todo verify this returns NULL.
pmdaDSO(interface, PCP_CPP_PMDA_INTERFACE_VERSION,
const_cast<char *>(agent->get_pmda_name().c_str()),
const_cast<char *>(agent->get_help_text_pathname().c_str()));
agent->initialize_pmda(*interface);
} catch (const std::exception &ex) {
__pmNotifyErr(LOG_ERR, "%s", ex.what());
}
Expand Down
2 changes: 2 additions & 0 deletions test/functional/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ while IFS= read -d '' -r COMMAND; do
echo "$DIFF_OUTPUT"
exit $RC
fi
else
echo -n '(no expectations) '
fi
echo "OK"
done < <(find "$TEST_DIR" -name 'test_*.command' -type f -print0)
8 changes: 8 additions & 0 deletions test/functional/test_simple_open_dso.command
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TEMP_DIR=`mktemp -d -t test_simple_open_dso-XXXXXXXXXX`
./pmdasimple --export-all "$TEMP_DIR"
if [ $? -ne 0 ]; then exit; fi
dbpmda -e -n "$TEMP_DIR/root" <<EOF
open dso libpmda_simple.so simple_init
close
EOF
rm -rf "$TEMP_DIR"
2 changes: 2 additions & 0 deletions test/functional/test_simple_open_dso.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
open dso libpmda_simple.so simple_init
close
10 changes: 10 additions & 0 deletions test/functional/test_simplecpu_open_dso.command
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
TEMP_DIR=`mktemp -d -t test_simplecpu_open_dso-XXXXXXXXXX`
./pmdasimplecpu --export-all "$TEMP_DIR"
if [ $? -ne 0 ]; then exit; fi
dbpmda -e -n "$TEMP_DIR/root" <<EOF
open dso libpmda_simplecpu.so simplecpu_init
text simplecpu.ticks.total
text simplecpu.ticks.cpu0
close
EOF
rm -rf "$TEMP_DIR"
10 changes: 10 additions & 0 deletions test/functional/test_simplecpu_open_dso.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
open dso libpmda_simplecpu.so simplecpu_init
text simplecpu.ticks.total
PMID: 129.0.0
[The amount of time spent in various states]
The amount of time spent in various states
text simplecpu.ticks.cpu0
PMID: 129.0.1
[The amount of time spent in various states]
The amount of time spent in various states
close
9 changes: 9 additions & 0 deletions test/functional/test_trivial_open_dso.command
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
TEMP_DIR=`mktemp -d -t test_trivial_open_dso-XXXXXXXXXX`
./pmdatrivial --export-all "$TEMP_DIR"
if [ $? -ne 0 ]; then exit; fi
dbpmda -e -n "$TEMP_DIR/root" <<EOF
open dso libpmda_trivial.so trivial_init
text trivial.time
close
EOF
rm -rf "$TEMP_DIR"
6 changes: 6 additions & 0 deletions test/functional/test_trivial_open_dso.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
open dso libpmda_trivial.so trivial_init
text trivial.time
PMID: 250.0.0
[The time in seconds since 1 Jan 1970]
The time in seconds since the 1st of January, 1970.
close

0 comments on commit 54fbd03

Please sign in to comment.