PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
disable_component.c
Go to the documentation of this file.
1 /*
2  * File: disable_component.c
3  * Author: Vince Weaver
4  * vweaver1@eecs.utk.edu
5  */
6 
7 /*
8  This tests the functionality of PAPI_disable_component()
9 */
10 
11 
12 #include "papi_test.h"
13 
14 
15 int
16 main( int argc, char **argv )
17 {
18  int retval;
19  const PAPI_component_info_t* cmpinfo;
20  int numcmp, cid, active_components=0;
21 
22  /* Set TESTS_QUIET variable */
23  tests_quiet( argc, argv );
24 
25  /* Disable All Compiled-in Components */
26  numcmp = PAPI_num_components( );
27 
28  if (!TESTS_QUIET) printf("Compiled-in components:\n");
29  for( cid = 0; cid < numcmp; cid++ ) {
30  cmpinfo = PAPI_get_component_info( cid );
31 
32  if (!TESTS_QUIET) {
33  printf( "Name: %-23s %s\n", cmpinfo->name, cmpinfo->description);
34  }
35 
36  retval=PAPI_disable_component( cid );
37  if (retval!=PAPI_OK) {
38  test_fail(__FILE__,__LINE__,"Error disabling component",retval);
39  }
40  }
41 
42 
43  /* Initialize the library */
45  if ( retval != PAPI_VER_CURRENT ) {
46  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
47  }
48 
49  /* Try to disable after init, should fail */
50  retval=PAPI_disable_component( 0 );
51  if (retval==PAPI_OK) {
52  test_fail( __FILE__, __LINE__, "PAPI_disable_component should fail",
53  retval );
54  }
55 
56  if (!TESTS_QUIET) printf("\nAfter init components:\n");
57  for( cid = 0; cid < numcmp; cid++ ) {
58 
59  cmpinfo = PAPI_get_component_info( cid );
60 
61  if (!TESTS_QUIET) {
62  printf( "%d %d Name: %-23s %s\n",
63  cid,
64  PAPI_get_component_index((char *)cmpinfo->name),
65  cmpinfo->name ,cmpinfo->description);
66 
67  }
68 
69  if (cid!=PAPI_get_component_index((char *)cmpinfo->name)) {
70  test_fail( __FILE__, __LINE__, "PAPI_get_component_index mismatch",
71  2 );
72  }
73 
74 
75  if (cmpinfo->disabled) {
76  if (!TESTS_QUIET) {
77  printf(" \\-> Disabled: %s\n",cmpinfo->disabled_reason);
78  }
79  } else {
80  active_components++;
81  }
82  }
83 
84  if (active_components>0) {
85  test_fail( __FILE__, __LINE__, "too many active components", retval );
86  }
87 
88  test_pass( __FILE__, NULL, 0 );
89 
90  return PAPI_OK;
91 }
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:625
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:803
int PAPI_num_components(void)
Definition: papi.c:4272
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
int PAPI_disable_component(int cidx)
Definition: papi.c:6524
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:632
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_get_component_index(char *name)
Definition: papi.c:6469
char description[PAPI_MAX_STR_LEN]
Definition: papi.h:628
ssize_t retval
Definition: libasync.c:338
int main(int argc, char **argv)
List all appio events codes and names.