Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Make test robust
Browse files Browse the repository at this point in the history
  • Loading branch information
bzEq committed Feb 29, 2024
1 parent 446d343 commit 3f3b568
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
14 changes: 7 additions & 7 deletions passes/bytes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ extern "C" {

void ByteSwap(uint8_t *__restrict__ dst, const uint8_t *__restrict__ src,
size_t len) {
static const size_t n = sizeof(uint64_t);
uint64_t *__restrict__ u64_dst = reinterpret_cast<uint64_t *>(dst);
const uint64_t *__restrict__ u64_src =
reinterpret_cast<const uint64_t *>(src);
static constexpr size_t n = sizeof(uint64_t);
auto dst64 = reinterpret_cast<uint64_t *>(dst);
auto src64 = reinterpret_cast<const uint64_t *>(src);
const size_t m = len / n;
const size_t r = m * n;
for (size_t i = 0; i < m; ++i)
u64_dst[i] = __builtin_bswap64(u64_src[m - 1 - i]);
for (size_t i = m * n; i < len; ++i)
dst[i] = src[i];
dst64[i] = __builtin_bswap64(src64[m - 1 - i]);
for (size_t i = 0; i < len - r; ++i)
dst[r + i] = src[len - 1 - i];
}
}
59 changes: 40 additions & 19 deletions passes/passes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ func TestCompress(t *testing.T) {
pm := core.NewLegacyPassManager()
pm.AddPass(&RandCompressor{})
pm.AddPass(&RandDecompressor{})
r, err := pm.RunOnBytes([]byte("wtf"))
if string(r) != "wtf" || err != nil {
const s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
r, err := pm.RunOnBytes([]byte(s))
if string(r) != s || err != nil {
t.Log(err)
t.Log(r)
t.Fail()
Expand All @@ -34,8 +35,9 @@ func TestLZ4Compress(t *testing.T) {
pm := core.NewLegacyPassManager()
pm.AddPass(&LZ4Compressor{})
pm.AddPass(&LZ4Decompressor{})
r, err := pm.RunOnBytes([]byte("wtfwtfwtfwtf"))
if string(r) != "wtfwtfwtfwtf" || err != nil {
const s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
r, err := pm.RunOnBytes([]byte(s))
if string(r) != s || err != nil {
t.Log(err)
t.Log(r)
t.Fail()
Expand All @@ -46,8 +48,9 @@ func TestSnappyCompress(t *testing.T) {
pm := core.NewLegacyPassManager()
pm.AddPass(&SnappyEncoder{})
pm.AddPass(&SnappyDecoder{})
r, err := pm.RunOnBytes([]byte("wtfwtfwtfwtf"))
if string(r) != "wtfwtfwtfwtf" || err != nil {
const s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
r, err := pm.RunOnBytes([]byte(s))
if string(r) != s || err != nil {
t.Log(err)
t.Log(r)
t.Fail()
Expand All @@ -58,8 +61,9 @@ func TestRandCompress(t *testing.T) {
pm := core.NewLegacyPassManager()
pm.AddPass(&RandCompressor{})
pm.AddPass(&RandDecompressor{})
r, err := pm.RunOnBytes([]byte("wtfwtfwtfwtf"))
if string(r) != "wtfwtfwtfwtf" || err != nil {
const s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
r, err := pm.RunOnBytes([]byte(s))
if string(r) != s || err != nil {
t.Log(err)
t.Log(r)
t.Fail()
Expand Down Expand Up @@ -106,8 +110,9 @@ func TestRC4(t *testing.T) {
pm := core.NewLegacyPassManager()
pm.AddPass(&RC4Enc{})
pm.AddPass(&RC4Dec{})
r, err := pm.RunOnBytes([]byte("wtf"))
if string(r) != "wtf" || err != nil {
const s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
r, err := pm.RunOnBytes([]byte(s))
if string(r) != s || err != nil {
t.Log(err)
t.Log(r)
t.Fail()
Expand All @@ -118,8 +123,9 @@ func TestOBFS(t *testing.T) {
pm := core.NewLegacyPassManager()
pm.AddPass(&OBFSEncoder{})
pm.AddPass(&OBFSDecoder{})
r, err := pm.RunOnBytes([]byte("wtf"))
if string(r) != "wtf" || err != nil {
const s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
r, err := pm.RunOnBytes([]byte(s))
if string(r) != s || err != nil {
t.Log(err)
t.Log(r)
t.Fail()
Expand All @@ -130,20 +136,34 @@ func TestRotateLeft(t *testing.T) {
pm := core.NewLegacyPassManager()
pm.AddPass(&RotateLeft{})
pm.AddPass(&DeRotateLeft{})
r, err := pm.RunOnBytes([]byte("wtf"))
if string(r) != "wtf" || err != nil {
const s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
r, err := pm.RunOnBytes([]byte(s))
if string(r) != s || err != nil {
t.Log(err)
t.Log(r)
t.Fail()
}
}

func TestByteSwap(t *testing.T) {
func TestByteSwapTwice(t *testing.T) {
pm := core.NewLegacyPassManager()
pm.AddPass(&ByteSwap{})
pm.AddPass(&ByteSwap{})
r, err := pm.RunOnBytes([]byte("wtfwtfwtfwtfwtfwtfwtf"))
if string(r) != "wtfwtfwtfwtfwtfwtfwtf" || err != nil {
const s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
r, err := pm.RunOnBytes([]byte(s))
if string(r) != s || err != nil {
t.Log(err)
t.Log(r)
t.Fail()
}
}

func TestByteSwap(t *testing.T) {
pm := core.NewLegacyPassManager()
pm.AddPass(&ByteSwap{})
const s = "0123456789ABCDE"
r, err := pm.RunOnBytes([]byte(s))
if string(r) != "76543210EDCBA98" || err != nil {
t.Log(err)
t.Log(r)
t.Fail()
Expand All @@ -154,8 +174,9 @@ func TestIntegration(t *testing.T) {
pm := core.NewLegacyPassManager()
pm.AddPass(&ByteSwap{}).AddPass(&OBFSEncoder{}).AddPass(&LZ4Compressor{}).AddPass(&Reverse{}).AddPass(&RotateLeft{})
pm.AddPass(&DeRotateLeft{}).AddPass(&Reverse{}).AddPass(&LZ4Decompressor{}).AddPass(&OBFSDecoder{}).AddPass(&ByteSwap{})
r, err := pm.RunOnBytes([]byte("wtfwtfwtf"))
if string(r) != "wtfwtfwtf" || err != nil {
const s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
r, err := pm.RunOnBytes([]byte(s))
if string(r) != s || err != nil {
t.Log(err)
t.Log(r)
t.Fail()
Expand Down

0 comments on commit 3f3b568

Please sign in to comment.