Skip to contentSkip to conversation

Add quiet command line option

PATCH Superseded Daniel Wagner 4 participants 29 messages Nov 18, 2020 – Dec 1, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add quiet command line option

Silence the terminal output for automated tested. I think I got all tests udpated which are pretty load.

This series is ontop of "Teach signaltest affinity" series [1]

[1] https://lore.kernel.org/linux-rt-users/[email protected]/

Daniel Wagner (12):
cyclicdeadline: Remove dead code
cyclicdeadline: Use common error handlers
cyclicdeadline: Add quiet command line option
pmqtest: Move statictic output into print_stat()
pmqtest: Add quiet command line option
ptsematest: Move statictic output into print_stat()
ptsematest: Add quiet command line option
svsematest: Move statictic output into print_stat()
svsematest: Add quiet command line option
sigwaittest: Move statictic output into print_stat()
sigwaittest: Add quiet command line option
rt-migrate-test: Add quiet command line option

 compare.py                            |  12 ++
 src/pmqtest/pmqtest.8                 |   5 +-
 src/pmqtest/pmqtest.c                 |  77 +++++-----
 src/ptsematest/ptsematest.8           |   5 +-
 src/ptsematest/ptsematest.c           |  79 +++++-----
 src/rt-migrate-test/rt-migrate-test.c |  12 +-
 src/sched_deadline/cyclicdeadline.8   |   6 +-
 src/sched_deadline/cyclicdeadline.c   | 200 ++++++++++----------------
 src/sigwaittest/sigwaittest.c         | 110 +++++++-------
 src/svsematest/svsematest.8           |   5 +-
 src/svsematest/svsematest.c           | 113 ++++++++-------
 11 files changed, 304 insertions(+), 320 deletions(-)
 create mode 100644 compare.py
Signature · 1 line
2.29.2
#1 lore raw

PATCH 1/12 cyclicdeadline: Remove dead code

my_sprintf() is not used, remove it.

---
 compare.py                          | 12 ++++++++++++
 src/sched_deadline/cyclicdeadline.c | 13 -------------
 2 files changed, 12 insertions(+), 13 deletions(-)
 create mode 100644 compare.py
compare.py new file +12 -0
new file mode 100644
index 000000000000..7fb6ae818a00
@@ -0,0 +1,12 @@
+with open('old', 'r') as old:
+    with open('new', 'r') as new:
+        for ol in old.readlines():
+            new.seek(0)
+            for nl in new.readlines():
+                o = ol.split()
+                n = nl.split()
+
+                if o[8] == n[8]:
+                    d = int(n[4]) - int(o[4])
+                    p = d/int(o[4]) * 100
+                    print('{:20} {:>8} {:>8} {:>6} {:>2.2}%'.format(o[8], o[4], n[4], d, p))
src/sched_deadline/cyclicdeadline.c +0 -13
index a6309ded3c52..e0db9669f676 100644
@@ -215,19 +215,6 @@ static int my_vsprintf(char *buf, int size, const char *fmt, va_list ap)
 	return s - buf;
 }
 
-#if 0
-static int my_sprintf(char *buf, int size, const char *fmt, ...)
-{
-	va_list ap;
-	int n;
-
-	va_start(ap, fmt);
-	n = vsnprintf(buf, size, fmt, ap);
-	va_end(ap);
-	return n;
-}
-#endif
-
 static void ftrace_write(char *buf, const char *fmt, ...)
 {
 	va_list ap;
Signature · 1 line
2.29.2
#2 lore raw

Re: [rt-tests v1 01/12] cyclicdeadline: Remove dead code

Hi Daniel,

One comment / query below -

Quoted 17 lines · Daniel Wagner

my_sprintf() is not used, remove it.

---
 compare.py                          | 12 ++++++++++++
 src/sched_deadline/cyclicdeadline.c | 13 -------------
 2 files changed, 12 insertions(+), 13 deletions(-)
 create mode 100644 compare.py
compare.py new file +2 -0
new file mode 100644
index 000000000000..7fb6ae818a00
@@ -0,0 +1,12 @@
+with open('old', 'r') as old:
+    with open('new', 'r') as new:

compare.py line 12

Quoted 10 lines
compare.py new file +10 -0
+        for ol in old.readlines():
+            new.seek(0)
+            for nl in new.readlines():
+                o = ol.split()
+                n = nl.split()
+
+                if o[8] == n[8]:
+                    d = int(n[4]) - int(o[4])
+                    p = d/int(o[4]) * 100
+                    print('{:20} {:>8} {:>8} {:>6} {:>2.2}%'.format(o[8], o[4], n[4], d, p))

This hunk seems to be unrelated and also not mentioned in the commit log. Perhaps it's accidentally part of this commit?

Thanks,
Punit

[...]

#3 lore raw

Re: [rt-tests v1 01/12] cyclicdeadline: Remove dead code

Hi Punit,

Quoted 28 lines · Punit Agrawal

Hi Daniel,

One comment / query below -

Quoted 22 lines · Daniel Wagner

my_sprintf() is not used, remove it.

---
  compare.py                          | 12 ++++++++++++
  src/sched_deadline/cyclicdeadline.c | 13 -------------
  2 files changed, 12 insertions(+), 13 deletions(-)

create mode 100644 compare.py

compare.py new file +7 -0
new file mode 100644
index 000000000000..7fb6ae818a00
@@ -0,0 +1,12 @@
+with open('old', 'r') as old:
+    with open('new', 'r') as new:
+        for ol in old.readlines():
+            new.seek(0)
+            for nl in new.readlines():
+                o = ol.split()
+                n = nl.split()
Quoted 8 lines

compare.py line 12

Quoted 5 lines
compare.py new file +5 -0
+
+                if o[8] == n[8]:
+                    d = int(n[4]) - int(o[4])
+                    p = d/int(o[4]) * 100
+                    print('{:20} {:>8} {:>8} {:>6} {:>2.2}%'.format(o[8], o[4], n[4], d, p))

This hunk seems to be unrelated and also not mentioned in the commit log. Perhaps it's accidentally part of this commit?

Indeed, this sneaked into the commit. Totally unrelated :)

I'll send an update.

Thanks,
Daniel

#4 lore raw

Re: [rt-tests v1 01/12] cyclicdeadline: Remove dead code

In reply to Daniel Wagner
Quoted 55 lines · Daniel Wagner

my_sprintf() is not used, remove it.

---
 compare.py                          | 12 ++++++++++++
 src/sched_deadline/cyclicdeadline.c | 13 -------------
 2 files changed, 12 insertions(+), 13 deletions(-)
 create mode 100644 compare.py
compare.py new file +12 -0
new file mode 100644
index 000000000000..7fb6ae818a00
@@ -0,0 +1,12 @@
+with open('old', 'r') as old:
+    with open('new', 'r') as new:
+        for ol in old.readlines():
+            new.seek(0)
+            for nl in new.readlines():
+                o = ol.split()
+                n = nl.split()
+
+                if o[8] == n[8]:
+                    d = int(n[4]) - int(o[4])
+                    p = d/int(o[4]) * 100
+                    print('{:20} {:>8} {:>8} {:>6} {:>2.2}%'.format(o[8], o[4], n[4], d, p))
src/sched_deadline/cyclicdeadline.c +0 -13
index a6309ded3c52..e0db9669f676 100644
@@ -215,19 +215,6 @@ static int my_vsprintf(char *buf, int size, const char *fmt, va_list ap)
 	return s - buf;
 }
 
-#if 0
-static int my_sprintf(char *buf, int size, const char *fmt, ...)
-{
-	va_list ap;
-	int n;
-
-	va_start(ap, fmt);
-	n = vsnprintf(buf, size, fmt, ap);
-	va_end(ap);
-	return n;
-}
-#endif
-
 static void ftrace_write(char *buf, const char *fmt, ...)
 {
 	va_list ap;
Signature · 1 line
2.29.2

Well, your git version is okay, but the version you posted here has compare.py, which I assume is somekind of internal tooling you created.

My SOB refers to your git version

#5 lore raw

Re: [rt-tests v1 01/12] cyclicdeadline: Remove dead code

Quoted 2 lines · John Kacur

Well, your git version is okay, but the version you posted here has compare.py, which I assume is somekind of internal tooling you created.

I've updated the patch and resend it.

Quoted 1 line

My SOB refers to your git version

Yes, the git version is reflects the latest version (without the compare.py junk)

Quoted 1 line
#6 lore raw

PATCH 2/12 cyclicdeadline: Use common error handlers

In reply to Daniel Wagner

Use the common error handlers. This will make the fatal, error and debug output consistent with the output from cyclictest. The current normal output is not changed.

While at it drop the 'fail' flag and use 'shutdown' flag which does the same thing.

---
 src/sched_deadline/cyclicdeadline.c | 165 ++++++++++------------------
 1 file changed, 59 insertions(+), 106 deletions(-)
src/sched_deadline/cyclicdeadline.c +59 -106
index e0db9669f676..7adc91465f44 100644
@@ -32,6 +32,7 @@
 
 #include <rt-utils.h>
 #include <rt-sched.h>
+#include <error.h>
 
 #define _STR(x) #x
 #define STR(x) _STR(x)
@@ -165,10 +166,8 @@ static int my_vsprintf(char *buf, int size, const char *fmt, va_list ap)
 			p++;
 			switch (*p) {
 			case 's':
-				if (l) {
-					fprintf(stderr, "Illegal print format l used with %%s\n");
-					exit(-1);
-				}
+				if (l)
+					fatal("Illegal print format l used with %%s\n");
 				str = va_arg(ap, char *);
 				l = strlen(str);
 				strncpy(s, str, end - s);
@@ -184,10 +183,9 @@ static int my_vsprintf(char *buf, int size, const char *fmt, va_list ap)
 				}
 				if (l == 2)
 					lng = va_arg(ap, long long);
-				else if (l > 2) {
-					fprintf(stderr, "Illegal print format l=%d\n", l);
-					exit(-1);
-				} else
+				else if (l > 2)
+					fatal("Illegal print format l=%d\n", l);
+				else
 					lng = va_arg(ap, int);
 				i = 0;
 				while (lng > 0) {
@@ -204,8 +202,7 @@ static int my_vsprintf(char *buf, int size, const char *fmt, va_list ap)
 				}
 				break;
 			default:
-				fprintf(stderr, "Illegal print format '%c'\n", *p);
-				exit(-1);
+				fatal("Illegal print format '%c'\n", *p);
 			}
 			continue;
 		}
@@ -397,8 +394,8 @@ enum {
 	CPUSET_FL_CLONE_CHILDREN	= (1 << 6),
 };
 
