segmentation fault - jetlongjump ?

40 views
Skip to first unread message

ya...@infiswift.com

unread,
May 17, 2017, 5:26:42 PM5/17/17
to ThrowTheSwitch Forums
Hello,

I am new to Unity testing framework. I just downloaded the code from github and trying to run a simple program:

// file test1.c
#include <stdio.h>
#include <stdlib.h>
#include "unity.h"

int main()
{
    int a=2;
    TEST_ASSERT_TRUE(0);  //Gives segmentation fault TEST_ASSERT_TRUE(1); works (no fault
    printf("Hello this is test1.\n");
}

I compile using
gcc -c test1.c
gcc -c unity.c
gcc test1.o unity.o -o test1

Thanks

Yash

Mark Vander Voord

unread,
May 18, 2017, 7:55:58 AM5/18/17
to ThrowTheSwitch Forums
Yash:

Hi!

You're getting a segfault because the assertions use longjmp to immediately jump out of the test. This requires a properly formed setjmp ahead of time. This (and other accounting) are handled by the macros UNITY_BEGIN() and UNITY_END(). You need to call those before and after any tests. In addition, it's best to wrap your tests themselves in RUN_TEST macros. 

Your test would then look something like this:

// file test1.c
#include <stdio.h>
#include <stdlib.h>
#include "unity.h"

void test_firstTest(void)
{
    int a=2;
    TEST_ASSERT_TRUE(0);  //Gives segmentation fault TEST_ASSERT_TRUE(1); works (no fault
    printf("Hello this is test1.\n");
}

int main(void)
{
    UNITY_BEGIN();
    RUN_TEST(test_firstTest, 5);
    return UNITY_END();
}

You can find more information about this in the documentation folder. In particular, check out the file UnityGettingStartedGuide.md

Best of luck!

Mark 


--
You received this message because you are subscribed to the Google Groups "ThrowTheSwitch Forums" group.
To unsubscribe from this group and stop receiving emails from it, send an email to throwtheswitc...@googlegroups.com.
To post to this group, send email to throwth...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/throwtheswitch/2f68bb59-65c3-4636-a9d5-76364bff4ca4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yashwant Shitoot

unread,
May 18, 2017, 11:30:05 PM5/18/17
to throwth...@googlegroups.com
Hello Mark,

Thanks I will try it out tomorrow morning.

Yash

Yashwant Shitoot

To unsubscribe from this group and stop receiving emails from it, send an email to throwtheswitch+unsubscribe@googlegroups.com.
To post to this group, send email to throwtheswitch@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "ThrowTheSwitch Forums" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/throwtheswitch/ll2QipYfE7Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to throwtheswitch+unsubscribe@googlegroups.com.
To post to this group, send email to throwtheswitch@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/throwtheswitch/CAAu8-XGPQ2FU9vQ-nT5uzaz7As7grW%2B6Ho%3D6qTpyCXtuFc1pHw%40mail.gmail.com.

Yashwant Shitoot

unread,
May 19, 2017, 3:34:47 PM5/19/17
to throwth...@googlegroups.com
Mark,

Thanks. With your help I was able to get it working.

Yash

Yashwant Shitoot


Yashwant Shitoot


To post to this group, send email to throwth...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "ThrowTheSwitch Forums" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/throwtheswitch/ll2QipYfE7Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to throwtheswitch+unsubscribe@googlegroups.com.
To post to this group, send email to throwth...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages