Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: don't know how to compile with CUnit framework..

  1. #1
    Join Date
    Jun 2010
    Location
    india
    Beans
    207
    Distro
    Ubuntu 12.10 Quantal Quetzal

    don't know how to compile with CUnit framework..

    i went to this site--
    http://w3.scs.ryerson.ca/~schi/cps707/

    In "users without administration permission", it is written here--
    "The files required for compiling will be found in the CUnit/include and CUnit/lib directories".But after extracting the files i am not able to find include and lib...i am including some screenshots what i am getting...please tell me how to compile it...
    Attached Images Attached Images

  2. #2
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,223
    Distro
    Kubuntu

    Re: don't know how to compile with CUnit framework..

    Step 1: Download CUnit package from Source Forge.

    Step 2: Find where you saved the package on your system, and uncompress it:
    Code:
    tar xjf CUnit-2.1-2-src.tar.bz2
    Step 3: Go into the CUnit-2.1.2 directory.
    Code:
    cd CUnit-2.1.2
    Step 4: Run the following sequence of commands:
    Code:
    mkdir -p $HOME/local
    ./configure --prefix=$HOME/local
    make clean
    make
    make install
    Step 5: Goto the directory $HOME/local. Verify that you have the following sub-directories: doc, include, lib, and share. Each of these should have the products you seek.

    Step 6. To build an application using CUnit, something like this is used:
    Code:
    gcc -Wall -I$HOME/local/include MyProg.c -L$HOME/local/lib -lcunit -o myprog
    Note: In your source code, include CUnit header files such as:
    Code:
    #include <CUnit/CUnit.h>
    ...
    Last edited by dwhitney67; April 12th, 2011 at 10:02 AM.

  3. #3
    Join Date
    Jun 2010
    Location
    india
    Beans
    207
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: don't know how to compile with CUnit framework..

    Thanks...now i am able to locate those files...but i am getting error after compilation--

    praveen@praveen-laptop:~/Desktop/one$ gcc -Wall -I$HOME/local/include/CUnit Basic_Simple.c -L$HOME/local/lib -lcunit -o Basic_Simple

    praveen@praveen-laptop:~/Desktop/one$ ./Basic_Simple

    ./Basic_Simple: error while loading shared libraries: libcunit.so.1: cannot open shared object file: No such file or directory

    i am trying to run this first time so please help....

  4. #4
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,223
    Distro
    Kubuntu

    Re: don't know how to compile with CUnit framework..

    Quote Originally Posted by Praveen30 View Post

    ./Basic_Simple: error while loading shared libraries: libcunit.so.1: cannot open shared object file: No such file or directory
    Sorry about that; I forgot to offer the instructions to run your application. Try something like:
    Code:
    LD_LIBRARY_PATH=$HOME/local/lib ./Basic_Simple
    Alternatively, you can add the LD_LIBRARY_PATH to your ~/.bashrc file, thus making it available each/every time you log in. Something like:
    Code:
    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$HOME/local/lib
    If you go this way, please source your ~/.bashrc file, then run your program:
    Code:
    <edit ~/.bashrc>
    
    source ~/.bashrc
    
    ./Basic_Simple

  5. #5
    Join Date
    Jun 2010
    Location
    india
    Beans
    207
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: don't know how to compile with CUnit framework..

    Quote Originally Posted by dwhitney67 View Post
    Sorry about that; I forgot to offer the instructions to run your application. Try something like:
    Code:
    LD_LIBRARY_PATH=$HOME/local/lib ./Basic_Simple
    Alternatively, you can add the LD_LIBRARY_PATH to your ~/.bashrc file, thus making it available each/every time you log in. Something like:
    Code:
    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$HOME/local/lib
    If you go this way, please source your ~/.bashrc file, then run your program:
    Code:
    <edit ~/.bashrc>
    
    source ~/.bashrc
    
    ./Basic_Simple
    Hats off to you.
    Thanks a lot!!!!

  6. #6
    Join Date
    Jun 2010
    Location
    india
    Beans
    207
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: don't know how to compile with CUnit framework..

    Can you tell me one more thing after executing commands, i am getting this--
    PHP Code:
         CUnit A unit testing framework for Version 2.1-2
         http
    ://cunit.sourceforge.net/


    SuiteSimple_suite1
      Test
    test of maxi ...FAILED
        1. Basic_Simple
    .c:34  CU_ASSERT_EQUAL(maxi(3,6),3)

    Run Summary:    Type  Total    Ran Passed Failed Inactive
                             suites      1         1     n
    /a     0           0
                              tests       1         1      0       1           0
                            asserts     2          2     1        1         n
    /a

    Elapsed time 
    =    0.000 seconds
    Testing completes
    .. 
    can you please explain these things...what is this n/a and all other things in short.....???
    Last edited by Praveen30; April 12th, 2011 at 03:09 PM.

  7. #7
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,223
    Distro
    Kubuntu

    Re: don't know how to compile with CUnit framework..

    n/a is an abbreviation for "not applicable".

    The results you posted, which by the way would have looked better if enclosed in CODE tags, merely offer a summary of the test results.

    For example, the following test program from the CUnit web-site produces the following results:
    Code:
         CUnit - A unit testing framework for C - Version 2.1-2
         http://cunit.sourceforge.net/
    
    
    Suite: Suite_1
      Test: test Deposit ...passed
      Test: test Withdraw ...passed
      Test: test set balance ...passed
      Test: test get balance ...FAILED
        1. testBank.c:35  - CU_ASSERT_EQUAL(getBalance(),5000)
    
    Run Summary:    Type  Total    Ran Passed Failed Inactive
                  suites      1      1    n/a      0        0
                   tests      4      4      3      1        0
                 asserts      4      4      3      1      n/a
    
    Elapsed time =    0.000 seconds
    As indicated above, only one test suite exists, and thus only one was executed. Test suites are not evaluated for pass/fail, thus in the Passed column "n/a" is shown.

    In the test suite, there are 4 tests, of which each was executed. Of these tests, 3 Passed and 1 Failed.

    There were a total of 4 assert() calls in the test suite (this does not imply that there is 1 assert() per test, but in this case it is probably true). Anyhow, 3 succeeded and 1 failed.
    Last edited by dwhitney67; April 12th, 2011 at 09:31 PM. Reason: Edited URL for CUnit Example

  8. #8
    Join Date
    Feb 2012
    Beans
    1

    Re: don't know how to compile with CUnit framework..

    Hi,

    I am new to CUnit frame work .. Can you please share a basic program which help in crating test cases.

    Suppose we want to test a max function ...
    My .c file is like this

    # include <stdio.h>
    # include <stdlib.h>

    /*int main ()
    {
    int maxi(int, int);
    int i=2;
    int j=4;
    int result = maxi(i,j);
    return 0;
    }
    */

    int maxi(int i1, int i2)
    {
    return (i1 > i2) ? i1 : i2;
    }

    and the test file is

    # include <stdio.h>
    # include <stdlib.h>
    # include <CUnit/CUnit.h>
    # include "max.c"

    int main ()
    {

    CU_ASSERT( maxi(2, 4) == 4);
    CU_ASSERT( maxi(0,-4) == 0);
    CU_ASSERT( maxi(2, 2) == 2);
    }

    When i am running this code then m getting error as
    CU_assertImplementation: Assertion `((void *)0) != f_pCurSuite' failed.


    Please help

  9. #9
    Join Date
    Aug 2012
    Beans
    538

    Re: don't know how to compile with CUnit framework..

    Quote Originally Posted by dwhitney67 View Post
    Step 1: Download CUnit package from Source Forge.

    Step 2: Find where you saved the package on your system, and uncompress it:
    Code:
    tar xjf CUnit-2.1-2-src.tar.bz2
    Step 3: Go into the CUnit-2.1.2 directory.
    Code:
    cd CUnit-2.1.2
    Step 4: Run the following sequence of commands:
    Code:
    mkdir -p $HOME/local
    ./configure --prefix=$HOME/local
    make clean
    make
    make install
    Step 5: Goto the directory $HOME/local. Verify that you have the following sub-directories: doc, include, lib, and share. Each of these should have the products you seek.

    Step 6. To build an application using CUnit, something like this is used:
    Code:
    gcc -Wall -I$HOME/local/include MyProg.c -L$HOME/local/lib -lcunit -o myprog
    Note: In your source code, include CUnit header files such as:
    Code:
    #include <CUnit/CUnit.h>
    ...
    dwhitney, I'm sorry to revive a 1-year old thread, but I promise not to make too many posts here. Just had a doubt regarding the compilation steps mentioned in step4.
    Why is it that if you follow the normal procedure, by which I mean
    Code:
    ./configure
    make clean
    make 
    make install
    it won't work ?

    If it works on a directory called $HOME/local, then , it should work on say, the /$HOME/Desktop also right, which is the default path for me when I open a terminal ?

    Of course, thanks to you, I have it working, but I was stuck for a few days, because the normal procedure doesn't work and I didn't know that you have a create a directory called $HOME/local.

    For future purposes.. how are users supposed to know of these special steps/considerations while building a software from source ?

    Thanks.

  10. #10
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,297
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: don't know how to compile with CUnit framework..

    It probably does not matter at all where CUnit is installed. I haven't read the thread but perhaps dwhitney67 said to install it in $HOME because OP does not have root privileges, or something of that sort. Anyway, what matters is that after you have installed CUnit, wherever that may be, you have to make the compiler aware of where to find the headers and libraries. This is exactly what the -I and -L flags do in step 6 above. If you installed CUnit somewhere else, you just specify that path instead of $HOME/local, and it will work just as well.
    「明後日の夕方には帰ってるからね。」


Page 1 of 2 12 LastLast

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
  •