-static const char *make_cpuset(const char *name, const char *cpus,
-			       const char *mems, unsigned flags, ...)
+static void make_cpuset(const char *name, const char *cpus,
+		        const char *mems, unsigned flags, ...)
 {
 	struct stat st;
 	char path[MAXPATH];
@@ -413,64 +410,64 @@ static const char *make_cpuset(const char *name, const char *cpus,
 
 	ret = mount_cpuset();
 	if (ret < 0)
-		return "mount_cpuset";
+		fatal("mount_cpuset");
 
 	ret = stat(path, &st);
 	if (ret < 0) {
 		ret = mkdir(path, 0755);
 		if (ret < 0)
-			return "mkdir";
+			fatal("mkdir");
 	}
 
 	fd = open_cpuset(path, "cpuset.cpus");
 	if (fd < 0)
-		return "cset";
+		fatal("cset");
 	ret = write(fd, cpus, strlen(cpus));
 	close(fd);
 	if (ret < 0)
-		return "write cpus";
+		fatal("write cpus");
 
 	if (mems) {
 		fd = open_cpuset(path, "cpuset.mems");
 		if (fd < 0)
-			return "open mems";
+			fatal("open mems");
 		ret = write(fd, mems, strlen(mems));
 		close(fd);
 		if (ret < 0)
-			return "write mems";
+			fatal("write mems");
 	}
 
 	if (flags & CPUSET_FL_CPU_EXCLUSIVE) {
 		fd = open_cpuset(path, "cpuset.cpu_exclusive");
 		if (fd < 0)
-			return "open cpu_exclusive";
+			fatal("open cpu_exclusive");
 		ret = write(fd, "1", 2);
 		close(fd);
 		if (ret < 0)
-			return "write cpu_exclusive";
+			fatal("write cpu_exclusive");
 	}
 
 	if (flags & (CPUSET_FL_CLEAR_LOADBALANCE | CPUSET_FL_SET_LOADBALANCE)) {
 		fd = open_cpuset(path, "cpuset.sched_load_balance");
 		if (fd < 0)
-			return "open sched_load_balance";
+			fatal("open sched_load_balance");
 		if (flags & CPUSET_FL_SET_LOADBALANCE)
 			ret = write(fd, "1", 2);
 		else
 			ret = write(fd, "0", 2);
 		close(fd);
 		if (ret < 0)
-			return "write sched_load_balance";
+			fatal("write sched_load_balance");
 	}
 
 	if (flags & CPUSET_FL_CLONE_CHILDREN) {
 		fd = open_cpuset(path, "cgroup.clone_children");
 		if (fd < 0)
-			return "open clone_children";
+			fatal("open clone_children");
 		ret = write(fd, "1", 2);
 		close(fd);
 		if (ret < 0)
-			return "write clone_children";
+			fatal("write clone_children");
 	}
 
 
@@ -482,7 +479,7 @@ static const char *make_cpuset(const char *name, const char *cpus,
 
 		fd = open_cpuset(path, "tasks");
 		if (fd < 0)
-			return "open tasks";
+			fatal("open tasks");
 
 		ret = 0;
 		pids = va_arg(ap, int *);
@@ -492,10 +489,8 @@ static const char *make_cpuset(const char *name, const char *cpus,
 		}
 		va_end(ap);
 		close(fd);
-		if (ret < 0) {
-			fprintf(stderr, "Failed on task %d\n", pids[i]);
-			return "write tasks";
-		}
+		if (ret < 0)
+			fatal("Failed on task %d\n", pids[i]);
 	}
 
 	if (flags & CPUSET_FL_ALL_TASKS) {
@@ -507,7 +502,7 @@ static const char *make_cpuset(const char *name, const char *cpus,
 		snprintf(path, MAXPATH - 1, "%s/tasks", CPUSET_PATH);
 		if ((fp = fopen(path, "r")) == NULL) {
 			close(fd);
-			return "opening cpuset tasks";
+			fatal("opening cpuset tasks");
 		}
 
 		while (fscanf(fp, "%d", &pid) == 1) {
@@ -521,14 +516,12 @@ static const char *make_cpuset(const char *name, const char *cpus,
 			if (ret < 0 && errno == ENOSPC) {
 				fclose(fp);
 				close(fd);
-				return "Can not move tasks";
+				fatal("Can not move tasks");
 			}
 		}
 		fclose(fp);
 		close(fd);
 	}
-
-	return NULL;
 }
 
 static void destroy_cpuset(const char *name, int print)
@@ -580,16 +573,14 @@ static void destroy_cpuset(const char *name, int print)
 	snprintf(path, MAXPATH - 1, "%s/%s", CPUSET_PATH, name);
 	path[MAXPATH - 1] = 0;
 
-//	return;
 	sleep(1);
 	ret = rmdir(path);
 	if (ret < 0) {
 		if (retry++ < 5)
 			goto again;
-		fprintf(stderr, "Failed to remove %s\n", path);
-		perror("rmdir");
+		err_msg_n(errno, "Failed to remove %s\n", path);
 		if (retry++ < 5) {
-			fprintf(stderr, "Trying again\n");
+			err_msg("Trying again\n");
 			goto again;
 		}
 	}
@@ -640,8 +631,6 @@ static void usage(int error)
 	exit(error);
 }
 
-static int fail;
-
 static u64 get_time_us(void)
 {
 	struct timespec ts;
@@ -740,9 +729,8 @@ void *run_deadline(void *data)
 
 	ret = sched_getattr(0, &attr, sizeof(attr), 0);
 	if (ret < 0) {
-		fprintf(stderr, "[%ld]", tid);
-		perror("sched_getattr");
-		fail = 1;
+		err_msg_n(errno, "[%ld]", tid);
+		shutdown = 1;
 		pthread_barrier_wait(&barrier);
 		pthread_exit("Failed sched_getattr");
 		return NULL;
@@ -750,23 +738,19 @@ void *run_deadline(void *data)
 
 	pthread_barrier_wait(&barrier);
 
-	if (fail)
-		return NULL;
-
 	attr.sched_policy = SCHED_DEADLINE;
 	attr.sched_runtime = sd->runtime_us * 1000;
 	attr.sched_deadline = sd->deadline_us * 1000;
 
 	printf("thread[%d] runtime=%lldus deadline=%lldus\n",
-	       gettid(), sd->runtime_us, sd->deadline_us);
+	      gettid(), sd->runtime_us, sd->deadline_us);
 
 	pthread_barrier_wait(&barrier);
 
 	ret = sched_setattr(0, &attr, 0);
 	if (ret < 0) {
-		fprintf(stderr, "[%ld]", tid);
-		perror("sched_setattr");
-		fail = 1;
+		err_msg_n(errno, "[%ld]", tid);
+		shutdown = 1;
 		pthread_barrier_wait(&barrier);
 		pthread_exit("Failed sched_setattr");
 		return NULL;
@@ -774,9 +758,6 @@ void *run_deadline(void *data)
 
 	pthread_barrier_wait(&barrier);
 
-	if (fail)
-		return NULL;
-
 	sched_yield();
 	period = get_time_us();
 
@@ -786,7 +767,7 @@ void *run_deadline(void *data)
 	}
 	ret = sched_getattr(0, &attr, sizeof(attr), 0);
 	if (ret < 0) {
-		perror("sched_getattr");
+		err_msg_n(errno, "sched_getattr");
 		pthread_exit("Failed second sched_getattr");
 	}
 
@@ -1015,10 +996,8 @@ int main(int argc, char **argv)
 	int c;
 
 	cpu_count = sysconf(_SC_NPROCESSORS_CONF);
-	if (cpu_count < 1) {
-		fprintf(stderr, "Can not calculate number of CPUS\n");
-		exit(-1);
-	}
+	if (cpu_count < 1)
+		err_quit("Can not calculate number of CPUS\n");
 
 	for (;;) {
 		static struct option options[] = {
@@ -1069,10 +1048,8 @@ int main(int argc, char **argv)
 
 	if (setcpu) {
 		nr_cpus = calc_nr_cpus(setcpu, &setcpu_buf);
-		if (nr_cpus < 0 || nr_cpus > cpu_count) {
-			fprintf(stderr, "Invalid cpu input '%s'\n", setcpu);
-			exit(-1);
-		}
+		if (nr_cpus < 0 || nr_cpus > cpu_count)
+			fatal("Invalid cpu input '%s'\n", setcpu);
 	} else
 		nr_cpus = cpu_count;
 
@@ -1084,10 +1061,8 @@ int main(int argc, char **argv)
 	/* Default cpu to use is the last one */
 	if (!all_cpus && !setcpu) {
 		setcpu_buf = malloc(10);
-		if (!setcpu_buf) {
-			perror("malloc");
-			exit(-1);
-		}
+		if (!setcpu_buf)
+			fatal("malloc");
 		sprintf(setcpu_buf, "%d", cpu_count - 1);
 	}
 
@@ -1097,16 +1072,14 @@ int main(int argc, char **argv)
 		make_other_cpu_list(setcpu, &allcpu_buf);
 
 	if (mlockall(MCL_CURRENT|MCL_FUTURE) == -1)
-		perror("mlockall");
+		warn("mlockall");
 
 	setup_ftrace_marker();
 
 	thread = calloc(nr_threads, sizeof(*thread));
 	sched_data = calloc(nr_threads, sizeof(*sched_data));
-	if (!thread || !sched_data) {
-		perror("allocating threads");
-		exit(-1);
-	}
+	if (!thread || !sched_data)
+		fatal("allocating threads");
 
 	if (nr_threads > nr_cpus) {
 		/*
@@ -1130,11 +1103,9 @@ int main(int argc, char **argv)
 			 * If the runtime is less than 2ms, then we better
 			 * have HRTICK enabled.
 			 */
-			if (!setup_hr_tick()) {
-				fprintf(stderr, "For less than 2ms run times, you need to\n"
-					"have HRTICK enabled in debugfs/sched_features\n");
-				exit(-1);
-			}
+			if (!setup_hr_tick())
+				fatal("For less than 2ms run times, you need to\n"
+				      "have HRTICK enabled in debugfs/sched_features\n");
 		}
 		sd->runtime_us = runtime;
 		sd->deadline_us = interval;
@@ -1145,11 +1116,9 @@ int main(int argc, char **argv)
 		start_period = get_time_us();
 		do_runtime(gettid(), sd, start_period);
 		end_period = get_time_us();
-		if (end_period - start_period > sd->runtime_us) {
-			fprintf(stderr, "Failed to perform task within runtime: Missed by %lld us\n",
-				end_period - start_period - sd->runtime_us);
-			exit(-1);
-		}
+		if (end_period - start_period > sd->runtime_us)
+			fatal("Failed to perform task within runtime: Missed by %lld us\n",
+			      end_period - start_period - sd->runtime_us);
 
 		printf("  Tested at %lldus of %lldus\n",
 		       end_period - start_period, sd->runtime_us);
@@ -1169,42 +1138,29 @@ int main(int argc, char **argv)
 
 	pthread_barrier_wait(&barrier);
 
-	if (fail) {
-		printf("fail 1\n");
-		exit(-1);
-	}
+	if (shutdown)
+		fatal("failed to setup child threads at step 1\n");
 
 	if (!all_cpus) {
 		int *pids;
 
-		res = make_cpuset(CPUSET_ALL, allcpu_buf, "0",
+		make_cpuset(CPUSET_ALL, allcpu_buf, "0",
 				  CPUSET_FL_SET_LOADBALANCE |
 				  CPUSET_FL_CLONE_CHILDREN |
 				  CPUSET_FL_ALL_TASKS);
-		if (res) {
-			perror(res);
-			exit(-1);
-		}
 
 		pids = calloc(nr_threads + 1, sizeof(int));
-		if (!pids) {
-			perror("Allocating pids");
-			exit(-1);
-		}
+		if (!pids)
+			fatal("Allocating pids");
 
 		for (i = 0; i < nr_threads; i++)
 			pids[i] = sched_data[i].stat.tid;
 
-		res = make_cpuset(CPUSET_LOCAL, setcpu, "0",
+		make_cpuset(CPUSET_LOCAL, setcpu, "0",
 				  CPUSET_FL_CPU_EXCLUSIVE |
 				  CPUSET_FL_SET_LOADBALANCE |
 				  CPUSET_FL_CLONE_CHILDREN |
 				  CPUSET_FL_TASKS, pids);
-		free(pids);
-		if (res) {
-			perror(res);
-			exit(-1);
-		}
 
 		system("cat /sys/fs/cgroup/cpuset/my_cpuset/tasks");
 	}
@@ -1213,10 +1169,8 @@ int main(int argc, char **argv)
 
 	pthread_barrier_wait(&barrier);
 
-	if (fail) {
-		printf("fail 2\n");
-		exit(-1);
-	}
+	if (shutdown)
+		fatal("failed to setup child threads at step 2");
 
 	pthread_barrier_wait(&barrier);
 
@@ -1227,8 +1181,7 @@ int main(int argc, char **argv)
 	if (duration)
 		alarm(duration);
 
-	if (!fail)
-		loop(sched_data, nr_threads);
+	loop(sched_data, nr_threads);
 
 	for (i = 0; i < nr_threads; i++) {
 
@@ -1236,7 +1189,7 @@ int main(int argc, char **argv)
 
 		res = join_thread(&thread[i]);
 		if (res) {
-			printf("Thread %d failed: %s\n", i, res);
+			warn("Thread %d failed: %s\n", i, res);
 			continue;
 		}
 	}
Signature · 1 line
2.29.2
#7 lore raw

Re: [rt-tests v1 02/12] cyclicdeadline: Use common error handlers

Quoted 456 lines · Daniel Wagner

Use the common error handlers. This will make the fatal, error and debug output consistent with the output from cyclictest. The current normal output is not changed.

While at it drop the 'fail' flag and use 'shutdown' flag which does the same thing.

---
 src/sched_deadline/cyclicdeadline.c | 165 ++++++++++------------------
 1 file changed, 59 insertions(+), 106 deletions(-)
src/sched_deadline/cyclicdeadline.c +59 -106
index e0db9669f676..7adc91465f44 100644
@@ -32,6 +32,7 @@
 
 #include <rt-utils.h>
 #include <rt-sched.h>
+#include <error.h>
 
 #define _STR(x) #x
 #define STR(x) _STR(x)
@@ -165,10 +166,8 @@ static int my_vsprintf(char *buf, int size, const char *fmt, va_list ap)
 			p++;
 			switch (*p) {
 			case 's':
-				if (l) {
-					fprintf(stderr, "Illegal print format l used with %%s\n");
-					exit(-1);
-				}
+				if (l)
+					fatal("Illegal print format l used with %%s\n");
 				str = va_arg(ap, char *);
 				l = strlen(str);
 				strncpy(s, str, end - s);
@@ -184,10 +183,9 @@ static int my_vsprintf(char *buf, int size, const char *fmt, va_list ap)
 				}
 				if (l == 2)
 					lng = va_arg(ap, long long);
-				else if (l > 2) {
-					fprintf(stderr, "Illegal print format l=%d\n", l);
-					exit(-1);
-				} else
+				else if (l > 2)
+					fatal("Illegal print format l=%d\n", l);
+				else
 					lng = va_arg(ap, int);
 				i = 0;
 				while (lng > 0) {
@@ -204,8 +202,7 @@ static int my_vsprintf(char *buf, int size, const char *fmt, va_list ap)
 				}
 				break;
 			default:
-				fprintf(stderr, "Illegal print format '%c'\n", *p);
-				exit(-1);
+				fatal("Illegal print format '%c'\n", *p);
 			}
 			continue;
 		}
@@ -397,8 +394,8 @@ enum {
 	CPUSET_FL_CLONE_CHILDREN	= (1 << 6),
 };
 
-static const char *make_cpuset(const char *name, const char *cpus,
-			       const char *mems, unsigned flags, ...)
+static void make_cpuset(const char *name, const char *cpus,
+		        const char *mems, unsigned flags, ...)
 {
 	struct stat st;
 	char path[MAXPATH];
@@ -413,64 +410,64 @@ static const char *make_cpuset(const char *name, const char *cpus,
 
 	ret = mount_cpuset();
 	if (ret < 0)
-		return "mount_cpuset";
+		fatal("mount_cpuset");
 
 	ret = stat(path, &st);
 	if (ret < 0) {
 		ret = mkdir(path, 0755);
 		if (ret < 0)
-			return "mkdir";
+			fatal("mkdir");
 	}
 
 	fd = open_cpuset(path, "cpuset.cpus");
 	if (fd < 0)
-		return "cset";
+		fatal("cset");
 	ret = write(fd, cpus, strlen(cpus));
 	close(fd);
 	if (ret < 0)
-		return "write cpus";
+		fatal("write cpus");
 
 	if (mems) {
 		fd = open_cpuset(path, "cpuset.mems");
 		if (fd < 0)
-			return "open mems";
+			fatal("open mems");
 		ret = write(fd, mems, strlen(mems));
 		close(fd);
 		if (ret < 0)
-			return "write mems";
+			fatal("write mems");
 	}
 
 	if (flags & CPUSET_FL_CPU_EXCLUSIVE) {
 		fd = open_cpuset(path, "cpuset.cpu_exclusive");
 		if (fd < 0)
-			return "open cpu_exclusive";
+			fatal("open cpu_exclusive");
 		ret = write(fd, "1", 2);
 		close(fd);
 		if (ret < 0)
-			return "write cpu_exclusive";
+			fatal("write cpu_exclusive");
 	}
 
 	if (flags & (CPUSET_FL_CLEAR_LOADBALANCE | CPUSET_FL_SET_LOADBALANCE)) {
 		fd = open_cpuset(path, "cpuset.sched_load_balance");
 		if (fd < 0)
-			return "open sched_load_balance";
+			fatal("open sched_load_balance");
 		if (flags & CPUSET_FL_SET_LOADBALANCE)
 			ret = write(fd, "1", 2);
 		else
 			ret = write(fd, "0", 2);
 		close(fd);
 		if (ret < 0)
-			return "write sched_load_balance";
+			fatal("write sched_load_balance");
 	}
 
 	if (flags & CPUSET_FL_CLONE_CHILDREN) {
 		fd = open_cpuset(path, "cgroup.clone_children");
 		if (fd < 0)
-			return "open clone_children";
+			fatal("open clone_children");
 		ret = write(fd, "1", 2);
 		close(fd);
 		if (ret < 0)
-			return "write clone_children";
+			fatal("write clone_children");
 	}
 
 
@@ -482,7 +479,7 @@ static const char *make_cpuset(const char *name, const char *cpus,
 
 		fd = open_cpuset(path, "tasks");
 		if (fd < 0)
-			return "open tasks";
+			fatal("open tasks");
 
 		ret = 0;
 		pids = va_arg(ap, int *);
@@ -492,10 +489,8 @@ static const char *make_cpuset(const char *name, const char *cpus,
 		}
 		va_end(ap);
 		close(fd);
-		if (ret < 0) {
-			fprintf(stderr, "Failed on task %d\n", pids[i]);
-			return "write tasks";
-		}
+		if (ret < 0)
+			fatal("Failed on task %d\n", pids[i]);
 	}
 
 	if (flags & CPUSET_FL_ALL_TASKS) {
@@ -507,7 +502,7 @@ static const char *make_cpuset(const char *name, const char *cpus,
 		snprintf(path, MAXPATH - 1, "%s/tasks", CPUSET_PATH);
 		if ((fp = fopen(path, "r")) == NULL) {
 			close(fd);
-			return "opening cpuset tasks";
+			fatal("opening cpuset tasks");
 		}
 
 		while (fscanf(fp, "%d", &pid) == 1) {
@@ -521,14 +516,12 @@ static const char *make_cpuset(const char *name, const char *cpus,
 			if (ret < 0 && errno == ENOSPC) {
 				fclose(fp);
 				close(fd);
-				return "Can not move tasks";
+				fatal("Can not move tasks");
 			}
 		}
 		fclose(fp);
 		close(fd);
 	}
-
-	return NULL;
 }
 
 static void destroy_cpuset(const char *name, int print)
@@ -580,16 +573,14 @@ static void destroy_cpuset(const char *name, int print)
 	snprintf(path, MAXPATH - 1, "%s/%s", CPUSET_PATH, name);
 	path[MAXPATH - 1] = 0;
 
-//	return;
 	sleep(1);
 	ret = rmdir(path);
 	if (ret < 0) {
 		if (retry++ < 5)
 			goto again;
-		fprintf(stderr, "Failed to remove %s\n", path);
-		perror("rmdir");
+		err_msg_n(errno, "Failed to remove %s\n", path);
 		if (retry++ < 5) {
-			fprintf(stderr, "Trying again\n");
+			err_msg("Trying again\n");
 			goto again;
 		}
 	}
@@ -640,8 +631,6 @@ static void usage(int error)
 	exit(error);
 }
 
-static int fail;
-
 static u64 get_time_us(void)
 {
 	struct timespec ts;
@@ -740,9 +729,8 @@ void *run_deadline(void *data)
 
 	ret = sched_getattr(0, &attr, sizeof(attr), 0);
 	if (ret < 0) {
-		fprintf(stderr, "[%ld]", tid);
-		perror("sched_getattr");
-		fail = 1;
+		err_msg_n(errno, "[%ld]", tid);
+		shutdown = 1;
 		pthread_barrier_wait(&barrier);
 		pthread_exit("Failed sched_getattr");
 		return NULL;
@@ -750,23 +738,19 @@ void *run_deadline(void *data)
 
 	pthread_barrier_wait(&barrier);
 
-	if (fail)
-		return NULL;
-
 	attr.sched_policy = SCHED_DEADLINE;
 	attr.sched_runtime = sd->runtime_us * 1000;
 	attr.sched_deadline = sd->deadline_us * 1000;
 
 	printf("thread[%d] runtime=%lldus deadline=%lldus\n",
-	       gettid(), sd->runtime_us, sd->deadline_us);
+	      gettid(), sd->runtime_us, sd->deadline_us);
 
 	pthread_barrier_wait(&barrier);
 
 	ret = sched_setattr(0, &attr, 0);
 	if (ret < 0) {
-		fprintf(stderr, "[%ld]", tid);
-		perror("sched_setattr");
-		fail = 1;
+		err_msg_n(errno, "[%ld]", tid);
+		shutdown = 1;
 		pthread_barrier_wait(&barrier);
 		pthread_exit("Failed sched_setattr");
 		return NULL;
@@ -774,9 +758,6 @@ void *run_deadline(void *data)
 
 	pthread_barrier_wait(&barrier);
 
-	if (fail)
-		return NULL;
-
 	sched_yield();
 	period = get_time_us();
 
@@ -786,7 +767,7 @@ void *run_deadline(void *data)
 	}
 	ret = sched_getattr(0, &attr, sizeof(attr), 0);
 	if (ret < 0) {
-		perror("sched_getattr");
+		err_msg_n(errno, "sched_getattr");
 		pthread_exit("Failed second sched_getattr");
 	}
 
@@ -1015,10 +996,8 @@ int main(int argc, char **argv)
 	int c;
 
 	cpu_count = sysconf(_SC_NPROCESSORS_CONF);
-	if (cpu_count < 1) {
-		fprintf(stderr, "Can not calculate number of CPUS\n");
-		exit(-1);
-	}
+	if (cpu_count < 1)
+		err_quit("Can not calculate number of CPUS\n");
 
 	for (;;) {
 		static struct option options[] = {
@@ -1069,10 +1048,8 @@ int main(int argc, char **argv)
 
 	if (setcpu) {
 		nr_cpus = calc_nr_cpus(setcpu, &setcpu_buf);
-		if (nr_cpus < 0 || nr_cpus > cpu_count) {
-			fprintf(stderr, "Invalid cpu input '%s'\n", setcpu);
-			exit(-1);
-		}
+		if (nr_cpus < 0 || nr_cpus > cpu_count)
+			fatal("Invalid cpu input '%s'\n", setcpu);
 	} else
 		nr_cpus = cpu_count;
 
@@ -1084,10 +1061,8 @@ int main(int argc, char **argv)
 	/* Default cpu to use is the last one */
 	if (!all_cpus && !setcpu) {
 		setcpu_buf = malloc(10);
-		if (!setcpu_buf) {
-			perror("malloc");
-			exit(-1);
-		}
+		if (!setcpu_buf)
+			fatal("malloc");
 		sprintf(setcpu_buf, "%d", cpu_count - 1);
 	}
 
@@ -1097,16 +1072,14 @@ int main(int argc, char **argv)
 		make_other_cpu_list(setcpu, &allcpu_buf);
 
 	if (mlockall(MCL_CURRENT|MCL_FUTURE) == -1)
-		perror("mlockall");
+		warn("mlockall");
 
 	setup_ftrace_marker();
 
 	thread = calloc(nr_threads, sizeof(*thread));
 	sched_data = calloc(nr_threads, sizeof(*sched_data));
-	if (!thread || !sched_data) {
-		perror("allocating threads");
-		exit(-1);
-	}
+	if (!thread || !sched_data)
+		fatal("allocating threads");
 
 	if (nr_threads > nr_cpus) {
 		/*
@@ -1130,11 +1103,9 @@ int main(int argc, char **argv)
 			 * If the runtime is less than 2ms, then we better
 			 * have HRTICK enabled.
 			 */
-			if (!setup_hr_tick()) {
-				fprintf(stderr, "For less than 2ms run times, you need to\n"
-					"have HRTICK enabled in debugfs/sched_features\n");
-				exit(-1);
-			}
+			if (!setup_hr_tick())
+				fatal("For less than 2ms run times, you need to\n"
+				      "have HRTICK enabled in debugfs/sched_features\n");
 		}
 		sd->runtime_us = runtime;
 		sd->deadline_us = interval;
@@ -1145,11 +1116,9 @@ int main(int argc, char **argv)
 		start_period = get_time_us();
 		do_runtime(gettid(), sd, start_period);
 		end_period = get_time_us();
-		if (end_period - start_period > sd->runtime_us) {
-			fprintf(stderr, "Failed to perform task within runtime: Missed by %lld us\n",
-				end_period - start_period - sd->runtime_us);
-			exit(-1);
-		}
+		if (end_period - start_period > sd->runtime_us)
+			fatal("Failed to perform task within runtime: Missed by %lld us\n",
+			      end_period - start_period - sd->runtime_us);
 
 		printf("  Tested at %lldus of %lldus\n",
 		       end_period - start_period, sd->runtime_us);
@@ -1169,42 +1138,29 @@ int main(int argc, char **argv)
 
 	pthread_barrier_wait(&barrier);
 
-	if (fail) {
-		printf("fail 1\n");
-		exit(-1);
-	}
+	if (shutdown)
+		fatal("failed to setup child threads at step 1\n");
 
 	if (!all_cpus) {
 		int *pids;
 
-		res = make_cpuset(CPUSET_ALL, allcpu_buf, "0",
+		make_cpuset(CPUSET_ALL, allcpu_buf, "0",
 				  CPUSET_FL_SET_LOADBALANCE |
 				  CPUSET_FL_CLONE_CHILDREN |
 				  CPUSET_FL_ALL_TASKS);
-		if (res) {
-			perror(res);
-			exit(-1);
-		}
 
 		pids = calloc(nr_threads + 1, sizeof(int));
-		if (!pids) {
-			perror("Allocating pids");
-			exit(-1);
-		}
+		if (!pids)
+			fatal("Allocating pids");
 
 		for (i = 0; i < nr_threads; i++)
 			pids[i] = sched_data[i].stat.tid;
 
-		res = make_cpuset(CPUSET_LOCAL, setcpu, "0",
+		make_cpuset(CPUSET_LOCAL, setcpu, "0",
 				  CPUSET_FL_CPU_EXCLUSIVE |
 				  CPUSET_FL_SET_LOADBALANCE |
 				  CPUSET_FL_CLONE_CHILDREN |
 				  CPUSET_FL_TASKS, pids);
-		free(pids);
-		if (res) {
-			perror(res);
-			exit(-1);
-		}
 
 		system("cat /sys/fs/cgroup/cpuset/my_cpuset/tasks");
 	}
@@ -1213,10 +1169,8 @@ int main(int argc, char **argv)
 
 	pthread_barrier_wait(&barrier);
 
-	if (fail) {
-		printf("fail 2\n");
-		exit(-1);
-	}
+	if (shutdown)
+		fatal("failed to setup child threads at step 2");
 
 	pthread_barrier_wait(&barrier);
 
@@ -1227,8 +1181,7 @@ int main(int argc, char **argv)
 	if (duration)
 		alarm(duration);
 
-	if (!fail)
-		loop(sched_data, nr_threads);
+	loop(sched_data, nr_threads);
 
 	for (i = 0; i < nr_threads; i++) {
 
@@ -1236,7 +1189,7 @@ int main(int argc, char **argv)
 
 		res = join_thread(&thread[i]);
 		if (res) {
-			printf("Thread %d failed: %s\n", i, res);
+			warn("Thread %d failed: %s\n", i, res);
 			continue;
 		}
 	}
Signature · 1 line
2.29.2

- Fixed indentation to use tabs instead of spaces for the line after make_cpuset()
- Fixed bare unsigned flags to unsigned int flags

#8 lore raw

PATCH 3/12 cyclicdeadline: Add quiet command line option

In reply to Daniel Wagner

The quiet option is useful for automated test setups where only the final result of the run is interesting. This avoids to fill up the logs.

---
 src/sched_deadline/cyclicdeadline.8 |  6 +++++-
 src/sched_deadline/cyclicdeadline.c | 22 +++++++++++++++++-----
 2 files changed, 22 insertions(+), 6 deletions(-)
src/sched_deadline/cyclicdeadline.8 +5 -1
index def42f77044a..59b60ca7bd31 100644
@@ -17,7 +17,7 @@ cyclicdeadline \- This program is used to test the deadline scheduler (SCHED_DEA
 .PP
 .SH SYNOPSIS
 .B cyclicdeadline
-.RI "[-a [CPUSET]] [-D TIME] [-h]  [-i INTV] [-s STEP] [-t NUM]"
+.RI "[-a [CPUSET]] [-D TIME] [-h]  [-i INTV] [-s STEP] [-t NUM] [-q]"
 .PP
 .SH DESCRIPTION
 .B cyclicdeadline
@@ -43,6 +43,10 @@ The amount to increase the deadline for each task in us. (default 500us)
 .TP
 .B \-t \-\-threads NUM
 The number of threads to run as deadline (default 1)
+.TP
+.B \-q, \-\-quiet
+Print a summary only on exit. Useful for automated tests, where only
+the summary output needs to be captured.
 .br
 .SH AUTHOR
 cyclicdeadline was written by Steven Rostedt <[email protected]>
src/sched_deadline/cyclicdeadline.c +17 -5
index 7adc91465f44..40b514c5e7e0 100644
@@ -108,6 +108,8 @@ static int use_nsecs;
 
 static int mark_fd;
 
+static int quiet;
+
 static int find_mount(const char *mount, char *debugfs)
 {
 	char type[100];
@@ -627,6 +629,7 @@ static void usage(int error)
 	       "-s STEP     --step         The amount to increase the deadline for each task in us\n"
 	       "                           (default 500us).\n"
 	       "-t NUM      --threads      The number of threads to run as deadline (default 1).\n"
+	       "-q          --quiet        print a summary only on exit\n"
 	       );
 	exit(error);
 }
@@ -966,13 +969,18 @@ static void loop(struct sched_data *sched_data, int nr_threads)
 
 	while (!shutdown) {
 		for (i = 0; i < nr_threads; i++)
-			print_stat(stdout, &sched_data[i], i, 0, 0);
+			print_stat(stdout, &sched_data[i], i, 0, quiet);
 		usleep(10000);
-		printf("\033[%dA", nr_threads);
+		if (!quiet)
+			printf("\033[%dA", nr_threads);
 	}
 	usleep(10000);
-	for (i = 0; i < nr_threads; i++)
-		printf("\n");
+	if (!quiet) {
+		printf("\033[%dB", nr_threads + 2);
+	} else {
+		for (i = 0; i < nr_threads; ++i)
+			print_stat(stdout, &sched_data[i], i, 0, 0);
+	}
 }
 
 int main(int argc, char **argv)
@@ -1006,9 +1014,10 @@ int main(int argc, char **argv)
 			{ "help",	no_argument,		NULL,	'h' },
 			{ "interval",	required_argument,	NULL,	'i' },
 			{ "threads",	required_argument,	NULL,	't' },
+			{ "quiet",	no_argument,		NULL,	'q' },
 			{ NULL,		0,			NULL,	0   },
 		};
-		c = getopt_long(argc, argv, "a::c:D:hi:t:", options, NULL);
+		c = getopt_long(argc, argv, "a::c:D:hi:t:q", options, NULL);
 		if (c == -1)
 			break;
 		switch (c) {
@@ -1035,6 +1044,9 @@ int main(int argc, char **argv)
 		case 'D':
 			duration = parse_time_string(optarg);
 			break;
+		case 'q':
+			quiet = 1;
+			break;
 		case 'h':
 			usage(0);
 			break;
Signature · 1 line
2.29.2
#9 lore raw

Re: [rt-tests v1 03/12] cyclicdeadline: Add quiet command line option

Quoted 104 lines · Daniel Wagner

The quiet option is useful for automated test setups where only the final result of the run is interesting. This avoids to fill up the logs.

---
 src/sched_deadline/cyclicdeadline.8 |  6 +++++-
 src/sched_deadline/cyclicdeadline.c | 22 +++++++++++++++++-----
 2 files changed, 22 insertions(+), 6 deletions(-)
src/sched_deadline/cyclicdeadline.8 +5 -1
index def42f77044a..59b60ca7bd31 100644
@@ -17,7 +17,7 @@ cyclicdeadline \- This program is used to test the deadline scheduler (SCHED_DEA
 .PP
 .SH SYNOPSIS
 .B cyclicdeadline
-.RI "[-a [CPUSET]] [-D TIME] [-h]  [-i INTV] [-s STEP] [-t NUM]"
+.RI "[-a [CPUSET]] [-D TIME] [-h]  [-i INTV] [-s STEP] [-t NUM] [-q]"
 .PP
 .SH DESCRIPTION
 .B cyclicdeadline
@@ -43,6 +43,10 @@ The amount to increase the deadline for each task in us. (default 500us)
 .TP
 .B \-t \-\-threads NUM
 The number of threads to run as deadline (default 1)
+.TP
+.B \-q, \-\-quiet
+Print a summary only on exit. Useful for automated tests, where only
+the summary output needs to be captured.
 .br
 .SH AUTHOR
 cyclicdeadline was written by Steven Rostedt <[email protected]>
src/sched_deadline/cyclicdeadline.c +17 -5
index 7adc91465f44..40b514c5e7e0 100644
@@ -108,6 +108,8 @@ static int use_nsecs;
 
 static int mark_fd;
 
+static int quiet;
+
 static int find_mount(const char *mount, char *debugfs)
 {
 	char type[100];
@@ -627,6 +629,7 @@ static void usage(int error)
 	       "-s STEP     --step         The amount to increase the deadline for each task in us\n"
 	       "                           (default 500us).\n"
 	       "-t NUM      --threads      The number of threads to run as deadline (default 1).\n"
+	       "-q          --quiet        print a summary only on exit\n"
 	       );
 	exit(error);
 }
@@ -966,13 +969,18 @@ static void loop(struct sched_data *sched_data, int nr_threads)
 
 	while (!shutdown) {
 		for (i = 0; i < nr_threads; i++)
-			print_stat(stdout, &sched_data[i], i, 0, 0);
+			print_stat(stdout, &sched_data[i], i, 0, quiet);
 		usleep(10000);
-		printf("\033[%dA", nr_threads);
+		if (!quiet)
+			printf("\033[%dA", nr_threads);
 	}
 	usleep(10000);
-	for (i = 0; i < nr_threads; i++)
-		printf("\n");
+	if (!quiet) {
+		printf("\033[%dB", nr_threads + 2);
+	} else {
+		for (i = 0; i < nr_threads; ++i)
+			print_stat(stdout, &sched_data[i], i, 0, 0);
+	}
 }
 
 int main(int argc, char **argv)
@@ -1006,9 +1014,10 @@ int main(int argc, char **argv)
 			{ "help",	no_argument,		NULL,	'h' },
 			{ "interval",	required_argument,	NULL,	'i' },
 			{ "threads",	required_argument,	NULL,	't' },
+			{ "quiet",	no_argument,		NULL,	'q' },
 			{ NULL,		0,			NULL,	0   },
 		};
-		c = getopt_long(argc, argv, "a::c:D:hi:t:", options, NULL);
+		c = getopt_long(argc, argv, "a::c:D:hi:t:q", options, NULL);
 		if (c == -1)
 			break;
 		switch (c) {
@@ -1035,6 +1044,9 @@ int main(int argc, char **argv)
 		case 'D':
 			duration = parse_time_string(optarg);
 			break;
+		case 'q':
+			quiet = 1;
+			break;
 		case 'h':
 			usage(0);
 			break;
Signature · 1 line
2.29.2
#10 lore raw

PATCH 4/12 pmqtest: Move statictic output into print_stat()

In reply to Daniel Wagner

Prepare the code to introduce the quiet command line option by moving the statistic output code into print_stat(). We follow here the pattern from cyclictest.

While at it replace the rather sophisticated error printing code with a fatal(). Just fail if something is not working.

---
 src/pmqtest/pmqtest.c | 64 ++++++++++++++++++-------------------------
 1 file changed, 26 insertions(+), 38 deletions(-)
src/pmqtest/pmqtest.c +26 -38
index a1e487b85d2c..b0a2cbede4a0 100644
@@ -64,7 +64,6 @@ struct params {
 	char recvsyncmsg[MSG_SIZE];
 	char recvtestmsg[MSG_SIZE];
 	struct params *neighbor;
-	char error[MAX_PATH * 2];
 };
 
 void *pmqthread(void *param)
@@ -192,9 +191,7 @@ void *pmqthread(void *param)
 					write(tracing_enabled, "0", 1);
 					close(tracing_enabled);
 				} else
-					snprintf(par->error, sizeof(par->error),
-					    "Could not access %s\n",
-					    tracing_enabled_file);
+					fatal("Could not access %s\n", tracing_enabled_file);
 				par->shutdown = 1;
 				par->neighbor->shutdown = 1;
 			}
@@ -376,6 +373,27 @@ static void sighand(int sig)
 	shutdown = 1;
 }
 
+static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
+		       int verbose, int quiet)
+{
+	int i;
+
+	for (i = 0; i < num_threads; i++) {
+		printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, TO %d, Cycles %d\n",
+			i*2, receiver[i].tid, receiver[i].priority, receiver[i].cpu,
+			receiver[i].delay.tv_nsec / 1000,
+			i*2+1, sender[i].tid, sender[i].priority, sender[i].cpu,
+			receiver[i].timeoutcount, sender[i].samples);
+	}
+	for (i = 0; i < num_threads; i++) {
+		printf("#%d -> #%d, Min %4d, Cur %4d, Avg %4d, Max %4d\n",
+			i*2+1, i*2,
+			receiver[i].mindiff, (int) receiver[i].diff.tv_usec,
+			(int) ((receiver[i].sumdiff / receiver[i].samples) + 0.5),
+			receiver[i].maxdiff);
+	}
+}
+
 int main(int argc, char *argv[])
 {
 	int i;
@@ -385,8 +403,6 @@ int main(int argc, char *argv[])
 	sigset_t sigset;
 	int oldsamples = INT_MAX;
 	int oldtimeoutcount = INT_MAX;
-	int first = 1;
-	int errorlines = 0;
 	struct timespec maindelay;
 	int oflag = O_CREAT|O_RDWR;
 	struct mq_attr mqstat;
@@ -489,38 +505,8 @@ int main(int argc, char *argv[])
 
 		if (minsamples > 1 && (shutdown || newsamples > oldsamples ||
 			newtimeoutcount > oldtimeoutcount)) {
-
-			if (!first)
-				printf("\033[%dA", num_threads*2 + errorlines);
-			first = 0;
-
-			for (i = 0; i < num_threads; i++) {
-				printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, TO %d, Cycles %d   \n",
-				    i*2, receiver[i].tid, receiver[i].priority, receiver[i].cpu,
-				    receiver[i].delay.tv_nsec / 1000,
-				    i*2+1, sender[i].tid, sender[i].priority, sender[i].cpu,
-				    receiver[i].timeoutcount, sender[i].samples);
-			}
-			for (i = 0; i < num_threads; i++) {
-				printf("#%d -> #%d, Min %4d, Cur %4d, Avg %4d, Max %4d\n",
-					i*2+1, i*2,
-					receiver[i].mindiff, (int) receiver[i].diff.tv_usec,
-					(int) ((receiver[i].sumdiff / receiver[i].samples) + 0.5),
-					receiver[i].maxdiff);
-				if (receiver[i].error[0] != '\0') {
-					printf("%s", receiver[i].error);
-					errorlines++;
-					receiver[i].error[0] = '\0';
-				}
-				if (sender[i].error[0] != '\0') {
-					printf("%s", sender[i].error);
-					errorlines++;
-					receiver[i].error[0] = '\0';
-				}
-			}
-		} else {
-			if (minsamples < 1)
-				printf("Collecting ...\n\033[1A");
+			print_stat(stdout, receiver, sender, 0, 0);
+			printf("\033[%dA", num_threads*2);
 		}
 
 		fflush(NULL);
@@ -539,6 +525,8 @@ int main(int argc, char *argv[])
 
 	} while (!shutdown);
 
+	printf("\033[%dB", num_threads*2 + 2);
+
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
 		sender[i].shutdown = 1;
Signature · 1 line
2.29.2
#11 lore raw

Re: [rt-tests v1 04/12] pmqtest: Move statictic output into print_stat()

Quoted 126 lines · Daniel Wagner

Prepare the code to introduce the quiet command line option by moving the statistic output code into print_stat(). We follow here the pattern from cyclictest.

While at it replace the rather sophisticated error printing code with a fatal(). Just fail if something is not working.

---
 src/pmqtest/pmqtest.c | 64 ++++++++++++++++++-------------------------
 1 file changed, 26 insertions(+), 38 deletions(-)
src/pmqtest/pmqtest.c +26 -38
index a1e487b85d2c..b0a2cbede4a0 100644
@@ -64,7 +64,6 @@ struct params {
 	char recvsyncmsg[MSG_SIZE];
 	char recvtestmsg[MSG_SIZE];
 	struct params *neighbor;
-	char error[MAX_PATH * 2];
 };
 
 void *pmqthread(void *param)
@@ -192,9 +191,7 @@ void *pmqthread(void *param)
 					write(tracing_enabled, "0", 1);
 					close(tracing_enabled);
 				} else
-					snprintf(par->error, sizeof(par->error),
-					    "Could not access %s\n",
-					    tracing_enabled_file);
+					fatal("Could not access %s\n", tracing_enabled_file);
 				par->shutdown = 1;
 				par->neighbor->shutdown = 1;
 			}
@@ -376,6 +373,27 @@ static void sighand(int sig)
 	shutdown = 1;
 }
 
+static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
+		       int verbose, int quiet)
+{
+	int i;
+
+	for (i = 0; i < num_threads; i++) {
+		printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, TO %d, Cycles %d\n",
+			i*2, receiver[i].tid, receiver[i].priority, receiver[i].cpu,
+			receiver[i].delay.tv_nsec / 1000,
+			i*2+1, sender[i].tid, sender[i].priority, sender[i].cpu,
+			receiver[i].timeoutcount, sender[i].samples);
+	}
+	for (i = 0; i < num_threads; i++) {
+		printf("#%d -> #%d, Min %4d, Cur %4d, Avg %4d, Max %4d\n",
+			i*2+1, i*2,
+			receiver[i].mindiff, (int) receiver[i].diff.tv_usec,
+			(int) ((receiver[i].sumdiff / receiver[i].samples) + 0.5),
+			receiver[i].maxdiff);
+	}
+}
+
 int main(int argc, char *argv[])
 {
 	int i;
@@ -385,8 +403,6 @@ int main(int argc, char *argv[])
 	sigset_t sigset;
 	int oldsamples = INT_MAX;
 	int oldtimeoutcount = INT_MAX;
-	int first = 1;
-	int errorlines = 0;
 	struct timespec maindelay;
 	int oflag = O_CREAT|O_RDWR;
 	struct mq_attr mqstat;
@@ -489,38 +505,8 @@ int main(int argc, char *argv[])
 
 		if (minsamples > 1 && (shutdown || newsamples > oldsamples ||
 			newtimeoutcount > oldtimeoutcount)) {
-
-			if (!first)
-				printf("\033[%dA", num_threads*2 + errorlines);
-			first = 0;
-
-			for (i = 0; i < num_threads; i++) {
-				printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, TO %d, Cycles %d   \n",
-				    i*2, receiver[i].tid, receiver[i].priority, receiver[i].cpu,
-				    receiver[i].delay.tv_nsec / 1000,
-				    i*2+1, sender[i].tid, sender[i].priority, sender[i].cpu,
-				    receiver[i].timeoutcount, sender[i].samples);
-			}
-			for (i = 0; i < num_threads; i++) {
-				printf("#%d -> #%d, Min %4d, Cur %4d, Avg %4d, Max %4d\n",
-					i*2+1, i*2,
-					receiver[i].mindiff, (int) receiver[i].diff.tv_usec,
-					(int) ((receiver[i].sumdiff / receiver[i].samples) + 0.5),
-					receiver[i].maxdiff);
-				if (receiver[i].error[0] != '\0') {
-					printf("%s", receiver[i].error);
-					errorlines++;
-					receiver[i].error[0] = '\0';
-				}
-				if (sender[i].error[0] != '\0') {
-					printf("%s", sender[i].error);
-					errorlines++;
-					receiver[i].error[0] = '\0';
-				}
-			}
-		} else {
-			if (minsamples < 1)
-				printf("Collecting ...\n\033[1A");
+			print_stat(stdout, receiver, sender, 0, 0);
+			printf("\033[%dA", num_threads*2);
 		}
 
 		fflush(NULL);
