Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: source/libvpx/test/register_state_check.h

Issue 11974002: libvpx: Pull from upstream (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/test/pp_filter_test.cc ('k') | source/libvpx/test/sad_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifndef LIBVPX_TEST_REGISTER_STATE_CHECK_H_
12 #define LIBVPX_TEST_REGISTER_STATE_CHECK_H_
13
14 #ifdef _WIN64
15
16 #define _WIN32_LEAN_AND_MEAN
17 #include <windows.h>
18 #include <winnt.h>
19
20 #include "third_party/googletest/src/include/gtest/gtest.h"
21
22 namespace testing {
23 namespace internal {
24
25 inline bool operator==(const M128A& lhs, const M128A& rhs) {
26 return (lhs.Low == rhs.Low && lhs.High == rhs.High);
27 }
28
29 } // namespace internal
30 } // namespace testing
31
32 namespace libvpx_test {
33
34 // Compares the state of xmm[6-15] at construction with their state at
35 // destruction. These registers should be preserved by the callee on
36 // Windows x64.
37 // Usage:
38 // {
39 // RegisterStateCheck reg_check;
40 // FunctionToVerify();
41 // }
42 class RegisterStateCheck {
43 public:
44 RegisterStateCheck() { initialized_ = StoreRegisters(&pre_context_); }
45 ~RegisterStateCheck() { EXPECT_TRUE(Check()); }
46
47 private:
48 static bool StoreRegisters(CONTEXT* const context) {
49 const HANDLE this_thread = GetCurrentThread();
50 EXPECT_TRUE(this_thread != NULL);
51 context->ContextFlags = CONTEXT_FLOATING_POINT;
52 const bool context_saved = GetThreadContext(this_thread, context) == TRUE;
53 EXPECT_TRUE(context_saved) << "GetLastError: " << GetLastError();
54 return context_saved;
55 }
56
57 // Compares the register state. Returns true if the states match.
58 bool Check() const {
59 if (!initialized_) return false;
60 CONTEXT post_context;
61 if (!StoreRegisters(&post_context)) return false;
62
63 const M128A* xmm_pre = &pre_context_.Xmm6;
64 const M128A* xmm_post = &post_context.Xmm6;
65 for (int i = 6; i <= 15; ++i) {
66 EXPECT_EQ(*xmm_pre, *xmm_post) << "xmm" << i << " has been modified!";
67 ++xmm_pre;
68 ++xmm_post;
69 }
70 return !testing::Test::HasNonfatalFailure();
71 }
72
73 bool initialized_;
74 CONTEXT pre_context_;
75 };
76
77 #define REGISTER_STATE_CHECK(statement) do { \
78 libvpx_test::RegisterStateCheck reg_check; \
79 statement; \
80 } while (false)
81
82 } // namespace libvpx_test
83
84 #else // !_WIN64
85
86 namespace libvpx_test {
87
88 class RegisterStateCheck {};
89 #define REGISTER_STATE_CHECK(statement) statement
90
91 } // namespace libvpx_test
92
93 #endif // _WIN64
94
95 #endif // LIBVPX_TEST_REGISTER_STATE_CHECK_H_
OLDNEW
« no previous file with comments | « source/libvpx/test/pp_filter_test.cc ('k') | source/libvpx/test/sad_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698