[rtems commit] libtest: Add support to seize/surrender objects

Sebastian Huber sebh at rtems.org
Wed Feb 24 09:47:57 UTC 2021


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Sun Feb 21 17:26:31 2021 +0100

libtest: Add support to seize/surrender objects

---

 cpukit/include/rtems/test.h        |  5 ++++
 cpukit/libtest/t-test-rtems-objs.c | 54 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git a/cpukit/include/rtems/test.h b/cpukit/include/rtems/test.h
index b42bf5f..10ff665 100644
--- a/cpukit/include/rtems/test.h
+++ b/cpukit/include/rtems/test.h
@@ -36,6 +36,7 @@
 
 #ifdef __rtems__
 #include <rtems/score/cpu.h>
+#include <rtems/rtems/status.h>
 #endif
 
 #ifdef __cplusplus
@@ -2512,6 +2513,10 @@ typedef enum {
 } T_thread_timer_state;
 
 T_thread_timer_state T_get_thread_timer_state(uint32_t);
+
+void *T_seize_objects(rtems_status_code (*)(void *, uint32_t *), void *);
+
+void T_surrender_objects(void **, rtems_status_code (*)(uint32_t));
 #endif /* __rtems__ */
 
 /**
diff --git a/cpukit/libtest/t-test-rtems-objs.c b/cpukit/libtest/t-test-rtems-objs.c
index ad8d153..6548848 100644
--- a/cpukit/libtest/t-test-rtems-objs.c
+++ b/cpukit/libtest/t-test-rtems-objs.c
@@ -410,3 +410,57 @@ T_check_rtems_timers(T_event event, const char *name)
 		break;
 	};
 }
+
+void *
+T_seize_objects(rtems_status_code (*create)(void *, uint32_t *), void *arg)
+{
+	void *objects;
+
+	objects = NULL;
+
+	while (true) {
+		rtems_status_code sc;
+		rtems_id id;
+
+		id = 0;
+		sc = (*create)(arg, &id);
+
+		if (sc == RTEMS_SUCCESSFUL) {
+			const Objects_Information *info;
+			Objects_Control *obj;
+
+			info = _Objects_Get_information_id(id);
+			T_quiet_assert_not_null(info);
+			obj = _Objects_Get_no_protection(id, info);
+			T_quiet_assert_not_null(obj);
+			obj->Node.next = objects;
+			objects = obj;
+		} else {
+			T_quiet_rsc(sc, RTEMS_TOO_MANY);
+			break;
+		}
+	}
+
+	return objects;
+}
+
+void
+T_surrender_objects(void **objects_p, rtems_status_code (*delete)(uint32_t))
+{
+	void *objects;
+
+	objects = *objects_p;
+	*objects_p = NULL;
+
+	while (objects != NULL) {
+		Objects_Control *obj;
+		rtems_status_code sc;
+
+		obj = objects;
+		objects = _Chain_Next(&obj->Node);
+		_Chain_Set_off_chain(&obj->Node);
+
+		sc = (*delete)(obj->id);
+		T_quiet_rsc_success(sc);
+	}
+}



More information about the vc mailing list