@@ -539,6 +525,8 @@ int main(int argc, char *argv[])
 
 	} while (!shutdown);
 
+	printf("\033[%dB", num_threads*2 + 2);
+
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
 		sender[i].shutdown = 1;
Signature · 1 line
2.29.2
#12 lore raw

PATCH 5/12 pmqtest: Add quiet command line option

In reply to Daniel Wagner

The quiet option is useful for automated test setups where only the final result of the run is interesting. This avoids to fill up the logs.

---
 src/pmqtest/pmqtest.8 |  5 ++++-
 src/pmqtest/pmqtest.c | 19 +++++++++++++++----
 2 files changed, 19 insertions(+), 5 deletions(-)
src/pmqtest/pmqtest.8 +4 -1
index e44411ce0ef3..36678d0c5026 100644
@@ -4,7 +4,7 @@
 \fBpmqtest\fR \- Start pairs of threads and measure the latency of interprocess communication with POSIX messages queues
 .SH "SYNTAX"
 .LP
-pmqtest [-a|-a PROC] [-b USEC] [-d DIST] [-D TIME] [-f TO] [-h] [-i INTV] [-l LOOPS] [-p PRIO] [-S] [-t|-t NUM]
+pmqtest [-a|-a PROC] [-b USEC] [-d DIST] [-D TIME] [-f TO] [-h] [-i INTV] [-l LOOPS] [-p PRIO] [-q] [-S] [-t|-t NUM]
 .br
 .SH "DESCRIPTION"
 .LP
