mirror of
https://github.com/myhdl/myhdl.git
synced 2025-01-24 21:52:56 +08:00
output file backup
This commit is contained in:
parent
4bf0050b01
commit
d76a81bc4b
@ -196,6 +196,8 @@ class Simulation(object):
|
|||||||
except SuspendSimulation:
|
except SuspendSimulation:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
printExcInfo()
|
printExcInfo()
|
||||||
|
if tracing:
|
||||||
|
tracefile.flush()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
except StopSimulation:
|
except StopSimulation:
|
||||||
|
@ -34,8 +34,9 @@ path = os.path
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
import shutil
|
||||||
|
|
||||||
from myhdl import delay, Signal
|
from myhdl import delay, Signal, Simulation
|
||||||
from trace_sigs import trace_sigs, TopLevelNameError, ArgTypeError, \
|
from trace_sigs import trace_sigs, TopLevelNameError, ArgTypeError, \
|
||||||
NoInstancesError
|
NoInstancesError
|
||||||
|
|
||||||
@ -66,10 +67,20 @@ def top():
|
|||||||
|
|
||||||
class TestTraceSigs(TestCase):
|
class TestTraceSigs(TestCase):
|
||||||
|
|
||||||
def testTopName(self):
|
def setUp(self):
|
||||||
p = "dut.vcd"
|
self.paths = paths = ["dut.vcd", "inst.vcd"]
|
||||||
|
for p in paths:
|
||||||
if path.exists(p):
|
if path.exists(p):
|
||||||
os.remove(p)
|
os.remove(p)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
for p in self.paths:
|
||||||
|
if path.exists(p):
|
||||||
|
os.remove(p)
|
||||||
|
|
||||||
|
|
||||||
|
def testTopName(self):
|
||||||
|
p = "dut.vcd"
|
||||||
dut = trace_sigs(fun)
|
dut = trace_sigs(fun)
|
||||||
try:
|
try:
|
||||||
trace_sigs(fun)
|
trace_sigs(fun)
|
||||||
@ -80,8 +91,6 @@ class TestTraceSigs(TestCase):
|
|||||||
|
|
||||||
def testArgType1(self):
|
def testArgType1(self):
|
||||||
p = "dut.vcd"
|
p = "dut.vcd"
|
||||||
if path.exists(p):
|
|
||||||
os.remove(p)
|
|
||||||
try:
|
try:
|
||||||
dut = trace_sigs([1, 2])
|
dut = trace_sigs([1, 2])
|
||||||
except ArgTypeError:
|
except ArgTypeError:
|
||||||
@ -91,8 +100,6 @@ class TestTraceSigs(TestCase):
|
|||||||
|
|
||||||
def testArgType2(self):
|
def testArgType2(self):
|
||||||
p = "dut.vcd"
|
p = "dut.vcd"
|
||||||
if path.exists(p):
|
|
||||||
os.remove(p)
|
|
||||||
try:
|
try:
|
||||||
dut = trace_sigs(gen, Signal(0))
|
dut = trace_sigs(gen, Signal(0))
|
||||||
except ArgTypeError:
|
except ArgTypeError:
|
||||||
@ -102,8 +109,6 @@ class TestTraceSigs(TestCase):
|
|||||||
|
|
||||||
def testReturnVal(self):
|
def testReturnVal(self):
|
||||||
p = "dut.vcd"
|
p = "dut.vcd"
|
||||||
if path.exists(p):
|
|
||||||
os.remove(p)
|
|
||||||
try:
|
try:
|
||||||
dut = trace_sigs(dummy)
|
dut = trace_sigs(dummy)
|
||||||
except NoInstancesError:
|
except NoInstancesError:
|
||||||
@ -111,28 +116,32 @@ class TestTraceSigs(TestCase):
|
|||||||
else:
|
else:
|
||||||
self.fail()
|
self.fail()
|
||||||
|
|
||||||
|
|
||||||
def testHierarchicalTrace1(self):
|
def testHierarchicalTrace1(self):
|
||||||
p = "inst.vcd"
|
p = "inst.vcd"
|
||||||
if path.exists(p):
|
|
||||||
os.remove(p)
|
|
||||||
top()
|
top()
|
||||||
self.assert_(path.exists(p))
|
self.assert_(path.exists(p))
|
||||||
|
|
||||||
def testHierarchicalTrace2(self):
|
def testHierarchicalTrace2(self):
|
||||||
pdut = "dut.vcd"
|
pdut = "dut.vcd"
|
||||||
psub = "inst.vcd"
|
psub = "inst.vcd"
|
||||||
for p in (pdut, psub):
|
|
||||||
if path.exists(p):
|
|
||||||
os.remove(p)
|
|
||||||
dut = trace_sigs(top)
|
dut = trace_sigs(top)
|
||||||
self.assert_(path.exists(pdut))
|
self.assert_(path.exists(pdut))
|
||||||
self.assert_(not path.exists(psub))
|
self.assert_(not path.exists(psub))
|
||||||
|
|
||||||
|
def testBackupOutputFile(self):
|
||||||
|
p = "dut.vcd"
|
||||||
|
dut = trace_sigs(fun)
|
||||||
|
Simulation(dut).run(1000)
|
||||||
|
size = path.getsize(p)
|
||||||
|
pbak = p + '.' + str(path.getmtime(p))
|
||||||
|
self.assert_(not path.exists(pbak))
|
||||||
|
dut = trace_sigs(fun)
|
||||||
|
self.assert_(path.exists(p))
|
||||||
|
self.assert_(path.exists(pbak))
|
||||||
|
self.assert_(path.getsize(pbak) == size)
|
||||||
|
self.assert_(path.getsize(p) < size)
|
||||||
|
os.remove(pbak)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -34,6 +34,9 @@ import re
|
|||||||
import string
|
import string
|
||||||
import time
|
import time
|
||||||
from types import FunctionType
|
from types import FunctionType
|
||||||
|
import os
|
||||||
|
path = os.path
|
||||||
|
import shutil
|
||||||
|
|
||||||
from myhdl import _simulator, Signal, __version__
|
from myhdl import _simulator, Signal, __version__
|
||||||
from myhdl.util import _isGenSeq, _isgeneratorfunction
|
from myhdl.util import _isGenSeq, _isgeneratorfunction
|
||||||
@ -80,8 +83,12 @@ def trace_sigs(dut, *args, **kwargs):
|
|||||||
else:
|
else:
|
||||||
raise TopLevelNameError
|
raise TopLevelNameError
|
||||||
h = HierExtr(name, dut, *args, **kwargs)
|
h = HierExtr(name, dut, *args, **kwargs)
|
||||||
vcdfilename = name + ".vcd"
|
vcdpath = name + ".vcd"
|
||||||
vcdfile = open(vcdfilename, 'w')
|
if path.exists(vcdpath):
|
||||||
|
backup = vcdpath + '.' + str(path.getmtime(vcdpath))
|
||||||
|
shutil.copyfile(vcdpath, backup)
|
||||||
|
os.remove(vcdpath)
|
||||||
|
vcdfile = open(vcdpath, 'w')
|
||||||
_simulator._tracing = 1
|
_simulator._tracing = 1
|
||||||
_simulator._tf = vcdfile
|
_simulator._tf = vcdfile
|
||||||
_writeVcdHeader(vcdfile)
|
_writeVcdHeader(vcdfile)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user