Skip to content

Commit 20c0ce6

Browse files
committed
supported examples added
1 parent 6048615 commit 20c0ce6

26 files changed

+384
-114
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <stdlib.h>
2+
3+
int abs_val(int x) {
4+
if (x < 0 && abs(x) > 0) {
5+
return -1;
6+
} else if (x > 0) {
7+
return 1;
8+
}
9+
return abs(x);
10+
}
11+
12+
int sign(char const *str) {
13+
int x = atoi(str);
14+
if (x == 5) {
15+
return 7;
16+
}
17+
if (x > 0) {
18+
return 1;
19+
} else if (x < 0) {
20+
return -1;
21+
}
22+
return 0;
23+
}

integration-tests/c-example/lib/assertion_failures.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include "assert.h"
55

66
int buggy_function1(int a, int b);
7+
78
int buggy_function2(int a);
9+
810
int buggy_function3(int a, int b);
911

10-
#endif //UNITTESTBOT_SRC_ASSERT_FAIL_H
12+
#endif //SIMPLE_TEST_PROJECT_SRC_ASSERT_FAIL_H

integration-tests/c-example/lib/basic_functions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
#define SIMPLE_TEST_PROJECT_BASIC_FUNCTIONS_H
33

44
int max_(int a, int b);
5+
56
int min(int a, int b);
7+
68
int sqr_positive(int a);
9+
710
int simple_loop(unsigned int n);
811

912
#endif //SIMPLE_TEST_PROJECT_BASIC_FUNCTIONS_H
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
int f() {
2+
struct s {
3+
int i;
4+
} *p = 0, *q;
5+
int j = 0;
6+
again:
7+
q = p, p = &((struct s) { j++ });
8+
if (j < 2) goto again;
9+
return p == q && q->i == 1; // always returns 1
10+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#define typeid(x) _Generic((x), \
2+
_Bool: 0, \
3+
char: 1, \
4+
int: 2, \
5+
float: 3, \
6+
default: 4)
7+
8+
int get_typeid(unsigned short int casen) {
9+
switch (casen) {
10+
case 0:
11+
return typeid((_Bool const) 0);
12+
case 1:
13+
return typeid((char) 'c');
14+
case 2:
15+
return typeid(24);
16+
case 3:
17+
return typeid(42.f);
18+
default:
19+
return typeid("char const *");
20+
}
21+
}
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "halt.h"
22

3-
#include "signal.h"
3+
#include <signal.h>
4+
#include <stdio.h>
5+
#include <stdlib.h>
46

57
int raise_by_num(int num) {
68
return raise(num);
@@ -9,3 +11,15 @@ int raise_by_num(int num) {
911
int raise_stop(int _) {
1012
return raise(SIGSTOP);
1113
}
14+
15+
void cleanup() {
16+
fprintf(stderr, "Normal program termination with cleaning up\n");
17+
}
18+
19+
int call_abort() {
20+
if (atexit(cleanup)) {
21+
return EXIT_FAILURE;
22+
}
23+
fprintf(stderr, "Going to abort the program\n");
24+
abort();
25+
}

integration-tests/c-example/lib/halt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ int raise_by_num(int num);
55

66
int raise_stop(int _);
77

8+
void cleanup();
9+
10+
int call_abort();
11+
812
#endif
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include "loops.h"
2+
#include <stdbool.h>
3+
4+
unsigned int while_loop(unsigned int n) {
5+
unsigned int i = 0;
6+
while (i < n) {
7+
i = i + 1;
8+
if (n % i == 37U)
9+
return 1;
10+
else if (i == 50U)
11+
return 2U;
12+
}
13+
return 0U;
14+
}
15+
16+
int do_while_loop(int n) {
17+
int i = 0;
18+
do {
19+
i = i + 1;
20+
if (n % i == 37)
21+
return 1;
22+
else if (i == 50)
23+
return 2;
24+
} while (i < n);
25+
return 0;
26+
}
27+
28+
int continue_break(int n) {
29+
int i = n, res = 0;
30+
do {
31+
res += i;
32+
if (res > 100) {
33+
break;
34+
}
35+
if (i < 20) {
36+
continue;
37+
}
38+
} while (false);
39+
return res;
40+
}
41+
42+
int goto_keyword(unsigned int a) {
43+
unsigned int sum = 0;
44+
do {
45+
if (a == 15) {
46+
goto RET;
47+
}
48+
sum += a;
49+
a++;
50+
} while (a < 22);
51+
if (sum > 1000) {
52+
return 1;
53+
}
54+
return 2;
55+
RET: return -1;
56+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef C_EXAMPLE_LOOPS_H
2+
#define C_EXAMPLE_LOOPS_H
3+
4+
unsigned int while_loop(unsigned int n);
5+
6+
int do_while_loop(int n);
7+
8+
int continue_break(int n);
9+
10+
int goto_keyword(unsigned int a);
11+
12+
#endif //C_EXAMPLE_LOOPS_H

integration-tests/c-example/lib/memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "stdlib.h"
2-
#include "string.h"
1+
#include <stdlib.h>
2+
#include <string.h>
33

44
int out_of_bound_access_to_heap(int num) {
55
int *p = calloc(5, sizeof(int));

0 commit comments

Comments
 (0)