@@ -41,6 +41,9 @@ Set the number of loops. The default is 0 (endless). This option is useful for a
 .B \-p, \-\-prio=PRIO
 Set the priority of the process.
 .TP
+.B \-q, \-\-quiet
+Print a summary only on exit. Useful for automated tests, where only the summary output needs to be captured.
+.TP
 .B \-S, \-\-smp
 Test mode for symmetric multi-processing, implies -a and -t and uses the same priority on all threads.
 .TP
src/pmqtest/pmqtest.c +15 -4
index b0a2cbede4a0..5f7a24d55db6 100644
@@ -232,6 +232,7 @@ static void display_help(int error)
 	       "-i INTV  --interval=INTV   base interval of thread in us default=1000\n"
 	       "-l LOOPS --loops=LOOPS     number of loops: default=0(endless)\n"
 	       "-p PRIO  --prio=PRIO       priority\n"
+	       "-q       --quiet           print a summary only on exit\n"
 	       "-S       --smp             SMP testing: options -a -t and same priority\n"
 	       "                           of all threads\n"
 	       "-t       --threads         one thread per available processor\n"
@@ -256,6 +257,7 @@ static int smp;
 static int sameprio;
 static int timeout;
 static int forcetimeout;
+static int quiet;
 
 static void process_options(int argc, char *argv[])
 {
@@ -275,12 +277,13 @@ static void process_options(int argc, char *argv[])
 			{"interval",		required_argument,	NULL, 'i'},
 			{"loops",		required_argument,	NULL, 'l'},
 			{"priority",		required_argument,	NULL, 'p'},
+			{"quiet",		no_argument,		NULL, 'q'},
 			{"smp",			no_argument,		NULL, 'S'},
 			{"threads",		optional_argument,	NULL, 't'},
 			{"timeout",		required_argument,	NULL, 'T'},
 			{NULL, 0, NULL, 0}
 		};
