1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
|
// -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi:tw=80:et:ts=2:sts=2
//
// -----------------------------------------------------------------------
//
// This file is part of RLVM, a RealLive virtual machine clone.
//
// -----------------------------------------------------------------------
//
// Copyright (C) 2006, 2007 Elliot Glaysher
//
// 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 3 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
// -----------------------------------------------------------------------
#include "gtest/gtest.h"
#include "libreallive/archive.h"
#include "libreallive/intmemref.h"
#include "machine/rlmachine.h"
#include "modules/module_mem.h"
#include "test_system/test_system.h"
#include "test_utils.h"
#include <iostream>
using namespace std;
using libreallive::IntMemRef;
// Tests setarray_0.
//
// Corresponding kepago listing:
//
// intA[3] = -1
// setarray(intA[0], 1, 2, 3)
//
TEST(LargeMemTest, setarray_0) {
libreallive::Archive arc(locateTestCase("Module_Mem_SEEN/setarray_0.TXT"));
TestSystem system;
RLMachine rlmachine(system, arc);
rlmachine.AttachModule(new MemModule);
rlmachine.ExecuteUntilHalted();
EXPECT_EQ(1, rlmachine.GetIntValue(IntMemRef('A', 0)))
<< "setarray returned wrong value for intA[0]";
EXPECT_EQ(2, rlmachine.GetIntValue(IntMemRef('A', 1)))
<< "setarray returned wrong value for intA[1]";
EXPECT_EQ(3, rlmachine.GetIntValue(IntMemRef('A', 2)))
<< "setarray returned wrong value for intA[2]";
EXPECT_EQ(-1, rlmachine.GetIntValue(IntMemRef('A', 3)))
<< "setarray touched the value in intA[3]!!";
}
// Tests setrng_0.
//
// Corresponding kepago listing:
//
// intA[4] = -1
// intA[0] = -1
// setrng(intA[0], intA[3])
TEST(LargeMemTest, setrng_0) {
libreallive::Archive arc(locateTestCase("Module_Mem_SEEN/setrng_0.TXT"));
TestSystem system;
RLMachine rlmachine(system, arc);
rlmachine.AttachModule(new MemModule);
rlmachine.ExecuteUntilHalted();
EXPECT_EQ(0, rlmachine.GetIntValue(IntMemRef('A', 0)))
<< "setrng returned wrong value for intA[0]";
EXPECT_EQ(0, rlmachine.GetIntValue(IntMemRef('A', 1)))
<< "setrng returned wrong value for intA[1]";
EXPECT_EQ(0, rlmachine.GetIntValue(IntMemRef('A', 2)))
<< "setrng returned wrong value for intA[2]";
EXPECT_EQ(0, rlmachine.GetIntValue(IntMemRef('A', 3)))
<< "setrng returned wrong value for intA[3]";
EXPECT_EQ(-1, rlmachine.GetIntValue(IntMemRef('A', 4)))
<< "setrng touched the value in intA[4]!!!";
}
// Tests setrng_1.
//
// intA[4] = -1
// intA[0] = -1
// setrng(intA[0], intA[3], 4)
TEST(LargeMemTest, setrng_1) {
libreallive::Archive arc(locateTestCase("Module_Mem_SEEN/setrng_1.TXT"));
TestSystem system;
RLMachine rlmachine(system, arc);
rlmachine.AttachModule(new MemModule);
rlmachine.ExecuteUntilHalted();
EXPECT_EQ(4, rlmachine.GetIntValue(IntMemRef('A', 0)))
<< "setrng returned wrong value for intA[0]";
EXPECT_EQ(4, rlmachine.GetIntValue(IntMemRef('A', 1)))
<< "setrng returned wrong value for intA[1]";
EXPECT_EQ(4, rlmachine.GetIntValue(IntMemRef('A', 2)))
<< "setrng returned wrong value for intA[2]";
EXPECT_EQ(4, rlmachine.GetIntValue(IntMemRef('A', 3)))
<< "setrng returned wrong value for intA[3]";
EXPECT_EQ(-1, rlmachine.GetIntValue(IntMemRef('A', 4)))
<< "setrng touched the value in intA[4]!!!";
}
// Tests cpyrng_0.
TEST(LargeMemTest, cpyrng_0) {
libreallive::Archive arc(locateTestCase("Module_Mem_SEEN/cpyrng_0.TXT"));
TestSystem system;
RLMachine rlmachine(system, arc);
rlmachine.AttachModule(new MemModule);
rlmachine.ExecuteUntilHalted();
// First make sure setarray did what we expected it to...
EXPECT_EQ(1, rlmachine.GetIntValue(IntMemRef('A', 0)))
<< "setarray returned wrong value for intA[0]";
EXPECT_EQ(2, rlmachine.GetIntValue(IntMemRef('A', 1)))
<< "setarray returned wrong value for intA[1]";
EXPECT_EQ(3, rlmachine.GetIntValue(IntMemRef('A', 2)))
<< "setarray returned wrong value for intA[2]";
// Now make sure cpyrng did its job.
EXPECT_EQ(1, rlmachine.GetIntValue(IntMemRef('B', 0)))
<< "cpyrng returned wrong value for intB[0]";
EXPECT_EQ(2, rlmachine.GetIntValue(IntMemRef('B', 1)))
<< "cpyrng returned wrong value for intB[1]";
EXPECT_EQ(3, rlmachine.GetIntValue(IntMemRef('B', 2)))
<< "cpyrng returned wrong value for intB[2]";
}
// Tests setarray_stepped_0.
//
// setrng(intA[0], intA[5], -1)
// setarray_stepped(intA[0], 2, 1, 2, 3)
//
TEST(LargeMemTest, setarray_stepped_0) {
libreallive::Archive arc(
locateTestCase("Module_Mem_SEEN/setarray_stepped_0.TXT"));
TestSystem system;
RLMachine rlmachine(system, arc);
rlmachine.AttachModule(new MemModule);
rlmachine.ExecuteUntilHalted();
// First make sure setarray_stepped did what we expected it to, and that it
// didn't overwrite the work of setrng
EXPECT_EQ(1, rlmachine.GetIntValue(IntMemRef('A', 0)))
<< "setarray_stepped returned wrong value for intA[0]";
EXPECT_EQ(-1, rlmachine.GetIntValue(IntMemRef('A', 1)))
<< "setarray_stepped touched the value of intA[1]";
EXPECT_EQ(2, rlmachine.GetIntValue(IntMemRef('A', 2)))
<< "setarray_stepped returned wrong value for intA[2]";
EXPECT_EQ(-1, rlmachine.GetIntValue(IntMemRef('A', 3)))
<< "setarray_stepped touched the value for intA[3]";
EXPECT_EQ(3, rlmachine.GetIntValue(IntMemRef('A', 4)))
<< "setarray_stepped returned wrong value for intA[4]";
EXPECT_EQ(-1, rlmachine.GetIntValue(IntMemRef('A', 5)))
<< "setarray_stepped touched the value for intA[5]";
}
// Tests setrng_stepped_0.
//
// setrng(intA[0], intA[5], -1)
// setrng_stepped(intA[0], 2, 3)
//
TEST(LargeMemTest, setrng_stepped_0) {
libreallive::Archive arc(
locateTestCase("Module_Mem_SEEN/setrng_stepped_0.TXT"));
TestSystem system;
RLMachine rlmachine(system, arc);
rlmachine.AttachModule(new MemModule);
rlmachine.ExecuteUntilHalted();
// First make sure setrng_stepped did what we expected it to, and that it
// didn't overwrite the work of setrng
EXPECT_EQ(0, rlmachine.GetIntValue(IntMemRef('A', 0)))
<< "setrng_stepped returned wrong value for intA[0]";
EXPECT_EQ(-1, rlmachine.GetIntValue(IntMemRef('A', 1)))
<< "setrng_stepped touched the value of intA[1]";
EXPECT_EQ(0, rlmachine.GetIntValue(IntMemRef('A', 2)))
<< "setrng_stepped returned wrong value for intA[2]";
EXPECT_EQ(-1, rlmachine.GetIntValue(IntMemRef('A', 3)))
<< "setrng_stepped touched the value for intA[3]";
EXPECT_EQ(0, rlmachine.GetIntValue(IntMemRef('A', 4)))
<< "setrng_stepped returned wrong value for intA[4]";
EXPECT_EQ(-1, rlmachine.GetIntValue(IntMemRef('A', 5)))
<< "setrng_stepped touched the value for intA[5]";
}
// Tests setrng_stepped_1.
//
// setrng(intA[0], intA[5], -1)
// setrng_stepped(intA[0], 2, 3, 5)
//
TEST(LargeMemTest, setrng_stepped_1) {
libreallive::Archive arc(
locateTestCase("Module_Mem_SEEN/setrng_stepped_1.TXT"));
TestSystem system;
RLMachine rlmachine(system, arc);
rlmachine.AttachModule(new MemModule);
rlmachine.ExecuteUntilHalted();
// First make sure setrng_stepped did what we expected it to, and that it
// didn't overwrite the work of setrng
EXPECT_EQ(5, rlmachine.GetIntValue(IntMemRef('A', 0)))
<< "setrng_stepped returned wrong value for intA[0]";
EXPECT_EQ(-1, rlmachine.GetIntValue(IntMemRef('A', 1)))
<< "setrng_stepped touched the value of intA[1]";
EXPECT_EQ(5, rlmachine.GetIntValue(IntMemRef('A', 2)))
<< "setrng_stepped returned wrong value for intA[2]";
EXPECT_EQ(-1, rlmachine.GetIntValue(IntMemRef('A', 3)))
<< "setrng_stepped touched the value for intA[3]";
EXPECT_EQ(5, rlmachine.GetIntValue(IntMemRef('A', 4)))
<< "setrng_stepped returned wrong value for intA[4]";
EXPECT_EQ(-1, rlmachine.GetIntValue(IntMemRef('A', 5)))
<< "setrng_stepped touched the value for intA[5]";
}
// Tests cpyvars.
//
// intB[3] = 5
// intB[5] = 1
// intB[8] = 2
// cpyvars(intA[0], 2, intB[1], intB[3], intB[6])
TEST(LargeMemTest, cpyvars) {
libreallive::Archive arc(locateTestCase("Module_Mem_SEEN/cpyvars_0.TXT"));
TestSystem system;
RLMachine rlmachine(system, arc);
rlmachine.AttachModule(new MemModule);
rlmachine.ExecuteUntilHalted();
// First make sure cpyvars did what we expected it to...
EXPECT_EQ(5, rlmachine.GetIntValue(IntMemRef('A', 0)))
<< "cpyvars set wrong value for intA[0]";
EXPECT_EQ(1, rlmachine.GetIntValue(IntMemRef('A', 1)))
<< "cpyvars set wrong value for intA[1]";
EXPECT_EQ(2, rlmachine.GetIntValue(IntMemRef('A', 2)))
<< "cpyvars set wrong value for intA[2]";
}
// Tests sum.
//
// intA[0] = 0
// intA[1] = 1
// intA[2] = 2
// intA[3] = 3
// intA[10] = sum(intA[0], intA[3])
//
TEST(LargeMemTest, sum_0) {
libreallive::Archive arc(locateTestCase("Module_Mem_SEEN/sum_0.TXT"));
TestSystem system;
RLMachine rlmachine(system, arc);
rlmachine.AttachModule(new MemModule);
rlmachine.ExecuteUntilHalted();
// First make sure sum did what we expected it to...
EXPECT_EQ(6, rlmachine.GetIntValue(IntMemRef('A', 10)))
<< "sum returned the wrong value for intA[10]";
}
|