Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 #ifndef _MEMBLOCK_TEST_H
0003 #define _MEMBLOCK_TEST_H
0004 
0005 #include <stdlib.h>
0006 #include <assert.h>
0007 #include <linux/types.h>
0008 #include <linux/memblock.h>
0009 #include <linux/sizes.h>
0010 #include <linux/printk.h>
0011 #include <../selftests/kselftest.h>
0012 
0013 #define MEM_SIZE SZ_16K
0014 
0015 /**
0016  * ASSERT_EQ():
0017  * Check the condition
0018  * @_expected == @_seen
0019  * If false, print failed test message (if in VERBOSE mode) and then assert
0020  */
0021 #define ASSERT_EQ(_expected, _seen) do { \
0022     if ((_expected) != (_seen)) \
0023         test_fail(); \
0024     assert((_expected) == (_seen)); \
0025 } while (0)
0026 
0027 /**
0028  * ASSERT_NE():
0029  * Check the condition
0030  * @_expected != @_seen
0031  * If false, print failed test message (if in VERBOSE mode) and then assert
0032  */
0033 #define ASSERT_NE(_expected, _seen) do { \
0034     if ((_expected) == (_seen)) \
0035         test_fail(); \
0036     assert((_expected) != (_seen)); \
0037 } while (0)
0038 
0039 /**
0040  * ASSERT_LT():
0041  * Check the condition
0042  * @_expected < @_seen
0043  * If false, print failed test message (if in VERBOSE mode) and then assert
0044  */
0045 #define ASSERT_LT(_expected, _seen) do { \
0046     if ((_expected) >= (_seen)) \
0047         test_fail(); \
0048     assert((_expected) < (_seen)); \
0049 } while (0)
0050 
0051 #define PREFIX_PUSH() prefix_push(__func__)
0052 
0053 /*
0054  * Available memory registered with memblock needs to be valid for allocs
0055  * test to run. This is a convenience wrapper for memory allocated in
0056  * dummy_physical_memory_init() that is later registered with memblock
0057  * in setup_memblock().
0058  */
0059 struct test_memory {
0060     void *base;
0061 };
0062 
0063 struct region {
0064     phys_addr_t base;
0065     phys_addr_t size;
0066 };
0067 
0068 void reset_memblock_regions(void);
0069 void reset_memblock_attributes(void);
0070 void setup_memblock(void);
0071 void dummy_physical_memory_init(void);
0072 void dummy_physical_memory_cleanup(void);
0073 void parse_args(int argc, char **argv);
0074 
0075 void test_fail(void);
0076 void test_pass(void);
0077 void test_print(const char *fmt, ...);
0078 void prefix_reset(void);
0079 void prefix_push(const char *prefix);
0080 void prefix_pop(void);
0081 
0082 static inline void test_pass_pop(void)
0083 {
0084     test_pass();
0085     prefix_pop();
0086 }
0087 
0088 #endif