Skip to content

Commit

Permalink
Merge pull request Intermodalics#64 from Intermodalics/feature/add_un…
Browse files Browse the repository at this point in the history
…it_test

Feature/add unit test
  • Loading branch information
Perrine Aguiar authored Nov 22, 2016
2 parents 9d2d955 + ae682a7 commit f088376
Show file tree
Hide file tree
Showing 38 changed files with 1,023 additions and 33 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@
######################
*OpenCV_sdk_native/
*roscpp_android_ndk/
*miniglog/
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "miniglog"]
path = miniglog
url = https://github.com/tzutalin/miniglog
[submodule "third_party/glog_catkin"]
path = third_party/glog_catkin
url = https://github.com/ethz-asl/glog_catkin
[submodule "third_party/catkin_simple"]
path = third_party/catkin_simple
url = https://github.com/catkin/catkin_simple
5 changes: 2 additions & 3 deletions TangoxRos/README.md → RosApp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
### Miniglog

* From the TangoApps repository:
```$ git clone https://github.com/tzutalin/miniglog.git```
```$ cd miniglog```
```$ ./build.sh```

### Building the app with android studio

* Download Android Studio (version 2.2 seems to not work properly with this project, you can download previous versions [here](http://tools.android.com/system/app/pages/subPages?path=/download/studio/builds)).

* When starting Android Studio import the project by selecting the TangoxRos directory.
* When starting Android Studio import the project by selecting the RosApp directory.

* In your local.properties file check that the paths to your android sdk and ndk are set properly.
Example:
Expand All @@ -45,4 +44,4 @@ sdk.dir=/opt/android-sdk-linux

* Enter the ros master URI when the application is asking and press connect.

* Open rviz with the config file located at TangoxRos/tango_ros.rviz to visualize the different tango data (device pose, point cloud, image).
* Open rviz with the config file located at RosApp/tango_ros.rviz to visualize the different tango data (device pose, point cloud, image).
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public class JNIInterface {
* initRos should always be called before.
* @param callerActivity the caller activity of this function.
*/
public static native void initNode(Activity callerActivity, PublisherConfiguration publisherConfiguration);
public static native boolean initNode(Activity callerActivity, PublisherConfiguration publisherConfiguration);

/**
* Called when the Tango service is connected successfully.
*
* @param nativeTangoServiceBinder The native binder object.
*/
public static native void onTangoServiceConnected(IBinder nativeTangoServiceBinder);
public static native boolean onTangoServiceConnected(IBinder nativeTangoServiceBinder);

/**
* Disconnects from Tango.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import android.text.format.Formatter;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.Toast;

public class MainActivity extends Activity implements SetMasterUriDialog.CallbackListener {
private static final String TAG = MainActivity.class.getSimpleName();
Expand All @@ -22,7 +24,7 @@ public class MainActivity extends Activity implements SetMasterUriDialog.Callbac

private JNIInterface mJniInterface;
private String mMasterUri;
private boolean mIsInitialised = false;
private boolean mIsNodeInitialised = false;
private PublisherConfiguration mPublishConfig;

/**
Expand Down Expand Up @@ -58,24 +60,18 @@ private void showSetMasterUriDialog() {
setMasterUriDialog.show(manager, "MatserUriDialog");
}

/**
* Implements callback for Apply button.
*/
public void applySettings(View view) {
onPause();
mJniInterface.initNode(this, mPublishConfig);
mIsInitialised = true;
onResume();
}

/**
* Tango Service connection.
*/
ServiceConnection mTangoServiceConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName name, IBinder service) {
// Synchronization around MainActivity object is to avoid
// Tango disconnect in the middle of the connecting operation.
mJniInterface.onTangoServiceConnected(service);
if(!mJniInterface.onTangoServiceConnected(service)) {
Log.e(TAG, getResources().getString(R.string.tango_service_error));
Toast.makeText(getApplicationContext(), R.string.tango_service_error, Toast.LENGTH_SHORT).show();
onDestroy();
}
}

public void onServiceDisconnected(ComponentName name) {
Expand All @@ -84,21 +80,38 @@ public void onServiceDisconnected(ComponentName name) {
}
};

public boolean initNode() {
if(!mJniInterface.initNode(this, mPublishConfig)) {
Log.e(TAG, getResources().getString(R.string.tango_node_error));
Toast.makeText(getApplicationContext(), R.string.tango_node_error, Toast.LENGTH_SHORT).show();
return false;
}
return true;
}

public void init() {
if (mMasterUri != null) {
WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
String ip_address = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
if (mJniInterface.initRos(MASTER_URI_PREFIX + mMasterUri, IP_PREFIX + ip_address)) {
mJniInterface.initNode(this, mPublishConfig);
mIsInitialised = true;
mIsNodeInitialised = initNode();
} else {
Log.e(TAG, "Unable to init ROS!");
Log.e(TAG, getResources().getString(R.string.tango_ros_error));
Toast.makeText(getApplicationContext(), R.string.tango_ros_error, Toast.LENGTH_SHORT).show();
}
} else {
Log.e(TAG, "Master URI is null");
}
}

public void applySettings() {
onPause();
mIsNodeInitialised = initNode();
if (mIsNodeInitialised) {
onResume();
}
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -113,7 +126,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.i(TAG, "Publish device pose is switched on");
} else {
mPublishConfig.publishDevicePose = false;
Log.i(TAG, "Publish device pose i switched off");
Log.i(TAG, "Publish device pose is switched off");
}
}
});
Expand Down Expand Up @@ -157,14 +170,22 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
}
});
// Set callback for apply button.
Button buttonApply = (Button)findViewById(R.id.apply);
buttonApply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
applySettings();
}
});
// Request master URI from user.
showSetMasterUriDialog();
}

