diff --git a/.gitignore b/.gitignore index f1ef5004..b0259661 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ build*/ *.swo cscope* DRAMSys/analyzer/scripts/__pycache__/ +*.pyc diff --git a/DRAMSys/tests/tests.pri b/DRAMSys/tests/tests.pri index c5ceed89..b264d78f 100644 --- a/DRAMSys/tests/tests.pri +++ b/DRAMSys/tests/tests.pri @@ -22,3 +22,6 @@ OTHER_FILES += tests/evaluation/sim-batch.xml OTHER_FILES += tests/evaluation/fifoStrict.xml OTHER_FILES += tests/evaluation/test.pl +# python unit tests +OTHER_FILES += tests/unit/unit_test.py +OTHER_FILES += tests/unit/mem_util.py diff --git a/DRAMSys/tests/unit/mem_util.py b/DRAMSys/tests/unit/mem_util.py new file mode 100644 index 00000000..cb487a37 --- /dev/null +++ b/DRAMSys/tests/unit/mem_util.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2016, University of Kaiserslautern +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. 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. +# +# 3. Neither the name of the copyright holder 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 HOLDER +# 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: Éder F. Zulian +# + +import xml.etree.ElementTree as ET + + +class MemConfig(object): + """ Memory Configuration Class + + The format used in memory specification XML files differs from the + format used in memory configuration XML files. Each class uses the + proper format when searching for elements. + """ + def getValue(self, id): + return self.xmlMemConfig.findall(id)[0].attrib['value'] + + def getIntValue(self, id): + return int(self.getValue(id)) + + def __init__(self, xmlfile): + self.xmlMemConfig = ET.parse(xmlfile) + + +class MemSpec(object): + """ Memory Specification Class + + The format used in memory specification XML files differs from the + format used in memory configuration XML files. Each class uses the + proper format when searching for elements. + """ + def getValue(self, id): + return self.xmlMemSpec.findall(".//parameter[@id='{0}']". + format(id))[0].attrib['value'] + + def getIntValue(self, id): + return int(self.getValue(id)) + + def __init__(self, xmlfile): + self.xmlMemSpec = ET.parse(xmlfile) diff --git a/DRAMSys/tests/unit/unit_test.py b/DRAMSys/tests/unit/unit_test.py new file mode 100644 index 00000000..aacc500b --- /dev/null +++ b/DRAMSys/tests/unit/unit_test.py @@ -0,0 +1,103 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2016, University of Kaiserslautern +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. 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. +# +# 3. Neither the name of the copyright holder 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 HOLDER +# 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: Éder F. Zulian +# + +import unittest +import subprocess +import os +import shutil +import multiprocessing +import sys +import tempfile +from mem_util import * + + +devnull = None + +rootdir = '../../..' +tempfile.tempdir = os.getcwd() + '/' + rootdir +builddir = tempfile.mkdtemp() +simdir = builddir + '/simulator' + +memConfigPath = rootdir + '/DRAMSys/simulator/resources/configs/memconfigs' +memSpecsPath = rootdir + '/DRAMSys/simulator/resources/configs/memspecs' + + +def build_project(): + if os.path.exists(builddir): + shutil.rmtree(builddir) + os.makedirs(builddir) + os.chdir(builddir) + qmakeprojfile = '../DRAMSys/dram.vp.system.pro' + subprocess.call(['qmake', qmakeprojfile], stdout=devnull, stderr=devnull) + makejobs = '-j' + str(multiprocessing.cpu_count()) + ret = subprocess.call(['make', makejobs], stdout=devnull, stderr=devnull) + return ret + + +class TestBuild(unittest.TestCase): + def test_build_project(self): + """ The project's build process should succeed """ + self.assertEqual(build_project(), 0) + + def tearDown(self): + shutil.rmtree(builddir) + + +class TestOutput(unittest.TestCase): + def setUp(self): + build_project() + + def test_run_without_arguments(self): + """ running dramSys without arguments returns 0 """ + os.chdir(simdir) + self.assertEqual(subprocess.call(['./dramSys'], stdout=devnull), 0) + + def tearDown(self): + shutil.rmtree(builddir) + + +@unittest.skip("skipping this") +class TestDummy(unittest.TestCase): + def test_list_files(self): + for file in os.listdir(memConfigPath): + if file.endswith(".xml"): + print(file) + for file in os.listdir(memSpecsPath): + if file.endswith(".xml"): + print(file) + + +if __name__ == '__main__': + with open(os.devnull, 'wb') as devnull: + unittest.main() diff --git a/DRAMSys/tests/unit_test.py b/DRAMSys/tests/unit_test.py deleted file mode 100644 index 9d2a6c3c..00000000 --- a/DRAMSys/tests/unit_test.py +++ /dev/null @@ -1,28 +0,0 @@ -import unittest -import subprocess -import os -import shutil -import multiprocessing - -devnull = None - - -class TestBuild(unittest.TestCase): - def test_build_project(self): - """ The project's build process should succeed """ - builddir = "../../build" - if os.path.exists(builddir): - shutil.rmtree(builddir) - os.makedirs(builddir) - os.chdir(builddir) - self.assertEqual(subprocess.call(['qmake', - '../DRAMSys/dram.vp.system.pro'], stdout=devnull, - stderr=devnull), 0) - makejobs = "-j" + str(multiprocessing.cpu_count()) - self.assertEqual(subprocess.call(['make', makejobs], stdout=devnull, - stderr=devnull), 0) - - -if __name__ == '__main__': - with open(os.devnull, 'wb') as devnull: - unittest.main()