PAPI  5.6.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 #include <stdio.h>
12 
13 #include "papi.h"
14 #include "papi_test.h"
15 
16 
17 int
18 main( int argc, char **argv )
19 {
20  int retval;
21  const PAPI_component_info_t* cmpinfo;
22  int numcmp, cid, active_components=0;
23 
24  /* Set TESTS_QUIET variable */
25  tests_quiet( argc, argv );
26 
27  /* Disable All Compiled-in Components */
28  numcmp = PAPI_num_components( );
29 
30  if (!TESTS_QUIET) printf("Compiled-in components:\n");
31  for( cid = 0; cid < numcmp; cid++ ) {
32  cmpinfo = PAPI_get_component_info( cid );
33 
34  if (!TESTS_QUIET) {
35  printf( "Name: %-23s %s\n", cmpinfo->name, cmpinfo->description);
36  }
37 
38  retval=PAPI_disable_component( cid );
39  if (retval!=PAPI_OK) {
40  test_fail(__FILE__,__LINE__,"Error disabling component",retval);
41  }
42  }
43 
44 
45  /* Initialize the library */
47  if ( retval != PAPI_VER_CURRENT ) {
48  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
49  }
50 
51  /* Try to disable after init, should fail */
52  retval=PAPI_disable_component( 0 );
53  if (retval==PAPI_OK) {
54  test_fail( __FILE__, __LINE__, "PAPI_disable_component should fail",
55  retval );
56  }
57 
58  if (!TESTS_QUIET) printf("\nAfter init components:\n");
59  for( cid = 0; cid < numcmp; cid++ ) {
60 
61  cmpinfo = PAPI_get_component_info( cid );
62 
63  if (!TESTS_QUIET) {
64  printf( "%d %d Name: %-23s %s\n",
65  cid,
66  PAPI_get_component_index((char *)cmpinfo->name),
67  cmpinfo->name ,cmpinfo->description);
68 
69  }
70 
71  if (cid!=PAPI_get_component_index((char *)cmpinfo->name)) {
72  test_fail( __FILE__, __LINE__, "PAPI_get_component_index mismatch",
73  2 );
74  }
75 
76 
77  if (cmpinfo->disabled) {
78  if (!TESTS_QUIET) {
79  printf(" \\-> Disabled: %s\n",cmpinfo->disabled_reason);
80  }
81  } else {
82  active_components++;
83  }
84  }
85 
86  if (active_components>0) {
87  test_fail( __FILE__, __LINE__, "too many active components", retval );
88  }
89 
90  test_pass( __FILE__ );
91 
92  return PAPI_OK;
93 }
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:629
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:796
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_num_components(void)
Definition: papi.c:4387
return PAPI_OK
Definition: linux-nvml.c:497
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
char ** argv
Definition: iozone.c:1610
int PAPI_disable_component(int cidx)
Definition: papi.c:6666
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:636
int PAPI_library_init(int version)
Definition: papi.c:500
int PAPI_get_component_index(const char *name)
Definition: papi.c:6610
char description[PAPI_MAX_STR_LEN]
Definition: papi.h:632
printf("\tTry: -i 0 -i 1 \n\n")
int TESTS_QUIET
Definition: test_utils.c:18
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:225
int main(int argc, char **argv)
List all appio events codes and names.