Add tests for clearing BSS, copying C structs.
The new tests are bss_e.c, structcopy_e.c. We do clear the BSS before calling _m_a_i_n, so fix the comments in the other tests.
This commit is contained in:
parent
cdde55535e
commit
b38fcdded3
|
@ -1,6 +1,6 @@
|
|||
#include "test.h"
|
||||
|
||||
/* Bypasses the CRT, so there's no stdio or BSS initialisation. */
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void)
|
||||
{
|
||||
ASSERT(0 == 0);
|
||||
|
|
27
tests/plat/bss_e.c
Normal file
27
tests/plat/bss_e.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "test.h"
|
||||
|
||||
/*
|
||||
* EM puts these variables in BSS. Their initial values must be zero.
|
||||
* Some platforms, like Linux, clear the BSS before they run the
|
||||
* program. For other platforms, like pc86, we clear the BSS in
|
||||
* boot.s before we call _m_a_i_n.
|
||||
*/
|
||||
char c;
|
||||
int array[9000];
|
||||
short s;
|
||||
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void)
|
||||
{
|
||||
int bad, i;
|
||||
|
||||
ASSERT(c == 0);
|
||||
bad = 0;
|
||||
for (i = 0; i < sizeof(array) / sizeof(array[0]); i++) {
|
||||
if(array[i])
|
||||
bad++;
|
||||
}
|
||||
ASSERT(bad == 0);
|
||||
ASSERT(s == 0);
|
||||
finished();
|
||||
}
|
|
@ -40,7 +40,7 @@ void c(int i, int tru, int fal) {
|
|||
ASSERT((i != i) == fal);
|
||||
}
|
||||
|
||||
/* Bypasses the CRT. */
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void) {
|
||||
a();
|
||||
b();
|
||||
|
|
|
@ -9,22 +9,14 @@ definerule("plat_testsuite",
|
|||
-- Remember this is executed from the caller's directory; local
|
||||
-- target names will resolve there.
|
||||
local testfiles = filenamesof(
|
||||
-- added structcopy_e.c
|
||||
"tests/plat/*.c",
|
||||
"tests/plat/dup_e.e",
|
||||
"tests/plat/exg_e.e",
|
||||
"tests/plat/inn_e.e",
|
||||
"tests/plat/rck_e.e",
|
||||
"tests/plat/rotate_e.e",
|
||||
"tests/plat/*.e",
|
||||
"tests/plat/*.p",
|
||||
"tests/plat/b/*.b",
|
||||
"tests/plat/bugs/bug-22-inn_mod.mod",
|
||||
"tests/plat/bugs/bug-62-notvar_var_e.c",
|
||||
"tests/plat/m2/ConvTest_mod.mod",
|
||||
"tests/plat/m2/NestProc_mod.mod",
|
||||
"tests/plat/m2/OpenArray_mod.mod",
|
||||
"tests/plat/m2/SemaTest_mod.mod",
|
||||
"tests/plat/m2/Set100_mod.mod",
|
||||
"tests/plat/m2/StringTest_mod.mod"
|
||||
"tests/plat/bugs/*.c",
|
||||
"tests/plat/bugs/*.mod",
|
||||
"tests/plat/m2/*.mod"
|
||||
)
|
||||
|
||||
acklibrary {
|
||||
|
|
|
@ -11,7 +11,7 @@ int csa(int i)
|
|||
}
|
||||
}
|
||||
|
||||
/* Bypasses the CRT, so there's no stdio or BSS initialisation. */
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void)
|
||||
{
|
||||
ASSERT(csa(0) == 0);
|
||||
|
|
|
@ -11,7 +11,7 @@ int csa(int i)
|
|||
}
|
||||
}
|
||||
|
||||
/* Bypasses the CRT, so there's no stdio or BSS initialisation. */
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void)
|
||||
{
|
||||
ASSERT(csa(0) == 0);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
double one = 1.0;
|
||||
double zero = 0.0;
|
||||
|
||||
/* Bypasses the CRT, so there's no stdio or BSS initialisation. */
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void)
|
||||
{
|
||||
ASSERT(zero == zero);
|
||||
|
|
|
@ -8,7 +8,7 @@ double minusone = -1.0;
|
|||
double big = (double)INT_MAX;
|
||||
double minusbig = (double)INT_MIN;
|
||||
|
||||
/* Bypasses the CRT, so there's no stdio or BSS initialisation. */
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void)
|
||||
{
|
||||
ASSERT((int)zero == 0);
|
||||
|
|
|
@ -6,7 +6,7 @@ double one = 1.0;
|
|||
double zero = 0.0;
|
||||
double big = (double)UINT_MAX;
|
||||
|
||||
/* Bypasses the CRT, so there's no stdio or BSS initialisation. */
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void)
|
||||
{
|
||||
ASSERT((unsigned int)zero == 0);
|
||||
|
|
|
@ -8,7 +8,7 @@ int minusone = -1;
|
|||
int big = INT_MAX;
|
||||
int minusbig = INT_MIN;
|
||||
|
||||
/* Bypasses the CRT, so there's no stdio or BSS initialisation. */
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void)
|
||||
{
|
||||
ASSERT((double)zero == 0.0);
|
||||
|
|
|
@ -6,7 +6,7 @@ unsigned int one_u = 1;
|
|||
unsigned int zero_u = 0;
|
||||
unsigned int big_u = UINT_MAX;
|
||||
|
||||
/* Bypasses the CRT, so there's no stdio or BSS initialisation. */
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void)
|
||||
{
|
||||
ASSERT((double)zero_u == 0.0);
|
||||
|
|
|
@ -6,7 +6,7 @@ int one = 1;
|
|||
int zero = 0;
|
||||
int minusone = -1;
|
||||
|
||||
/* Bypasses the CRT, so there's no stdio or BSS initialisation. */
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void)
|
||||
{
|
||||
ASSERT((two + one) == 3);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
int one = 1;
|
||||
int zero = 0;
|
||||
|
||||
/* Bypasses the CRT, so there's no stdio or BSS initialisation. */
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void)
|
||||
{
|
||||
ASSERT(zero == zero);
|
||||
|
|
|
@ -6,7 +6,7 @@ int two = 2;
|
|||
int one = 1;
|
||||
int zero = 0;
|
||||
|
||||
/* Bypasses the CRT, so there's no stdio or BSS initialisation. */
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void)
|
||||
{
|
||||
ASSERT((three / two) == 1);
|
||||
|
|
|
@ -6,7 +6,7 @@ int two = 2;
|
|||
int one = 1;
|
||||
int zero = 0;
|
||||
|
||||
/* Bypasses the CRT, so there's no stdio or BSS initialisation. */
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void)
|
||||
{
|
||||
ASSERT((three % two) == 1);
|
||||
|
|
|
@ -6,7 +6,7 @@ int one = 1;
|
|||
int zero = 0;
|
||||
int minusone = -1;
|
||||
|
||||
/* Bypasses the CRT, so there's no stdio or BSS initialisation. */
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void)
|
||||
{
|
||||
ASSERT((one <<zero) == 1);
|
||||
|
|
|
@ -7,7 +7,7 @@ int one = 1;
|
|||
int zero = 0;
|
||||
int minusone = -1;
|
||||
|
||||
/* Bypasses the CRT, so there's no stdio or BSS initialisation. */
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void)
|
||||
{
|
||||
ASSERT((two - one) == 1);
|
||||
|
|
113
tests/plat/structcopy_e.c
Normal file
113
tests/plat/structcopy_e.c
Normal file
|
@ -0,0 +1,113 @@
|
|||
#include "test.h"
|
||||
|
||||
/* ACK's C compiler uses EM's loi, sti, blm, or an inline loop to copy
|
||||
* these structs. The compiler doesn't call memcpy() or other
|
||||
* functions in libc, so this test passes without linking the CRT.
|
||||
*/
|
||||
|
||||
struct c5 { /* not a whole number of words */
|
||||
char one[5];
|
||||
};
|
||||
|
||||
struct ii { /* two words */
|
||||
int one;
|
||||
int two;
|
||||
};
|
||||
|
||||
struct iii { /* three words */
|
||||
int one;
|
||||
int two;
|
||||
int three;
|
||||
};
|
||||
|
||||
int equal5(char *a, char *b) { /* a, b must have 5 characters */
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 5; i++)
|
||||
if (a[i] != b[i]) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct c5 make_c5(char *str) { /* str must have 5 characters */
|
||||
struct c5 out;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 5; i++)
|
||||
out.one[i] = str[i];
|
||||
return out;
|
||||
}
|
||||
|
||||
struct ii make_ii(int i, int j) {
|
||||
struct ii out;
|
||||
|
||||
out.one = i;
|
||||
out.two = j;
|
||||
return out;
|
||||
}
|
||||
|
||||
struct iii make_iii(struct ii in, int k) {
|
||||
struct iii out;
|
||||
|
||||
out.one = in.one;
|
||||
out.two = in.two;
|
||||
out.three = k;
|
||||
return out;
|
||||
}
|
||||
|
||||
struct c5 rotate_left_c5(struct c5 in) {
|
||||
int i;
|
||||
char c = in.one[0];
|
||||
|
||||
/* Modifies our copy of _in_, not caller's copy. */
|
||||
for (i = 0; i < 4; i++)
|
||||
in.one[i] = in.one[i + 1];
|
||||
in.one[4] = c;
|
||||
return in;
|
||||
}
|
||||
|
||||
struct iii rotate_left_iii(struct iii in) {
|
||||
int i = in.one;
|
||||
|
||||
/* Modifies our copy of _in_, not caller's copy. */
|
||||
in.one = in.two;
|
||||
in.two = in.three;
|
||||
in.three = i;
|
||||
return in;
|
||||
}
|
||||
|
||||
/* Bypasses the CRT, so there's no stdio. */
|
||||
void _m_a_i_n(void) {
|
||||
struct c5 earth, heart, dup_heart, rol_heart;
|
||||
struct ii pair, dup_pair;
|
||||
struct iii triple, dup_triple, rol_triple;
|
||||
|
||||
earth = make_c5("earth");
|
||||
heart = make_c5("heart");
|
||||
dup_heart = heart;
|
||||
rol_heart = rotate_left_c5(heart);
|
||||
ASSERT(equal5(earth.one, "earth"));
|
||||
ASSERT(equal5(heart.one, "heart"));
|
||||
ASSERT(equal5(dup_heart.one, "heart"));
|
||||
ASSERT(equal5(rol_heart.one, "earth"));
|
||||
|
||||
pair = make_ii(29, 31);
|
||||
dup_pair = pair;
|
||||
triple = make_iii(pair, -9);
|
||||
dup_triple = triple;
|
||||
rol_triple = rotate_left_iii(triple);
|
||||
ASSERT(pair.one == 29);
|
||||
ASSERT(pair.two == 31);
|
||||
ASSERT(dup_pair.one == 29);
|
||||
ASSERT(dup_pair.two == 31);
|
||||
ASSERT(triple.one == 29);
|
||||
ASSERT(triple.two == 31);
|
||||
ASSERT(triple.three == -9);
|
||||
ASSERT(dup_triple.one == 29);
|
||||
ASSERT(dup_triple.two == 31);
|
||||
ASSERT(dup_triple.three == -9);
|
||||
ASSERT(rol_triple.one == 31);
|
||||
ASSERT(rol_triple.two == -9);
|
||||
ASSERT(rol_triple.three == 29);
|
||||
|
||||
finished();
|
||||
}
|
Loading…
Reference in a new issue