-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
135 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package xyz.colinholzman.makina | ||
|
||
import org.junit.jupiter.api.Test | ||
|
||
class FinalTest { | ||
@Test | ||
fun final() { | ||
externalMakefileTest("./../test/final") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
out | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.PHONY: test | ||
test: out/test | ||
./out/test | ||
|
||
out/test: test_driver.c out/test.c out/test.h out | ||
gcc test_driver.c out/test.c -I "." -std=c99 -Wall -Wextra -Werror -o out/test -g | ||
|
||
out/test.c: | ||
java -jar ../../makina-compiler/out/artifacts/makina_compiler_jar/makina-compiler.jar test_source.mkna -o out | ||
|
||
out: | ||
mkdir out | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
#include <stdio.h> | ||
#include <assert.h> | ||
#include <string.h> | ||
#include "out/test.h" | ||
|
||
static const char *expected_output[] = { | ||
"s1_entry", | ||
"s1_s2_entry", | ||
"s1_s2_exit", | ||
"f_entry" | ||
}; | ||
|
||
#define N_EVENTS (sizeof(expected_output) / sizeof(const char *)) | ||
|
||
static const char *actual_output[N_EVENTS]; | ||
|
||
static size_t output_index = 0; | ||
|
||
#define PUSH_EVENT(e) do { \ | ||
assert(output_index < N_EVENTS); \ | ||
actual_output[output_index++] = e; \ | ||
} while (0) | ||
|
||
int s1_s2_entry(struct test *self, struct test_event *event) { | ||
(void)self; (void)event; | ||
PUSH_EVENT("s1_s2_entry"); | ||
return 0; | ||
} | ||
|
||
int s1_s2_exit(struct test *self, struct test_event *event) { | ||
(void)self; (void)event; | ||
PUSH_EVENT("s1_s2_exit"); | ||
return 0; | ||
} | ||
|
||
int f_entry(struct test *self, struct test_event *event) { | ||
(void)self; (void)event; | ||
PUSH_EVENT("f_entry"); | ||
return 0; | ||
} | ||
|
||
int s1_e1_action(struct test *self, struct test_event *event) { | ||
(void)self; (void)event; | ||
PUSH_EVENT("s1_e1_action"); | ||
return 0; | ||
} | ||
|
||
int s1_entry(struct test *self, struct test_event *event) { | ||
(void)self; (void)event; | ||
PUSH_EVENT("s1_entry"); | ||
return 0; | ||
} | ||
|
||
int s1_exit(struct test *self, struct test_event *event) { | ||
(void)self; (void)event; | ||
PUSH_EVENT("s1_exit"); | ||
return 0; | ||
} | ||
|
||
int main (void) { | ||
struct test instance; | ||
test_init(&instance); | ||
test_process_event(&instance, &(struct test_event){.id = test_event_e1}); | ||
test_process_event(&instance, &(struct test_event){.id = test_event_e1}); | ||
for (size_t i = 0; i < N_EVENTS; ++i) { | ||
assert(strcmp(expected_output[i], actual_output[i]) == 0); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
machine test; | ||
|
||
state s1 { | ||
on e1 s1_e1_action; | ||
entry s1_entry; | ||
state s2 { | ||
entry s1_s2_entry; | ||
on e1 -> f; | ||
exit s1_s2_exit; | ||
} | ||
final state f { | ||
entry f_entry; | ||
} | ||
exit s1_exit; | ||
} |