2 * POWER Data Stream Control Register (DSCR) fork exec test
4 * This testcase modifies the DSCR using mtspr, forks & execs and
5 * verifies that the child is using the changed DSCR using mfspr.
7 * When using the privilege state SPR, the instructions such as
8 * mfspr or mtspr are privileged and the kernel emulates them
9 * for us. Instructions using problem state SPR can be executed
10 * directly without any emulation if the HW supports them. Else
11 * they also get emulated by the kernel.
13 * Copyright 2012, Anton Blanchard, IBM Corporation.
14 * Copyright 2015, Anshuman Khandual, IBM Corporation.
16 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License version 2 as published
18 * by the Free Software Foundation.
24 static void do_exec(unsigned long parent_dscr
)
26 unsigned long cur_dscr
, cur_dscr_usr
;
28 cur_dscr
= get_dscr();
29 cur_dscr_usr
= get_dscr_usr();
31 if (cur_dscr
!= parent_dscr
) {
32 fprintf(stderr
, "Parent DSCR %ld was not inherited "
33 "over exec (kernel value)\n", parent_dscr
);
37 if (cur_dscr_usr
!= parent_dscr
) {
38 fprintf(stderr
, "Parent DSCR %ld was not inherited "
39 "over exec (user value)\n", parent_dscr
);
45 int dscr_inherit_exec(void)
47 unsigned long i
, dscr
= 0;
50 for (i
= 0; i
< COUNT
; i
++) {
55 if (dscr
== get_default_dscr())
65 perror("fork() failed");
70 if (waitpid(pid
, &status
, 0) == -1) {
71 perror("waitpid() failed");
75 if (!WIFEXITED(status
)) {
76 fprintf(stderr
, "Child didn't exit cleanly\n");
80 if (WEXITSTATUS(status
) != 0) {
81 fprintf(stderr
, "Child didn't exit cleanly\n");
87 sprintf(dscr_str
, "%ld", dscr
);
88 execlp(prog
, prog
, "exec", dscr_str
, NULL
);
95 int main(int argc
, char *argv
[])
97 if (argc
== 3 && !strcmp(argv
[1], "exec")) {
98 unsigned long parent_dscr
;
100 parent_dscr
= atoi(argv
[2]);
101 do_exec(parent_dscr
);
102 } else if (argc
!= 1) {
103 fprintf(stderr
, "Usage: %s\n", argv
[0]);
108 return test_harness(dscr_inherit_exec
, "dscr_inherit_exec_test");