Skip to content

Commit 584d68e

Browse files
Saveliy Grigoryevsava-cska
authored andcommitted
Add commits to klee and new tests: wrong bubble sort for array and hard_length for linked list
1 parent 5ba805b commit 584d68e

File tree

13 files changed

+256
-18
lines changed

13 files changed

+256
-18
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
3+
*/
4+
5+
#include "array-sort.h"
6+
7+
#define SIZE 4
8+
9+
int sort_array(int *arr, int n) {
10+
if (n >= SIZE) {
11+
for (int i = 0; i < n - 2; i++) {
12+
for (int j = 0; j < n - 1; j++) {
13+
if (arr[j] > arr[j + 1]) {
14+
int t = arr[j];
15+
arr[j] = arr[j + 1];
16+
arr[j + 1] = t;
17+
}
18+
}
19+
}
20+
21+
int fl = 1;
22+
for (int i = 0; i < n - 1; i++) {
23+
if (arr[i] > arr[i + 1]) {
24+
fl = 0;
25+
}
26+
}
27+
28+
if (fl) {
29+
return 1;
30+
} else {
31+
return -1;
32+
}
33+
}
34+
return 0;
35+
}
36+
37+
int sort_array_with_comparator(int *arr, int n, int (*cmp) (int, int)) {
38+
if (n >= SIZE) {
39+
for (int i = 0; i < n - 2; i++) {
40+
for (int j = 0; j < n - 1; j++) {
41+
if (!cmp(arr[j], arr[j + 1])) {
42+
int t = arr[j];
43+
arr[j] = arr[j + 1];
44+
arr[j + 1] = t;
45+
}
46+
}
47+
}
48+
49+
int fl = 1;
50+
for (int i = 0; i < n - 1; i++) {
51+
if (!cmp(arr[i], arr[i + 1])) {
52+
fl = 0;
53+
}
54+
}
55+
56+
if (fl) {
57+
return 1;
58+
} else {
59+
return -1;
60+
}
61+
}
62+
return 0;
63+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
3+
*/
4+
5+
#ifndef ARRAY_SORT_H
6+
#define ARRAY_SORT_H
7+
8+
int sort_array(int *arr, int n);
9+
10+
int sort_array_with_comparator(int *arr, int n, int (*cmp) (int, int));
11+
12+
#endif

integration-tests/c-example/lib/linked-list/linked-list.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ int sum_list(struct Node *head) {
4545
return s;
4646
}
4747

48+
int sign_sum(struct Node *head) {
49+
int sum = sum_list(head);
50+
if (sum > 0) {
51+
return 1;
52+
} else if (sum < 0) {
53+
return -1;
54+
} else {
55+
return 0;
56+
}
57+
}
58+
4859
int hard_length2(struct HardNode *head) {
4960
if (head == NULL) {
5061
return 0;

server/test/framework/Syntax_Tests.cpp

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ namespace {
5151
fs::path different_parameters_cpp = getTestFilePath("different_parameters.cpp");
5252
fs::path simple_class_cpp = getTestFilePath("simple_class.cpp");
5353
fs::path inner_unnamed_c = getTestFilePath("inner_unnamed.c");
54+
fs::path array_sort_c = getTestFilePath("array_sort.c");
5455

5556
void SetUp() override {
5657
clearEnv();
@@ -1199,7 +1200,8 @@ namespace {
11991200
testUtils::checkMinNumberOfTests(testGen.tests.at(structs_with_pointers_c).methods.begin().value().testCases, 1);
12001201
}
12011202

1202-
TEST_F(Syntax_Test, Pointers_In_Structs_3) {
1203+
TEST_F(Syntax_Test, DISABLED_Pointers_In_Structs_3) {
1204+
//This test worked with flag --search=dfs, but plugin utbot doesn't use this flag
12031205
auto [testGen, status] = createTestForFunction(structs_with_pointers_c, 31);
12041206

12051207
ASSERT_TRUE(status.ok()) << status.error_message();
@@ -1296,7 +1298,7 @@ namespace {
12961298
}
12971299

12981300
TEST_F(Syntax_Test, Correct_CodeText_For_Regression_And_Error) {
1299-
auto [testGen, status] = createTestForFunction(linked_list_c, 3);
1301+
auto [testGen, status] = createTestForFunction(linked_list_c, 7);
13001302
const string code = testGen.tests.begin()->second.code;
13011303
const string beginRegressionRegion = "#pragma region " + Tests::DEFAULT_SUITE_NAME + NL;
13021304
const string endRegion = std::string("#pragma endregion") + NL;
@@ -1671,7 +1673,7 @@ namespace {
16711673
}
16721674

16731675
TEST_F(Syntax_Test, length_of_linked_list3) {
1674-
auto [testGen, status] = createTestForFunction(linked_list_c, 3, 45);
1676+
auto [testGen, status] = createTestForFunction(linked_list_c, 7);
16751677

16761678
ASSERT_TRUE(status.ok()) << status.error_message();
16771679

@@ -1696,7 +1698,7 @@ namespace {
16961698
}
16971699

16981700
TEST_F(Syntax_Test, length_of_linked_list2) {
1699-
auto [testGen, status] = createTestForFunction(linked_list_c, 19);
1701+
auto [testGen, status] = createTestForFunction(linked_list_c, 23);
17001702

17011703
ASSERT_TRUE(status.ok()) << status.error_message();
17021704

@@ -1718,13 +1720,29 @@ namespace {
17181720
}
17191721

17201722
TEST_F(Syntax_Test, hard_length_of_linked_list2) {
1721-
auto [testGen, status] = createTestForFunction(linked_list_c, 32);
1723+
auto [testGen, status] = createTestForFunction(linked_list_c, 36);
17221724

17231725
ASSERT_TRUE(status.ok()) << status.error_message();
1726+
1727+
checkTestCasePredicates(
1728+
testGen.tests.at(linked_list_c).methods.begin().value().testCases,
1729+
vector<TestCasePredicate>(
1730+
{
1731+
[] (const tests::Tests::MethodTestCase& testCase) {
1732+
return stoi(testCase.returnValueView->getEntryValue()) == 1;
1733+
},
1734+
[] (const tests::Tests::MethodTestCase& testCase) {
1735+
return stoi(testCase.returnValueView->getEntryValue()) == 2;
1736+
},
1737+
[] (const tests::Tests::MethodTestCase& testCase) {
1738+
return stoi(testCase.returnValueView->getEntryValue()) == -1;
1739+
}
1740+
})
1741+
);
17241742
}
17251743

17261744
TEST_F(Syntax_Test, middle_length_of_linked_list2) {
1727-
auto [testGen, status] = createTestForFunction(linked_list_c, 45);
1745+
auto [testGen, status] = createTestForFunction(linked_list_c, 49);
17281746

17291747
ASSERT_TRUE(status.ok()) << status.error_message();
17301748

@@ -1746,7 +1764,7 @@ namespace {
17461764
}
17471765

17481766
TEST_F(Syntax_Test, cycle_linked_list3) {
1749-
auto [testGen, status] = createTestForFunction(linked_list_c, 58);
1767+
auto [testGen, status] = createTestForFunction(linked_list_c, 62);
17501768

17511769
ASSERT_TRUE(status.ok()) << status.error_message();
17521770

@@ -1789,7 +1807,7 @@ namespace {
17891807
}
17901808

17911809
TEST_F(Syntax_Test, len_bound) {
1792-
auto [testGen, status] = createTestForFunction(linked_list_c, 92);
1810+
auto [testGen, status] = createTestForFunction(linked_list_c, 96);
17931811

17941812
ASSERT_TRUE(status.ok()) << status.error_message();
17951813

@@ -1808,7 +1826,7 @@ namespace {
18081826
}
18091827

18101828
TEST_F(Syntax_Test, sort_list) {
1811-
auto [testGen, status] = createTestForFunction(linked_list_c, 104);
1829+
auto [testGen, status] = createTestForFunction(linked_list_c, 108);
18121830

18131831
ASSERT_TRUE(status.ok()) << status.error_message();
18141832

@@ -1830,7 +1848,7 @@ namespace {
18301848
}
18311849

18321850
TEST_F(Syntax_Test, sort_list_with_cmp) {
1833-
auto [testGen, status] = createTestForFunction(linked_list_c, 135);
1851+
auto [testGen, status] = createTestForFunction(linked_list_c, 139);
18341852

18351853
ASSERT_TRUE(status.ok()) << status.error_message();
18361854

@@ -1851,24 +1869,68 @@ namespace {
18511869
);
18521870
}
18531871

1872+
TEST_F(Syntax_Test, sort_array) {
1873+
auto [testGen, status] = createTestForFunction(array_sort_c, 9);
1874+
1875+
ASSERT_TRUE(status.ok()) << status.error_message();
1876+
1877+
checkTestCasePredicates(
1878+
testGen.tests.at(array_sort_c).methods.begin().value().testCases,
1879+
vector<TestCasePredicate>(
1880+
{
1881+
[] (const tests::Tests::MethodTestCase& testCase) {
1882+
return stoi(testCase.returnValueView->getEntryValue()) == -1;
1883+
},
1884+
[] (const tests::Tests::MethodTestCase& testCase) {
1885+
return stoi(testCase.returnValueView->getEntryValue()) == 1;
1886+
},
1887+
[] (const tests::Tests::MethodTestCase& testCase) {
1888+
return stoi(testCase.returnValueView->getEntryValue()) == 0;
1889+
}
1890+
})
1891+
);
1892+
}
1893+
1894+
TEST_F(Syntax_Test, sort_array_with_comparator) {
1895+
auto [testGen, status] = createTestForFunction(array_sort_c, 37);
1896+
1897+
ASSERT_TRUE(status.ok()) << status.error_message();
1898+
1899+
checkTestCasePredicates(
1900+
testGen.tests.at(array_sort_c).methods.begin().value().testCases,
1901+
vector<TestCasePredicate>(
1902+
{
1903+
[] (const tests::Tests::MethodTestCase& testCase) {
1904+
return stoi(testCase.returnValueView->getEntryValue()) == -1;
1905+
},
1906+
[] (const tests::Tests::MethodTestCase& testCase) {
1907+
return stoi(testCase.returnValueView->getEntryValue()) == 1;
1908+
},
1909+
[] (const tests::Tests::MethodTestCase& testCase) {
1910+
return stoi(testCase.returnValueView->getEntryValue()) == 0;
1911+
}
1912+
})
1913+
);
1914+
}
1915+
18541916
TEST_F(Syntax_Test, find_maximum) {
1855-
auto [testGen, status] = createTestForFunction(linked_list_c, 166);
1917+
auto [testGen, status] = createTestForFunction(linked_list_c, 170);
18561918

18571919
ASSERT_TRUE(status.ok()) << status.error_message();
18581920

18591921
EXPECT_EQ(2, testUtils::getNumberOfTests(testGen.tests));
18601922
}
18611923

18621924
TEST_F(Syntax_Test, vowel_consonant) {
1863-
auto [testGen, status] = createTestForFunction(linked_list_c, 175);
1925+
auto [testGen, status] = createTestForFunction(linked_list_c, 179);
18641926

18651927
ASSERT_TRUE(status.ok()) << status.error_message();
18661928

18671929
EXPECT_TRUE(testUtils::getNumberOfTests(testGen.tests) >= 2);
18681930
}
18691931

18701932
TEST_F(Syntax_Test, tree_deep) {
1871-
auto [testGen, status] = createTestForFunction(tree_c, 3, 45);
1933+
auto [testGen, status] = createTestForFunction(tree_c, 7);
18721934

18731935
ASSERT_TRUE(status.ok()) << status.error_message();
18741936

server/test/framework/TestUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ namespace testUtils {
170170
int kleeTimeout) {
171171
auto projectContext = GrpcUtils::createProjectContext(
172172
projectName, projectPath, projectPath / "tests", buildDirRelativePath);
173-
auto settingsContext = GrpcUtils::createSettingsContext(true, verbose, kleeTimeout, 0, true, useStubs);
173+
auto settingsContext = GrpcUtils::createSettingsContext(true, verbose, kleeTimeout, 0, false, useStubs);
174174
return GrpcUtils::createProjectRequest(std::move(projectContext),
175175
std::move(settingsContext), srcPaths);
176176
}

server/test/suites/syntax/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ add_executable(syntax1
3434
tree.c
3535
different_parameters.cpp
3636
simple_class.cpp
37-
inner_unnamed.c)
37+
inner_unnamed.c
38+
array_sort.c)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
3+
*/
4+
5+
#include "array_sort.h"
6+
7+
#define SIZE 4
8+
9+
int sort_array(int *arr, int n) {
10+
if (n >= SIZE) {
11+
for (int i = 0; i < n - 2; i++) {
12+
for (int j = 0; j < n - 1; j++) {
13+
if (arr[j] > arr[j + 1]) {
14+
int t = arr[j];
15+
arr[j] = arr[j + 1];
16+
arr[j + 1] = t;
17+
}
18+
}
19+
}
20+
21+
int fl = 1;
22+
for (int i = 0; i < n - 1; i++) {
23+
if (arr[i] > arr[i + 1]) {
24+
fl = 0;
25+
}
26+
}
27+
28+
if (fl) {
29+
return 1;
30+
} else {
31+
return -1;
32+
}
33+
}
34+
return 0;
35+
}
36+
37+
int sort_array_with_comparator(int *arr, int n, int (*cmp) (int, int)) {
38+
if (n >= SIZE) {
39+
for (int i = 0; i < n - 2; i++) {
40+
for (int j = 0; j < n - 1; j++) {
41+
if (!cmp(arr[j], arr[j + 1])) {
42+
int t = arr[j];
43+
arr[j] = arr[j + 1];
44+
arr[j + 1] = t;
45+
}
46+
}
47+
}
48+
49+
int fl = 1;
50+
for (int i = 0; i < n - 1; i++) {
51+
if (!cmp(arr[i], arr[i + 1])) {
52+
fl = 0;
53+
}
54+
}
55+
56+
if (fl) {
57+
return 1;
58+
} else {
59+
return -1;
60+
}
61+
}
62+
return 0;
63+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
3+
*/
4+
5+
#ifndef ARRAY_SORT_H
6+
#define ARRAY_SORT_H
7+
8+
int sort_array(int *arr, int n);
9+
10+
int sort_array_with_comparator(int *arr, int n, int (*cmp) (int, int));
11+
12+
#endif

server/test/suites/syntax/linked_list.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
3+
*/
4+
15
#include "linked_list.h"
26

37
int length_of_linked_list3(struct Node *head) {
@@ -179,5 +183,4 @@ int vowel_consonant(char c, char (*vowel) (char)) {
179183
} else {
180184
return -1;
181185
}
182-
183186
}

server/test/suites/syntax/linked_list.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
3+
*/
4+
15
#ifndef UNITTESTBOT_LINKED_LIST_H
26
#define UNITTESTBOT_LINKED_LIST_H
37

0 commit comments

Comments
 (0)