Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ jobs:
- name: Compile Xmipp will all dependencies in branch ${{ github.head_ref }} (if such branch exists, default is devel)
env:
BRANCH_NAME: ${{ github.head_ref }}
SEND_INSTALLATION_STATISTICS: OFF
run: |
echo "XMIPP_LINK_TO_SCIPION=OFF" > xmipp.conf
echo -e "XMIPP_LINK_TO_SCIPION=OFF\nSEND_INSTALLATION_STATISTICS=OFF" > xmipp.conf
./xmipp all -b $BRANCH_NAME --keep-output || (cat compilation.log && false)
1 change: 1 addition & 0 deletions cmake/xmipp.bashrc.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export LD_LIBRARY_PATH=@XMIPP_HOME@/@CMAKE_INSTALL_LIBDIR@:@XMIPP_HOME@/bindings
export PYTHONPATH=@XMIPP_HOME@/bindings/python:@XMIPP_HOME@/pylib:$PYTHONPATH
export MATLABPATH=@XMIPP_HOME@/bindings/matlab:$MATLABPATH
export XMIPP_SRC=@PROJECT_SOURCE_DIR@/src
export XMIPP_TEST_DATA=@PROJECT_SOURCE_DIR@/src/xmipp/tests/data

alias x='xmipp'
alias xsj='xmipp_showj'
Expand Down
5 changes: 4 additions & 1 deletion installer/constants/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
CMAKE_COMPILE_ERROR = 5
CMAKE_INSTALL_ERROR = 6
IO_ERROR = 7
ENVIROMENT_ERROR = 8

# Error messages
__CHECK_LOG_MESSAGE = f'Check the inside file \'{LOG_FILE}\'.'
Expand All @@ -49,5 +50,7 @@
CMAKE_CONFIGURE_ERROR: ['Error configuring with CMake.', __CHECK_LOG_MESSAGE],
CMAKE_COMPILE_ERROR: ['Error compiling with CMake.', __CHECK_LOG_MESSAGE],
CMAKE_INSTALL_ERROR: ['Error installing with CMake.', __CHECK_LOG_MESSAGE],
IO_ERROR: ['Input/output error.', 'This error can be caused by the installer not being able to read/write/create/delete a file. Check your permissions on this directory.']
IO_ERROR: ['Input/output error.', 'This error can be caused by the installer not being able to read/write/create/delete a file. Check your permissions on this directory.'],
ENVIROMENT_ERROR: ['XMIPP_SRC is not in the enviroment. To run the tests you need to run: source dist/xmipp.bashrc', '']

}
18 changes: 16 additions & 2 deletions installer/constants/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,15 @@
PARAM_MODELS_DIRECTORY = 'models-directory'
PARAM_TEST_NAME = 'test-name'
PARAM_SHOW_TESTS = 'show-tests'
PARAM_TEST_PRO = 'allPrograms'
PARAM_TEST_FUNC = 'allFuncs'
PARAM_GIT_COMMAND = 'git-command'
PARAM_LOGIN = 'login'
PARAM_MODEL_PATH = 'model-path'
PARAM_UPDATE = 'update'
PARAM_OVERWRITE = 'overwrite'
PARAM_KEEP_OUTPUT = "keep-output"

PARAMS = {
PARAM_SHORT: {
LONG_VERSION: "--short",
Expand All @@ -131,6 +134,14 @@
SHORT_VERSION: "testName",
DESCRIPTION: "Run certain test. If combined with --show, greps the test name from the test list."
},
PARAM_TEST_PRO: {
LONG_VERSION: "--allPrograms",
DESCRIPTION: "If set, all test available will be run."
},
PARAM_TEST_FUNC: {
LONG_VERSION: "--allFuncs",
DESCRIPTION: "If set, all function test available will be run."
},
PARAM_SHOW_TESTS: {
LONG_VERSION: "--show",
DESCRIPTION: "Shows the tests available and how to invoke those."
Expand Down Expand Up @@ -173,7 +184,7 @@
MODE_GET_SOURCES: [PARAM_BRANCH, PARAM_KEEP_OUTPUT],
MODE_CLEAN_BIN: [],
MODE_CLEAN_ALL: [],
MODE_TEST: [PARAM_TEST_NAME, PARAM_SHOW_TESTS],
MODE_TEST: [PARAM_TEST_NAME, PARAM_SHOW_TESTS, PARAM_TEST_FUNC, PARAM_TEST_PRO],
MODE_GIT: [PARAM_GIT_COMMAND],
MODE_ADD_MODEL: [PARAM_LOGIN, PARAM_MODEL_PATH, PARAM_UPDATE]
}
Expand Down Expand Up @@ -215,7 +226,10 @@
MODE_CLEAN_ALL: [],
MODE_TEST: [
f'./xmipp {MODE_TEST} xmipp_sample_test',
f'./xmipp {MODE_TEST} {PARAMS[PARAM_SHORT][LONG_VERSION]}',
f'./xmipp {MODE_TEST} {PARAMS[PARAM_SHOW_TESTS][LONG_VERSION]}',
f'./xmipp {MODE_TEST} {PARAMS[PARAM_TEST_FUNC][LONG_VERSION]}',
f'./xmipp {MODE_TEST} {PARAMS[PARAM_TEST_PRO][LONG_VERSION]}',

],
MODE_GIT: [
f'./xmipp {MODE_GIT} pull',
Expand Down
85 changes: 85 additions & 0 deletions installer/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# ***************************************************************************
# * Authors: Alberto Garcia ([email protected])
# *
# *
# * 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., 59 Temple Place, Suite 330, Boston, MA
# * 02111-1307 USA
# *
# * All comments concerning this program package may be sent to the
# * e-mail address '[email protected]'
# ***************************************************************************/
"""
This module contains the necessary functions to run and manage the test.
"""

# General imports
from os import environ, path

# Self imports
from .constants import XMIPP, SCIPION_TESTS_URLS, CONFIG_FILE, XMIPP_USE_CUDA, XMIPP_LINK_TO_SCIPION, ENVIROMENT_ERROR
from .logger import blue, red, logger
from .utils import runJob, runStreamingJob
from .config import readConfig
from .main import handleRetCode

####################### COMMAND FUNCTIONS #######################


def runTests(testNames):
"""
### This function fetches the sources needed for Xmipp to compile.

#### Params:
- branch (str): Optional. Branch to clone the sources from.
"""
xmippSrc = environ.get('XMIPP_SRC', None)
if xmippSrc and path.isdir(xmippSrc):
environ['PYTHONPATH'] = ':'.join([
path.join(environ['XMIPP_SRC'], XMIPP),
environ.get('PYTHONPATH', '')])
testsPath = path.join(environ['XMIPP_SRC'], XMIPP, 'tests')
dataSetPath = path.join(testsPath, 'data')

else:
handleRetCode(ENVIROMENT_ERROR, predefinedErrorCode=ENVIROMENT_ERROR, sendAPI=False)

# downloading/updating the dataset
dataset = 'xmipp_programs'
if path.isdir(dataSetPath):
logger(blue("Updating the test files"))
task = "update"
showO = False
else:
logger(blue("Downloading the test files"))
task = "download"
showO = True
args = "%s %s %s" % ("tests/data", SCIPION_TESTS_URLS, dataset)
runJob("bin/xmipp_sync_data %s %s" % (task, args), cwd='src/xmipp', showOutput=showO)

configDict = readConfig(CONFIG_FILE) if path.exists(CONFIG_FILE) else {}
CUDA = configDict.get(XMIPP_USE_CUDA)
noCudaStr = '--noCuda' if CUDA == 'OFF' else ''

logger(" Tests to do: %s" % ', '.join(testNames))

# if configDict.get(XMIPP_LINK_TO_SCIPION) == 'ON':
# pythonExe = 'scipion3 python'
# else:
# pythonExe = 'python3'

pythonExe = 'python3' #TODO should be scipion3?
testScripts = path.dirname(environ['XMIPP_TEST_DATA'])
runStreamingJob(cmd="%s test.py %s %s" % (pythonExe, testNames, noCudaStr), cwd=testScripts, showOutput=True, showError=True)

62 changes: 25 additions & 37 deletions src/xmipp/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@
import shutil
from traceback import format_exception

VAHID = "vahid"
RM = 'rmarabini'
COSS = 'coss'
JMRT = 'delarosatrevin'
JOTON = 'joton'
DISCONTINUED = 'nobody'
JMOTA = 'javimota'
EFG = 'estrellafg'


class Command(object):
Expand Down Expand Up @@ -75,7 +67,7 @@ class ProgramTest(unittest.TestCase):
_timeout = 300

# _labels = [WEEKLY]

@classmethod
def setTestDir(cls, newTestDir):
cls._testDir = newTestDir
Expand All @@ -93,12 +85,12 @@ def _parseArgs(self, args):
args = args.replace("%o", self.outputDir)
args = args.replace("%p", self.program)
#args = args.replace("%d", self.fnDir)
return args
return args

def _runCommands(self, cmdList, cmdType):
""" Run several commands.
Params:
cmdList: the list of commands to execute.
cmdList: the list of commands to execute.
cmdType: either 'preruns' or 'postruns'
"""
pipe = '>'
Expand All @@ -113,7 +105,7 @@ def _runCommands(self, cmdList, cmdType):
pipe = ">>"
sys.stdout.flush()

def runCase(self, args, mpi=0, changeDir=False,
def runCase(self, args, mpi=0, changeDir=False,
preruns=None, postruns=None, validate=None,
outputs=None, random=False, errorthreshold=0.001):
# Retrieve the correct case number from the test name id
Expand Down Expand Up @@ -222,18 +214,15 @@ def __init__(self):
unittest.TestResult.__init__(self)
self.startTimeAll = time.time()

def openXmlReport(self, classname, filename):
# self.xml = open(filename, 'w')
# self.xml.write('<testsuite name="%s">\n' % classname)
pass

def doReport(self):
secs = time.time() - self.startTimeAll
sys.stderr.write("%s run %d tests (%0.3f secs)\n" %
(green("[==========]"), self.numberTests, secs))
sys.stderr.flush()
if self.testFailed:
sys.stderr.write(red("[ FAILED ]") + " %d tests\n" % self.testFailed)
sys.stderr.write(green("[ PASSED ]") + " %d tests" % (self.numberTests - self.testFailed))
sys.stderr.write(green("[ PASSED ]") + " %d tests\n" % (self.numberTests - self.testFailed))
sys.stderr.flush()
sys.stdout.flush()
return -1 if self.testFailed else 0

Expand All @@ -246,6 +235,9 @@ def toc(self):
def startTest(self, test):
self.tic()
self.numberTests += 1
sys.stderr.write(
"%s %s\n" % (green('[ RUN ]'), self.getTestName(test)))
sys.stderr.flush()

def getTestName(self, test):
parts = str(test).split()
Expand All @@ -257,19 +249,20 @@ def getTestName(self, test):
def addSuccess(self, test):
secs = self.toc()
sys.stderr.write("%s %s (%0.3f secs)\n\n" % (green('[ RUN OK ]'), self.getTestName(test), secs))
sys.stderr.flush()

def reportError(self, test, err):
sys.stderr.write("\n%s" % ("".join(format_exception(*err))))
sys.stderr.write("%s %s\n\n" % (red('[ FAILED ]'),
self.getTestName(test)))
sys.stderr.write("%s %s\n\n" % (red('[ FAILED ]'), self.getTestName(test)))
sys.stderr.flush()
self.testFailed += 1

def addError(self, test, err):
self.reportError(test, err)

def addFailure(self, test, err):
self.reportError(test, err)

def green(text):
return "\033[92m "+text+"\033[0m"

Expand All @@ -287,7 +280,6 @@ def createDir(dirname, clean=False):
shutil.rmtree(dirname)
os.makedirs(dirname)


def visitTests(tests, grepStr=''):
""" Show the list of tests available """

Expand All @@ -309,7 +301,6 @@ def visitTests(tests, grepStr=''):
lastModule = None

grepPrint = '' if grepStr == '' else red(' (grep: %s)'%grepStr)

for t in testsFlat:
moduleName, className, testName = t.id().rsplit('.', 2)

Expand All @@ -330,30 +321,24 @@ def visitTests(tests, grepStr=''):


if __name__ == "__main__":

cudaTests = True
for i, arg in enumerate(sys.argv):
if arg == '--noCuda':
cudaTests = False
sys.argv.pop(i)

testNames = sys.argv[1:]

cudaExcludeStr = '| grep -v xmipp_test_cuda_' if not cudaTests else ''
cTests = subprocess.check_output('compgen -ac | grep xmipp_test_ %s' % cudaExcludeStr,
shell=True, executable='/bin/bash').decode('utf-8').splitlines()

tests = unittest.TestSuite()
if '--show' in testNames or '--allPrograms' in testNames:
# tests.addTests(unittest.defaultTestLoader.discover(os.environ.get("XMIPP_TEST_DATA")+'/..',
# pattern='test*.py'))#,top_level_dir=os.environ.get("XMIPP_TEST_DATA")+'/..'))
listDir = os.listdir(os.environ.get("XMIPP_TEST_DATA")+'/..')
for path in listDir:
if path.startswith('test_') and path.endswith('.py'):
tests.addTests(unittest.defaultTestLoader.loadTestsFromName('tests.' + path[:-3]))

testData = os.environ['XMIPP_TEST_DATA']
testScripts = os.path.dirname(testData)
tests.addTests(unittest.defaultTestLoader.discover(start_dir=testScripts, pattern='test*.py', top_level_dir=testScripts + '/..'))

if '--show' in testNames:
print(blue("\n > > You can run any of the following tests by:\n"))
print(blue("\n >> You can run any of the following tests by:\n"))
grepStr = '' if len(testNames)<2 else testNames[1]
visitTests(tests, grepStr)
print("\n - From applications/function_tests (to run all use --allFuncs):")
Expand All @@ -362,7 +347,8 @@ def visitTests(tests, grepStr=''):
elif '--allPrograms' in testNames:
result = GTestResult()
tests.run(result)
sys.exit(result.doReport())
result.doReport()
sys.exit(0)
elif '--allFuncs' in testNames:
xmippBinDir = os.path.join(os.environ.get("XMIPP_SRC"), 'xmipp', 'bin')
errors = []
Expand Down Expand Up @@ -400,4 +386,6 @@ def visitTests(tests, grepStr=''):

result = GTestResult()
tests.run(result)
sys.exit(result.doReport())
result.doReport()
sys.exit(0)

12 changes: 9 additions & 3 deletions src/xmipp/tests/test_programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@
# * All comments concerning this program package may be sent to the
# * e-mail address '[email protected]'
# ***************************************************************************/

VAHID = "vahid"
RM = 'rmarabini'
COSS = 'coss'
JMRT = 'delarosatrevin'
JOTON = 'joton'
DISCONTINUED = 'nobody'
JMOTA = 'javimota'
EFG = 'estrellafg'

# import math
import os

# import pyworkflow.utils as pwutils
# import xmipp3
# from pyworkflow.tests import DataSet
from tests.test import *

from tests.test import ProgramTest


class XmippProgramTest(ProgramTest):
Expand Down
Loading