18c2ecf20Sopenharmony_ci/* ADJ_FREQ Skew consistency test
28c2ecf20Sopenharmony_ci *		by: john stultz (johnstul@us.ibm.com)
38c2ecf20Sopenharmony_ci *		(C) Copyright IBM 2012
48c2ecf20Sopenharmony_ci *		Licensed under the GPLv2
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci *  NOTE: This is a meta-test which cranks the ADJ_FREQ knob back
78c2ecf20Sopenharmony_ci *  and forth and watches for consistency problems. Thus this test requires
88c2ecf20Sopenharmony_ci *  that the inconsistency-check tests be present in the same directory it
98c2ecf20Sopenharmony_ci *  is run from.
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci *  To build:
128c2ecf20Sopenharmony_ci *	$ gcc skew_consistency.c -o skew_consistency -lrt
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci *   This program is free software: you can redistribute it and/or modify
158c2ecf20Sopenharmony_ci *   it under the terms of the GNU General Public License as published by
168c2ecf20Sopenharmony_ci *   the Free Software Foundation, either version 2 of the License, or
178c2ecf20Sopenharmony_ci *   (at your option) any later version.
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci *   This program is distributed in the hope that it will be useful,
208c2ecf20Sopenharmony_ci *   but WITHOUT ANY WARRANTY; without even the implied warranty of
218c2ecf20Sopenharmony_ci *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
228c2ecf20Sopenharmony_ci *   GNU General Public License for more details.
238c2ecf20Sopenharmony_ci */
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#include <stdio.h>
278c2ecf20Sopenharmony_ci#include <stdlib.h>
288c2ecf20Sopenharmony_ci#include <unistd.h>
298c2ecf20Sopenharmony_ci#include <sys/time.h>
308c2ecf20Sopenharmony_ci#include <sys/timex.h>
318c2ecf20Sopenharmony_ci#include <time.h>
328c2ecf20Sopenharmony_ci#include <sys/types.h>
338c2ecf20Sopenharmony_ci#include <sys/stat.h>
348c2ecf20Sopenharmony_ci#include <fcntl.h>
358c2ecf20Sopenharmony_ci#include <string.h>
368c2ecf20Sopenharmony_ci#include <sys/wait.h>
378c2ecf20Sopenharmony_ci#include "../kselftest.h"
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define NSEC_PER_SEC 1000000000LL
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciint main(int argv, char **argc)
428c2ecf20Sopenharmony_ci{
438c2ecf20Sopenharmony_ci	struct timex tx;
448c2ecf20Sopenharmony_ci	int ret, ppm;
458c2ecf20Sopenharmony_ci	pid_t pid;
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	printf("Running Asynchronous Frequency Changing Tests...\n");
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	pid = fork();
518c2ecf20Sopenharmony_ci	if (!pid)
528c2ecf20Sopenharmony_ci		return system("./inconsistency-check -c 1 -t 600");
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	ppm = 500;
558c2ecf20Sopenharmony_ci	ret = 0;
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	while (pid != waitpid(pid, &ret, WNOHANG)) {
588c2ecf20Sopenharmony_ci		ppm = -ppm;
598c2ecf20Sopenharmony_ci		tx.modes = ADJ_FREQUENCY;
608c2ecf20Sopenharmony_ci		tx.freq = ppm << 16;
618c2ecf20Sopenharmony_ci		adjtimex(&tx);
628c2ecf20Sopenharmony_ci		usleep(500000);
638c2ecf20Sopenharmony_ci	}
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	/* Set things back */
668c2ecf20Sopenharmony_ci	tx.modes = ADJ_FREQUENCY;
678c2ecf20Sopenharmony_ci	tx.offset = 0;
688c2ecf20Sopenharmony_ci	adjtimex(&tx);
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	if (ret) {
728c2ecf20Sopenharmony_ci		printf("[FAILED]\n");
738c2ecf20Sopenharmony_ci		return ksft_exit_fail();
748c2ecf20Sopenharmony_ci	}
758c2ecf20Sopenharmony_ci	printf("[OK]\n");
768c2ecf20Sopenharmony_ci	return ksft_exit_pass();
778c2ecf20Sopenharmony_ci}
78