1 /* 2 * Copyright 2019 The Hafnium Authors. 3 * 4 * Use of this source code is governed by a BSD-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/BSD-3-Clause. 7 */ 8 9 #pragma once 10 11 #include "vmapi/hf/call.h" 12 13 #include "../msr.h" 14 #include "test/hftest.h" 15 16 #define TRY_READ(REG) dlog(#REG "=%#x\n", read_msr(REG)) 17 18 #define CHECK_READ(REG, VALUE) \ 19 do { \ 20 uintreg_t x; \ 21 x = read_msr(REG); \ 22 EXPECT_EQ(x, VALUE); \ 23 } while (0) 24 25 /* 26 * Checks that the register can be updated. The first value is written and read 27 * back and then the second value is written and read back. The values must be 28 * different so that success means the register value has been changed and 29 * updated as expected without relying on the initial value of the register. 30 */ 31 #define CHECK_UPDATE(REG, FROM, TO) \ 32 do { \ 33 uintreg_t x; \ 34 EXPECT_NE(FROM, TO); \ 35 write_msr(REG, FROM); \ 36 x = read_msr(REG); \ 37 EXPECT_EQ(x, FROM); \ 38 write_msr(REG, TO); \ 39 x = read_msr(REG); \ 40 EXPECT_EQ(x, TO); \ 41 } while (0) 42