~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/dscr/dscr_inherit_test.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * POWER Data Stream Control Register (DSCR) fork test
  4  *
  5  * This testcase modifies the DSCR using mtspr, forks and then
  6  * verifies that the child process has the correct changed DSCR
  7  * value using mfspr.
  8  *
  9  * When using the privilege state SPR, the instructions such as
 10  * mfspr or mtspr are privileged and the kernel emulates them
 11  * for us. Instructions using problem state SPR can be executed
 12  * directly without any emulation if the HW supports them. Else
 13  * they also get emulated by the kernel.
 14  *
 15  * Copyright 2012, Anton Blanchard, IBM Corporation.
 16  * Copyright 2015, Anshuman Khandual, IBM Corporation.
 17  */
 18 #include "dscr.h"
 19 
 20 int dscr_inherit(void)
 21 {
 22         unsigned long i, dscr = 0;
 23         pid_t pid;
 24 
 25         SKIP_IF(!have_hwcap2(PPC_FEATURE2_DSCR));
 26 
 27         srand(getpid());
 28         set_dscr(dscr);
 29 
 30         for (i = 0; i < COUNT; i++) {
 31                 unsigned long cur_dscr, cur_dscr_usr;
 32 
 33                 dscr++;
 34                 if (dscr > DSCR_MAX)
 35                         dscr = 0;
 36 
 37                 if (i % 2 == 0)
 38                         set_dscr_usr(dscr);
 39                 else
 40                         set_dscr(dscr);
 41 
 42                 pid = fork();
 43                 if (pid == -1) {
 44                         perror("fork() failed");
 45                         exit(1);
 46                 } else if (pid) {
 47                         int status;
 48 
 49                         if (waitpid(pid, &status, 0) == -1) {
 50                                 perror("waitpid() failed");
 51                                 exit(1);
 52                         }
 53 
 54                         if (!WIFEXITED(status)) {
 55                                 fprintf(stderr, "Child didn't exit cleanly\n");
 56                                 exit(1);
 57                         }
 58 
 59                         if (WEXITSTATUS(status) != 0) {
 60                                 fprintf(stderr, "Child didn't exit cleanly\n");
 61                                 return 1;
 62                         }
 63                 } else {
 64                         cur_dscr = get_dscr();
 65                         if (cur_dscr != dscr) {
 66                                 fprintf(stderr, "Kernel DSCR should be %ld "
 67                                         "but is %ld\n", dscr, cur_dscr);
 68                                 exit(1);
 69                         }
 70 
 71                         cur_dscr_usr = get_dscr_usr();
 72                         if (cur_dscr_usr != dscr) {
 73                                 fprintf(stderr, "User DSCR should be %ld "
 74                                         "but is %ld\n", dscr, cur_dscr_usr);
 75                                 exit(1);
 76                         }
 77                         exit(0);
 78                 }
 79         }
 80         return 0;
 81 }
 82 
 83 int main(int argc, char *argv[])
 84 {
 85         return test_harness(dscr_inherit, "dscr_inherit_test");
 86 }
 87 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php