summaryrefslogtreecommitdiffstats
path: root/tests/integration/deckard/contrib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/integration/deckard/contrib/__init__.py0
-rw-r--r--tests/integration/deckard/contrib/deckard.vim26
-rw-r--r--tests/integration/deckard/contrib/licenses/ISC15
-rw-r--r--tests/integration/deckard/contrib/namespaces.py125
-rw-r--r--tests/integration/deckard/contrib/namespaces.spdx10
5 files changed, 176 insertions, 0 deletions
diff --git a/tests/integration/deckard/contrib/__init__.py b/tests/integration/deckard/contrib/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/integration/deckard/contrib/__init__.py
diff --git a/tests/integration/deckard/contrib/deckard.vim b/tests/integration/deckard/contrib/deckard.vim
new file mode 100644
index 0000000..3ae687a
--- /dev/null
+++ b/tests/integration/deckard/contrib/deckard.vim
@@ -0,0 +1,26 @@
+" Deckard syntax highlighting & folding
+"
+" Usage: Put following lines into ~/.vim/ftdetect/deckard.vim
+" au BufRead,BufNewFile *.rpl set filetype=deckard
+" au BufRead,BufNewFile *.stc set foldmethod=syntax
+
+syntax keyword Keyword MATCH STEP ADJUST MANDATORY RAW
+syntax keyword Structure CONFIG_END
+syntax keyword Function CHECK_ANSWER QUERY TIME_PASSES
+
+syntax region deckardEntry matchgroup=Structure start="ENTRY_BEGIN" end="ENTRY_END" fold transparent
+syntax region deckardRange matchgroup=Structure start="RANGE_BEGIN" end="RANGE_END" fold transparent
+syntax region deckardScenario matchgroup=Structure start="SCENARIO_BEGIN" end="SCENARIO_END" fold transparent
+
+syntax match deckardSection 'SECTION \+[^ ]\+'
+syntax match deckardReply 'REPLY.*'
+
+syntax match Comment ';.*$'
+
+hi def link deckardEntry Folded
+hi def link deckardRange Folded
+hi def link deckardScenario Folded
+hi def link deckardSection Special
+hi def link deckardReply String
+
+let b:current_syntax = 'deckard'
diff --git a/tests/integration/deckard/contrib/licenses/ISC b/tests/integration/deckard/contrib/licenses/ISC
new file mode 100644
index 0000000..e813ff3
--- /dev/null
+++ b/tests/integration/deckard/contrib/licenses/ISC
@@ -0,0 +1,15 @@
+SPDX-License-Identifier: ISC
+SPDX-URL: https://spdx.org/licenses/ISC.html
+License-Text:
+
+Permission to use, copy, modify, and/or distribute this software for any purpose
+with or without fee is hereby granted, provided that the above copyright notice
+and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
+INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
diff --git a/tests/integration/deckard/contrib/namespaces.py b/tests/integration/deckard/contrib/namespaces.py
new file mode 100644
index 0000000..16c2285
--- /dev/null
+++ b/tests/integration/deckard/contrib/namespaces.py
@@ -0,0 +1,125 @@
+# SPDX-License-Identifier: ISC
+# Source: https://vincentbernat.github.io/lldpd/
+# Copyright (c) 2008-2017, Vincent Bernat <vincent@bernat.im>
+
+import contextlib
+import ctypes
+import errno
+import os
+import signal
+
+# All allowed namespace types
+NAMESPACE_FLAGS = dict(mnt=0x00020000,
+ uts=0x04000000,
+ ipc=0x08000000,
+ user=0x10000000,
+ pid=0x20000000,
+ net=0x40000000)
+STACKSIZE = 1024*1024
+
+libc = ctypes.CDLL('libc.so.6', use_errno=True)
+
+
+@contextlib.contextmanager
+def keep_directory():
+ """Restore the current directory on exit."""
+ pwd = os.getcwd()
+ try:
+ yield
+ finally:
+ os.chdir(pwd)
+
+
+class LinuxNamespace:
+ """Combine several namespaces into one.
+ This gets a list of namespace types to create and combine into one. The
+ combined namespace can be used as a context manager to enter all the
+ created namespaces and exit them at the end.
+ """
+
+ def __init__(self, *namespaces):
+ self.namespaces = namespaces
+ for ns in namespaces:
+ assert ns in NAMESPACE_FLAGS
+
+ # Get a pipe to signal the future child to exit
+ self.pipe = os.pipe()
+
+ # First, create a child in the given namespaces
+ child = ctypes.CFUNCTYPE(ctypes.c_int)(self.child)
+ child_stack = ctypes.create_string_buffer(STACKSIZE)
+ child_stack_pointer = ctypes.c_void_p(
+ ctypes.cast(child_stack,
+ ctypes.c_void_p).value + STACKSIZE)
+ flags = signal.SIGCHLD
+ for ns in namespaces:
+ flags |= NAMESPACE_FLAGS[ns]
+ pid = libc.clone(child, child_stack_pointer, flags)
+ if pid == -1:
+ e = ctypes.get_errno()
+ raise OSError(e, os.strerror(e))
+
+ # If a user namespace, map UID 0 to the current one
+ if 'user' in namespaces:
+ uid_map = '0 {} 1'.format(os.getuid())
+ gid_map = '0 {} 1'.format(os.getgid())
+ with open('/proc/{}/uid_map'.format(pid), 'w') as f:
+ f.write(uid_map)
+ with open('/proc/{}/setgroups'.format(pid), 'w') as f:
+ f.write('deny')
+ with open('/proc/{}/gid_map'.format(pid), 'w') as f:
+ f.write(gid_map)
+
+ # Retrieve a file descriptor to this new namespace
+ self.next = [os.open('/proc/{}/ns/{}'.format(pid, x),
+ os.O_RDONLY) for x in namespaces]
+
+ # Keep a file descriptor to our old namespaces
+ self.previous = [os.open('/proc/self/ns/{}'.format(x),
+ os.O_RDONLY) for x in namespaces]
+
+ # Tell the child all is done and let it die
+ os.close(self.pipe[0])
+ if 'pid' not in namespaces:
+ os.close(self.pipe[1])
+ self.pipe = None
+ os.waitpid(pid, 0)
+
+ def __del__(self):
+ pass
+
+ def child(self):
+ """Cloned child.
+ Just be here until our parent extract the file descriptor from
+ us.
+ """
+ os.close(self.pipe[1])
+
+ while True:
+ try:
+ os.read(self.pipe[0], 1)
+ except OSError as e:
+ if e.errno in [errno.EAGAIN, errno.EINTR]:
+ continue
+ break
+
+ os._exit(0) # Adopted code. pylint: disable=protected-access
+
+ def fd(self, namespace):
+ """Return the file descriptor associated to a namespace"""
+ assert namespace in self.namespaces
+ return self.next[self.namespaces.index(namespace)]
+
+ def __enter__(self):
+ with keep_directory():
+ for n in self.next:
+ if libc.setns(n, 0) == -1:
+ ns = self.namespaces[self.next.index(n)] # noqa Adopted code. pylint: disable=unused-variable
+ e = ctypes.get_errno()
+ raise OSError(e, os.strerror(e))
+
+ def __exit__(self, *exc):
+ pass
+
+ def __repr__(self):
+ return 'Namespace({})'.format(", ".join(self.namespaces))
diff --git a/tests/integration/deckard/contrib/namespaces.spdx b/tests/integration/deckard/contrib/namespaces.spdx
new file mode 100644
index 0000000..4eea4e8
--- /dev/null
+++ b/tests/integration/deckard/contrib/namespaces.spdx
@@ -0,0 +1,10 @@
+SPDXVersion: SPDX-2.1
+DataLicense: CC0-1.0
+SPDXID: SPDXRef-DOCUMENT
+DocumentName: lldpd-namespaces
+DocumentNamespace: http://spdx.org/spdxdocs/spdx-v2.1-ab80d102-398e-43c0-b978-7a9559f5a76b
+
+PackageName: lldpd-namespaces
+PackageDownloadLocation: git+https://github.com/vincentbernat/lldpd.git@987454994be604a3b8c27e58d68ff7d88fcf24de#tests/integration/fixtures/namespaces.py
+PackageOriginator: Person: Vincent Bernat (vincent@bernat.im)
+PackageLicenseDeclared: ISC