DRAMSys unit tests.
- Build test improved to used a temp dir which is removed after the test. - New test: Run dramSys without arguments. - Tests are totally independent. - New utility functions to get data from config/specs XML files. - Unit test files will now appear in qtcreator. - Info header added to the files.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,3 +17,4 @@ build*/
|
|||||||
*.swo
|
*.swo
|
||||||
cscope*
|
cscope*
|
||||||
DRAMSys/analyzer/scripts/__pycache__/
|
DRAMSys/analyzer/scripts/__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|||||||
@@ -22,3 +22,6 @@ OTHER_FILES += tests/evaluation/sim-batch.xml
|
|||||||
OTHER_FILES += tests/evaluation/fifoStrict.xml
|
OTHER_FILES += tests/evaluation/fifoStrict.xml
|
||||||
OTHER_FILES += tests/evaluation/test.pl
|
OTHER_FILES += tests/evaluation/test.pl
|
||||||
|
|
||||||
|
# python unit tests
|
||||||
|
OTHER_FILES += tests/unit/unit_test.py
|
||||||
|
OTHER_FILES += tests/unit/mem_util.py
|
||||||
|
|||||||
70
DRAMSys/tests/unit/mem_util.py
Normal file
70
DRAMSys/tests/unit/mem_util.py
Normal file
@@ -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)
|
||||||
103
DRAMSys/tests/unit/unit_test.py
Normal file
103
DRAMSys/tests/unit/unit_test.py
Normal file
@@ -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()
|
||||||
@@ -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()
|
|
||||||
Reference in New Issue
Block a user