-
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.
This should have been in the last commit.
- Loading branch information
Showing
7 changed files
with
160 additions
and
0 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
46 changes: 46 additions & 0 deletions
46
makina-compiler/test/xyz/colinholzman/makina/ExternalTransitionTest.kt
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,46 @@ | ||
package xyz.colinholzman.makina | ||
|
||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
import java.io.File | ||
import java.util.concurrent.TimeUnit | ||
|
||
class ExternalTransitionTest { | ||
|
||
val output = listOf( | ||
"s1_entry", | ||
"s1_s2_entry", | ||
"s1_s2_e1_guard", | ||
"s1_s2_exit", | ||
"s1_exit", | ||
"s1_entry", | ||
"s1_s2_entry", | ||
"s1_s2_e1_guard", | ||
"s1_s2_exit", | ||
"s1_exit", | ||
"s1_entry", | ||
"s1_s2_entry", | ||
"s1_s2_e2_guard", | ||
"s1_s2_exit", | ||
"s1_s2_entry", | ||
"s1_s2_e2_guard", | ||
"s1_s2_exit", | ||
"s1_s2_entry" | ||
) | ||
@Test | ||
fun externalTransition() { | ||
val makeClean = ProcessBuilder() | ||
.directory(File("./../test/external_transition")) | ||
.command("make", "clean").start() | ||
makeClean.waitFor(10, TimeUnit.SECONDS) | ||
|
||
val make = ProcessBuilder() | ||
.directory(File("./../test/external_transition")) | ||
.command("make").start() | ||
make.waitFor(10, TimeUnit.SECONDS) | ||
|
||
File("./../test/external_transition/out/test_output.txt").reader().use { | ||
Assertions.assertEquals(output, it.readLines()) | ||
} | ||
} | ||
} |
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 | ||
|
||
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,64 @@ | ||
|
||
#include <stdio.h> | ||
#include "out/test.h" | ||
|
||
FILE *output; | ||
|
||
int s1_s2_entry(struct test *self, struct test_event *event) { | ||
(void)self; (void)event; | ||
fprintf(output, "s1_s2_entry\n"); | ||
return 0; | ||
} | ||
|
||
static int guard = 0; | ||
|
||
int s1_s2_e1_guard(struct test *self, struct test_event *event) { | ||
(void)self; (void)event; | ||
fprintf(output, "s1_s2_e1_guard\n"); | ||
return guard; | ||
} | ||
|
||
int s1_s2_e2_guard(struct test *self, struct test_event *event) { | ||
(void)self; (void)event; | ||
fprintf(output, "s1_s2_e2_guard\n"); | ||
return guard; | ||
} | ||
|
||
int s1_s2_e1_action(struct test *self, struct test_event *event) { | ||
(void)self; (void)event; | ||
fprintf(output, "s1_s2_e1_action\n"); | ||
return 0; | ||
} | ||
|
||
int s1_s2_exit(struct test *self, struct test_event *event) { | ||
(void)self; (void)event; | ||
fprintf(output, "s1_s2_exit\n"); | ||
return 0; | ||
} | ||
|
||
int s1_entry(struct test *self, struct test_event *event) { | ||
(void)self; (void)event; | ||
fprintf(output, "s1_entry\n"); | ||
return 0; | ||
} | ||
|
||
int s1_exit(struct test *self, struct test_event *event) { | ||
(void)self; (void)event; | ||
fprintf(output, "s1_exit\n"); | ||
return 0; | ||
} | ||
|
||
int main (void) { | ||
output = fopen("out/test_output.txt", "w+"); | ||
struct test instance; | ||
test_init(&instance); /*s1_entry, s1_s2_entry*/ | ||
test_process_event(&instance, &(struct test_event){.id = test_event_e1}); /*s1_s2_e1_guard, s1_s2_exit, s1_exit, s1_entry, s1_s2_entry*/ | ||
guard = 1; | ||
test_process_event(&instance, &(struct test_event){.id = test_event_e1}); /*s1_s2_e1_guard, s1_s2_exit, s1_exit, s1_entry, s1_s2_entry*/ | ||
guard = 0; | ||
test_process_event(&instance, &(struct test_event){.id = test_event_e2}); /*s1_s2_e2_guard, s1_s2_exit, s1_s2_entry*/ | ||
guard = 1; | ||
test_process_event(&instance, &(struct test_event){.id = test_event_e2}); /*s1_s2_e2_guard, s1_s2_exit, s1_s2_entry*/ | ||
fclose(output); | ||
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,14 @@ | ||
machine test; | ||
|
||
state s1 { | ||
on e1 -> s1; | ||
on e2 -> s2; | ||
entry s1_entry; | ||
state s2 { | ||
entry s1_s2_entry; | ||
on e1 (s1_s2_e1_guard) -> s1; | ||
on e2 (s1_s2_e2_guard) -> s2; | ||
exit s1_s2_exit; | ||
} | ||
exit s1_exit; | ||
} |