Linux 4.8-rc8
[linux/fpc-iii.git] / tools / testing / selftests / powerpc / dscr / dscr_explicit_test.c
blobad9c3ec260489fe17a347423360a2b31a587250f
1 /*
2 * POWER Data Stream Control Register (DSCR) explicit test
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.
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.
14 * Copyright 2012, Anton Blanchard, IBM Corporation.
15 * Copyright 2015, Anshuman Khandual, IBM Corporation.
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.
21 #include "dscr.h"
23 int dscr_explicit(void)
25 unsigned long i, dscr = 0;
27 srand(getpid());
28 set_dscr(dscr);
30 for (i = 0; i < COUNT; i++) {
31 unsigned long cur_dscr, cur_dscr_usr;
32 double ret = uniform_deviate(rand());
34 if (ret < 0.001) {
35 dscr++;
36 if (dscr > DSCR_MAX)
37 dscr = 0;
39 set_dscr(dscr);
42 cur_dscr = get_dscr();
43 if (cur_dscr != dscr) {
44 fprintf(stderr, "Kernel DSCR should be %ld but "
45 "is %ld\n", dscr, cur_dscr);
46 return 1;
49 ret = uniform_deviate(rand());
50 if (ret < 0.001) {
51 dscr++;
52 if (dscr > DSCR_MAX)
53 dscr = 0;
55 set_dscr_usr(dscr);
58 cur_dscr_usr = get_dscr_usr();
59 if (cur_dscr_usr != dscr) {
60 fprintf(stderr, "User DSCR should be %ld but "
61 "is %ld\n", dscr, cur_dscr_usr);
62 return 1;
65 return 0;
68 int main(int argc, char *argv[])
70 return test_harness(dscr_explicit, "dscr_explicit_test");