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:
George Koehler 2018-01-27 20:09:16 -05:00
parent cdde55535e
commit b38fcdded3
18 changed files with 173 additions and 41 deletions

View file

@ -1,6 +1,6 @@
#include "test.h" #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) void _m_a_i_n(void)
{ {
ASSERT(0 == 0); ASSERT(0 == 0);

27
tests/plat/bss_e.c Normal file
View 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();
}

View file

@ -40,7 +40,7 @@ void c(int i, int tru, int fal) {
ASSERT((i != i) == fal); ASSERT((i != i) == fal);
} }
/* Bypasses the CRT. */ /* Bypasses the CRT, so there's no stdio. */
void _m_a_i_n(void) { void _m_a_i_n(void) {
a(); a();
b(); b();

View file

@ -9,22 +9,14 @@ definerule("plat_testsuite",
-- Remember this is executed from the caller's directory; local -- Remember this is executed from the caller's directory; local
-- target names will resolve there. -- target names will resolve there.
local testfiles = filenamesof( local testfiles = filenamesof(
-- added structcopy_e.c
"tests/plat/*.c", "tests/plat/*.c",
"tests/plat/dup_e.e", "tests/plat/*.e",
"tests/plat/exg_e.e",
"tests/plat/inn_e.e",
"tests/plat/rck_e.e",
"tests/plat/rotate_e.e",
"tests/plat/*.p", "tests/plat/*.p",
"tests/plat/b/*.b", "tests/plat/b/*.b",
"tests/plat/bugs/bug-22-inn_mod.mod", "tests/plat/bugs/*.c",
"tests/plat/bugs/bug-62-notvar_var_e.c", "tests/plat/bugs/*.mod",
"tests/plat/m2/ConvTest_mod.mod", "tests/plat/m2/*.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"
) )
acklibrary { acklibrary {

View file

@ -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) void _m_a_i_n(void)
{ {
ASSERT(csa(0) == 0); ASSERT(csa(0) == 0);
@ -23,4 +23,4 @@ void _m_a_i_n(void)
ASSERT(csa(6) == 0); ASSERT(csa(6) == 0);
finished(); finished();
} }

View file

@ -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) void _m_a_i_n(void)
{ {
ASSERT(csa(0) == 0); ASSERT(csa(0) == 0);
@ -23,4 +23,4 @@ void _m_a_i_n(void)
ASSERT(csa(600) == 0); ASSERT(csa(600) == 0);
finished(); finished();
} }

View file

@ -4,7 +4,7 @@
double one = 1.0; double one = 1.0;
double zero = 0.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) void _m_a_i_n(void)
{ {
ASSERT(zero == zero); ASSERT(zero == zero);
@ -17,4 +17,4 @@ void _m_a_i_n(void)
ASSERT(one >= one); ASSERT(one >= one);
finished(); finished();
} }

View file

@ -8,7 +8,7 @@ double minusone = -1.0;
double big = (double)INT_MAX; double big = (double)INT_MAX;
double minusbig = (double)INT_MIN; 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) void _m_a_i_n(void)
{ {
ASSERT((int)zero == 0); ASSERT((int)zero == 0);
@ -18,4 +18,4 @@ void _m_a_i_n(void)
ASSERT((int)minusbig == INT_MIN); ASSERT((int)minusbig == INT_MIN);
finished(); finished();
} }

View file

@ -6,7 +6,7 @@ double one = 1.0;
double zero = 0.0; double zero = 0.0;
double big = (double)UINT_MAX; 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) void _m_a_i_n(void)
{ {
ASSERT((unsigned int)zero == 0); ASSERT((unsigned int)zero == 0);
@ -14,4 +14,4 @@ void _m_a_i_n(void)
ASSERT((unsigned int)big == UINT_MAX); ASSERT((unsigned int)big == UINT_MAX);
finished(); finished();
} }

View file

@ -8,7 +8,7 @@ int minusone = -1;
int big = INT_MAX; int big = INT_MAX;
int minusbig = INT_MIN; 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) void _m_a_i_n(void)
{ {
ASSERT((double)zero == 0.0); ASSERT((double)zero == 0.0);
@ -18,4 +18,4 @@ void _m_a_i_n(void)
/* ASSERT((double)minusbig == (double)INT_MIN); FIXME: fails for now */ /* ASSERT((double)minusbig == (double)INT_MIN); FIXME: fails for now */
finished(); finished();
} }

View file

@ -6,7 +6,7 @@ unsigned int one_u = 1;
unsigned int zero_u = 0; unsigned int zero_u = 0;
unsigned int big_u = UINT_MAX; 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) void _m_a_i_n(void)
{ {
ASSERT((double)zero_u == 0.0); ASSERT((double)zero_u == 0.0);
@ -14,4 +14,4 @@ void _m_a_i_n(void)
ASSERT((double)big_u == (double)UINT_MAX); ASSERT((double)big_u == (double)UINT_MAX);
finished(); finished();
} }

View file

@ -6,7 +6,7 @@ int one = 1;
int zero = 0; int zero = 0;
int minusone = -1; 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) void _m_a_i_n(void)
{ {
ASSERT((two + one) == 3); ASSERT((two + one) == 3);
@ -28,4 +28,4 @@ void _m_a_i_n(void)
ASSERT(((unsigned int)-1 + (unsigned int)two) == 1); ASSERT(((unsigned int)-1 + (unsigned int)two) == 1);
finished(); finished();
} }

View file

@ -4,7 +4,7 @@
int one = 1; int one = 1;
int zero = 0; 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) void _m_a_i_n(void)
{ {
ASSERT(zero == zero); ASSERT(zero == zero);
@ -62,4 +62,4 @@ void _m_a_i_n(void)
ASSERT((unsigned int)1 >= (unsigned int)one); ASSERT((unsigned int)1 >= (unsigned int)one);
finished(); finished();
} }

View file

@ -6,7 +6,7 @@ int two = 2;
int one = 1; int one = 1;
int zero = 0; 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) void _m_a_i_n(void)
{ {
ASSERT((three / two) == 1); ASSERT((three / two) == 1);
@ -25,4 +25,4 @@ void _m_a_i_n(void)
ASSERT((3 / -two) == -1); ASSERT((3 / -two) == -1);
finished(); finished();
} }

View file

@ -6,7 +6,7 @@ int two = 2;
int one = 1; int one = 1;
int zero = 0; 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) void _m_a_i_n(void)
{ {
ASSERT((three % two) == 1); ASSERT((three % two) == 1);
@ -25,4 +25,4 @@ void _m_a_i_n(void)
ASSERT((3 % -two) == 1); ASSERT((3 % -two) == 1);
finished(); finished();
} }

View file

@ -6,7 +6,7 @@ int one = 1;
int zero = 0; int zero = 0;
int minusone = -1; 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) void _m_a_i_n(void)
{ {
ASSERT((one <<zero) == 1); ASSERT((one <<zero) == 1);
@ -50,4 +50,4 @@ void _m_a_i_n(void)
ASSERT(((unsigned int)minusone>>(unsigned int)1) == (UINT_MAX>>1)); ASSERT(((unsigned int)minusone>>(unsigned int)1) == (UINT_MAX>>1));
finished(); finished();
} }

View file

@ -7,7 +7,7 @@ int one = 1;
int zero = 0; int zero = 0;
int minusone = -1; 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) void _m_a_i_n(void)
{ {
ASSERT((two - one) == 1); ASSERT((two - one) == 1);
@ -29,4 +29,4 @@ void _m_a_i_n(void)
ASSERT(((unsigned int)1 - (unsigned int)two) == UINT_MAX); ASSERT(((unsigned int)1 - (unsigned int)two) == UINT_MAX);
finished(); finished();
} }

113
tests/plat/structcopy_e.c Normal file
View 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();
}