1 #pragma once 2 /* 3 * Copyright (C) 2016 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #include <memory> 19 #include <functional> 20 21 #include "common/vsoc/lib/typed_region_view.h" 22 #include "common/vsoc/shm/e2e_test_region_layout.h" 23 24 namespace vsoc { 25 template <typename Layout> 26 class E2ERegionView : public vsoc::TypedRegionView< 27 E2ERegionView<Layout>, 28 Layout> { 29 public: 30 read_guest_self_register()31 uint32_t read_guest_self_register() const { 32 return this->data().guest_self_register; 33 } 34 write_guest_self_register(uint32_t val)35 void write_guest_self_register(uint32_t val) { 36 this->data()->guest_self_register = val; 37 } 38 signal_guest_self_register()39 void signal_guest_self_register() { 40 this->SendSignal(layout::Sides::OurSide, 41 &this->data()->guest_self_register); 42 } 43 wait_guest_self_register(uint32_t expected_value)44 int wait_guest_self_register(uint32_t expected_value) { 45 return this->WaitForSignal( 46 &this->data()->guest_self_register, expected_value); 47 } 48 signal_guest_to_host_register()49 void signal_guest_to_host_register() { 50 this->SendSignal(layout::Sides::OurSide, 51 &this->data()->guest_to_host_signal); 52 } 53 guest_to_host_signal_offset()54 uint32_t guest_to_host_signal_offset() const { 55 return this->pointer_to_region_offset(&this->data().guest_to_host_signal); 56 } 57 host_to_guest_signal_offset()58 uint32_t host_to_guest_signal_offset() const { 59 return this->pointer_to_region_offset(&this->data().host_to_guest_signal); 60 } 61 guest_string(size_t index)62 const char* guest_string(size_t index) const { 63 return const_cast<const char*>(this->data().data[index].guest_writable); 64 } 65 host_string(size_t index)66 const char* host_string(size_t index) const { 67 return const_cast<const char*>(this->data().data[index].host_writable); 68 } 69 set_guest_string(size_t index,const char * value)70 bool set_guest_string(size_t index, const char* value) { 71 strcpy(const_cast<char*>(this->data()->data[index].guest_writable), 72 value); 73 return true; 74 } 75 set_host_string(size_t index,const char * value)76 bool set_host_string(size_t index, const char* value) { 77 strcpy(const_cast<char*>(this->data()->data[index].host_writable), 78 value); 79 return true; 80 } 81 string_size()82 size_t string_size() const { 83 return Layout::NumFillRecords(this->control_->region_data_size()); 84 } 85 guest_status(vsoc::layout::e2e_test::E2ETestStage stage)86 void guest_status(vsoc::layout::e2e_test::E2ETestStage stage) { 87 this->data()->guest_status.set_value(stage); 88 } 89 host_status(vsoc::layout::e2e_test::E2ETestStage stage)90 void host_status(vsoc::layout::e2e_test::E2ETestStage stage) { 91 this->data()->host_status.set_value(stage); 92 } 93 }; 94 95 using E2EPrimaryRegionView = 96 vsoc::E2ERegionView<layout::e2e_test::E2EPrimaryTestRegionLayout>; 97 98 using E2ESecondaryRegionView = 99 vsoc::E2ERegionView<layout::e2e_test::E2ESecondaryTestRegionLayout>; 100 101 using E2EUnfindableRegionView = 102 vsoc::E2ERegionView<layout::e2e_test::E2EUnfindableRegionLayout>; 103 104 } // namespace vsoc 105