diff mbox series

[rt-tests,v2,05/14] rt-util: Add start time of test execution for JSON output

Message ID 20210305073500.17926-6-dwagner@suse.de
State Superseded
Headers show
Series JSON cleanups and more tests updated | expand

Commit Message

Daniel Wagner March 5, 2021, 7:34 a.m. UTC
Store the start time when the test starts to execute in the JSON
output.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 src/cyclictest/cyclictest.c           |  1 +
 src/include/rt-utils.h                |  2 ++
 src/lib/rt-utils.c                    | 34 +++++++++++++++++++--------
 src/oslat/oslat.c                     |  1 +
 src/pmqtest/pmqtest.c                 |  1 +
 src/ptsematest/ptsematest.c           |  1 +
 src/rt-migrate-test/rt-migrate-test.c |  1 +
 src/sched_deadline/cyclicdeadline.c   |  1 +
 src/signaltest/signaltest.c           |  1 +
 src/sigwaittest/sigwaittest.c         |  1 +
 src/svsematest/svsematest.c           |  1 +
 11 files changed, 35 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 3f3b91bab53b..033b95a3a19a 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -615,6 +615,7 @@  static void *timerthread(void *param)
 		setitimer(ITIMER_REAL, &itimer, NULL);
 	}
 
+	rt_test_start();
 	stat->threadstarted++;
 
 	while (!shutdown) {
diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h
index 11d69ea7e49a..d83f11930998 100644
--- a/src/include/rt-utils.h
+++ b/src/include/rt-utils.h
@@ -82,6 +82,8 @@  static inline int64_t calctime(struct timespec t)
 
 void rt_init(int argc, char *argv[]);
 
+void rt_test_start(void);
+
 void rt_write_json(const char *filename,
 		   void (*cb)(FILE *, void *), void *data);
 
diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
index 9c9d0dee3255..09d79170c371 100644
--- a/src/lib/rt-utils.c
+++ b/src/lib/rt-utils.c
@@ -30,6 +30,7 @@ 
 
 #define  TRACEBUFSIZ  1024
 #define  MAX_COMMAND_LINE 4096
+#define  MAX_TS_SIZE 64
 
 static char debugfileprefix[MAX_PATH];
 static char *fileprefix;
@@ -37,6 +38,7 @@  static int trace_fd = -1;
 static int tracemark_fd = -1;
 static __thread char tracebuf[TRACEBUFSIZ];
 static char cmdline[MAX_COMMAND_LINE];
+static char ts_start[MAX_TS_SIZE];
 
 /*
  * Finds the tracing directory in a mounted debugfs
@@ -514,16 +516,31 @@  void rt_init(int argc, char *argv[])
 	}
 }
 
+static void get_timestamp(char *tsbuf)
+{
+	struct timeval tv;
+	struct tm *tm;
+	time_t t;
+
+	gettimeofday(&tv, NULL);
+	t = tv.tv_sec;
+	tm = localtime(&t);
+	/* RFC 2822-compliant date format */
+	strftime(tsbuf, MAX_TS_SIZE, "%a, %d %b %Y %T %z", tm);
+}
+
+void rt_test_start(void)
+{
+	get_timestamp(ts_start);
+}
+
 void rt_write_json(const char *filename,
 		   void (*cb)(FILE *, void *), void *data)
 {
 	unsigned char buf[1];
 	struct utsname uts;
-	struct timeval tv;
-	char tsbuf[64];
-	struct tm *tm;
+	char ts_end[MAX_TS_SIZE];
 	FILE *f, *s;
-	time_t t;
 	size_t n;
 	int rt = 0;
 
@@ -535,11 +552,7 @@  void rt_write_json(const char *filename,
 			err_exit(errno, "Failed to open '%s'\n", filename);
 	}
 
-	gettimeofday(&tv, NULL);
-	t = tv.tv_sec;
-	tm = localtime(&t);
-	/* RFC 2822-compliant date format */
-	strftime(tsbuf, sizeof(tsbuf), "%a, %d %b %Y %T %z", tm);
+	get_timestamp(ts_end);
 
 	s = fopen("/sys/kernel/realtime", "r");
 	if (s) {
@@ -556,7 +569,8 @@  void rt_write_json(const char *filename,
 	fprintf(f, "  \"file_version\": 1,\n");
 	fprintf(f, "  \"cmdline:\": \"%s\",\n", cmdline);
 	fprintf(f, "  \"rt_test_version:\": \"%1.2f\",\n", VERSION);
-	fprintf(f, "  \"finished\": \"%s\",\n", tsbuf);
+	fprintf(f, "  \"start_time\": \"%s\",\n", ts_start);
+	fprintf(f, "  \"end_time\": \"%s\",\n", ts_end);
 	fprintf(f, "  \"sysinfo\": {\n");
 	fprintf(f, "    \"sysname\": \"%s\",\n", uts.sysname);
 	fprintf(f, "    \"nodename\": \"%s\",\n", uts.nodename);
diff --git a/src/oslat/oslat.c b/src/oslat/oslat.c
index ac54d05697ef..2f02f5399405 100644
--- a/src/oslat/oslat.c
+++ b/src/oslat/oslat.c
@@ -854,6 +854,7 @@  int main(int argc, char *argv[])
 		printf("Test starts...\n");
 	/* Reset n_threads to always run on all the cores */
 	g.n_threads = g.n_threads_total;
+	rt_test_start();
 	run_expt(threads, g.runtime);
 
 	if (!g.quiet)
diff --git a/src/pmqtest/pmqtest.c b/src/pmqtest/pmqtest.c
index f96b3d0bf400..adf72c10ce83 100644
--- a/src/pmqtest/pmqtest.c
+++ b/src/pmqtest/pmqtest.c
@@ -583,6 +583,7 @@  int main(int argc, char *argv[])
 	sigemptyset(&sigset);
 	pthread_sigmask(SIG_SETMASK, &sigset, NULL);
 
+	rt_test_start();
 	do {
 		int newsamples = 0, newtimeoutcount = 0;
 		int minsamples = INT_MAX;
diff --git a/src/ptsematest/ptsematest.c b/src/ptsematest/ptsematest.c
index a32bfc1698f0..471f1b307c14 100644
--- a/src/ptsematest/ptsematest.c
+++ b/src/ptsematest/ptsematest.c
@@ -468,6 +468,7 @@  int main(int argc, char *argv[])
 	maindelay.tv_sec = 0;
 	maindelay.tv_nsec = 50000000; /* 50 ms */
 
+	rt_test_start();
 	while (!shutdown) {
 		for (i = 0; i < num_threads; i++)
 			shutdown |= receiver[i].shutdown | sender[i].shutdown;
diff --git a/src/rt-migrate-test/rt-migrate-test.c b/src/rt-migrate-test/rt-migrate-test.c
index cdfbfafb200b..8f628d347a23 100644
--- a/src/rt-migrate-test/rt-migrate-test.c
+++ b/src/rt-migrate-test/rt-migrate-test.c
@@ -621,6 +621,7 @@  int main (int argc, char **argv)
 
 	setup_ftrace_marker();
 
+	rt_test_start();
 	for (loop=0; loop < nr_runs; loop++) {
 		unsigned long long end;
 
diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
index e6811838b62d..a649e5a0fe5e 100644
--- a/src/sched_deadline/cyclicdeadline.c
+++ b/src/sched_deadline/cyclicdeadline.c
@@ -1213,6 +1213,7 @@  int main(int argc, char **argv)
 	if (duration)
 		alarm(duration);
 
+	rt_test_start();
 	loop(sched_data, nr_threads);
 
 	for (i = 0; i < nr_threads; i++) {
diff --git a/src/signaltest/signaltest.c b/src/signaltest/signaltest.c
index 6abf38b7821c..7327d0d0144d 100644
--- a/src/signaltest/signaltest.c
+++ b/src/signaltest/signaltest.c
@@ -500,6 +500,7 @@  int main(int argc, char **argv)
 			      strerror(status));
 	}
 
+	rt_test_start();
 	while (!shutdown) {
 		int allstarted = 1;
 
diff --git a/src/sigwaittest/sigwaittest.c b/src/sigwaittest/sigwaittest.c
index 142419f9e315..6e8bc7b50d5f 100644
--- a/src/sigwaittest/sigwaittest.c
+++ b/src/sigwaittest/sigwaittest.c
@@ -652,6 +652,7 @@  int main(int argc, char *argv[])
 			    &sender[i]);
 	}
 
+	rt_test_start();
 	while (!mustshutdown) {
 		for (i = 0; i < num_threads; i++)
 			mustshutdown |= receiver[i].shutdown |
diff --git a/src/svsematest/svsematest.c b/src/svsematest/svsematest.c
index 7c9d21edbab2..7533b1b569cc 100644
--- a/src/svsematest/svsematest.c
+++ b/src/svsematest/svsematest.c
@@ -724,6 +724,7 @@  int main(int argc, char *argv[])
 			    &sender[i]);
 	}
 
+	rt_test_start();
 	while (!mustshutdown) {
 		for (i = 0; i < num_threads; i++)
 			mustshutdown |= receiver[i].shutdown |