You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/06/08 23:46:00 UTC

incubator-mynewt-core git commit: libs/crash_test; add a package to test faulting the system.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop c35d48d84 -> b1f2c51e5


libs/crash_test; add a package to test faulting the system.


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/b1f2c51e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b1f2c51e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b1f2c51e

Branch: refs/heads/develop
Commit: b1f2c51e5fc00a29a72ec3442d419419f1f2f630
Parents: c35d48d
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Jun 8 16:42:05 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Jun 8 16:42:05 2016 -0700

----------------------------------------------------------------------
 libs/crash_test/include/crash_test/crash_test.h | 27 ++++++++
 libs/crash_test/pkg.yml                         | 36 ++++++++++
 libs/crash_test/src/crash_cli.c                 | 46 ++++++++++++
 libs/crash_test/src/crash_nmgr.c                | 73 ++++++++++++++++++++
 libs/crash_test/src/crash_test.c                | 70 +++++++++++++++++++
 libs/crash_test/src/crash_test_priv.h           | 31 +++++++++
 libs/newtmgr/include/newtmgr/newtmgr.h          |  1 +
 7 files changed, 284 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1f2c51e/libs/crash_test/include/crash_test/crash_test.h
----------------------------------------------------------------------
diff --git a/libs/crash_test/include/crash_test/crash_test.h b/libs/crash_test/include/crash_test/crash_test.h
new file mode 100644
index 0000000..73135fd
--- /dev/null
+++ b/libs/crash_test/include/crash_test/crash_test.h
@@ -0,0 +1,27 @@
+/**
+ * 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 __CRASH_TEST_H__
+#define __CRASH_TEST_H__
+
+/*
+ * Adds the crash commands to your shell/newtmgr.
+ */
+int crash_test_init(void);
+
+#endif /* __CRASH_TEST_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1f2c51e/libs/crash_test/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/crash_test/pkg.yml b/libs/crash_test/pkg.yml
new file mode 100644
index 0000000..872c029
--- /dev/null
+++ b/libs/crash_test/pkg.yml
@@ -0,0 +1,36 @@
+#
+# 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: libs/crash_test
+pkg.description: Generate different kinds of faults
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps.SHELL:
+    - libs/shell
+pkg.req_apis.SHELL:
+    - console
+pkg.cflags.SHELL:
+    - -DSHELL_PRESENT
+
+pkg.deps.NEWTMGR:
+    - libs/newtmgr
+    - libs/json
+pkg.cflags.NEWTMGR:
+    - -DNEWTMGR_PRESENT

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1f2c51e/libs/crash_test/src/crash_cli.c
----------------------------------------------------------------------
diff --git a/libs/crash_test/src/crash_cli.c b/libs/crash_test/src/crash_cli.c
new file mode 100644
index 0000000..db22e13
--- /dev/null
+++ b/libs/crash_test/src/crash_cli.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.
+ */
+#ifdef SHELL_PRESENT
+#include <inttypes.h>
+#include <os/os.h>
+#include <console/console.h>
+#include <shell/shell.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "crash_test/crash_test.h"
+#include "crash_test_priv.h"
+
+static int crash_cli_cmd(int argc, char **argv);
+struct shell_cmd crash_cmd_struct = {
+    .sc_cmd = "crash",
+    .sc_cmd_func = crash_cli_cmd
+};
+
+static int
+crash_cli_cmd(int argc, char **argv)
+{
+    if (argc >= 2 && crash_device(argv[1]) == 0) {
+        return 0;
+    }
+    console_printf("Usage crash [div0|jump0|ref0|assert]\n");
+    return 0;
+}
+
+#endif /* SHELL_PRESENT */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1f2c51e/libs/crash_test/src/crash_nmgr.c
----------------------------------------------------------------------
diff --git a/libs/crash_test/src/crash_nmgr.c b/libs/crash_test/src/crash_nmgr.c
new file mode 100644
index 0000000..e53fdf8
--- /dev/null
+++ b/libs/crash_test/src/crash_nmgr.c
@@ -0,0 +1,73 @@
+/**
+ * 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.
+ */
+
+#ifdef NEWTMGR_PRESENT
+
+#include <string.h>
+
+#include <newtmgr/newtmgr.h>
+#include <json/json.h>
+#include <console/console.h>
+
+#include "crash_test/crash_test.h"
+#include "crash_test_priv.h"
+
+static int crash_test_nmgr_write(struct nmgr_jbuf *);
+
+static const struct nmgr_handler crash_test_nmgr_handler[] = {
+    [0] = { crash_test_nmgr_write, crash_test_nmgr_write }
+};
+
+struct nmgr_group crash_test_nmgr_group = {
+    .ng_handlers = (struct nmgr_handler *)crash_test_nmgr_handler,
+    .ng_handlers_count = 1,
+    .ng_group_id = NMGR_GROUP_ID_CRASH
+};
+
+static int
+crash_test_nmgr_write(struct nmgr_jbuf *njb)
+{
+    char tmp_str[64];
+    const struct json_attr_t attr[2] = {
+        [0] = {
+            .attribute = "t",
+            .type = t_string,
+            .addr.string = tmp_str,
+            .len = sizeof(tmp_str)
+        },
+        [1] = {
+            .attribute = NULL
+        }
+    };
+    int rc;
+
+    rc = json_read_object(&njb->njb_buf, attr);
+    if (rc) {
+        rc = NMGR_ERR_EINVAL;
+    } else {
+        rc = crash_device(tmp_str);
+        if (rc) {
+            rc = NMGR_ERR_EINVAL;
+        }
+    }
+    nmgr_jbuf_setoerr(njb, rc);
+    return 0;
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1f2c51e/libs/crash_test/src/crash_test.c
----------------------------------------------------------------------
diff --git a/libs/crash_test/src/crash_test.c b/libs/crash_test/src/crash_test.c
new file mode 100644
index 0000000..91f1dbd
--- /dev/null
+++ b/libs/crash_test/src/crash_test.c
@@ -0,0 +1,70 @@
+/**
+ * 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 <inttypes.h>
+#include <os/os.h>
+#include <console/console.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include "crash_test/crash_test.h"
+#include "crash_test_priv.h"
+
+#ifdef SHELL_PRESENT
+#include <shell/shell.h>
+#endif
+#ifdef NEWTMGR_PRESENT
+#include <newtmgr/newtmgr.h>
+#endif
+
+int
+crash_device(char *how)
+{
+    volatile int val1, val2, val3;
+
+    if (!strcmp(how, "div0")) {
+
+        val1 = 42;
+        val2 = 0;
+
+        val3 = val1 / val2;
+        console_printf("42/0 = %d\n", val3);
+    } else if (!strcmp(how, "jump0")) {
+        ((void (*)(void))0)();
+    } else if (!strcmp(how, "ref0")) {
+        val1 = *(int *)0;
+    } else if (!strcmp(how, "assert")) {
+        assert(0);
+    } else {
+        return -1;
+    }
+    return 0;
+}
+
+int
+crash_test_init(void)
+{
+#ifdef SHELL_PRESENT
+    shell_cmd_register(&crash_cmd_struct);
+#endif
+#ifdef NEWTMGR_PRESENT
+    nmgr_group_register(&crash_test_nmgr_group);
+#endif
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1f2c51e/libs/crash_test/src/crash_test_priv.h
----------------------------------------------------------------------
diff --git a/libs/crash_test/src/crash_test_priv.h b/libs/crash_test/src/crash_test_priv.h
new file mode 100644
index 0000000..e4af708
--- /dev/null
+++ b/libs/crash_test/src/crash_test_priv.h
@@ -0,0 +1,31 @@
+/**
+ * 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 __CRASH_TEST_PRIV_H__
+#define __CRASH_TEST_PRIV_H__
+
+#ifdef SHELL_PRESENT
+extern struct shell_cmd crash_cmd_struct;
+#endif
+#ifdef NEWTMGR_PRESENT
+extern struct nmgr_group crash_test_nmgr_group;
+#endif
+
+int crash_device(char *how);
+
+#endif /* __CRASH_TEST_PRIV_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b1f2c51e/libs/newtmgr/include/newtmgr/newtmgr.h
----------------------------------------------------------------------
diff --git a/libs/newtmgr/include/newtmgr/newtmgr.h b/libs/newtmgr/include/newtmgr/newtmgr.h
index c2c327d..b93b2a4 100644
--- a/libs/newtmgr/include/newtmgr/newtmgr.h
+++ b/libs/newtmgr/include/newtmgr/newtmgr.h
@@ -32,6 +32,7 @@
 #define NMGR_GROUP_ID_STATS     (2)
 #define NMGR_GROUP_ID_CONFIG    (3)
 #define NMGR_GROUP_ID_LOGS      (4)
+#define NMGR_GROUP_ID_CRASH     (5)
 #define NMGR_GROUP_ID_PERUSER   (64)
 
 #define NMGR_OP_READ            (0)