Results 1 to 2 of 2

Thread: Testing through Shared Object File of Code

  1. #1
    Member honey bee's Avatar
    Join Date
    Feb 2006
    Location
    Pakistan
    Posts
    146

    Question Testing through Shared Object File of Code

    Hello!

    I have a shared object(.so) file of code.Now, i want to test the code.I want to knoe how to test the code now?.

    Also the code is given xml packet as an input.How can i provide these input to the code in order to test it?

  2. #2
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811
    You need to create a program in C or C++ which makes use of the functions provided from your .so file, since you havn't mentioned what share object you're reffering to, I cant be of any help, what so ever, to how you can make use of it, but for a small example, here's how the use of libpthread-0.10.so is tested..
    Code:
    #include <stdio.h>
    #include <pthread.h>
    
    pthread_mutex_t mutex; 
    
    void* id_me(void* n);
    
    int main()
    {
      int i, threads = 3; 
      pthread_t t_ptr[threads];
      pthread_mutex_init(&mutex, NULL);
      for(i=1; i <= threads; ++i)
        pthread_create(&t_ptr[i-1], NULL, id_me, (void*) i);
      id_me((void *)i);
      sleep(1); /* give the other threads some time to finish */
      return 0;
    }
     
    
    void* id_me(void* n)
    {
      int i;
      pthread_mutex_lock(&mutex);
      printf("Thread %d is awakened\n", (int)n);
      pthread_mutex_unlock(&mutex);
      for(i=0; i< 10; ++i){
        sleep(1); /* give the other threads some time to run */
        pthread_mutex_lock(&mutex);
        printf("Thread %d is alive for the %d time.\n", (int)n, i+1);
        pthread_mutex_unlock(&mutex);
      }
      pthread_mutex_lock(&mutex);
      printf("Thread %d is dying\n");
      pthread_mutex_unlock(&mutex);
      return NULL;
    }
    It is compiled by using:
    > gcc -o program -lpthread program.c
    Let me go through the importain lines:
    Code:
    #include <pthread.h>
    This tells teh compiler, we need the functions provided by libpthread made available
    Code:
    pthread_mutex_t mutex;
    From libpthread a handler is available, which is of type pthread_mutex_t so in order to handle our threads, we need this mutex as our variable to control the threads at hand
    Code:
    pthread_t t_ptr[threads];
    For us to have more control of the threads, we need container, this is of type pthread_t which again is a type provided by libpthread
    Code:
    pthread_mutex_init(&mutex, NULL);
    Here we initialize our thread handler, so we now have a live mutex to interact with our threads through
    Code:
    pthread_create(&t_ptr[i-1], NULL, id_me, (void*) i);
    Now we create the seperate threads we want to use, remember the parent thread (this main function) will remain as a thread aswell, but since it is initializing every other part it dosn't need to be created as a pthread.
    Code:
     pthread_mutex_lock(&mutex);
    Since we can't have two (or more) threads filling any output buffer, even stdout, at the same time since it would garble the output, we need to lock any threads running in the background, here our mutex variable comes in handy
    Code:
    pthread_mutex_unlock(&mutex);
    Once we're through using handling of vital parts, where we can't have any interchanging from other threads, we need to tell the mutex that it is OK to let other threads have a go at it.

    And when compiling, the flag -lpthread tells the linker to link our program with the systems pthread implementation.
    If you're on a BSD deriviate, your link flag should be -lpthreads with the addition of a -D_GNU_SOURCE flag, same goes if you're on a HP_UX system.

    As to XML usage, read up on the XML standard, and form a file, which conforms with the standards, to test what you need to test.

    Crap, I'm giving away all the good stuff here
    Last edited by redhead; 07-27-2006 at 12:31 PM.
    Don't worry Ma'am. We're university students, - We know what We're doing.
    'Ruiat coelum, fiat voluntas tua.'
    Datalogi - en livsstil; Intet liv, ingen stil.

Similar Threads

  1. object file not supporting kernel version
    By misbah_khan in forum Linux - General Topics
    Replies: 1
    Last Post: 11-27-2006, 07:02 AM
  2. libXmu.so: cannot open shared object file: Too many levels of symbolic links
    By shupi in forum Linux - Software, Applications & Programming
    Replies: 0
    Last Post: 07-04-2006, 05:18 AM
  3. libXmu.so: cannot open shared object file
    By shupi in forum Linux - General Topics
    Replies: 0
    Last Post: 07-02-2006, 09:49 AM
  4. Possible to get different object files from the same source code & toolchain?
    By josaiah in forum Linux - Software, Applications & Programming
    Replies: 3
    Last Post: 10-17-2002, 02:24 AM
  5. Object Oriented question.
    By cloverm in forum Linux - Software, Applications & Programming
    Replies: 28
    Last Post: 03-25-2002, 01:11 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •