<commit_before>/* 
* File:    multiplex1_pthreads.c
* CVS:     $Id$
* Author:  <NAME>
*          <EMAIL>
* Mods:    <NAME>
*          <EMAIL>
*/  

/* This file tests the multiplex pthread functionality when there are
 * threads in which the application isn't calling PAPI (and only
 * one thread that is calling PAPI.)
 *
 * This test will fail on most, if not all platforms due to signal handling.
 */ 

#include <pthread.h>
#include "papi_test.h"

#define NUM 10
#define NUM_THREADS 4
#define SUCCESS 1
#define FAILURE 0

extern void do_flops(int);
extern void do_reads(int);

extern int TESTS_QUIET; /* Declared in test_utils.c */

/* A thread function that does nothing forever, while the other
 * tests are running.
 */
void * thread_fn( void * dummy )
{
	while(1)
	  do_flops(10000);
}

void init_papi(void)
{
  int retval;

  /* Initialize the library */

  retval = PAPI_library_init(PAPI_VER_CURRENT);
  if (retval != PAPI_VER_CURRENT)
    test_fail(__FILE__,__LINE__,"PAPI_library_init",retval);

  if ((retval=PAPI_thread_init((unsigned long (*)(void))(pthread_self), 0)) != PAPI_OK){
     if (retval == PAPI_ESBSTR)
        test_skip(__FILE__,__LINE__,"PAPI_thread_init",retval);
     else
        test_fail(__FILE__,__LINE__,"PAPI_thread_init",retval);
  }

  /* Turn on automatic error reporting */

  retval = PAPI_set_debug(PAPI_VERB_ECONT);
  if (retval != PAPI_OK)
    test_fail(__FILE__,__LINE__,"PAPI_set_debug",retval);
}

/* Runs a bunch of multiplexed events */

