OLD | NEW |
1 /* Copyright (c) 2010, Google Inc. | 1 /* |
| 2 * |
| 3 * Copyright 2015, Google Inc. |
2 * All rights reserved. | 4 * All rights reserved. |
3 * | 5 * |
4 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
6 * met: | 8 * met: |
7 * | 9 * |
8 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 11 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 12 * * Redistributions in binary form must reproduce the above |
11 * copyright notice, this list of conditions and the following disclaimer | 13 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 14 * in the documentation and/or other materials provided with the |
13 * distribution. | 15 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 16 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 17 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 18 * this software without specific prior written permission. |
17 * | 19 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 * | 31 * |
30 * --- | |
31 * This file is an internal part spinlock.cc and once.cc | |
32 * It may not be used directly by code outside of //base. | |
33 */ | 32 */ |
34 | 33 |
35 #ifndef BASE_SPINLOCK_INTERNAL_H_ | 34 #ifndef GRPC_TEST_CORE_END2END_CQ_VERIFIER_H |
36 #define BASE_SPINLOCK_INTERNAL_H_ | 35 #define GRPC_TEST_CORE_END2END_CQ_VERIFIER_H |
37 | 36 |
38 #include <config.h> | 37 #include <grpc/grpc.h> |
39 #include "base/basictypes.h" | 38 #include "test/core/util/test_config.h" |
40 #include "base/atomicops.h" | |
41 | 39 |
42 namespace base { | 40 /* A cq_verifier can verify that expected events arrive in a timely fashion |
43 namespace internal { | 41 on a single completion queue */ |
44 | 42 |
45 // SpinLockWait() waits until it can perform one of several transitions from | 43 typedef struct cq_verifier cq_verifier; |
46 // "from" to "to". It returns when it performs a transition where done==true. | |
47 struct SpinLockWaitTransition { | |
48 int32 from; | |
49 int32 to; | |
50 bool done; | |
51 }; | |
52 | 44 |
53 // Wait until *w can transition from trans[i].from to trans[i].to for some i | 45 /* construct/destroy a cq_verifier */ |
54 // satisfying 0<=i<n && trans[i].done, atomically make the transition, | 46 cq_verifier *cq_verifier_create(grpc_completion_queue *cq); |
55 // then return the old value of *w. Make any other atomic tranistions | 47 void cq_verifier_destroy(cq_verifier *v); |
56 // where !trans[i].done, but continue waiting. | |
57 int32 SpinLockWait(volatile Atomic32 *w, int n, | |
58 const SpinLockWaitTransition trans[]); | |
59 void SpinLockWake(volatile Atomic32 *w, bool all); | |
60 void SpinLockDelay(volatile Atomic32 *w, int32 value, int loop); | |
61 | 48 |
62 } // namespace internal | 49 /* ensure all expected events (and only those events) are present on the |
63 } // namespace base | 50 bound completion queue */ |
64 #endif | 51 void cq_verify(cq_verifier *v); |
| 52 |
| 53 /* ensure that the completion queue is empty */ |
| 54 void cq_verify_empty(cq_verifier *v); |
| 55 |
| 56 /* Various expectation matchers |
| 57 Any functions taking ... expect a NULL terminated list of key/value pairs |
| 58 (each pair using two parameter slots) of metadata that MUST be present in |
| 59 the event. */ |
| 60 void cq_expect_completion(cq_verifier *v, void *tag, int success); |
| 61 |
| 62 int byte_buffer_eq_string(grpc_byte_buffer *byte_buffer, const char *string); |
| 63 int contains_metadata(grpc_metadata_array *array, const char *key, |
| 64 const char *value); |
| 65 |
| 66 #endif /* GRPC_TEST_CORE_END2END_CQ_VERIFIER_H */ |
OLD | NEW |