mirror of https://github.com/KLayout/klayout.git
Provide tests to text buddy executables without framework
This commit is contained in:
parent
4c8727182e
commit
08aacbd2e8
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
/*
|
||||
|
||||
KLayout Layout Viewer
|
||||
Copyright (C) 2006-2019 Matthias Koefferlein
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
// NOTE: klayout_main_tests is actually a Ruby test which does all test automation
|
||||
// The tests will also test Python capabilities, so Python is required too.
|
||||
|
||||
#if defined(HAVE_RUBY) && defined(HAVE_PYTHON)
|
||||
|
||||
#include "rba.h"
|
||||
#include "gsiDecl.h"
|
||||
|
||||
// On Windows, ruby.h is not compatible with windows.h which is included by utHead - at least not if
|
||||
// windows.h is included before ruby.h ...
|
||||
#include "tlUnitTest.h"
|
||||
|
||||
void run_rubytest (tl::TestBase * /*_this*/, const std::string &fn)
|
||||
{
|
||||
tl_assert (rba::RubyInterpreter::instance ());
|
||||
|
||||
std::string fp (tl::testsrc ());
|
||||
fp += "/testdata/buddies/";
|
||||
fp += fn;
|
||||
rba::RubyInterpreter::instance ()->load_file (fp.c_str ());
|
||||
}
|
||||
|
||||
#define RUBYTEST(n, file) \
|
||||
TEST(n) { run_rubytest(_this, file); }
|
||||
|
||||
RUBYTEST (main, "buddies.rb")
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -15,9 +15,9 @@ SOURCES = \
|
|||
bdStrmcmpTests.cc \
|
||||
bdStrmxorTests.cc \
|
||||
bdStrmrunTests.cc \
|
||||
buddies_main.cc \
|
||||
|
||||
INCLUDEPATH += $$BD_INC $$DB_INC $$TL_INC $$GSI_INC $$RBA_INC
|
||||
DEPENDPATH += $$BD_INC $$DB_INC $$TL_INC $$GSI_INC $$RBA_INC
|
||||
|
||||
INCLUDEPATH += $$BD_INC $$DB_INC $$TL_INC $$GSI_INC
|
||||
DEPENDPATH += $$BD_INC $$DB_INC $$TL_INC $$GSI_INC
|
||||
|
||||
LIBS += -L$$DESTDIR_UT -lklayout_bd -lklayout_db -lklayout_tl -lklayout_gsi
|
||||
LIBS += -L$$DESTDIR_UT -lklayout_bd -lklayout_db -lklayout_tl -lklayout_gsi -lklayout_rba
|
||||
|
|
|
|||
|
|
@ -0,0 +1,142 @@
|
|||
# encoding: UTF-8
|
||||
|
||||
# KLayout Layout Viewer
|
||||
# Copyright (C) 2006-2019 Matthias Koefferlein
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
if !$:.member?(File::dirname($0))
|
||||
$:.push(File::dirname($0))
|
||||
end
|
||||
|
||||
load("test_prologue.rb")
|
||||
|
||||
# Tests for the buddy executables
|
||||
#
|
||||
# This tests actually runs inside a KLayout/unit_tests instance but
|
||||
# only for providing the test automation.
|
||||
|
||||
class Buddies_TestClass < TestBase
|
||||
|
||||
def buddy_bin(name)
|
||||
file = File.join(RBA::Application::instance.inst_path, name)
|
||||
return file
|
||||
end
|
||||
|
||||
def test_basic
|
||||
|
||||
# Basic - buddies can be called
|
||||
%w(strm2cif strm2dxf strm2gds strm2gdstxt strm2oas strm2txt strmclip strmcmp strmrun strmxor).each do |bin|
|
||||
version = bin + " " + `#{self.buddy_bin(bin)} --version`
|
||||
assert_equal(version =~ /^#{bin} \d+\./, 0)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def test_converters
|
||||
|
||||
%w(strm2cif strm2dxf strm2gds strm2gdstxt strm2oas strm2txt).each do |bin|
|
||||
|
||||
puts "Testing #{bin} ..."
|
||||
|
||||
out_file = File.join($ut_testtmp, "out")
|
||||
if File.exists?(out_file)
|
||||
File.unlink(out_file)
|
||||
end
|
||||
assert_equal(File.exists?(out_file), false)
|
||||
|
||||
in_file = File.join(File.dirname(__FILE__), "test1.gds")
|
||||
|
||||
log = bin + "\n" + `#{self.buddy_bin(bin)} #{in_file} #{out_file} 2>&1`
|
||||
assert_equal(File.exists?(out_file), true)
|
||||
assert_equal(log, bin + "\n")
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def test_strmxor
|
||||
|
||||
out_file = File.join($ut_testtmp, "out")
|
||||
if File.exists?(out_file)
|
||||
File.unlink(out_file)
|
||||
end
|
||||
assert_equal(File.exists?(out_file), false)
|
||||
|
||||
in_file1 = File.join(File.dirname(__FILE__), "test1.gds")
|
||||
in_file2 = File.join(File.dirname(__FILE__), "test2.gds")
|
||||
|
||||
log = "strmxor\n" + `#{self.buddy_bin("strmxor")} #{in_file1} #{in_file2} #{out_file} 2>&1`
|
||||
assert_equal(File.exists?(out_file), true)
|
||||
assert_equal(log, <<"END")
|
||||
strmxor
|
||||
Warning: Layer 1/0 is not present in second layout, but in first
|
||||
Warning: Layer 2/0 is not present in first layout, but in second
|
||||
Result summary (layers without differences are not shown):
|
||||
|
||||
Layer Output Differences (shape count)
|
||||
-------------------------------------------------------
|
||||
1/0 - (no such layer in second layout)
|
||||
2/0 - (no such layer in first layout)
|
||||
|
||||
END
|
||||
|
||||
end
|
||||
|
||||
def test_strmcmp
|
||||
|
||||
in_file1 = File.join(File.dirname(__FILE__), "test1.gds")
|
||||
in_file2 = File.join(File.dirname(__FILE__), "test2.gds")
|
||||
|
||||
log = "strmcmp\n" + `#{self.buddy_bin("strmcmp")} #{in_file1} #{in_file2} 2>&1`
|
||||
assert_equal(log, <<"END")
|
||||
strmcmp
|
||||
ERROR: Layer 1/0 is not present in layout b, but in a
|
||||
ERROR: Layer 2/0 is not present in layout a, but in b
|
||||
ERROR: Cell TOP1 is not present in layout b, but in a
|
||||
ERROR: Cell TOP2 is not present in layout a, but in b
|
||||
ERROR: Layouts differ
|
||||
END
|
||||
|
||||
end
|
||||
|
||||
def test_strmclip
|
||||
|
||||
out_file = File.join($ut_testtmp, "out")
|
||||
if File.exists?(out_file)
|
||||
File.unlink(out_file)
|
||||
end
|
||||
assert_equal(File.exists?(out_file), false)
|
||||
|
||||
in_file = File.join(File.dirname(__FILE__), "test1.gds")
|
||||
|
||||
log = "strmclip\n" + `#{self.buddy_bin("strmclip")} #{in_file} #{out_file} 2>&1`
|
||||
assert_equal(File.exists?(out_file), true)
|
||||
assert_equal(log, "strmclip\n")
|
||||
|
||||
end
|
||||
|
||||
def test_strmrun
|
||||
|
||||
in_file = File.join(File.dirname(__FILE__), "test2.rb")
|
||||
|
||||
log = "strmrun\n" + `#{self.buddy_bin("strmrun")} #{in_file} 2>&1`
|
||||
assert_equal(log, "strmrun\ntest2\n")
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
load("test_epilogue.rb")
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
puts "test2"
|
||||
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
|
||||
# In the test environment, we cannot make sure that we destroy the ruby interpreter before the RBA
|
||||
# environment is shut down. Therefore we must release all RBA objects by explicitly calling the GC
|
||||
# and start the test suite manually.
|
||||
|
||||
err = 0
|
||||
any = nil
|
||||
repeat = (ENV["TESTREPEAT"] || "1").to_i
|
||||
|
||||
class MyTestRunner < Test::Unit::UI::Console::TestRunner
|
||||
def initialize(suite, *args)
|
||||
super(suite, *args)
|
||||
end
|
||||
def test_started(name)
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
Object.constants.each do |c|
|
||||
if c.to_s =~ /_TestClass$/
|
||||
repeat.times do
|
||||
r = MyTestRunner::new(Object.const_get(c)).start
|
||||
err += r.error_count + r.failure_count
|
||||
end
|
||||
any = true
|
||||
end
|
||||
end
|
||||
|
||||
if !any
|
||||
raise("No test class defined (any ending with _TestClass)")
|
||||
end
|
||||
|
||||
if err > 0
|
||||
raise("Tests failed (#{err} Errors + Failures)")
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
# in MSVC environment:
|
||||
if ENV["RUBY"]
|
||||
ruby_libs = "#{ENV["RUBY"]}/lib/ruby/#{RUBY_VERSION}"
|
||||
if !$:.member?(ruby_libs)
|
||||
$:.push(ruby_libs)
|
||||
end
|
||||
end
|
||||
|
||||
# Set this to true to disable some tests involving exceptions
|
||||
$leak_check = ENV["TEST_LEAK_CHECK"]
|
||||
|
||||
# Fetch location of source files and the temp files
|
||||
$ut_testsrc = ENV["TESTSRC"] || raise("Environment variable $TESTSRC not set")
|
||||
$ut_testtmp = ENV["TESTTMP_WITH_NAME"] || ENV["TESTTMP"] || raise("Environment variable $TESTTMP not set")
|
||||
|
||||
# Pull packages from vendor drop-in
|
||||
vendor = File.join($ut_testsrc, "testdata", "vendor", "ruby")
|
||||
if !$:.member?(vendor)
|
||||
$:.unshift(vendor)
|
||||
end
|
||||
|
||||
# Require Test::Unit
|
||||
require 'test/unit/ui/console/testrunner'
|
||||
|
||||
# TestBase is an alias for "TestCase"
|
||||
Object.const_defined?(:TestBase) && Object.send(:remove_const, :TestBase)
|
||||
TestBase = Test::Unit::TestCase
|
||||
|
||||
# undefine existing classes
|
||||
|
||||
Object.constants.each do |c|
|
||||
if c.to_s =~ /_TestClass$/
|
||||
Object.send(:remove_const, c)
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue