summaryrefslogtreecommitdiffstats
path: root/src/kmk/testcase-math.kmk
blob: bd4fb7edc19810120f035df0a5c6f4aafffab7c2 (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
# $Id: testcase-math.kmk 2413 2010-09-11 17:43:04Z bird $
## @file
# kBuild - testcase for the math functions.
#

#
# Copyright (c) 2007-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
#
# This file is part of kBuild.
#
# kBuild 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 3 of the License, or
# (at your option) any later version.
#
# kBuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with kBuild.  If not, see <http://www.gnu.org/licenses/>
#
#

DEPTH = ../..
include $(PATH_KBUILD)/header.kmk

ifneq ($(not 1),)
 $(error The 'not' function is missing)
endif
ifneq ($(eq 1,1),1)
 $(error The 'eq' function is missing)
endif


ASSERT_TRUE  = $(if $(not $(1)),$(error failure: '$(1)' isn't true))
ASSERT_FALSE = $(if       $(1) ,$(error failure: '$(1)' isn't false))

$(call ASSERT_TRUE, $(int-eq 0x0, 0))
$(call ASSERT_FALSE,$(int-eq 1, 0))
$(call ASSERT_FALSE,$(int-eq 1123123123, 9898787987))
$(call ASSERT_TRUE, $(int-eq 1234567890, 1234567890))
$(call ASSERT_TRUE, $(int-eq 0x1c, 28))
$(call ASSERT_TRUE, $(int-eq 1c, 28))
$(call ASSERT_TRUE, $(int-ne 0x123, -0x123))
$(call ASSERT_TRUE, $(int-ne 123, -0x123))
$(call ASSERT_FALSE,$(int-ne 0x100, 256))
$(call ASSERT_FALSE,$(int-ne 0x0, 0))
$(call ASSERT_FALSE,$(int-ne 0x1c, 28))
$(call ASSERT_TRUE, $(int-le 0, 0))
$(call ASSERT_TRUE, $(int-le -0, 0))
$(call ASSERT_FALSE,$(int-le 5, 1))
$(call ASSERT_FALSE,$(int-lt 5, 1))
$(call ASSERT_FALSE,$(int-lt 5, 5))
$(call ASSERT_TRUE, $(int-lt 9, 10))
$(call ASSERT_TRUE, $(int-lt -9, -8))
$(call ASSERT_TRUE, $(int-ge 0, 0))
$(call ASSERT_TRUE, $(int-ge -0, 0))
$(call ASSERT_TRUE, $(int-ge 1, 0))
$(call ASSERT_TRUE, $(int-ge -55, -55))
$(call ASSERT_TRUE, $(int-ge 512, 400))
$(call ASSERT_TRUE, $(int-ge -18, -19))
$(call ASSERT_FALSE,$(int-ge -19, -18))
$(call ASSERT_FALSE,$(int-ge 15, 20))
$(call ASSERT_FALSE,$(int-gt 15, 20))
$(call ASSERT_FALSE,$(int-gt 15, 15))
$(call ASSERT_TRUE, $(int-gt 20, 15))

ASSERT2 = $(if $(not $(int-eq $(1),$(2))),$(error failure: '$(1)' -ne '$(2)'))
$(call ASSERT2,$(int-add 1, 1),0x2)
$(call ASSERT2,$(int-add 1, 1, 1, 1, 1, 1, 1),7)
$(call ASSERT2,$(int-add 1, -1),0)
$(call ASSERT2,$(int-sub 1, -1),2)
$(call ASSERT2,$(int-sub 1, 5),-4)
$(call ASSERT2,$(int-mul 0x10, 0x20),0x200)
$(call ASSERT2,$(int-mul 0x20, 0x10),0x200)
$(call ASSERT2,$(int-mul 4, 7),28)
$(call ASSERT2,$(int-mul 2, 2, 2, 2, 2, 4, 1, 1, 1, 1),128)
$(call ASSERT2,$(int-div 0x1000, 0x100),0x10)
$(call ASSERT2,$(int-div 999, 10),99)
$(call ASSERT2,$(int-div 4096, 4,2,2,2,2),64)
#$(call ASSERT2,$(int-div 0x1230023213, 0),0x0)
$(call ASSERT2,$(int-mod 19, 10),9)
$(call ASSERT2,$(int-mod 9, 10),9)
$(call ASSERT2,$(int-mod 30, 10),0)
$(call ASSERT2,$(int-not 0),-1)
$(call ASSERT2,$(int-and 1, 1),1)
$(call ASSERT2,$(int-and 0x123123214, 0xfff),0x214)
$(call ASSERT2,$(int-and 0x123123214, 0xf0f, 0xf),4)
$(call ASSERT2,$(int-or 1, 1, 1, 2, 2),3)
$(call ASSERT2,$(int-xor 1, 1, 2, 2),0)
$(call ASSERT2,$(int-xor 1, 2, 4),7)


all_recursive:
	$(ECHO) The math works. 6 * 7 = $(int-mul 6,7)