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: 3 additions & 0 deletions modulemd/common/tests/test-dirty.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import sys
import git
import subprocess

script_dir = os.path.dirname(os.path.realpath(__file__))

Expand All @@ -29,6 +30,8 @@
if (repo.is_dirty()):
print("Autoformatter was not run before submitting. Please run "
"`ninja test`, amend the commit and resubmit this pull request.")
res = subprocess.run(['git', 'diff'], capture_output=True, text=True)
print(res.stdout, file=sys.stderr)
sys.exit(os.EX_USAGE)

sys.exit(os.EX_OK)
84 changes: 46 additions & 38 deletions modulemd/common/tests/test-valgrind.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
import tempfile
import xml.etree.ElementTree as ET

from multiprocessing import Pool, TimeoutError

if os.getenv('MMD_SKIP_VALGRIND'):
sys.exit(77)


failed = False

# Get the list of tests to run
Expand Down Expand Up @@ -49,9 +52,9 @@
continue
tests.append(test)


with tempfile.TemporaryDirectory(prefix="libmodulemd_valgrind_") as tmpdirname:
for test in tests:
# TODO: auto-detect the location of the suppression file
def exec_valgrind(test):
valgrind_command = "/usr/bin/valgrind " \
"--leak-check=full " \
"--suppressions=/usr/share/glib-2.0/valgrind/glib.supp " \
Expand All @@ -66,42 +69,47 @@
'--wrap=%s' % valgrind_command,
test])

if proc_result.returncode != 0:
print("Valgrind exited with an error on %s" % test,
file=sys.stderr)
failed = True
continue

# Process the XML for leaks
tree = ET.parse('%s/%s.xml' % (tmpdirname, test))
root = tree.getroot()

for root_child in root:
if (root_child.tag == "error"):
for error_child in root_child:
if error_child.tag == 'kind':
if error_child.text == 'Leak_DefinitelyLost':
print("Memory leak detected in %s" % test,
file=sys.stderr)
failed = True

elif error_child.text == 'InvalidFree':
print("Invalid free() detected in %s" % test,
file=sys.stderr)
failed = True

elif error_child.text == 'InvalidRead':
print("Invalid read detected in %s" % test,
file=sys.stderr)
failed = True

elif error_child.text == 'UninitCondition':
print("Uninitialized usage detected in %s" % test,
file=sys.stderr)
failed = True
if failed:
with open('%s/%s.xml' % (tmpdirname, test), 'r') as xml:
print(xml.read())
return proc_result.returncode, test

with Pool() as pool:
for returncode, test in pool.map(exec_valgrind, tests):
if returncode != 0:
print("Valgrind exited with an error on %s" % test,
file=sys.stderr)
failed = True
continue

# Process the XML for leaks
tree = ET.parse('%s/%s.xml' % (tmpdirname, test))
root = tree.getroot()

for root_child in root:
if (root_child.tag == "error"):
for error_child in root_child:
if error_child.tag == 'kind':
if error_child.text == 'Leak_DefinitelyLost':
print("Memory leak detected in %s" % test,
file=sys.stderr)
failed = True

elif error_child.text == 'InvalidFree':
print("Invalid free() detected in %s" % test,
file=sys.stderr)
failed = True

elif error_child.text == 'InvalidRead':
print("Invalid read detected in %s" % test,
file=sys.stderr)
failed = True

elif error_child.text == 'UninitCondition':
print(
"Uninitialized usage detected in %s" %
test, file=sys.stderr)
failed = True
if failed:
with open('%s/%s.xml' % (tmpdirname, test), 'r') as xml:
print(xml.read())


if failed:
Expand Down
1 change: 1 addition & 0 deletions modulemd/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ test_v2_python_scripts = files(
'v2/tests/ModulemdTests/defaultsv1.py',
'v2/tests/ModulemdTests/dependencies.py',
'v2/tests/ModulemdTests/merger.py',
'v2/tests/ModulemdTests/module.py',
'v2/tests/ModulemdTests/moduleindex.py',
'v2/tests/ModulemdTests/modulestream.py',
'v2/tests/ModulemdTests/profile.py',
Expand Down
4 changes: 2 additions & 2 deletions modulemd/v2/include/modulemd-2.0/modulemd-module.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ modulemd_module_get_stream_by_NSVC (ModulemdModule *self,
* @arch: (nullable): The processor architecture of the stream to retrieve. If
* NULL, the architecture is not included in the search.
*
* Returns: (transfer full) (element-type ModulemdModuleStream): The list of
* stream objects matching the requested parameters. This function cannot
* Returns: (transfer container) (element-type ModulemdModuleStream): The list
* of stream objects matching the requested parameters. This function cannot
* fail, but it may return a zero-length list if no matches were found. The
* returned streams will be in a predictable order, sorted first by stream
* name, then by version (highest to lowest), then by context and finally by
Expand Down
17 changes: 16 additions & 1 deletion modulemd/v2/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,22 @@ test ('dependencies_python2_release', python2,
env : py_test_release_env,
args : dependencies_python_script)

# -- Test Modulemd.Module (Python) -- #
module_python_script = files('tests/ModulemdTests/module.py')
test ('module_python3_debug', python3,
env : py_test_env,
args : module_python_script)
test ('module_python3_release', python3,
env : py_test_release_env,
args : module_python_script)

test ('module_python2_debug', python2,
env : py_test_env,
args : module_python_script)
test ('module_python2_release', python2,
env : py_test_release_env,
args : module_python_script)

# -- Test Modulemd.ModuleIndex (Python) -- #
moduleindex_python_script = files('tests/ModulemdTests/moduleindex.py')
test ('moduleindex_python3_debug', python3,
Expand All @@ -401,7 +417,6 @@ test ('moduleindex_python3_release', python3,
env : py_test_release_env,
args : moduleindex_python_script)

moduleindex_python_script = files('tests/ModulemdTests/moduleindex.py')
test ('moduleindex_python2_debug', python2,
env : py_test_env,
args : moduleindex_python_script)
Expand Down
46 changes: 46 additions & 0 deletions modulemd/v2/tests/ModulemdTests/module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/python3

# This file is part of libmodulemd
# Copyright (C) 2017-2018 Stephen Gallagher
#
# Fedora-License-Identifier: MIT
# SPDX-2.0-License-Identifier: MIT
# SPDX-3.0-License-Identifier: MIT
#
# This program is free software.
# For more information on the license, see COPYING.
# For more information on free software, see
# <https://www.gnu.org/philosophy/free-sw.en.html>.

from os import path
import sys
try:
import unittest
import gi
gi.require_version('Modulemd', '2.0')
from gi.repository import Modulemd
from gi.repository.Modulemd import ModuleIndex
from gi.repository import GLib
except ImportError:
# Return error 77 to skip this test on platforms without the necessary
# python modules
sys.exit(77)

from base import TestBase


class TestModule(TestBase):

def test_search_streams(self):
idx = Modulemd.ModuleIndex.new()
idx.update_from_file(path.join(self.source_root,
"modulemd/v2/tests/test_data/f29.yaml"),
True)
module = idx.get_module('nodejs')

self.assertEquals(len(module.search_streams('8', 0)), 1)
self.assertEquals(len(module.search_streams('10', 0)), 1)


if __name__ == '__main__':
unittest.main()