Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
OJITestLoader Class Reference

#include <OJITestLoader.h>

Inheritance diagram for OJITestLoader:
Inheritance graph
[legend]
Collaboration diagram for OJITestLoader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS OJITestLoader ()
virtual ~OJITestLoader ()

Static Public Member Functions

static NS_METHOD Create (nsISupports *outer, const nsIID &aIID, void **aInstancePtr)

Private Member Functions

char ** loadTestList ()
TestResultrunTest (const char *testCase, const char *libName)
int countChars (char *buf, char ch)
void registerRes (TestResult *res, char *testCase)
TEST_TYPE getTestType (char *tc)

Private Attributes

PRFileDescfdResFile

Detailed Description

Definition at line 68 of file OJITestLoader.h.


Constructor & Destructor Documentation

Definition at line 46 of file OJITestLoader.cpp.

{

  TestResult* res = NULL;
  char** testCase = loadTestList();
  int i = 0;
  TEST_TYPE testType;

  if (!testCase) {
       fprintf(stderr, "ERROR: Can't load test list !\n");
       return;
  }
  if (!(fdResFile = PR_Open(OJI_TEST_RESULTS, PR_CREATE_FILE | PR_WRONLY, PR_IRWXU))) {
    fprintf(stderr, "ERROR: Can't open test results file !\n");
  }
  for(i=0; testCase[i]; i++) {
    res = NULL;
    switch(testType = getTestType(testCase[i])) {
    case(JNI):
      res = runTest(testCase[i], OJI_JNI_TESTS);
      break;
    case(JM):
      res = runTest(testCase[i], OJI_JM_TESTS);
      break;
    case(TM):
      res = runTest(testCase[i], OJI_TM_TESTS);
      break;
    case(LCM):
      res = runTest(testCase[i], OJI_LCM_TESTS);
      break;
    case(JMPTI):
      res = runTest(testCase[i], OJI_JMPTI_TESTS);
      break;
    default:
      fprintf(stderr, "Can't determine test type (%s)\n", testCase[i]);
    }  
    if (res)
      registerRes(res, testCase[i]);
    else
      registerRes(TestResult::FAIL("Test execution failed"), testCase[i]);
  }


}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 126 of file OJITestLoader.cpp.


Member Function Documentation

int OJITestLoader::countChars ( char *  buf,
char  ch 
) [private]

Definition at line 189 of file OJITestLoader.cpp.

                                                {
       char *pos = buf;
       int count = 0;

       while((pos = PL_strchr(pos, ch))) { 
              pos++;
              count++;
       }
       return count;
} 

Here is the call graph for this function:

Here is the caller graph for this function:

NS_METHOD OJITestLoader::Create ( nsISupports *  outer,
const nsIID aIID,
void **  aInstancePtr 
) [static]

Definition at line 218 of file OJITestLoader.cpp.

                                                                                          {
       OJITestLoader *tl = new OJITestLoader();
       if (!aInstancePtr)
              return NS_ERROR_NULL_POINTER;
       *aInstancePtr = nsnull;
       if (aIID.Equals(kISupportsIID)) 
              *aInstancePtr  = (void*)(nsISupports*)tl;
       if (aIID.Equals(kIOJITestLoaderIID))
              *aInstancePtr = (void*)tl;
       if(!(*aInstancePtr))
              return NS_ERROR_NO_INTERFACE;
       return NS_OK;
}

Here is the call graph for this function:

TEST_TYPE OJITestLoader::getTestType ( char *  tc) [private]

Definition at line 202 of file OJITestLoader.cpp.

                                             {
       char *buf = PL_strdup(tc);
       char *pos = PL_strchr(buf, '_');
       if (!pos)
              return (TEST_TYPE)-1;
       *pos = 0;
       for(int i=0; test_types[i]; i++) {
              if (!PL_strcmp(buf, test_types[i])) {
                     free(buf);
                     return (TEST_TYPE)i;
              }
       }
       free(buf);
       return (TEST_TYPE)-1;
}

Here is the call graph for this function:

char ** OJITestLoader::loadTestList ( ) [private]

Definition at line 133 of file OJITestLoader.cpp.

                                   {
       struct stat st;
       FILE *file = NULL;
       char *content;
       int nRead, nTests, count = 0;
       char *pos, *pos1;
       char **testList;

       if (stat(OJI_TESTS_LIST, &st) < 0) {
              fprintf(stderr, "ERROR: can't get stat from file %s\n", OJI_TESTS_LIST);
              return NULL;
       }
       content = (char*)calloc(1, st.st_size+1);
       if ((file = fopen(OJI_TESTS_LIST, "r")) == NULL) {
              fprintf(stderr, "ERROR: can't open file %s\n", OJI_TESTS_LIST);
              return NULL;
       }
       if ((nRead = fread(content, 1, st.st_size, file)) < st.st_size) {
              fprintf(stderr, "WARNING: can't read entire file in text mode (%d of %d) !\n", nRead, st.st_size);
              //return;
       }
       content[nRead] = 0;
       //printf("File content: %s\n", content);
       fclose(file);

       //allocate maximal possible size
       nTests = countChars(content, '\n') + 2;
       printf("nTests = %d\n", nTests);
       testList = (char**)calloc(sizeof(char*), nTests);
       testList[0] = 0;
       pos = content;
       while((pos1 = PL_strchr(pos, '\n'))) {
              *pos1 = 0;
              if(*pos && *pos != '#') {
                //printf("First char: %c\n", *pos);
                     testList[count++] = PL_strdup(pos);
              }
              pos = pos1+1;
              if (!(*pos)) {
                     printf("Parser done: %d .. ", count);
                     testList[count] = 0;
                     printf("ok\n");
                     break;
              }
       }
       //If there is no \n after last line
       if (*pos && *pos != '#') {
              testList[count++] = PL_strdup(pos);
              testList[count] = 0;
       }
       //free(content);
       return testList;
       
}

Here is the call graph for this function:

void OJITestLoader::registerRes ( TestResult res,
char *  testCase 
) [private]

Definition at line 111 of file OJITestLoader.cpp.

                                                        {
       char *outBuf = (char*)calloc(1, res->comment.Length() + PL_strlen(tc) + 100);
       
       sprintf(outBuf, "%s: %s (%s)\n", tc, res->status?"PASS":"FAILED", NS_LossyConvertUCS2toASCII(res->comment).get());
       if (fdResFile) {     
              printf("%s", outBuf);       
              if (PR_Write(fdResFile, outBuf, PL_strlen(outBuf)) < PL_strlen(outBuf))
                     fprintf(stderr, "WARNING: Can't write entire result message. Possibly not enough free disk space !\n");
       } else {
              printf("%s", outBuf);
       }
       free(outBuf);
}

Here is the call graph for this function:

TestResult * OJITestLoader::runTest ( const char *  testCase,
const char *  libName 
) [private]

Definition at line 92 of file OJITestLoader.cpp.

                                                                            {

  PRLibrary* lib = PR_LoadLibrary(libName);
  OJI_TESTPROC testProc = NULL; 

  if (lib) {
       testProc = (OJI_TESTPROC)PR_FindSymbol(lib, testCase);
       if (testProc) {
              return testProc();
       } else {
              fprintf(stderr, "WARNING: Can't find %s method in %s library\n", testCase, libName);
       }
  } else {
       fprintf(stderr, "WARNING: Can't load %s library\n", libName);
  }
  return NULL;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 87 of file OJITestLoader.h.


The documentation for this class was generated from the following files: