Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
asn1c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
asn1c
Commits
edfc7e7f
Commit
edfc7e7f
authored
Feb 02, 2024
by
v0-e
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
copy: Add tests
parent
c19e515f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
204 additions
and
2 deletions
+204
-2
tests/tests-randomized/check-bundles.sh
tests/tests-randomized/check-bundles.sh
+10
-0
tests/tests-randomized/random-test-driver.c
tests/tests-randomized/random-test-driver.c
+82
-2
tests/tests-skeletons/Makefile.am
tests/tests-skeletons/Makefile.am
+5
-0
tests/tests-skeletons/check-copy.c
tests/tests-skeletons/check-copy.c
+107
-0
No files found.
tests/tests-randomized/check-bundles.sh
View file @
edfc7e7f
...
...
@@ -187,6 +187,16 @@ compile_and_test() {
return
3
fi
echo
"Checking random data copy"
copy_check_cmd
=
"
${
ASAN_ENV_FLAGS
}
./random-test-driver -s
${
rmax
}
${
encodings
}
-y"
echo
"(
${
reproduce_make
}
&&
${
copy_check_cmd
}
)"
>
.test-reproduce
if
eval
"
$copy_check_cmd
"
;
then
echo
"Copy test OK"
else
{
echo
"RETRY:"
;
cat
.test-reproduce
;
}
return
3
fi
echo
"Generating new random data"
rm
-rf
random-data
cmd
=
"
${
ASAN_ENV_FLAGS
}
UBSAN_OPTIONS=print_stacktrace=1"
...
...
tests/tests-randomized/random-test-driver.c
View file @
edfc7e7f
...
...
@@ -327,12 +327,85 @@ check_random_roundtrip(enum asn_transfer_syntax syntax, size_t max_random_value_
enc
.
name
);
}
static
void
check_copy_op
(
enum
asn_transfer_syntax
syntax
,
size_t
max_random_value_size
,
int
iterations
,
int
debug
)
{
struct
encoding_map
enc
;
for
(
size_t
i
=
0
;
i
<
sizeof
(
encodings
)
/
sizeof
(
encodings
[
0
]);
i
++
)
{
enc
=
encodings
[
i
];
if
(
enc
.
syntax
==
syntax
)
{
fprintf
(
stderr
,
"Testing %d iterations of round-trip for %s
\n
"
,
iterations
,
enc
.
name
);
break
;
}
}
for
(
int
i
=
0
;
i
<
iterations
;
i
++
)
{
T_t
*
structure
=
0
;
T_t
*
new_structure
=
0
;
if
(
asn_random_fill
(
&
asn_DEF_T
,
(
void
**
)
&
structure
,
max_random_value_size
)
==
-
1
)
{
assert
(
structure
==
0
);
fprintf
(
stderr
,
"Can't generate %d'th value, skipping
\n
"
,
i
);
continue
;
}
assert
(
structure
!=
0
);
if
(
debug
)
{
fprintf
(
stderr
,
"Random structure %s:
\n
"
,
sizeof
(
ASN1_STR
)
>
60
?
"T"
:
ASN1_STR
);
asn_fprint
(
stderr
,
&
asn_DEF_T
,
structure
);
xer_fprint
(
stderr
,
&
asn_DEF_T
,
structure
);
}
int
cr
=
asn_DEF_T
.
op
->
copy_struct
(
&
asn_DEF_T
,
(
void
**
)
&
new_structure
,
structure
);
if
(
cr
!=
0
)
{
fprintf
(
stderr
,
"Copying structure %s:
\n
"
,
sizeof
(
ASN1_STR
)
>
60
?
"T"
:
ASN1_STR
);
asn_fprint
(
stderr
,
&
asn_DEF_T
,
structure
);
assert
(
cr
==
0
);
exit
(
EX_SOFTWARE
);
}
assert
(
new_structure
!=
0
);
/*
* Confirm that we decoded the same data.
*/
int
cmp
=
asn_DEF_T
.
op
->
compare_struct
(
&
asn_DEF_T
,
structure
,
new_structure
);
if
(
cmp
!=
0
||
debug
)
{
fprintf
(
stderr
,
"Random %s value:
\n
"
,
ASN1_STR
);
asn_fprint
(
stderr
,
&
asn_DEF_T
,
structure
);
xer_fprint
(
stderr
,
&
asn_DEF_T
,
structure
);
fprintf
(
stderr
,
"Copied %s value:
\n
"
,
ASN1_STR
);
asn_fprint
(
stderr
,
&
asn_DEF_T
,
new_structure
);
xer_fprint
(
stderr
,
&
asn_DEF_T
,
new_structure
);
assert
(
cmp
==
0
);
}
ASN_STRUCT_FREE
(
asn_DEF_T
,
structure
);
ASN_STRUCT_FREE
(
asn_DEF_T
,
new_structure
);
if
(
i
<
5
)
{
fprintf
(
stderr
,
"[%03d] copy OK
\n
"
,
i
);
}
else
if
(
i
==
5
)
{
fprintf
(
stderr
,
"... and so on
\n
"
);
}
}
fprintf
(
stderr
,
"OK %d iterations of copy-op for %s
\n
"
,
iterations
,
enc
.
name
);
}
int
main
(
int
argc
,
char
**
argv
)
{
uint32_t
enabled_encodings
=
0
;
enum
{
MODE_UNKNOWN
,
MODE_GENERATE_RANDOM_DATA
,
MODE_CHECK_RANDOM_ROUNDTRIP
MODE_CHECK_RANDOM_ROUNDTRIP
,
MODE_CHECK_COPY_OP
}
mode
=
MODE_UNKNOWN
;
const
char
*
generate_into_dir
=
NULL
;
int
iterations
=
100
;
...
...
@@ -340,7 +413,7 @@ int main(int argc, char **argv) {
int
debug
=
0
;
int
c
;
while
((
c
=
getopt
(
argc
,
argv
,
"cde:g:hn:s:"
))
!=
-
1
)
{
while
((
c
=
getopt
(
argc
,
argv
,
"cde:g:hn:s:
y
"
))
!=
-
1
)
{
switch
(
c
)
{
case
'c'
:
mode
=
MODE_CHECK_RANDOM_ROUNDTRIP
;
...
...
@@ -377,6 +450,9 @@ int main(int argc, char **argv) {
}
max_random_value_size
=
atoi
(
optarg
);
break
;
case
'y'
:
mode
=
MODE_CHECK_COPY_OP
;
break
;
default:
usage
(
argv
[
0
]);
exit
(
2
);
...
...
@@ -408,6 +484,10 @@ int main(int argc, char **argv) {
check_random_roundtrip
(
syntax
,
max_random_value_size
,
iterations
,
debug
);
break
;
case
MODE_CHECK_COPY_OP
:
check_copy_op
(
syntax
,
max_random_value_size
,
iterations
,
debug
);
break
;
}
}
}
...
...
tests/tests-skeletons/Makefile.am
View file @
edfc7e7f
...
...
@@ -4,6 +4,7 @@ check_PROGRAMS = \
check-ber_tlv_tag
\
check-length
\
check-bits
\
check-copy
\
check-OIDs
\
check-GeneralizedTime
\
check-OCTET_STRING
\
...
...
@@ -27,6 +28,7 @@ check_PROGRAMS += \
check-32-ber_tlv_tag
\
check-32-length
\
check-32-bits
\
check-32-copy
\
check-32-OIDs
\
check-32-GeneralizedTime
\
check-32-OCTET_STRING
\
...
...
@@ -54,6 +56,9 @@ check_32_length_SOURCES=check-length.c
check_32_bits_CFLAGS
=
$(CFLAGS_M32)
check_32_bits_LDADD
=
$(LDADD_32)
check_32_bits_SOURCES
=
check-bits.c
check_32_copy_CFLAGS
=
$(CFLAGS_M32)
check_32_copy_LDADD
=
$(LDADD_32)
check_32_copy_SOURCES
=
check-copy.c
check_32_OIDs_CFLAGS
=
$(CFLAGS_M32)
check_32_OIDs_LDADD
=
$(LDADD_32)
check_32_OIDs_SOURCES
=
check-OIDs.c
...
...
tests/tests-skeletons/check-copy.c
0 → 100644
View file @
edfc7e7f
#include <stdio.h>
#include <assert.h>
#include <OCTET_STRING.c>
#include <BIT_STRING.c>
#include <INTEGER.c>
#include <BOOLEAN.c>
#include <NULL.c>
#include <REAL.c>
#define check(td, a, b) test(__LINE__, td, a, b)
static
int
copy
(
asn_TYPE_descriptor_t
*
td
,
void
**
a
,
const
void
*
b
)
{
return
asn_copy
(
td
,
a
,
b
)
!=
0
;
}
static
int
compare
(
asn_TYPE_descriptor_t
*
td
,
void
*
a
,
void
*
b
)
{
return
td
->
op
->
compare_struct
(
td
,
a
,
b
)
!=
0
;
}
static
int
test
(
int
lineno
,
asn_TYPE_descriptor_t
*
td
,
void
**
a
,
void
*
b
)
{
int
rv
;
rv
=
copy
(
td
,
a
,
b
);
if
(
rv
)
{
fprintf
(
stderr
,
"%03d: copy() failed
\n
"
,
lineno
);
assert
(
rv
==
0
);
}
rv
=
compare
(
td
,
*
a
,
b
);
if
(
rv
)
{
fprintf
(
stderr
,
"%03d: compare() failed
\n
"
,
lineno
);
assert
(
rv
==
0
);
}
ASN_STRUCT_FREE
(
*
td
,
*
a
);
ASN_STRUCT_FREE_CONTENTS_ONLY
(
*
td
,
b
);
return
0
;
}
int
main
(
int
ac
,
char
**
av
)
{
(
void
)
ac
;
(
void
)
av
;
/* OCTET STRING */
{
OCTET_STRING_t
b
=
{
0
};
OCTET_STRING_fromBuf
(
&
b
,
"Hello"
,
5
);
OCTET_STRING_t
*
a
=
NULL
;
check
(
&
asn_DEF_OCTET_STRING
,
(
void
**
)
&
a
,
&
b
);
}
/* INTEGER */
{
INTEGER_t
b
=
{
0
};
asn_ulong2INTEGER
(
&
b
,
123
);
INTEGER_t
*
a
=
NULL
;
check
(
&
asn_DEF_INTEGER
,
(
void
**
)
&
a
,
&
b
);
}
{
INTEGER_t
b
=
{
0
};
INTEGER_t
*
a
=
NULL
;
check
(
&
asn_DEF_INTEGER
,
(
void
**
)
&
a
,
&
b
);
}
/* BIT STRING */
{
BIT_STRING_t
b
=
{
0
};
b
.
buf
=
MALLOC
(
2
);
b
.
size
=
2
;
b
.
buf
[
0
]
=
0x80
;
b
.
buf
[
1
]
=
0x02
;
b
.
bits_unused
=
1
;
BIT_STRING_t
*
a
=
NULL
;
check
(
&
asn_DEF_BIT_STRING
,
(
void
**
)
&
a
,
&
b
);
}
/* BOOLEAN */
{
BOOLEAN_t
b
=
{
0
};
b
=
1
;
BIT_STRING_t
*
a
=
NULL
;
check
(
&
asn_DEF_BOOLEAN
,
(
void
**
)
&
a
,
&
b
);
}
/* NULL */
{
NULL_t
b
=
{
0
};
NULL_t
*
a
=
NULL
;
check
(
&
asn_DEF_NULL
,
(
void
**
)
&
a
,
&
b
);
}
/* REAL */
{
REAL_t
b
=
{
0
};
asn_double2REAL
(
&
b
,
123
.
456
);
REAL_t
*
a
=
NULL
;
check
(
&
asn_DEF_REAL
,
(
void
**
)
&
a
,
&
b
);
}
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment