summaryrefslogtreecommitdiffhomepage
path: root/mixlib/testsuite
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2004-06-09 22:49:17 +0000
committerJose Antonio Ortega Ruiz <jao@gnu.org>2004-06-09 22:49:17 +0000
commitfa1f40e8b2dc8d0c93179e80fc74d746be59a3fe (patch)
tree18c02eb0d0775b5cd5386b2e78f3719264451ef9 /mixlib/testsuite
parent4a2addab5bb22c113bb9156f05b4f8f134a9b1d2 (diff)
downloadmdk-fa1f40e8b2dc8d0c93179e80fc74d746be59a3fe.tar.gz
mdk-fa1f40e8b2dc8d0c93179e80fc74d746be59a3fe.tar.bz2
new LDN behaviour.
Diffstat (limited to 'mixlib/testsuite')
-rw-r--r--mixlib/testsuite/mix_vm_ins_t.c131
1 files changed, 68 insertions, 63 deletions
diff --git a/mixlib/testsuite/mix_vm_ins_t.c b/mixlib/testsuite/mix_vm_ins_t.c
index 55ce7f3..ce368ee 100644
--- a/mixlib/testsuite/mix_vm_ins_t.c
+++ b/mixlib/testsuite/mix_vm_ins_t.c
@@ -1,32 +1,32 @@
/* ---------------------- mix_vm_ins_t.c :
* Tests for the virtual machine instruction handlers.
* ------------------------------------------------------------------
-** Copyright (C) 2000 Free Software Foundation, Inc.
-**
+** Copyright (C) 2000, 2004 Free Software Foundation, Inc.
+**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
-**
+**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
-**
+**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-**
+**
*/
#include <stdlib.h>
-/*#define VERBOSE_TEST*/
+/* #define VERBOSE_TEST */
#include "test.h"
#include "mix_vm.h"
#include "mix_vm_dump.h"
-typedef struct
+typedef struct
{
mix_word_t rA_b, rA_a;
mix_word_t rX_b, rX_a;
@@ -49,7 +49,7 @@ set_cells_(test_desc_t *t, mix_address_t begin, mix_address_t end)
t->cells_a = g_new(mix_word_t,end-begin);
}
-static void
+static void
free_cells_(test_desc_t *t)
{
g_assert(t);
@@ -66,7 +66,7 @@ fill_test_desc_(test_desc_t *t, const mix_vm_t *vm, const mix_ins_t *ins)
guint k;
g_assert(t);
g_assert(vm);
-
+
t->rA_b = t->rA_a = mix_vm_get_rA(vm);
t->rX_b = t->rX_a = mix_vm_get_rX(vm);
t->rJ_b = t->rJ_a = mix_vm_get_rJ(vm);
@@ -74,9 +74,9 @@ fill_test_desc_(test_desc_t *t, const mix_vm_t *vm, const mix_ins_t *ins)
t->rI_b[k] = t->rI_a[k] = mix_vm_get_rI(vm,k+1);
t->cmp_b = t->cmp_a = mix_vm_get_cmpflag(vm);
t->over_b = t->over_a = mix_vm_get_overflow(vm);
-
+
for (k = 0; k < t->end-t->begin; ++k)
- t->cells_a[k] = t->cells_b[k] =
+ t->cells_a[k] = t->cells_b[k] =
mix_vm_get_addr_contents(vm,t->begin+k);
t->ins = ins;
}
@@ -88,7 +88,7 @@ run_test_(test_desc_t *t, mix_vm_t *vm, mix_dump_context_t *dc)
guint k;
g_assert(t);
g_assert(vm);
-
+
mix_vm_set_rA(vm, t->rA_b);
mix_vm_set_rX(vm, t->rX_b);
mix_vm_set_rJ(vm, t->rJ_b);
@@ -115,7 +115,7 @@ run_test_(test_desc_t *t, mix_vm_t *vm, mix_dump_context_t *dc)
g_assert(mix_vm_get_addr_contents(vm, k) == t->cells_a[k-t->begin]);
}
-
+
static void
test_arithmetics_(mix_vm_t *vm, mix_dump_context_t *dc)
@@ -266,23 +266,23 @@ test_spc_(mix_vm_t *vm, mix_dump_context_t *dc)
test.rX_a = test.rX_b;
run_test_(&test, vm, dc);
- mix_ins_fill_from_id(ins, mix_INCA);
- ins.address = 1;
- fill_test_desc_(&test, vm, &ins);
+ mix_ins_fill_from_id(ins, mix_INCA);
+ ins.address = 1;
+ fill_test_desc_(&test, vm, &ins);
test.rA_a = mix_word_negative(12977699);
run_test_(&test, vm, dc);
- mix_ins_fill_from_id(ins, mix_CHAR);
- fill_test_desc_(&test, vm, &ins);
+ mix_ins_fill_from_id(ins, mix_CHAR);
+ fill_test_desc_(&test, vm, &ins);
test.rA_a = mix_word_new_bn(30,30,31,32,39);
test.rX_a = mix_word_new_b(37,37,36,39,39);
run_test_(&test, vm, dc);
-
+
mix_ins_fill_from_id(ins, mix_HLT);
fill_test_desc_(&test, vm, &ins);
run_test_(&test, vm, dc);
g_assert(mix_vm_is_halted(vm));
-
+
}
static void
@@ -297,21 +297,21 @@ test_move_(mix_vm_t *vm, mix_dump_context_t *dc)
set_cells_(&test,0,10);
fill_test_desc_(&test,vm,&ins);
mix_ins_fill_from_id(ins,mix_MOVE);
-
+
ins.index = 0;
ins.address = 0;
ins.fspec = 5;
for ( k = 0; k < 5; ++k )
test.cells_b[k] = test.cells_a[k+5] = test.cells_a[k] =mix_word_new(100*k);
-
+
test.rI_b[0] = 5;
test.rI_a[0] = 10;
run_test_(&test,vm,dc);
-
+
free_cells_(&test);
}
-
+
static void
test_load_(mix_vm_t *vm, mix_dump_context_t *dc)
@@ -319,43 +319,47 @@ test_load_(mix_vm_t *vm, mix_dump_context_t *dc)
test_desc_t test;
mix_ins_t ins;
mix_ins_id_t ids[4] = {mix_LDA, mix_LDX, mix_LDAN, mix_LDXN};
- mix_word_t r_a[14] = { mix_word_new_bn(1,16,3,5,4),
- mix_word_new_b(1,16,3,5,4),
- mix_word_new_b(0,0,3,5,4),
- mix_word_new_bn(0,0,1,16,3),
- mix_word_new_b(0,0,0,0,5),
- MIX_WORD_MINUS_ZERO,
- mix_word_new_b(0,0,0,0,1),
- mix_word_new_b(1,16,3,5,4),
- mix_word_new_b(1,16,3,5,4),
- mix_word_new_b(0,0,3,5,4),
- mix_word_new_b(0,0,1,16,3),
- mix_word_new_b(0,0,0,0,5),
- MIX_WORD_ZERO,
- mix_word_new_b(0,0,0,0,1)};
- mix_fspec_t fs[11] = {5,13,29,3,36,0,9,0,0,0,0};
- mix_address_t a_a[11] = { MIX_SHORT_MINUS_ZERO,
- mix_short_new_bn(0,1),
- mix_short_new_bn(1,16),
- mix_short_new_bn(16,3),
- mix_short_new_bn(3,5),
- mix_short_new_bn(5,4),
- mix_short_new_b(1,16),
- mix_short_new_b(16,3),
- mix_short_new_b(5,4),
- mix_short_new_b(5,4),
- mix_short_new_b(3,5)};
+ mix_word_t r_a[14] = {
+ mix_word_new_bn(1,16,3,5,4),
+ mix_word_new_b(1,16,3,5,4),
+ mix_word_new_b(0,0,3,5,4),
+ mix_word_new_bn(0,0,1,16,3),
+ mix_word_new_b(0,0,0,0,5),
+ mix_word_new_b(0,0,0,0,1),
+ MIX_WORD_MINUS_ZERO,
+ mix_word_new_b(1,16,3,5,4),
+ mix_word_new_bn(1,16,3,5,4),
+ mix_word_new_bn(0,0,3,5,4),
+ mix_word_new_b(0,0,1,16,3),
+ mix_word_new_bn(0,0,0,0,5),
+ mix_word_new_bn(0,0,0,0,1),
+ MIX_WORD_ZERO
+ };
+ mix_fspec_t fs[11] = {5,13,29,3,36,9,0,0,0,0,0};
+ mix_address_t a_a[11] = {
+ MIX_SHORT_MINUS_ZERO,
+ mix_short_new_bn(0,1),
+ mix_short_new_bn(1,16),
+ mix_short_new_bn(16,3),
+ mix_short_new_bn(3,5),
+ mix_short_new_bn(5,4),
+ mix_short_new_b(1,16),
+ mix_short_new_b(16,3),
+ mix_short_new_b(5,4),
+ mix_short_new_b(5,4),
+ mix_short_new_b(3,5)
+ };
mix_word_t val = mix_word_new_bn(1,16,3,5,4);
gint j;
-
+
g_print("Testing load instructions...\n");
set_cells_(&test,2000,2001);
ins.index = 1;
ins.address = mix_short_negative(50);
-
+
mix_vm_reset(vm);
mix_vm_set_addr_contents(vm, 2000, val);
-
+
for (j = 0; j < 4; ++j)
{
gint k;
@@ -363,23 +367,24 @@ test_load_(mix_vm_t *vm, mix_dump_context_t *dc)
for ( k = 0; k < 7; ++k ) {
fill_test_desc_(&test,vm,&ins);
ins.fspec = fs[k];
- switch (ids[j])
+ switch (ids[j])
{
case mix_LDA: test.rA_a = r_a[k]; break;
case mix_LDX: test.rX_a = r_a[k]; break;
- case mix_LDAN: test.rA_a = r_a[k+7]; break;
- case mix_LDXN: test.rX_a = r_a[k+7]; break;
+ case mix_LDAN: test.rA_a = r_a[k + 7]; break;
+ case mix_LDXN: test.rX_a = r_a[k + 7]; break;
default: g_assert_not_reached();
}
test.rI_b[0] = test.rI_a[0] = 2050;
run_test_(&test, vm, dc);
}
}
+
ins.index = 0;
ins.address = 2000;
fs[0] = 0; fs[1] = 1; fs[2] = 2; fs[3] = 3; fs[4] = 4; fs[5] = 5;
fs[6] = 10; fs[7] = 11; fs[8] = 37; fs[9] = 29; fs[10] = 12;
-
+
mix_vm_reset(vm);
mix_vm_set_addr_contents(vm, 2000, val);
for ( j = 0; j < 14; j++ )
@@ -394,7 +399,7 @@ test_load_(mix_vm_t *vm, mix_dump_context_t *dc)
if ( j < 6 )
test.rI_a[j] = a_a[k];
else /* mix_LDiN */
- test.rI_a[j-8] = mix_short_magnitude(a_a[k]);
+ test.rI_a[j-8] = mix_short_negative (a_a[k]);
run_test_(&test, vm, dc);
}
}
@@ -436,7 +441,7 @@ test_store_(mix_vm_t *vm, mix_dump_context_t *dc)
set_cells_(&test,2000,2001);
ins.index = 0;
ins.address = 2000;
-
+
mix_vm_reset(vm);
fill_test_desc_(&test,vm,&ins);
test.rA_a = test.rA_b = test.rX_a = test.rX_b = reg;
@@ -444,7 +449,7 @@ test_store_(mix_vm_t *vm, mix_dump_context_t *dc)
for (j = 0; j < 6; ++j)
test.rI_a[j] = test.rI_b[j] = test.rJ_a;
test.cells_b[0] = add;
-
+
for (i = 0; i < 10; ++i)
{
mix_ins_fill_from_id(ins,mix_STA+i);
@@ -460,7 +465,7 @@ test_store_(mix_vm_t *vm, mix_dump_context_t *dc)
run_test_(&test,vm,dc);
}
}
-
+
free_cells_(&test);
}
@@ -471,7 +476,7 @@ main(int argc, const char **argv)
{
mix_vm_t *vm;
mix_dump_context_t *dc;
-
+
INIT_TEST;
vm = mix_vm_new();
@@ -488,7 +493,7 @@ main(int argc, const char **argv)
test_move_(vm,dc);
test_load_(vm,dc);
test_store_(vm,dc);
-
+
mix_vm_delete(vm);
#ifdef VERBOSE_TEST