Blame src/ftests/strtest.F

Packit 577717
C  Strtest - Perform some basic tests of the functionality of the
Packit 577717
C  string passing to and from the PAPI Fortran interface. 
Packit 577717
C
Packit 577717
C    Test 1: Look up an event name from an event code. Use this name
Packit 577717
C            to try and locate the event code using the name received.
Packit 577717
C            Long, short and too short strings are used in the tests
Packit 577717
C
Packit 577717
C    Test 2: Look up a PAPI error string. Use long, short and too 
Packit 577717
C            short strings to store the result.
Packit 577717
C
Packit 577717
C    Test 3: Look up and display event descriptions 
Packit 577717
C            using PAPIf_get_event_info.
Packit 577717
C
Packit 577717
C    Comments:
Packit 577717
C    When using the Fortran interface it may not always be possible to
Packit 577717
C    use the PAPI predefined constants as actual arguments. Due to the
Packit 577717
C    values in these compilers might occasionally cast these into the
Packit 577717
C    wrong type. In the code below the line code=MSGCODE is used to 
Packit 577717
C    make sure that the event code get the right type.
Packit 577717
C
Packit 577717
#include "fpapi_test.h"
Packit 577717
C Set MSGLEN to the number of characters in the named event in MSGCODE
Packit 577717
#define MSGLEN 11
Packit 577717
#define MSGCODE PAPI_L1_DCM 
Packit 577717
#define ERRCODE PAPI_EINVAL
Packit 577717
       
Packit 577717
      program strtest
Packit 577717
      implicit integer (p)
Packit 577717
      
Packit 577717
      CHARACTER*(PAPI_MAX_STR_LEN) papistr
Packit 577717
      CHARACTER*(PAPI_MAX_STR_LEN*2) papidblstr
Packit 577717
Packit 577717
      CHARACTER*(PAPI_MAX_STR_LEN) ckstr
Packit 577717
      CHARACTER*(MSGLEN) invstr1
Packit 577717
      CHARACTER*(MSGLEN+1) invstr2
Packit 577717
      CHARACTER*(MSGLEN+2) invstr3
Packit 577717
      CHARACTER*(MSGLEN-1) invstr4
Packit 577717
      CHARACTER*(MSGLEN-2) invstr5
Packit 577717
Packit 577717
      integer check,lastchar
Packit 577717
      integer code,papicode
Packit 577717
      integer getstrlen
Packit 577717
      external getstrlen
Packit 577717
      integer tests_quiet, get_quiet
Packit 577717
      external get_quiet
Packit 577717
Packit 577717
      tests_quiet = get_quiet()
Packit 577717
Packit 577717
      check=PAPI_VER_CURRENT
Packit 577717
      call PAPIF_library_init(check)
Packit 577717
      if ( check.NE.PAPI_VER_CURRENT) then
Packit 577717
           call PAPIF_perror( 'PAPI_library_init' )
Packit 577717
        call ftest_fail(__FILE__, __LINE__,
Packit 577717
     . 'PAPI_library_init', check)
Packit 577717
      end if
Packit 577717
Packit 577717
      code=MSGCODE
Packit 577717
Packit 577717
      if (tests_quiet .EQ. 0) then
Packit 577717
         print *,'---------------------------------------------------'
Packit 577717
         print *,'   Testing PAPIF_name_to_code/PAPIF_code_to_name   '
Packit 577717
         print *,'---------------------------------------------------'
Packit 577717
         print *,' These tests look up an event name and event code'
Packit 577717
         print *,' On no occasion should a NULL character be found(+)'
Packit 577717
         print *,' When strings are too short, the lookup should fail'
Packit 577717
         print *
Packit 577717
         print *,' Tests use the event code ',code
Packit 577717
         print *
Packit 577717
       end if
Packit 577717
Packit 577717
      lastchar=PAPI_MAX_STR_LEN
Packit 577717
      call checkstr(code,ckstr,check,lastchar,tests_quiet)
Packit 577717
      lastchar=getstrlen(ckstr)
Packit 577717
 
Packit 577717
      call checkstr(code,invstr1,check,lastchar,tests_quiet)
Packit 577717
Packit 577717
      call checkstr(code,invstr2,check,lastchar,tests_quiet)
Packit 577717
Packit 577717
      call checkstr(code,invstr3,check,lastchar,tests_quiet)
