Fix Android build failures, enable random unit tests
authorErich Keane <erich.keane@intel.com>
Mon, 18 May 2015 17:51:06 +0000 (10:51 -0700)
committerErich Keane <erich.keane@intel.com>
Tue, 19 May 2015 00:24:17 +0000 (00:24 +0000)
It was discovered that the ocrandom uuid changes broke the android
build.  This is because Android, despite being an incomplete linux
implementation, defines __linux__.  This patch fixes that, and properly
enables the ocrandom unit tests.

Additionally, the OC_WIFI/OC_ETHERNET removals weren't propogated
properly to the android build, this patch does that in order to fix the
build.

Change-Id: Iabfeb704d046fbadf1fd368259d0e96ca1e74d90
Signed-off-by: Erich Keane <erich.keane@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1020
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Mandeep Shetty <mandeep.shetty@intel.com>
Reviewed-by: Vijay Kesavan <vijay.s.kesavan@intel.com>
android/android_api/base/jni/JniUtils.h
android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java
android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityType.java
android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java
resource/csdk/ocrandom/src/ocrandom.c
resource/csdk/ocrandom/test/SConscript [new file with mode: 0644]

index e64e16b..c4553ff 100644 (file)
@@ -128,9 +128,9 @@ public:
     {\r
         switch (type) {\r
         case 0:\r
-            return OCConnectivityType::OC_ETHERNET;\r
+            return OCConnectivityType::OC_IPV4;\r
         case 1:\r
-            return OCConnectivityType::OC_WIFI;\r
+            return OCConnectivityType::OC_IPV6;\r
         case 2:\r
             return OCConnectivityType::OC_EDR;\r
         case 3:\r
@@ -227,4 +227,4 @@ public:
             return "";\r
         }\r
     }\r
-};
\ No newline at end of file
+};\r
index 04e8cb0..490496a 100755 (executable)
@@ -96,7 +96,7 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener);
 
             //wait for onResourceFound event
@@ -138,7 +138,7 @@ public class SmokeTest extends InstrumentationTestCase {
                             //client
                             OcPresenceHandle presenceHandle = OcPlatform.subscribePresence(
                                     resource.getHost(),
-                                    OcConnectivityType.WIFI,
+                                    OcConnectivityType.IPV4,
                                     presenceListener
                             );
 
@@ -168,7 +168,7 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener);
 
             //server
@@ -314,7 +314,7 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource(null,
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener);
 
             //wait for onResourceFound event
@@ -477,7 +477,7 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener);
 
             //wait for onResourceFound event
@@ -643,7 +643,7 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener);
 
             //wait for onResourceFound event
@@ -747,7 +747,7 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener);
 
             //wait for onResourceFound event
@@ -925,7 +925,7 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener);
 
             //wait for onResourceFound event
@@ -993,7 +993,7 @@ public class SmokeTest extends InstrumentationTestCase {
             OcPlatform.getDeviceInfo(
                     "",
                     OcPlatform.WELL_KNOWN_QUERY + "/d",
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     deviceFoundListener);
 
             //wait for onDeviceFound event
@@ -1093,7 +1093,7 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener1);
 
             //wait for onResourceFound event to find 3 registered resources
@@ -1106,7 +1106,7 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener3);
 
             //wait for onResourceFound event to find 1 collection resources
@@ -1118,7 +1118,7 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener2);
 
             //wait for onResourceFound event to find 2 resources
@@ -1130,7 +1130,7 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener4);
 
             //wait for onResourceFound event to find 3 registered resources
@@ -1145,7 +1145,7 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener6);
 
             //wait for onResourceFound event to find 1 collection resources
@@ -1156,7 +1156,7 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener5);
 
             //wait for onResourceFound event to find 1 collection resources
@@ -1240,12 +1240,12 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType1,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener);
 
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType2,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener);
 
             //wait for onResourceFound event
