|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* Test case for appio
|
|
Packit |
577717 |
* Author: Tushar Mohan
|
|
Packit |
577717 |
* tusharmohan@gmail.com
|
|
Packit |
577717 |
*
|
|
Packit |
577717 |
* Description: This test case reads from standard linux /etc/group
|
|
Packit |
577717 |
* and writes the output to /dev/null
|
|
Packit |
577717 |
* Fread and fwrite are used for I/O.
|
|
Packit |
577717 |
* Statistics are printed at the end of the run.,
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
#include <papi.h>
|
|
Packit |
577717 |
#include <errno.h>
|
|
Packit |
577717 |
#include <stdio.h>
|
|
Packit |
577717 |
#include <stdlib.h>
|
|
Packit |
577717 |
#include <sys/types.h>
|
|
Packit |
577717 |
#include <sys/stat.h>
|
|
Packit |
577717 |
#include <fcntl.h>
|
|
Packit |
577717 |
#include <unistd.h>
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include "papi.h"
|
|
Packit |
577717 |
#include "papi_test.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#define NUM_EVENTS 8
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int main(int argc, char** argv) {
|
|
Packit |
577717 |
int Events[NUM_EVENTS];
|
|
Packit |
577717 |
const char* names[NUM_EVENTS] = {"READ_CALLS", "READ_BYTES","READ_USEC","READ_ERR", "READ_EOF", "WRITE_CALLS","WRITE_BYTES","WRITE_USEC"};
|
|
Packit |
577717 |
long long values[NUM_EVENTS];
|
|
Packit |
577717 |
|
|
Packit |
577717 |
char *infile = "/etc/group";
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Set TESTS_QUIET variable */
|
|
Packit |
577717 |
tests_quiet( argc, argv );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int version = PAPI_library_init (PAPI_VER_CURRENT);
|
|
Packit |
577717 |
if (version != PAPI_VER_CURRENT) {
|
|
Packit |
577717 |
fprintf(stderr, "PAPI_library_init version mismatch\n");
|
|
Packit |
577717 |
exit(1);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
if (!TESTS_QUIET) printf("This program will read %s and write it to /dev/null\n", infile);
|
|
Packit |
577717 |
FILE* fdin=fopen(infile, "r");
|
|
Packit |
577717 |
if (fdin == NULL) perror("Could not open file for reading: \n");
|
|
Packit |
577717 |
FILE* fout=fopen("/dev/null", "w");
|
|
Packit |
577717 |
if (fout == NULL) perror("Could not open file for writing: \n");
|
|
Packit |
577717 |
int bytes = 0;
|
|
Packit |
577717 |
char buf[1024];
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int retval;
|
|
Packit |
577717 |
int e;
|
|
Packit |
577717 |
for (e=0; e
|
|
Packit |
577717 |
retval = PAPI_event_name_to_code((char*)names[e], &Events[e]);
|
|
Packit |
577717 |
if (retval != PAPI_OK) {
|
|
Packit |
577717 |
fprintf(stderr, "Error getting code for %s\n", names[e]);
|
|
Packit |
577717 |
exit(2);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Start counting events */
|
|
Packit |
577717 |
if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK) {
|
|
Packit |
577717 |
fprintf(stderr, "Error in PAPI_start_counters\n");
|
|
Packit |
577717 |
exit(1);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
//if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK)
|
|
Packit |
577717 |
// handle_error(1);
|
|
Packit |
577717 |
//printf("After reading the counters: %lld\n",values[0]);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
while ((bytes = fread(buf, 1, 1024, fdin)) > 0) {
|
|
Packit |
577717 |
fwrite(buf, 1, bytes, fout);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
fclose(fdin);
|
|
Packit |
577717 |
fclose(fout);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Stop counting events */
|
|
Packit |
577717 |
if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK) {
|
|
Packit |
577717 |
fprintf(stderr, "Error in PAPI_stop_counters\n");
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (!TESTS_QUIET) {
|
|
Packit |
577717 |
printf("----\n");
|
|
Packit |
577717 |
for (e=0; e
|
|
Packit |
577717 |
printf("%s: %lld\n", names[e], values[e]);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
test_pass( __FILE__ );
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
}
|