Packit 577717
Packit 577717
      call checkstr(code,invstr4,check,lastchar,tests_quiet)
Packit 577717
Packit 577717
      call checkstr(code,invstr5,check,lastchar,tests_quiet)
Packit 577717
Packit 577717
      if (tests_quiet .EQ. 0) then
Packit 577717
         print *,'---------------------------------------------------'
Packit 577717
         print *,'          Testing PAPIF_descr_event                '
Packit 577717
         print *,'---------------------------------------------------'
Packit 577717
         print *,' These tests should return a PAPI description for'
Packit 577717
         print *,' various event names and argument shapes.'
Packit 577717
         print *,' On no occasion should a NULL character be found(+)'
Packit 577717
         print *
Packit 577717
Packit 577717
         print 200,'Test 1'
Packit 577717
      end if
Packit 577717
Packit 577717
      papistr="  "
Packit 577717
      papicode=PAPI_L1_DCM
Packit 577717
      call test_papif_descr(papistr,papicode,papidblstr,
Packit 577717
     .  check,tests_quiet)
Packit 577717
      call checkcode(papicode,PAPI_L1_DCM,tests_quiet)
Packit 577717
Packit 577717
      if (tests_quiet .EQ. 0) then
Packit 577717
         print *
Packit 577717
         print 200,'Test 2'
Packit 577717
      end if
Packit 577717
Packit 577717
      papistr="  "
Packit 577717
      papicode=PAPI_L2_DCM
Packit 577717
      call test_papif_descr(papistr,papicode,papidblstr,
Packit 577717
     .  check,tests_quiet)
Packit 577717
      call checkname(papistr,"PAPI_L2_DCM",tests_quiet)
Packit 577717
Packit 577717
      if (tests_quiet .EQ. 0) then
Packit 577717
         print *
Packit 577717
         print 200,'Test 3'
Packit 577717
      end if
Packit 577717
Packit 577717
      invstr1="  "
Packit 577717
      papicode=PAPI_L1_ICM
Packit 577717
      call test_papif_descr(invstr1,papicode,papidblstr,
Packit 577717
     .  check,tests_quiet)
Packit 577717
      call checkcode(papicode,PAPI_L1_ICM,tests_quiet)
Packit 577717
Packit 577717
      if (tests_quiet .EQ. 0) then
Packit 577717
          print *
Packit 577717
          print 200,'Test 4'
Packit 577717
      end if
Packit 577717
Packit 577717
      invstr1="  "
Packit 577717
      papicode=PAPI_L2_ICM
Packit 577717
      call test_papif_descr(invstr1,papicode,papidblstr,
Packit 577717
     .  check,tests_quiet)
Packit 577717
      call checkname(invstr1,"PAPI_L2_ICM",tests_quiet)
Packit 577717
Packit 577717
      if (tests_quiet .EQ. 0) then
Packit 577717
         print *
Packit 577717
         print 200,'Test 5  (This should get a truncated description)'
Packit 577717
      end if
Packit 577717
Packit 577717
      invstr2="  "
Packit 577717
      papicode=PAPI_L3_DCM
Packit 577717
      call test_papif_descr(invstr2,papicode,invstr1,
Packit 577717
     .  check,tests_quiet)
Packit 577717
      call checkcode(papicode,PAPI_L3_DCM,tests_quiet)
Packit 577717
Packit 577717
      if (tests_quiet .EQ. 0) then
Packit 577717
         print *
Packit 577717
         print 200,'Test 6  (This should get a truncated description)'
Packit 577717
      end if
Packit 577717
Packit 577717
      invstr2="  "
Packit 577717
      papicode=PAPI_L3_ICM
Packit 577717
      call test_papif_descr(invstr2,papicode,invstr1,
Packit 577717
     .  check,tests_quiet)
Packit 577717
      call checkname(invstr2,"PAPI_L3_ICM",tests_quiet)
Packit 577717
Packit 577717
      if (tests_quiet .EQ. 0) then
Packit 577717
         print *
Packit 577717
         print 200,'Test 7  (This should get a truncated name)'
Packit 577717
      end if
Packit 577717
Packit 577717
      invstr4="  "
Packit 577717
      papicode=PAPI_L1_DCM
Packit 577717
      call test_papif_descr(invstr4,papicode,papistr,
Packit 577717
     .  check,tests_quiet)
Packit 577717
      if (tests_quiet .EQ. 0) then
