[CRIU] Re: [PATCH] uptime_grow test

Andrew Vagin avagin at parallels.com
Tue Jun 19 09:10:19 EDT 2012


On Tue, Jun 19, 2012 at 01:22:29PM +0400, Evgeny Antyshev wrote:
> we query system timer CLOCK_MONOTONIC continuously
> and fail in case it stepped backwards
> ---
>  test/zdtm/live/static/Makefile      |    2 +
>  test/zdtm/live/static/uptime_grow.c |   46 +++++++++++++++++++++++++++++++++++
>  2 files changed, 48 insertions(+), 0 deletions(-)
>  create mode 100644 test/zdtm/live/static/uptime_grow.c
> 
> diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> index a399741..5492d05 100644
> --- a/test/zdtm/live/static/Makefile
> +++ b/test/zdtm/live/static/Makefile
> @@ -46,6 +46,7 @@ TST_NOFILE	=				\
>  		file_fown			\
>  		eventfs00			\
>  		inotify00			\
> +		uptime_grow			\
>  #		jobctl00			\
>  
>  TST_FILE	=				\
> @@ -157,6 +158,7 @@ futex:			override LDFLAGS += -pthread
>  jobctl00:		override LDLIBS += -lutil
>  socket_listen:		override LDLIBS += -lrt
>  socket_aio:		override LDLIBS += -lrt
> +uptime_grow:	override LDLIBS += -lrt
>  unlink_largefile:	override CFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
>  inotify_system_nodel:	override CFLAGS += -DNODEL
>  pthread00:		override LDLIBS += -pthread
> diff --git a/test/zdtm/live/static/uptime_grow.c b/test/zdtm/live/static/uptime_grow.c
> new file mode 100644
> index 0000000..ca2b4ef
> --- /dev/null
> +++ b/test/zdtm/live/static/uptime_grow.c
> @@ -0,0 +1,46 @@
> +#include "zdtmtst.h"
> +
> +const char *test_doc    = "test to ensure that monotonic clock doesn't decrease";
> +const char *test_author = "Evgeny Antysev <eantyshev at parallels.com>";
> +
> +#include <stdio.h>
> +#include <time.h>
> +#include <sys/types.h>
> +#include <unistd.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +#include <string.h>
> +#include <errno.h>
> +#include <stdlib.h>

Looks like you copied this include from another test case. Pls remove
unused headers.
> +
> +#define NEWER(t1,t2) (t1.tv_sec > t2.tv_sec || t1.tv_nsec > t2.tv_nsec)

The logic of this macros is incorrect.
t1 = {1, 5}
t2 = {2, 4}

t1 < t2, but according to this macros t2 < t1

This macros should be like this:
# define tv_gt(a, b) \
  (((a)->tv_sec == (b)->tv_sec) ? \
   ((a)->tv_usec > (b)->tv_usec) : \
   ((a)->tv_sec > (b)->tv_sec))
> +
> +int main(int argc, char **argv)
> +{
> +	struct timespec tm_old, tm;
> +	double diff_nsec;tm.tv_nsec
> +	test_init(argc, argv);
> +
> +	if (0 != clock_gettime(CLOCK_MONOTONIC, &tm_old)) {
Here is enough:
	if (clock_gettime(CLOCK_MONOTONIC, &tm_old)) {

but your version is usually written like this:

if (clock_gettime(CLOCK_MONOTONIC, &tm_old) != 0)
> +		err("clock_gettime failed: %m\n");
> +		exit(1);
> +	}
> +
> +	test_daemon();
> +
> +	while (test_go()) {
> +		if (0 != clock_gettime(CLOCK_MONOTONIC, &tm)) {
> +			err("clock_gettime failed: %m\n");
> +			exit(1);
> +		}
> +		if (!NEWER(tm, tm_old)) {
> +			diff_nsec = (tm_old.tv_sec - tm.tv_sec) * 1.0E9 +\
> +				(tm_old.tv_nsec - tm.tv_nsec);
> +			fail("clock step backward for %e nsec\n", diff_nsec);
> +			exit(1);
> +		}
> +		memcpy(&tm_old, &tm, sizeof(struct timespec));
		tm_old = tm;
> +	}
> +	pass();
> +	return 0;
> +}
> -- 
> 1.6.5.1.1367.gcd48
> 


More information about the CRIU mailing list