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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/papr_attributes/attr_test.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ 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-or-later
  2 /*
  3  * PAPR Energy attributes sniff test
  4  * This checks if the papr folders and contents are populated relating to
  5  * the energy and frequency attributes
  6  *
  7  * Copyright 2022, Pratik Rajesh Sampat, IBM Corp.
  8  */
  9 
 10 #include <errno.h>
 11 #include <stdio.h>
 12 #include <string.h>
 13 #include <dirent.h>
 14 #include <sys/types.h>
 15 #include <sys/stat.h>
 16 #include <unistd.h>
 17 #include <stdlib.h>
 18 
 19 #include "utils.h"
 20 
 21 enum energy_freq_attrs {
 22         POWER_PERFORMANCE_MODE = 1,
 23         IDLE_POWER_SAVER_STATUS = 2,
 24         MIN_FREQ = 3,
 25         STAT_FREQ = 4,
 26         MAX_FREQ = 6,
 27         PROC_FOLDING_STATUS = 8
 28 };
 29 
 30 enum type {
 31         INVALID,
 32         STR_VAL,
 33         NUM_VAL
 34 };
 35 
 36 static int value_type(int id)
 37 {
 38         int val_type;
 39 
 40         switch (id) {
 41         case POWER_PERFORMANCE_MODE:
 42         case IDLE_POWER_SAVER_STATUS:
 43                 val_type = STR_VAL;
 44                 break;
 45         case MIN_FREQ:
 46         case STAT_FREQ:
 47         case MAX_FREQ:
 48         case PROC_FOLDING_STATUS:
 49                 val_type = NUM_VAL;
 50                 break;
 51         default:
 52                 val_type = INVALID;
 53         }
 54 
 55         return val_type;
 56 }
 57 
 58 static int verify_energy_info(void)
 59 {
 60         const char *path = "/sys/firmware/papr/energy_scale_info";
 61         struct dirent *entry;
 62         struct stat s;
 63         DIR *dirp;
 64 
 65         errno = 0;
 66         if (stat(path, &s)) {
 67                 SKIP_IF(errno == ENOENT);
 68                 FAIL_IF(errno);
 69         }
 70 
 71         FAIL_IF(!S_ISDIR(s.st_mode));
 72 
 73         dirp = opendir(path);
 74 
 75         while ((entry = readdir(dirp)) != NULL) {
 76                 char file_name[64];
 77                 int id, attr_type;
 78                 FILE *f;
 79 
 80                 if (strcmp(entry->d_name, ".") == 0 ||
 81                     strcmp(entry->d_name, "..") == 0)
 82                         continue;
 83 
 84                 id = atoi(entry->d_name);
 85                 attr_type = value_type(id);
 86                 FAIL_IF(attr_type == INVALID);
 87 
 88                 /* Check if the files exist and have data in them */
 89                 sprintf(file_name, "%s/%d/desc", path, id);
 90                 f = fopen(file_name, "r");
 91                 FAIL_IF(!f);
 92                 FAIL_IF(fgetc(f) == EOF);
 93 
 94                 sprintf(file_name, "%s/%d/value", path, id);
 95                 f = fopen(file_name, "r");
 96                 FAIL_IF(!f);
 97                 FAIL_IF(fgetc(f) == EOF);
 98 
 99                 if (attr_type == STR_VAL) {
100                         sprintf(file_name, "%s/%d/value_desc", path, id);
101                         f = fopen(file_name, "r");
102                         FAIL_IF(!f);
103                         FAIL_IF(fgetc(f) == EOF);
104                 }
105         }
106 
107         return 0;
108 }
109 
110 int main(void)
111 {
112         return test_harness(verify_energy_info, "papr_attributes");
113 }
114 

~ [ 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