From ca8a075f462b11c3da9d10658cd9f49a657b118a Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 2 Feb 2016 20:51:44 +0100 Subject: [PATCH 1/3] test/ctlmgr: use sys.executable, use default localhost binding --- artiq/test/ctlmgr.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/artiq/test/ctlmgr.py b/artiq/test/ctlmgr.py index 61db39f61..de205a677 100644 --- a/artiq/test/ctlmgr.py +++ b/artiq/test/ctlmgr.py @@ -1,4 +1,5 @@ import os +import sys import unittest import logging import asyncio @@ -55,12 +56,13 @@ class ControllerCase(unittest.TestCase): raise asyncio.TimeoutError def test_start_ping_stop_controller(self): + command = sys.executable + " -m " entry = { "type": "controller", "host": "::1", "port": 3253, - "command": "lda_controller -p {port} --bind {bind} " - "--no-localhost-bind --simulation", + "command": sys.executable + " -m artiq.frontend.lda_controller " + "-p {port} --simulation" } async def test(): await self.start("lda_sim", entry) From 9ca8b48bf9f7fb756b4fecc4e5087c801d836e3d Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 2 Feb 2016 21:52:33 +0100 Subject: [PATCH 2/3] assume 'import artiq' works before running tests --- .../{domination.py => test_domination.py} | 0 .../{analyzer.py => test_analyzer.py} | 0 .../coredevice/{cache.py => test_cache.py} | 0 .../{embedding.py => test_embedding.py} | 0 .../{portability.py => test_portability.py} | 0 .../test/coredevice/{rtio.py => test_rtio.py} | 0 artiq/test/harness.py | 35 ---------------- artiq/test/lit/lit.cfg | 42 +++++++++---------- .../{coefficients.py => test_coefficients.py} | 0 artiq/test/{ctlmgr.py => test_ctlmgr.py} | 0 artiq/test/{h5types.py => test_h5types.py} | 0 artiq/test/{language.py => test_language.py} | 0 artiq/test/{lda.py => test_lda.py} | 0 .../{novatech409b.py => test_novatech409b.py} | 0 artiq/test/{pc_rpc.py => test_pc_rpc.py} | 0 artiq/test/{pdq2.py => test_pdq2.py} | 0 artiq/test/{pipe_ipc.py => test_pipe_ipc.py} | 0 .../test/{scheduler.py => test_scheduler.py} | 0 ...serialization.py => test_serialization.py} | 0 .../{sync_struct.py => test_sync_struct.py} | 0 ...orlabs_tcube.py => test_thorlabs_tcube.py} | 0 .../test/{wavesynth.py => test_wavesynth.py} | 0 artiq/test/{worker.py => test_worker.py} | 0 doc/manual/faq.rst | 5 +++ setup.py | 1 - 25 files changed, 26 insertions(+), 57 deletions(-) rename artiq/test/compiler/{domination.py => test_domination.py} (100%) rename artiq/test/coredevice/{analyzer.py => test_analyzer.py} (100%) rename artiq/test/coredevice/{cache.py => test_cache.py} (100%) rename artiq/test/coredevice/{embedding.py => test_embedding.py} (100%) rename artiq/test/coredevice/{portability.py => test_portability.py} (100%) rename artiq/test/coredevice/{rtio.py => test_rtio.py} (100%) delete mode 100644 artiq/test/harness.py rename artiq/test/{coefficients.py => test_coefficients.py} (100%) rename artiq/test/{ctlmgr.py => test_ctlmgr.py} (100%) rename artiq/test/{h5types.py => test_h5types.py} (100%) rename artiq/test/{language.py => test_language.py} (100%) rename artiq/test/{lda.py => test_lda.py} (100%) rename artiq/test/{novatech409b.py => test_novatech409b.py} (100%) rename artiq/test/{pc_rpc.py => test_pc_rpc.py} (100%) rename artiq/test/{pdq2.py => test_pdq2.py} (100%) rename artiq/test/{pipe_ipc.py => test_pipe_ipc.py} (100%) rename artiq/test/{scheduler.py => test_scheduler.py} (100%) rename artiq/test/{serialization.py => test_serialization.py} (100%) rename artiq/test/{sync_struct.py => test_sync_struct.py} (100%) rename artiq/test/{thorlabs_tcube.py => test_thorlabs_tcube.py} (100%) rename artiq/test/{wavesynth.py => test_wavesynth.py} (100%) rename artiq/test/{worker.py => test_worker.py} (100%) diff --git a/artiq/test/compiler/domination.py b/artiq/test/compiler/test_domination.py similarity index 100% rename from artiq/test/compiler/domination.py rename to artiq/test/compiler/test_domination.py diff --git a/artiq/test/coredevice/analyzer.py b/artiq/test/coredevice/test_analyzer.py similarity index 100% rename from artiq/test/coredevice/analyzer.py rename to artiq/test/coredevice/test_analyzer.py diff --git a/artiq/test/coredevice/cache.py b/artiq/test/coredevice/test_cache.py similarity index 100% rename from artiq/test/coredevice/cache.py rename to artiq/test/coredevice/test_cache.py diff --git a/artiq/test/coredevice/embedding.py b/artiq/test/coredevice/test_embedding.py similarity index 100% rename from artiq/test/coredevice/embedding.py rename to artiq/test/coredevice/test_embedding.py diff --git a/artiq/test/coredevice/portability.py b/artiq/test/coredevice/test_portability.py similarity index 100% rename from artiq/test/coredevice/portability.py rename to artiq/test/coredevice/test_portability.py diff --git a/artiq/test/coredevice/rtio.py b/artiq/test/coredevice/test_rtio.py similarity index 100% rename from artiq/test/coredevice/rtio.py rename to artiq/test/coredevice/test_rtio.py diff --git a/artiq/test/harness.py b/artiq/test/harness.py deleted file mode 100644 index 9828dc462..000000000 --- a/artiq/test/harness.py +++ /dev/null @@ -1,35 +0,0 @@ -""" -The purpose of this harness is to emulate the behavior of -the python executable, but add the ARTIQ root to sys.path -beforehand. - -This is necessary because eggs override the PYTHONPATH environment -variable, but not current directory; therefore `python -m artiq...` -ran from the ARTIQ root would work, but there is no simple way to -emulate the same behavior when invoked under lit. -""" - -import sys, os, argparse, importlib - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("-m", metavar="mod", type=str, - help="run library module as a script") - parser.add_argument("args", type=str, nargs="+", - help="arguments passed to program in sys.argv[1:]") - args = parser.parse_args(sys.argv[1:]) - - artiq_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) - sys.path.insert(1, artiq_path) - - if args.m: - sys.argv[1:] = args.args - importlib.import_module(args.m).main() - else: - sys.argv[1:] = args.args[1:] - with open(args.args[0]) as f: - code = compile(f.read(), args.args[0], "exec") - exec(code, globals()) - -if __name__ == "__main__": - main() diff --git a/artiq/test/lit/lit.cfg b/artiq/test/lit/lit.cfg index 0a5cb2c74..b52a4c752 100644 --- a/artiq/test/lit/lit.cfg +++ b/artiq/test/lit/lit.cfg @@ -1,35 +1,35 @@ # -*- python -*- -import os, subprocess +import os +import sys +import subprocess import lit.util import lit.formats -root = os.path.join(os.path.dirname(__file__), '..') +root = os.path.join(os.path.dirname(__file__), "..") -config.name = 'ARTIQ' +config.name = "ARTIQ" config.test_format = lit.formats.ShTest() -config.suffixes = ['.py'] +config.suffixes = [".py"] -python_executable = 'python3.5' - -harness = os.path.join(root, 'harness.py') -if os.getenv('COVERAGE'): - harness = 'coverage run --parallel-mode --source=artiq {}'.format(harness) - config.environment['COVERAGE_FILE'] = os.path.join(root, '..', '.coverage') - config.substitutions.append( ('%python', harness) ) +if os.getenv("COVERAGE"): + config.environment["COVERAGE_FILE"] = os.path.join(root, "..", ".coverage") + python = "coverage run --parallel-mode --source=artiq" else: - harness = '{} {}'.format(python_executable, harness) - config.substitutions.append( ('%python', harness) ) + python = sys.executable +config.substitutions.append( ("%python", python) ) -not_ = '{} {}'.format(python_executable, os.path.join(root, 'not.py')) -config.substitutions.append( ('%not', not_) ) +config.environment["PYTHONPATH"] = os.getenv("PYTHONPATH") -if os.name == 'posix': - support_build = os.path.join(root, 'libartiq_support') - if subprocess.call(['make', '-sC', support_build]) != 0: +not_ = "{} {}".format(sys.executable, os.path.join(root, "not.py")) +config.substitutions.append( ("%not", not_) ) + +if os.name == "posix": + support_build = os.path.join(root, "libartiq_support") + if subprocess.call(["make", "-sC", support_build]) != 0: lit_config.fatal("Unable to build JIT support library") - support_lib = os.path.join(support_build, 'libartiq_support.so') - config.environment['LIBARTIQ_SUPPORT'] = support_lib + support_lib = os.path.join(support_build, "libartiq_support.so") + config.environment["LIBARTIQ_SUPPORT"] = support_lib - config.available_features.add('exceptions') + config.available_features.add("exceptions") diff --git a/artiq/test/coefficients.py b/artiq/test/test_coefficients.py similarity index 100% rename from artiq/test/coefficients.py rename to artiq/test/test_coefficients.py diff --git a/artiq/test/ctlmgr.py b/artiq/test/test_ctlmgr.py similarity index 100% rename from artiq/test/ctlmgr.py rename to artiq/test/test_ctlmgr.py diff --git a/artiq/test/h5types.py b/artiq/test/test_h5types.py similarity index 100% rename from artiq/test/h5types.py rename to artiq/test/test_h5types.py diff --git a/artiq/test/language.py b/artiq/test/test_language.py similarity index 100% rename from artiq/test/language.py rename to artiq/test/test_language.py diff --git a/artiq/test/lda.py b/artiq/test/test_lda.py similarity index 100% rename from artiq/test/lda.py rename to artiq/test/test_lda.py diff --git a/artiq/test/novatech409b.py b/artiq/test/test_novatech409b.py similarity index 100% rename from artiq/test/novatech409b.py rename to artiq/test/test_novatech409b.py diff --git a/artiq/test/pc_rpc.py b/artiq/test/test_pc_rpc.py similarity index 100% rename from artiq/test/pc_rpc.py rename to artiq/test/test_pc_rpc.py diff --git a/artiq/test/pdq2.py b/artiq/test/test_pdq2.py similarity index 100% rename from artiq/test/pdq2.py rename to artiq/test/test_pdq2.py diff --git a/artiq/test/pipe_ipc.py b/artiq/test/test_pipe_ipc.py similarity index 100% rename from artiq/test/pipe_ipc.py rename to artiq/test/test_pipe_ipc.py diff --git a/artiq/test/scheduler.py b/artiq/test/test_scheduler.py similarity index 100% rename from artiq/test/scheduler.py rename to artiq/test/test_scheduler.py diff --git a/artiq/test/serialization.py b/artiq/test/test_serialization.py similarity index 100% rename from artiq/test/serialization.py rename to artiq/test/test_serialization.py diff --git a/artiq/test/sync_struct.py b/artiq/test/test_sync_struct.py similarity index 100% rename from artiq/test/sync_struct.py rename to artiq/test/test_sync_struct.py diff --git a/artiq/test/thorlabs_tcube.py b/artiq/test/test_thorlabs_tcube.py similarity index 100% rename from artiq/test/thorlabs_tcube.py rename to artiq/test/test_thorlabs_tcube.py diff --git a/artiq/test/wavesynth.py b/artiq/test/test_wavesynth.py similarity index 100% rename from artiq/test/wavesynth.py rename to artiq/test/test_wavesynth.py diff --git a/artiq/test/worker.py b/artiq/test/test_worker.py similarity index 100% rename from artiq/test/worker.py rename to artiq/test/test_worker.py diff --git a/doc/manual/faq.rst b/doc/manual/faq.rst index 54ea2523b..4c40ffdea 100644 --- a/doc/manual/faq.rst +++ b/doc/manual/faq.rst @@ -86,3 +86,8 @@ URL: it allows to select the serial device by its USB vendor ID, product ID and/or serial number. Those never change, unlike the device file name. See the :ref:`TDC001 documentation ` for an example of ``hwgrep://`` usage. + +run unit tests? +--------------- + +The unit tests assume that the Python environment has been set up in such a way that ``import artiq`` will import the code being tested, and that this is still true for any subprocess created. This is not the way setuptools operates as it adds the path to ARTIQ to ``sys.path`` which is not passed to subprocesses; as a result, running the tests via ``setup.py`` is not supported. The user must first install the package or set ``PYTHONPATH``, and then run the tests with e.g. ``python3.5 -m unittest discover`` in the ``artiq/test`` folder and ``lit .`` in the ``artiq/test/lit`` folder. diff --git a/setup.py b/setup.py index 1f5c651bd..75cdc277f 100755 --- a/setup.py +++ b/setup.py @@ -57,7 +57,6 @@ setup( ], packages=find_packages(), namespace_packages=[], - test_suite="artiq.test", include_package_data=True, ext_modules=[], entry_points={ From 89f68f34706d0922f774c8495f8287de5f741942 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 2 Feb 2016 21:57:25 +0100 Subject: [PATCH 3/3] style --- artiq/compiler/testbench/jit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/artiq/compiler/testbench/jit.py b/artiq/compiler/testbench/jit.py index a6d5efcf1..9d35a5a93 100644 --- a/artiq/compiler/testbench/jit.py +++ b/artiq/compiler/testbench/jit.py @@ -5,7 +5,7 @@ from ..module import Module, Source from ..targets import NativeTarget def main(): - libartiq_support = os.getenv('LIBARTIQ_SUPPORT') + libartiq_support = os.getenv("LIBARTIQ_SUPPORT") if libartiq_support is not None: llvm.load_library_permanently(libartiq_support)