skew_consistency.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* ADJ_FREQ Skew consistency test
  2. * by: john stultz (johnstul@us.ibm.com)
  3. * (C) Copyright IBM 2012
  4. * Licensed under the GPLv2
  5. *
  6. * NOTE: This is a meta-test which cranks the ADJ_FREQ knob back
  7. * and forth and watches for consistency problems. Thus this test requires
  8. * that the inconsistency-check tests be present in the same directory it
  9. * is run from.
  10. *
  11. * To build:
  12. * $ gcc skew_consistency.c -o skew_consistency -lrt
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation, either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. */
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <unistd.h>
  27. #include <sys/time.h>
  28. #include <sys/timex.h>
  29. #include <time.h>
  30. #include <sys/types.h>
  31. #include <sys/stat.h>
  32. #include <fcntl.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <sys/wait.h>
  36. #include "../kselftest.h"
  37. #define NSEC_PER_SEC 1000000000LL
  38. int main(int argv, char **argc)
  39. {
  40. struct timex tx;
  41. int ret, ppm;
  42. pid_t pid;
  43. printf("Running Asynchronous Frequency Changing Tests...\n");
  44. pid = fork();
  45. if (!pid)
  46. return system("./inconsistency-check -c 1 -t 600");
  47. ppm = 500;
  48. ret = 0;
  49. while (pid != waitpid(pid, &ret, WNOHANG)) {
  50. ppm = -ppm;
  51. tx.modes = ADJ_FREQUENCY;
  52. tx.freq = ppm << 16;
  53. adjtimex(&tx);
  54. usleep(500000);
  55. }
  56. /* Set things back */
  57. tx.modes = ADJ_FREQUENCY;
  58. tx.offset = 0;
  59. adjtimex(&tx);
  60. if (ret) {
  61. printf("[FAILED]\n");
  62. return ksft_exit_fail();
  63. }
  64. printf("[OK]\n");
  65. return ksft_exit_pass();
  66. }