|
| 1 | +#!/bin/env python3 |
| 2 | +# crun - OCI runtime written in C |
| 3 | +# |
| 4 | +# Copyright (C) 2017, 2018, 2019 Giuseppe Scrivano <giuseppe@scrivano.org> |
| 5 | +# crun is free software; you can redistribute it and/or modify |
| 6 | +# it under the terms of the GNU General Public License as published by |
| 7 | +# the Free Software Foundation; either version 2 of the License, or |
| 8 | +# (at your option) any later version. |
| 9 | +# |
| 10 | +# crun is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU General Public License |
| 16 | +# along with crun. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +import subprocess |
| 19 | +import sys |
| 20 | +import json |
| 21 | +import os |
| 22 | +from tests_utils import * |
| 23 | + |
| 24 | +def check_mempolicy_prerequisites(): |
| 25 | + """Check all prerequisites for numa mempolicy tests. Returns 77 (skip) if not met, 0 if OK""" |
| 26 | + # TODO: stub entry for now. |
| 27 | + # there is no numa python bindings packaged for most distros. |
| 28 | + # the only way would be to call numactl shell and parse the output. |
| 29 | + return 0 |
| 30 | + |
| 31 | +def test_mempolicy(): |
| 32 | + """Test numa mempolicy""" |
| 33 | + ret = check_mempolicy_prerequisites() |
| 34 | + if ret != 0: |
| 35 | + return ret |
| 36 | + |
| 37 | + conf = base_config() |
| 38 | + conf['process']['args'] = ['/init', 'pause'] |
| 39 | + add_all_namespaces(conf) |
| 40 | + conf['linux']['memoryPolicy'] = {} |
| 41 | + |
| 42 | + cid = None |
| 43 | + try: |
| 44 | + _, cid = run_and_get_output(conf, command='run', detach=True) |
| 45 | + out = run_crun_command(["exec", cid, "/init", "cat", "/proc/self/numa_maps"]) |
| 46 | + print(out) |
| 47 | + except Exception as e: |
| 48 | + sys.stderr.write("# Test failed with exception: %s\n" % str(e)) |
| 49 | + return -1 |
| 50 | + finally: |
| 51 | + if cid is not None: |
| 52 | + run_crun_command(["delete", "-f", cid]) |
| 53 | + |
| 54 | + return 0 |
| 55 | + |
| 56 | +all_tests = { |
| 57 | + "mempolicy": test_mempolicy, |
| 58 | +} |
| 59 | + |
| 60 | +if __name__ == "__main__": |
| 61 | + tests_main(all_tests) |
0 commit comments