-		int c = getopt_long (argc, argv, "a::b:d:D:f:i:l:p:St::T:",
+		int c = getopt_long (argc, argv, "a::b:d:D:f:i:l:p:qSt::T:",
 			long_options, &option_index);
 		if (c == -1)
 			break;
@@ -309,6 +312,7 @@ static void process_options(int argc, char *argv[])
 		case 'i': interval = atoi(optarg); break;
 		case 'l': max_cycles = atoi(optarg); break;
 		case 'p': priority = atoi(optarg); break;
+		case 'q': quiet = 1; break;
 		case 'S':
 			smp = 1;
 			num_threads = max_cpus;
@@ -378,6 +382,9 @@ static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
 {
 	int i;
 
+	if (quiet)
+		return;
+
 	for (i = 0; i < num_threads; i++) {
 		printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, TO %d, Cycles %d\n",
 			i*2, receiver[i].tid, receiver[i].priority, receiver[i].cpu,
@@ -505,8 +512,9 @@ int main(int argc, char *argv[])
 
 		if (minsamples > 1 && (shutdown || newsamples > oldsamples ||
 			newtimeoutcount > oldtimeoutcount)) {
-			print_stat(stdout, receiver, sender, 0, 0);
-			printf("\033[%dA", num_threads*2);
+			print_stat(stdout, receiver, sender, 0, quiet);
+			if (!quiet)
+				printf("\033[%dA", num_threads*2);
 		}
 
 		fflush(NULL);
@@ -525,7 +533,10 @@ int main(int argc, char *argv[])
 
 	} while (!shutdown);
 
-	printf("\033[%dB", num_threads*2 + 2);
+	if (!quiet)
+		printf("\033[%dB", num_threads*2 + 2);
+	else
+		print_stat(stdout, receiver, sender, 0, 0);
 
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
Signature · 1 line
2.29.2
#13 lore raw

Re: [rt-tests v1 05/12] pmqtest: Add quiet command line option

Quoted 114 lines · Daniel Wagner

The quiet option is useful for automated test setups where only the final result of the run is interesting. This avoids to fill up the logs.

---
 src/pmqtest/pmqtest.8 |  5 ++++-
 src/pmqtest/pmqtest.c | 19 +++++++++++++++----
 2 files changed, 19 insertions(+), 5 deletions(-)
src/pmqtest/pmqtest.8 +4 -1
index e44411ce0ef3..36678d0c5026 100644
@@ -4,7 +4,7 @@
 \fBpmqtest\fR \- Start pairs of threads and measure the latency of interprocess communication with POSIX messages queues
 .SH "SYNTAX"
 .LP
-pmqtest [-a|-a PROC] [-b USEC] [-d DIST] [-D TIME] [-f TO] [-h] [-i INTV] [-l LOOPS] [-p PRIO] [-S] [-t|-t NUM]
+pmqtest [-a|-a PROC] [-b USEC] [-d DIST] [-D TIME] [-f TO] [-h] [-i INTV] [-l LOOPS] [-p PRIO] [-q] [-S] [-t|-t NUM]
 .br
 .SH "DESCRIPTION"
 .LP
@@ -41,6 +41,9 @@ Set the number of loops. The default is 0 (endless). This option is useful for a
 .B \-p, \-\-prio=PRIO
 Set the priority of the process.
 .TP
+.B \-q, \-\-quiet
+Print a summary only on exit. Useful for automated tests, where only the summary output needs to be captured.
+.TP
 .B \-S, \-\-smp
 Test mode for symmetric multi-processing, implies -a and -t and uses the same priority on all threads.
 .TP
src/pmqtest/pmqtest.c +15 -4
index b0a2cbede4a0..5f7a24d55db6 100644
@@ -232,6 +232,7 @@ static void display_help(int error)
 	       "-i INTV  --interval=INTV   base interval of thread in us default=1000\n"
 	       "-l LOOPS --loops=LOOPS     number of loops: default=0(endless)\n"
 	       "-p PRIO  --prio=PRIO       priority\n"
+	       "-q       --quiet           print a summary only on exit\n"
 	       "-S       --smp             SMP testing: options -a -t and same priority\n"
 	       "                           of all threads\n"
 	       "-t       --threads         one thread per available processor\n"
@@ -256,6 +257,7 @@ static int smp;
 static int sameprio;
 static int timeout;
 static int forcetimeout;
+static int quiet;
 
 static void process_options(int argc, char *argv[])
 {
@@ -275,12 +277,13 @@ static void process_options(int argc, char *argv[])
 			{"interval",		required_argument,	NULL, 'i'},
 			{"loops",		required_argument,	NULL, 'l'},
 			{"priority",		required_argument,	NULL, 'p'},
+			{"quiet",		no_argument,		NULL, 'q'},
 			{"smp",			no_argument,		NULL, 'S'},
 			{"threads",		optional_argument,	NULL, 't'},
 			{"timeout",		required_argument,	NULL, 'T'},
 			{NULL, 0, NULL, 0}
 		};
-		int c = getopt_long (argc, argv, "a::b:d:D:f:i:l:p:St::T:",
+		int c = getopt_long (argc, argv, "a::b:d:D:f:i:l:p:qSt::T:",
 			long_options, &option_index);
 		if (c == -1)
 			break;
@@ -309,6 +312,7 @@ static void process_options(int argc, char *argv[])
 		case 'i': interval = atoi(optarg); break;
 		case 'l': max_cycles = atoi(optarg); break;
 		case 'p': priority = atoi(optarg); break;
+		case 'q': quiet = 1; break;
 		case 'S':
 			smp = 1;
 			num_threads = max_cpus;
@@ -378,6 +382,9 @@ static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
 {
 	int i;
 
+	if (quiet)
+		return;
+
 	for (i = 0; i < num_threads; i++) {
 		printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, TO %d, Cycles %d\n",
 			i*2, receiver[i].tid, receiver[i].priority, receiver[i].cpu,
@@ -505,8 +512,9 @@ int main(int argc, char *argv[])
 
 		if (minsamples > 1 && (shutdown || newsamples > oldsamples ||
 			newtimeoutcount > oldtimeoutcount)) {
-			print_stat(stdout, receiver, sender, 0, 0);
-			printf("\033[%dA", num_threads*2);
+			print_stat(stdout, receiver, sender, 0, quiet);
+			if (!quiet)
+				printf("\033[%dA", num_threads*2);
 		}
 
 		fflush(NULL);
@@ -525,7 +533,10 @@ int main(int argc, char *argv[])
 
 	} while (!shutdown);
 
-	printf("\033[%dB", num_threads*2 + 2);
+	if (!quiet)
+		printf("\033[%dB", num_threads*2 + 2);
+	else
+		print_stat(stdout, receiver, sender, 0, 0);
 
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
Signature · 1 line
2.29.2
#14 lore raw

PATCH 6/12 ptsematest: Move statictic output into print_stat()

In reply to Daniel Wagner

Prepare the code to introduce the quiet command line option by moving the statistic output code into print_stat(). We follow here the pattern from cyclictest.

While at it replace the rather sophisticated error printing code with a fatal(). Just fail if something is not working.

---
 src/ptsematest/ptsematest.c | 65 ++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 37 deletions(-)
src/ptsematest/ptsematest.c +28 -37
index 9cd5f34509a8..69b4e1221361 100644
@@ -52,7 +52,6 @@ struct params {
 	struct timeval unblocked, received, diff;
 	pthread_t threadid;
 	struct params *neighbor;
-	char error[MAX_PATH * 2];
 };
 
 void *semathread(void *param)
@@ -121,9 +120,8 @@ void *semathread(void *param)
 					write(tracing_enabled, "0", 1);
 					close(tracing_enabled);
 				} else
-					snprintf(par->error, sizeof(par->error),
-					    "Could not access %s\n",
-					    tracing_enabled_file);
+					fatal("Could not access %s\n",
+					      tracing_enabled_file);
 				par->shutdown = 1;
 				par->neighbor->shutdown = 1;
 			}
@@ -290,6 +288,28 @@ static void sighand(int sig)
 	shutdown = 1;
 }
 
+static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
+		       int verbose, int quiet)
+{
+	int i;
+
+	for (i = 0; i < num_threads; i++) {
+		printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, Cycles %d\n",
+			i*2, receiver[i].tid, receiver[i].priority, receiver[i].cpu,
+			receiver[i].delay.tv_nsec / 1000,
+			i*2+1, sender[i].tid, sender[i].priority, sender[i].cpu,
+			sender[i].samples);
+	}
+	for (i = 0; i < num_threads; i++) {
+		printf("#%d -> #%d, Min %4d, Cur %4d, Avg %4d, Max %4d\n",
+			i*2+1, i*2,
+			receiver[i].mindiff, (int) receiver[i].diff.tv_usec,
+			(int) ((receiver[i].sumdiff / receiver[i].samples) + 0.5),
+			receiver[i].maxdiff);
+	}
+}
+
+
 int main(int argc, char *argv[])
 {
 	int i;
@@ -367,40 +387,13 @@ int main(int argc, char *argv[])
 	maindelay.tv_nsec = 50000000; /* 50 ms */
 
 	while (!shutdown) {
-		int printed;
-		int errorlines = 0;
-
 		for (i = 0; i < num_threads; i++)
 			shutdown |= receiver[i].shutdown | sender[i].shutdown;
 
 		if (receiver[0].samples > oldsamples || shutdown) {
-			for (i = 0; i < num_threads; i++) {
-				printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, Cycles %d\n",
-				    i*2, receiver[i].tid, receiver[i].priority, receiver[i].cpu,
-				    receiver[i].delay.tv_nsec / 1000,
-				    i*2+1, sender[i].tid, sender[i].priority, sender[i].cpu,
-				    sender[i].samples);
-			}
-			for (i = 0; i < num_threads; i++) {
-				printf("#%d -> #%d, Min %4d, Cur %4d, Avg %4d, Max %4d\n",
-					i*2+1, i*2,
-					receiver[i].mindiff, (int) receiver[i].diff.tv_usec,
-					(int) ((receiver[i].sumdiff / receiver[i].samples) + 0.5),
-					receiver[i].maxdiff);
-				if (receiver[i].error[0] != '\0') {
-					printf("%s", receiver[i].error);
-					errorlines++;
-					receiver[i].error[0] = '\0';
-				}
-				if (sender[i].error[0] != '\0') {
-					printf("%s", sender[i].error);
-					errorlines++;
-					receiver[i].error[0] = '\0';
-				}
-			}
-			printed = 1;
-		} else
-			printed = 0;
+			print_stat(stdout, receiver, sender, 0, 0);
+			printf("\033[%dA", num_threads*2);
+		}
 
 		sigemptyset(&sigset);
 		sigaddset(&sigset, SIGTERM);
@@ -411,10 +404,8 @@ int main(int argc, char *argv[])
 
 		sigemptyset(&sigset);
 		pthread_sigmask(SIG_SETMASK, &sigset, NULL);
-
-		if (printed && !shutdown)
-			printf("\033[%dA", num_threads*2 + errorlines);
 	}
+	printf("\033[%dB", num_threads*2 + 2);
 
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
Signature · 1 line
2.29.2
#15 lore raw

Re: [rt-tests v1 06/12] ptsematest: Move statictic output into print_stat()

Quoted 125 lines · Daniel Wagner

Prepare the code to introduce the quiet command line option by moving the statistic output code into print_stat(). We follow here the pattern from cyclictest.

While at it replace the rather sophisticated error printing code with a fatal(). Just fail if something is not working.

---
 src/ptsematest/ptsematest.c | 65 ++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 37 deletions(-)
src/ptsematest/ptsematest.c +28 -37
index 9cd5f34509a8..69b4e1221361 100644
@@ -52,7 +52,6 @@ struct params {
 	struct timeval unblocked, received, diff;
 	pthread_t threadid;
 	struct params *neighbor;
-	char error[MAX_PATH * 2];
 };
 
 void *semathread(void *param)
@@ -121,9 +120,8 @@ void *semathread(void *param)
 					write(tracing_enabled, "0", 1);
 					close(tracing_enabled);
 				} else
-					snprintf(par->error, sizeof(par->error),
-					    "Could not access %s\n",
-					    tracing_enabled_file);
+					fatal("Could not access %s\n",
+					      tracing_enabled_file);
 				par->shutdown = 1;
 				par->neighbor->shutdown = 1;
 			}
@@ -290,6 +288,28 @@ static void sighand(int sig)
 	shutdown = 1;
 }
 
+static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
+		       int verbose, int quiet)
+{
+	int i;
+
+	for (i = 0; i < num_threads; i++) {
+		printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, Cycles %d\n",
+			i*2, receiver[i].tid, receiver[i].priority, receiver[i].cpu,
+			receiver[i].delay.tv_nsec / 1000,
+			i*2+1, sender[i].tid, sender[i].priority, sender[i].cpu,
+			sender[i].samples);
+	}
+	for (i = 0; i < num_threads; i++) {
+		printf("#%d -> #%d, Min %4d, Cur %4d, Avg %4d, Max %4d\n",
+			i*2+1, i*2,
+			receiver[i].mindiff, (int) receiver[i].diff.tv_usec,
+			(int) ((receiver[i].sumdiff / receiver[i].samples) + 0.5),
+			receiver[i].maxdiff);
+	}
+}
+
+
 int main(int argc, char *argv[])
 {
 	int i;
@@ -367,40 +387,13 @@ int main(int argc, char *argv[])
 	maindelay.tv_nsec = 50000000; /* 50 ms */
 
 	while (!shutdown) {
-		int printed;
-		int errorlines = 0;
-
 		for (i = 0; i < num_threads; i++)
 			shutdown |= receiver[i].shutdown | sender[i].shutdown;
 
 		if (receiver[0].samples > oldsamples || shutdown) {
-			for (i = 0; i < num_threads; i++) {
-				printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, Cycles %d\n",
-				    i*2, receiver[i].tid, receiver[i].priority, receiver[i].cpu,
-				    receiver[i].delay.tv_nsec / 1000,
-				    i*2+1, sender[i].tid, sender[i].priority, sender[i].cpu,
-				    sender[i].samples);
-			}
-			for (i = 0; i < num_threads; i++) {
-				printf("#%d -> #%d, Min %4d, Cur %4d, Avg %4d, Max %4d\n",
-					i*2+1, i*2,
-					receiver[i].mindiff, (int) receiver[i].diff.tv_usec,
-					(int) ((receiver[i].sumdiff / receiver[i].samples) + 0.5),
-					receiver[i].maxdiff);
-				if (receiver[i].error[0] != '\0') {
-					printf("%s", receiver[i].error);
-					errorlines++;
-					receiver[i].error[0] = '\0';
-				}
-				if (sender[i].error[0] != '\0') {
-					printf("%s", sender[i].error);
-					errorlines++;
-					receiver[i].error[0] = '\0';
-				}
-			}
-			printed = 1;
-		} else
-			printed = 0;
+			print_stat(stdout, receiver, sender, 0, 0);
+			printf("\033[%dA", num_threads*2);
+		}
 
 		sigemptyset(&sigset);
 		sigaddset(&sigset, SIGTERM);
@@ -411,10 +404,8 @@ int main(int argc, char *argv[])
 
 		sigemptyset(&sigset);
 		pthread_sigmask(SIG_SETMASK, &sigset, NULL);
-
-		if (printed && !shutdown)
-			printf("\033[%dA", num_threads*2 + errorlines);
 	}
+	printf("\033[%dB", num_threads*2 + 2);
 
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
Signature · 1 line
2.29.2
#16 lore raw

PATCH 7/12 ptsematest: Add quiet command line option

In reply to Daniel Wagner

The quiet option is useful for automated test setups where only the final result of the run is interesting. This avoids to fill up the logs.

---
 src/ptsematest/ptsematest.8 |  5 ++++-
 src/ptsematest/ptsematest.c | 20 ++++++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)
src/ptsematest/ptsematest.8 +4 -1
index 05a0cdfd3657..a435e7a6221c 100644
@@ -4,7 +4,7 @@
 \fBptsematest\fR \- Start two threads and measure the latency of interprocess communication with POSIX mutex.
 .SH "SYNOPSIS"
 .LP
-ptsematest [-a|--affinity [PROC]] [-b|--breaktrace USEC] [-d|--distance DIST] [-D|--duration TIME] [-h|--help] [-i|--interval INTV] [-l|--loops LOOPS] [-p|--prio PRIO] [-S|--smp] [-t|--threads [NUM]]
+ptsematest [-a|--affinity [PROC]] [-b|--breaktrace USEC] [-d|--distance DIST] [-D|--duration TIME] [-h|--help] [-i|--interval INTV] [-l|--loops LOOPS] [-p|--prio PRIO] [-q|--quiet] [-S|--smp] [-t|--threads [NUM]]
 .br
 .SH "DESCRIPTION"
 .LP
@@ -38,6 +38,9 @@ Set the number of loops. The default is 0 (endless). This option is useful for a
 .B \-p, \-\-prio=PRIO
 Set the priority of the process.
 .TP
+.B \-q, \-\-quiet
+Print a summary only on exit. Useful for automated tests, where only the summary output needs to be captured.
+.TP
 .B \-S, \-\-smp
 SMP testing: options -a -t and same priority
 .TP
src/ptsematest/ptsematest.c +16 -4
index 69b4e1221361..2e392299fdc4 100644
@@ -156,6 +156,7 @@ static void display_help(int error)
 	       "-i INTV  --interval=INTV   base interval of thread in us default=1000\n"
 	       "-l LOOPS --loops=LOOPS     number of loops: default=0(endless)\n"
 	       "-p PRIO  --prio=PRIO       priority\n"
+	       "-q       --quiet           print a summary only on exit\n"
 	       "-S       --smp             SMP testing: options -a -t and same priority\n"
 	       "                           of all threads\n"
 	       "-t       --threads         one thread per available processor\n"
@@ -178,6 +179,7 @@ static int interval = 1000;
 static int distance = 500;
 static int smp;
 static int sameprio;
+static int quiet;
 
 static void process_options(int argc, char *argv[])
 {
@@ -196,11 +198,12 @@ static void process_options(int argc, char *argv[])
 			{"interval",	required_argument,	NULL, 'i'},
 			{"loops",	required_argument,	NULL, 'l'},
 			{"priority",	required_argument,	NULL, 'p'},
+			{"quiet",	no_argument	,	NULL, 'q'},
 			{"smp",		no_argument,		NULL, 'S'},
 			{"threads",	optional_argument,	NULL, 't'},
 			{NULL, 0, NULL, 0}
 		};
