add a cycle test
authorLaurent Mazet <mazet@softndesign.org>
Sat, 4 Oct 2025 21:17:17 +0000 (23:17 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Sat, 4 Oct 2025 21:17:17 +0000 (23:17 +0200)
cycle.c [new file with mode: 0644]

diff --git a/cycle.c b/cycle.c
new file mode 100644 (file)
index 0000000..5ebc8e7
--- /dev/null
+++ b/cycle.c
@@ -0,0 +1,48 @@
+/* depend: */
+/* cflags: */
+/* linker: mtime.o test.o stat.o -lm -lrt */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "mtime.h"
+#include "test.h"
+
+/* global variables */
+
+dts_t *deltas = NULL;
+int nb_measurements = 0;
+
+char *message = "Cycle latency";
+void (*usage_ext) (FILE *) = NULL;
+int (*parse_arg_ext) (char *) = NULL;
+
+int try = 0;
+
+#define MAXDUR 1000
+#define MINDUR 100
+
+int test (dts_t *buffer, int nb)
+{
+
+    /* set global variables */
+
+    deltas = buffer;
+    nb_measurements = nb;
+
+    /* thread test */
+
+    for (int i = 0; i < nb_measurements; i++) {
+
+        int duration = MINDUR * ((MAXDUR / MINDUR) * rand () / RAND_MAX);
+
+        ts_t ts1, ts2;
+        sys_timestamp (&ts1);
+        usleep (duration);
+        sys_timestamp (&ts2);
+        deltas[i] = diff_timestamp (&ts2, &ts1) - duration;
+    }
+
+    return 0;
+}