GP-0: Move several ghidra.pcode packages to Framework Emulation

This commit is contained in:
Dan 2023-04-21 14:58:54 -04:00
parent 39611523bf
commit 88650b1dbb
126 changed files with 5 additions and 6 deletions

View file

@ -1,255 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.memstate;
import static org.junit.Assert.*;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import generic.test.AbstractGenericTest;
import ghidra.pcode.error.LowlevelError;
import ghidra.pcode.memstate.UniqueMemoryBank.WordInfo;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.address.GenericAddressSpace;
import ghidra.program.model.lang.SpaceNames;
public class UniqueMemoryBankTest extends AbstractGenericTest {
private AddressSpace uniqueSpace;
private UniqueMemoryBank uniqueBank;
private byte[] eightTestBytes = new byte[] { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7 };
private byte[] eightZeroBytes = new byte[8];
private byte[] sixteenTestBytes = new byte[] { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9,
0xa, 0xb, 0xc, 0xd, 0xe, 0xf };
@Before
public void setUp() {
uniqueSpace =
new GenericAddressSpace(SpaceNames.UNIQUE_SPACE_NAME, 64, AddressSpace.TYPE_UNIQUE, 0);
uniqueBank = new UniqueMemoryBank(uniqueSpace, false);
}
public UniqueMemoryBankTest() {
super();
}
@Test
public void WordInfoBasicTest() {
WordInfo info = new WordInfo();
assertFalse(info.isEntireWordInitialized());
info.setByte((byte) 0x0, 0);
assertFalse(info.isEntireWordInitialized());
info.setByte((byte) 0x1, 1);
assertFalse(info.isEntireWordInitialized());
info.setByte((byte) 0x2, 2);
assertFalse(info.isEntireWordInitialized());
info.setByte((byte) 0x3, 3);
assertFalse(info.isEntireWordInitialized());
info.setByte((byte) 0x4, 4);
assertFalse(info.isEntireWordInitialized());
info.setByte((byte) 0x5, 5);
assertFalse(info.isEntireWordInitialized());
info.setByte((byte) 0x6, 6);
assertFalse(info.isEntireWordInitialized());
info.setByte((byte) 0x7, 7);
assertTrue(info.isEntireWordInitialized());
for (int i = 0; i < 8; ++i) {
assertEquals((byte) i, info.getByte(i));
}
}
@Test(expected = LowlevelError.class)
public void testGetUninitializedByte() {
WordInfo info = new WordInfo();
info.setByte((byte) 0, 0);
info.setByte((byte) 1, 1);
info.setByte((byte) 3, 3);
info.setByte((byte) 4, 4);
info.setByte((byte) 5, 5);
info.setByte((byte) 6, 6);
info.setByte((byte) 7, 7);
@SuppressWarnings("unused")
byte val = info.getByte(2);
}
@Test
public void testSimpleRead() {
uniqueBank.setChunk(0x1000, 8, eightTestBytes);
byte[] dest = new byte[8];
int numBytes = uniqueBank.getChunk(0x1000, 8, dest, true);
assertEquals(8, numBytes);
assertTrue(Arrays.equals(dest, eightTestBytes));
}
@Test
public void testDifferentlySizedReads() {
uniqueBank.setChunk(0x1000, 8, eightTestBytes);
byte[] dest = new byte[4];
int numBytes = uniqueBank.getChunk(0x1000, 4, dest, true);
assertEquals(4, numBytes);
assertTrue(Arrays.equals(dest, new byte[] { 0x0, 0x1, 0x2, 0x3 }));
numBytes = uniqueBank.getChunk(0x1004, 4, dest, true);
assertEquals(4, numBytes);
assertTrue(Arrays.equals(dest, new byte[] { 0x4, 0x5, 0x6, 0x7 }));
}
@Test
public void testLargeReadWrite() {
uniqueBank.setChunk(0x1004, 16, sixteenTestBytes);
byte[] dest = new byte[16];
int numBytes = uniqueBank.getChunk(0x1004, 16, dest, true);
assertEquals(16, numBytes);
assertTrue(Arrays.equals(dest, sixteenTestBytes));
byte[] largeSrc = new byte[64];
for (int i = 0; i < 64; ++i) {
largeSrc[i] = (byte) (i + 1);
}
uniqueBank.setChunk(0x1007, 64, largeSrc);
dest = new byte[64];
numBytes = uniqueBank.getChunk(0x1007, 64, dest, true);
assertEquals(64, numBytes);
assertTrue(Arrays.equals(dest, largeSrc));
}
@Test
public void testReadAcrossUndefined() {
byte[] fourBytes = new byte[] { 0x11, 0x22, 0x33, 0x44 };
uniqueBank.setChunk(0x1007, 4, fourBytes);
uniqueBank.setChunk(0x100c, 4, fourBytes);
byte[] dest = new byte[9];
int numBytes = uniqueBank.getChunk(0x1007, 9, dest, true);
assertEquals(4, numBytes);
assertEquals(0x11, dest[0]);
assertEquals(0x22, dest[1]);
assertEquals(0x33, dest[2]);
assertEquals(0x44, dest[3]);
}
@Test
public void testNonAlignedReadWrite() {
byte[] fourBytes = new byte[] { 0x11, 0x22, 0x33, 0x44 };
uniqueBank.setChunk(0x1004, 4, fourBytes);
byte[] dest = new byte[4];
int numBytes = uniqueBank.getChunk(0x1004, 4, dest, true);
assertEquals(4, numBytes);
assertTrue(Arrays.equals(fourBytes, dest));
}
@Test
public void testOverlappingReadWrite() {
uniqueBank.setChunk(0x1000, 16, sixteenTestBytes);
uniqueBank.setChunk(0x1004, 8, eightZeroBytes);
byte[] dest = new byte[16];
int numBytes = uniqueBank.getChunk(0x1000, 16, dest, true);
assertEquals(16, numBytes);
for (int i = 0; i < 16; ++i) {
if (i > 3 && i < 12) {
assertEquals(0, dest[i]);
}
else {
assertEquals(i, dest[i]);
}
}
}
@Test
public void testOneByteRead() {
byte[] one = new byte[] { (byte) 0x7f };
uniqueBank.setChunk(0x1000, 1, one);
byte[] dest = new byte[16];
int numBytes = uniqueBank.getChunk(0x1000, 1, dest, false);
assertEquals(1, numBytes);
assertEquals(dest[0], (byte) 0x7f);
}
@Test
public void testClear() {
uniqueBank.setChunk(0x1000, 8, eightTestBytes);
byte[] dest = new byte[8];
uniqueBank.clear();
int numBytes = uniqueBank.getChunk(0x1000, 8, dest, true);
assertEquals(0, numBytes);
numBytes = uniqueBank.getChunk(0x1000, 7, dest, true);
assertEquals(0, numBytes);
numBytes = uniqueBank.getChunk(0x1000, 6, dest, true);
assertEquals(0, numBytes);
numBytes = uniqueBank.getChunk(0x1000, 5, dest, true);
assertEquals(0, numBytes);
numBytes = uniqueBank.getChunk(0x1000, 4, dest, true);
assertEquals(0, numBytes);
numBytes = uniqueBank.getChunk(0x1000, 3, dest, true);
assertEquals(0, numBytes);
numBytes = uniqueBank.getChunk(0x1000, 2, dest, true);
assertEquals(0, numBytes);
numBytes = uniqueBank.getChunk(0x1000, 1, dest, true);
assertEquals(0, numBytes);
numBytes = uniqueBank.getChunk(0x1000, 0, dest, true);
assertEquals(0, numBytes);
}
@Test
public void testSimpleOverwrite() {
uniqueBank.setChunk(0x1000, 8, eightTestBytes);
byte[] dest = new byte[8];
int numBytes = uniqueBank.getChunk(0x1000, 8, dest, true);
assertEquals(8, numBytes);
assertTrue(Arrays.equals(dest, eightTestBytes));
uniqueBank.setChunk(0x1000, 8, eightZeroBytes);
numBytes = uniqueBank.getChunk(0x1000, 8, dest, true);
assertEquals(8, numBytes);
assertTrue(Arrays.equals(dest, eightZeroBytes));
}
@Test(expected = LowlevelError.class)
public void testUninitializedReadStop() {
byte[] dest = new byte[16];
uniqueBank.getChunk(0x1000, 0x10, dest, false);
}
@Test
public void testUninitializedReadContinue() {
byte[] dest = new byte[16];
int bytesRead = uniqueBank.getChunk(0x1000, 0x10, dest, true);
assertEquals(0, bytesRead);
}
@SuppressWarnings("unused")
@Test(expected = UnsupportedOperationException.class)
public void testGetPageException() {
MemoryPage page = uniqueBank.getPage(0);
}
@Test(expected = UnsupportedOperationException.class)
public void testSetPageException() {
uniqueBank.setPage(0, new byte[0], 0, 4096, 0);
}
@Test(expected = UnsupportedOperationException.class)
public void testSetPageInitializedException() {
uniqueBank.setPageInitialized(0, true, 0, 4096, 0);
}
//possibly add:
//zero-byte read/write
//try to write more bytes than the array has
//try to read more bytes into the array than it has
}

View file

@ -1,66 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import generic.test.AbstractGenericTest;
import ghidra.pcode.utils.Utils;
import ghidra.util.StringUtilities;
public abstract class AbstractOpBehaviorTest extends AbstractGenericTest {
public AbstractOpBehaviorTest() {
super();
}
protected void assertEquals(BigInteger expected, BigInteger result, int byteSize) {
// discards irrelevant bytes before comparing - ignores overflow bytes
byte[] resultBytes = Utils.bigIntegerToBytes(result, byteSize, true);
byte[] expectedBytes = Utils.bigIntegerToBytes(expected, byteSize, true);
org.junit.Assert.assertEquals(toHexString(expectedBytes), toHexString(resultBytes));
}
protected void assertEquals(long expected, long result, int byteSize) {
// discards irrelevant bytes before comparing - ignores overflow bytes
byte[] resultBytes = Utils.longToBytes(result, byteSize, true);
byte[] expectedBytes = Utils.longToBytes(expected, byteSize, true);
org.junit.Assert.assertEquals(toHexString(expectedBytes), toHexString(resultBytes));
}
private String toHexString(byte[] bytes) {
StringBuilder buf = new StringBuilder("0x");
for (byte b : bytes) {
String valStr = StringUtilities.pad(Integer.toHexString(b & 0xff), '0', 2);
buf.append(valStr);
}
return buf.toString();
}
protected BigInteger getUnsignedBigInt(long val) {
if (val > 0) {
return BigInteger.valueOf(val);
}
return new BigInteger(1, Utils.longToBytes(val, 8, true));
}
protected BigInteger getUnsignedBigInt(long val, int size) {
if (val > 0) {
return BigInteger.valueOf(val);
}
return new BigInteger(1, Utils.longToBytes(val, size, true));
}
}

View file

@ -1,54 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
public class OpBehaviorBoolAndTest extends AbstractOpBehaviorTest {
public OpBehaviorBoolAndTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorBoolOr op = new OpBehaviorBoolOr();
Assert.assertEquals(0, op.evaluateBinary(1, 1, 0, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 1, 0, 1));
Assert.assertEquals(1, op.evaluateBinary(1, 1, 1, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 1, 1, 1));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorBoolOr op = new OpBehaviorBoolOr();
Assert.assertEquals(BigInteger.ZERO,
op.evaluateBinary(1, 1, BigInteger.ZERO, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(1, 1, BigInteger.ZERO, BigInteger.ONE));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(1, 1, BigInteger.ONE, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(1, 1, BigInteger.ONE, BigInteger.ONE));
}
}

View file

@ -1,46 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
public class OpBehaviorBoolNegateTest extends AbstractOpBehaviorTest {
public OpBehaviorBoolNegateTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorBoolNegate op = new OpBehaviorBoolNegate();
Assert.assertEquals(1, op.evaluateUnary(1, 1, 0));
Assert.assertEquals(0, op.evaluateUnary(1, 1, 1));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorBoolNegate op = new OpBehaviorBoolNegate();
Assert.assertEquals(BigInteger.ONE, op.evaluateUnary(1, 1, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ZERO, op.evaluateUnary(1, 1, BigInteger.ONE));
}
}

View file

@ -1,50 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
public class OpBehaviorBoolOrTest extends AbstractOpBehaviorTest {
public OpBehaviorBoolOrTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorBoolOr op = new OpBehaviorBoolOr();
Assert.assertEquals(0, op.evaluateBinary(1, 1, 0, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 1, 0, 1));
Assert.assertEquals(1, op.evaluateBinary(1, 1, 1, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 1, 1, 1));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorBoolOr op = new OpBehaviorBoolOr();
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 1, BigInteger.ZERO, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 1, BigInteger.ZERO, BigInteger.ONE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 1, BigInteger.ONE, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 1, BigInteger.ONE, BigInteger.ONE));
}
}

View file

@ -1,50 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
public class OpBehaviorBoolXorTest extends AbstractOpBehaviorTest {
public OpBehaviorBoolXorTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorBoolXor op = new OpBehaviorBoolXor();
Assert.assertEquals(0, op.evaluateBinary(1, 1, 0, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 1, 0, 1));
Assert.assertEquals(1, op.evaluateBinary(1, 1, 1, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 1, 1, 1));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorBoolXor op = new OpBehaviorBoolXor();
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 1, BigInteger.ZERO, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 1, BigInteger.ZERO, BigInteger.ONE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 1, BigInteger.ONE, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 1, BigInteger.ONE, BigInteger.ONE));
}
}

View file

