lvc/api-sanity-checker

How to include system header files while building test cases generated by the tool?

anurag029 opened this issue · 15 comments

I have some confusion regarding working of this tool. I have created a shared object file (.so) of a project on Debian. The test cases are successfully generated but not a single test cases is successfully build. There are linking issues while test cases are build. There are system header files included in the source code, it seems that tool is unable to include those system header files while building the generated test cases. Please suggest how to make these generated test cases to successfully build. Thanks a lot.

lvc commented

Hi,

If the compiler cannot find a header (when compiling the test case) then try to add necessary system include paths (where this header should be found) to the input XML descriptor and regenerate tests:

<add_include_paths>
  /path1
  /path2
    ...
</add_include_paths>

If the test case doesn't include some header files then try to add them to the test_include_preamble section of the descriptor:

<test_include_preamble>
  /path1
  /path2
    ...
</test_include_preamble>

If there are linker (ld) errors occurred then try to add your custom options to the compiler:

<gcc_options>
  option1
  option2
    ...
</gcc_options>

Please point me to the code (if possible) where the problem is reproduced, so I can debug the tool and investigate why it doesn't generate correct make-files.

Thanks!

Thanks a lot lvc !

I have been using Hiawatha open source code for generating the shared library object and then running the tool for that .so file.

Thanks!

lvc commented

You mean hiawatha-webserver.org ?

Yeah, using source code of hiawatha webserver. Link for the sorce code download:

http://www.hiawatha-webserver.org/download

lvc commented

How did you compiled a shared object? Please also post the content of used XML descriptor.

Compiled the source code using cmake and then used

gcc -shared -o libhiawatha.so *.o

to generate .so file. then used that shared object library with the tool..

The Version.xml file used is

<version>
0.0.1
</version>

<headers>
/path to hiwatha headers/hiawatha-8.6/src/
</headers>

<libs>
/path to hiwatha shared library/hiawatha-8.6/
</libs>

<include_preamble>
/usr/include/netinet/in.h
/usr/include/sys/types.h
/usr/include/sys/wait.h
/usr/include/time.h
</include_preamble>

lvc commented

The file tests/hiawatha/0.0.1/scenario should contain paths to generated test cases. Please cd to one of them and check build_log file for errors.

There are 202 test cases generated in my environment.

lvc commented

The build of my tests has failed with:

libhiawatha.so: undefined reference to `crypt'
collect2: ld returned 1 exit status
make: *** [test] Error 1

And I fixed them by adding this section of the XML-descriptor and regenerating tests:

<gcc_options>
  -lcrypt
</gcc_options>

Have the test cases being build in your enviroment ?
I am getting the following errors in build_lod error file for one of the test case.

/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to ssl_cache_set' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tossl_set_hostname'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to net_recv' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tossl_read'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to ssl_set_ca_chain' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference torsa_free'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to ssl_set_own_cert' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tossl_set_min_version'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to ssl_set_rng' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tossl_set_sni'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to md5' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tossl_init'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to ssl_cache_free' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tossl_set_renegotiation'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to ssl_set_dh_param' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference toctr_drbg_random'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to base64_decode' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tox509parse_dn_gets'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to ssl_cache_set_max_entries' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tossl_get_bytes_avail'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to ctr_drbg_init' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tox509parse_crlfile'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to ssl_write' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference toentropy_init'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to x509parse_keyfile' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tossl_cache_get'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to ctr_drbg_set_prediction_resistance' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tossl_set_session_cache'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to ssl_set_authmode' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tossl_cache_init'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to ssl_set_dbg' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tossl_close_notify'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to ssl_set_bio' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tossl_set_ciphersuites'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to rsa_init' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tossl_handshake'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to crypt' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tossl_set_endpoint'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to entropy_func' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tossl_free'
/home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference to x509parse_crtfile' /home/Anurag/hiawatha-8.6/libhiawatha.so: undefined reference tonet_send'
collect2: ld returned 1 exit status
make: *** [test] Error 1

Thanks a lot for your responses.

Kindly share your xml descriptor.

lvc commented

Please also add -lpolarssl:

<gcc_options>
  -lcrypt
  -lpolarssl
</gcc_options>

This is, probably, a bug in the tool that it doesn't add this option automatically.

My descriptor is:

<version>
 0.0.1
</version>
<headers>
  /source-tree/src/
</headers>
<libs>
  /install-tree/hiawatha/
</libs>
<add_include_paths>
    /source-tree/polarssl/include/
</add_include_paths>
<gcc_options>
 -lcrypt
 -lpolarssl
</gcc_options>
<include_order>
 netinet/in.h:src/serverconfig.h
</include_order>
<include_preamble>
 netinet/in.h
 sys/types.h
 sys/wait.h
 time.h
</include_preamble>

api-sanity-checker -l hiawatha -d desc.xml -gen -build -run

Using GCC 4.6.1 (i586-mandriva-linux-gnu)
checking header(s) 0.0.1 ...
creating library ABI dump ...
generating tests: 202/202 [100.00%], success/fail: 202/0    
1. see generated test suite in the directory 'tests/hiawatha/0.0.1/'
2. for viewing tests use 'tests/hiawatha/0.0.1/view_tests.html'
3. use -build option for building tests
building tests: 202/202 [100.00%], success/fail: 192/10    
running tests: 192/192 [100.00%], success/fail: 147/45    
creating report ...
see test results in the file:
  test_results/hiawatha/0.0.1/test_results.html

On adding

<gcc_options>
-lcrypt
-lpolarssl
<gcc_options>

in XML descriptor adds the option in CFLAGS variable of Makefile of each test.c generated, that's why test build is failing for every test case. The given options must be added in LIBS variable of the Makefile. Here is sample Makefile generated :

CC = gcc
CFLAGS = -Wall -lpolarssl -lcrypt
INCLUDES = -I/home/Anurag/polarssl-1.2.3/include/polarssl -I/home/Anurag/hiawatha-8.6 -I/usr/lib/gcc/i486-linux-gnu/4.4/include
LIBS = /usr/lib/libnet.so.1 /usr/lib/libxslt.so.1 -L/home/Anurag/hiawatha-8.6 -lxml2 -lssl -lhiawatha -lpthread

all: test

test: test.c
$(CC) $(CFLAGS) $(INCLUDES) test.c -o test $(LIBS)

clean:
rm -f test test.o

Kindly guide what we have to add in XML Descriptor so that the options -lpolarssl and -lcrypt are added in LIBS variable not in CFLAGS variable of all the Makefiles generated.

Thanks!

This is fixed in 1.98.2. Please update. You need no any changes in the input descriptor.