diff options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/image-fuzzer/runner.py | 50 | ||||
-rwxr-xr-x | tests/qemu-iotests/028 | 1 | ||||
-rw-r--r-- | tests/qemu-iotests/028.out | 3 | ||||
-rwxr-xr-x | tests/qemu-iotests/099 | 116 | ||||
-rw-r--r-- | tests/qemu-iotests/099.out | 20 | ||||
-rwxr-xr-x | tests/qemu-iotests/101 | 58 | ||||
-rw-r--r-- | tests/qemu-iotests/101.out | 10 | ||||
-rwxr-xr-x | tests/qemu-iotests/103 | 99 | ||||
-rw-r--r-- | tests/qemu-iotests/103.out | 29 | ||||
-rw-r--r-- | tests/qemu-iotests/common.filter | 22 | ||||
-rw-r--r-- | tests/qemu-iotests/common.rc | 19 | ||||
-rw-r--r-- | tests/qemu-iotests/group | 3 | ||||
-rw-r--r-- | tests/test-coroutine.c | 30 |
13 files changed, 433 insertions, 27 deletions
diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py index 58079d3..c903c8a 100755 --- a/tests/image-fuzzer/runner.py +++ b/tests/image-fuzzer/runner.py @@ -25,6 +25,7 @@ import subprocess import random import shutil from itertools import count +import time import getopt import StringIO import resource @@ -64,14 +65,35 @@ def run_app(fd, q_args): """Start an application with specified arguments and return its exit code or kill signal depending on the result of execution. """ + + class Alarm(Exception): + """Exception for signal.alarm events.""" + pass + + def handler(*arg): + """Notify that an alarm event occurred.""" + raise Alarm + + signal.signal(signal.SIGALRM, handler) + signal.alarm(600) + term_signal = signal.SIGKILL devnull = open('/dev/null', 'r+') process = subprocess.Popen(q_args, stdin=devnull, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = process.communicate() - fd.write(out) - fd.write(err) - return process.returncode + try: + out, err = process.communicate() + signal.alarm(0) + fd.write(out) + fd.write(err) + fd.flush() + return process.returncode + + except Alarm: + os.kill(process.pid, term_signal) + fd.write('The command was terminated by timeout.\n') + fd.flush() + return -term_signal class TestException(Exception): @@ -269,6 +291,7 @@ if __name__ == '__main__': Optional arguments: -h, --help display this help and exit + -d, --duration=NUMBER finish tests after NUMBER of seconds -c, --command=JSON run tests for all commands specified in the JSON array -s, --seed=STRING seed for a test image generation, @@ -325,10 +348,15 @@ if __name__ == '__main__': finally: test.finish() + def should_continue(duration, start_time): + """Return True if a new test can be started and False otherwise.""" + current_time = int(time.time()) + return (duration is None) or (current_time - start_time < duration) + try: - opts, args = getopt.gnu_getopt(sys.argv[1:], 'c:hs:kv', + opts, args = getopt.gnu_getopt(sys.argv[1:], 'c:hs:kvd:', ['command=', 'help', 'seed=', 'config=', - 'keep_passed', 'verbose']) + 'keep_passed', 'verbose', 'duration=']) except getopt.error, e: print >>sys.stderr, \ "Error: %s\n\nTry 'runner.py --help' for more information" % e @@ -339,6 +367,8 @@ if __name__ == '__main__': log_all = False seed = None config = None + duration = None + for opt, arg in opts: if opt in ('-h', '--help'): usage() @@ -357,6 +387,8 @@ if __name__ == '__main__': log_all = True elif opt in ('-s', '--seed'): seed = arg + elif opt in ('-d', '--duration'): + duration = int(arg) elif opt == '--config': try: config = json.loads(arg) @@ -394,9 +426,11 @@ if __name__ == '__main__': resource.setrlimit(resource.RLIMIT_CORE, (-1, -1)) # If a seed is specified, only one test will be executed. # Otherwise runner will terminate after a keyboard interruption - for test_id in count(1): + start_time = int(time.time()) + test_id = count(1) + while should_continue(duration, start_time): try: - run_test(str(test_id), seed, work_dir, run_log, cleanup, + run_test(str(test_id.next()), seed, work_dir, run_log, cleanup, log_all, command, config) except (KeyboardInterrupt, SystemExit): sys.exit(1) diff --git a/tests/qemu-iotests/028 b/tests/qemu-iotests/028 index 9e701e1..a1f4423 100755 --- a/tests/qemu-iotests/028 +++ b/tests/qemu-iotests/028 @@ -113,6 +113,7 @@ QEMU_COMM_TIMEOUT=1 # Silence output since it contains the disk image path and QEMU's readline # character echoing makes it very hard to filter the output _send_qemu_cmd $h "drive_backup disk ${TEST_IMG}.copy" "(qemu)" >/dev/null +_send_qemu_cmd $h "" "Formatting" | _filter_img_create qemu_cmd_repeat=20 _send_qemu_cmd $h "info block-jobs" "No active jobs" _send_qemu_cmd $h 'quit' "" diff --git a/tests/qemu-iotests/028.out b/tests/qemu-iotests/028.out index 0e1a5ae..e8d0245 100644 --- a/tests/qemu-iotests/028.out +++ b/tests/qemu-iotests/028.out @@ -468,7 +468,8 @@ No errors were found on the image. block-backup -Formatting 'TEST_DIR/t.qcow2.copy', fmt=qcow2 size=4294968832 backing_file='TEST_DIR/t.qcow2.base' backing_fmt='qcow2' encryption=off cluster_size=65536 lazy_refcounts=off +Formatting 'TEST_DIR/t.IMGFMT.copy', fmt=IMGFMT size=4294968832 backing_file='TEST_DIR/t.IMGFMT.base' backing_fmt='IMGFMT' +(qemu) (qemu) i[K[Din[K[D[Dinf[K[D[D[Dinfo[K[D[D[D[Dinfo [K[D[D[D[D[Dinfo b[K[D[D[D[D[D[Dinfo bl[K[D[D[D[D[D[D[Dinfo blo[K[D[D[D[D[D[D[D[Dinfo bloc[K[D[D[D[D[D[D[D[D[Dinfo block[K[D[D[D[D[D[D[D[D[D[Dinfo block-[K[D[D[D[D[D[D[D[D[D[D[Dinfo block-j[K[D[D[D[D[D[D[D[D[D[D[D[Dinfo block-jo[K[D[D[D[D[D[D[D[D[D[D[D[D[Dinfo block-job[K[D[D[D[D[D[D[D[D[D[D[D[D[D[Dinfo block-jobs[K Type backup, device disk: Completed 0 of 4294968832 bytes, speed limit 0 bytes/s i[K[Din[K[D[Dinf[K[D[D[Dinfo[K[D[D[D[Dinfo [K[D[D[D[D[Dinfo b[K[D[D[D[D[D[Dinfo bl[K[D[D[D[D[D[D[Dinfo blo[K[D[D[D[D[D[D[D[Dinfo bloc[K[D[D[D[D[D[D[D[D[Dinfo block[K[D[D[D[D[D[D[D[D[D[Dinfo block-[K[D[D[D[D[D[D[D[D[D[D[Dinfo block-j[K[D[D[D[D[D[D[D[D[D[D[D[Dinfo block-jo[K[D[D[D[D[D[D[D[D[D[D[D[D[Dinfo block-job[K[D[D[D[D[D[D[D[D[D[D[D[D[D[Dinfo block-jobs[K diff --git a/tests/qemu-iotests/099 b/tests/qemu-iotests/099 new file mode 100755 index 0000000..a26d3d2 --- /dev/null +++ b/tests/qemu-iotests/099 @@ -0,0 +1,116 @@ +#!/bin/bash +# +# Test valid filenames for blkdebug and blkverify representatively for +# other protocols (such as NBD) when queried +# +# Copyright (C) 2014 Red Hat, Inc. +# +# 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, see <http://www.gnu.org/licenses/>. +# + +# creator +owner=mreitz@redhat.com + +seq="$(basename $0)" +echo "QA output created by $seq" + +here="$PWD" +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +# Basically all formats, but "raw" has issues with _filter_imgfmt regarding the +# raw comparison image for blkverify; also, all images have to support creation +_supported_fmt cow qcow qcow2 qed vdi vhdx vmdk vpc +_supported_proto file +_supported_os Linux + + +function do_run_qemu() +{ + $QEMU -nographic -qmp stdio -serial none "$@" +} + +function run_qemu() +{ + # Get the "file": "foo" entry ($foo may only contain escaped double quotes, + # which is how we can extract it) + do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qmp \ + | grep "drv0" \ + | sed -e 's/^.*"file": "\(\(\\"\|[^"]\)*\)".*$/\1/' -e 's/\\"/"/g' +} + +function test_qemu() +{ + run_qemu -drive "if=none,id=drv0,$1" <<EOF + { 'execute': 'qmp_capabilities' } + { 'execute': 'query-block' } + { 'execute': 'quit' } +EOF +} + + + +IMG_SIZE=128K + +_make_test_img $IMG_SIZE +$QEMU_IMG create -f raw "$TEST_IMG.compare" $IMG_SIZE \ + | _filter_testdir | _filter_imgfmt + +echo +echo '=== Testing simple filename for blkverify ===' +echo + +# This should return simply the filename itself +test_qemu "file=blkverify:$TEST_IMG.compare:$TEST_IMG" + +echo +echo '=== Testing filename reconstruction for blkverify ===' +echo + +# This should return the same filename as above +test_qemu "file.driver=blkverify,file.raw.filename=$TEST_IMG.compare,file.test.file.filename=$TEST_IMG" + +echo +echo '=== Testing JSON filename for blkdebug ===' +echo + +# blkdebug cannot create a configuration file, therefore it is unable to +# generate a plain filename here; thus this should return a JSON filename +test_qemu "file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=l1_update" + +echo +echo '=== Testing indirectly enforced JSON filename ===' +echo + +# Because blkdebug cannot return a plain filename, blkverify is forced to +# generate a JSON object here as well +test_qemu "file.driver=blkverify,file.raw.filename=$TEST_IMG.compare,file.test.file.driver=blkdebug,file.test.file.image.filename=$TEST_IMG,file.test.file.inject-error.0.event=l1_update" + + +rm -f "$TEST_IMG.compare" + +# success, all done +echo "*** done" +rm -f $seq.full +status=0 diff --git a/tests/qemu-iotests/099.out b/tests/qemu-iotests/099.out new file mode 100644 index 0000000..55be4d4 --- /dev/null +++ b/tests/qemu-iotests/099.out @@ -0,0 +1,20 @@ +QA output created by 099 +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=131072 +Formatting 'TEST_DIR/t.IMGFMT.compare', fmt=raw size=131072 + +=== Testing simple filename for blkverify === + +blkverify:TEST_DIR/t.IMGFMT.compare:TEST_DIR/t.IMGFMT + +=== Testing filename reconstruction for blkverify === + +blkverify:TEST_DIR/t.IMGFMT.compare:TEST_DIR/t.IMGFMT + +=== Testing JSON filename for blkdebug === + +json:{"driver": "IMGFMT", "file": {"inject-error": [{"immediately": false, "once": false, "state": 0, "sector": -1, "event": "l1_update", "errno": 5}], "image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug"}} + +=== Testing indirectly enforced JSON filename === + +json:{"driver": "raw", "file": {"test": {"driver": "IMGFMT", "file": {"inject-error": [{"immediately": false, "once": false, "state": 0, "sector": -1, "event": "l1_update", "errno": 5}], "image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug"}}, "driver": "blkverify", "raw": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT.compare"}}} +*** done diff --git a/tests/qemu-iotests/101 b/tests/qemu-iotests/101 new file mode 100755 index 0000000..70fbf25 --- /dev/null +++ b/tests/qemu-iotests/101 @@ -0,0 +1,58 @@ +#!/bin/bash +# +# Test short file I/O +# +# Copyright (C) 2014 Red Hat, Inc. +# +# 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, see <http://www.gnu.org/licenses/>. +# + +# creator +owner=stefanha@redhat.com + +seq=`basename $0` +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt raw +_supported_proto file +_supported_os Linux + + +echo +echo "== creating short image file ==" +dd if=/dev/zero of="$TEST_IMG" bs=1 count=320 + +echo +echo "== reading bytes beyond EOF gives zeroes ==" +$QEMU_IO -c "read -P 0 0 512" "$TEST_IMG" | _filter_qemu_io + + +# success, all done +echo "*** done" +rm -f $seq.full +status=0 diff --git a/tests/qemu-iotests/101.out b/tests/qemu-iotests/101.out new file mode 100644 index 0000000..9a996e8 --- /dev/null +++ b/tests/qemu-iotests/101.out @@ -0,0 +1,10 @@ +QA output created by 101 + +== creating short image file == +320+0 records in +320+0 records out + +== reading bytes beyond EOF gives zeroes == +read 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +*** done diff --git a/tests/qemu-iotests/103 b/tests/qemu-iotests/103 new file mode 100755 index 0000000..0f1dc9f --- /dev/null +++ b/tests/qemu-iotests/103 @@ -0,0 +1,99 @@ +#!/bin/bash +# +# Test case for qcow2 metadata cache size specification +# +# Copyright (C) 2014 Red Hat, Inc. +# +# 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, see <http://www.gnu.org/licenses/>. +# + +# creator +owner=mreitz@redhat.com + +seq=$(basename $0) +echo "QA output created by $seq" + +here=$PWD +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +IMG_SIZE=64K + +_make_test_img $IMG_SIZE +$QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io + +echo +echo '=== Testing invalid option combinations ===' +echo + +# all sizes set at the same time +$QEMU_IO -c "open -o cache-size=1.25M,l2-cache-size=1M,refcount-cache-size=0.25M $TEST_IMG" \ + 2>&1 | _filter_testdir | _filter_imgfmt +# l2-cache-size may not exceed cache-size +$QEMU_IO -c "open -o cache-size=1M,l2-cache-size=2M $TEST_IMG" 2>&1 \ + | _filter_testdir | _filter_imgfmt +# refcount-cache-size may not exceed cache-size +$QEMU_IO -c "open -o cache-size=1M,refcount-cache-size=2M $TEST_IMG" 2>&1 \ + | _filter_testdir | _filter_imgfmt +# 0 should be a valid size (e.g. for enforcing the minimum), so this should not +# work +$QEMU_IO -c "open -o cache-size=0,l2-cache-size=0,refcount-cache-size=0 $TEST_IMG" \ + 2>&1 | _filter_testdir | _filter_imgfmt + +echo +echo '=== Testing valid option combinations ===' +echo + +# There should be a reasonable and working minimum +$QEMU_IO -c "open -o cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \ + | _filter_qemu_io +$QEMU_IO -c "open -o l2-cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \ + | _filter_qemu_io +$QEMU_IO -c "open -o refcount-cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \ + | _filter_qemu_io + +# Derive cache sizes from combined size (with a reasonable ratio, but we cannot +# test that) +$QEMU_IO -c "open -o cache-size=2M $TEST_IMG" -c 'read -P 42 0 64k' \ + | _filter_qemu_io +# Fix one cache, derive the other +$QEMU_IO -c "open -o cache-size=2M,l2-cache-size=1M $TEST_IMG" \ + -c 'read -P 42 0 64k' \ + | _filter_qemu_io +$QEMU_IO -c "open -o cache-size=2M,refcount-cache-size=1M $TEST_IMG" \ + -c 'read -P 42 0 64k' \ + | _filter_qemu_io +# Directly set both caches +$QEMU_IO -c "open -o l2-cache-size=1M,refcount-cache-size=0.25M $TEST_IMG" \ + -c 'read -P 42 0 64k' \ + | _filter_qemu_io + +# success, all done +echo '*** done' +rm -f $seq.full +status=0 diff --git a/tests/qemu-iotests/103.out b/tests/qemu-iotests/103.out new file mode 100644 index 0000000..ddf6b5a --- /dev/null +++ b/tests/qemu-iotests/103.out @@ -0,0 +1,29 @@ +QA output created by 103 +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65536 +wrote 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=== Testing invalid option combinations === + +qemu-io: can't open device TEST_DIR/t.IMGFMT: cache-size, l2-cache-size and refcount-cache-size may not be set the same time +qemu-io: can't open device TEST_DIR/t.IMGFMT: l2-cache-size may not exceed cache-size +qemu-io: can't open device TEST_DIR/t.IMGFMT: refcount-cache-size may not exceed cache-size +qemu-io: can't open device TEST_DIR/t.IMGFMT: cache-size, l2-cache-size and refcount-cache-size may not be set the same time + +=== Testing valid option combinations === + +read 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +*** done diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter index a04df7f..51192c8 100644 --- a/tests/qemu-iotests/common.filter +++ b/tests/qemu-iotests/common.filter @@ -170,5 +170,27 @@ _filter_qmp() -e 's#^{"QMP":.*}$#QMP_VERSION#' } +# replace driver-specific options in the "Formatting..." line +_filter_img_create() +{ + sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \ + -e "s#$TEST_DIR#TEST_DIR#g" \ + -e "s#$IMGFMT#IMGFMT#g" \ + -e "s# encryption=off##g" \ + -e "s# cluster_size=[0-9]\\+##g" \ + -e "s# table_size=[0-9]\\+##g" \ + -e "s# compat='[^']*'##g" \ + -e "s# compat6=\\(on\\|off\\)##g" \ + -e "s# static=\\(on\\|off\\)##g" \ + -e "s# zeroed_grain=\\(on\\|off\\)##g" \ + -e "s# subformat='[^']*'##g" \ + -e "s# adapter_type='[^']*'##g" \ + -e "s# lazy_refcounts=\\(on\\|off\\)##g" \ + -e "s# block_size=[0-9]\\+##g" \ + -e "s# block_state_zero=\\(on\\|off\\)##g" \ + -e "s# log_size=[0-9]\\+##g" \ + -e "s/archipelago:a/TEST_DIR\//g" +} + # make sure this script returns success /bin/true diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index 3fd691e..9c49deb 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -149,24 +149,7 @@ _make_test_img() else $QEMU_IMG create -f $IMGFMT $extra_img_options "$img_name" $image_size 2>&1 fi - ) | \ - sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \ - -e "s#$TEST_DIR#TEST_DIR#g" \ - -e "s#$IMGFMT#IMGFMT#g" \ - -e "s# encryption=off##g" \ - -e "s# cluster_size=[0-9]\\+##g" \ - -e "s# table_size=[0-9]\\+##g" \ - -e "s# compat='[^']*'##g" \ - -e "s# compat6=\\(on\\|off\\)##g" \ - -e "s# static=\\(on\\|off\\)##g" \ - -e "s# zeroed_grain=\\(on\\|off\\)##g" \ - -e "s# subformat='[^']*'##g" \ - -e "s# adapter_type='[^']*'##g" \ - -e "s# lazy_refcounts=\\(on\\|off\\)##g" \ - -e "s# block_size=[0-9]\\+##g" \ - -e "s# block_state_zero=\\(on\\|off\\)##g" \ - -e "s# log_size=[0-9]\\+##g" \ - -e "s/archipelago:a/TEST_DIR\//g" + ) | _filter_img_create # Start an NBD server on the image file, which is what we'll be talking to if [ $IMGPROTO = "nbd" ]; then diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 6e67f61..2803d68 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -100,3 +100,6 @@ 091 rw auto quick 092 rw auto quick 095 rw auto quick +099 rw auto quick +101 rw auto quick +103 rw auto quick diff --git a/tests/test-coroutine.c b/tests/test-coroutine.c index 6e634f4..e22fae1 100644 --- a/tests/test-coroutine.c +++ b/tests/test-coroutine.c @@ -311,6 +311,35 @@ static void perf_baseline(void) maxcycles, duration); } +static __attribute__((noinline)) void perf_cost_func(void *opaque) +{ + qemu_coroutine_yield(); +} + +static void perf_cost(void) +{ + const unsigned long maxcycles = 40000000; + unsigned long i = 0; + double duration; + unsigned long ops; + Coroutine *co; + + g_test_timer_start(); + while (i++ < maxcycles) { + co = qemu_coroutine_create(perf_cost_func); + qemu_coroutine_enter(co, &i); + qemu_coroutine_enter(co, NULL); + } + duration = g_test_timer_elapsed(); + ops = (long)(maxcycles / (duration * 1000)); + + g_test_message("Run operation %lu iterations %f s, %luK operations/s, " + "%luns per coroutine", + maxcycles, + duration, ops, + (unsigned long)(1000000000 * duration) / maxcycles); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -325,6 +354,7 @@ int main(int argc, char **argv) g_test_add_func("/perf/nesting", perf_nesting); g_test_add_func("/perf/yield", perf_yield); g_test_add_func("/perf/function-call", perf_baseline); + g_test_add_func("/perf/cost", perf_cost); } return g_test_run(); } |