@ -1,88 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.FloatFormat;
import ghidra.pcode.floatformat.FloatFormatFactory;
public class OpBehaviorFloatAbsTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatAbsTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatAbs op = new OpBehaviorFloatAbs();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
long a = ff.getEncoding(2.5);
long result = op.evaluateUnary(8, 8, ff.opAbs(a));
Assert.assertEquals(2.5, ff.getHostFloat(result), 0);
a = ff.getEncoding(-2.5);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(2.5, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.POSITIVE_INFINITY);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Double.POSITIVE_INFINITY, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.NEGATIVE_INFINITY);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Double.POSITIVE_INFINITY, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.NaN);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Double.NaN, ff.getHostFloat(result), 0);
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatAbs op = new OpBehaviorFloatAbs();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
BigInteger a = ff.getEncoding(ff.getBigFloat(2.5d));
BigInteger result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigFloat(2.5d), ff.getHostFloat(result));
a = ff.getEncoding(ff.getBigFloat(-2.5d));
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigFloat(2.5d), ff.getHostFloat(result));
a = ff.getBigInfinityEncoding(false);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigInfinity(false), ff.getHostFloat(result));
a = ff.getBigInfinityEncoding(true);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigInfinity(false), ff.getHostFloat(result));
a = ff.getBigNaNEncoding(false);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigNaN(false), ff.getHostFloat(result));
}
}

View file

@ -1,108 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.FloatFormat;
import ghidra.pcode.floatformat.FloatFormatFactory;
public class OpBehaviorFloatAddTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatAddTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatAdd op = new OpBehaviorFloatAdd();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
long a = ff.getEncoding(1.234);
long b = ff.getEncoding(1.123);
long result = op.evaluateBinary(8, 8, a, b);// 1.234 + 1.123
Assert.assertEquals(2.357, ff.getHostFloat(result), 0);
a = ff.getEncoding(-1.123);
result = op.evaluateBinary(8, 8, a, b);// -1.123 + 1.123
Assert.assertEquals(0d, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.POSITIVE_INFINITY);
result = op.evaluateBinary(8, 8, a, b);// +INFINITY + 1.123
Assert.assertEquals(Double.POSITIVE_INFINITY, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.NEGATIVE_INFINITY);
result = op.evaluateBinary(8, 8, a, b);// -INFINITY + 1.123
Assert.assertEquals(Double.NEGATIVE_INFINITY, ff.getHostFloat(result), 0);
b = ff.getEncoding(Double.NEGATIVE_INFINITY);
result = op.evaluateBinary(8, 8, a, b);// -INFINITY + -INFINITY
Assert.assertEquals(Double.NEGATIVE_INFINITY, ff.getHostFloat(result), 0);
b = ff.getEncoding(Double.POSITIVE_INFINITY);
result = op.evaluateBinary(8, 8, a, b);// -INFINITY + +INFINITY
Assert.assertEquals(Double.NaN, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.NaN);
b = ff.getEncoding(1.123);
result = op.evaluateBinary(8, 8, a, b);// NaN + 1.123
Assert.assertEquals(Double.NaN, ff.getHostFloat(result), 0);
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatAdd op = new OpBehaviorFloatAdd();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
BigInteger a = ff.getEncoding(ff.getBigFloat(1.234d));
BigInteger b = ff.getEncoding(ff.getBigFloat(1.123d));
BigInteger result = op.evaluateBinary(8, 8, a, b);// 1.234 + 1.123
Assert.assertEquals(ff.getBigFloat(2.357), ff.getHostFloat(result));
a = ff.getEncoding(ff.getBigFloat(-1.123d));
result = op.evaluateBinary(8, 8, a, b);// -1.123 + 1.123
Assert.assertEquals(ff.getBigZero(false), ff.getHostFloat(result));
a = ff.getEncoding(ff.getBigInfinity(false));
result = op.evaluateBinary(8, 8, a, b);// +INFINITY + 1.123
Assert.assertEquals(ff.getBigInfinity(false), ff.getHostFloat(result));
a = ff.getBigInfinityEncoding(true);
result = op.evaluateBinary(8, 8, a, b);// -INFINITY + 1.123
Assert.assertEquals(ff.getBigInfinity(true), ff.getHostFloat(result));
b = ff.getBigInfinityEncoding(true);
result = op.evaluateBinary(8, 8, a, b);// -INFINITY + -INFINITY
Assert.assertEquals(ff.getBigInfinity(true), ff.getHostFloat(result));
b = ff.getEncoding(ff.getBigInfinity(false));
result = op.evaluateBinary(8, 8, a, b);// -INFINITY + +INFINITY
Assert.assertEquals(ff.getBigNaN(false), ff.getHostFloat(result));
a = ff.getBigNaNEncoding(false);
b = ff.getEncoding(ff.getBigFloat(1.123d));
result = op.evaluateBinary(8, 8, a, b);// NaN + 1.123
Assert.assertEquals(ff.getBigNaN(false), ff.getHostFloat(result));
}
}

View file

@ -1,88 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.FloatFormat;
import ghidra.pcode.floatformat.FloatFormatFactory;
public class OpBehaviorFloatCeilTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatCeilTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatCeil op = new OpBehaviorFloatCeil();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
long a = ff.getEncoding(2.5);
long result = ff.opCeil(a);
Assert.assertEquals(3.0, ff.getHostFloat(result), 0);
a = ff.getEncoding(-2.5);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(-2.0, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.POSITIVE_INFINITY);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Double.POSITIVE_INFINITY, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.NEGATIVE_INFINITY);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Double.NEGATIVE_INFINITY, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.NaN);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Double.NaN, ff.getHostFloat(result), 0);
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatCeil op = new OpBehaviorFloatCeil();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
BigInteger a = ff.getEncoding(ff.getBigFloat(2.5d));
BigInteger result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigFloat(3.0d), ff.getHostFloat(result));
a = ff.getEncoding(ff.getBigFloat(-2.5d));
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigFloat(-2.0d), ff.getHostFloat(result));
a = ff.getBigInfinityEncoding(false);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigInfinity(false), ff.getHostFloat(result));
a = ff.getBigInfinityEncoding(true);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigInfinity(true), ff.getHostFloat(result));
a = ff.getBigNaNEncoding(false);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigNaN(false), ff.getHostFloat(result));
}
}

View file

@ -1,82 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.FloatFormat;
import ghidra.pcode.floatformat.FloatFormatFactory;
public class OpBehaviorFloatDivTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatDivTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatDiv op = new OpBehaviorFloatDiv();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
long a = ff.getEncoding(3.75);
long b = ff.getEncoding(1.5);
long result = ff.opDiv(a, b);
Assert.assertEquals(2.5, ff.getHostFloat(result), 0);
b = ff.getEncoding(0);
result = op.evaluateBinary(8, 8, a, b);
Assert.assertEquals(Double.POSITIVE_INFINITY, ff.getHostFloat(result), 0);
a = ff.getEncoding(-3.75);
result = op.evaluateBinary(8, 8, a, b);
Assert.assertEquals(Double.NEGATIVE_INFINITY, ff.getHostFloat(result), 0);
b = ff.getEncoding(Double.NaN);
result = op.evaluateBinary(8, 8, a, b);
Assert.assertEquals(Double.NaN, ff.getHostFloat(result), 0);
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatDiv op = new OpBehaviorFloatDiv();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
BigInteger a = ff.getEncoding(ff.getBigFloat(3.75d));
BigInteger b = ff.getEncoding(ff.getBigFloat(1.5d));
BigInteger result = op.evaluateBinary(8, 8, a, b);
Assert.assertEquals(ff.getBigFloat(2.5d), ff.getHostFloat(result));
b = ff.getBigZeroEncoding(false);
result = op.evaluateBinary(8, 8, a, b);
Assert.assertEquals(ff.getBigInfinity(false), ff.getHostFloat(result));
a = ff.getEncoding(ff.getBigFloat(-3.75d));
result = op.evaluateBinary(8, 8, a, b);
Assert.assertEquals(ff.getBigInfinity(true), ff.getHostFloat(result));
b = ff.getBigNaNEncoding(false);
result = op.evaluateBinary(8, 8, a, b);
Assert.assertEquals(ff.getBigNaN(false), ff.getHostFloat(result));
}
}

View file

@ -1,81 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.*;
public class OpBehaviorFloatEqualTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatEqualTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatEqual op = new OpBehaviorFloatEqual();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
Assert.assertEquals(1,
op.evaluateBinary(8, 8, ff.getEncoding(1.234), ff.getEncoding(1.234)));
Assert.assertEquals(1,
op.evaluateBinary(8, 8, ff.getEncoding(-1.234), ff.getEncoding(-1.234)));
Assert.assertEquals(0,
op.evaluateBinary(8, 8, ff.getEncoding(-1.234), ff.getEncoding(1.234)));
Assert.assertEquals(1, op.evaluateBinary(8, 8, ff.getEncoding(Double.POSITIVE_INFINITY),
ff.getEncoding(Double.POSITIVE_INFINITY)));
Assert.assertEquals(0, op.evaluateBinary(8, 8, ff.getEncoding(Double.POSITIVE_INFINITY),
ff.getEncoding(Double.NEGATIVE_INFINITY)));
Assert.assertEquals(1, op.evaluateBinary(8, 8, ff.getEncoding(Double.NEGATIVE_INFINITY),
ff.getEncoding(Double.NEGATIVE_INFINITY)));
Assert.assertEquals(0, op.evaluateBinary(8, 8, ff.getEncoding(Double.POSITIVE_INFINITY),
ff.getEncoding(Double.NaN)));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatEqual op = new OpBehaviorFloatEqual();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
BigFloat a = ff.getBigFloat(1.234d);
BigFloat b = ff.getBigFloat(-1.234d);
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(8, 8, ff.getEncoding(a), ff.getEncoding(a)));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(8, 8, ff.getEncoding(b), ff.getEncoding(b)));
Assert.assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, ff.getEncoding(b), ff.getEncoding(a)));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(8, 8,
ff.getBigInfinityEncoding(false), ff.getBigInfinityEncoding(false)));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(8, 8,
ff.getBigInfinityEncoding(false), ff.getBigInfinityEncoding(true)));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(8, 8, ff.getBigInfinityEncoding(true),
ff.getBigInfinityEncoding(true)));
Assert.assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, ff.getBigInfinityEncoding(false), ff.getBigNaNEncoding(false)));
}
}

View file

@ -1,90 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.FloatFormat;
import ghidra.pcode.floatformat.FloatFormatFactory;
public class OpBehaviorFloatFloat2FloatTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatFloat2FloatTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatFloat2Float op = new OpBehaviorFloatFloat2Float();
FloatFormat ff8 = FloatFormatFactory.getFloatFormat(8);
FloatFormat ff4 = FloatFormatFactory.getFloatFormat(4);
long a = ff4.getEncoding(1.75);
long result = op.evaluateUnary(8, 4, a);
Assert.assertEquals(1.75, ff8.getHostFloat(result), 0);
a = ff4.getEncoding(-1.75);
result = op.evaluateUnary(8, 4, a);
Assert.assertEquals(-1.75, ff8.getHostFloat(result), 0);
a = ff4.getEncoding(Float.POSITIVE_INFINITY);
result = op.evaluateUnary(8, 4, a);
Assert.assertEquals(Double.POSITIVE_INFINITY, ff8.getHostFloat(result), 0);
a = ff4.getEncoding(Float.NEGATIVE_INFINITY);
result = op.evaluateUnary(8, 4, a);
Assert.assertEquals(Double.NEGATIVE_INFINITY, ff8.getHostFloat(result), 0);
a = ff4.getEncoding(Float.NaN);
result = op.evaluateUnary(8, 4, a);
Assert.assertEquals(Double.NaN, ff8.getHostFloat(result), 0);
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatFloat2Float op = new OpBehaviorFloatFloat2Float();
FloatFormat ff8 = FloatFormatFactory.getFloatFormat(8);
FloatFormat ff4 = FloatFormatFactory.getFloatFormat(4);
BigInteger a = ff4.getEncoding(ff4.getBigFloat(1.75d));
BigInteger result = op.evaluateUnary(8, 4, a);
Assert.assertEquals(ff8.getBigFloat(1.75d), ff8.getHostFloat(result));
a = ff4.getEncoding(ff4.getBigFloat(-1.75d));
result = op.evaluateUnary(8, 4, a);
Assert.assertEquals(ff8.getBigFloat(-1.75d), ff8.getHostFloat(result));
a = ff4.getEncoding(ff4.getBigInfinity(false));
result = op.evaluateUnary(8, 4, a);
Assert.assertEquals(ff8.getBigInfinity(false), ff8.getHostFloat(result));
a = ff4.getEncoding(ff4.getBigInfinity(true));
result = op.evaluateUnary(8, 4, a);
Assert.assertEquals(ff8.getBigInfinity(true), ff8.getHostFloat(result));
a = ff4.getEncoding(ff4.getBigNaN(false));
result = op.evaluateUnary(8, 4, a);
Assert.assertEquals(ff8.getBigNaN(false), ff8.getHostFloat(result));
}
}

View file

@ -1,96 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.FloatFormat;
import ghidra.pcode.floatformat.FloatFormatFactory;
public class OpBehaviorFloatFloorTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatFloorTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatFloor op = new OpBehaviorFloatFloor();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
long a = ff.getEncoding(2.5);
long result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(2.0, ff.getHostFloat(result), 0);
a = ff.getEncoding(-2.0);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(-2.0, ff.getHostFloat(result), 0);
a = ff.getEncoding(-2.5);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(-3.0, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.POSITIVE_INFINITY);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Double.POSITIVE_INFINITY, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.NEGATIVE_INFINITY);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Double.NEGATIVE_INFINITY, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.NaN);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Double.NaN, ff.getHostFloat(result), 0);
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatFloor op = new OpBehaviorFloatFloor();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
BigInteger a = ff.getEncoding(ff.getBigFloat(2.5d));
BigInteger result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigFloat(2.0d), ff.getHostFloat(result));
a = ff.getEncoding(ff.getBigFloat(-2.0d));
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigFloat(-2.0d), ff.getHostFloat(result));
a = ff.getEncoding(ff.getBigFloat(-2.5d));
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigFloat(-3.0d), ff.getHostFloat(result));
a = ff.getBigInfinityEncoding(false);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigInfinity(false), ff.getHostFloat(result));
a = ff.getBigInfinityEncoding(true);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigInfinity(true), ff.getHostFloat(result));
a = ff.getBigNaNEncoding(false);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigNaN(false), ff.getHostFloat(result));
}
}

View file

@ -1,87 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import static org.junit.Assert.*;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.FloatFormat;
import ghidra.pcode.floatformat.FloatFormatFactory;
import ghidra.pcode.utils.Utils;
public class OpBehaviorFloatInt2FloatTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatInt2FloatTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatInt2Float op = new OpBehaviorFloatInt2Float();
FloatFormat ff = FloatFormatFactory.getFloatFormat(4);
long result = op.evaluateUnary(4, 4, 2);
Assert.assertEquals(0, result & 0xffffffff00000000L);// verify that only 4-bytes are used
Assert.assertEquals(2.0d, ff.getHostFloat(result), 0);
result = op.evaluateUnary(4, 4, -2);
Assert.assertEquals(0, result & 0xffffffff00000000L);// verify that only 4-bytes are used
Assert.assertEquals(-2.0d, ff.getHostFloat(result), 0);
result = op.evaluateUnary(4, 4, 0);
Assert.assertEquals(0, result & 0xffffffff00000000L);// verify that only 4-bytes are used
Assert.assertEquals(0d, ff.getHostFloat(result), 0);
result = op.evaluateUnary(4, 4, 0x0ffffffffL);
Assert.assertEquals(0, result & 0xffffffff00000000L);// verify that only 4-bytes are used
Assert.assertEquals(-1.0d, ff.getHostFloat(result), 0);
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatInt2Float op = new OpBehaviorFloatInt2Float();
FloatFormat ff = FloatFormatFactory.getFloatFormat(4);
BigInteger limit = BigInteger.ONE.shiftLeft(32);
BigInteger result = op.evaluateUnary(4, 4, BigInteger.valueOf(2));
assertTrue(result.compareTo(limit) < 0);// verify that only 4-bytes are used
Assert.assertEquals(ff.getBigFloat(2.0d), ff.getHostFloat(result));
result = op.evaluateUnary(4, 4, BigInteger.valueOf(-2));
assertTrue(result.compareTo(limit) < 0);// verify that only 4-bytes are used
Assert.assertEquals(ff.getBigFloat(-2.0d), ff.getHostFloat(result));
result = op.evaluateUnary(4, 4, BigInteger.ZERO);
assertTrue(result.compareTo(limit) < 0);// verify that only 4-bytes are used
Assert.assertEquals(ff.getBigZero(false), ff.getHostFloat(result));
BigInteger NEG_ONE = Utils.bytesToBigInteger(
new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff }, 4, false, false);
result = op.evaluateUnary(4, 4, NEG_ONE);
Assert.assertEquals(ff.getBigFloat(-1.0d), ff.getHostFloat(result));
}
}

View file

@ -1,108 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.*;
public class OpBehaviorFloatLessEqualTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatLessEqualTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatLessEqual op = new OpBehaviorFloatLessEqual();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
Assert.assertEquals(1,
op.evaluateBinary(8, 8, ff.getEncoding(1.234), ff.getEncoding(1.234)));
Assert.assertEquals(1,
op.evaluateBinary(8, 8, ff.getEncoding(-1.234), ff.getEncoding(-1.234)));
Assert.assertEquals(0,
op.evaluateBinary(8, 8, ff.getEncoding(1.234), ff.getEncoding(-1.234)));
Assert.assertEquals(0, op.evaluateBinary(8, 8, ff.getEncoding(0), ff.getEncoding(-1.234)));
Assert.assertEquals(1, op.evaluateBinary(8, 8, ff.getEncoding(0), ff.getEncoding(1.234)));
Assert.assertEquals(1,
op.evaluateBinary(8, 8, ff.getEncoding(-1.234), ff.getEncoding(1.234)));
Assert.assertEquals(0, op.evaluateBinary(8, 8, ff.getEncoding(Double.POSITIVE_INFINITY),
ff.getEncoding(1.234)));
Assert.assertEquals(1, op.evaluateBinary(8, 8, ff.getEncoding(Double.NEGATIVE_INFINITY),
ff.getEncoding(1.234)));
Assert.assertEquals(1, op.evaluateBinary(8, 8, ff.getEncoding(1.234),
ff.getEncoding(Double.POSITIVE_INFINITY)));
Assert.assertEquals(0, op.evaluateBinary(8, 8, ff.getEncoding(1.234),
ff.getEncoding(Double.NEGATIVE_INFINITY)));
Assert.assertEquals(1, op.evaluateBinary(8, 8, ff.getEncoding(Double.POSITIVE_INFINITY),
ff.getEncoding(Double.POSITIVE_INFINITY)));
Assert.assertEquals(1, op.evaluateBinary(8, 8, ff.getEncoding(Double.NEGATIVE_INFINITY),
ff.getEncoding(Double.POSITIVE_INFINITY)));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatLessEqual op = new OpBehaviorFloatLessEqual();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
BigFloat a = ff.getBigFloat(1.234d);
BigFloat b = ff.getBigFloat(-1.234d);
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(8, 8, ff.getEncoding(a), ff.getEncoding(a)));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(8, 8, ff.getEncoding(b), ff.getEncoding(b)));
Assert.assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, ff.getEncoding(a), ff.getEncoding(b)));
Assert.assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, ff.getBigZeroEncoding(false), ff.getEncoding(b)));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(8, 8, ff.getBigZeroEncoding(false), ff.getEncoding(a)));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(8, 8, ff.getEncoding(b), ff.getEncoding(a)));
Assert.assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, ff.getBigInfinityEncoding(false), ff.getEncoding(a)));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(8, 8, ff.getBigInfinityEncoding(true), ff.getEncoding(a)));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(8, 8, ff.getEncoding(a), ff.getBigInfinityEncoding(false)));
Assert.assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, ff.getEncoding(a), ff.getBigInfinityEncoding(true)));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(8, 8,
ff.getBigInfinityEncoding(false), ff.getBigInfinityEncoding(false)));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(8, 8, ff.getBigInfinityEncoding(true),
ff.getBigInfinityEncoding(false)));
}
}

View file

@ -1,105 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.*;
public class OpBehaviorFloatLessTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatLessTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatLess op = new OpBehaviorFloatLess();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
Assert.assertEquals(0,
op.evaluateBinary(8, 8, ff.getEncoding(1.234), ff.getEncoding(1.234)));
Assert.assertEquals(0,
op.evaluateBinary(8, 8, ff.getEncoding(-1.234), ff.getEncoding(-1.234)));
Assert.assertEquals(0,
op.evaluateBinary(8, 8, ff.getEncoding(1.234), ff.getEncoding(-1.234)));
Assert.assertEquals(0, op.evaluateBinary(8, 8, ff.getEncoding(0), ff.getEncoding(-1.234)));
Assert.assertEquals(1, op.evaluateBinary(8, 8, ff.getEncoding(0), ff.getEncoding(1.234)));
Assert.assertEquals(1,
op.evaluateBinary(8, 8, ff.getEncoding(-1.234), ff.getEncoding(1.234)));
Assert.assertEquals(0, op.evaluateBinary(8, 8, ff.getEncoding(Double.POSITIVE_INFINITY),
ff.getEncoding(1.234)));
Assert.assertEquals(1, op.evaluateBinary(8, 8, ff.getEncoding(Double.NEGATIVE_INFINITY),
ff.getEncoding(1.234)));
Assert.assertEquals(1, op.evaluateBinary(8, 8, ff.getEncoding(1.234),
ff.getEncoding(Double.POSITIVE_INFINITY)));
Assert.assertEquals(0, op.evaluateBinary(8, 8, ff.getEncoding(1.234),
ff.getEncoding(Double.NEGATIVE_INFINITY)));
Assert.assertEquals(0, op.evaluateBinary(8, 8, ff.getEncoding(Double.POSITIVE_INFINITY),
ff.getEncoding(Double.POSITIVE_INFINITY)));
Assert.assertEquals(1, op.evaluateBinary(8, 8, ff.getEncoding(Double.NEGATIVE_INFINITY),
ff.getEncoding(Double.POSITIVE_INFINITY)));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatLess op = new OpBehaviorFloatLess();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
BigFloat a = ff.getBigFloat(1.234d);
BigFloat b = ff.getBigFloat(-1.234d);
Assert.assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, ff.getEncoding(a), ff.getEncoding(a)));
Assert.assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, ff.getEncoding(b), ff.getEncoding(b)));
Assert.assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, ff.getEncoding(a), ff.getEncoding(b)));
Assert.assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, ff.getBigZeroEncoding(false), ff.getEncoding(b)));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(8, 8, ff.getBigZeroEncoding(false), ff.getEncoding(a)));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(8, 8, ff.getEncoding(b), ff.getEncoding(a)));
Assert.assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, ff.getBigInfinityEncoding(false), ff.getEncoding(a)));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(8, 8, ff.getBigInfinityEncoding(true), ff.getEncoding(a)));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(8, 8, ff.getEncoding(a), ff.getBigInfinityEncoding(false)));
Assert.assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, ff.getEncoding(a), ff.getBigInfinityEncoding(true)));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(8, 8,
ff.getBigInfinityEncoding(false), ff.getBigInfinityEncoding(false)));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(8, 8, ff.getBigInfinityEncoding(true),
ff.getBigInfinityEncoding(false)));
}
}

View file

@ -1,82 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.FloatFormat;
import ghidra.pcode.floatformat.FloatFormatFactory;
public class OpBehaviorFloatMultTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatMultTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatMult op = new OpBehaviorFloatMult();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
long a = ff.getEncoding(2.5);
long b = ff.getEncoding(1.5);
long result = op.evaluateBinary(8, 8, a, b);
Assert.assertEquals(3.75, ff.getHostFloat(result), 0);
b = ff.getEncoding(Double.POSITIVE_INFINITY);
result = op.evaluateBinary(8, 8, a, b);
Assert.assertEquals(Double.POSITIVE_INFINITY, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.NEGATIVE_INFINITY);
result = op.evaluateBinary(8, 8, a, b);
Assert.assertEquals(Double.NEGATIVE_INFINITY, ff.getHostFloat(result), 0);
b = ff.getEncoding(Double.NaN);
result = op.evaluateBinary(8, 8, a, b);
Assert.assertEquals(Double.NaN, ff.getHostFloat(result), 0);
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatMult op = new OpBehaviorFloatMult();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
BigInteger a = ff.getEncoding(ff.getBigFloat(2.5d));
BigInteger b = ff.getEncoding(ff.getBigFloat(1.5d));
BigInteger result = op.evaluateBinary(8, 8, a, b);
Assert.assertEquals(ff.getBigFloat(3.75d), ff.getHostFloat(result));
b = ff.getBigInfinityEncoding(false);
result = op.evaluateBinary(8, 8, a, b);
Assert.assertEquals(ff.getBigInfinity(false), ff.getHostFloat(result));
a = ff.getBigInfinityEncoding(true);
result = op.evaluateBinary(8, 8, a, b);
Assert.assertEquals(ff.getBigInfinity(true), ff.getHostFloat(result));
b = ff.getBigNaNEncoding(false);
result = op.evaluateBinary(8, 8, a, b);
Assert.assertEquals(ff.getBigNaN(false), ff.getHostFloat(result));
}
}

View file

@ -1,58 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.FloatFormat;
import ghidra.pcode.floatformat.FloatFormatFactory;
public class OpBehaviorFloatNanTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatNanTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatNan op = new OpBehaviorFloatNan();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
Assert.assertEquals(1, op.evaluateUnary(1, 8, ff.getEncoding(Double.NaN)));
Assert.assertEquals(0, op.evaluateUnary(1, 8, ff.getEncoding(0)));
Assert.assertEquals(0, op.evaluateUnary(1, 8, ff.getEncoding(1.234)));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatNan op = new OpBehaviorFloatNan();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
Assert.assertEquals(BigInteger.ONE, op.evaluateUnary(1, 8, ff.getBigNaNEncoding(false)));
Assert.assertEquals(BigInteger.ZERO, op.evaluateUnary(1, 8, ff.getBigZeroEncoding(false)));
Assert.assertEquals(BigInteger.ZERO,
op.evaluateUnary(1, 8, ff.getEncoding(ff.getBigFloat(1.234d))));
}
}

View file

@ -1,88 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.FloatFormat;
import ghidra.pcode.floatformat.FloatFormatFactory;
public class OpBehaviorFloatNegTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatNegTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatNeg op = new OpBehaviorFloatNeg();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
long a = ff.getEncoding(2.5);
long result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(-2.5, ff.getHostFloat(result), 0);
a = ff.getEncoding(-2.5);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(2.5, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.POSITIVE_INFINITY);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Double.NEGATIVE_INFINITY, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.NEGATIVE_INFINITY);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Double.POSITIVE_INFINITY, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.NaN);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Double.NaN, ff.getHostFloat(result), 0);
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatNeg op = new OpBehaviorFloatNeg();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
BigInteger a = ff.getEncoding(ff.getBigFloat(2.5d));
BigInteger result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigFloat(-2.5d), ff.getHostFloat(result));
a = ff.getEncoding(ff.getBigFloat(-2.5d));
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigFloat(2.5d), ff.getHostFloat(result));
a = ff.getBigInfinityEncoding(false);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigInfinity(true), ff.getHostFloat(result));
a = ff.getBigInfinityEncoding(true);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigInfinity(false), ff.getHostFloat(result));
a = ff.getBigNaNEncoding(false);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigNaN(false), ff.getHostFloat(result));
}
}

View file

@ -1,81 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.*;
public class OpBehaviorFloatNotEqualTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatNotEqualTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatNotEqual op = new OpBehaviorFloatNotEqual();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
Assert.assertEquals(0,
op.evaluateBinary(1, 8, ff.getEncoding(1.234), ff.getEncoding(1.234)));
Assert.assertEquals(0,
op.evaluateBinary(1, 8, ff.getEncoding(-1.234), ff.getEncoding(-1.234)));
Assert.assertEquals(1,
op.evaluateBinary(1, 8, ff.getEncoding(-1.234), ff.getEncoding(1.234)));
Assert.assertEquals(0, op.evaluateBinary(1, 8, ff.getEncoding(Double.POSITIVE_INFINITY),
ff.getEncoding(Double.POSITIVE_INFINITY)));
Assert.assertEquals(1, op.evaluateBinary(1, 8, ff.getEncoding(Double.POSITIVE_INFINITY),
ff.getEncoding(Double.NEGATIVE_INFINITY)));
Assert.assertEquals(0, op.evaluateBinary(1, 8, ff.getEncoding(Double.NEGATIVE_INFINITY),
ff.getEncoding(Double.NEGATIVE_INFINITY)));
Assert.assertEquals(1, op.evaluateBinary(1, 8, ff.getEncoding(Double.POSITIVE_INFINITY),
ff.getEncoding(Double.NaN)));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatNotEqual op = new OpBehaviorFloatNotEqual();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
BigFloat a = ff.getBigFloat(1.234d);
BigFloat b = ff.getBigFloat(-1.234d);
Assert.assertEquals(BigInteger.ZERO,
op.evaluateBinary(1, 8, ff.getEncoding(a), ff.getEncoding(a)));
Assert.assertEquals(BigInteger.ZERO,
op.evaluateBinary(1, 8, ff.getEncoding(b), ff.getEncoding(b)));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(1, 8, ff.getEncoding(b), ff.getEncoding(a)));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 8,
ff.getBigInfinityEncoding(false), ff.getBigInfinityEncoding(false)));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 8,
ff.getBigInfinityEncoding(false), ff.getBigInfinityEncoding(true)));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 8,
ff.getBigInfinityEncoding(true), ff.getBigInfinityEncoding(true)));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(1, 8, ff.getBigInfinityEncoding(false), ff.getBigNaNEncoding(false)));
}
}

View file

@ -1,121 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.FloatFormat;
import ghidra.pcode.floatformat.FloatFormatFactory;
public class OpBehaviorFloatRoundTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatRoundTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatRound op = new OpBehaviorFloatRound();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
long a = ff.getEncoding(2.5);
long result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(3.0, ff.getHostFloat(result), 0);
a = ff.getEncoding(2.25);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(2.0, ff.getHostFloat(result), 0);
a = ff.getEncoding(2.75);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(3.0, ff.getHostFloat(result), 0);
a = ff.getEncoding(-2.5);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(-2.0, ff.getHostFloat(result), 0);
a = ff.getEncoding(-2.25);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(-2.0, ff.getHostFloat(result), 0);
a = ff.getEncoding(-2.75);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(-3.0, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.POSITIVE_INFINITY);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Double.POSITIVE_INFINITY, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.NEGATIVE_INFINITY);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Double.NEGATIVE_INFINITY, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.NaN);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Double.NaN, ff.getHostFloat(result), 0);
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatRound op = new OpBehaviorFloatRound();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
BigInteger a = ff.getEncoding(ff.getBigFloat(2.5d));
BigInteger result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigFloat(3.0d), ff.getHostFloat(result));
a = ff.getEncoding(ff.getBigFloat(2.25d));
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigFloat(2.0d), ff.getHostFloat(result));
a = ff.getEncoding(ff.getBigFloat(2.75d));
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigFloat(3.0d), ff.getHostFloat(result));
a = ff.getEncoding(ff.getBigFloat(-2.5d));
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigFloat(-2.0d), ff.getHostFloat(result));
a = ff.getEncoding(ff.getBigFloat(-2.25d));
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigFloat(-2.0d), ff.getHostFloat(result));
a = ff.getEncoding(ff.getBigFloat(-2.75d));
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigFloat(-3.0d), ff.getHostFloat(result));
a = ff.getBigInfinityEncoding(false);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigInfinity(false), ff.getHostFloat(result));
a = ff.getBigInfinityEncoding(true);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigInfinity(true), ff.getHostFloat(result));
a = ff.getBigNaNEncoding(false);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(ff.getBigNaN(false), ff.getHostFloat(result));
}
}

View file

@ -1,59 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.*;
public class OpBehaviorFloatSqrtTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatSqrtTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatSqrt op = new OpBehaviorFloatSqrt();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
long longbits = ff.getEncoding(2.0);
longbits = op.evaluateUnary(8, 8, longbits);
double d = ff.getHostFloat(longbits);
Assert.assertEquals("1.414213562373095", Double.toString(d).substring(0, 17));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatSqrt op = new OpBehaviorFloatSqrt();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
BigFloat big = ff.getBigFloat(2.0);
BigInteger encoding = ff.getEncoding(big);
encoding = op.evaluateUnary(8, 8, encoding);
BigFloat result = ff.getHostFloat(encoding);
Assert.assertEquals("1.414213562373095", ff.round(result).toString());
}
}

View file

@ -1,109 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.FloatFormat;
import ghidra.pcode.floatformat.FloatFormatFactory;
public class OpBehaviorFloatSubTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatSubTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatSub op = new OpBehaviorFloatSub();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
long a = ff.getEncoding(1.5);
long b = ff.getEncoding(1.25);
long result = op.evaluateBinary(8, 8, a, b);// 1.5 - 1.25
Assert.assertEquals(0.25, ff.getHostFloat(result), 0);
a = ff.getEncoding(-1.25);
result = op.evaluateBinary(8, 8, a, b);// -1.25 - 1.25
Assert.assertEquals(-2.5, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.POSITIVE_INFINITY);
result = op.evaluateBinary(8, 8, a, b);// +INFINITY - 1.25
Assert.assertEquals(Double.POSITIVE_INFINITY, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.NEGATIVE_INFINITY);
result = op.evaluateBinary(8, 8, a, b);// -INFINITY - 1.25
Assert.assertEquals(Double.NEGATIVE_INFINITY, ff.getHostFloat(result), 0);
b = ff.getEncoding(Double.NEGATIVE_INFINITY);
result = op.evaluateBinary(8, 8, a, b);// -INFINITY - -INFINITY
Assert.assertEquals(Double.NaN, ff.getHostFloat(result), 0);
b = ff.getEncoding(Double.POSITIVE_INFINITY);
result = op.evaluateBinary(8, 8, a, b);// -INFINITY - +INFINITY
Assert.assertEquals(Double.NEGATIVE_INFINITY, ff.getHostFloat(result), 0);
a = ff.getEncoding(Double.NaN);
b = ff.getEncoding(1.25);
result = op.evaluateBinary(8, 8, a, b);// NaN - 1.25
Assert.assertEquals(Double.NaN, ff.getHostFloat(result), 0);
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatSub op = new OpBehaviorFloatSub();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
BigInteger a = ff.getEncoding(ff.getBigFloat(1.5d));
BigInteger b = ff.getEncoding(ff.getBigFloat(1.25d));
BigInteger result = op.evaluateBinary(8, 8, a, b);// 1.5 - 1.25
Assert.assertEquals(ff.getBigFloat(0.25d), ff.getHostFloat(result));
a = ff.getEncoding(ff.getBigFloat(-1.25d));
result = op.evaluateBinary(8, 8, a, b);// -1.25 - 1.25
Assert.assertEquals(ff.getBigFloat(-2.5d), ff.getHostFloat(result));
a = ff.getBigInfinityEncoding(false);
result = op.evaluateBinary(8, 8, a, b);// +INFINITY - 1.25
Assert.assertEquals(ff.getBigInfinity(false), ff.getHostFloat(result));
a = ff.getBigInfinityEncoding(true);
result = op.evaluateBinary(8, 8, a, b);// -INFINITY - 1.25
Assert.assertEquals(ff.getBigInfinity(true), ff.getHostFloat(result));
b = ff.getBigInfinityEncoding(true);
result = op.evaluateBinary(8, 8, a, b);// -INFINITY - -INFINITY
Assert.assertEquals(ff.getBigNaN(false), ff.getHostFloat(result));
b = ff.getBigInfinityEncoding(false);
result = op.evaluateBinary(8, 8, a, b);// -INFINITY - +INFINITY
Assert.assertEquals(ff.getBigInfinity(true), ff.getHostFloat(result));
a = ff.getBigNaNEncoding(false);
b = ff.getEncoding(ff.getBigFloat(1.25d));
result = op.evaluateBinary(8, 8, a, b);// NaN - 1.25
Assert.assertEquals(ff.getBigNaN(false), ff.getHostFloat(result));
}
}

View file

@ -1,90 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.floatformat.FloatFormat;
import ghidra.pcode.floatformat.FloatFormatFactory;
public class OpBehaviorFloatTruncTest extends AbstractOpBehaviorTest {
public OpBehaviorFloatTruncTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorFloatTrunc op = new OpBehaviorFloatTrunc();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
long a = ff.getEncoding(2.5);
long result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(2, result);
a = ff.getEncoding(-2.5);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(-2, result);
a = ff.getEncoding(Double.POSITIVE_INFINITY);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Long.MAX_VALUE, result);
a = ff.getEncoding(Double.NEGATIVE_INFINITY);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(Long.MIN_VALUE, result);
// TODO: What should the correct result be?
a = ff.getEncoding(Double.NaN);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(0, result);
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorFloatTrunc op = new OpBehaviorFloatTrunc();
FloatFormat ff = FloatFormatFactory.getFloatFormat(8);
BigInteger a = ff.getEncoding(ff.getBigFloat(2.5d));
BigInteger result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(BigInteger.valueOf(2), result);
a = ff.getEncoding(ff.getBigFloat(-2.5d));
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(BigInteger.valueOf(-2), result);
a = ff.getBigInfinityEncoding(false);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(BigInteger.valueOf(Long.MAX_VALUE), result);
a = ff.getBigInfinityEncoding(true);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(BigInteger.valueOf(Long.MIN_VALUE), result);
// TODO: What should the correct result be?
a = ff.getBigNaNEncoding(false);
result = op.evaluateUnary(8, 8, a);
Assert.assertEquals(BigInteger.ZERO, result);
}
}

View file

@ -1,64 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
public class OpBehaviorInt2CompTest extends AbstractOpBehaviorTest {
public OpBehaviorInt2CompTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorInt2Comp op = new OpBehaviorInt2Comp();
Assert.assertEquals(0, op.evaluateUnary(4, 4, 0));
Assert.assertEquals(1, op.evaluateUnary(4, 4, 0xffffffffL));
Assert.assertEquals(0xffffffffL, op.evaluateUnary(4, 4, 1));
Assert.assertEquals(0x80000001L, op.evaluateUnary(4, 4, 0x7fffffffL));
Assert.assertEquals(0x80000000L, op.evaluateUnary(4, 4, 0x80000000L));// overflow
Assert.assertEquals(0, op.evaluateUnary(8, 8, 0));
Assert.assertEquals(1, op.evaluateUnary(8, 8, -1));
Assert.assertEquals(-1, op.evaluateUnary(8, 8, 1));
Assert.assertEquals(Long.MIN_VALUE + 1, op.evaluateUnary(8, 8, Long.MAX_VALUE));
Assert.assertEquals(Long.MIN_VALUE, op.evaluateUnary(8, 8, Long.MIN_VALUE));// overflow
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorInt2Comp op = new OpBehaviorInt2Comp();
BigInteger negOne = new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
BigInteger minNum = new BigInteger("80000000000000000000000000000000", 16);
BigInteger maxNum = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
assertEquals(BigInteger.ZERO, op.evaluateUnary(8, 8, BigInteger.ZERO), 16);
assertEquals(BigInteger.ONE, op.evaluateUnary(8, 8, negOne), 16);
assertEquals(negOne, op.evaluateUnary(8, 8, BigInteger.ONE), 16);
assertEquals(minNum.add(BigInteger.ONE), op.evaluateUnary(8, 8, maxNum), 16);
assertEquals(minNum, op.evaluateUnary(8, 8, minNum), 16);// overflow
}
}

View file

@ -1,107 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.utils.Utils;
public class OpBehaviorIntAddTest extends AbstractOpBehaviorTest {
public OpBehaviorIntAddTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorIntAdd op = new OpBehaviorIntAdd();
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 0));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 1, 0));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 0, 1));
Assert.assertEquals(0xffffffffL, op.evaluateBinary(4, 4, 0xffffffffL, 0));
Assert.assertEquals(0xffffffffL, op.evaluateBinary(4, 4, 0, 0xffffffffL));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0xffffffffL, 1));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 1, 0xffffffffL));
Assert.assertEquals(0xfffffffeL, op.evaluateBinary(4, 4, 0xffffffffL, 0xffffffffL));
Assert.assertEquals(0x80000000L, op.evaluateBinary(4, 4, 0x80000000L, 0));
Assert.assertEquals(0x80000000L, op.evaluateBinary(4, 4, 0, 0x80000000L));
Assert.assertEquals(0x80000001L, op.evaluateBinary(4, 4, 0x80000000L, 1));
Assert.assertEquals(0x80000001L, op.evaluateBinary(4, 4, 1, 0x80000000L));
Assert.assertEquals(0xffffffffL, op.evaluateBinary(4, 4, 0x80000000L, 0x7fffffffL));
Assert.assertEquals(0xffffffffL, op.evaluateBinary(4, 4, 0x7fffffffL, 0x80000000L));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0x80000000L, 0x80000000L));// overflow
Assert.assertEquals(0xfffffffeL, op.evaluateBinary(4, 4, 0x7fffffffL, 0x7fffffffL));// overflow
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, 0));
Assert.assertEquals(1, op.evaluateBinary(8, 8, 1, 0));
Assert.assertEquals(1, op.evaluateBinary(8, 8, 0, 1));
Assert.assertEquals(0xffffffffffffffffL, op.evaluateBinary(8, 8, 0xffffffffffffffffL, 0));
Assert.assertEquals(0xffffffffffffffffL, op.evaluateBinary(8, 8, 0, 0xffffffffffffffffL));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0xffffffffffffffffL, 1));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 1, 0xffffffffffffffffL));
Assert.assertEquals(0xfffffffffffffffeL,
op.evaluateBinary(8, 8, 0xffffffffffffffffL, 0xffffffffffffffffL));
Assert.assertEquals(Long.MIN_VALUE, op.evaluateBinary(8, 8, Long.MIN_VALUE, 0));
Assert.assertEquals(Long.MIN_VALUE, op.evaluateBinary(8, 8, 0, Long.MIN_VALUE));
Assert.assertEquals(Long.MIN_VALUE + 1, op.evaluateBinary(8, 8, Long.MIN_VALUE, 1));
Assert.assertEquals(Long.MIN_VALUE + 1, op.evaluateBinary(8, 8, 1, Long.MIN_VALUE));
Assert.assertEquals(0xffffffffffffffffL,
op.evaluateBinary(8, 8, Long.MIN_VALUE, Long.MAX_VALUE));
Assert.assertEquals(0xffffffffffffffffL,
op.evaluateBinary(8, 8, Long.MAX_VALUE, Long.MIN_VALUE));
Assert.assertEquals(0, op.evaluateBinary(8, 8, Long.MIN_VALUE, Long.MIN_VALUE));// overflow
Assert.assertEquals(0xfffffffffffffffeL,
op.evaluateBinary(8, 8, Long.MAX_VALUE, Long.MAX_VALUE));// overflow
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorIntAdd op = new OpBehaviorIntAdd();
BigInteger NEGATIVE_ONE = Utils.convertToUnsignedValue(BigInteger.valueOf(-1), 16);
BigInteger NEGATIVE_TWO = Utils.convertToUnsignedValue(BigInteger.valueOf(-2), 16);
BigInteger BIG_POSITIVE = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
BigInteger BIG_NEGATIVE = Utils.convertToUnsignedValue(
new BigInteger("80000000000000000000000000000000", 16), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ZERO),
16);
assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ONE, BigInteger.ZERO), 16);
assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ONE), 16);
assertEquals(NEGATIVE_ONE, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ZERO), 16);
assertEquals(NEGATIVE_ONE, op.evaluateBinary(1, 16, BigInteger.ZERO, NEGATIVE_ONE), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ONE), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ONE, NEGATIVE_ONE), 16);
assertEquals(NEGATIVE_TWO, op.evaluateBinary(1, 16, NEGATIVE_ONE, NEGATIVE_ONE), 16);
assertEquals(BIG_NEGATIVE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ZERO), 16);
assertEquals(BIG_NEGATIVE, op.evaluateBinary(1, 16, BigInteger.ZERO, BIG_NEGATIVE), 16);
assertEquals(BIG_NEGATIVE.add(BigInteger.ONE),
op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ONE), 16);
assertEquals(BIG_NEGATIVE.add(BigInteger.ONE),
op.evaluateBinary(1, 16, BigInteger.ONE, BIG_NEGATIVE), 16);
assertEquals(NEGATIVE_ONE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_POSITIVE), 16);
assertEquals(NEGATIVE_ONE, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_NEGATIVE), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_NEGATIVE), 16);// overflow
assertEquals(NEGATIVE_TWO, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_POSITIVE), 16);// overflow
}
}

View file

@ -1,105 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.utils.Utils;
public class OpBehaviorIntAndTest extends AbstractOpBehaviorTest {
public OpBehaviorIntAndTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorIntAnd op = new OpBehaviorIntAnd();
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 0));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 1, 0));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 1));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0xffffffffL, 0));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 0xffffffffL));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 0xffffffffL, 1));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 1, 0xffffffffL));
Assert.assertEquals(0xffffffffL, op.evaluateBinary(4, 4, 0xffffffffL, 0xffffffffL));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0x80000000L, 0));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 0x80000000L));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0x80000000L, 1));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 1, 0x80000000L));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0x80000000L, 0x7fffffffL));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0x7fffffffL, 0x80000000L));
Assert.assertEquals(0x80000000L, op.evaluateBinary(4, 4, 0x80000000L, 0x80000000L));// overflow
Assert.assertEquals(0x7fffffffL, op.evaluateBinary(4, 4, 0x7fffffffL, 0x7fffffffL));// overflow
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, 0));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 1, 0));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, 1));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0xffffffffffffffffL, 0));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, 0xffffffffffffffffL));
Assert.assertEquals(1, op.evaluateBinary(8, 8, 0xffffffffffffffffL, 1));
Assert.assertEquals(1, op.evaluateBinary(8, 8, 1, 0xffffffffffffffffL));
Assert.assertEquals(0xffffffffffffffffL,
op.evaluateBinary(8, 8, 0xffffffffffffffffL, 0xffffffffffffffffL));
Assert.assertEquals(0, op.evaluateBinary(8, 8, Long.MIN_VALUE, 0));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, Long.MIN_VALUE));
Assert.assertEquals(0, op.evaluateBinary(8, 8, Long.MIN_VALUE, 1));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 1, Long.MIN_VALUE));
Assert.assertEquals(0, op.evaluateBinary(8, 8, Long.MIN_VALUE, Long.MAX_VALUE));
Assert.assertEquals(0, op.evaluateBinary(8, 8, Long.MAX_VALUE, Long.MIN_VALUE));
Assert.assertEquals(Long.MIN_VALUE,
op.evaluateBinary(8, 8, Long.MIN_VALUE, Long.MIN_VALUE));// overflow
Assert.assertEquals(Long.MAX_VALUE,
op.evaluateBinary(8, 8, Long.MAX_VALUE, Long.MAX_VALUE));// overflow
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorIntAnd op = new OpBehaviorIntAnd();
BigInteger NEGATIVE_ONE = Utils.convertToUnsignedValue(BigInteger.valueOf(-1), 16);
BigInteger BIG_POSITIVE = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
BigInteger BIG_NEGATIVE = Utils.convertToUnsignedValue(
new BigInteger("80000000000000000000000000000000", 16), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ZERO),
16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ONE, BigInteger.ZERO),
16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ONE),
16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ZERO), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, NEGATIVE_ONE), 16);
assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ONE), 16);
assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ONE, NEGATIVE_ONE), 16);
assertEquals(NEGATIVE_ONE, op.evaluateBinary(1, 16, NEGATIVE_ONE, NEGATIVE_ONE), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ZERO), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, BIG_NEGATIVE), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ONE), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ONE, BIG_NEGATIVE), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_POSITIVE), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_NEGATIVE), 16);
assertEquals(BIG_NEGATIVE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_NEGATIVE), 16);// overflow
assertEquals(BIG_POSITIVE, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_POSITIVE), 16);// overflow
}
}

View file

@ -1,74 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
public class OpBehaviorIntCarryTest extends AbstractOpBehaviorTest {
public OpBehaviorIntCarryTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorIntCarry op = new OpBehaviorIntCarry();
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 0));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 1, 0xffffffffL));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 0xffffffffL, 1));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0x7fffffffL, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 0x7fffffffL, 0x80000001L));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0x80000000L, 0x7fffffffL));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 0x80000001L, 0x7fffffffL));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, 0));
Assert.assertEquals(0, op.evaluateBinary(8, 8, Long.MAX_VALUE, Long.MIN_VALUE));
Assert.assertEquals(1, op.evaluateBinary(8, 8, Long.MAX_VALUE, Long.MIN_VALUE + 1));
Assert.assertEquals(0, op.evaluateBinary(8, 8, Long.MIN_VALUE, Long.MAX_VALUE));
Assert.assertEquals(1, op.evaluateBinary(8, 8, Long.MIN_VALUE + 1, Long.MAX_VALUE));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0x7fffffffffffffffL, 1L));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 1L, 0x7fffffffffffffffL));
Assert.assertEquals(1, op.evaluateBinary(8, 8, 0xffffffffffffffffL, 1L));
Assert.assertEquals(1, op.evaluateBinary(8, 8, 1L, 0xffffffffffffffffL));
Assert.assertEquals(1, op.evaluateBinary(8, 8, 0xffffffffffffffffL, 0xffffffffffffffffL));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorIntCarry op = new OpBehaviorIntCarry();
BigInteger NEGATIVE_ONE = new BigInteger("FFFFFFFFFFFFFFFF", 16);
BigInteger BIG_POSITIVE = new BigInteger("7FFFFFFFFFFFFFFF", 16);
BigInteger BIG_NEGATIVE = new BigInteger("8000000000000000", 16);
Assert.assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, BigInteger.ZERO, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(8, 8, BigInteger.ONE, NEGATIVE_ONE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(8, 8, NEGATIVE_ONE, BigInteger.ONE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(8, 8, BIG_POSITIVE, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(8, 8, BIG_POSITIVE, BIG_NEGATIVE.add(BigInteger.ONE)));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(8, 8, BIG_NEGATIVE, BIG_POSITIVE));
Assert.assertEquals(BigInteger.ONE,
op.evaluateBinary(8, 8, BIG_NEGATIVE.add(BigInteger.ONE), BIG_POSITIVE));
}
}

View file

@ -1,102 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.utils.Utils;
public class OpBehaviorIntDivTest extends AbstractOpBehaviorTest {
public OpBehaviorIntDivTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorIntDiv op = new OpBehaviorIntDiv();
Assert.assertEquals(0, op.evaluateBinary(4, 4, 1, 0));// divide by zero
Assert.assertEquals(13, op.evaluateBinary(4, 4, 65, 5));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 1));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 0xffffffffL));
Assert.assertEquals(0xffffffffL, op.evaluateBinary(4, 4, 0xffffffffL, 1));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 1, 0xffffffffL));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 0xffffffffL, 0xffffffffL));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 0x80000000L));
Assert.assertEquals(0x80000000L, op.evaluateBinary(4, 4, 0x80000000L, 1));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 1, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 0x80000000L, 0x7fffffffL));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0x7fffffffL, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 0x80000000L, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 0x7fffffffL, 0x7fffffffL));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 1, 0));// divide by zero
Assert.assertEquals(0x3E0708EEL, op.evaluateBinary(8, 8, 0x2512345678L, 0x99));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, 1));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, 0xffffffffffffffffL));
Assert.assertEquals(0xffffffffffffffffL, op.evaluateBinary(8, 8, 0xffffffffffffffffL, 1));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 1, 0xffffffffffffffffL));
Assert.assertEquals(1, op.evaluateBinary(8, 8, 0xffffffffffffffffL, 0xffffffffffffffffL));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, Long.MIN_VALUE));
Assert.assertEquals(Long.MIN_VALUE, op.evaluateBinary(8, 8, Long.MIN_VALUE, 1));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 1, Long.MIN_VALUE));
Assert.assertEquals(1, op.evaluateBinary(8, 8, Long.MIN_VALUE, Long.MAX_VALUE));
Assert.assertEquals(0, op.evaluateBinary(8, 8, Long.MAX_VALUE, Long.MIN_VALUE));
Assert.assertEquals(1, op.evaluateBinary(8, 8, Long.MIN_VALUE, Long.MIN_VALUE));
Assert.assertEquals(1, op.evaluateBinary(8, 8, Long.MAX_VALUE, Long.MAX_VALUE));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorIntDiv op = new OpBehaviorIntDiv();
BigInteger NEGATIVE_ONE = Utils.convertToUnsignedValue(BigInteger.valueOf(-1), 16);
BigInteger BIG_POSITIVE = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
BigInteger BIG_NEGATIVE = Utils.convertToUnsignedValue(
new BigInteger("80000000000000000000000000000000", 16), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ONE, BigInteger.ZERO),
16);
Assert.assertEquals(BigInteger.valueOf(0x3E0708EEL),
op.evaluateBinary(8, 8, BigInteger.valueOf(0x2512345678L), BigInteger.valueOf(0x99)));
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ONE),
16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, NEGATIVE_ONE), 16);
assertEquals(NEGATIVE_ONE, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ONE), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ONE, NEGATIVE_ONE), 16);
assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, NEGATIVE_ONE, NEGATIVE_ONE), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, BIG_NEGATIVE), 16);
assertEquals(BIG_NEGATIVE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ONE), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ONE, BIG_NEGATIVE), 16);
assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_POSITIVE), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_NEGATIVE), 16);
assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_NEGATIVE), 16);// overflow
assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_POSITIVE), 16);// overflow
}
}

View file

@ -1,86 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
public class OpBehaviorIntLeftTest extends AbstractOpBehaviorTest {
public OpBehaviorIntLeftTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorIntLeft op = new OpBehaviorIntLeft();
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 8));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, -1));
Assert.assertEquals(0x100, op.evaluateBinary(4, 4, 1, 8));
Assert.assertEquals(0x80000000L, op.evaluateBinary(4, 4, 1, 31));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 1, 32));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 1, 33));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, 8));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, -1));
Assert.assertEquals(0x100L, op.evaluateBinary(8, 8, 1, 8));
Assert.assertEquals(Long.MIN_VALUE, op.evaluateBinary(8, 8, 1, 63));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 1, 64));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 1, 65));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorIntLeft op = new OpBehaviorIntLeft();
assertEquals(BigInteger.ZERO,
op.evaluateBinary(4, 4, BigInteger.ZERO, getUnsignedBigInt(8)), 4);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(4, 4, BigInteger.ZERO, getUnsignedBigInt(-1)), 4);
assertEquals(getUnsignedBigInt(0x100L),
op.evaluateBinary(4, 4, BigInteger.ONE, getUnsignedBigInt(8)), 4);
assertEquals(getUnsignedBigInt(0x80000000L),
op.evaluateBinary(4, 4, BigInteger.ONE, getUnsignedBigInt(31)), 4);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(4, 4, BigInteger.ONE, getUnsignedBigInt(32)), 4);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(4, 4, BigInteger.ONE, getUnsignedBigInt(33)), 4);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(4, 4, getUnsignedBigInt(0x80000000L), BigInteger.ONE), 4);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, BigInteger.ZERO, getUnsignedBigInt(8)), 8);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, BigInteger.ZERO, getUnsignedBigInt(-1)), 8);
assertEquals(getUnsignedBigInt(0x100L),
op.evaluateBinary(8, 8, BigInteger.ONE, getUnsignedBigInt(8)), 8);
assertEquals(getUnsignedBigInt(Long.MIN_VALUE),
op.evaluateBinary(8, 8, BigInteger.ONE, getUnsignedBigInt(63)), 8);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, BigInteger.ONE, getUnsignedBigInt(64)), 8);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, BigInteger.ONE, getUnsignedBigInt(65)), 8);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, getUnsignedBigInt(Long.MIN_VALUE), BigInteger.ONE), 4);
}
}

View file

@ -1,104 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.utils.Utils;
public class OpBehaviorIntLessEqualTest extends AbstractOpBehaviorTest {
public OpBehaviorIntLessEqualTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorIntLessEqual op = new OpBehaviorIntLessEqual();
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 1, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0, 1));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0xffffffffL, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0, 0xffffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0xffffffffL, 1));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 1, 0xffffffffL));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0xffffffffL, 0xffffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0x80000000L, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0, 0x80000000L));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0x80000000L, 1));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 1, 0x80000000L));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0x80000000L, 0x7fffffffL));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0x7fffffffL, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0x80000000L, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0x7fffffffL, 0x7fffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0xffffffffL, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0x80000000L, 0xffffffffL));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 1, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0, 1));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 0xffffffffffffffffL, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0, 0xffffffffffffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 0xffffffffffffffffL, 1));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 1, 0xffffffffffffffffL));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0xffffffffffffffffL, 0xffffffffffffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 8, Long.MIN_VALUE, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0, Long.MIN_VALUE));
Assert.assertEquals(0, op.evaluateBinary(1, 8, Long.MIN_VALUE, 1));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 1, Long.MIN_VALUE));
Assert.assertEquals(0, op.evaluateBinary(1, 8, Long.MIN_VALUE, Long.MAX_VALUE));
Assert.assertEquals(1, op.evaluateBinary(1, 8, Long.MAX_VALUE, Long.MIN_VALUE));
Assert.assertEquals(1, op.evaluateBinary(1, 8, Long.MIN_VALUE, Long.MIN_VALUE));
Assert.assertEquals(1, op.evaluateBinary(1, 8, Long.MAX_VALUE, Long.MAX_VALUE));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 0xffffffffffffffffL, 0x8000000000000000L));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0x8000000000000000L, 0xffffffffffffffffL));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorIntLessEqual op = new OpBehaviorIntLessEqual();
BigInteger NEGATIVE_ONE = Utils.convertToUnsignedValue(BigInteger.valueOf(-1), 16);
BigInteger BIG_POSITIVE = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
BigInteger BIG_NEGATIVE =
Utils.convertToUnsignedValue(new BigInteger("80000000000000000000000000000000", 16), 16);
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ONE, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ONE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ZERO, NEGATIVE_ONE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ONE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ONE, NEGATIVE_ONE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, NEGATIVE_ONE, NEGATIVE_ONE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ZERO, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ONE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ONE, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_POSITIVE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_POSITIVE));
}
}

View file

@ -1,103 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.utils.Utils;
public class OpBehaviorIntLessTest extends AbstractOpBehaviorTest {
public OpBehaviorIntLessTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorIntLess op = new OpBehaviorIntLess();
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 1, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0, 1));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0xffffffffL, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0, 0xffffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0xffffffffL, 1));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 1, 0xffffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0xffffffffL, 0xffffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0x80000000L, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0, 0x80000000L));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0x80000000L, 1));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 1, 0x80000000L));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0x80000000L, 0x7fffffffL));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0x7fffffffL, 0x80000000L));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0x80000000L, 0x80000000L));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0x7fffffffL, 0x7fffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0xffffffffL, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0x80000000L, 0xffffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 0, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 1, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0, 1));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 0xffffffffffffffffL, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0, 0xffffffffffffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 0xffffffffffffffffL, 1));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 1, 0xffffffffffffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 0xffffffffffffffffL, 0xffffffffffffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 8, Long.MIN_VALUE, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0, Long.MIN_VALUE));
Assert.assertEquals(0, op.evaluateBinary(1, 8, Long.MIN_VALUE, 1));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 1, Long.MIN_VALUE));
Assert.assertEquals(0, op.evaluateBinary(1, 8, Long.MIN_VALUE, Long.MAX_VALUE));
Assert.assertEquals(1, op.evaluateBinary(1, 8, Long.MAX_VALUE, Long.MIN_VALUE));
Assert.assertEquals(0, op.evaluateBinary(1, 8, Long.MIN_VALUE, Long.MIN_VALUE));
Assert.assertEquals(0, op.evaluateBinary(1, 8, Long.MAX_VALUE, Long.MAX_VALUE));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 0xffffffffffffffffL, 0x8000000000000000L));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0x8000000000000000L, 0xffffffffffffffffL));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorIntLess op = new OpBehaviorIntLess();
BigInteger NEGATIVE_ONE = Utils.convertToUnsignedValue(BigInteger.valueOf(-1), 16);
BigInteger BIG_POSITIVE = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
BigInteger BIG_NEGATIVE =
Utils.convertToUnsignedValue(new BigInteger("80000000000000000000000000000000", 16), 16);
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ONE, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ONE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ZERO, NEGATIVE_ONE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ONE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ONE, NEGATIVE_ONE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, NEGATIVE_ONE, NEGATIVE_ONE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ZERO, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ONE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ONE, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_POSITIVE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_POSITIVE));
}
}

View file

@ -1,110 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.utils.Utils;
public class OpBehaviorIntMultTest extends AbstractOpBehaviorTest {
public OpBehaviorIntMultTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorIntMult op = new OpBehaviorIntMult();
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 0));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 1, 0));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 1));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0xffffffffL, 0));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 0xffffffffL));
Assert.assertEquals(0xffffffffL, op.evaluateBinary(4, 4, 0xffffffffL, 1));
Assert.assertEquals(0xffffffffL, op.evaluateBinary(4, 4, 1, 0xffffffffL));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 0xffffffffL, 0xffffffffL));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0x80000000L, 0));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 0x80000000L));
Assert.assertEquals(0x80000000L, op.evaluateBinary(4, 4, 0x80000000L, 1));
Assert.assertEquals(0x80000000L, op.evaluateBinary(4, 4, 1, 0x80000000L));
Assert.assertEquals(0x80000000L, op.evaluateBinary(4, 4, 0x80000000L, 0x7fffffffL), 4);
Assert.assertEquals(0x80000000L, op.evaluateBinary(4, 4, 0x7fffffffL, 0x80000000L));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0x80000000L, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 0x7fffffffL, 0x7fffffffL));
Assert.assertEquals(0x71c71c72, op.evaluateBinary(4, 4, 0x55555555L, 0xaaaaaaaaL));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, 0));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 1, 0));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, 1));
Assert.assertEquals(0, op.evaluateBinary(8, 8, -1, 0));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, -1));
Assert.assertEquals(-1, op.evaluateBinary(8, 8, -1, 1));
Assert.assertEquals(-1, op.evaluateBinary(8, 8, 1, -1));
Assert.assertEquals(1, op.evaluateBinary(8, 8, -1, -1));
Assert.assertEquals(0, op.evaluateBinary(8, 8, Long.MIN_VALUE, 0));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, Long.MIN_VALUE));
Assert.assertEquals(Long.MIN_VALUE, op.evaluateBinary(8, 8, Long.MIN_VALUE, 1));
Assert.assertEquals(Long.MIN_VALUE, op.evaluateBinary(8, 8, 1, Long.MIN_VALUE));
Assert.assertEquals(Long.MIN_VALUE,
op.evaluateBinary(8, 8, Long.MIN_VALUE, Long.MAX_VALUE));
Assert.assertEquals(Long.MIN_VALUE,
op.evaluateBinary(8, 8, Long.MAX_VALUE, Long.MIN_VALUE));
Assert.assertEquals(0, op.evaluateBinary(8, 8, Long.MIN_VALUE, Long.MIN_VALUE));
Assert.assertEquals(1, op.evaluateBinary(8, 8, Long.MAX_VALUE, Long.MAX_VALUE));
Assert.assertEquals(0x1c71c71c71c71c72L,
op.evaluateBinary(8, 8, 0x5555555555555555L, 0xaaaaaaaaaaaaaaaaL), 8);
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorIntMult op = new OpBehaviorIntMult();
BigInteger NEGATIVE_ONE = Utils.convertToUnsignedValue(BigInteger.valueOf(-1), 16);
BigInteger BIG_POSITIVE = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
BigInteger BIG_NEGATIVE = Utils.convertToUnsignedValue(
new BigInteger("80000000000000000000000000000000", 16), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ZERO),
16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ONE, BigInteger.ZERO),
16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ONE),
16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ZERO), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, NEGATIVE_ONE), 16);
assertEquals(NEGATIVE_ONE, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ONE), 16);
assertEquals(NEGATIVE_ONE, op.evaluateBinary(1, 16, BigInteger.ONE, NEGATIVE_ONE), 16);
assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, NEGATIVE_ONE, NEGATIVE_ONE), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ZERO), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, BIG_NEGATIVE), 16);
assertEquals(BIG_NEGATIVE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ONE), 16);
assertEquals(BIG_NEGATIVE, op.evaluateBinary(1, 16, BigInteger.ONE, BIG_NEGATIVE), 16);
assertEquals(BIG_NEGATIVE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_POSITIVE), 16);
assertEquals(BIG_NEGATIVE, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_NEGATIVE), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_NEGATIVE), 16);
assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_POSITIVE), 16);
assertEquals(new BigInteger("71c71c71c71c71c71c71c71c71c71c72", 16),
op.evaluateBinary(8, 8, new BigInteger("55555555555555555555555555555555", 16),
new BigInteger("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 16)),
16);
}
}

View file

@ -1,72 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
public class OpBehaviorIntNegateTest extends AbstractOpBehaviorTest {
public OpBehaviorIntNegateTest() {
super();
}
@Test
public void testevaluateUnaryLong() {
OpBehaviorIntNegate op = new OpBehaviorIntNegate();
Assert.assertEquals(0xffffffffL, op.evaluateUnary(4, 4, 0));
Assert.assertEquals(0, op.evaluateUnary(4, 4, 0xffffffffL));
Assert.assertEquals(0xfffffffdL, op.evaluateUnary(4, 4, 2));
Assert.assertEquals(2, op.evaluateUnary(4, 4, 0xfffffffdL));
Assert.assertEquals(0x80000000L, op.evaluateUnary(4, 4, 0x7fffffffL));
Assert.assertEquals(0x7fffffffL, op.evaluateUnary(4, 4, 0x80000000L));
Assert.assertEquals(1, op.evaluateUnary(4, 4, 0xfffffffeL));
Assert.assertEquals(0xfffffffeL, op.evaluateUnary(4, 4, 1));
Assert.assertEquals(0, op.evaluateUnary(8, 8, -1));
Assert.assertEquals(-1, op.evaluateUnary(8, 8, 0));
Assert.assertEquals(-3, op.evaluateUnary(8, 8, 2));
Assert.assertEquals(2, op.evaluateUnary(8, 8, -3));
Assert.assertEquals(Long.MIN_VALUE, op.evaluateUnary(8, 8, Long.MAX_VALUE));
Assert.assertEquals(Long.MAX_VALUE, op.evaluateUnary(8, 8, Long.MIN_VALUE));
Assert.assertEquals(1, op.evaluateUnary(8, 8, -2));
Assert.assertEquals(-2, op.evaluateUnary(8, 8, 1));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorIntNegate op = new OpBehaviorIntNegate();
BigInteger negOne = new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
BigInteger minNum = new BigInteger("80000000000000000000000000000000", 16);
BigInteger maxNum = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
assertEquals(negOne, op.evaluateUnary(8, 8, BigInteger.ZERO), 16);
assertEquals(BigInteger.ZERO, op.evaluateUnary(8, 8, negOne), 16);
assertEquals(getUnsignedBigInt(-3, 16), op.evaluateUnary(8, 8, getUnsignedBigInt(2)), 16);
assertEquals(getUnsignedBigInt(2), op.evaluateUnary(8, 8, getUnsignedBigInt(-3, 16)), 16);
assertEquals(minNum, op.evaluateUnary(8, 8, maxNum), 16);
assertEquals(maxNum, op.evaluateUnary(8, 8, minNum), 16);
assertEquals(BigInteger.ONE, op.evaluateUnary(8, 8, getUnsignedBigInt(-2, 16)), 16);
assertEquals(getUnsignedBigInt(-2, 16), op.evaluateUnary(8, 8, BigInteger.ONE), 16);
}
}

View file

@ -1,104 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.utils.Utils;
public class OpBehaviorIntOrTest extends AbstractOpBehaviorTest {
public OpBehaviorIntOrTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorIntOr op = new OpBehaviorIntOr();
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 0));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 1, 0));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 0, 1));
Assert.assertEquals(0xffffffffL, op.evaluateBinary(4, 4, 0xffffffffL, 0));
Assert.assertEquals(0xffffffffL, op.evaluateBinary(4, 4, 0, 0xffffffffL));
Assert.assertEquals(0xffffffffL, op.evaluateBinary(4, 4, 0xffffffffL, 1));
Assert.assertEquals(0xffffffffL, op.evaluateBinary(4, 4, 1, 0xffffffffL));
Assert.assertEquals(0xffffffffL, op.evaluateBinary(4, 4, 0xffffffffL, 0xffffffffL));
Assert.assertEquals(0x80000000L, op.evaluateBinary(4, 4, 0x80000000L, 0));
Assert.assertEquals(0x80000000L, op.evaluateBinary(4, 4, 0, 0x80000000L));
Assert.assertEquals(0x80000001L, op.evaluateBinary(4, 4, 0x80000000L, 1));
Assert.assertEquals(0x80000001L, op.evaluateBinary(4, 4, 1, 0x80000000L));
Assert.assertEquals(0xffffffffL, op.evaluateBinary(4, 4, 0x80000000L, 0x7fffffffL));
Assert.assertEquals(0xffffffffL, op.evaluateBinary(4, 4, 0x7fffffffL, 0x80000000L));
Assert.assertEquals(0x80000000L, op.evaluateBinary(4, 4, 0x80000000L, 0x80000000L));// overflow
Assert.assertEquals(0x7fffffffL, op.evaluateBinary(4, 4, 0x7fffffffL, 0x7fffffffL));// overflow
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, 0));
Assert.assertEquals(1, op.evaluateBinary(8, 8, 1, 0));
Assert.assertEquals(1, op.evaluateBinary(8, 8, 0, 1));
Assert.assertEquals(-1, op.evaluateBinary(8, 8, -1, 0));
Assert.assertEquals(-1, op.evaluateBinary(8, 8, 0, -1));
Assert.assertEquals(-1, op.evaluateBinary(8, 8, -1, 1));
Assert.assertEquals(-1, op.evaluateBinary(8, 8, 1, -1));
Assert.assertEquals(-1, op.evaluateBinary(8, 8, -1, -1));
Assert.assertEquals(Long.MIN_VALUE, op.evaluateBinary(8, 8, Long.MIN_VALUE, 0));
Assert.assertEquals(Long.MIN_VALUE, op.evaluateBinary(8, 8, 0, Long.MIN_VALUE));
Assert.assertEquals(Long.MIN_VALUE + 1, op.evaluateBinary(8, 8, Long.MIN_VALUE, 1));
Assert.assertEquals(Long.MIN_VALUE + 1, op.evaluateBinary(8, 8, 1, Long.MIN_VALUE));
Assert.assertEquals(-1, op.evaluateBinary(8, 8, Long.MIN_VALUE, Long.MAX_VALUE));
Assert.assertEquals(-1, op.evaluateBinary(8, 8, Long.MAX_VALUE, Long.MIN_VALUE));
Assert.assertEquals(Long.MIN_VALUE,
op.evaluateBinary(8, 8, Long.MIN_VALUE, Long.MIN_VALUE));// overflow
Assert.assertEquals(Long.MAX_VALUE,
op.evaluateBinary(8, 8, Long.MAX_VALUE, Long.MAX_VALUE));// overflow
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorIntOr op = new OpBehaviorIntOr();
BigInteger NEGATIVE_ONE = Utils.convertToUnsignedValue(BigInteger.valueOf(-1), 16);
BigInteger BIG_POSITIVE = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
BigInteger BIG_NEGATIVE = Utils.convertToUnsignedValue(
new BigInteger("80000000000000000000000000000000", 16), 16);
assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ZERO),
16);
assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ONE, BigInteger.ZERO), 16);
assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ONE), 16);
assertEquals(NEGATIVE_ONE, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ZERO), 16);
assertEquals(NEGATIVE_ONE, op.evaluateBinary(1, 16, BigInteger.ZERO, NEGATIVE_ONE), 16);
assertEquals(NEGATIVE_ONE, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ONE), 16);
assertEquals(NEGATIVE_ONE, op.evaluateBinary(1, 16, BigInteger.ONE, NEGATIVE_ONE), 16);
assertEquals(NEGATIVE_ONE, op.evaluateBinary(1, 16, NEGATIVE_ONE, NEGATIVE_ONE), 16);
assertEquals(BIG_NEGATIVE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ZERO), 16);
assertEquals(BIG_NEGATIVE, op.evaluateBinary(1, 16, BigInteger.ZERO, BIG_NEGATIVE), 16);
assertEquals(BIG_NEGATIVE.add(BigInteger.ONE),
op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ONE), 16);
assertEquals(BIG_NEGATIVE.add(BigInteger.ONE),
op.evaluateBinary(1, 16, BigInteger.ONE, BIG_NEGATIVE), 16);
assertEquals(NEGATIVE_ONE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_POSITIVE), 16);
assertEquals(NEGATIVE_ONE, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_NEGATIVE), 16);
assertEquals(BIG_NEGATIVE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_NEGATIVE), 16);// overflow
assertEquals(BIG_POSITIVE, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_POSITIVE), 16);// overflow
}
}

View file

@ -1,60 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.error.LowlevelError;
public class OpBehaviorIntRemTest extends AbstractOpBehaviorTest {
public OpBehaviorIntRemTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorIntRem op = new OpBehaviorIntRem();
Assert.assertEquals(0L, op.evaluateBinary(4, 4, 16, 2));
Assert.assertEquals(1L, op.evaluateBinary(4, 4, 17, 2));
Assert.assertEquals(1L, op.evaluateBinary(8, 8, 0xffffffffffffffffL, 2L));
}
@Test(expected = LowlevelError.class)
public void testDivideByZeroLong() {
OpBehaviorIntRem op = new OpBehaviorIntRem();
op.evaluateBinary(4, 4, 1, 0);
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorIntRem op = new OpBehaviorIntRem();
Assert.assertEquals(BigInteger.TWO,
op.evaluateBinary(16, 16, new BigInteger("fffffffffffffffffffffffffffffff2", 16),
BigInteger.TWO.add(BigInteger.TWO)));
}
@Test(expected = LowlevelError.class)
public void testDivideByZeroBigInteger() {
OpBehaviorIntRem op = new OpBehaviorIntRem();
op.evaluateBinary(16, 16, BigInteger.ONE, BigInteger.ZERO);
}
}

View file

@ -1,87 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
public class OpBehaviorIntRightTest extends AbstractOpBehaviorTest {
public OpBehaviorIntRightTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorIntRight op = new OpBehaviorIntRight();
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 8));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, -1));
Assert.assertEquals(0x800000L, op.evaluateBinary(4, 4, 0x80000000L, 8));
Assert.assertEquals(1, op.evaluateBinary(4, 4, 0x80000000L, 31));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0x80000000L, 32));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0x80000000L, 33));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, 8));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, -1));
Assert.assertEquals(0x80000000000000L, op.evaluateBinary(8, 8, 0x8000000000000000L, 8));
Assert.assertEquals(1, op.evaluateBinary(8, 8, 0x8000000000000000L, 63));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0x8000000000000000L, 64));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0x8000000000000000L, 65));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorIntRight op = new OpBehaviorIntRight();
assertEquals(BigInteger.ZERO,
op.evaluateBinary(4, 4, BigInteger.ZERO, getUnsignedBigInt(8)), 4);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(4, 4, BigInteger.ZERO, getUnsignedBigInt(-1)), 4);
assertEquals(getUnsignedBigInt(0x800000L),
op.evaluateBinary(4, 4, getUnsignedBigInt(0x80000000L), getUnsignedBigInt(8)), 4);
assertEquals(BigInteger.ONE,
op.evaluateBinary(4, 4, getUnsignedBigInt(0x80000000L), getUnsignedBigInt(31)), 4);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(4, 4, getUnsignedBigInt(0x80000000L), getUnsignedBigInt(32)), 4);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(4, 4, getUnsignedBigInt(0x80000000L), getUnsignedBigInt(33)), 4);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, BigInteger.ZERO, getUnsignedBigInt(8)), 8);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, BigInteger.ZERO, getUnsignedBigInt(-1)), 8);
assertEquals(getUnsignedBigInt(0x80000000000000L),
op.evaluateBinary(8, 8, getUnsignedBigInt(0x8000000000000000L), getUnsignedBigInt(8)),
8);
assertEquals(BigInteger.ONE,
op.evaluateBinary(8, 8, getUnsignedBigInt(0x8000000000000000L), getUnsignedBigInt(63)),
8);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, getUnsignedBigInt(0x8000000000000000L), getUnsignedBigInt(64)),
8);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, getUnsignedBigInt(0x8000000000000000L), getUnsignedBigInt(65)),
8);
}
}

View file

@ -1,104 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.utils.Utils;
public class OpBehaviorIntSLessEqualTest extends AbstractOpBehaviorTest {
public OpBehaviorIntSLessEqualTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorIntSless op = new OpBehaviorIntSless();
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 1, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0, 1));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0xffffffffL, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0, 0xffffffffL));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0xffffffffL, 1));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 1, 0xffffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0xffffffffL, 0xffffffffL));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0x80000000L, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0x80000000L, 1));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 1, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0x80000000L, 0x7fffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0x7fffffffL, 0x80000000L));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0x80000000L, 0x80000000L));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0x7fffffffL, 0x7fffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0xffffffffL, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0x80000000L, 0xffffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 0, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 1, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0, 1));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0xffffffffffffffffL, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 0, 0xffffffffffffffffL));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0xffffffffffffffffL, 1));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 1, 0xffffffffffffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 0xffffffffffffffffL, 0xffffffffffffffffL));
Assert.assertEquals(1, op.evaluateBinary(1, 8, Long.MIN_VALUE, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 0, Long.MIN_VALUE));
Assert.assertEquals(1, op.evaluateBinary(1, 8, Long.MIN_VALUE, 1));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 1, Long.MIN_VALUE));
Assert.assertEquals(1, op.evaluateBinary(1, 8, Long.MIN_VALUE, Long.MAX_VALUE));
Assert.assertEquals(0, op.evaluateBinary(1, 8, Long.MAX_VALUE, Long.MIN_VALUE));
Assert.assertEquals(0, op.evaluateBinary(1, 8, Long.MIN_VALUE, Long.MIN_VALUE));
Assert.assertEquals(0, op.evaluateBinary(1, 8, Long.MAX_VALUE, Long.MAX_VALUE));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 0xffffffffffffffffL, 0x8000000000000000L));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0x8000000000000000L, 0xffffffffffffffffL));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorIntSless op = new OpBehaviorIntSless();
BigInteger NEGATIVE_ONE = Utils.convertToUnsignedValue(BigInteger.valueOf(-1), 16);
BigInteger BIG_POSITIVE = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
BigInteger BIG_NEGATIVE =
Utils.convertToUnsignedValue(new BigInteger("80000000000000000000000000000000", 16), 16);
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ONE, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ONE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, NEGATIVE_ONE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ONE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ONE, NEGATIVE_ONE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, NEGATIVE_ONE, NEGATIVE_ONE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ONE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ONE, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_POSITIVE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_POSITIVE));
}
}

View file

@ -1,104 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.utils.Utils;
public class OpBehaviorIntSLessTest extends AbstractOpBehaviorTest {
public OpBehaviorIntSLessTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorIntSlessEqual op = new OpBehaviorIntSlessEqual();
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 1, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0, 1));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0xffffffffL, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0, 0xffffffffL));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0xffffffffL, 1));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 1, 0xffffffffL));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0xffffffffL, 0xffffffffL));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0x80000000L, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0x80000000L, 1));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 1, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0x80000000L, 0x7fffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0x7fffffffL, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0x80000000L, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0x7fffffffL, 0x7fffffffL));
Assert.assertEquals(0, op.evaluateBinary(1, 4, 0xffffffffL, 0x80000000L));
Assert.assertEquals(1, op.evaluateBinary(1, 4, 0x80000000L, 0xffffffffL));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 1, 0));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0, 1));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0xffffffffffffffffL, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 0, 0xffffffffffffffffL));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0xffffffffffffffffL, 1));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 1, 0xffffffffffffffffL));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0xffffffffffffffffL, 0xffffffffffffffffL));
Assert.assertEquals(1, op.evaluateBinary(1, 8, Long.MIN_VALUE, 0));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 0, Long.MIN_VALUE));
Assert.assertEquals(1, op.evaluateBinary(1, 8, Long.MIN_VALUE, 1));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 1, Long.MIN_VALUE));
Assert.assertEquals(1, op.evaluateBinary(1, 8, Long.MIN_VALUE, Long.MAX_VALUE));
Assert.assertEquals(0, op.evaluateBinary(1, 8, Long.MAX_VALUE, Long.MIN_VALUE));
Assert.assertEquals(1, op.evaluateBinary(1, 8, Long.MIN_VALUE, Long.MIN_VALUE));
Assert.assertEquals(1, op.evaluateBinary(1, 8, Long.MAX_VALUE, Long.MAX_VALUE));
Assert.assertEquals(0, op.evaluateBinary(1, 8, 0xffffffffffffffffL, 0x8000000000000000L));
Assert.assertEquals(1, op.evaluateBinary(1, 8, 0x8000000000000000L, 0xffffffffffffffffL));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorIntSlessEqual op = new OpBehaviorIntSlessEqual();
BigInteger NEGATIVE_ONE = Utils.convertToUnsignedValue(BigInteger.valueOf(-1), 16);
BigInteger BIG_POSITIVE = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
BigInteger BIG_NEGATIVE =
Utils.convertToUnsignedValue(new BigInteger("80000000000000000000000000000000", 16), 16);
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ONE, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BigInteger.ZERO, BigInteger.ONE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, NEGATIVE_ONE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, NEGATIVE_ONE, BigInteger.ONE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ONE, NEGATIVE_ONE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, NEGATIVE_ONE, NEGATIVE_ONE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ZERO));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ZERO, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BigInteger.ONE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BigInteger.ONE, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_POSITIVE));
Assert.assertEquals(BigInteger.ZERO, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BIG_NEGATIVE, BIG_NEGATIVE));
Assert.assertEquals(BigInteger.ONE, op.evaluateBinary(1, 16, BIG_POSITIVE, BIG_POSITIVE));
}
}

View file

@ -1,115 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
public class OpBehaviorIntSRightTest extends AbstractOpBehaviorTest {
public OpBehaviorIntSRightTest() {
super();
}
@Test
public void testEvaluateBinaryLong() {
OpBehaviorIntSright op = new OpBehaviorIntSright();
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, 8));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0, -1));
Assert.assertEquals(0xFF800000L, op.evaluateBinary(4, 4, 0x80000000L, 8));
Assert.assertEquals(0xFFFFFFFFL, op.evaluateBinary(4, 4, 0x80000000L, 31));
Assert.assertEquals(0xFFFFFFFFL, op.evaluateBinary(4, 4, 0x80000000L, 32));
Assert.assertEquals(0xFFFFFFFFL, op.evaluateBinary(4, 4, 0x80000000L, 33));
Assert.assertEquals(0x400000L, op.evaluateBinary(4, 4, 0x40000000L, 8));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0x40000000L, 31));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0x40000000L, 32));
Assert.assertEquals(0, op.evaluateBinary(4, 4, 0x40000000L, 33));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, 8));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0, -1));
Assert.assertEquals(0xFF80000000000000L, op.evaluateBinary(8, 8, 0x8000000000000000L, 8));
Assert.assertEquals(-1, op.evaluateBinary(8, 8, 0x8000000000000000L, 63));
Assert.assertEquals(-1, op.evaluateBinary(8, 8, 0x8000000000000000L, 64));
Assert.assertEquals(-1, op.evaluateBinary(8, 8, 0x8000000000000000L, 65));
Assert.assertEquals(0x40000000000000L, op.evaluateBinary(8, 8, 0x4000000000000000L, 8));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0x4000000000000000L, 63));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0x4000000000000000L, 64));
Assert.assertEquals(0, op.evaluateBinary(8, 8, 0x4000000000000000L, 65));
}
@Test
public void testEvaluateBinaryBigInteger() {
OpBehaviorIntSright op = new OpBehaviorIntSright();
assertEquals(BigInteger.ZERO,
op.evaluateBinary(4, 4, BigInteger.ZERO, getUnsignedBigInt(8)), 4);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(4, 4, BigInteger.ZERO, getUnsignedBigInt(-1)), 4);
assertEquals(getUnsignedBigInt(0xFF800000L),
op.evaluateBinary(4, 4, getUnsignedBigInt(0x80000000L), getUnsignedBigInt(8)), 4);
assertEquals(getUnsignedBigInt(0xFFFFFFFFL),
op.evaluateBinary(4, 4, getUnsignedBigInt(0x80000000L), getUnsignedBigInt(31)), 4);
assertEquals(getUnsignedBigInt(0xFFFFFFFFL),
op.evaluateBinary(4, 4, getUnsignedBigInt(0x80000000L), getUnsignedBigInt(32)), 4);
assertEquals(getUnsignedBigInt(0xFFFFFFFFL),
op.evaluateBinary(4, 4, getUnsignedBigInt(0x80000000L), getUnsignedBigInt(33)), 4);
assertEquals(getUnsignedBigInt(0x400000L),
op.evaluateBinary(4, 4, getUnsignedBigInt(0x40000000L), getUnsignedBigInt(8)), 4);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(4, 4, getUnsignedBigInt(0x40000000L), getUnsignedBigInt(31)), 4);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(4, 4, getUnsignedBigInt(0x40000000L), getUnsignedBigInt(32)), 4);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(4, 4, getUnsignedBigInt(0x40000000L), getUnsignedBigInt(33)), 4);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, BigInteger.ZERO, getUnsignedBigInt(8)), 8);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, BigInteger.ZERO, getUnsignedBigInt(-1)), 8);
assertEquals(getUnsignedBigInt(0xFF80000000000000L),
op.evaluateBinary(8, 8, getUnsignedBigInt(0x8000000000000000L), getUnsignedBigInt(8)),
8);
assertEquals(getUnsignedBigInt(-1L),
op.evaluateBinary(8, 8, getUnsignedBigInt(0x8000000000000000L), getUnsignedBigInt(63)),
8);
assertEquals(getUnsignedBigInt(-1L),
op.evaluateBinary(8, 8, getUnsignedBigInt(0x8000000000000000L), getUnsignedBigInt(64)),
8);
assertEquals(getUnsignedBigInt(-1L),
op.evaluateBinary(8, 8, getUnsignedBigInt(0x8000000000000000L), getUnsignedBigInt(65)),
8);
assertEquals(getUnsignedBigInt(0x40000000000000L),
op.evaluateBinary(8, 8, getUnsignedBigInt(0x4000000000000000L), getUnsignedBigInt(8)),
8);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, getUnsignedBigInt(0x4000000000000000L), getUnsignedBigInt(63)),
8);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, getUnsignedBigInt(0x4000000000000000L), getUnsignedBigInt(64)),
8);
assertEquals(BigInteger.ZERO,
op.evaluateBinary(8, 8, getUnsignedBigInt(0x4000000000000000L), getUnsignedBigInt(65)),
8);
}
}

View file

@ -1,91 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.utils.Utils;
public class OpBehaviorLzcountTest extends AbstractOpBehaviorTest {
@Test
public void testEvaluateUnaryLong() {
OpBehaviorLzcount op = new OpBehaviorLzcount();
Assert.assertEquals(8, op.evaluateUnary(1, 1, 0L));
Assert.assertEquals(16, op.evaluateUnary(1, 2, 0L));
Assert.assertEquals(32, op.evaluateUnary(1, 4, 0L));
Assert.assertEquals(64, op.evaluateUnary(1, 8, 0L));
Assert.assertEquals(0, op.evaluateUnary(1, 1, 0xffL));
Assert.assertEquals(0, op.evaluateUnary(1, 2, 0xffffL));
Assert.assertEquals(0, op.evaluateUnary(1, 4, 0xffffffffL));
Assert.assertEquals(0, op.evaluateUnary(1, 8, 0xffffffffffffffffL));
Assert.assertEquals(0, op.evaluateUnary(1, 1, 0x96L));
Assert.assertEquals(0, op.evaluateUnary(1, 2, 0xdbf4L));
Assert.assertEquals(1, op.evaluateUnary(1, 4, 0x460f457bL));
Assert.assertEquals(3, op.evaluateUnary(1, 8, 0x1fae97efca7d5759L));
Assert.assertEquals(4, op.evaluateUnary(1, 1, 0xaL));
Assert.assertEquals(6, op.evaluateUnary(1, 2, 0x2a5L));
Assert.assertEquals(9, op.evaluateUnary(1, 4, 0x60dfffL));
Assert.assertEquals(13, op.evaluateUnary(1, 8, 0x635017adefe4eL));
Assert.assertEquals(3, op.evaluateUnary(1, 1, 0x17L));
Assert.assertEquals(8, op.evaluateUnary(1, 2, 0xd1L));
Assert.assertEquals(22, op.evaluateUnary(1, 4, 0x39eL));
Assert.assertEquals(27, op.evaluateUnary(1, 8, 0x189c178d6aL));
Assert.assertEquals(4, op.evaluateUnary(1, 1, 0xfL));
Assert.assertEquals(4, op.evaluateUnary(1, 2, 0xff0L));
Assert.assertEquals(0, op.evaluateUnary(1, 4, 0xffff0000L));
Assert.assertEquals(24, op.evaluateUnary(1, 8, 0xff00ff00ffL));
}
@Test
public void testEvaluateUnaryBigInteger() {
OpBehaviorLzcount op = new OpBehaviorLzcount();
BigInteger NEGATIVE_ONE = Utils.convertToUnsignedValue(BigInteger.valueOf(-1), 16);
BigInteger BIG_POSITIVE = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
BigInteger BIG_NEGATIVE = Utils
.convertToUnsignedValue(new BigInteger("80000000000000000000000000000000", 16), 16);
assertEquals(BigInteger.valueOf(128), op.evaluateUnary(1, 16, BigInteger.ZERO), 16);
assertEquals(BigInteger.ZERO, op.evaluateUnary(1, 16, NEGATIVE_ONE), 16);
assertEquals(BigInteger.ONE, op.evaluateUnary(1, 16, BIG_POSITIVE), 16);
assertEquals(BigInteger.ZERO, op.evaluateUnary(1, 16, BIG_NEGATIVE), 16);
BigInteger val = BigInteger.valueOf(0x35017adefe4eL);
val = val.shiftLeft(64);
val = val.or(Utils.convertToUnsignedValue(BigInteger.valueOf(0xd46223189c178d6aL), 8));
assertEquals(BigInteger.valueOf(18), op.evaluateUnary(1, 16, val), 16);
BigInteger FF = BigInteger.valueOf(0xff);
val = BigInteger.ZERO;
for (int i = 0; i < 20; ++i) {
val = val.shiftLeft(16);
val = val.add(FF);
}
assertEquals(BigInteger.valueOf(8), op.evaluateUnary(1, 40, val), 40);
}
}

View file

@ -1,90 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.pcode.opbehavior;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
import ghidra.pcode.utils.Utils;
public class OpBehaviorPopcountTest extends AbstractOpBehaviorTest {
@Test
public void testEvaluateUnaryLong() {
OpBehaviorPopcount op = new OpBehaviorPopcount();
Assert.assertEquals(0, op.evaluateUnary(1, 1, 0L));
Assert.assertEquals(0, op.evaluateUnary(1, 2, 0L));
Assert.assertEquals(0, op.evaluateUnary(1, 4, 0L));
Assert.assertEquals(0, op.evaluateUnary(1, 8, 0L));
Assert.assertEquals(8, op.evaluateUnary(1, 1, 0xffL));
Assert.assertEquals(16, op.evaluateUnary(1, 2, 0xffffL));
Assert.assertEquals(32, op.evaluateUnary(1, 4, 0xffffffffL));
Assert.assertEquals(64, op.evaluateUnary(1, 8, 0xffffffffffffffffL));
Assert.assertEquals(4, op.evaluateUnary(1, 1, 0x96L));
Assert.assertEquals(11, op.evaluateUnary(1, 2, 0xdbf4L));
Assert.assertEquals(16, op.evaluateUnary(1, 4, 0x460f457bL));
Assert.assertEquals(41, op.evaluateUnary(1, 8, 0x1fae97efca7d5759L));
Assert.assertEquals(5, op.evaluateUnary(1, 1, 0x7aL));
Assert.assertEquals(10, op.evaluateUnary(1, 2, 0xfca5L));
Assert.assertEquals(20, op.evaluateUnary(1, 4, 0x2660dfffL));
Assert.assertEquals(38, op.evaluateUnary(1, 8, 0x79f635017adefe4eL));
Assert.assertEquals(4, op.evaluateUnary(1, 1, 0x17L));
Assert.assertEquals(10, op.evaluateUnary(1, 2, 0x77d1L));
Assert.assertEquals(15, op.evaluateUnary(1, 4, 0x5758039eL));
Assert.assertEquals(28, op.evaluateUnary(1, 8, 0xd46223189c178d6aL));
Assert.assertEquals(7, op.evaluateUnary(1, 1, 0xbfL));
Assert.assertEquals(12, op.evaluateUnary(1, 2, 0xe3efL));
Assert.assertEquals(17, op.evaluateUnary(1, 4, 0xb2d7e134L));
Assert.assertEquals(34, op.evaluateUnary(1, 8, 0x69f7a0fa6eeda6L));
}
@Test
public void testEvaluateUnaryBigInteger() {
OpBehaviorPopcount op = new OpBehaviorPopcount();
BigInteger NEGATIVE_ONE = Utils.convertToUnsignedValue(BigInteger.valueOf(-1), 16);
BigInteger BIG_POSITIVE = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
BigInteger BIG_NEGATIVE = Utils
.convertToUnsignedValue(new BigInteger("80000000000000000000000000000000", 16), 16);
assertEquals(BigInteger.ZERO, op.evaluateUnary(1, 16, BigInteger.ZERO), 16);
assertEquals(BigInteger.valueOf(128), op.evaluateUnary(1, 16, NEGATIVE_ONE), 16);
assertEquals(BigInteger.valueOf(127), op.evaluateUnary(1, 16, BIG_POSITIVE), 16);
assertEquals(BigInteger.ONE, op.evaluateUnary(1, 16, BIG_NEGATIVE), 16);
BigInteger val = BigInteger.valueOf(0x79f635017adefe4eL);
val = val.shiftLeft(64);
val = val.or(Utils.convertToUnsignedValue(BigInteger.valueOf(0xd46223189c178d6aL), 8));
assertEquals(BigInteger.valueOf(66), op.evaluateUnary(1, 16, val), 16);
BigInteger FF = BigInteger.valueOf(0xff);
val = BigInteger.ZERO;
for (int i = 0; i < 20; ++i) {
val = val.shiftLeft(16);
val = val.add(FF);
}
assertEquals(BigInteger.valueOf(160), op.evaluateUnary(1, 40, val), 40);
}
}