1

I am looking for procedure or suggestions if this is do able or not.

I have source files or (object code) which is compiled on a MATLAB environment using embedded coder. Now I want to bring those source code into Python and perform a code performance test based on input test case.

For example: My object code contains a logic: Like, If int a = 7; int b 8; then int c = a+b;

Now I have to test the above logic using specified test case to really see my object code is doing what it is really designed for..

So, Is there any procedure or material available for me to learn on how to import object code/source files into Python and perform testing?

Thank.

3
  • 1
    I'm having a hard time understanding your question. Are you looking for a MATLAB to Python transpiler? Or are you looking for a test case generator? Commented Jun 19, 2019 at 1:41
  • Lets remove MATLAB from equation. So there's a bunch of source files or computed object code from source file. I need to write a test case to test the logic inside source code or object code. By using Python environment. I know we can do this in Visual studio. Commented Jun 19, 2019 at 2:40
  • 1
    ctypes are really cool, you can load code and inspect, invoke it etc.... It's very verbose Commented Jun 22, 2019 at 17:11

1 Answer 1

0
  1. If you could instead write the tests in MATLAB, software-in-the-loop (SIL) with Embedded Coder let you call the actual generated code from MATLAB just like any other function. Combining that with MATLAB unit testing frameworks, you can build up an automated test suite in MATLAB.

    cfg = coder.config('lib');
    cfg.VerificationMode = 'SIL';
    
    codegen foo.m -config cfg ...
    % Runs the generated code
    foo_sil(args); 
    
  2. Python provides several interfaces to C code. A popular one I've tried is ctypes:

    https://docs.python.org/3/library/ctypes.html

    You can use that to call the generated code.

  3. You can use a wrapper generator, like SWIG, to wrap generated code with Python bindings. That gives you a simple Python interface to the generated code. Examples that run on Linux here:

    https://github.com/mathworks/coder-swig

    that generate code, call SWIG to generate Python bindings, and build everything. With that you could then call the generated code from Python, Java, C#, or any other SWIG-supported language.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.