Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Add unit test #58

Merged
merged 3 commits into from
Feb 6, 2018
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
Binary file added data/images/bicycle.bmp
Binary file not shown.
Binary file added data/images/bicycle.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/bicycle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions movidius_ncs_image/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ find_package(catkin REQUIRED COMPONENTS
image_transport
cv_bridge
roslint
rostest
)

catkin_package(
Expand Down Expand Up @@ -104,4 +105,15 @@ if(CATKIN_ENABLE_TESTING)
find_package(roslint REQUIRED)
roslint_cpp()
roslint_add_test()

# rostest classification
add_executable(unittest_image_classification tests/unittest_image_classification.cpp)
target_link_libraries(unittest_image_classification ${catkin_LIBRARIES} ${GTEST_LIBRARIES} ${UNITEST_LIBRARIES})
add_dependencies(unittest_image_classification ${catkin_EXPORTED_TARGETS})
# rostest detection
add_executable(unittest_image_detection tests/unittest_image_detection.cpp)
target_link_libraries(unittest_image_detection ${catkin_LIBRARIES} ${GTEST_LIBRARIES} ${UNITEST_LIBRARIES})
add_dependencies(unittest_image_detection ${catkin_EXPORTED_TARGETS})

add_rostest(tests/test_unit.test)
endif()
1 change: 1 addition & 0 deletions movidius_ncs_image/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ limitations under the License.
<build_depend>object_msgs</build_depend>
<build_depend>movidius_ncs_lib</build_depend>
<build_depend>roslint</build_depend>
<build_depend>rostest</build_depend>

<run_depend>roscpp</run_depend>
<run_depend>sensor_msgs</run_depend>
Expand Down
37 changes: 37 additions & 0 deletions movidius_ncs_image/tests/test_unit.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!--
Copyright (c) 2017 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<launch>
<arg name="cnn_type" default="alexnet" />
<group>
<include file="$(find movidius_ncs_launch)/launch/includes/ncs_image.launch">
<arg name="cnn_type" value="$(arg cnn_type)" />
</include>
</group>

<group if="$(eval cnn_type == 'alexnet' or cnn_type == 'googlenet'
or cnn_type == 'inception_v1' or cnn_type == 'inception_v2'
or cnn_type == 'inception_v3' or cnn_type == 'inception_v4'
or cnn_type == 'mobilenet' or cnn_type == 'squeezenet')">
<test pkg="movidius_ncs_image" type="unittest_image_classification" test-name="image_test" time-limit="10">
</test>
</group>

<group if="$(eval cnn_type == 'mobilenetssd' or cnn_type == 'tinyyolo_v1')">
<test pkg="movidius_ncs_image" type="unittest_image_detection" test-name="image_test" time-limit="10">
</test>
</group>
</launch>
51 changes: 51 additions & 0 deletions movidius_ncs_image/tests/unittest_image_classification.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2017 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <string>

#include <gtest/gtest.h>
#include <opencv2/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
#include <ros/package.h>
#include <ros/ros.h>
#include <object_msgs/ClassifyObject.h>

TEST(UnitTestClassification, testImage)
{
ros::NodeHandle n;
ros::ServiceClient client;
client = n.serviceClient<object_msgs::ClassifyObject>("/movidius_ncs_image/classify_object");
object_msgs::ClassifyObject srv;

cv_bridge::CvImage cv_image;
sensor_msgs::Image ros_image;
cv_image.image = cv::imread(ros::package::getPath("movidius_ncs_lib") + "/../data/images/bicycle.jpg");
cv_image.encoding = "bgr8";
cv_image.toImageMsg(ros_image);
srv.request.image = ros_image;

client.waitForExistence(ros::Duration(60));
EXPECT_TRUE(client.call(srv));
EXPECT_TRUE(srv.response.objects.objects_vector.size());
EXPECT_TRUE(srv.response.objects.objects_vector[0].object_name.find("cycle") != std::string::npos);
}

int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init(argc, argv, "movidius_ncs_image_tests");
return RUN_ALL_TESTS();
}
64 changes: 64 additions & 0 deletions movidius_ncs_image/tests/unittest_image_detection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2017 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <string>
#include <vector>

#include <gtest/gtest.h>
#include <opencv2/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
#include <ros/package.h>
#include <ros/ros.h>
#include <object_msgs/DetectObject.h>

TEST(UnitTestDetection, testImage)
{
ros::NodeHandle n;
ros::ServiceClient client = n.serviceClient<object_msgs::DetectObject>("/movidius_ncs_image/detect_object");
object_msgs::DetectObject srv;

cv_bridge::CvImage cv_image;
sensor_msgs::Image ros_image;
std::vector<std::string> image_format = {".jpg", ".jpeg", ".png", ".bmp"};
for (std::string suffix : image_format)
{
cv_image.image = cv::imread(ros::package::getPath("movidius_ncs_lib") + "/../data/images/bicycle"+suffix);
cv_image.encoding = "bgr8";
cv_image.toImageMsg(ros_image);

srv.request.image = ros_image;

client.waitForExistence(ros::Duration(60));
EXPECT_TRUE(client.call(srv));
EXPECT_TRUE(srv.response.objects.objects_vector.size());
EXPECT_EQ(srv.response.objects.objects_vector[0].object.object_name, "bicycle");
EXPECT_TRUE(srv.response.objects.objects_vector[0].roi.x_offset > 130 &&
srv.response.objects.objects_vector[0].roi.x_offset < 150 &&
srv.response.objects.objects_vector[0].roi.y_offset > 90 &&
srv.response.objects.objects_vector[0].roi.y_offset < 110 &&
srv.response.objects.objects_vector[0].roi.width > 410 &&
srv.response.objects.objects_vector[0].roi.width < 470 &&
srv.response.objects.objects_vector[0].roi.height > 340 &&
srv.response.objects.objects_vector[0].roi.height < 360);
}
}