-		int c = getopt_long (argc, argv, "a::b:d:i:l:D:p:St::h",
+		int c = getopt_long (argc, argv, "a::b:d:i:l:D:p:qSt::h",
 			long_options, &option_index);
 		if (c == -1)
 			break;
@@ -228,6 +231,7 @@ static void process_options(int argc, char *argv[])
 		case 'h': display_help(0); break;
 		case 'l': max_cycles = atoi(optarg); break;
 		case 'p': priority = atoi(optarg); break;
+		case 'q': quiet = 1; break;
 		case 'S':
 			smp = 1;
 			num_threads = max_cpus;
@@ -293,6 +297,9 @@ static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
 {
 	int i;
 
+	if (quiet)
+		return;
+
 	for (i = 0; i < num_threads; i++) {
 		printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, Cycles %d\n",
 			i*2, receiver[i].tid, receiver[i].priority, receiver[i].cpu,
@@ -391,8 +398,9 @@ int main(int argc, char *argv[])
 			shutdown |= receiver[i].shutdown | sender[i].shutdown;
 
 		if (receiver[0].samples > oldsamples || shutdown) {
-			print_stat(stdout, receiver, sender, 0, 0);
-			printf("\033[%dA", num_threads*2);
+			print_stat(stdout, receiver, sender, 0, quiet);
+			if (!quiet)
+				printf("\033[%dA", num_threads*2);
 		}
 
 		sigemptyset(&sigset);
@@ -405,7 +413,11 @@ int main(int argc, char *argv[])
 		sigemptyset(&sigset);
 		pthread_sigmask(SIG_SETMASK, &sigset, NULL);
 	}
-	printf("\033[%dB", num_threads*2 + 2);
+
+	if (!quiet)
+		printf("\033[%dB", num_threads*2 + 2);
+	else
+		print_stat(stdout, receiver, sender, 0, 0);
 
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
Signature · 1 line
2.29.2
#17 lore raw

Re: [rt-tests v1 07/12] ptsematest: Add quiet command line option

Quoted 114 lines · Daniel Wagner

The quiet option is useful for automated test setups where only the final result of the run is interesting. This avoids to fill up the logs.

---
 src/ptsematest/ptsematest.8 |  5 ++++-
 src/ptsematest/ptsematest.c | 20 ++++++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)
src/ptsematest/ptsematest.8 +4 -1
index 05a0cdfd3657..a435e7a6221c 100644
@@ -4,7 +4,7 @@
 \fBptsematest\fR \- Start two threads and measure the latency of interprocess communication with POSIX mutex.
 .SH "SYNOPSIS"
 .LP
-ptsematest [-a|--affinity [PROC]] [-b|--breaktrace USEC] [-d|--distance DIST] [-D|--duration TIME] [-h|--help] [-i|--interval INTV] [-l|--loops LOOPS] [-p|--prio PRIO] [-S|--smp] [-t|--threads [NUM]]
+ptsematest [-a|--affinity [PROC]] [-b|--breaktrace USEC] [-d|--distance DIST] [-D|--duration TIME] [-h|--help] [-i|--interval INTV] [-l|--loops LOOPS] [-p|--prio PRIO] [-q|--quiet] [-S|--smp] [-t|--threads [NUM]]
 .br
 .SH "DESCRIPTION"
 .LP
@@ -38,6 +38,9 @@ Set the number of loops. The default is 0 (endless). This option is useful for a
 .B \-p, \-\-prio=PRIO
 Set the priority of the process.
 .TP
+.B \-q, \-\-quiet
+Print a summary only on exit. Useful for automated tests, where only the summary output needs to be captured.
+.TP
 .B \-S, \-\-smp
 SMP testing: options -a -t and same priority
 .TP
src/ptsematest/ptsematest.c +16 -4
index 69b4e1221361..2e392299fdc4 100644
@@ -156,6 +156,7 @@ static void display_help(int error)
 	       "-i INTV  --interval=INTV   base interval of thread in us default=1000\n"
 	       "-l LOOPS --loops=LOOPS     number of loops: default=0(endless)\n"
 	       "-p PRIO  --prio=PRIO       priority\n"
+	       "-q       --quiet           print a summary only on exit\n"
 	       "-S       --smp             SMP testing: options -a -t and same priority\n"
 	       "                           of all threads\n"
 	       "-t       --threads         one thread per available processor\n"
@@ -178,6 +179,7 @@ static int interval = 1000;
 static int distance = 500;
 static int smp;
 static int sameprio;
+static int quiet;
 
 static void process_options(int argc, char *argv[])
 {
@@ -196,11 +198,12 @@ static void process_options(int argc, char *argv[])
 			{"interval",	required_argument,	NULL, 'i'},
 			{"loops",	required_argument,	NULL, 'l'},
 			{"priority",	required_argument,	NULL, 'p'},
+			{"quiet",	no_argument	,	NULL, 'q'},
 			{"smp",		no_argument,		NULL, 'S'},
 			{"threads",	optional_argument,	NULL, 't'},
 			{NULL, 0, NULL, 0}
 		};
-		int c = getopt_long (argc, argv, "a::b:d:i:l:D:p:St::h",
+		int c = getopt_long (argc, argv, "a::b:d:i:l:D:p:qSt::h",
 			long_options, &option_index);
 		if (c == -1)
 			break;
@@ -228,6 +231,7 @@ static void process_options(int argc, char *argv[])
 		case 'h': display_help(0); break;
 		case 'l': max_cycles = atoi(optarg); break;
 		case 'p': priority = atoi(optarg); break;
+		case 'q': quiet = 1; break;
 		case 'S':
 			smp = 1;
 			num_threads = max_cpus;
@@ -293,6 +297,9 @@ static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
 {
 	int i;
 
+	if (quiet)
+		return;
+
 	for (i = 0; i < num_threads; i++) {
 		printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, Cycles %d\n",
 			i*2, receiver[i].tid, receiver[i].priority, receiver[i].cpu,
@@ -391,8 +398,9 @@ int main(int argc, char *argv[])
 			shutdown |= receiver[i].shutdown | sender[i].shutdown;
 
 		if (receiver[0].samples > oldsamples || shutdown) {
-			print_stat(stdout, receiver, sender, 0, 0);
-			printf("\033[%dA", num_threads*2);
+			print_stat(stdout, receiver, sender, 0, quiet);
+			if (!quiet)
+				printf("\033[%dA", num_threads*2);
 		}
 
 		sigemptyset(&sigset);
@@ -405,7 +413,11 @@ int main(int argc, char *argv[])
 		sigemptyset(&sigset);
 		pthread_sigmask(SIG_SETMASK, &sigset, NULL);
 	}
-	printf("\033[%dB", num_threads*2 + 2);
+
+	if (!quiet)
+		printf("\033[%dB", num_threads*2 + 2);
+	else
+		print_stat(stdout, receiver, sender, 0, 0);
 
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
Signature · 1 line
2.29.2
#18 lore raw

PATCH 8/12 svsematest: Move statictic output into print_stat()

In reply to Daniel Wagner

Prepare the code to introduce the quiet command line option by moving the statistic output code into print_stat(). We follow here the pattern from cyclictest.

While at it replace the rather sophisticated error printing code with a fatal(). Just fail if something is not working.

---
 src/svsematest/svsematest.c | 101 ++++++++++++++++--------------------
 1 file changed, 45 insertions(+), 56 deletions(-)
src/svsematest/svsematest.c +45 -56
index 98efd930e63f..7de20dc65445 100644
@@ -65,7 +65,6 @@ struct params {
 	struct timeval unblocked, received, diff;
 	pthread_t threadid;
 	struct params *neighbor;
-	char error[MAX_PATH * 2];
 };
 
 static int mustfork;
@@ -95,9 +94,8 @@ void *semathread(void *param)
 		CPU_ZERO(&mask);
 		CPU_SET(par->cpu, &mask);
 		if (sched_setaffinity(0, sizeof(mask), &mask) == -1)
-			snprintf(par->error, sizeof(par->error),
-			    "WARNING: Could not set CPU affinity "
-			    "to CPU #%d\n", par->cpu);
+			fatal("Could not set CPU affinity "
+			      "to CPU #%d\n", par->cpu);
 	} else {
 		int max_cpus = sysconf(_SC_NPROCESSORS_CONF);
 
@@ -178,9 +176,8 @@ void *semathread(void *param)
 					write(tracing_enabled, "0", 1);
 					close(tracing_enabled);
 				} else
-					snprintf(par->error, sizeof(par->error),
-					    "Could not access %s\n",
-					    tracing_enabled_file);
+					fatal("Could not access %s\n",
+					      tracing_enabled_file);
 				par->shutdown = 1;
 				neighbor->shutdown = 1;
 			}
@@ -379,6 +376,42 @@ static void sighand(int sig)
 	mustshutdown = 1;
 }
 
+static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
+		       int verbose, int quiet)
+{
+	int i;
+
+	for (i = 0; i < num_threads; i++) {
+		int receiver_pid, sender_pid;
+
+		if (mustfork) {
+			receiver_pid = receiver[i].pid;
+			sender_pid = sender[i].pid;
+		} else {
+			receiver_pid = receiver[i].tid;
+			sender_pid = sender[i].tid;
+		}
+		printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, Cycles %d\n",
+			i*2, receiver_pid, receiver[i].priority,
+			receiver[i].cpu, receiver[i].delay.tv_nsec /
+			1000, i*2+1, sender_pid, sender[i].priority,
+			sender[i].cpu, sender[i].samples);
+	}
+
+	for (i = 0; i < num_threads; i++) {
+		if (receiver[i].mindiff == -1)
+			printf("#%d -> #%d (not yet ready)\n",
+				i*2+1, i*2);
+		else
+			printf("#%d -> #%d, Min %4d, Cur %4d, Avg %4d, Max %4d\n",
+				i*2+1, i*2, receiver[i].mindiff,
+				(int) receiver[i].diff.tv_usec,
+				(int) ((receiver[i].sumdiff /
+						receiver[i].samples) + 0.5),
+				receiver[i].maxdiff);
+	}
+}
+
 int main(int argc, char *argv[])
 {
 	char *myfile;
@@ -608,57 +641,14 @@ int main(int argc, char *argv[])
 	}
 
 	while (!mustshutdown) {
-		int printed;
-		int errorlines = 0;
-
 		for (i = 0; i < num_threads; i++)
 			mustshutdown |= receiver[i].shutdown |
 			    sender[i].shutdown;
 
 		if (receiver[0].samples > oldsamples || mustshutdown) {
-			for (i = 0; i < num_threads; i++) {
-				int receiver_pid, sender_pid;
-
-				if (mustfork) {
-					receiver_pid = receiver[i].pid;
-					sender_pid = sender[i].pid;
-				} else {
-					receiver_pid = receiver[i].tid;
-					sender_pid = sender[i].tid;
-				}
-				printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: "
-				    "ID%d, P%d, CPU%d, Cycles %d\n",
-				    i*2, receiver_pid, receiver[i].priority,
-				    receiver[i].cpu, receiver[i].delay.tv_nsec /
-				    1000, i*2+1, sender_pid, sender[i].priority,
-				    sender[i].cpu, sender[i].samples);
-			}
-			for (i = 0; i < num_threads; i++) {
-				if (receiver[i].mindiff == -1)
-					printf("#%d -> #%d (not yet ready)\n",
-					    i*2+1, i*2);
-				else
-					printf("#%d -> #%d, Min %4d, Cur %4d, "
-					    "Avg %4d, Max %4d\n",
-					    i*2+1, i*2, receiver[i].mindiff,
-					    (int) receiver[i].diff.tv_usec,
-					    (int) ((receiver[i].sumdiff /
-					    receiver[i].samples) + 0.5),
-					    receiver[i].maxdiff);
-				if (receiver[i].error[0] != '\0') {
-					printf("%s", receiver[i].error);
-					receiver[i].error[0] = '\0';
-					errorlines++;
-				}
-				if (sender[i].error[0] != '\0') {
-					printf("%s", sender[i].error);
-					sender[i].error[0] = '\0';
-					errorlines++;
-				}
-			}
-			printed = 1;
-		} else
-			printed = 0;
+			print_stat(stdout, receiver, sender, 0, 0);
+			printf("\033[%dA", num_threads*2);
+		}
 
 		sigemptyset(&sigset);
 		sigaddset(&sigset, SIGTERM);
@@ -670,11 +660,10 @@ int main(int argc, char *argv[])
 
 		sigemptyset(&sigset);
 		pthread_sigmask(SIG_SETMASK, &sigset, NULL);
-
-		if (printed && !mustshutdown)
-			printf("\033[%dA", num_threads*2 + errorlines);
 	}
 
+	printf("\033[%dB", num_threads*2 + 2);
+
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
 		sender[i].shutdown = 1;
Signature · 1 line
2.29.2
#19 lore raw

Re: [rt-tests v1 08/12] svsematest: Move statictic output into print_stat()

Quoted 170 lines · Daniel Wagner

Prepare the code to introduce the quiet command line option by moving the statistic output code into print_stat(). We follow here the pattern from cyclictest.

While at it replace the rather sophisticated error printing code with a fatal(). Just fail if something is not working.

---
 src/svsematest/svsematest.c | 101 ++++++++++++++++--------------------
 1 file changed, 45 insertions(+), 56 deletions(-)
src/svsematest/svsematest.c +45 -56
index 98efd930e63f..7de20dc65445 100644
@@ -65,7 +65,6 @@ struct params {
 	struct timeval unblocked, received, diff;
 	pthread_t threadid;
 	struct params *neighbor;
-	char error[MAX_PATH * 2];
 };
 
 static int mustfork;
@@ -95,9 +94,8 @@ void *semathread(void *param)
 		CPU_ZERO(&mask);
 		CPU_SET(par->cpu, &mask);
 		if (sched_setaffinity(0, sizeof(mask), &mask) == -1)
-			snprintf(par->error, sizeof(par->error),
-			    "WARNING: Could not set CPU affinity "
-			    "to CPU #%d\n", par->cpu);
+			fatal("Could not set CPU affinity "
+			      "to CPU #%d\n", par->cpu);
 	} else {
 		int max_cpus = sysconf(_SC_NPROCESSORS_CONF);
 
@@ -178,9 +176,8 @@ void *semathread(void *param)
 					write(tracing_enabled, "0", 1);
 					close(tracing_enabled);
 				} else
-					snprintf(par->error, sizeof(par->error),
-					    "Could not access %s\n",
-					    tracing_enabled_file);
+					fatal("Could not access %s\n",
+					      tracing_enabled_file);
 				par->shutdown = 1;
 				neighbor->shutdown = 1;
 			}
@@ -379,6 +376,42 @@ static void sighand(int sig)
 	mustshutdown = 1;
 }
 
+static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
+		       int verbose, int quiet)
+{
+	int i;
+
+	for (i = 0; i < num_threads; i++) {
+		int receiver_pid, sender_pid;
+
+		if (mustfork) {
+			receiver_pid = receiver[i].pid;
+			sender_pid = sender[i].pid;
+		} else {
+			receiver_pid = receiver[i].tid;
+			sender_pid = sender[i].tid;
+		}
+		printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, Cycles %d\n",
+			i*2, receiver_pid, receiver[i].priority,
+			receiver[i].cpu, receiver[i].delay.tv_nsec /
+			1000, i*2+1, sender_pid, sender[i].priority,
+			sender[i].cpu, sender[i].samples);
+	}
+
+	for (i = 0; i < num_threads; i++) {
+		if (receiver[i].mindiff == -1)
+			printf("#%d -> #%d (not yet ready)\n",
+				i*2+1, i*2);
+		else
+			printf("#%d -> #%d, Min %4d, Cur %4d, Avg %4d, Max %4d\n",
+				i*2+1, i*2, receiver[i].mindiff,
+				(int) receiver[i].diff.tv_usec,
+				(int) ((receiver[i].sumdiff /
+						receiver[i].samples) + 0.5),
+				receiver[i].maxdiff);
+	}
+}
+
 int main(int argc, char *argv[])
 {
 	char *myfile;
@@ -608,57 +641,14 @@ int main(int argc, char *argv[])
 	}
 
 	while (!mustshutdown) {
-		int printed;
-		int errorlines = 0;
-
 		for (i = 0; i < num_threads; i++)
 			mustshutdown |= receiver[i].shutdown |
 			    sender[i].shutdown;
 
 		if (receiver[0].samples > oldsamples || mustshutdown) {
-			for (i = 0; i < num_threads; i++) {
-				int receiver_pid, sender_pid;
-
-				if (mustfork) {
-					receiver_pid = receiver[i].pid;
-					sender_pid = sender[i].pid;
-				} else {
-					receiver_pid = receiver[i].tid;
-					sender_pid = sender[i].tid;
-				}
-				printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: "
-				    "ID%d, P%d, CPU%d, Cycles %d\n",
-				    i*2, receiver_pid, receiver[i].priority,
-				    receiver[i].cpu, receiver[i].delay.tv_nsec /
-				    1000, i*2+1, sender_pid, sender[i].priority,
-				    sender[i].cpu, sender[i].samples);
-			}
-			for (i = 0; i < num_threads; i++) {
-				if (receiver[i].mindiff == -1)
-					printf("#%d -> #%d (not yet ready)\n",
-					    i*2+1, i*2);
-				else
-					printf("#%d -> #%d, Min %4d, Cur %4d, "
-					    "Avg %4d, Max %4d\n",
-					    i*2+1, i*2, receiver[i].mindiff,
-					    (int) receiver[i].diff.tv_usec,
-					    (int) ((receiver[i].sumdiff /
-					    receiver[i].samples) + 0.5),
-					    receiver[i].maxdiff);
-				if (receiver[i].error[0] != '\0') {
-					printf("%s", receiver[i].error);
-					receiver[i].error[0] = '\0';
-					errorlines++;
-				}
-				if (sender[i].error[0] != '\0') {
-					printf("%s", sender[i].error);
-					sender[i].error[0] = '\0';
-					errorlines++;
-				}
-			}
-			printed = 1;
-		} else
-			printed = 0;
+			print_stat(stdout, receiver, sender, 0, 0);
+			printf("\033[%dA", num_threads*2);
+		}
 
 		sigemptyset(&sigset);
 		sigaddset(&sigset, SIGTERM);
@@ -670,11 +660,10 @@ int main(int argc, char *argv[])
 
 		sigemptyset(&sigset);
 		pthread_sigmask(SIG_SETMASK, &sigset, NULL);
-
-		if (printed && !mustshutdown)
-			printf("\033[%dA", num_threads*2 + errorlines);
 	}
 
+	printf("\033[%dB", num_threads*2 + 2);
+
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
 		sender[i].shutdown = 1;
Signature · 1 line
2.29.2
#20 lore raw

PATCH 9/12 svsematest: Add quiet command line option

In reply to Daniel Wagner