Packit 577717
         call checkname(invstr4,"PAPI_L1_DCM",tests_quiet)
Packit 577717
      end if
Packit 577717
Packit 577717
 200  format(t1,a)
Packit 577717
Packit 577717
      if (tests_quiet .EQ. 0) then
Packit 577717
         print *,'---------------------------------------------------'
Packit 577717
         print *,'(+) Fortran implementations that do not provide the'
Packit 577717
         print *,'    string argument length might show NULL '//
Packit 577717
     .           'characters.'
Packit 577717
         print *,'    This may or may not be OK depending on the '//
Packit 577717
     .           'Fortran'
Packit 577717
         print *,'    compiler. See papi_fwrappers.c and your Fortran'
Packit 577717
         print *,'    compiler reference manual.'
Packit 577717
      end if
Packit 577717
Packit 577717
      call ftests_pass(__FILE__)      
Packit 577717
      end
Packit 577717
Packit 577717
      subroutine checkstr(incode,string,check,lastchar,quiet)
Packit 577717
      implicit integer (P)
Packit 577717
      integer incode
Packit 577717
      integer check,lastchar, quiet
Packit 577717
      character*(*) string
Packit 577717
      integer code
Packit 577717
      integer getstrlen
Packit 577717
      external getstrlen
Packit 577717
Packit 577717
 100  format(t1,a,i4)
Packit 577717
Packit 577717
      if (quiet .EQ. 0) then
Packit 577717
         print 100,"Testing string length ",len(string)
Packit 577717
         if(len(string).lt.lastchar)then
Packit 577717
            print *,'This call should return an error code.'
Packit 577717
         end if
Packit 577717
      end if
Packit 577717
Packit 577717
      code=incode
Packit 577717
      call PAPIF_event_code_to_name(code,string,check)
Packit 577717
      if(check.ne.PAPI_OK)then
Packit 577717
        if (len(string).ge.lastchar)then
Packit 577717
          call ftest_fail(__FILE__, __LINE__,
Packit 577717
     . 'PAPIF_event_code_to_name', check)
Packit 577717
        else
Packit 577717
        if (quiet .EQ. 0) then
Packit 577717
           call PAPIF_perror( 'PAPIF_event_code_to_name' )
Packit 577717
           print *,'*ERROR* '
Packit 577717
           print *,'******* '//'Error in checkstr using '//
Packit 577717
     $ 'PAPIF_event_code_to_name'
Packit 577717
        end if
Packit 577717
       end if
Packit 577717
      end if
Packit 577717
Packit 577717
 200  format(t1,a,'"',a,'"')
Packit 577717
      if (quiet .EQ. 0) then
Packit 577717
         print 200,'The event name is: ',string(1:getstrlen(string))
Packit 577717
      end if
Packit 577717
Packit 577717
      call PAPIF_event_name_to_code(string,code,check)
Packit 577717
      if(check.ne.PAPI_OK)then
Packit 577717
      if (len(string).ge.lastchar)then
Packit 577717
          call ftest_fail(__FILE__, __LINE__,
Packit 577717
     . 'PAPIF_event_name_to_code', check)
Packit 577717
      else
Packit 577717
      if (quiet .EQ. 0) then
Packit 577717
         call PAPIF_perror( 'PAPIF_event_name_to_code' )
Packit 577717
         print *,'*ERROR* '
Packit 577717
         print *,'******* '//'Error in checkstr using '//
Packit 577717
     $   'PAPIF_event_name_to_code'
Packit 577717
      end if
Packit 577717
      end if
Packit 577717
      end if
Packit 577717
      
Packit 577717
      call findnull(string,quiet)
Packit 577717
Packit 577717
      if (quiet .EQ. 0) then
Packit 577717
         print *
Packit 577717
      end if
Packit 577717
Packit 577717
      return
Packit 577717
      end
Packit 577717
Packit 577717
      subroutine test_papif_descr(name,code,string,check,quiet)
Packit 577717
      implicit integer (P)
Packit 577717
      integer code,count,flags
Packit 577717
      integer check,quiet
Packit 577717
      character*(*) name,string
Packit 577717
Packit 577717
      character*(PAPI_MAX_STR_LEN) label,note
Packit 577717
      integer getstrlen
Packit 577717
      external getstrlen
