[rtems commit] libtest: Add T_get_scope()

Sebastian Huber sebh at rtems.org
Thu Jul 23 08:57:41 UTC 2020


Module:    rtems
Branch:    master
Commit:    63e42784290b4bb103fbb3f64bad23dc9edef9f3
Changeset: http://git.rtems.org/rtems/commit/?id=63e42784290b4bb103fbb3f64bad23dc9edef9f3

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Jun 26 07:44:55 2020 +0200

libtest: Add T_get_scope()

Update #3199.

---

 cpukit/include/rtems/test.h | 23 +++++++++++++++++++++++
 cpukit/libtest/t-test.c     | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/cpukit/include/rtems/test.h b/cpukit/include/rtems/test.h
index 04f92dd..09afc29 100644
--- a/cpukit/include/rtems/test.h
+++ b/cpukit/include/rtems/test.h
@@ -2243,6 +2243,29 @@ void *T_push_fixture(T_fixture_node *, const T_fixture *);
 
 void T_pop_fixture(void);
 
+/**
+ * @brief Gets the scope for nested fixtures.
+ *
+ * This function should help implementing scope fixture methods.  The parameter
+ * layout allows efficient code generation for this method.
+ *
+ * @param desc is the description table.  It shall be a NULL-terminated array
+ *   which references arrays of descriptive strings.
+ *
+ * @param buf is the buffer for the scope string.
+ *
+ * @param n is the size of the scope buffer in characters.
+ *
+ * @param second_indices is an array of indices defining which descriptive
+ *   string is used for each entry in the description table.
+ */
+void T_get_scope(
+  const char * const * const *desc,
+  char *buf,
+  size_t n,
+  const size_t *second_indices
+);
+
 #ifdef __rtems__
 #define T_TEST_CASE_FIXTURE(name, fixture)			\
 void T_case_body_##name(void);					\
diff --git a/cpukit/libtest/t-test.c b/cpukit/libtest/t-test.c
index bf9b68c..e74b4d3 100644
--- a/cpukit/libtest/t-test.c
+++ b/cpukit/libtest/t-test.c
@@ -1095,3 +1095,42 @@ T_pop_fixture(void)
 
 	memset(node, 0, sizeof(*node));
 }
+
+void
+T_get_scope(const char * const * const *desc, char *buf, size_t n,
+    const size_t *second_indices)
+{
+	size_t i;
+
+	i = 0;
+
+	while (true) {
+		const char * const *desc2;
+		size_t m;
+
+		desc2 = desc[i];
+
+		if (desc2 == NULL) {
+			return;
+		}
+
+		if (n > 1) {
+			buf[0] = '/';
+			--n;
+			++buf;
+		} else {
+			return;
+		}
+
+		m = strlcpy(buf, desc2[second_indices[i]], n);
+
+		if (m < n) {
+			n -= m;
+			buf += m;
+		} else {
+			return;
+		}
+
+		++i;
+	}
+}



More information about the vc mailing list