-
Notifications
You must be signed in to change notification settings - Fork 54
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
48 changed files
with
584 additions
and
24 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,4 @@ | ||
interface BoolTest { | ||
command void test(const char *test_name, const _Bool arg); | ||
event void testDone(const char *test_name, _Bool result, _Bool arg); | ||
} |
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,8 @@ | ||
module BoolTestM { | ||
provides interface BoolTest; | ||
} | ||
implementation { | ||
command void BoolTest.test(const char *test_name, const _Bool arg) { | ||
signal BoolTest.testDone(test_name, !arg, arg); | ||
} | ||
} |
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,45 @@ | ||
extern int printf(const char *__restrict format, ...); | ||
|
||
typedef struct { | ||
_Bool a; | ||
} bool_test_args; | ||
|
||
nx_struct nx_header { | ||
nx_uint32_t src; | ||
nx_uint32_t dst; | ||
}; | ||
|
||
module TestP { | ||
uses interface BoolTest; | ||
} | ||
implementation { | ||
int main() @C() @spontaneous() { | ||
#define do_test(test_name, bool_expr) call BoolTest.test(#test_name, bool_expr) | ||
|
||
do_test(TrueConst, 1); | ||
do_test(TrueExpr, 1 == 1 && 0 < 1); | ||
do_test(TrueExprSC, 0 == 0 || 0 > 1); | ||
do_test(IntTrue, 1234); | ||
do_test(FloatTrue, 1.23); | ||
do_test(String, "string"); | ||
|
||
do_test(FalseConst, 0); | ||
do_test(FalseExpr, 0 == 1 || 0 > 1); | ||
do_test(FalseExprSC, 1 == 0 && 0 < 1); | ||
do_test(IntZero, 0); | ||
do_test(FloatZero, 0.0); | ||
do_test(NullVoid, (const void *)0); | ||
do_test(NullULL, (unsigned long long *)0); | ||
do_test(NullStruct, (const bool_test_args *const __restrict)0); | ||
do_test(NullFnP, (int (*)(char[], double))0); | ||
do_test(Network, (nx_uint32_t *)0); | ||
do_test(NetworkStruct, (nx_struct nx_header *)0); | ||
#undef do_test | ||
|
||
return 0; | ||
} | ||
|
||
event void BoolTest.testDone(const char *test_name, _Bool result, _Bool arg) { | ||
printf("%15s: %d -> %d\n", test_name, arg, result); | ||
} | ||
} |
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,7 @@ | ||
configuration test { | ||
} | ||
implementation { | ||
components TestP, BoolTestM; | ||
|
||
TestP.BoolTest -> BoolTestM; | ||
} |
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,11 @@ | ||
typedef struct { | ||
_Bool a:1; | ||
_Bool b; | ||
} bool_test_args; | ||
|
||
interface BoolTest { | ||
command void unary(const _Bool a); | ||
command void binary(const bool_test_args args); | ||
event void unaryDone(const char *test_name, _Bool result, _Bool arg); | ||
event void binaryDone(const char *test_name, _Bool result, bool_test_args args); | ||
} |
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 @@ | ||
generic module BoolTestM(_Bool val, char test_name[]) { | ||
provides interface BoolTest; | ||
} | ||
implementation { | ||
command void BoolTest.unary(const _Bool a) { | ||
const _Bool result = val ? a : !a; | ||
signal BoolTest.unaryDone(test_name, result, a); | ||
} | ||
|
||
command void BoolTest.binary(const bool_test_args args) { | ||
const _Bool xor = args.a ^ args.b; | ||
const _Bool result = val ? xor : !xor; | ||
signal BoolTest.binaryDone(test_name, result, args); | ||
} | ||
} |
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,31 @@ | ||
extern int printf(const char *__restrict format, ...); | ||
|
||
module TestP { | ||
uses interface BoolTest; | ||
} | ||
implementation { | ||
int main() @C() @spontaneous() { | ||
bool_test_args args; | ||
|
||
call BoolTest.unary(0); | ||
call BoolTest.unary(1); | ||
args.a = args.b = 0; | ||
call BoolTest.binary(args); | ||
args.b = 1; | ||
call BoolTest.binary(args); | ||
args.a = 1; args.b = 0; | ||
call BoolTest.binary(args); | ||
args.a = args.b = 1; | ||
call BoolTest.binary(args); | ||
|
||
return 0; | ||
} | ||
|
||
event void BoolTest.unaryDone(const char *test_name, _Bool result, _Bool arg) { | ||
printf("%15s: %d -> %d\n", test_name, arg, result); | ||
} | ||
|
||
event void BoolTest.binaryDone(const char *test_name, _Bool result, bool_test_args args) { | ||
printf("%15s: %d, %d -> %d\n", test_name, args.a, args.b, result); | ||
} | ||
} |
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,34 @@ | ||
nx_struct nx_header { | ||
nx_uint32_t src; | ||
nx_uint32_t dst; | ||
}; | ||
|
||
configuration test { | ||
} | ||
implementation { | ||
components TestP; | ||
#define define_test(test_name, bool_expr) \ | ||
components new BoolTestM(bool_expr, #test_name) as Test##test_name; \ | ||
Test##test_name <- TestP.BoolTest | ||
|
||
define_test(TrueConst, 1); | ||
define_test(TrueExpr, 1 == 1 && 0 < 1); | ||
define_test(TrueExprSC, 0 == 0 || 0 > 1); | ||
define_test(IntTrue, 1234); | ||
define_test(FloatTrue, 1.23); | ||
define_test(String, "string"); | ||
|
||
define_test(FalseConst, 0); | ||
define_test(FalseExpr, 0 == 1 || 0 > 1); | ||
define_test(FalseExprSC, 1 == 0 && 0 < 1); | ||
define_test(IntZero, 0); | ||
define_test(FloatZero, 0.0); | ||
define_test(NullVoid, (const void *)0); | ||
define_test(NullULL, (unsigned long long *)0); | ||
define_test(NullStruct, (const bool_test_args *const __restrict)0); | ||
define_test(NullFnP, (int (*)(char[], double))0); | ||
define_test(Network, (nx_uint32_t *)0); | ||
define_test(NetworkStruct, (nx_struct nx_header *)0); | ||
|
||
#undef define_test | ||
} |
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,4 @@ | ||
interface BoolInit { | ||
command void test(); | ||
event void testDone(const char *test_name, _Bool value); | ||
} |
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,3 @@ | ||
interface BoolReturn { | ||
command _Bool get(); | ||
} |
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,17 @@ | ||
module NegativeIntM { | ||
provides { | ||
interface BoolInit; | ||
interface BoolReturn; | ||
} | ||
} | ||
implementation { | ||
_Bool value = -9876; | ||
|
||
command void BoolInit.test() { | ||
signal BoolInit.testDone("NegativeInt", value); | ||
} | ||
|
||
command _Bool BoolReturn.get() { | ||
return -9876; | ||
} | ||
} |
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,17 @@ | ||
module NoneZeroFloatM { | ||
provides { | ||
interface BoolInit; | ||
interface BoolReturn; | ||
} | ||
} | ||
implementation { | ||
_Bool value = 3.456; | ||
|
||
command void BoolInit.test() { | ||
signal BoolInit.testDone("NonZeroFloat", value); | ||
} | ||
|
||
command _Bool BoolReturn.get() { | ||
return 3.456; | ||
} | ||
} |
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,17 @@ | ||
module NullM { | ||
provides { | ||
interface BoolInit; | ||
interface BoolReturn; | ||
} | ||
} | ||
implementation { | ||
_Bool value = (void *)0; | ||
|
||
command void BoolInit.test() { | ||
signal BoolInit.testDone("Null", value); | ||
} | ||
|
||
command _Bool BoolReturn.get() { | ||
return (void *)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,17 @@ | ||
module PositiveIntM { | ||
provides { | ||
interface BoolInit; | ||
interface BoolReturn; | ||
} | ||
} | ||
implementation { | ||
_Bool value = (unsigned int)1234; | ||
|
||
command void BoolInit.test() { | ||
signal BoolInit.testDone("PositiveInt", value); | ||
} | ||
|
||
command _Bool BoolReturn.get() { | ||
return (unsigned int)1234; | ||
} | ||
} |
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,18 @@ | ||
module StringM { | ||
provides { | ||
interface BoolInit; | ||
interface BoolReturn; | ||
} | ||
} | ||
implementation { | ||
static const char string[] = "string"; | ||
_Bool value = &string; | ||
|
||
command void BoolInit.test() { | ||
signal BoolInit.testDone("String", value); | ||
} | ||
|
||
command _Bool BoolReturn.get() { | ||
return "string"; | ||
} | ||
} |
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,45 @@ | ||
extern int printf(const char *__restrict __format, ...); | ||
|
||
module TestP { | ||
uses { | ||
interface BoolInit; | ||
interface BoolReturn as ZeroInt; | ||
interface BoolReturn as PositiveInt; | ||
interface BoolReturn as NegativeInt; | ||
interface BoolReturn as ZeroFloat; | ||
interface BoolReturn as NoneZeroFloat; | ||
interface BoolReturn as String; | ||
interface BoolReturn as Null; | ||
} | ||
} | ||
implementation { | ||
static void testDone(const char *test_name, _Bool value) { | ||
printf("%15s: %d\n", test_name, value); | ||
} | ||
|
||
int main() @C() @spontaneous() { | ||
printf("===== BoolInit =====\n"); | ||
call BoolInit.test(); | ||
|
||
#define do_test(test_name) \ | ||
testDone(#test_name, call test_name.get()) | ||
|
||
printf("===== BoolReturn =====\n"); | ||
do_test(ZeroInt); | ||
do_test(ZeroFloat); | ||
do_test(Null); | ||
|
||
do_test(PositiveInt); | ||
do_test(NegativeInt); | ||
do_test(NoneZeroFloat); | ||
do_test(String); | ||
|
||
#undef do_test | ||
|
||
return 0; | ||
} | ||
|
||
event void BoolInit.testDone(const char *test_name, _Bool value) { | ||
testDone(test_name, value); | ||
} | ||
} |
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,17 @@ | ||
module ZeroFloatM { | ||
provides { | ||
interface BoolInit; | ||
interface BoolReturn; | ||
} | ||
} | ||
implementation { | ||
_Bool value = 0.00; | ||
|
||
command void BoolInit.test() { | ||
signal BoolInit.testDone("ZeroFloat", value); | ||
} | ||
|
||
command _Bool BoolReturn.get() { | ||
return 0.00; | ||
} | ||
} |
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,17 @@ | ||
module ZeroIntM { | ||
provides { | ||
interface BoolInit; | ||
interface BoolReturn; | ||
} | ||
} | ||
implementation { | ||
_Bool value = 0; | ||
|
||
command void BoolInit.test() { | ||
signal BoolInit.testDone("ZeroInt", value); | ||
} | ||
|
||
command _Bool BoolReturn.get() { | ||
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,21 @@ | ||
configuration test { | ||
} | ||
implementation { | ||
components TestP; | ||
|
||
#define define_test(test_name) \ | ||
components test_name##M; \ | ||
test_name##M <- TestP.BoolInit; \ | ||
test_name##M <- TestP.test_name | ||
|
||
define_test(ZeroInt); | ||
define_test(ZeroFloat); | ||
define_test(Null); | ||
|
||
define_test(PositiveInt); | ||
define_test(NegativeInt); | ||
define_test(NoneZeroFloat); | ||
define_test(String); | ||
|
||
#undef define_test | ||
} |
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
Oops, something went wrong.