Skip to content
Browse files

parameterizable fibonacci tests runs for multiple inputs (tested unti…

…l 2000th number)
  • Loading branch information...
1 parent 729fd17 commit f0abd1ea9a867d5dffb53c22ea92b8b3be397ec6 @sztomi committed
Showing with 70 additions and 1 deletion.
  1. +1 −1 premake4.lua
  2. +3 −0 src/mipscpu.cpp
  3. +1 −0 src/mipscpu.h
  4. +65 −0 test/main.cpp
  5. BIN testmips/fibo_2.bin
View
2 premake4.lua
@@ -9,7 +9,7 @@ solution "tememu"
configuration { "debug" }
targetdir "build/debug"
- defines { "DEBUG", "TRACE_OPCODES" }
+ defines { "DEBUG" }
configuration { "release" }
targetdir "build/release"
View
3 src/mipscpu.cpp
@@ -29,6 +29,7 @@
#include <cstring>
#include <iostream>
+
namespace tememu
{
#ifndef TRACE_OPCODES
@@ -79,6 +80,8 @@ namespace tememu
for ( int i = 0; i < gpr_count; ++i ) _GPR[i] = 0;
for ( int i = 0; i < fpr_count; ++i ) _FPR[i] = 0;
for ( int i = 0; i < fcr_count; ++i ) _FCR[i] = 0;
+ _HI = _LO = _FCSR = 0;
+ _nPC = _PC = 4;
}
/**
View
1 src/mipscpu.h
@@ -60,6 +60,7 @@ namespace tememu
void runProgram();
void reset();
int32 gprValue(int index) const { return _GPR[index]; }
+ void setGPR(int index, int32 value) { _GPR[index] = value; } // range checking?
int32 hi() const { return _HI; }
int32 lo() const { return _LO; }
View
65 test/main.cpp
@@ -399,3 +399,68 @@ TEST(Complex, fibonacci)
EXPECT_EQ(cpu.lo(), 34);
}
+TEST(Complex, fibonacci2)
+{
+ boost::shared_ptr< std::vector<int32> > program(new std::vector<int32>);
+ tememu::MipsCPU cpu;
+
+ loadMipsBinDump("testmips/fibo_2.bin", program);
+
+ cpu.loadProgram(program);
+
+ cpu.setGPR(7,8);
+
+ cpu.stepProgram(9);
+
+ EXPECT_EQ(cpu.gprValue(2), 1);
+ EXPECT_EQ(cpu.gprValue(4), 1);
+ EXPECT_EQ(cpu.gprValue(5), 1);
+ EXPECT_EQ(cpu.gprValue(6), 1);
+ EXPECT_EQ(cpu.gprValue(7), 8);
+ EXPECT_EQ(cpu.hi(), 1);
+ EXPECT_EQ(cpu.lo(), 1);
+
+ cpu.stepProgram();
+
+ EXPECT_EQ(cpu.gprValue(7), 7);
+
+ cpu.runProgram();
+
+ EXPECT_EQ(cpu.gprValue(2), 1);
+ EXPECT_EQ(cpu.gprValue(4), 21);
+ EXPECT_EQ(cpu.gprValue(5), 34);
+ EXPECT_EQ(cpu.gprValue(6), 34);
+ EXPECT_EQ(cpu.gprValue(7), 0);
+ EXPECT_EQ(cpu.hi(), 34);
+ EXPECT_EQ(cpu.lo(), 21);
+}
+
+int fibo(int n)
+{
+ int a = 1, b = 0, c = 0;
+ for ( int i = 0; i < n; ++i )
+ {
+ c = a + b;
+ a = b;
+ b = c;
+ }
+ return c;
+}
+
+TEST(Complex, fibonacci3)
+{
+ boost::shared_ptr< std::vector<int32> > program(new std::vector<int32>);
+ tememu::MipsCPU cpu;
+
+ loadMipsBinDump("testmips/fibo_2.bin", program);
+ cpu.loadProgram(program);
+
+ for ( int i = 1; i < 20; ++i )
+ {
+ cpu.setGPR(7,i); cpu.runProgram();
+ EXPECT_EQ(fibo(i+1), cpu.gprValue(5));
+
+ cpu.reset();
+ }
+ }
+
View
BIN testmips/fibo_2.bin
Binary file not shown.

0 comments on commit f0abd1e

Please sign in to comment.
Something went wrong with that request. Please try again.