OVP Forums - A community of assistance, help, questions, and answers.
  FAQFAQ    SearchSearch      RegisterRegister  ProfileProfile    Log in to check your private messagesLog in to check your private messages    Log inLog in
Comiplation of harness.c with gcc

 
Post new topic   Reply to topic    Open Virtual Platforms Forum Index -> Ask a Question
View previous topic :: View next topic  
Author Message
AmmarTanveer



Joined: 24 Nov 2018
Posts: 8

PostPosted: Sun Jan 20, 2019 6:52 am    Post subject: Comiplation of harness.c with gcc Reply with quote

Hello,

I am trying to compile harness.c file from OP API (C API) with the help of GCC (MinGW).

Although, i have a make file for compilation but i want to make this harness.c file as a shared library (.dll) file with the help of GCC.

When i compile this (harness.c) file with GCC i get a error and don't know how to resolve it. Error is

fatal error: op/op.h: No such file or directory

^
compilation terminated.



Kindly help me if you can.
Back to top
View user's profile Send private message
DuncGrah
OVP Technologist
OVP Technologist


Joined: 27 Feb 2008
Posts: 1581
Location: United Kingdom

PostPosted: Mon Jan 21, 2019 12:46 am    Post subject: Reply with quote

Are you using the provided Makefile, Makefile.harness that is found at Imperas/ImperasLib/buildutils?

What is the reason you want harness as a shared library (dll)?
Back to top
View user's profile Send private message Visit poster's website
AmmarTanveer



Joined: 24 Nov 2018
Posts: 8

PostPosted: Mon Jan 21, 2019 7:06 am    Post subject: Reply with quote

Yes, i am using the provided make file present in Imperas/ImperasLib/buildutils.

I have done changes in this make file at line number 70 and 123 to get a .dll file.

At line 70, i changed EXECUTABLE to SHAREDOBJ.

At line 123, i wrote the name for my dll i.e in my case harness.dll.

Although these changes give me harness.dll file but i am unable to call any of the functions inside this (harness.dll).

Then i tried to compile my harness.c file using gcc command(gcc -shared -fPIC harness.c -o harness.dll), into a shared library(.dll file) but when i run gcc command for shared object it gives me error i mentioned in my first post i.e

fatal error: op/op.h: No such file or directory

^
compilation terminated.



Can you tell me how how to resolve this error and to be precise where can i find this header file (op/op.h) in the Imperas directory.

Secondly, the reason i want this harness as a shared library (dll) is because i want to call functions inside this(dll) through python.
Back to top
View user's profile Send private message
DuncGrah
OVP Technologist
OVP Technologist


Joined: 27 Feb 2008
Posts: 1581
Location: United Kingdom

PostPosted: Mon Jan 21, 2019 9:03 am    Post subject: Reply with quote

Can you take a look at Imperas/ImperasLib/buildutils/Makefile.platform as this supports a flow that generates both an exe and a shared library. A harness and a platform are very similar. This may show you how to build the shared library.

op/op.h is found at Imperas/ImpPublic/include/host/op/op.h
Back to top
View user's profile Send private message Visit poster's website
AmmarTanveer



Joined: 24 Nov 2018
Posts: 8

PostPosted: Mon Jan 21, 2019 11:04 am    Post subject: Reply with quote

Thank you very much for your guidance.

I will have a look and will post accordingly.
Back to top
View user's profile Send private message
AmmarTanveer



Joined: 24 Nov 2018
Posts: 8

PostPosted: Wed Jan 23, 2019 10:42 am    Post subject: Reply with quote

Hello,

I tried to call a function OPSessionInit using python Ctypes, which is now inside my harness.dll created from harness.c file(containing Platform and testbench/harness) but i am unable to call it . It shows me an error and a warning.

Warning (OP_RTLV) The runtime loader version (┬ѧjP·┬) does not match the version of op.h (3.0.1) that compiled this code.
Fatal (OP_CHK) opSessionInit: platform compiled with OP interface version 3.0.1, Product OP interface version is ┬ѧjP·┬ - please recompile Platform
Info Exiting


Can you explain this error and any suggestions to tackle with it.
Back to top
View user's profile Send private message
DuncGrah
OVP Technologist
OVP Technologist


Joined: 27 Feb 2008
Posts: 1581
Location: United Kingdom

PostPosted: Thu Jan 24, 2019 2:00 am    Post subject: Reply with quote

the shared library is intended to be loaded by a runtime loader module in the product. There is an initial check that the API versions used when the module and product were built are the same.
As you are pretending to be the 'product' with your Python which is loading the shared object this is failing.

This I will need to discuss with our engineering team to make sure it is actually possible, it should be but you will need to provide the correct interface requirements .. I guess. Sorry a little out of my area of knowledge doing this ;-)
Back to top
View user's profile Send private message Visit poster's website
MatthewHall
OVP Technologist
OVP Technologist


Joined: 26 Feb 2008
Posts: 84

PostPosted: Thu Jan 24, 2019 4:16 am    Post subject: Passing a python string into C Reply with quote