int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
ros::init(argc, argv, "movidius_ncs_image_tests");
return RUN_ALL_TESTS();
}
13 changes: 13 additions & 0 deletions movidius_ncs_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ project(movidius_ncs_lib)
find_package(catkin REQUIRED COMPONENTS
roscpp
roslint
rostest
)

catkin_package(
Expand Down Expand Up @@ -122,6 +123,18 @@ install(DIRECTORY include/${PROJECT_NAME}/

if(CATKIN_ENABLE_TESTING)
find_package(roslint REQUIRED)
find_package(OpenCV REQUIRED)
find_package(catkin REQUIRED COMPONENTS roslib)
roslint_cpp()
roslint_add_test()

# rostest NCS SDK environment
add_executable(unittest_environment tests/unittest_environment.cpp)
target_link_libraries(unittest_environment ${catkin_LIBRARIES} ${GTEST_LIBRARIES} ${UNITEST_LIBRARIES})
# rostest library function
add_executable(unittest_function tests/unittest_function.cpp)
target_link_libraries(unittest_function ${PROJECT_NAME} ${OpenCV_LIBS} ${catkin_LIBRARIES} ${GTEST_LIBRARIES} ${UNITEST_LIBRARIES})
add_dependencies(unittest_function ${catkin_EXPORTED_TARGETS})

add_rostest(tests/test_all.test)
endif()
1 change: 1 addition & 0 deletions movidius_ncs_lib/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ limitations under the License.

<build_depend>roscpp</build_depend>
<build_depend>roslint</build_depend>
<build_depend>rostest</build_depend>

<run_depend>roscpp</run_depend>
<run_depend>roslint</run_depend>
Expand Down
22 changes: 22 additions & 0 deletions movidius_ncs_lib/tests/test_all.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
Copyright (c) 2017 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<launch>
<test pkg="movidius_ncs_lib" type="unittest_environment" test-name="environment_test" time-limit="10">
</test>
<test pkg="movidius_ncs_lib" type="unittest_function" test-name="function_test" time-limit="100">
</test>
</launch>
67 changes: 67 additions & 0 deletions movidius_ncs_lib/tests/unittest_environment.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2017 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <fstream>
#include <string>
#include <vector>

#include <boost/filesystem/operations.hpp>
#include <gtest/gtest.h>

TEST(UnitTestEnvironment, testSDK)
{
std::system("python2 /opt/movidius/NCSDK/tests/api-check/ncs-python2-check.py > /tmp/NCS_unittest.txt");
EXPECT_TRUE(boost::filesystem::exists("/tmp/NCS_unittest.txt"));
std::ifstream fin("/tmp/NCS_unittest.txt");
std::string ncs_check, tmp;
while (std::getline(fin, tmp))
{
ncs_check = tmp;
}
EXPECT_EQ(ncs_check, "NCS device working.");
std::system("rm -rf /tmp/NCS_unittest.txt > /dev/null 2>&1");
}

TEST(UnitTestEnvironment, testAppZoo)
{
EXPECT_TRUE(boost::filesystem::exists("/opt/movidius/ncappzoo"));
std::system("cd /opt/movidius/ncappzoo && make > /dev/null 2>&1");
std::vector<std::string> caffe_dirs = { "AlexNet", "GoogLeNet", "SqueezeNet", "SSD_MobileNet", "TinyYolo" };
std::vector<std::string> tf_dirs = { "inception_v1", "inception_v2", "inception_v3", "inception_v4", "mobilenets" };
for (std::string caffe : caffe_dirs)
{
EXPECT_TRUE(boost::filesystem::exists("/opt/movidius/ncappzoo/caffe/" + caffe + "/graph"));
}

for (std::string tf : tf_dirs)
{
EXPECT_TRUE(boost::filesystem::exists("/opt/movidius/ncappzoo/tensorflow/" + tf + "/graph"));
}
}

TEST(UnitTestEnvironment, testCategories)
{
EXPECT_TRUE(boost::filesystem::exists("/opt/movidius/ncappzoo/data/ilsvrc12/imagenet1000.txt"));
EXPECT_TRUE(boost::filesystem::exists("/opt/movidius/ncappzoo/data/ilsvrc12/imagenet1001.txt"));
EXPECT_TRUE(boost::filesystem::exists("/opt/movidius/ncappzoo/data/ilsvrc12/voc20.txt"));
EXPECT_TRUE(boost::filesystem::exists("/opt/movidius/ncappzoo/data/ilsvrc12/voc21.txt"));
}

int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Loading