int case1(void) 
{
  int retval, i, EventSet = PAPI_NULL, max_to_add = 6, j = 0;
  int allvalid = 1;
  long long *values;
  const PAPI_preset_info_t *pset;

  init_papi();

  pset = PAPI_query_all_events_verbose();
  if (pset == NULL)
    test_fail(__FILE__,__LINE__,"PAPI_query_all_events_verbose",0);

  retval = PAPI_multiplex_init();
  if (retval != PAPI_OK)
    test_fail(__FILE__,__LINE__,"PAPI_multiplex_init",retval);
  
  retval = PAPI_create_eventset(&EventSet);
  if (retval != PAPI_OK)
    test_fail(__FILE__,__LINE__,"PAPI_create_eventset",retval);

  retval = PAPI_set_multiplex(&EventSet);
  if (retval != PAPI_OK)
    test_fail(__FILE__,__LINE__,"PAPI_set_multiplex",retval);

  for (i=0;i<PAPI_MAX_PRESET_EVENTS;i++)
    {
      if ((pset->avail) && (pset->event_code != PAPI_TOT_CYC))
	{
	  if ( !TESTS_QUIET ) 
	    printf("Adding %s\n",pset->event_name);

	  retval = PAPI_add_event(&EventSet, pset->event_code);
	  if ((retval != PAPI_OK) && (retval != PAPI_ECNFLCT))
	    test_fail(__FILE__,__LINE__,"PAPI_add_event",retval);

	  if ( !TESTS_QUIET ) 
	    {
	      if (retval == PAPI_OK)
		printf("Added %s\n",pset->event_name);
	      else
		printf("Could not add %s\n",pset->event_name);
	    }

	  if (retval == PAPI_OK)
	    {
	      if (++j >= max_to_add)
		break;
	    }
	}
	pset++;
    }

  values = (long long *)malloc(max_to_add*sizeof(long long));
  if (values == NULL)
    test_fail(__FILE__,__LINE__,"malloc",0);

  if (PAPI_start(EventSet) != PAPI_OK)
    test_fail(__FILE__,__LINE__,"PAPI_start",retval);

  do_reads(10000);

  retval = PAPI_stop(EventSet, values);
  if (retval != PAPI_OK)
    test_fail(__FILE__,__LINE__,"PAPI_stop",retval);

  printf("case1:");
  for( i = 0; i < max_to_add; i++ ) {
	  printf(" %lld", values[i]);

	  /* There should be some sort of value for all events */
	  if( values[i] == 0 ) allvalid = 0;
  }
  printf("\n");

  if( !allvalid )
    test_fail(__FILE__,__LINE__,"case1",-1);

  retval = PAPI_cleanup_eventset(&EventSet);
  if (retval != PAPI_OK)
    test_fail(__FILE__,__LINE__,"PAPI_cleanup_eventset",retval);

  retval = PAPI_destroy_eventset(&EventSet);
  if (retval != PAPI_OK)
    test_fail(__FILE__,__LINE__,"PAPI_destroy_eventset",retval);<commit_msg>Wrapped a printf in case1 with TESTS_QUIET.<commit_after>/* 
* File:    multiplex1_pthreads.c
* CVS:     $Id$
* Author:  <NAME>
*          <EMAIL>
* Mods:    <NAME>
*          <EMAIL>
*/  

/* This file tests the multiplex pthread functionality when there are
 * threads in which the application isn't calling PAPI (and only
 * one thread that is calling PAPI.)
 *
 * This test will fail on most, if not all platforms due to signal handling.
 */ 

#include <pthread.h>
#include "papi_test.h"

#define NUM 10
#define NUM_THREADS 4
#define SUCCESS 1
#define FAILURE 0

extern void do_flops(int);
extern void do_reads(int);

extern int TESTS_QUIET; /* Declared in test_utils.c */

/* A thread function that does nothing forever, while the other
 * tests are running.
 */
void * thread_fn( void * dummy )
{
	while(1)
	  do_flops(10000);
}

void init_papi(void)
{
  int retval;

  /* Initialize the library */

  retval = PAPI_library_init(PAPI_VER_CURRENT);
  if (retval != PAPI_VER_CURRENT)
    test_fail(__FILE__,__LINE__,"PAPI_library_init",retval);

  if ((retval=PAPI_thread_init((unsigned long (*)(void))(pthread_self), 0)) != PAPI_OK){
     if (retval == PAPI_ESBSTR)
        test_skip(__FILE__,__LINE__,"PAPI_thread_init",retval);
     else
        test_fail(__FILE__,__LINE__,"PAPI_thread_init",retval);
  }

  /* Turn on automatic error reporting */

  retval = PAPI_set_debug(PAPI_VERB_ECONT);
  if (retval != PAPI_OK)
    test_fail(__FILE__,__LINE__,"PAPI_set_debug",retval);
}

/* Runs a bunch of multiplexed events */

int case1(void) 
{
  int retval, i, EventSet = PAPI_NULL, max_to_add = 6, j = 0;
  int allvalid = 1;
  long long *values;
  const PAPI_preset_info_t *pset;

  init_papi();

  pset = PAPI_query_all_events_verbose();
  if (pset == NULL)
    test_fail(__FILE__,__LINE__,"PAPI_query_all_events_verbose",0);

  retval = PAPI_multiplex_init();
  if (retval != PAPI_OK)
    test_fail(__FILE__,__LINE__,"PAPI_multiplex_init",retval);
  
  retval = PAPI_create_eventset(&EventSet);
  if (retval != PAPI_OK)
    test_fail(__FILE__,__LINE__,"PAPI_create_eventset",retval);

  retval = PAPI_set_multiplex(&EventSet);
  if (retval != PAPI_OK)
    test_fail(__FILE__,__LINE__,"PAPI_set_multiplex",retval);

  for (i=0;i<PAPI_MAX_PRESET_EVENTS;i++)
    {
      if ((pset->avail) && (pset->event_code != PAPI_TOT_CYC))
	{
	  if ( !TESTS_QUIET ) 
	    printf("Adding %s\n",pset->event_name);

	  retval = PAPI_add_event(&EventSet, pset->event_code);
	  if ((retval != PAPI_OK) && (retval != PAPI_ECNFLCT))
	    test_fail(__FILE__,__LINE__,"PAPI_add_event",retval);

	  if ( !TESTS_QUIET ) 
	    {
	      if (retval == PAPI_OK)
		printf("Added %s\n",pset->event_name);
	      else
		printf("Could not add %s\n",pset->event_name);
	    }

	  if (retval == PAPI_OK)
	    {
	      if (++j >= max_to_add)
		break;
	    }
	}
	pset++;
    }

  values = (long long *)malloc(max_to_add*sizeof(long long));
  if (values == NULL)
    test_fail(__FILE__,__LINE__,"malloc",0);

  if (PAPI_start(EventSet) != PAPI_OK)
    test_fail(__FILE__,__LINE__,"PAPI_start",retval);

  do_reads(10000);

  retval = PAPI_stop(EventSet, values);
  if (retval != PAPI_OK)
    test_fail(__FILE__,__LINE__,"PAPI_stop",retval);

  if ( !TESTS_QUIET ) {
    printf("case1:");
    for( i = 0; i < max_to_add; i++ ) {
      printf(" %lld", values[i]);

    /* There should be some sort of value for all events */
    if( values[i] == 0 ) allvalid = 0;
	}
    printf("\n");
  }

  if( !allvalid )
    test_fail(__FILE__,__LINE__,"case1",-1);

  retval = PAPI_cleanup_eventset(&EventSet);
  if (retval != PAPI_OK)
    test_fail(__FILE__,__LINE__,"PAPI_cleanup_eventset",retval);

  retval = PAPI_destroy_eventset(&EventSet);
  if (retval != PAPI_OK)
    test_fail(__FILE__,__LINE__,"PAPI_destroy_eventset",retval);
{'fraction_non_alphanumeric': 0.13844515441959532, 'fraction_numerical': 0.008386581469648562, 'mean_word_length': 3.9820954907161803, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4311134', 'n_tokens_mistral': 2943, 'n_tokens_neox': 2793, 'n_words': 579}