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

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

Version: ~ [ linux-5.2-rc5 ] ~ [ linux-5.1.12 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.53 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.128 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.182 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.182 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.68 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * POWER Data Stream Control Register (DSCR) sysfs interface test
  3  *
  4  * This test updates to system wide DSCR default through the sysfs interface
  5  * and then verifies that all the CPU specific DSCR defaults are updated as
  6  * well verified from their sysfs interfaces.
  7  *
  8  * Copyright 2015, Anshuman Khandual, IBM Corporation.
  9  *
 10  * This program is free software; you can redistribute it and/or modify it
 11  * under the terms of the GNU General Public License version 2 as published
 12  * by the Free Software Foundation.
 13  */
 14 #include "dscr.h"
 15 
 16 static int check_cpu_dscr_default(char *file, unsigned long val)
 17 {
 18         char buf[10];
 19         int fd, rc;
 20 
 21         fd = open(file, O_RDWR);
 22         if (fd == -1) {
 23                 perror("open() failed");
 24                 return 1;
 25         }
 26 
 27         rc = read(fd, buf, sizeof(buf));
 28         if (rc == -1) {
 29                 perror("read() failed");
 30                 return 1;
 31         }
 32         close(fd);
 33 
 34         buf[rc] = '\0';
 35         if (strtol(buf, NULL, 16) != val) {
 36                 printf("DSCR match failed: %ld (system) %ld (cpu)\n",
 37                                         val, strtol(buf, NULL, 16));
 38                 return 1;
 39         }
 40         return 0;
 41 }
 42 
 43 static int check_all_cpu_dscr_defaults(unsigned long val)
 44 {
 45         DIR *sysfs;
 46         struct dirent *dp;
 47         char file[LEN_MAX];
 48 
 49         sysfs = opendir(CPU_PATH);
 50         if (!sysfs) {
 51                 perror("opendir() failed");
 52                 return 1;
 53         }
 54 
 55         while ((dp = readdir(sysfs))) {
 56                 if (!(dp->d_type & DT_DIR))
 57                         continue;
 58                 if (!strcmp(dp->d_name, "cpuidle"))
 59                         continue;
 60                 if (!strstr(dp->d_name, "cpu"))
 61                         continue;
 62 
 63                 sprintf(file, "%s%s/dscr", CPU_PATH, dp->d_name);
 64                 if (access(file, F_OK))
 65                         continue;
 66 
 67                 if (check_cpu_dscr_default(file, val))
 68                         return 1;
 69         }
 70         closedir(sysfs);
 71         return 0;
 72 }
 73 
 74 int dscr_sysfs(void)
 75 {
 76         unsigned long orig_dscr_default;
 77         int i, j;
 78 
 79         orig_dscr_default = get_default_dscr();
 80         for (i = 0; i < COUNT; i++) {
 81                 for (j = 0; j < DSCR_MAX; j++) {
 82                         set_default_dscr(j);
 83                         if (check_all_cpu_dscr_defaults(j))
 84                                 goto fail;
 85                 }
 86         }
 87         set_default_dscr(orig_dscr_default);
 88         return 0;
 89 fail:
 90         set_default_dscr(orig_dscr_default);
 91         return 1;
 92 }
 93 
 94 int main(int argc, char *argv[])
 95 {
 96         return test_harness(dscr_sysfs, "dscr_sysfs_test");
 97 }
 98 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp