Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asn1c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
qwebaby3
asn1c
Commits
ed46543c
Commit
ed46543c
authored
20 years ago
by
Lev Walkin
Browse files
Options
Downloads
Patches
Plain Diff
pretty-printing check cases
parent
92b35d2b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
skeletons/tests/check-REAL.c
+89
-39
89 additions, 39 deletions
skeletons/tests/check-REAL.c
with
89 additions
and
39 deletions
skeletons/tests/check-REAL.c
+
89
−
39
View file @
ed46543c
...
...
@@ -7,8 +7,53 @@
#include
<der_encoder.c>
#include
<constraints.c>
static
char
reconstructed
[
2
][
512
];
static
int
reconstr_lens
[
2
];
static
int
callback
(
const
void
*
buffer
,
size_t
size
,
void
*
app_key
)
{
char
*
buf
=
reconstructed
[
app_key
?
1
:
0
];
int
*
len
=
&
reconstr_lens
[
app_key
?
1
:
0
];
if
(
*
len
+
size
>=
sizeof
(
reconstructed
[
0
]))
return
-
1
;
memcpy
(
buf
+
*
len
,
buffer
,
size
);
*
len
+=
size
;
return
0
;
}
static
void
check_str_repr
(
double
d
,
const
char
*
sample
,
const
char
*
canonical_sample
)
{
ssize_t
s1
,
s2
;
reconstr_lens
[
1
]
=
reconstr_lens
[
0
]
=
0
;
s1
=
REAL__dump
(
d
,
0
,
callback
,
0
);
assert
(
s1
<
sizeof
(
reconstructed
[
0
]));
assert
(
s1
==
reconstr_lens
[
0
]);
reconstructed
[
0
][
s1
]
=
'\0'
;
s2
=
REAL__dump
(
d
,
1
,
callback
,
(
void
*
)
1
);
assert
(
s2
<
sizeof
(
reconstructed
[
1
]));
assert
(
s2
==
reconstr_lens
[
1
]);
reconstructed
[
1
][
s2
]
=
'\0'
;
if
(
sample
)
{
printf
(
"Checking [%s] against [%s]
\n
"
,
reconstructed
[
0
],
sample
);
assert
(
!
strcmp
(
reconstructed
[
0
],
sample
));
}
if
(
canonical_sample
)
{
printf
(
"Checking [%s] against [%s] (canonical)
\n
"
,
reconstructed
[
1
],
canonical_sample
);
assert
(
!
strcmp
(
reconstructed
[
1
],
canonical_sample
));
}
}
static
void
check
(
REAL_t
*
rn
,
double
orig_dbl
)
{
check
(
REAL_t
*
rn
,
double
orig_dbl
,
const
char
*
sample
,
const
char
*
canonical_sample
)
{
double
val
;
uint8_t
*
p
,
*
end
;
int
ret
;
...
...
@@ -44,17 +89,19 @@ check(REAL_t *rn, double orig_dbl) {
assert
(
orig_dbl
==
val
);
printf
(
"OK
\n
"
);
check_str_repr
(
val
,
sample
,
canonical_sample
);
}
uint8_t
buf_1_0
[]
=
{
0x80
,
0xcc
,
0x10
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
};
uint8_t
buf_1_1
[]
=
{
0x80
,
0xcc
,
0x11
,
0x99
,
0x99
,
0x99
,
0x99
,
0x99
,
0x9a
};
uint8_t
buf_3_14
[]
=
{
0x80
,
0xcd
,
0x19
,
0x1e
,
0xb8
,
0x51
,
0xeb
,
0x85
,
0x1f
};
/* These ones are very interesting! It checks mantissa overflow! */
uint8_t
buf_mo1
[]
=
{
0x
8
0
,
0xc5
,
0x19
,
0x1e
,
0xb8
,
0x51
,
0xeb
,
0x85
,
0x1f
,
3
};
uint8_t
buf_mo1
[]
=
{
0x
C
0
,
0xc5
,
0x19
,
0x1e
,
0xb8
,
0x51
,
0xeb
,
0x85
,
0x1f
,
3
};
uint8_t
buf_mo2
[]
=
{
0x80
,
0xbd
,
0x19
,
0x1e
,
0xb8
,
0x51
,
0xeb
,
0x85
,
0x1f
,
3
,
2
};
static
void
check_buf
(
uint8_t
*
buf
,
size_t
bufsize
,
double
verify
)
{
check_buf
(
uint8_t
*
buf
,
size_t
bufsize
,
double
verify
,
const
char
*
sample
,
const
char
*
canonical_sample
)
{
REAL_t
rn
;
double
val
;
uint8_t
*
p
,
*
end
;
...
...
@@ -90,6 +137,8 @@ check_buf(uint8_t *buf, size_t bufsize, double verify) {
printf
(
"%.12f vs %.12f
\n
"
,
verify
,
val
);
assert
(
val
==
verify
);
check_str_repr
(
val
,
sample
,
canonical_sample
);
}
int
...
...
@@ -98,42 +147,43 @@ main() {
memset
(
&
rn
,
0
,
sizeof
(
rn
));
check
(
&
rn
,
0
.
0
);
check
(
&
rn
,
1
.
0
);
check
(
&
rn
,
-
1
.
0
);
check
(
&
rn
,
1
.
5
);
check
(
&
rn
,
0
.
1
);
check
(
&
rn
,
0
.
33333
);
check
(
&
rn
,
2
);
check
(
&
rn
,
2
.
1
);
check
(
&
rn
,
3
);
check
(
&
rn
,
3
.
1
);
check
(
&
rn
,
3
.
14
);
check
(
&
rn
,
3
.
1415
);
check
(
&
rn
,
3
.
141592
);
check
(
&
rn
,
3
.
14159265
);
check
(
&
rn
,
-
3
.
14159265
);
check
(
&
rn
,
14159265
.
0
);
check
(
&
rn
,
-
123456789123456789
.
0
);
check
(
&
rn
,
0
.
00000000001
);
check
(
&
rn
,
0
.
00000000002
);
check
(
&
rn
,
0
.
0000000000
9
);
check
(
&
rn
,
0
.
0000000000000000000001
);
check
(
&
rn
,
0
.
000000000000000000000000000001
);
/* proved 2B a problem */
check
(
&
rn
,
-
0
.
000000000000000000000000000001
);
/* proved 2B a problem */
check
(
&
rn
,
0
.
0000000000010000000001000000000001
);
check
(
&
rn
,
0
.
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
);
check
(
&
rn
,
0
.
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
);
check
(
&
rn
,
-
0
.
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
);
check
(
&
rn
,
-
3
.
33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
);
check
(
&
rn
,
0
.
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000033333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
);
check
(
&
rn
,
-
0
.
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
);
check_buf
(
buf_1_0
,
sizeof
(
buf_1_0
),
1
.
0
);
check_buf
(
buf_1_1
,
sizeof
(
buf_1_1
),
1
.
1
);
check_buf
(
buf_3_14
,
sizeof
(
buf_3_14
),
3
.
14
);
check_buf
(
buf_mo1
,
sizeof
(
buf_mo1
),
3
.
14
);
check_buf
(
buf_mo2
,
sizeof
(
buf_mo2
),
3
.
14
);
check
(
&
rn
,
0
.
0
,
"0"
,
"0"
);
check
(
&
rn
,
-
0
.
0
,
"-0"
,
"-0"
);
/* minus-zero */
check
(
&
rn
,
1
.
0
,
"1.0"
,
"1.0E0"
);
check
(
&
rn
,
-
1
.
0
,
"-1.0"
,
"-1.0E0"
);
check
(
&
rn
,
1
.
5
,
"1.5"
,
"1.5E0"
);
check
(
&
rn
,
0
.
1
,
"0.1"
,
"1.0E-1"
);
check
(
&
rn
,
0
.
33333
,
"0.33333"
,
"3.3333E-1"
);
check
(
&
rn
,
2
,
"2.0"
,
"2.0E0"
);
check
(
&
rn
,
2
.
1
,
"2.1"
,
"2.1E0"
);
check
(
&
rn
,
3
,
"3.0"
,
"3.0E0"
);
check
(
&
rn
,
3
.
1
,
"3.1"
,
"3.1E0"
);
check
(
&
rn
,
3
.
14
,
"3.14"
,
"3.14E0"
);
check
(
&
rn
,
3
.
1415
,
"3.1415"
,
"3.1415E0"
);
check
(
&
rn
,
3
.
141592
,
"3.141592"
,
"3.141592E0"
);
check
(
&
rn
,
3
.
14159265
,
"3.14159265"
,
"3.14159265E0"
);
check
(
&
rn
,
-
3
.
14159265
,
"-3.14159265"
,
"-3.14159265E0"
);
check
(
&
rn
,
14159265
.
0
,
"14159265.0"
,
"1.4159265E7"
);
check
(
&
rn
,
-
123456789123456789
.
0
,
"-123456789123456784.0"
,
"-1.234567891234568E17"
);
check
(
&
rn
,
0
.
00000000001
,
"0.0"
,
"9.999999999999999E-12"
);
check
(
&
rn
,
0
.
00000000002
,
"0.0"
,
"2.0E-11"
);
check
(
&
rn
,
0
.
0000000000
9
,
"0.0"
,
"9.0E-11"
);
check
(
&
rn
,
0
.
0000000000000000000001
,
"0.0"
,
"1.0E-22"
);
check
(
&
rn
,
0
.
000000000000000000000000000001
,
"0.0"
,
"1.0E-30"
);
/* proved 2B a problem */
check
(
&
rn
,
-
0
.
000000000000000000000000000001
,
"-0.0"
,
"-1.0E-30"
);
/* proved 2B a problem */
check
(
&
rn
,
0
.
0000000000010000000001000000000001
,
0
,
0
);
check
(
&
rn
,
0
.
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
,
0
,
0
);
check
(
&
rn
,
0
.
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
,
0
,
0
);
check
(
&
rn
,
-
0
.
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
,
0
,
0
);
check
(
&
rn
,
-
3
.
33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
,
0
,
0
);
check
(
&
rn
,
0
.
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000033333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
,
0
,
0
);
check
(
&
rn
,
-
0
.
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
,
0
,
0
);
check_buf
(
buf_1_0
,
sizeof
(
buf_1_0
),
1
.
0
,
"1.0"
,
"1.0E0"
);
check_buf
(
buf_1_1
,
sizeof
(
buf_1_1
),
1
.
1
,
"1.1"
,
"1.1E0"
);
check_buf
(
buf_3_14
,
sizeof
(
buf_3_14
),
3
.
14
,
"3.14"
,
"3.14E0"
);
check_buf
(
buf_mo1
,
sizeof
(
buf_mo1
),
-
3
.
14
,
"-3.14"
,
"-3.14E0"
);
check_buf
(
buf_mo2
,
sizeof
(
buf_mo2
),
3
.
14
,
"3.14"
,
"3.14E0"
);
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment