Daniel Carvalho has uploaded this change for review. ( https://gem5-review.googlesource.com/11101

Change subject: mem-cache: Add a test for no compression
......................................................................

mem-cache: Add a test for no compression

Add a unit test to check if the no_compressor compressor works
as intended. It consists of a compression followed by a
decompression, with checks on the compression size (which must
be equal to the original data size), decompression latency (0),
and matching original and decompressed lines.

Change-Id: I2beb576eab529b6be2199ae79c16e8ae153f8903
---
M src/mem/cache/compressors/SConscript
A src/mem/cache/compressors/test_no_compressor.cc
2 files changed, 76 insertions(+), 0 deletions(-)



diff --git a/src/mem/cache/compressors/SConscript b/src/mem/cache/compressors/SConscript
index 3c6cfce..363a2db 100644
--- a/src/mem/cache/compressors/SConscript
+++ b/src/mem/cache/compressors/SConscript
@@ -34,3 +34,4 @@

 Source('base.cc')
 Source('no_compressor.cc')
+GTest('test_no_compressor', 'test_no_compressor.cc', 'no_compressor.cc')
diff --git a/src/mem/cache/compressors/test_no_compressor.cc b/src/mem/cache/compressors/test_no_compressor.cc
new file mode 100644
index 0000000..e2c70c3
--- /dev/null
+++ b/src/mem/cache/compressors/test_no_compressor.cc
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2018 Inria
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Daniel Carvalho
+ */
+
+#include <gtest/gtest.h>
+
+#include "base/types.hh"
+#include "mem/cache/compressors/no_compressor.hh"
+
+// TODO how can I test within Gem5?
+
+// Create test fixture
+class TestNoCompressor : public testing::Test
+{
+  protected:
+    std::unique_ptr<NoCompressor> compressor;
+
+    // Line size in bytes
+    uint64_t lineSize;
+
+    // Instantiate compressor
+    void SetUp()
+    {
+        // TODO How can I acquire the params?
+        compressor = std::unique_ptr<NoCompressor>(params);
+
+        lineSize = params->line_size;
+    }
+};
+
+TEST_F(TestNoCompressor, Misc)
+{
+    uint64_t data[] = {0x0000000000000000, 0x0123456701234567,
+                       0x0123012301230123, 0x8091A2B3C4D5E6F7,
+                       0xAB17A9B8C9FFFFFF, 0xFFFFFFFFFFF80010,
+                       0x918274526BB172A2, 0xFFFFFFFFFFFFFFFF};
+
+    // Apply compression and check if size matches the original size
+    std::unique_ptr<CompressionData> comp_data = compressor.compress(data);
+    EXPECT_EQ(comp_data->getSize(), lineSize);
+
+    // Check if decompressed data matches original data
+    uint64_t decomp_data[(lineSize*8)/64];
+    Cycles lat = compressor.decompress(comp_data.get(), decomp_data);
+    EXPECT_FALSE(memcmp(data, decomp_data, sizeof(data)));
+
+    // Decompression latency for a no compressor is zero
+    EXPECT_EQ(lat, Cycles(0));
+}

--
To view, visit https://gem5-review.googlesource.com/11101
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I2beb576eab529b6be2199ae79c16e8ae153f8903
Gerrit-Change-Number: 11101
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Carvalho <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to