|
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 does a strided read of /etc/group
|
|
Packit |
577717 |
* and writes the output to stdout.
|
|
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 |
#define NUM_EVENTS 7
|
|
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_BLOCK_SIZE", "READ_USEC", "SEEK_CALLS", "SEEK_USEC", "SEEK_ABS_STRIDE_SIZE"};
|
|
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 |
|
|
Packit |
577717 |
int fdin;
|
|
Packit |
577717 |
if (!TESTS_QUIET) printf("This program will do a strided read %s and write it to stdout\n", infile);
|
|
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 |
fdin=open(infile, O_RDONLY);
|
|
Packit |
577717 |
if (fdin < 0) perror("Could not open file for reading: \n");
|
|
Packit |
577717 |
int bytes = 0;
|
|
Packit |
577717 |
char buf[1024];
|
|
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 = read(fdin, buf, 32)) > 0) {
|
|
Packit |
577717 |
write(1, buf, bytes);
|
|
Packit |
577717 |
lseek(fdin, 16, SEEK_CUR);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Closing the descriptors before doing the PAPI_stop
|
|
Packit |
577717 |
means, OPEN_FDS will be reported as zero, which is
|
|
Packit |
577717 |
right, since at the time of PAPI_stop, the descriptors
|
|
Packit |
577717 |
we opened have been closed */
|
|
Packit |
577717 |
close (fdin);
|
|
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 |
}
|