Skip to content

Commit cd3eb3d

Browse files
authored
Testharnish (#28)
#25 Testkonzept und -umgebung für Builder und Runtime Additions: * CBuilder JUNIT Tests * CBuilder JUNIT System-Tests * C-Runtime Catch2 System-Tests * Gtihub Action test_suite.yml
1 parent 35744f2 commit cd3eb3d

File tree

131 files changed

+9433
-554
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+9433
-554
lines changed

.github/workflows/test_suite.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
name: Testing C-Runtime
1010
strategy:
1111
matrix:
12-
os: [ubuntu-latest, macos-latest]
12+
os: [macos-latest, ubuntu-latest]
1313
runs-on: ${{ matrix.os }}
1414
steps:
1515
- name: Checkout
@@ -25,18 +25,18 @@ jobs:
2525
run: make test_clean ; make clean
2626

2727
languagefeatures:
28-
name: Testing CBuilder (Java)
29-
strategy:
30-
matrix:
31-
os: [ubuntu-latest, macos-latest]
32-
runs-on: ${{ matrix.os }}
33-
steps:
34-
- name: Checkout
35-
uses: actions/checkout@v4
36-
- name: Set up JDK 21
37-
uses: actions/setup-java@v4
38-
with:
39-
java-version: '21'
40-
distribution: 'temurin'
41-
- name: Build with Gradle
42-
run: ./gradlew test
28+
name: Testing CBuilder (Java)
29+
strategy:
30+
matrix:
31+
os: [ubuntu-latest, macos-latest]
32+
runs-on: ${{ matrix.os }}
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v4
36+
- name: Set up JDK 21
37+
uses: actions/setup-java@v4
38+
with:
39+
java-version: '21'
40+
distribution: 'temurin'
41+
- name: Build with Gradle
42+
run: ./gradlew test

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,8 @@ pip-log.txt
8484
*.zip
8585
*.tgz
8686
*.tar.gz
87+
88+
# Catch2 #
89+
##########
90+
c-runtime/test/include/catch_amalgamated.hpp
91+
c-runtime/test/src/catch_amalgamated.cpp

c-runtime/Makefile

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,28 @@ MKDIR_P := mkdir -p
1212
# make SRCDIR and INCLUDEDIR available to doxygen
1313
export SRCDIR := $(realpath ./src)
1414
export INCLUDEDIR := $(realpath ./include)
15-
DOXYFILE := $(realpath ./Doxyfile)
16-
15+
export TESTDIR := $(realpath ./test)
16+
export INCLUDEDIRTEST := $(realpath ./test/include)
17+
export SRCDIRTEST := $(realpath ./test/src)
18+
19+
CATCHFILES = $(TESTDIR)/include/catch_amalgamated.hpp $(TESTDIR)/src/catch_amalgamated.cpp
20+
export C_FILES_TEST := $(wildcard ./test/src/test/*.c ./test/src/test/*/*.c* ./test/src/*.cpp)
21+
export C_FILES_TEST := $(filter-out ./src/program.c, $(C_FILES_TEST))
22+
export C_FILES := $(wildcard ./src/*.c ./src/*/*.c*)
23+
export C_FILES := $(filter-out ./src/program.c, $(C_FILES))
24+
export DOXYFILE := $(realpath ./Doxyfile)
25+
26+
C_FILES_TEST += $(TESTDIR)/src/catch_amalgamated.cpp
1727
# make DOCDIR available to doxygen
1828
export DOCDIR := $(abspath ./doc)
19-
BINDIR := $(abspath ./bin)
20-
OUTDIR := $(abspath ./out)
29+
export BINDIR := $(abspath ./bin)
30+
export OUTDIR := $(abspath ./out)
2131

2232
#################
2333
# Default Flags #
2434
#################
2535

26-
CFLAGS ?= -pedantic -Wall -Werror
36+
CFLAGS ?= -Wall -Werror -pedantic
2737
CFLAGS += -std=c11 -I$(INCLUDEDIR)
2838
CFLAGS += -ffile-prefix-map=$(SRCDIR)=.
2939
# make getline() (see man getline(3)) available
@@ -37,6 +47,10 @@ else
3747
# not for now CFLAGS += -DNDEBUG
3848
endif
3949

50+
#####################
51+
# Default g++ Flags #
52+
#####################
53+
4054
###########
4155
# Targets #
4256
###########
@@ -49,7 +63,6 @@ SRC := $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/*/*.c) $(wildcard $(SRCDIR
4963
OBJECT := $(patsubst $(SRCDIR)/%.c,$(OUTDIR)/%.o,$(SRC))
5064
DEPENDENCY := $(OBJECT:.o=.d)
5165

52-
5366
#########
5467
# Rules #
5568
#########
@@ -79,6 +92,7 @@ run: $(BIN)
7992
.PHONY: clean
8093
clean:
8194
$(RM) -r $(BIN) $(OBJECT) $(DEPENDENCY) $(wildcard $(DOCDIR)/*)
95+
$(RM) $(TESTDIR)/main
8296

8397
.PHONY: doc
8498
doc:
@@ -89,11 +103,43 @@ doc:
89103
lint:
90104
clang-tidy --checks=*,-bugprone-reserved-identifier,-cert-dcl37-c,-cert-dcl51-cpp,-altera-struct-pack-align $(SRC)
91105

106+
#https://github.com/catchorg/Catch2/blob/v2.x/include/catch.hpp
107+
.PHONY: curl_catch
108+
$(CATCHFILES):
109+
curl -o $(TESTDIR)/include/catch_amalgamated.hpp https://github.com/catchorg/Catch2/devel/extras/catch_amalgamated.hpp
110+
curl -o $(TESTDIR)/src/catch_amalgamated.cpp https://github.com/catchorg/Catch2/devel/extras/catch_amalgamated.cpp
92111

93112
.PHONY: test
94-
test: test_clean
113+
test: $(C_FILES_TEST)
114+
d=$$(date +%s)\
115+
; make -f $(TESTDIR)/Systemtests/makefile \
116+
&& echo "Build took $$(($$(date +%s)-d)) seconds"
117+
make test_clean
95118

96119

97120
.PHONY: test_clean
98121
test_clean:
99-
echo "dummy to allow gh workflow to do its job"
122+
make -f $(TESTDIR)/Systemtests/makefile clean
123+
124+
$(RM) -r $(TESTDIR)/include/catch_amalgamated.hpp
125+
$(RM) -r $(TESTDIR)/src/catch_amalgamated.cpp
126+
127+
.PHONY: test_echo
128+
test_echo:
129+
make -f $(TESTDIR)/Systemtests/makefile echo
130+
131+
.PHONY: test_run
132+
test_run:
133+
make -f $(TESTDIR)/Systemtests/makefile run
134+
135+
.PHONY: test_target
136+
test_target: $(C_FILES_TEST)
137+
d=$$(date +%s)\
138+
; make -f $(TESTDIR)/Systemtests/makefile test_declaration_and_assignment \
139+
&& echo "Build took $$(($$(date +%s)-d)) seconds"
140+
make run_target
141+
make test_clean
142+
143+
.PHONY: run_target
144+
run_target:
145+
./test/Systemtests/DeclarationAndAssignment/TestDeclarationAndAssignment.out
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#define CATCH_CONFIG_MAIN
2+
3+
#include <stddef.h>
4+
5+
#include "catch_amalgamated.hpp"
6+
#include "assert.h"
7+
#include "mpy_aliases.h"
8+
#include "mpy_obj.h"
9+
#include "builtins-setup.h"
10+
#include "function-args.h"
11+
#include "literals/tuple.h"
12+
#include "literals/int.h"
13+
#include "literals/boolean.h"
14+
#include "literals/str.h"
15+
#include "type-hierarchy/object.h"
16+
#include "type-hierarchy/type.h"
17+
#include "test/test_helpers.h"
18+
19+
int add_op(int i, int j){
20+
__MPyObj *a;
21+
22+
__mpy_builtins_setup();
23+
a = __mpy_obj_init_object();
24+
__mpy_obj_ref_inc(a);
25+
26+
__mpy_obj_ref_dec(a);
27+
a = __mpy_call(__mpy_obj_get_attr(__mpy_obj_init_int(i), "__add__"), __mpy_tuple_assign(0, __mpy_obj_init_int(j), __mpy_obj_init_tuple(1)), NULL);
28+
__mpy_obj_ref_inc(a);
29+
30+
__mpy_obj_ref_dec(a);
31+
32+
printf("[ADD] i : %d --- j : %d\n",i,j);
33+
print_mpyobj_int(a);
34+
35+
__mpy_builtins_cleanup();
36+
37+
return (*(int*)(a->content)) == (i+j) ? 1 : 0;
38+
}
39+
40+
int sub_op(int i, int j){
41+
__MPyObj *a;
42+
43+
__mpy_builtins_setup();
44+
a = __mpy_obj_init_object();
45+
__mpy_obj_ref_inc(a);
46+
47+
__mpy_obj_ref_dec(a);
48+
a = __mpy_call(__mpy_obj_get_attr(__mpy_obj_init_int(i), "__sub__"), __mpy_tuple_assign(0, __mpy_obj_init_int(j), __mpy_obj_init_tuple(1)), NULL);
49+
__mpy_obj_ref_inc(a);
50+
51+
__mpy_obj_ref_dec(a);
52+
53+
printf("[SUB] i : %d --- j : %d\n",i,j);
54+
print_mpyobj_int(a);
55+
56+
__mpy_builtins_cleanup();
57+
58+
return (*(int*)(a->content)) == (i-j) ? 1 : 0;
59+
}
60+
61+
int mul_op(int i, int j){
62+
__MPyObj *a;
63+
64+
__mpy_builtins_setup();
65+
a = __mpy_obj_init_object();
66+
__mpy_obj_ref_inc(a);
67+
68+
__mpy_obj_ref_dec(a);
69+
a = __mpy_call(__mpy_obj_get_attr(__mpy_obj_init_int(i), "__mul__"), __mpy_tuple_assign(0, __mpy_obj_init_int(j), __mpy_obj_init_tuple(1)), NULL);
70+
__mpy_obj_ref_inc(a);
71+
72+
__mpy_obj_ref_dec(a);
73+
74+
printf("[MUL] i : %d --- j : %d\n",i,j);
75+
print_mpyobj_int(a);
76+
77+
__mpy_builtins_cleanup();
78+
79+
return (*(int*)(a->content)) == (i*j) ? 1 : 0;
80+
}
81+
82+
int div_op(int i, int j){
83+
__MPyObj *a;
84+
85+
__mpy_builtins_setup();
86+
a = __mpy_obj_init_object();
87+
__mpy_obj_ref_inc(a);
88+
89+
__mpy_obj_ref_dec(a);
90+
a = __mpy_call(__mpy_obj_get_attr(__mpy_obj_init_int(i), "__div__"), __mpy_tuple_assign(0, __mpy_obj_init_int(j), __mpy_obj_init_tuple(1)), NULL);
91+
__mpy_obj_ref_inc(a);
92+
93+
__mpy_obj_ref_dec(a);
94+
95+
printf("[DIV] i : %d --- j : %d\n",i,j);
96+
print_mpyobj_int(a);
97+
98+
__mpy_builtins_cleanup();
99+
100+
return (*(int*)(a->content)) == (i/j) ? 1 : 0;
101+
}
102+
103+
104+
TEST_CASE("GENERATE ADD OP"){
105+
auto i = GENERATE(1, 3, 5);
106+
auto j = GENERATE(2, 4, 6);
107+
CHECK(add_op(i, j) == 1);
108+
}
109+
110+
TEST_CASE("GENERATE SUB OP"){
111+
auto i = GENERATE(1, 3, 5);
112+
auto j = GENERATE(2, 4, 6);
113+
CHECK(sub_op(i, j) == 1);
114+
}
115+
116+
TEST_CASE("GENERATE MUL OP"){
117+
auto i = GENERATE(1, 3, 5);
118+
auto j = GENERATE(2, 4, 6);
119+
CHECK(mul_op(i, j) == 1);
120+
}
121+
122+
TEST_CASE("GENERATE DIV OP"){
123+
auto i = GENERATE(3, 8, 12);
124+
auto j = GENERATE(2, 4, 6);
125+
CHECK(div_op(i, j) == 1);
126+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#define CATCH_CONFIG_MAIN
2+
3+
#include <stddef.h>
4+
5+
#include "catch_amalgamated.hpp"
6+
#include "assert.h"
7+
#include "mpy_aliases.h"
8+
#include "mpy_obj.h"
9+
#include "builtins-setup.h"
10+
#include "function-args.h"
11+
#include "literals/tuple.h"
12+
#include "literals/int.h"
13+
#include "literals/boolean.h"
14+
#include "literals/str.h"
15+
#include "type-hierarchy/object.h"
16+
#include "type-hierarchy/type.h"
17+
#include "test/test_helpers.h"
18+
19+
void exit(int status) {
20+
throw std::runtime_error("Error");
21+
}
22+
23+
int cast_bool_to_int(bool input){
24+
__MPyObj *a;
25+
26+
__mpy_builtins_setup();
27+
a = __mpy_obj_init_object();
28+
__mpy_obj_ref_inc(a);
29+
30+
__mpy_obj_ref_dec(a);
31+
a = __mpy_obj_init_boolean(input);
32+
__mpy_obj_ref_inc(a);
33+
34+
a = __mpy_call(__mpy_obj_get_attr(a, "__int__"), __mpy_obj_init_tuple(0), NULL);
35+
36+
__mpy_obj_ref_dec(a);
37+
38+
print_mpyobj_int(a);
39+
40+
__mpy_builtins_cleanup();
41+
42+
return (*(int*)(a->content));
43+
}
44+
45+
int cast_string_to_int(const char* input){
46+
__MPyObj *a;
47+
48+
__mpy_builtins_setup();
49+
a = __mpy_obj_init_object();
50+
__mpy_obj_ref_inc(a);
51+
52+
__mpy_obj_ref_dec(a);
53+
a = __mpy_obj_init_str_static(input);
54+
__mpy_obj_ref_inc(a);
55+
56+
__mpy_obj_ref_dec(a);
57+
a = __mpy_call(__mpy_obj_get_attr(a, "__int__"), __mpy_obj_init_tuple(0), NULL);
58+
__mpy_obj_ref_inc(a);
59+
60+
__mpy_obj_ref_dec(a);
61+
62+
print_mpyobj_int(a);
63+
64+
__mpy_builtins_cleanup();
65+
66+
return (*(int*)(a->content));
67+
}
68+
69+
TEST_CASE("TEST CAST BOOL TO INT")
70+
{
71+
auto [input, expected_output] = GENERATE(table<bool, int>({
72+
{ true, 1 },
73+
{ false, 0 },
74+
{10, 1},
75+
}));
76+
77+
CAPTURE(input);
78+
CHECK(cast_bool_to_int(input) == expected_output);
79+
}
80+
81+
TEST_CASE("TEST CAST STRING TO INT")
82+
{
83+
auto [input, expected_output] = GENERATE(table<const char*, int>({
84+
{ "1", 1 },
85+
{ "0", 0 },
86+
{ "10", 10},
87+
}));
88+
89+
CAPTURE(input);
90+
CHECK(cast_string_to_int(input) == expected_output);
91+
}
92+
93+
TEST_CASE("TEST CAST STRING TO INT ERROR") {
94+
REQUIRE_THROWS_AS(cast_string_to_int("false"), std::runtime_error);
95+
}
96+
97+
/*
98+
And
99+
100+
int cast_int_to_int(int i){
101+
}
102+
103+
*/

0 commit comments

Comments
 (0)