summaryrefstree
path: root/kernel/drivers/vision/npu/idiot-def.h
blob: da2600227c1d82ac1a665f149e123ba42410f668 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Samsung Exynos SoC series NPU driver
 *
 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
 *	http://www.samsung.com/
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

/*
 * IDIOT - Intutive Device driver integrated Operation Testing
 *
 */

#include <linux/time.h>
#include <linux/timekeeping.h>
#include "idiot-config.h"

#define IDIOT_ASSERT_EQ(test, expected, TNAME_FMT)		__IDIOT_ASSERT_CONDITION(-, ==, test, expected, TNAME_FMT)
#define IDIOT_ASSERT_NEQ(test, expected, TNAME_FMT)		__IDIOT_ASSERT_CONDITION(-, !=, test, expected, TNAME_FMT)
#define IDIOT_ASSERT_LE(test, expected, TNAME_FMT)		__IDIOT_ASSERT_CONDITION(-, <=, test, expected, TNAME_FMT)
#define IDIOT_ASSERT_EQ_T(TAG, test, expected, TNAME_FMT)	__IDIOT_ASSERT_CONDITION(TAG, ==, test, expected, TNAME_FMT)
#define IDIOT_ASSERT_NEQ_T(TAG, test, expected, TNAME_FMT)	__IDIOT_ASSERT_CONDITION(TAG, !=, test, expected, TNAME_FMT)
#define IDIOT_ASSERT_LE_T(TAG, test, expected, TNAME_FMT)	__IDIOT_ASSERT_CONDITION(TAG, <=, test, expected, TNAME_FMT)
#define IDIOT_ASSERT_GE_T(TAG, test, expected, TNAME_FMT)	__IDIOT_ASSERT_CONDITION(TAG, >=, test, expected, TNAME_FMT)

/* For each condition - Old IF */
#define IDIOT_ASSERT(TNAME, TNAME_FMT, test, expected)		__IDIOT_ASSERT_CONDITION(-, ==, test, expected, TNAME_FMT)
#define IDIOT_ASSERT_NOT(TNAME, TNAME_FMT, test, expected)	__IDIOT_ASSERT_CONDITION(-, !=, test, expected, TNAME_FMT)

/* Base implementation of assert macro */
#define __IDIOT_ASSERT_CONDITION(TAG, COND, test, expected, TNAME_FMT)			\
do {											\
	typeof(test) __idiot_actual = (test);						\
	typeof(test) __idiot_expected = (expected);					\
	int __idiot_this_msgLen = 0;							\
	if (!((__idiot_actual) COND(__idiot_expected))) {				\
		__idiot_this_msgLen = scnprintf(__idiot_msgbuf, __idiot_bufLen		\
			, "Assert at %s:%d(" #TAG ") (Cond[" #test			\
			  "]/Expected[" #COND #expected "]) - Actual [" #TNAME_FMT	\
			  "] " #COND " Expected [" #TNAME_FMT "]\n"			\
			, __FILE__, __LINE__, __idiot_actual, __idiot_expected);	\
		__idiot_msgbuf += __idiot_this_msgLen;					\
		__idiot_bufLen -= __idiot_this_msgLen;					\
		__idiot_return_value = 1;						\
		goto __idiot_testcase_termination;					\
	}										\
} while (0)										\

#define IDIOT_ASSERT_DONE_IN_US(US, ...)						\
{											\
	ktime_t __idiot_kt_start, __idiot_kt_finish;					\
	s64 __idiot_time_diff_us;							\
	__idiot_kt_start = ktime_get_boottime();					\
	{										\
		/* Test code */								\
		__VA_ARGS__								\
	}										\
	__idiot_kt_finish = ktime_get_boottime();					\
	/* Time diff in usec */								\
	__idiot_time_diff_us =								\
		ktime_to_us(ktime_sub(__idiot_kt_finish, __idiot_kt_start));		\
	IDIOT_MSG("Line:%d : Elapsed time = %lld us\n", __LINE__, __idiot_time_diff_us);\
	IDIOT_ASSERT_LE(__idiot_time_diff_us, (US), % lld);				\
}											\

/* Leave a message in test result buffer for reference */
#define IDIOT_MSG(...)									\
do {											\
	int __idiot_this_msgLen = 0;							\
	__idiot_this_msgLen = scnprintf(__idiot_msgbuf, __idiot_bufLen, __VA_ARGS__);	\
	__idiot_msgbuf += __idiot_this_msgLen;						\
	__idiot_bufLen -= __idiot_this_msgLen;						\
} while (0)


/* Insert Testcase definition */
#undef TESTDEF
#undef SETUP_CODE
#undef TEARDOWN_CODE
#define SETUP_CODE
#define TEARDOWN_CODE
#define TESTDEF(fname, ...) \
int TESTFUNCNAME(fname) (struct file *file, char *__idiot_msgbuf, size_t __idiot_bufLen) \
{	\
	int __idiot_return_value = 0;		\
	SETUP_CODE				\
						\
	{					\
		__VA_ARGS__			\
__idiot_testcase_termination : \
		{				\
			TEARDOWN_CODE		\
		}				\
	}					\
						\
	return __idiot_return_value;		\
}						\

/* Include declaration section of idiot file */
#ifndef IDIOT_DECL_SECTION
#define IDIOT_DECL_SECTION
#endif

#ifdef IDIOT_TESTCASE_IMPL
#include IDIOT_TESTCASE_IMPL
#else
#error "Please define IDIOT_TESTCASE_IMPL as an testcase implementation."
#endif