The quiet option is useful for automated test setups where only the final result of the run is interesting. This avoids to fill up the logs.

---
 src/svsematest/svsematest.8 |  5 ++++-
 src/svsematest/svsematest.c | 18 ++++++++++++++----
 2 files changed, 18 insertions(+), 5 deletions(-)
src/svsematest/svsematest.8 +4 -1
index 5fcb96149bdd..828f9154e974 100644
@@ -4,7 +4,7 @@
 \fBsvsematest\fR \- Start two threads or fork two processes and measure the latency of SYSV semaphores
 .SH "SYNTAX"
 .LP
-svsematest [-a|--affinity NUM] [-b|--breaktrace USEC] [-d|--distance DIST] [-D|--duration TIME] [-f|--fork [OPT]] [-i|--interval INTV] [-l|--loops LOOPS] [-p|--prio PRIO] [-S|--smp] [-t|--threads [NUM]]
+svsematest [-a|--affinity NUM] [-b|--breaktrace USEC] [-d|--distance DIST] [-D|--duration TIME] [-f|--fork [OPT]] [-i|--interval INTV] [-l|--loops LOOPS] [-p|--prio PRIO] [-q|--quiet] [-S|--smp] [-t|--threads [NUM]]
 .br
 .SH "DESCRIPTION"
 .LP
@@ -38,6 +38,9 @@ Set the number of loops. The default is 0 (endless). This option is useful for a
 .B \-p, \-\-prio=PRIO
 Set the priority of the process.
 .TP
+.B \-q, \-\-quiet
+Print a summary only on exit. Useful for automated tests, where only the summary output needs to be captured.
+.TP
 .B \-S, \-\-smp
 SMP testing: options -a -t and same priority of all threads
 .TP
src/svsematest/svsematest.c +14 -4
index 7de20dc65445..7388efb3f488 100644
@@ -253,6 +253,7 @@ static int interval = 1000;
 static int distance = 500;
 static int smp;
 static int sameprio;
+static int quiet;
 
 static void process_options(int argc, char *argv[])
 {
@@ -273,11 +274,12 @@ static void process_options(int argc, char *argv[])
 			{"interval",		required_argument,	NULL, 'i'},
 			{"loops",		required_argument,	NULL, 'l'},
 			{"priority",		required_argument,	NULL, 'p'},
+			{"quiet",		no_argument,		NULL, 'q'},
 			{"smp",			no_argument,		NULL, 'S'},
 			{"threads",		optional_argument,	NULL, 't'},
 			{NULL, 0, NULL, 0}
 		};
-		int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:St::",
+		int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:qSt::",
 			long_options, &option_index);
 		if (c == -1)
 			break;
@@ -315,6 +317,7 @@ static void process_options(int argc, char *argv[])
 		case 'i': interval = atoi(optarg); break;
 		case 'l': max_cycles = atoi(optarg); break;
 		case 'p': priority = atoi(optarg); break;
+		case 'q': quiet = 1; break;
 		case 'S':
 			smp = 1;
 			num_threads = max_cpus;
@@ -381,6 +384,9 @@ static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
 {
 	int i;
 
+	if (quiet)
+		return;
+
 	for (i = 0; i < num_threads; i++) {
 		int receiver_pid, sender_pid;
 
@@ -646,8 +652,9 @@ int main(int argc, char *argv[])
 			    sender[i].shutdown;
 
 		if (receiver[0].samples > oldsamples || mustshutdown) {
-			print_stat(stdout, receiver, sender, 0, 0);
-			printf("\033[%dA", num_threads*2);
+			print_stat(stdout, receiver, sender, 0, quiet);
+			if (!quiet)
+				printf("\033[%dA", num_threads*2);
 		}
 
 		sigemptyset(&sigset);
@@ -662,7 +669,10 @@ int main(int argc, char *argv[])
 		pthread_sigmask(SIG_SETMASK, &sigset, NULL);
 	}
 
-	printf("\033[%dB", num_threads*2 + 2);
+	if (!quiet)
+		printf("\033[%dB", num_threads*2 + 2);
+	else
+		print_stat(stdout, receiver, sender, 0, 0);
 
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
Signature · 1 line
2.29.2
#21 lore raw

Re: [rt-tests v1 09/12] svsematest: Add quiet command line option

Quoted 105 lines · Daniel Wagner

The quiet option is useful for automated test setups where only the final result of the run is interesting. This avoids to fill up the logs.

---
 src/svsematest/svsematest.8 |  5 ++++-
 src/svsematest/svsematest.c | 18 ++++++++++++++----
 2 files changed, 18 insertions(+), 5 deletions(-)
src/svsematest/svsematest.8 +4 -1
index 5fcb96149bdd..828f9154e974 100644
@@ -4,7 +4,7 @@
 \fBsvsematest\fR \- Start two threads or fork two processes and measure the latency of SYSV semaphores
 .SH "SYNTAX"
 .LP
-svsematest [-a|--affinity NUM] [-b|--breaktrace USEC] [-d|--distance DIST] [-D|--duration TIME] [-f|--fork [OPT]] [-i|--interval INTV] [-l|--loops LOOPS] [-p|--prio PRIO] [-S|--smp] [-t|--threads [NUM]]
+svsematest [-a|--affinity NUM] [-b|--breaktrace USEC] [-d|--distance DIST] [-D|--duration TIME] [-f|--fork [OPT]] [-i|--interval INTV] [-l|--loops LOOPS] [-p|--prio PRIO] [-q|--quiet] [-S|--smp] [-t|--threads [NUM]]
 .br
 .SH "DESCRIPTION"
 .LP
@@ -38,6 +38,9 @@ Set the number of loops. The default is 0 (endless). This option is useful for a
 .B \-p, \-\-prio=PRIO
 Set the priority of the process.
 .TP
+.B \-q, \-\-quiet
+Print a summary only on exit. Useful for automated tests, where only the summary output needs to be captured.
+.TP
 .B \-S, \-\-smp
 SMP testing: options -a -t and same priority of all threads
 .TP
src/svsematest/svsematest.c +14 -4
index 7de20dc65445..7388efb3f488 100644
@@ -253,6 +253,7 @@ static int interval = 1000;
 static int distance = 500;
 static int smp;
 static int sameprio;
+static int quiet;
 
 static void process_options(int argc, char *argv[])
 {
@@ -273,11 +274,12 @@ static void process_options(int argc, char *argv[])
 			{"interval",		required_argument,	NULL, 'i'},
 			{"loops",		required_argument,	NULL, 'l'},
 			{"priority",		required_argument,	NULL, 'p'},
+			{"quiet",		no_argument,		NULL, 'q'},
 			{"smp",			no_argument,		NULL, 'S'},
 			{"threads",		optional_argument,	NULL, 't'},
 			{NULL, 0, NULL, 0}
 		};
-		int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:St::",
+		int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:qSt::",
 			long_options, &option_index);
 		if (c == -1)
 			break;
@@ -315,6 +317,7 @@ static void process_options(int argc, char *argv[])
 		case 'i': interval = atoi(optarg); break;
 		case 'l': max_cycles = atoi(optarg); break;
 		case 'p': priority = atoi(optarg); break;
+		case 'q': quiet = 1; break;
 		case 'S':
 			smp = 1;
 			num_threads = max_cpus;
@@ -381,6 +384,9 @@ static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
 {
 	int i;
 
+	if (quiet)
+		return;
+
 	for (i = 0; i < num_threads; i++) {
 		int receiver_pid, sender_pid;
 
@@ -646,8 +652,9 @@ int main(int argc, char *argv[])
 			    sender[i].shutdown;
 
 		if (receiver[0].samples > oldsamples || mustshutdown) {
-			print_stat(stdout, receiver, sender, 0, 0);
-			printf("\033[%dA", num_threads*2);
+			print_stat(stdout, receiver, sender, 0, quiet);
+			if (!quiet)
+				printf("\033[%dA", num_threads*2);
 		}
 
 		sigemptyset(&sigset);
@@ -662,7 +669,10 @@ int main(int argc, char *argv[])
 		pthread_sigmask(SIG_SETMASK, &sigset, NULL);
 	}
 
-	printf("\033[%dB", num_threads*2 + 2);
+	if (!quiet)
+		printf("\033[%dB", num_threads*2 + 2);
+	else
+		print_stat(stdout, receiver, sender, 0, 0);
 
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
Signature · 1 line
2.29.2
#22 lore raw

PATCH 10/12 sigwaittest: Move statictic output into print_stat()

In reply to Daniel Wagner

Prepare the code to introduce the quiet command line option by moving the statistic output code into print_stat(). We follow here the pattern from cyclictest.

While at it replace the rather sophisticated error printing code with a fatal(). Just fail if something is not working.

Also reorder the include headers so that project local headers follow the system include headers.

---
 src/sigwaittest/sigwaittest.c | 97 ++++++++++++++++-------------------
 1 file changed, 43 insertions(+), 54 deletions(-)
src/sigwaittest/sigwaittest.c +43 -54
index 8a5d73b14fc2..d3be2fd9508c 100644
@@ -38,10 +38,11 @@
 #include <sys/time.h>
 #include <linux/unistd.h>
 #include <utmpx.h>
+#include <pthread.h>
+
 #include "rt-utils.h"
 #include "rt-get_cpu.h"
-
-#include <pthread.h>
+#include "error.h"
 
 enum {
 	AFFINITY_UNSPECIFIED,
@@ -69,7 +70,6 @@ struct params {
 	struct timeval unblocked, received, diff;
 	pthread_t threadid;
 	struct params *neighbor;
-	char error[MAX_PATH * 2];
 };
 
 static int mustfork;
@@ -184,9 +184,8 @@ void *semathread(void *param)
 					write(tracing_enabled, "0", 1);
 					close(tracing_enabled);
 				} else
-					snprintf(par->error, sizeof(par->error),
-					    "Could not access %s\n",
-					    tracing_enabled_file);
+					fatal("Could not access %s\n",
+					      tracing_enabled_file);
 				par->shutdown = 1;
 				neighbor->shutdown = 1;
 			}
@@ -348,6 +347,39 @@ static void sighand(int sig)
 	mustshutdown = 1;
 }
 
+static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
+		       int verbose, int quiet)
+{
+	int i;
+
+	for (i = 0; i < num_threads; i++) {
+		int receiver_pid, sender_pid;
+		if (mustfork) {
+			receiver_pid = receiver[i].pid;
+			sender_pid = sender[i].pid;
+		} else {
+			receiver_pid = receiver[i].tid;
+			sender_pid = sender[i].tid;
+		}
+		printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, Cycles %d\n",
+			i*2, receiver_pid, receiver[i].priority,
+			receiver[i].cpu, receiver[i].delay.tv_nsec /
+			1000, i*2+1, sender_pid, sender[i].priority,
+			sender[i].cpu, sender[i].samples);
+	}
+
+	for (i = 0; i < num_threads; i++) {
+		if (receiver[i].mindiff == -1)
+			printf("#%d -> #%d (not yet ready)\n", i*2+1, i*2);
+		else
+			printf("#%d -> #%d, Min %4d, Cur %4d, Avg %4d, Max %4d\n",
+				i*2+1, i*2,	receiver[i].mindiff,
+				(int) receiver[i].diff.tv_usec,
+				(int) ((receiver[i].sumdiff /
+					receiver[i].samples) + 0.5),
+				receiver[i].maxdiff);
+	}
+}
 
 int main(int argc, char *argv[])
 {
@@ -540,56 +572,14 @@ int main(int argc, char *argv[])
 	}
 
 	while (!mustshutdown) {
-		int printed;
-		int errorlines = 0;
-
 		for (i = 0; i < num_threads; i++)
 			mustshutdown |= receiver[i].shutdown |
 			    sender[i].shutdown;
 
 		if (receiver[0].samples > oldsamples || mustshutdown) {
-			for (i = 0; i < num_threads; i++) {
-				int receiver_pid, sender_pid;
-				if (mustfork) {
-					receiver_pid = receiver[i].pid;
-					sender_pid = sender[i].pid;
-				} else {
-					receiver_pid = receiver[i].tid;
-					sender_pid = sender[i].tid;
-				}
-				printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: "
-				    "ID%d, P%d, CPU%d, Cycles %d\n",
-				    i*2, receiver_pid, receiver[i].priority,
-				    receiver[i].cpu, receiver[i].delay.tv_nsec /
-				    1000, i*2+1, sender_pid, sender[i].priority,
-				    sender[i].cpu, sender[i].samples);
-			}
-			for (i = 0; i < num_threads; i++) {
-				if (receiver[i].mindiff == -1)
-					printf("#%d -> #%d (not yet ready)\n",
-					    i*2+1, i*2);
-				else
-					printf("#%d -> #%d, Min %4d, Cur %4d, "
-					    "Avg %4d, Max %4d\n",
-					    i*2+1, i*2,	receiver[i].mindiff,
-					    (int) receiver[i].diff.tv_usec,
-					    (int) ((receiver[i].sumdiff /
-					    receiver[i].samples) + 0.5),
-					    receiver[i].maxdiff);
-				if (receiver[i].error[0] != '\0') {
-					printf("%s", receiver[i].error);
-					receiver[i].error[0] = '\0';
-					errorlines++;
-				}
-				if (sender[i].error[0] != '\0') {
-					printf("%s", sender[i].error);
-					sender[i].error[0] = '\0';
-					errorlines++;
-				}
-			}
-			printed = 1;
-		} else
-			printed = 0;
+			print_stat(stdout, receiver, sender, 0, 0);
+			printf("\033[%dA", num_threads*2);
+		}
 
 		sigemptyset(&sigset);
 		sigaddset(&sigset, SIGTERM);
@@ -601,11 +591,10 @@ int main(int argc, char *argv[])
 
 		sigemptyset(&sigset);
 		pthread_sigmask(SIG_SETMASK, &sigset, NULL);
-
-		if (printed && !mustshutdown)
-			printf("\033[%dA", num_threads*2 + errorlines);
 	}
 
+	printf("\033[%dB", num_threads*2 + 2);
+
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
 		sender[i].shutdown = 1;
Signature · 1 line
2.29.2
#23 lore raw

Re: [rt-tests v1 10/12] sigwaittest: Move statictic output into print_stat()

Quoted 171 lines · Daniel Wagner

Prepare the code to introduce the quiet command line option by moving the statistic output code into print_stat(). We follow here the pattern from cyclictest.

While at it replace the rather sophisticated error printing code with a fatal(). Just fail if something is not working.

Also reorder the include headers so that project local headers follow the system include headers.

---
 src/sigwaittest/sigwaittest.c | 97 ++++++++++++++++-------------------
 1 file changed, 43 insertions(+), 54 deletions(-)
src/sigwaittest/sigwaittest.c +43 -54
index 8a5d73b14fc2..d3be2fd9508c 100644
@@ -38,10 +38,11 @@
 #include <sys/time.h>
 #include <linux/unistd.h>
 #include <utmpx.h>
+#include <pthread.h>
+
 #include "rt-utils.h"
 #include "rt-get_cpu.h"
-
-#include <pthread.h>
+#include "error.h"
 
 enum {
 	AFFINITY_UNSPECIFIED,
@@ -69,7 +70,6 @@ struct params {
 	struct timeval unblocked, received, diff;
 	pthread_t threadid;
 	struct params *neighbor;
-	char error[MAX_PATH * 2];
 };
 
 static int mustfork;
@@ -184,9 +184,8 @@ void *semathread(void *param)
 					write(tracing_enabled, "0", 1);
 					close(tracing_enabled);
 				} else
-					snprintf(par->error, sizeof(par->error),
-					    "Could not access %s\n",
-					    tracing_enabled_file);
+					fatal("Could not access %s\n",
+					      tracing_enabled_file);
 				par->shutdown = 1;
 				neighbor->shutdown = 1;
 			}
@@ -348,6 +347,39 @@ static void sighand(int sig)
 	mustshutdown = 1;
 }
 
