2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-22 09:58:01 +00:00
ovs/tests/ovsdb-macros.at

130 lines
4.4 KiB
Plaintext
Raw Permalink Normal View History

dnl OVSDB_INIT([$1])
dnl
dnl Creates an empty database named $1.
m4_define([OVSDB_INIT],
[AT_CHECK(
[ovsdb-tool create $1 $abs_top_srcdir/vswitchd/vswitch.ovsschema],
[0], [stdout], [ignore])
AT_CHECK(
[[ovsdb-tool transact $1 \
'["Open_vSwitch",
{"op": "insert",
"table": "Open_vSwitch",
"row": {}}]']],
[0], [ignore], [ignore])])
dnl OVSDB_SERVER_SHUTDOWN([ALLOWLIST])
dnl
dnl Gracefully stops ovsdb-server, checking log files for messages with
dnl severity WARN or higher and signaling an error if any is present.
dnl The optional ALLOWLIST may contain shell-quoted "sed" commands to
dnl delete any warnings that are actually expected, e.g.:
dnl
dnl OVSDB_SERVER_SHUTDOWN(["/expected error/d"])
m4_define([OVSDB_SERVER_SHUTDOWN],
[AT_CHECK([check_logs $1])
OVS_APP_EXIT_AND_WAIT_BY_TARGET([ovsdb-server], [ovsdb-server.pid])])
# OVSDB_CHECK_POSITIVE(TITLE, TEST-OVSDB-ARGS, OUTPUT, [KEYWORDS], [PREREQ])
#
# Runs "test-ovsdb TEST-OVSDB-ARGS" and checks that it exits with
# status 0 and prints OUTPUT on stdout.
#
# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
m4_define([OVSDB_CHECK_POSITIVE],
[AT_SETUP([ovsdb - $1])
AT_KEYWORDS([ovsdb positive $4])
AT_CHECK([test-ovsdb $2], [0], [$3
], [])
AT_CLEANUP])
ovsdb: Use table indexes if available for ovsdb_query(). Currently all OVSDB database queries except for UUID lookups all result in linear lookups over the entire table, even if an index is present. This patch modifies ovsdb_query() to attempt an index lookup first, if possible. If no matching indexes are present then a linear index is still conducted. To test this, I set up an ovsdb database with a variable number of rows and timed the average of how long ovsdb-client took to query a single row. The first two tests involved a linear scan that didn't match any rows, so there was no overhead associated with sending or encoding output. The post-patch linear scan was a worst case scenario where the table did have an appropriate index but the conditions made its usage impossible. The indexed lookup test was for a matching row, which did also include overhead associated with a match. The results are included in the table below. Rows | 100k | 200k | 300k | 400k | 500k -----------------------+------+------+------+------+----- Pre-patch linear scan | 9ms | 24ms | 37ms | 49ms | 61ms Post-patch linear scan | 9ms | 24ms | 38ms | 49ms | 61ms Indexed lookup | 3ms | 3ms | 3ms | 3ms | 3ms I also tested the performance of ovsdb_query() by wrapping it in a loop and measuring the time it took to perform 1000 linear scans on 1, 10, 100k, and 200k rows. This test showed that the new index checking code did not slow down worst case lookups to a statistically detectable degree. Reported-at: https://issues.redhat.com/browse/FDP-590 Signed-off-by: Mike Pattrick <mkp@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2024-06-19 08:54:53 -04:00
# OVSDB_CHECK_POSITIVE_IDX(TITLE, TEST-OVSDB-ARGS, OUTPUT, [KEYWORDS], [PREREQ], [INDEX])
#
# Runs "test-ovsdb TEST-OVSDB-ARGS" twice, with and without an index, and checks
# that it exits with status 0 and prints OUTPUT on stdout.
#
# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
m4_define([OVSDB_CHECK_POSITIVE_IDX],
[OVSDB_CHECK_POSITIVE($1, [$2], $3, $4, $5)
OVSDB_CHECK_POSITIVE([indexed $1], [m4_bpatsubst([$2], ["columns":], ["indexes": [$6], "columns":])], $3, $4, $5)])
# OVSDB_CHECK_POSITIVE_PY(TITLE, TEST-OVSDB-ARGS, OUTPUT, [KEYWORDS], [PREREQ],
# [PY-CHECK])
#
# Runs "test-ovsdb.py TEST-OVSDB-ARGS" and checks that it exits with
# status 0 and prints OUTPUT on stdout.
#
# PY-CHECK is expanded before the check. It can check for features of the
# Python implementation that are required for the test to pass.
#
# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
m4_define([OVSDB_CHECK_POSITIVE_PY],
[AT_SETUP([ovsdb - $1])
$6
AT_KEYWORDS([ovsdb positive Python $4])
AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py $2], [0], [$3
], [])
AT_CLEANUP])
# OVSDB_CHECK_POSITIVE_CPY(TITLE, TEST-OVSDB-ARGS, OUTPUT, [KEYWORDS],
# [PREREQ], [PY3-CHECK])
#
# Runs identical C and Python tests, as specified.
m4_define([OVSDB_CHECK_POSITIVE_CPY],
[OVSDB_CHECK_POSITIVE([$1 - C], [$2], [$3], [$4], [$5])
OVSDB_CHECK_POSITIVE_PY([$1 - Python3], [$2], [$3], [$4], [$5], [$7])])
# OVSDB_CHECK_NEGATIVE(TITLE, TEST-OVSDB-ARGS, OUTPUT, [KEYWORDS], [PREREQ])
#
# Runs "test-ovsdb TEST-OVSDB-ARGS" and checks that it exits with
# status 1 and that its output on stdout contains substring OUTPUT.
# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
m4_define([OVSDB_CHECK_NEGATIVE],
[AT_SETUP([ovsdb - $1])
AT_KEYWORDS([ovsdb negative $4])
AT_CHECK([test-ovsdb $2], [1], [], [stderr])
m4_assert(m4_len([$3]))
AT_CHECK(
[if grep -F -e "AS_ESCAPE([$3])" stderr
then
:
else
exit 99
fi],
[0], [ignore], [ignore])
AT_CLEANUP])
# OVSDB_CHECK_NEGATIVE_PY(TITLE, TEST-OVSDB-ARGS, OUTPUT, [KEYWORDS], [PREREQ])
#
# Runs "test-ovsdb TEST-OVSDB-ARGS" and checks that it exits with
# status 1 and that its output on stdout contains substring OUTPUT.
# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
m4_define([OVSDB_CHECK_NEGATIVE_PY],
[AT_SETUP([ovsdb - $1])
AT_KEYWORDS([ovsdb negative $4])
AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py $2], [1], [], [stderr])
m4_assert(m4_len([$3]))
AT_CHECK(
[if grep -F -e "AS_ESCAPE([$3])" stderr
then
:
else
exit 99
fi],
[0], [ignore], [ignore])
AT_CLEANUP])
# OVSDB_CHECK_NEGATIVE_CPY(TITLE, TEST-OVSDB-ARGS, OUTPUT, [KEYWORDS],
# [PREREQ])
#
# Runs identical C and Python tests, as specified.
m4_define([OVSDB_CHECK_NEGATIVE_CPY],
[OVSDB_CHECK_NEGATIVE([$1 - C], [$2], [$3], [$4], [$5])
OVSDB_CHECK_NEGATIVE_PY([$1 - Python3], [$2], [$3], [$4], [$5])])
OVS_START_SHELL_HELPERS
ovsdb_client_wait() {
ovsdb-client -vconsole:warn -vreconnect:err -vjsonrpc:err -vtimeval:off -vfile -vsyslog:off -vvlog:off wait "$@"
}
OVS_END_SHELL_HELPERS