dscr_explicit_test.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * POWER Data Stream Control Register (DSCR) explicit test
  3. *
  4. * This test modifies the DSCR value using mtspr instruction and
  5. * verifies the change with mfspr instruction. It uses both the
  6. * privilege state SPR and the problem state SPR for this purpose.
  7. *
  8. * When using the privilege state SPR, the instructions such as
  9. * mfspr or mtspr are priviledged and the kernel emulates them
  10. * for us. Instructions using problem state SPR can be exuecuted
  11. * directly without any emulation if the HW supports them. Else
  12. * they also get emulated by the kernel.
  13. *
  14. * Copyright 2012, Anton Blanchard, IBM Corporation.
  15. * Copyright 2015, Anshuman Khandual, IBM Corporation.
  16. *
  17. * This program is free software; you can redistribute it and/or modify it
  18. * under the terms of the GNU General Public License version 2 as published
  19. * by the Free Software Foundation.
  20. */
  21. #include "dscr.h"
  22. int dscr_explicit(void)
  23. {
  24. unsigned long i, dscr = 0;
  25. srand(getpid());
  26. set_dscr(dscr);
  27. for (i = 0; i < COUNT; i++) {
  28. unsigned long cur_dscr, cur_dscr_usr;
  29. double ret = uniform_deviate(rand());
  30. if (ret < 0.001) {
  31. dscr++;
  32. if (dscr > DSCR_MAX)
  33. dscr = 0;
  34. set_dscr(dscr);
  35. }
  36. cur_dscr = get_dscr();
  37. if (cur_dscr != dscr) {
  38. fprintf(stderr, "Kernel DSCR should be %ld but "
  39. "is %ld\n", dscr, cur_dscr);
  40. return 1;
  41. }
  42. ret = uniform_deviate(rand());
  43. if (ret < 0.001) {
  44. dscr++;
  45. if (dscr > DSCR_MAX)
  46. dscr = 0;
  47. set_dscr_usr(dscr);
  48. }
  49. cur_dscr_usr = get_dscr_usr();
  50. if (cur_dscr_usr != dscr) {
  51. fprintf(stderr, "User DSCR should be %ld but "
  52. "is %ld\n", dscr, cur_dscr_usr);
  53. return 1;
  54. }
  55. }
  56. return 0;
  57. }
  58. int main(int argc, char *argv[])
  59. {
  60. return test_harness(dscr_explicit, "dscr_explicit_test");
  61. }