Packit 577717
Packit 577717
C      This API was deprecated with PAPI 3
Packit 577717
C      call PAPIF_describe_event(name,code,string,check)
Packit 577717
      call PAPIF_get_event_info(code,name,string,label,count,
Packit 577717
     $     note,flags,check)
Packit 577717
 100  format(t1,a,'"',a,'"')
Packit 577717
      if (quiet .EQ. 0) then
Packit 577717
        print 100,'The event description is: ',
Packit 577717
     $    string(1:getstrlen(string))
Packit 577717
      end if
Packit 577717
Packit 577717
      if(check.ne.PAPI_OK)then
Packit 577717
      if (quiet .EQ. 0) then
Packit 577717
          call PAPIF_perror( 'PAPI_get_event_info' )
Packit 577717
          print *,'*ERROR* '
Packit 577717
          print *,'******* '//'Error in test_papif_descr using '//
Packit 577717
     $      'PAPIF_get_event_info'
Packit 577717
      else
Packit 577717
          call ftest_fail(__FILE__, __LINE__,
Packit 577717
     . 'PAPIF_get_event_info', check)
Packit 577717
        end if
Packit 577717
      end if
Packit 577717
Packit 577717
      call findnull(string,quiet)
Packit 577717
      call findnull(name,quiet)
Packit 577717
Packit 577717
      return
Packit 577717
      end
Packit 577717
Packit 577717
      integer function getstrlen(string)
Packit 577717
      implicit integer (P)
Packit 577717
      character*(*) string
Packit 577717
      integer i
Packit 577717
Packit 577717
      do i=len(string),1,-1
Packit 577717
        if(string(i:i).ne.' ') then 
Packit 577717
          goto 20
Packit 577717
        end if
Packit 577717
      end do
Packit 577717
      getstrlen=0
Packit 577717
      return
Packit 577717
Packit 577717
 20   continue
Packit 577717
      getstrlen=i
Packit 577717
      return
Packit 577717
      end
Packit 577717
Packit 577717
      subroutine findnull(string,quiet)
Packit 577717
      implicit integer (P)
Packit 577717
      integer quiet,i
Packit 577717
      character*(*) string
Packit 577717
Packit 577717
      i=index(string,char(0))
Packit 577717
      if(i.gt.0)then
Packit 577717
        if(quiet.EQ.0)then
Packit 577717
           print *,'NULL character found in string!!!'
Packit 577717
        else
Packit 577717
            call ftest_fail(__FILE__, __LINE__,
Packit 577717
     . 'NULL character found in string!!!', 0)
Packit 577717
        end if
Packit 577717
      end if
Packit 577717
Packit 577717
      return
Packit 577717
      end
Packit 577717
Packit 577717
Packit 577717
      subroutine checkcode(code,check,quiet)
Packit 577717
      implicit integer (P)
Packit 577717
      integer code
Packit 577717
      integer check,quiet
Packit 577717
Packit 577717
      if(code.ne.check)then
Packit 577717
      if(quiet.EQ.0)then
Packit 577717
         print 100,'Code look up failed?'
Packit 577717
      else
Packit 577717
          call ftest_fail(__FILE__, __LINE__,
Packit 577717
     .   'Code look up failed?', 0)
Packit 577717
        end if
Packit 577717
      end if
Packit 577717
 100  format(t2,a)
Packit 577717
Packit 577717
      return
Packit 577717
      end
Packit 577717
Packit 577717
      subroutine checkname(name,check,quiet)
Packit 577717
      implicit integer (P)
Packit 577717
      character*(*) name
Packit 577717
      character*(*) check
Packit 577717
      integer i,quiet
Packit 577717
      integer getstrlen
Packit 577717
Packit 577717
      i=getstrlen(name)
Packit 577717
      if(name(1:i).ne.check)then
Packit 577717
        if (quiet .eq. 0) then
Packit 577717
           print 100,'PAPI name incorrect?'
Packit 577717
           print 110,'Got:      ',name(1:i)
Packit 577717
           print 110,'Expected: ',check
Packit 577717
        else
Packit 577717
          call ftest_fail(__FILE__, __LINE__,
Packit 577717
     .  'PAPI name incorrect?', 0)
Packit 577717
        end if
Packit 577717
      end if
Packit 577717
Packit 577717
 100  format(t2,a)
Packit 577717
 110  format(a12,'"',a,'"')
Packit 577717
Packit 577717
      return
Packit 577717
      end