at v6.0-rc6 88 lines 2.0 kB view raw
1/* SPDX-License-Identifier: GPL-2.0-or-later */ 2#ifndef _MEMBLOCK_TEST_H 3#define _MEMBLOCK_TEST_H 4 5#include <stdlib.h> 6#include <assert.h> 7#include <linux/types.h> 8#include <linux/memblock.h> 9#include <linux/sizes.h> 10#include <linux/printk.h> 11#include <../selftests/kselftest.h> 12 13#define MEM_SIZE SZ_16K 14 15/** 16 * ASSERT_EQ(): 17 * Check the condition 18 * @_expected == @_seen 19 * If false, print failed test message (if in VERBOSE mode) and then assert 20 */ 21#define ASSERT_EQ(_expected, _seen) do { \ 22 if ((_expected) != (_seen)) \ 23 test_fail(); \ 24 assert((_expected) == (_seen)); \ 25} while (0) 26 27/** 28 * ASSERT_NE(): 29 * Check the condition 30 * @_expected != @_seen 31 * If false, print failed test message (if in VERBOSE mode) and then assert 32 */ 33#define ASSERT_NE(_expected, _seen) do { \ 34 if ((_expected) == (_seen)) \ 35 test_fail(); \ 36 assert((_expected) != (_seen)); \ 37} while (0) 38 39/** 40 * ASSERT_LT(): 41 * Check the condition 42 * @_expected < @_seen 43 * If false, print failed test message (if in VERBOSE mode) and then assert 44 */ 45#define ASSERT_LT(_expected, _seen) do { \ 46 if ((_expected) >= (_seen)) \ 47 test_fail(); \ 48 assert((_expected) < (_seen)); \ 49} while (0) 50 51#define PREFIX_PUSH() prefix_push(__func__) 52 53/* 54 * Available memory registered with memblock needs to be valid for allocs 55 * test to run. This is a convenience wrapper for memory allocated in 56 * dummy_physical_memory_init() that is later registered with memblock 57 * in setup_memblock(). 58 */ 59struct test_memory { 60 void *base; 61}; 62 63struct region { 64 phys_addr_t base; 65 phys_addr_t size; 66}; 67 68void reset_memblock_regions(void); 69void reset_memblock_attributes(void); 70void setup_memblock(void); 71void dummy_physical_memory_init(void); 72void dummy_physical_memory_cleanup(void); 73void parse_args(int argc, char **argv); 74 75void test_fail(void); 76void test_pass(void); 77void test_print(const char *fmt, ...); 78void prefix_reset(void); 79void prefix_push(const char *prefix); 80void prefix_pop(void); 81 82static inline void test_pass_pop(void) 83{ 84 test_pass(); 85 prefix_pop(); 86} 87 88#endif