+static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
+		       int verbose, int quiet)
+{
+	int i;
+
+	for (i = 0; i < num_threads; i++) {
+		int receiver_pid, sender_pid;
+		if (mustfork) {
+			receiver_pid = receiver[i].pid;
+			sender_pid = sender[i].pid;
+		} else {
+			receiver_pid = receiver[i].tid;
+			sender_pid = sender[i].tid;
+		}
+		printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, Cycles %d\n",
+			i*2, receiver_pid, receiver[i].priority,
+			receiver[i].cpu, receiver[i].delay.tv_nsec /
+			1000, i*2+1, sender_pid, sender[i].priority,
+			sender[i].cpu, sender[i].samples);
+	}
+
+	for (i = 0; i < num_threads; i++) {
+		if (receiver[i].mindiff == -1)
+			printf("#%d -> #%d (not yet ready)\n", i*2+1, i*2);
+		else
+			printf("#%d -> #%d, Min %4d, Cur %4d, Avg %4d, Max %4d\n",
+				i*2+1, i*2,	receiver[i].mindiff,
+				(int) receiver[i].diff.tv_usec,
+				(int) ((receiver[i].sumdiff /
+					receiver[i].samples) + 0.5),
+				receiver[i].maxdiff);
+	}
+}
 
 int main(int argc, char *argv[])
 {
@@ -540,56 +572,14 @@ int main(int argc, char *argv[])
 	}
 
 	while (!mustshutdown) {
-		int printed;
-		int errorlines = 0;
-
 		for (i = 0; i < num_threads; i++)
 			mustshutdown |= receiver[i].shutdown |
 			    sender[i].shutdown;
 
 		if (receiver[0].samples > oldsamples || mustshutdown) {
-			for (i = 0; i < num_threads; i++) {
-				int receiver_pid, sender_pid;
-				if (mustfork) {
-					receiver_pid = receiver[i].pid;
-					sender_pid = sender[i].pid;
-				} else {
-					receiver_pid = receiver[i].tid;
-					sender_pid = sender[i].tid;
-				}
-				printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: "
-				    "ID%d, P%d, CPU%d, Cycles %d\n",
-				    i*2, receiver_pid, receiver[i].priority,
-				    receiver[i].cpu, receiver[i].delay.tv_nsec /
-				    1000, i*2+1, sender_pid, sender[i].priority,
-				    sender[i].cpu, sender[i].samples);
-			}
-			for (i = 0; i < num_threads; i++) {
-				if (receiver[i].mindiff == -1)
-					printf("#%d -> #%d (not yet ready)\n",
-					    i*2+1, i*2);
-				else
-					printf("#%d -> #%d, Min %4d, Cur %4d, "
-					    "Avg %4d, Max %4d\n",
-					    i*2+1, i*2,	receiver[i].mindiff,
-					    (int) receiver[i].diff.tv_usec,
-					    (int) ((receiver[i].sumdiff /
-					    receiver[i].samples) + 0.5),
-					    receiver[i].maxdiff);
-				if (receiver[i].error[0] != '\0') {
-					printf("%s", receiver[i].error);
-					receiver[i].error[0] = '\0';
-					errorlines++;
-				}
-				if (sender[i].error[0] != '\0') {
-					printf("%s", sender[i].error);
-					sender[i].error[0] = '\0';
-					errorlines++;
-				}
-			}
-			printed = 1;
-		} else
-			printed = 0;
+			print_stat(stdout, receiver, sender, 0, 0);
+			printf("\033[%dA", num_threads*2);
+		}
 
 		sigemptyset(&sigset);
 		sigaddset(&sigset, SIGTERM);
@@ -601,11 +591,10 @@ int main(int argc, char *argv[])
 
 		sigemptyset(&sigset);
 		pthread_sigmask(SIG_SETMASK, &sigset, NULL);
-
-		if (printed && !mustshutdown)
-			printf("\033[%dA", num_threads*2 + errorlines);
 	}
 
+	printf("\033[%dB", num_threads*2 + 2);
+
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
 		sender[i].shutdown = 1;
Signature · 1 line
2.29.2
#24 lore raw

PATCH 11/12 sigwaittest: Add quiet command line option

In reply to Daniel Wagner

The quiet option is useful for automated test setups where only the final result of the run is interesting. This avoids to fill up the logs.

---
 src/sigwaittest/sigwaittest.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
src/sigwaittest/sigwaittest.c +15 -4
index d3be2fd9508c..7e287bd2424f 100644
@@ -221,6 +221,7 @@ static void display_help(int error)
 	       "-i INTV  --interval=INTV   base interval of thread in us default=1000\n"
 	       "-l LOOPS --loops=LOOPS     number of loops: default=0(endless)\n"
 	       "-p PRIO  --prio=PRIO       priority\n"
+	       "-q       --quiet           print a summary only on exit\n"
 	       "-t       --threads         one thread per available processor\n"
 	       "-t [NUM] --threads=NUM     number of threads:\n"
 	       "                           without NUM, threads = max_cpus\n"
@@ -238,6 +239,7 @@ static int max_cycles;
 static int duration;
 static int interval = 1000;
 static int distance = 500;
+static int quiet;
 
 static void process_options(int argc, char *argv[])
 {
@@ -258,10 +260,11 @@ static void process_options(int argc, char *argv[])
 			{"interval",		required_argument,	NULL, 'i'},
 			{"loops",		required_argument,	NULL, 'l'},
 			{"priority",		required_argument,	NULL, 'p'},
+			{"quiet",		no_argument,		NULL, 'q'},
 			{"threads",		optional_argument,	NULL, 't'},
 			{NULL, 0, NULL, 0}
 		};
-		int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:t::",
+		int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:qt::",
 			long_options, &option_index);
 		if (c == -1)
 			break;
@@ -298,6 +301,7 @@ static void process_options(int argc, char *argv[])
 		case 'i': interval = atoi(optarg); break;
 		case 'l': max_cycles = atoi(optarg); break;
 		case 'p': priority = atoi(optarg); break;
+		case 'q': quiet = 1; break;
 		case 't':
 			if (optarg != NULL)
 				num_threads = atoi(optarg);
@@ -352,6 +356,9 @@ static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
 {
 	int i;
 
+	if (quiet)
+		return;
+
 	for (i = 0; i < num_threads; i++) {
 		int receiver_pid, sender_pid;
 		if (mustfork) {
@@ -577,8 +584,9 @@ int main(int argc, char *argv[])
 			    sender[i].shutdown;
 
 		if (receiver[0].samples > oldsamples || mustshutdown) {
-			print_stat(stdout, receiver, sender, 0, 0);
-			printf("\033[%dA", num_threads*2);
+			print_stat(stdout, receiver, sender, 0, quiet);
+			if (!quiet)
+				printf("\033[%dA", num_threads*2);
 		}
 
 		sigemptyset(&sigset);
@@ -593,7 +601,10 @@ int main(int argc, char *argv[])
 		pthread_sigmask(SIG_SETMASK, &sigset, NULL);
 	}
 
-	printf("\033[%dB", num_threads*2 + 2);
+	if (!quiet)
+		printf("\033[%dB", num_threads*2 + 2);
+	else
+		print_stat(stdout, receiver, sender, 0, 0);
 
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
Signature · 1 line
2.29.2
#25 lore raw

Re: [rt-tests v1 11/12] sigwaittest: Add quiet command line option

Quoted 88 lines · Daniel Wagner

The quiet option is useful for automated test setups where only the final result of the run is interesting. This avoids to fill up the logs.

---
 src/sigwaittest/sigwaittest.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
src/sigwaittest/sigwaittest.c +15 -4
index d3be2fd9508c..7e287bd2424f 100644
@@ -221,6 +221,7 @@ static void display_help(int error)
 	       "-i INTV  --interval=INTV   base interval of thread in us default=1000\n"
 	       "-l LOOPS --loops=LOOPS     number of loops: default=0(endless)\n"
 	       "-p PRIO  --prio=PRIO       priority\n"
+	       "-q       --quiet           print a summary only on exit\n"
 	       "-t       --threads         one thread per available processor\n"
 	       "-t [NUM] --threads=NUM     number of threads:\n"
 	       "                           without NUM, threads = max_cpus\n"
@@ -238,6 +239,7 @@ static int max_cycles;
 static int duration;
 static int interval = 1000;
 static int distance = 500;
+static int quiet;
 
 static void process_options(int argc, char *argv[])
 {
@@ -258,10 +260,11 @@ static void process_options(int argc, char *argv[])
 			{"interval",		required_argument,	NULL, 'i'},
 			{"loops",		required_argument,	NULL, 'l'},
 			{"priority",		required_argument,	NULL, 'p'},
+			{"quiet",		no_argument,		NULL, 'q'},
 			{"threads",		optional_argument,	NULL, 't'},
 			{NULL, 0, NULL, 0}
 		};
-		int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:t::",
+		int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:qt::",
 			long_options, &option_index);
 		if (c == -1)
 			break;
@@ -298,6 +301,7 @@ static void process_options(int argc, char *argv[])
 		case 'i': interval = atoi(optarg); break;
 		case 'l': max_cycles = atoi(optarg); break;
 		case 'p': priority = atoi(optarg); break;
+		case 'q': quiet = 1; break;
 		case 't':
 			if (optarg != NULL)
 				num_threads = atoi(optarg);
@@ -352,6 +356,9 @@ static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
 {
 	int i;
 
+	if (quiet)
+		return;
+
 	for (i = 0; i < num_threads; i++) {
 		int receiver_pid, sender_pid;
 		if (mustfork) {
@@ -577,8 +584,9 @@ int main(int argc, char *argv[])
 			    sender[i].shutdown;
 
 		if (receiver[0].samples > oldsamples || mustshutdown) {
-			print_stat(stdout, receiver, sender, 0, 0);
-			printf("\033[%dA", num_threads*2);
+			print_stat(stdout, receiver, sender, 0, quiet);
+			if (!quiet)
+				printf("\033[%dA", num_threads*2);
 		}
 
 		sigemptyset(&sigset);
@@ -593,7 +601,10 @@ int main(int argc, char *argv[])
 		pthread_sigmask(SIG_SETMASK, &sigset, NULL);
 	}
 
-	printf("\033[%dB", num_threads*2 + 2);
+	if (!quiet)
+		printf("\033[%dB", num_threads*2 + 2);
+	else
+		print_stat(stdout, receiver, sender, 0, 0);
 
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
Signature · 1 line
2.29.2
#26 lore raw

PATCH 12/12 rt-migrate-test: Add quiet command line option

In reply to Daniel Wagner

The quiet option is useful for automated test setups where only the final result of the run is interesting. This avoids to fill up the logs.

---
 src/rt-migrate-test/rt-migrate-test.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
src/rt-migrate-test/rt-migrate-test.c +9 -3
index f1b7e5e4fe8c..9bf716c9178c 100644
@@ -98,6 +98,7 @@ static unsigned long long now;
 static int done;
 static int loop;
 static int duration;
+static int quiet;
 
 static pthread_barrier_t start_barrier;
 static pthread_barrier_t end_barrier;
@@ -160,6 +161,7 @@ static void usage(int error)
 	       "-l LOOPS --loops=LOOPS     Number of iterations to run (50)\n"
 	       "-m TIME  --maxerr=TIME     Max allowed error (microsecs)\n"
 	       "-p PRIO  --prio=PRIO       base priority to start RT tasks with (2)\n"
+	       "-q       --quiet           print a summary only on exit\n"
 	       "-r TIME  --run-time=TIME   Run time (ms) to busy loop the threads (20)\n"
 	       "-s TIME  --sleep-time=TIME Sleep time (ms) between intervals (100)\n\n"
 	       "  () above are defaults \n"
@@ -180,11 +182,12 @@ static void parse_options(int argc, char *argv[])
 			{"loops",	required_argument,	NULL, 'l'},
 			{"maxerr",	required_argument,	NULL, 'm'},
 			{"prio",	required_argument,	NULL, 'p'},
+			{"quiet",	no_argument,		NULL, 'q'},
 			{"run-time",	required_argument,	NULL, 'r'},
 			{"sleep-time",	required_argument,	NULL, 's'},
 			{NULL, 0, NULL, 0}
 		};
-		int c = getopt_long(argc, argv, "cD:ehl:m:p:r:s:",
+		int c = getopt_long(argc, argv, "cD:ehl:m:p:qr:s:",
 			long_options, &option_index);
 		if (c == -1)
 			break;
@@ -199,6 +202,7 @@ static void parse_options(int argc, char *argv[])
 		case 'l': nr_runs = atoi(optarg); break;
 		case 'm': max_err = usec2nano(atoi(optarg)); break;
 		case 'p': prio_start = atoi(optarg); break;
+		case 'q': quiet = 1; break;
 		case 'r':
 			run_interval = atoi(optarg);
 			break;
@@ -532,7 +536,8 @@ int main (int argc, char **argv)
 	intv.tv_sec = nano2sec(INTERVAL);
 	intv.tv_nsec = INTERVAL % sec2nano(1);
 
-	print_progress_bar(0);
+	if (!quiet)
+		print_progress_bar(0);
 
 	setup_ftrace_marker();
 
@@ -552,7 +557,8 @@ int main (int argc, char **argv)
 
 		nanosleep(&intv, NULL);
 
-		print_progress_bar((loop * 100)/nr_runs);
+		if (!quiet)
+			print_progress_bar((loop * 100)/nr_runs);
 
 		end = get_time();
 		ftrace_write("Loop %d end now=%lld diff=%lld\n", loop, end, end - now);
Signature · 1 line
2.29.2
#27 lore raw

Re: [rt-tests v1 12/12] rt-migrate-test: Add quiet command line option

Quoted 75 lines · Daniel Wagner

The quiet option is useful for automated test setups where only the final result of the run is interesting. This avoids to fill up the logs.

---
 src/rt-migrate-test/rt-migrate-test.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
src/rt-migrate-test/rt-migrate-test.c +9 -3
index f1b7e5e4fe8c..9bf716c9178c 100644
@@ -98,6 +98,7 @@ static unsigned long long now;
 static int done;
 static int loop;
 static int duration;
+static int quiet;
 
 static pthread_barrier_t start_barrier;
 static pthread_barrier_t end_barrier;
@@ -160,6 +161,7 @@ static void usage(int error)
 	       "-l LOOPS --loops=LOOPS     Number of iterations to run (50)\n"
 	       "-m TIME  --maxerr=TIME     Max allowed error (microsecs)\n"
 	       "-p PRIO  --prio=PRIO       base priority to start RT tasks with (2)\n"
+	       "-q       --quiet           print a summary only on exit\n"
 	       "-r TIME  --run-time=TIME   Run time (ms) to busy loop the threads (20)\n"
 	       "-s TIME  --sleep-time=TIME Sleep time (ms) between intervals (100)\n\n"
 	       "  () above are defaults \n"
@@ -180,11 +182,12 @@ static void parse_options(int argc, char *argv[])
 			{"loops",	required_argument,	NULL, 'l'},
 			{"maxerr",	required_argument,	NULL, 'm'},
 			{"prio",	required_argument,	NULL, 'p'},
+			{"quiet",	no_argument,		NULL, 'q'},
 			{"run-time",	required_argument,	NULL, 'r'},
 			{"sleep-time",	required_argument,	NULL, 's'},
 			{NULL, 0, NULL, 0}
 		};
-		int c = getopt_long(argc, argv, "cD:ehl:m:p:r:s:",
+		int c = getopt_long(argc, argv, "cD:ehl:m:p:qr:s:",
 			long_options, &option_index);
 		if (c == -1)
 			break;
@@ -199,6 +202,7 @@ static void parse_options(int argc, char *argv[])
 		case 'l': nr_runs = atoi(optarg); break;
 		case 'm': max_err = usec2nano(atoi(optarg)); break;
 		case 'p': prio_start = atoi(optarg); break;
+		case 'q': quiet = 1; break;
 		case 'r':
 			run_interval = atoi(optarg);
 			break;
@@ -532,7 +536,8 @@ int main (int argc, char **argv)
 	intv.tv_sec = nano2sec(INTERVAL);
 	intv.tv_nsec = INTERVAL % sec2nano(1);
 
-	print_progress_bar(0);
+	if (!quiet)
+		print_progress_bar(0);
 
 	setup_ftrace_marker();
 
@@ -552,7 +557,8 @@ int main (int argc, char **argv)
 
 		nanosleep(&intv, NULL);
 
-		print_progress_bar((loop * 100)/nr_runs);
+		if (!quiet)
+			print_progress_bar((loop * 100)/nr_runs);
 
 		end = get_time();
 		ftrace_write("Loop %d end now=%lld diff=%lld\n", loop, end, end - now);
Signature · 1 line
2.29.2