# How to write a robot test to check a C-function

**URL:** <https://forum.robotframework.org/t/how-to-write-a-robot-test-to-check-a-c-function/1300>\
**Category:** Robot Framework\
**Created:** [5 February 2021 16:54 UTC](https://forum.robotframework.org/t/how-to-write-a-robot-test-to-check-a-c-function/1300 "2021-02-05T16:54:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pfox](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@pfox](https://forum.robotframework.org/u/pfox)\
**Post date:** [5 February 2021 16:54 UTC](https://forum.robotframework.org/t/how-to-write-a-robot-test-to-check-a-c-function/1300/1 "2021-02-05T16:54:37Z")

</div>

In my example I use Visual Code with the plugin PlatformIO and the Robor framework on top of it.

I have written a simple application in which two numbers are added. The function that is used for this is in a separate .c and .h file.

Now to my question:  
Is it possible to write a test to call the function to add two numbers and check the returned result ?  
I am looking for a way to call specific functions of my C-code and thus check them.

Translated with [www.DeepL.com/Translator](http://www.DeepL.com/Translator) (free version)

---

<div class="post-metadata">

**Author:** ![rasjani](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@rasjani](https://forum.robotframework.org/u/rasjani)\
**Post date:** [6 February 2021 11:42 UTC](https://forum.robotframework.org/t/how-to-write-a-robot-test-to-check-a-c-function/1300/2 "2021-02-06T11:42:15Z")

</div>

It should be possible.

First, you need to expose your C code into python. Depending on the use-case you could look at [1. Extending Python with C or C++ — Python 3.9.1 documentation](https://docs.python.org/3/extending/extending.html) or [ctypes — A foreign function library for Python — Python 3.9.1 documentation](https://docs.python.org/3/library/ctypes.html)

Once you have python\<-\>c bridge working, then you make a keyword library out of those exposed C functions in python as you would do with any normal python code that you want to access in Robot: [Robot Framework User Guide](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#creating-test-libraries) - there might be some additional python code added on top of python → c call for type casting from robot keyword call to suitable ctypes would work…

---

<div class="post-metadata">

**Author:** ![pfox](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@pfox](https://forum.robotframework.org/u/pfox)\
**Post date:** [8 February 2021 14:05 UTC](https://forum.robotframework.org/t/how-to-write-a-robot-test-to-check-a-c-function/1300/3 "2021-02-08T14:05:24Z")

</div>

Thanks for your quick and helpful reply.

---

<div class="post-metadata">

**Author:** ![kumaraswamygaviyappa](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/kumaraswamygaviyappa/32/2131_2.png) [@kumaraswamygaviyappa](https://forum.robotframework.org/u/kumaraswamygaviyappa)\
**Post date:** [5 December 2022 19:41 UTC](https://forum.robotframework.org/t/how-to-write-a-robot-test-to-check-a-c-function/1300/4 "2022-12-05T19:41:03Z")

</div>

@pfox Hallo, are you able to achieve c and py bridge.