@Override
protected void onResume() {
super.onResume();
if (mIsInitialised) {
if (mIsNodeInitialised) {
TangoInitializationHelper.bindTangoService(this, mTangoServiceConnection);
new Thread(new Runnable() {
@Override
Expand All @@ -180,7 +201,7 @@ public void run() {
@Override
protected void onPause() {
super.onPause();
if (mIsInitialised) {
if (mIsNodeInitialised) {
mJniInterface.tangoDisconnect();
unbindService(mTangoServiceConnection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@ PROJECT_ROOT_FROM_JNI:= ../../../..
PROJECT_ROOT:= $(call my-dir)/../../../..

include $(CLEAR_VARS)

LOCAL_MODULE := tango_ros_android
LOCAL_SRC_FILES := jni_interface.cc
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_CFLAGS += -g3 -ggdb --std=c++11 -pthread -fPIC -fexceptions -frtti
LOCAL_LDLIBS += -landroid -lm -llog
LOCAL_STATIC_LIBRARIES += roscpp_android_ndk
LOCAL_SHARED_LIBRARIES := tango_client_api tango_support_api tango_ros_native
include $(BUILD_SHARED_LIBRARY)

$(call import-add-path, $(PROJECT_ROOT)/../tango_ros_catkin/src)
include $(CLEAR_VARS)
LOCAL_MODULE := test_tango_ros_native
LOCAL_SRC_FILES := test/test_tango_ros_api.cc
LOCAL_CFLAGS += -g3 -ggdb --std=c++11 -pthread -fPIC -fexceptions -frtti
LOCAL_STATIC_LIBRARIES += roscpp_android_ndk googletest_main
LOCAL_SHARED_LIBRARIES := tango_client_api tango_support_api tango_ros_native
include $(BUILD_EXECUTABLE)

$(call import-add-path, $(PROJECT_ROOT)/../tango_ros_common)
$(call import-module,tango_ros_native)
$(call import-module,third_party/googletest)


File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ Java_eu_intermodalics_tangoxros_JNIInterface_isRosOk(JNIEnv* env, jobject /*obj*
return tango_ros_util::IsRosOK();
}

JNIEXPORT void JNICALL
JNIEXPORT jboolean JNICALL
Java_eu_intermodalics_tangoxros_JNIInterface_initNode(JNIEnv* env, jobject /*obj*/, jobject activity,
jobject jpublisherConfiguration) {
tango_ros_node::PublisherConfiguration publisher_configuration;
set_native_publisher_configuration_from_java_publisher_configuration(env, jpublisherConfiguration,
&publisher_configuration);
tango_ros.reset(new tango_ros_node::TangoRosNode(publisher_configuration));
tango_ros->CheckTangoVersion(env, activity);
return tango_ros->IsTangoVersionOk(env, activity);
}

JNIEXPORT void JNICALL
JNIEXPORT jboolean JNICALL
Java_eu_intermodalics_tangoxros_JNIInterface_onTangoServiceConnected(
JNIEnv* env, jobject /*obj*/, jobject iBinder) {
tango_ros->OnTangoServiceConnected(env, iBinder);
return tango_ros->SetBinder(env, iBinder) && tango_ros->OnTangoServiceConnected();
}

JNIEXPORT void JNICALL
Expand Down
28 changes: 28 additions & 0 deletions RosApp/app/src/main/jni/test/run_test_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#! /bin/bash -x
adb root
adb remount

LIB_DIR="$HOME/tango_apps_ws/src/TangoApps/RosApp/app/src/main/libs/armeabi-v7a"
DEST_DIR="/data/local/tmp"
MASTER_URI="im-desktop-005:11311"
DEVICE_IP="192.168.168.185"
DESKTOP_TEST_DIR="$HOME/tango_apps_ws/devel/lib/tango_ros_native"

# Push libs and test executable to the device.
adb push $LIB_DIR/libtango_ros_android.so $DEST_DIR/
adb push $LIB_DIR/libtango_ros_native.so $DEST_DIR/
adb push $LIB_DIR/libtango_support_api.so $DEST_DIR/
adb push $LIB_DIR/test_tango_ros_native $DEST_DIR/
adb shell chmod 775 $DEST_DIR/test_tango_ros_native

# Start the test on device.
adb shell LD_LIBRARY_PATH=$DEST_DIR $DEST_DIR/test_tango_ros_native __master:=http://$MASTER_URI __ip:=$DEVICE_IP & DEVICE_TEST=&!

# Sleep some time to be sure that the test on device is running.
sleep 5
# Start the test on desktop.
$DESKTOP_TEST_DIR/tango_ros_native_test_tango_ros & DESKTOP_TEST=$!

# Wait till both tests are finished.
wait $DEVICE_TEST
wait $DESKTOP_TEST
63 changes: 63 additions & 0 deletions RosApp/app/src/main/jni/test/test_tango_ros_api.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2016 Intermodalics All Rights Reserved.
//
// 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 <time.h>

#include <gtest/gtest.h>
#include <tango_ros_native/tango_ros_node.h>
#include <tango_ros_native/tango_ros_util.h>

std::string master_uri;
std::string device_ip;

class TangoRosTest : public ::testing::Test {
public:
const int TEST_DURATION = 5; // in second.
std::shared_ptr<tango_ros_node::TangoRosNode> tango_ros_node_;
tango_ros_node::PublisherConfiguration publisher_config_;
bool connected_to_tango = false;

protected:
virtual void SetUp() {
ASSERT_TRUE(tango_ros_util::InitRos(master_uri.c_str(), device_ip.c_str()));
publisher_config_.publish_device_pose = true;
publisher_config_.publish_point_cloud = true;
publisher_config_.publish_camera = tango_ros_node::CAMERA_FISHEYE | tango_ros_node::CAMERA_COLOR;
tango_ros_node_.reset(new tango_ros_node::TangoRosNode(publisher_config_));
ASSERT_TRUE(tango_ros_node_->OnTangoServiceConnected());
connected_to_tango = true;
}

virtual void TearDown() {
if(connected_to_tango) {
tango_ros_node_->TangoDisconnect();
}
}
};

TEST_F(TangoRosTest, TestPublishingForFixedTime) {
time_t current_time = time(NULL);
time_t end = current_time + TEST_DURATION;
while(tango_ros_util::IsRosOK() && current_time < end) {
tango_ros_node_->Publish();
current_time = time(NULL);
}
}

// Run all the tests that were declared with TEST()
int main(int argc, char **argv){
testing::InitGoogleTest(&argc, argv);
master_uri = argv[1];
device_ip = argv[2];
return RUN_ALL_TESTS();
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/checkbox_pointcloud"
android:text="@string/apply"
android:onClick="applySettings" />
android:text="@string/apply" />
</LinearLayout>
</FrameLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@
<string name="publish_fisheye_camera">Publish fisheye camera</string>
<string name="publish_color_camera">Publish color camera</string>
<string name="apply">Apply</string>

<string name="tango_ros_error">Unable to init ROS! Do you have a roscore running?</string>
<string name="tango_node_error">Unable to init Tango Ros node. Do you have a correct tango version?</string>
<string name="tango_service_error">Unable to connect to Tango Service</string>

</resources>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions tango_ros_common/tango_ros_native/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
LOCAL_PATH := $(call my-dir)
PROJECT_ROOT:= $(call my-dir)/..

include $(CLEAR_VARS)

OPENCV_INSTALL_MODULES:=on
OPENCV_CAMERA_MODULES:=off
OPENCV_LIB_TYPE:=STATIC
include $(PROJECT_ROOT)/../OpenCV_sdk_native/jni/OpenCV.mk

LOCAL_MODULE := tango_ros_native
LOCAL_SRC_FILES := $(LOCAL_PATH)/src/tango_ros_node.cpp $(LOCAL_PATH)/src/tango_ros_util.cpp
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_CFLAGS += -g3 -ggdb --std=c++11 -pthread -fPIC -fexceptions -frtti
LOCAL_LDLIBS += -landroid -lm -llog
LOCAL_STATIC_LIBRARIES += roscpp_android_ndk miniglog
LOCAL_SHARED_LIBRARIES := tango_client_api tango_support_api
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(BUILD_SHARED_LIBRARY)

include $(PROJECT_ROOT)/../miniglog/Android.mk
$(call import-add-path, $(PROJECT_ROOT)/..)
$(call import-module,roscpp_android_ndk)
$(call import-add-path, $(PROJECT_ROOT)/../tango_api)
$(call import-module,tango_client_api)
$(call import-module,tango_support_api)
Loading

0 comments on commit f088376

Please sign in to comment.