~ubuntu-branches/ubuntu/vivid/qemu/vivid

« back to all changes in this revision

Viewing changes to tests/test-rfifolock.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-02-25 22:31:43 UTC
  • mfrom: (1.8.5)
  • Revision ID: package-import@ubuntu.com-20140225223143-odhqxfc60wxrjl15
Tags: 2.0.0~rc1+dfsg-0ubuntu1
* Merge 2.0.0-rc1
* debian/rules: consolidate ppc filter entries.
* Move qemu-system-arch64 into qemu-system-arm
* debian/patches/define-trusty-machine-type.patch: define a trusty machine
  type, currently the same as pc-i440fx-2.0, to put is in a better position
  to enable live migrations from trusty onward.  (LP: #1294823)
* debian/control: build-dep on libfdt >= 1.4.0  (LP: #1295072)
* Merge latest upstream git to commit dc9528f
* Debian/rules:
  - remove -enable-uname-release=2.6.32
  - don't make the aarch64 target Ubuntu-specific.
* Remove patches which are now upstream:
  - fix-smb-security-share.patch
  - slirp-smb-redirect-port-445-too.patch 
  - linux-user-Implement-sendmmsg-syscall.patch (better version is upstream)
  - signal-added-a-wrapper-for-sigprocmask-function.patch
  - ubuntu/signal-sigsegv-protection-on-do_sigprocmask.patch
  - ubuntu/Don-t-block-SIGSEGV-at-more-places.patch
  - ubuntu/ppc-force-cpu-threads-count-to-be-power-of-2.patch
* add link for /usr/share/qemu/bios-256k.bin
* Remove all linaro patches.
* Remove all arm64/ patches.  Many but not all are upstream.
* Remove CVE-2013-4377.patch which is upstream.
* debian/control-in: don't make qemu-system-aarch64 ubuntu-specific

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * RFifoLock tests
 
3
 *
 
4
 * Copyright Red Hat, Inc. 2013
 
5
 *
 
6
 * Authors:
 
7
 *  Stefan Hajnoczi    <stefanha@redhat.com>
 
8
 *
 
9
 * This work is licensed under the terms of the GNU LGPL, version 2 or later.
 
10
 * See the COPYING.LIB file in the top-level directory.
 
11
 */
 
12
 
 
13
#include <glib.h>
 
14
#include "qemu-common.h"
 
15
#include "qemu/rfifolock.h"
 
16
 
 
17
static void test_nesting(void)
 
18
{
 
19
    RFifoLock lock;
 
20
 
 
21
    /* Trivial test, ensure the lock is recursive */
 
22
    rfifolock_init(&lock, NULL, NULL);
 
23
    rfifolock_lock(&lock);
 
24
    rfifolock_lock(&lock);
 
25
    rfifolock_lock(&lock);
 
26
    rfifolock_unlock(&lock);
 
27
    rfifolock_unlock(&lock);
 
28
    rfifolock_unlock(&lock);
 
29
    rfifolock_destroy(&lock);
 
30
}
 
31
 
 
32
typedef struct {
 
33
    RFifoLock lock;
 
34
    int fd[2];
 
35
} CallbackTestData;
 
36
 
 
37
static void rfifolock_cb(void *opaque)
 
38
{
 
39
    CallbackTestData *data = opaque;
 
40
    int ret;
 
41
    char c = 0;
 
42
 
 
43
    ret = write(data->fd[1], &c, sizeof(c));
 
44
    g_assert(ret == 1);
 
45
}
 
46
 
 
47
static void *callback_thread(void *opaque)
 
48
{
 
49
    CallbackTestData *data = opaque;
 
50
 
 
51
    /* The other thread holds the lock so the contention callback will be
 
52
     * invoked...
 
53
     */
 
54
    rfifolock_lock(&data->lock);
 
55
    rfifolock_unlock(&data->lock);
 
56
    return NULL;
 
57
}
 
58
 
 
59
static void test_callback(void)
 
60
{
 
61
    CallbackTestData data;
 
62
    QemuThread thread;
 
63
    int ret;
 
64
    char c;
 
65
 
 
66
    rfifolock_init(&data.lock, rfifolock_cb, &data);
 
67
    ret = qemu_pipe(data.fd);
 
68
    g_assert(ret == 0);
 
69
 
 
70
    /* Hold lock but allow the callback to kick us by writing to the pipe */
 
71
    rfifolock_lock(&data.lock);
 
72
    qemu_thread_create(&thread, "callback_thread",
 
73
                       callback_thread, &data, QEMU_THREAD_JOINABLE);
 
74
    ret = read(data.fd[0], &c, sizeof(c));
 
75
    g_assert(ret == 1);
 
76
    rfifolock_unlock(&data.lock);
 
77
    /* If we got here then the callback was invoked, as expected */
 
78
 
 
79
    qemu_thread_join(&thread);
 
80
    close(data.fd[0]);
 
81
    close(data.fd[1]);
 
82
    rfifolock_destroy(&data.lock);
 
83
}
 
84
 
 
85
int main(int argc, char **argv)
 
86
{
 
87
    g_test_init(&argc, &argv, NULL);
 
88
    g_test_add_func("/nesting", test_nesting);
 
89
    g_test_add_func("/callback", test_callback);
 
90
    return g_test_run();
 
91
}