Hi Ammar,
If I understand, you are trying to call into OVPsim from Python. OPVsim has a C API. It is possible to call C functions from Python, but the Python argument types that you are passing will not always match the C argument types that you are calling. The symptom you are seeing is that the function opSessionInit() takes a C string as its only argument. The argument must be OP_VERSION from line #18 of op.h. The python string that you are passing is not compatible.

I am not an expert on C-to-Python interfacing but there is plenty of literature to help you on-line. Try:

http://www.swig.org a tool to create an interface between C and many languages, including Python.

https://docs.python.org/2/extending/extending.html official python documentation about C-Python interfaces.

https://www.scipy-lectures.org/advanced/interfacing_with_c/interfacing_with_c.html

Alternatively, it might be easier to write in C rather than Python.
Back to top
View user's profile Send private message
AmmarTanveer



Joined: 24 Nov 2018
Posts: 8

PostPosted: Thu Jan 24, 2019 2:33 pm    Post subject: Reply with quote

DuncGrah wrote:
the shared library is intended to be loaded by a runtime loader module in the product. There is an initial check that the API versions used when the module and product were built are the same.
As you are pretending to be the 'product' with your Python which is loading the shared object this is failing.

This I will need to discuss with our engineering team to make sure it is actually possible, it should be but you will need to provide the correct interface requirements .. I guess. Sorry a little out of my area of knowledge doing this ;-)


Thanks DuncGrah for your quick response.

I think you are right there is a problem with the interface and i have to pass the correct arguments.
Back to top
View user's profile Send private message
AmmarTanveer



Joined: 24 Nov 2018
Posts: 8

PostPosted: Thu Jan 24, 2019 2:45 pm    Post subject: Re: Passing a python string into C Reply with quote

MatthewHall wrote:
Hi Ammar,
If I understand, you are trying to call into OVPsim from Python. OPVsim has a C API. It is possible to call C functions from Python, but the Python argument types that you are passing will not always match the C argument types that you are calling. The symptom you are seeing is that the function opSessionInit() takes a C string as its only argument. The argument must be OP_VERSION from line #18 of op.h. The python string that you are passing is not compatible.

I am not an expert on C-to-Python interfacing but there is plenty of literature to help you on-line. Try:

http://www.swig.org a tool to create an interface between C and many languages, including Python.

https://docs.python.org/2/extending/extending.html official python documentation about C-Python interfaces.

https://www.scipy-lectures.org/advanced/interfacing_with_c/interfacing_with_c.html

Alternatively, it might be easier to write in C rather than Python.


Hi MatthewHall,
Yes, you got it right. I am trying to call into OVPsim from Python. To be precise i want to make calls in OP API using python.

Secondly, you have pointed that there is a mismatch between the arguments. I think you are right . I will try to resolve this issue by passing the correct arguments and will see what happens.
Anyhow, thank you for your suggestions and guidance.
Back to top
View user's profile Send private message
AmmarTanveer



Joined: 24 Nov 2018
Posts: 8

PostPosted: Thu Jan 24, 2019 2:45 pm    Post subject: Re: Passing a python string into C Reply with quote

MatthewHall wrote:
Hi Ammar,
If I understand, you are trying to call into OVPsim from Python. OPVsim has a C API. It is possible to call C functions from Python, but the Python argument types that you are passing will not always match the C argument types that you are calling. The symptom you are seeing is that the function opSessionInit() takes a C string as its only argument. The argument must be OP_VERSION from line #18 of op.h. The python string that you are passing is not compatible.

I am not an expert on C-to-Python interfacing but there is plenty of literature to help you on-line. Try:

http://www.swig.org a tool to create an interface between C and many languages, including Python.

https://docs.python.org/2/extending/extending.html official python documentation about C-Python interfaces.

https://www.scipy-lectures.org/advanced/interfacing_with_c/interfacing_with_c.html

Alternatively, it might be easier to write in C rather than Python.


Hi MatthewHall,
Yes, you got it right. I am trying to call into OVPsim from Python. To be precise i want to make calls in OP API using python.

Secondly, you have pointed that there is a mismatch between the arguments. I think you are right . I will try to resolve this issue by passing the correct arguments and will see what happens.
Anyhow, thank you for your suggestions and guidance.
Back to top
View user's profile Send private message
AmmarTanveer



Joined: 24 Nov 2018
Posts: 8

PostPosted: Mon Jan 28, 2019 11:14 am    Post subject: Functions to load application and harness Reply with quote

Hello ,

I am trying to load an application program by calling into OP API using python Ctypes.

First, i called the function opSessionInit() to initialize the session and its working.

Now, i want to load the application.


I have seen in the document"Writing_Platforms_and_Modules_in_C_User_Guide" that for loading the application program there is a function opCmdParseStd(). As far as, i understood it we pass arguments on the command line(Terminal) to load application and run the simulator.

harness/harness.windows32.exe --program application /application.
OR1K.elf




So, is there any function in the OP API(C API) to load application directly and we can run the simulator (after that application has been loaded) by using another function without passing any arguments through main() as in case of opCmdParseStd().

So, i am looking for three functions.

First, to load Application.
Second, to Load harness(Containing testbench+platform) which is harness.c
Third to run the simulator for this harness.

Looking for urgent help and thanks in advance.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Open Virtual Platforms Forum Index -> Ask a Question All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Information regarding OVP © 2008-2020 Imperas Software