oic; start of selftests.

Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/9b4049e5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/9b4049e5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/9b4049e5

Branch: refs/heads/develop
Commit: 9b4049e5db8f62d65b3aee67ce85ea1533938b91
Parents: a787e03
Author: Marko Kiiskila <[email protected]>
Authored: Wed Jan 11 12:42:22 2017 -0800
Committer: Marko Kiiskila <[email protected]>
Committed: Wed Jan 11 12:42:22 2017 -0800

----------------------------------------------------------------------
 net/oic/test/pkg.yml                      |  32 ++++
 net/oic/test/src/test_oic.c               |  46 ++++++
 net/oic/test/src/test_oic.h               |  41 +++++
 net/oic/test/src/testcases/oic_discover.c | 215 +++++++++++++++++++++++++
 net/oic/test/syscfg.yml                   |  24 +++
 5 files changed, 358 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b4049e5/net/oic/test/pkg.yml
----------------------------------------------------------------------
diff --git a/net/oic/test/pkg.yml b/net/oic/test/pkg.yml
new file mode 100644
index 0000000..538b114
--- /dev/null
+++ b/net/oic/test/pkg.yml
@@ -0,0 +1,32 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+#
+pkg.name: net/oic/test
+pkg.type: unittest
+pkg.description: "OIC unit tests"
+pkg.author: "Apache Mynewt <[email protected]>"
+pkg.homepage: "http://mynewt.apache.org/";
+pkg.keywords:
+
+pkg.deps:
+    - net/oic
+    - encoding/tinycbor
+    - encoding/cborattr
+    - test/testutil
+
+pkg.deps.SELFTEST:
+    - sys/console/stub

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b4049e5/net/oic/test/src/test_oic.c
----------------------------------------------------------------------
diff --git a/net/oic/test/src/test_oic.c b/net/oic/test/src/test_oic.c
new file mode 100644
index 0000000..6f58b92
--- /dev/null
+++ b/net/oic/test/src/test_oic.c
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 "syscfg/syscfg.h"
+#include "testutil/testutil.h"
+#include "test_oic.h"
+
+TEST_SUITE(oic_test_all)
+{
+    oic_test_discover();
+}
+
+void
+oic_test_init(void)
+{
+}
+
+#if MYNEWT_VAL(SELFTEST)
+int
+main(int argc, char **argv)
+{
+    ts_config.ts_print_results = 1;
+    tu_init();
+
+    tu_suite_set_init_cb((void *)oic_test_init, NULL);
+    oic_test_all();
+
+    return tu_any_failed;
+}
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b4049e5/net/oic/test/src/test_oic.h
----------------------------------------------------------------------
diff --git a/net/oic/test/src/test_oic.h b/net/oic/test/src/test_oic.h
new file mode 100644
index 0000000..af227ac
--- /dev/null
+++ b/net/oic/test/src/test_oic.h
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+#ifndef TEST_OIC_H
+#define TEST_OIC_H
+
+#include <assert.h>
+#include <string.h>
+#include "testutil/testutil.h"
+#include "test_oic.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Testcases
+ */
+TEST_CASE_DECL(oic_test_discover);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TEST_OIC_H */
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b4049e5/net/oic/test/src/testcases/oic_discover.c
----------------------------------------------------------------------
diff --git a/net/oic/test/src/testcases/oic_discover.c 
b/net/oic/test/src/testcases/oic_discover.c
new file mode 100644
index 0000000..8a7a69a
--- /dev/null
+++ b/net/oic/test/src/testcases/oic_discover.c
@@ -0,0 +1,215 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 "test_oic.h"
+
+#include <os/os.h>
+#include <oic/oc_api.h>
+
+#define OIC_TAPP_PRIO       9
+#define OIC_TAPP_STACK_SIZE 1024
+
+static int oic_test_state;
+
+static struct os_task oic_tapp;
+static os_stack_t oic_tapp_stack[OS_STACK_ALIGN(OIC_TAPP_STACK_SIZE)];
+static struct os_eventq oic_tapp_evq;
+static void oic_test_next_step(struct os_event *);
+static struct os_event oic_test_next_step_ev = {
+    .ev_cb = oic_test_next_step
+};
+static struct os_callout oic_test_timer;
+
+/*
+ * Discovery.
+ */
+static void
+oic_test_discover_init(void)
+{
+    oc_init_platform("TestPlatform", NULL, NULL);
+}
+
+static void
+oic_test_discover_client_requests(void)
+{
+}
+
+static oc_handler_t oic_test_discover_handler = {
+    .init = oic_test_discover_init,
+    .requests_entry = oic_test_discover_client_requests
+};
+
+static oc_discovery_flags_t
+discover_cb(const char *di, const char *uri, oc_string_array_t types,
+            oc_interface_mask_t interfaces, oc_server_handle_t *server)
+{
+    uint8_t local_endpoint[] = { 0, 0, 0, 0, 0, 0, 0, 1 };
+
+    /*
+     * Only care about discovery responses from localhost.
+     */
+    if ((server->endpoint.oe.flags & IP) == 0) {
+        return 0;
+    }
+    if (memcmp(&server->endpoint.oe_ip.v6.address[8], local_endpoint, 8)) {
+        return 0;
+    }
+    printf("%d %s %s\n", oic_test_state, di, uri);
+    switch (oic_test_state) {
+    case 1:
+        TEST_ASSERT(!strcmp(uri, "/oic/p"));
+        TEST_ASSERT(interfaces == (OC_IF_BASELINE | OC_IF_R));
+        os_eventq_put(&oic_tapp_evq, &oic_test_next_step_ev);
+        return OC_STOP_DISCOVERY;
+        break;
+    case 2: {
+        static int seen_p = 0;
+        static int seen_d = 0;
+
+        if (!strcmp(uri, "/oic/p")) {
+            seen_p = 1;
+        } else if (!strcmp(uri, "/oic/d")) {
+            seen_d = 1;
+        } else {
+            TEST_ASSERT(0);
+        }
+        if (seen_p && seen_d) {
+            os_eventq_put(&oic_tapp_evq, &oic_test_next_step_ev);
+            return OC_STOP_DISCOVERY;
+        } else {
+            return OC_CONTINUE_DISCOVERY;
+        }
+    }
+    case 3: {
+        static int seen_p = 0;
+        static int seen_d = 0;
+        static int seen_light = 0;
+
+        if (!strcmp(uri, "/oic/p")) {
+            seen_p = 1;
+        } else if (!strcmp(uri, "/oic/d")) {
+            seen_d = 1;
+        } else if (!strcmp(uri, "/light/test")) {
+            seen_light = 1;
+        } else {
+            TEST_ASSERT(0);
+        }
+        if (seen_p && seen_d && seen_light) {
+            os_eventq_put(&oic_tapp_evq, &oic_test_next_step_ev);
+            /*
+             * Done.
+             */
+            tu_restart();
+            return OC_STOP_DISCOVERY;
+        } else {
+            return OC_CONTINUE_DISCOVERY;
+        }
+    }
+    default:
+        break;
+    }
+    TEST_ASSERT_FATAL(0);
+    return 0;
+}
+
+static void
+oic_test_timer_cb(struct os_event *ev)
+{
+    TEST_ASSERT_FATAL(0);
+}
+
+static void
+oic_light_get(oc_request_t *req, oc_interface_mask_t interface)
+{
+}
+
+static void
+oic_test_next_step(struct os_event *ev)
+{
+    oic_test_state++;
+    switch (oic_test_state) {
+    case 1:
+        /*
+         * No resources registered yet.
+         */
+        oc_do_ip_discovery(NULL, discover_cb);
+        os_callout_reset(&oic_test_timer, OS_TICKS_PER_SEC);
+        break;
+    case 2:
+        oc_add_device("/oic/d", "oic.d.light", "TestDev", "1.0", "1.1",
+          NULL, NULL);
+        oc_do_ip_discovery(NULL, discover_cb);
+        os_callout_reset(&oic_test_timer, OS_TICKS_PER_SEC);
+        break;
+    case 3: {
+        oc_resource_t *res = oc_new_resource("/light/test", 1, 0);
+
+        oc_resource_bind_resource_type(res, "oic.r.light");
+        oc_resource_bind_resource_interface(res, OC_IF_RW);
+        oc_resource_set_default_interface(res, OC_IF_RW);
+
+        oc_resource_set_discoverable(res);
+        oc_resource_set_request_handler(res, OC_GET, oic_light_get);
+        oc_add_resource(res);
+        oc_do_ip_discovery(NULL, discover_cb);
+        os_callout_reset(&oic_test_timer, OS_TICKS_PER_SEC);
+        break;
+    }
+    default:
+        TEST_ASSERT(0);
+        break;
+    }
+}
+
+
+static void
+oic_test_handler(void *arg)
+{
+    oc_main_init(&oic_test_discover_handler);
+
+    while (1) {
+        os_eventq_run(&oic_tapp_evq);
+    }
+}
+
+static void
+oic_test_init(void)
+{
+    int rc;
+
+    os_eventq_init(&oic_tapp_evq);
+
+    /*
+     * Starts tests.
+     */
+    os_eventq_put(&oic_tapp_evq, &oic_test_next_step_ev);
+    os_callout_init(&oic_test_timer, &oic_tapp_evq, oic_test_timer_cb, NULL);
+
+    rc = os_task_init(&oic_tapp, "oic_test", oic_test_handler, NULL,
+                      OIC_TAPP_PRIO, OS_WAIT_FOREVER,
+                      oic_tapp_stack, OS_STACK_ALIGN(OIC_TAPP_STACK_SIZE));
+    TEST_ASSERT_FATAL(rc == 0);
+    oc_evq_set(&oic_tapp_evq);
+
+    os_start();
+}
+
+TEST_CASE(oic_test_discover)
+{
+    oic_test_init();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b4049e5/net/oic/test/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/oic/test/syscfg.yml b/net/oic/test/syscfg.yml
new file mode 100644
index 0000000..47ceb25
--- /dev/null
+++ b/net/oic/test/syscfg.yml
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+#
+
+# Package: sys/config/test-fcb
+
+syscfg.vals:
+  OC_TRANSPORT_IP: 1
+  OC_SERVER: 1
+  OC_CLIENT: 1

Reply via email to