@@ -1289,7 +1289,7 @@ public class SmokeTest extends InstrumentationTestCase {
                             OcResource resourceProxy = OcPlatform.constructResourceObject(
                                     resource.getHost(),
                                     resource.getUri(),
-                                    OcConnectivityType.WIFI,
+                                    OcConnectivityType.IPV4,
                                     resource.isObservable(),
                                     resource.getResourceTypes(),
                                     resource.getResourceInterfaces());
@@ -1319,7 +1319,7 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener);
 
             //wait for onResourceFound event
@@ -1346,7 +1346,7 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener);
 
             //wait for onResourceFound event
@@ -1518,7 +1518,7 @@ public class SmokeTest extends InstrumentationTestCase {
             //client
             OcPlatform.findResource("",
                     OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType,
-                    OcConnectivityType.WIFI,
+                    OcConnectivityType.IPV4,
                     resourceFoundListener);
 
             //wait for onResourceFound event
@@ -1560,4 +1560,4 @@ public class SmokeTest extends InstrumentationTestCase {
     private OcRepresentation getRepresentation() {
         return getRepresentation(74);
     }
-}
\ No newline at end of file
+}
index e405790..db38881 100755 (executable)
@@ -25,8 +25,8 @@ package org.iotivity.base;
 import java.security.InvalidParameterException;\r
 \r
 public enum OcConnectivityType {\r
-    ETHERNET(0),\r
-    WIFI    (1),\r
+    IPV4    (0),\r
+    IPV6    (1),\r
     EDR     (2),\r
     LE      (3),\r
     ALL     (4),\r
index fe71268..f55269b 100755 (executable)
@@ -216,8 +216,8 @@ public final class OcPlatform {
      *                                If empty, performs multicast resource discovery query\r
      * @param resourceUri             name of the resource. If null or empty, performs search for all\r
      *                                resource names\r
-     * @param connectivityType        a type of connectivity indicating the interface. Example: WIFI,\r
-     *                                ETHERNET, ALL\r
+     * @param connectivityType        a type of connectivity indicating the interface. Example: IPV4,\r
+     *                                IPV6, ALL\r
      * @param onResourceFoundListener Handles events, success states and failure states.\r
      * @throws OcException\r
      */\r
@@ -248,8 +248,8 @@ public final class OcPlatform {
      *                                If empty, performs multicast resource discovery query\r
      * @param resourceUri             name of the resource. If null or empty, performs search for all\r
      *                                resource names\r
-     * @param connectivityType        a type of connectivity indicating the interface. Example: WIFI,\r
-     *                                ETHERNET, ALL\r
+     * @param connectivityType        a type of connectivity indicating the interface. Example: IPV4,\r
+     *                                IPV6, ALL\r
      * @param onResourceFoundListener Handles events, success states and failure states.\r
      * @param qualityOfService        the quality of communication\r
      * @throws OcException\r
@@ -281,8 +281,8 @@ public final class OcPlatform {
      *\r
      * @param host                  Host IP Address. If null or empty, Multicast is performed.\r
      * @param deviceUri             Uri containing address to the virtual device\r
-     * @param connectivityType      a type of connectivity indicating the interface. Example: WIFI,\r
-     *                              ETHERNET, ALL\r
+     * @param connectivityType      a type of connectivity indicating the interface. Example: IPV4,\r
+     *                              IPV6, ALL\r
      * @param onDeviceFoundListener Handles events, success states and failure states.\r
      * @throws OcException\r
      */\r
@@ -311,8 +311,8 @@ public final class OcPlatform {
      *\r
      * @param host                  Host IP Address. If null or empty, Multicast is performed.\r
      * @param deviceUri             Uri containing address to the virtual device\r
-     * @param connectivityType      a type of connectivity indicating the interface. Example: WIFI,\r
-     *                              ETHERNET, ALL\r
+     * @param connectivityType      a type of connectivity indicating the interface. Example: IPV4,\r
+     *                              IPV6, ALL\r
      * @param onDeviceFoundListener Handles events, success states and failure states.\r
      * @param qualityOfService      the quality of communication\r
      * @throws OcException\r
@@ -600,8 +600,8 @@ public final class OcPlatform {
      * server adds/removes/alters a resource, starts or is intentionally stopped\r
      *\r
      * @param host               The IP address/addressable name of the server to subscribe to\r
-     * @param connectivityType   a type of connectivity indicating the interface. Example: WIFI,\r
-     *                           ETHERNET, ALL\r
+     * @param connectivityType   a type of connectivity indicating the interface. Example: IPV4,\r
+     *                           IPV6, ALL\r
      * @param onPresenceListener listener that will receive notifications/subscription events\r
      * @return a handle object that can be used to identify this subscription request. It can be\r
      * used to unsubscribe from these events in the future\r
@@ -630,8 +630,8 @@ public final class OcPlatform {
      *\r
      * @param host               The IP address/addressable name of the server to subscribe to\r
      * @param resourceType       a resource type specified as a filter for subscription events.\r
-     * @param connectivityType   a type of connectivity indicating the interface. Example: WIFI,\r
-     *                           ETHERNET, ALL\r
+     * @param connectivityType   a type of connectivity indicating the interface. Example: IPV4,\r
+     *                           IPV6, ALL\r
      * @param onPresenceListener listener that will receive notifications/subscription events\r
      * @return a handle object that can be used to identify this subscription request. It can be\r
      * used to unsubscribe from these events in the future\r
@@ -687,8 +687,8 @@ public final class OcPlatform {
      * @param uri              the rest of the resource's URI that will permit messages to be\r
      *                         properly routed.\r
      *                         Example: /a/light\r
-     * @param connectivityType a type of connectivity indicating the interface. Example: WIFI,\r
-     *                         ETHERNET, ALL\r
+     * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,\r
+     *                         IPV6, ALL\r
      * @param isObservable     a boolean containing whether the resource supports observation\r
      * @param resourceTypeList a collection of resource types implemented by the resource\r
      * @param interfaceList    a collection of interfaces that the resource supports/implements\r
@@ -774,4 +774,4 @@ public final class OcPlatform {
                     "OcPlatform.Configure before any other API calls are permitted");\r
         }\r
     }\r
-}
\ No newline at end of file
+}\r
index 6271fad..dd03cd9 100644 (file)
@@ -26,7 +26,7 @@
 #include "ocrandom.h"
 #include <stdio.h>
 
-#if defined(__linux__) || defined(__APPLE__)
+#if !defined(__ANDROID__) && (defined(__linux__) || defined(__APPLE__))
 #include <uuid/uuid.h>
 #endif
 
@@ -162,11 +162,7 @@ OCRandomUuidResult OCGenerateUuid(uint8_t uuid[UUID_SIZE])
     {
         return RAND_UUID_INVALID_PARAM;
     }
-#if defined(__linux__) || defined(__APPLE__)
-    // note: uuid_t is typedefed as unsigned char[16] on linux/apple
-    uuid_generate(uuid);
-    return RAND_UUID_OK;
-#elif defined(__ANDROID__)
+#if defined(__ANDROID__)
     char uuidString[UUID_STRING_SIZE];
     int8_t ret = OCGenerateUuidString(uuidString);
 
@@ -197,6 +193,10 @@ OCRandomUuidResult OCGenerateUuid(uint8_t uuid[UUID_SIZE])
     uuid[15] = parseUuidPart(&uuidString[34]);
 
     return RAND_UUID_OK;
+#elif !defined(__ANDROID__) && (defined(__linux__) || defined(__APPLE__))
+    // note: uuid_t is typedefed as unsigned char[16] on linux/apple
+    uuid_generate(uuid);
+    return RAND_UUID_OK;
 #else
     // Fallback for all platforms is filling the array with random data
     OCFillRandomMem(uuid, UUID_SIZE);
@@ -210,19 +210,7 @@ OCRandomUuidResult OCGenerateUuidString(char uuidString[UUID_STRING_SIZE])
     {
         return RAND_UUID_INVALID_PARAM;
     }
-#if defined(__linux__) || defined(__APPLE__)
-    uint8_t uuid[UUID_SIZE];
-    int8_t ret = OCGenerateUuid(uuid);
-
-    if(ret != 0)
-    {
-        return ret;
-    }
-
-    uuid_unparse_lower(uuid, uuidString);
-    return RAND_UUID_OK;
-
-#elif defined(__ANDROID__)
+#if defined(__ANDROID__)
     int32_t fd = open("/proc/sys/kernel/random/uuid", O_RDONLY);
     if(fd > 0)
     {
@@ -250,6 +238,18 @@ OCRandomUuidResult OCGenerateUuidString(char uuidString[UUID_STRING_SIZE])
         close(fd);
         return RAND_UUID_READ_ERROR;
     }
+#elif !defined(__ANDROID__) && (defined(__linux__) || defined(__APPLE__))
+    uint8_t uuid[UUID_SIZE];
+    int8_t ret = OCGenerateUuid(uuid);
+
+    if(ret != 0)
+    {
+        return ret;
+    }
+
+    uuid_unparse_lower(uuid, uuidString);
+    return RAND_UUID_OK;
+
 #else
     uint8_t uuid[UUID_SIZE];
     OCGenerateUuid(uuid);
diff --git a/resource/csdk/ocrandom/test/SConscript b/resource/csdk/ocrandom/test/SConscript
new file mode 100644 (file)
index 0000000..ab221cd
--- /dev/null
@@ -0,0 +1,72 @@
+#******************************************************************
+#
+# Copyright 2014 Intel Mobile Communications GmbH 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.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+Import('env')
+import os
+import os.path
+randomtest_env = env.Clone()
+
+src_dir = randomtest_env.get('SRC_DIR')
+
+######################################################################
+# Build flags
+######################################################################
+randomtest_env.PrependUnique(CPPPATH = [
+        '../include',
+               '../../logger/include',
+               '../../ocmalloc/include',
+               '../../../oc_logger/include',
+               '../../../../extlibs/gtest/gtest-1.7.0/include'
+               ])
+
+randomtest_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+randomtest_env.AppendUnique(LIBS = ['-lpthread'])
+randomtest_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+randomtest_env.AppendUnique(LIBPATH = [src_dir + '/extlibs/gtest/gtest-1.7.0/lib/.libs'])
+randomtest_env.PrependUnique(LIBS = ['m',
+                                    'octbstack',
+                                    'uuid',
+                                    'gtest',
+                                    'gtest_main'])
+
+
+if env.get('LOGGING'):
+       randomtest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+randomtests = randomtest_env.Program('randomtests', ['linux/randomtest.cpp'])
+
+Alias("test", [randomtests])
+
+env.AppendTarget('test')
+if env.get('TEST') == '1':
+       target_os = env.get('TARGET_OS')
+       if target_os == 'linux':
+               out_dir = env.get('BUILD_DIR')
+               result_dir = env.get('BUILD_DIR') + '/test_out/'
+               if not os.path.isdir(result_dir):
+                       os.makedirs(result_dir)
+               randomtest_env.AppendENVPath('GTEST_OUTPUT', ['xml:'+ result_dir])
+               randomtest_env.AppendENVPath('LD_LIBRARY_PATH', [out_dir])
+               randomtest_env.AppendENVPath('LD_LIBRARY_PATH', ['./extlibs/gtest/gtest-1.7.0/lib/.libs'])
+               ut = randomtest_env.Command ('ut', None, 'valgrind -q --leak-check=full --xml=yes --xml-file=resource_csdk_random_test.memcheck ' + out_dir + 'resource/csdk/ocrandom/test/randomtests')
+               AlwaysBuild ('ut')