You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2018/12/28 23:38:50 UTC

[mynewt-core] branch master updated: sys/fault: Stub implementation

This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 8f6ab27  sys/fault: Stub implementation
8f6ab27 is described below

commit 8f6ab27ab1a06880d0879e42697ce001c028599a
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Fri Dec 28 14:52:07 2018 -0800

    sys/fault: Stub implementation
    
    This commit adds a new syscfg setting: FAULT_STUB.  When enabled, all
    fault functions are turned into no ops.  This is useful for unit testing
    or other similar applications when system-wide fault management is not
    wanted.
---
 sys/fault/src/fault.c      |   4 ++
 sys/fault/src/fault_stub.c | 100 +++++++++++++++++++++++++++++++++++++++++++++
 sys/fault/syscfg.yml       |   6 +++
 3 files changed, 110 insertions(+)

diff --git a/sys/fault/src/fault.c b/sys/fault/src/fault.c
index 55a40fc..928458b 100644
--- a/sys/fault/src/fault.c
+++ b/sys/fault/src/fault.c
@@ -19,6 +19,8 @@
 
 #include "os/mynewt.h"
 
+#if !MYNEWT_VAL(FAULT_STUB)
+
 #include "modlog/modlog.h"
 #include "fault/fault.h"
 #include "fault_priv.h"
@@ -336,3 +338,5 @@ fault_init(void)
     rc = fault_conf_init();
     SYSINIT_PANIC_ASSERT(rc == 0);
 }
+
+#endif /* !MYNEWT_VAL(FAULT_STUB) */
diff --git a/sys/fault/src/fault_stub.c b/sys/fault/src/fault_stub.c
new file mode 100644
index 0000000..5b3f3f2
--- /dev/null
+++ b/sys/fault/src/fault_stub.c
@@ -0,0 +1,100 @@
+/*
+ * 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 "os/mynewt.h"
+
+#if MYNEWT_VAL(FAULT_STUB)
+
+#include "fault/fault.h"
+
+void
+fault_configure_cb(fault_thresh_fn *cb)
+{ }
+
+int
+fault_process(struct fault_recorder *recorder, bool is_failure)
+{
+    return 0;
+}
+
+int
+fault_success(struct fault_recorder *recorder)
+{
+    return 0;
+}
+
+int
+fault_failure(struct fault_recorder *recorder)
+{
+    return 0;
+}
+
+void
+fault_fatal(int domain_id, void *arg, bool is_failure)
+{ }
+
+void
+fault_fatal_success(int domain_id, void *arg)
+{ }
+
+void
+fault_fatal_failure(int domain_id, void *arg)
+{ }
+
+int
+fault_get_chronic_count(int domain_id, uint8_t *out_count)
+{
+    *out_count = 0;
+    return 0;
+}
+
+int
+fault_set_chronic_count(int domain_id, uint8_t count)
+{
+    return 0;
+}
+
+int
+fault_recorder_init(struct fault_recorder *recorder,
+                    int domain_id,
+                    uint16_t warn_thresh,
+                    uint16_t error_thresh,
+                    void *arg)
+{
+    return 0;
+}
+
+const char *
+fault_domain_name(int domain_id)
+{
+    return NULL;
+}
+
+int
+fault_register_domain_priv(int domain_id, uint8_t success_delta,
+                           uint8_t failure_delta, const char *name)
+{
+    return 0;
+}
+
+void
+fault_init(void)
+{ }
+
+#endif /* MYNEWT_VAL(FAULT_STUB) */
diff --git a/sys/fault/syscfg.yml b/sys/fault/syscfg.yml
index dcf4fea..e25e6f1 100644
--- a/sys/fault/syscfg.yml
+++ b/sys/fault/syscfg.yml
@@ -18,6 +18,12 @@
 #
 
 syscfg.defs:
+    FAULT_STUB:
+        description: >
+            Turns all functions in the fault API into no-ops.  All domains are
+            considered to have a chronic fail count of 0.
+        value: 0
+
     FAULT_CLI:
         description: >
             Enables the `fault` CLI command.