diff options
Diffstat (limited to 'libctf/testsuite')
10 files changed, 164 insertions, 18 deletions
diff --git a/libctf/testsuite/libctf-lookup/add-to-opened.c b/libctf/testsuite/libctf-lookup/add-to-opened.c index 96629af..700257e 100644 --- a/libctf/testsuite/libctf-lookup/add-to-opened.c +++ b/libctf/testsuite/libctf-lookup/add-to-opened.c @@ -15,7 +15,7 @@ main (int argc, char *argv[]) ctf_encoding_t en = { CTF_INT_SIGNED, 0, sizeof (int) }; unsigned char *ctf_written; size_t size; - int err; + int err = 666; if (argc != 2) { @@ -25,9 +25,18 @@ main (int argc, char *argv[]) if ((ctf = ctf_open (argv[1], NULL, &err)) == NULL) goto open_err; + + /* The error int should be reset on success as well as on error. */ + if (err != 0) + goto err_err; + + err = 666; if ((fp = ctf_dict_open (ctf, NULL, &err)) == NULL) goto open_err; + if (err != 0) + goto err_err; + /* Check that various modifications to already-written types are prohibited. */ @@ -145,4 +154,8 @@ main (int argc, char *argv[]) open_err: fprintf (stderr, "%s: cannot open: %s\n", argv[0], ctf_errmsg (err)); return 1; + + err_err: + fprintf (stderr, "%s: open error not set to success on success\n", argv[0]); + return 1; } diff --git a/libctf/testsuite/libctf-lookup/struct-iteration-ctf.c b/libctf/testsuite/libctf-lookup/struct-iteration-ctf.c index 7df67ad..0a50d2c 100644 --- a/libctf/testsuite/libctf-lookup/struct-iteration-ctf.c +++ b/libctf/testsuite/libctf-lookup/struct-iteration-ctf.c @@ -6,12 +6,12 @@ struct foo_t size_t bar; const char *baz; struct foo_t *self; - union + const volatile union { double should_not_appear; char *nor_should_this; } named; - struct + volatile const struct { long unnamed_sub_member; union @@ -19,6 +19,9 @@ struct foo_t double one_more_level; long yes_really_one_more; }; + struct { + int and_finally; + }; }; struct {}; /* Empty ones */ union {}; diff --git a/libctf/testsuite/libctf-lookup/struct-iteration.c b/libctf/testsuite/libctf-lookup/struct-iteration.c index b240864..fd89ca7 100644 --- a/libctf/testsuite/libctf-lookup/struct-iteration.c +++ b/libctf/testsuite/libctf-lookup/struct-iteration.c @@ -51,11 +51,29 @@ main (int argc, char *argv[]) while ((offset = ctf_member_next (fp, type, &i, &name, &membtype, CTF_MN_RECURSE)) >= 0) { + ctf_membinfo_t memb; char *type_name = ctf_type_aname (fp, membtype); printf ("next test: %s, offset %zx, has type %lx/%s\n", name, offset, membtype, type_name); free (type_name); + + /* Check that we can get the same member via ctf_member_info too. */ + if (name[0] != '\0') + { + if (ctf_member_info (fp, type, name, &memb) != 0) + { + fprintf (stderr, "Cannot get member info for %s: %s\n", + name, ctf_errmsg (ctf_errno (fp))); + exit (1); + } + if (memb.ctm_offset != offset || memb.ctm_type != membtype) + { + fprintf (stderr, "ctf_member_info versus iteration comparison " + "failure: types %lx/%lx, offsets %zx/%lx\n", + membtype, memb.ctm_type, offset, memb.ctm_offset); + } + } } if (ctf_errno (fp) != ECTF_NEXT_END) goto nerr; diff --git a/libctf/testsuite/libctf-lookup/struct-iteration.lk b/libctf/testsuite/libctf-lookup/struct-iteration.lk index fd64454..aecffd4 100644 --- a/libctf/testsuite/libctf-lookup/struct-iteration.lk +++ b/libctf/testsuite/libctf-lookup/struct-iteration.lk @@ -4,8 +4,8 @@ iter test: foo, offset [0-9a-f]*, has type [0-9a-f]*/int iter test: bar, offset [0-9a-f]*, has type [0-9a-f]*/size_t iter test: baz, offset [0-9a-f]*, has type [0-9a-f]*/const char \* iter test: self, offset [0-9a-f]*, has type [0-9a-f]*/struct foo_t \* -iter test: named, offset [0-9a-f]*, has type [0-9a-f]*/union -iter test: , offset [0-9a-f]*, has type [0-9a-f]*/struct +iter test: named, offset [0-9a-f]*, has type [0-9a-f]*/volatile const union +iter test: , offset [0-9a-f]*, has type [0-9a-f]*/volatile const struct iter test: , offset [0-9a-f]*, has type [0-9a-f]*/struct iter test: , offset [0-9a-f]*, has type [0-9a-f]*/union iter test: after_the_end, offset [0-9a-f]*, has type [0-9a-f]*/int @@ -13,12 +13,14 @@ next test: foo, offset [0-9a-f]*, has type [0-9a-f]*/int next test: bar, offset [0-9a-f]*, has type [0-9a-f]*/size_t next test: baz, offset [0-9a-f]*, has type [0-9a-f]*/const char \* next test: self, offset [0-9a-f]*, has type [0-9a-f]*/struct foo_t \* -next test: named, offset [0-9a-f]*, has type [0-9a-f]*/union -next test: , offset [0-9a-f]*, has type [0-9a-f]*/struct +next test: named, offset [0-9a-f]*, has type [0-9a-f]*/volatile const union +next test: , offset [0-9a-f]*, has type [0-9a-f]*/volatile const struct next test: unnamed_sub_member, offset [0-9a-f]*, has type [0-9a-f]*/long int next test: , offset [0-9a-f]*, has type [0-9a-f]*/union next test: one_more_level, offset [0-9a-f]*, has type [0-9a-f]*/double next test: yes_really_one_more, offset [0-9a-f]*, has type [0-9a-f]*/long int next test: , offset [0-9a-f]*, has type [0-9a-f]*/struct +next test: and_finally, offset [0-9a-f]*, has type [0-9a-f]*/int +next test: , offset [0-9a-f]*, has type [0-9a-f]*/struct next test: , offset [0-9a-f]*, has type [0-9a-f]*/union next test: after_the_end, offset [0-9a-f]*, has type [0-9a-f]*/int diff --git a/libctf/testsuite/libctf-writable/ctf-compressed.c b/libctf/testsuite/libctf-writable/ctf-compressed.c index 4769cdb..646b603 100644 --- a/libctf/testsuite/libctf-writable/ctf-compressed.c +++ b/libctf/testsuite/libctf-writable/ctf-compressed.c @@ -119,10 +119,14 @@ main (int argc, char *argv[]) /* Dump the header of each archive member, and search for CTF_F_COMPRESS in the resulting dump. */ + err = 666; while ((dump_fp = ctf_archive_next (final_arc, &i, NULL, 0, &err)) != NULL) { char *dumpstr; + if (err != 0) + fprintf (stderr, "err not set to success on success\n"); + while ((dumpstr = ctf_dump (dump_fp, &dump_state, CTF_SECT_HEADER, NULL, NULL)) != NULL) { diff --git a/libctf/testsuite/libctf-writable/ctf-nonroot-addition.c b/libctf/testsuite/libctf-writable/ctf-nonroot-addition.c new file mode 100644 index 0000000..94ce05c --- /dev/null +++ b/libctf/testsuite/libctf-writable/ctf-nonroot-addition.c @@ -0,0 +1,38 @@ +/* Make sure adding a non-root-visible type after adding a root-visible forward + adds a new type rather than promoting and returning the existing one. */ + +#include <ctf-api.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int +main (int argc, char *argv[]) +{ + ctf_dict_t *fp; + ctf_id_t root, nonroot; + int err; + + if ((fp = ctf_create (&err)) == NULL) + { + fprintf (stderr, "Cannot create: %s\n", ctf_errmsg (err)); + return 1; + } + + if ((root = ctf_add_forward (fp, CTF_ADD_ROOT, "foo", CTF_K_ENUM)) == CTF_ERR) + goto add_err; + + if ((nonroot = ctf_add_enum (fp, CTF_ADD_NONROOT, "foo")) == CTF_ERR) + goto add_err; + + if (nonroot == root) + fprintf (stderr, "Non-root addition should not promote root-visible forwards\n"); + else + printf ("All done.\n"); + + ctf_dict_close (fp); + return 0; + + add_err: + fprintf (stderr, "Cannot add: %s\n", ctf_errmsg (ctf_errno (fp))); +} diff --git a/libctf/testsuite/libctf-writable/ctf-nonroot-addition.lk b/libctf/testsuite/libctf-writable/ctf-nonroot-addition.lk new file mode 100644 index 0000000..b944f73 --- /dev/null +++ b/libctf/testsuite/libctf-writable/ctf-nonroot-addition.lk @@ -0,0 +1 @@ +All done. diff --git a/libctf/testsuite/libctf-writable/ctf-nonroot-linking.c b/libctf/testsuite/libctf-writable/ctf-nonroot-linking.c index 6edd189..67b85eb 100644 --- a/libctf/testsuite/libctf-writable/ctf-nonroot-linking.c +++ b/libctf/testsuite/libctf-writable/ctf-nonroot-linking.c @@ -24,16 +24,6 @@ main (int argc, char *argv[]) ctf_next_t *i = NULL; int err; - /* Linking does not currently work on mingw because of an unreliable tmpfile - implementation on that platform (see - https://github.com/msys2/MINGW-packages/issues/18878). Simply skip for - now. */ - -#ifdef __MINGW32__ - printf ("UNSUPPORTED: platform bug breaks ctf_link\n"); - return 0; -#else - if ((fp = ctf_create (&err)) == NULL) goto create_err; @@ -123,5 +113,4 @@ main (int argc, char *argv[]) link_err: fprintf (stderr, "Cannot link: %s\n", ctf_errmsg (ctf_errno (fp))); return 1; -#endif } diff --git a/libctf/testsuite/libctf-writable/slice-of-slice.c b/libctf/testsuite/libctf-writable/slice-of-slice.c new file mode 100644 index 0000000..9bacfe2 --- /dev/null +++ b/libctf/testsuite/libctf-writable/slice-of-slice.c @@ -0,0 +1,77 @@ +/* Make sure that slices of slices are properly resolved. If they're not, both + population and lookup will fail. */ + +#include <ctf-api.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int main (void) +{ + ctf_dict_t *fp; + ctf_id_t base; + ctf_id_t slice; + ctf_id_t slice2; + ctf_encoding_t long_encoding = { CTF_INT_SIGNED, 0, sizeof (long) }; + ctf_encoding_t foo; + int val; + int err; + + if ((fp = ctf_create (&err)) == NULL) + { + fprintf (stderr, "Cannot create: %s\n", ctf_errmsg (err)); + return 1; + } + + if ((base = ctf_add_enum_encoded (fp, CTF_ADD_ROOT, "enom", &long_encoding)) + == CTF_ERR) + goto err; + + if (ctf_add_enumerator (fp, base, "a", 1) < 0 || + ctf_add_enumerator (fp, base, "b", 0) < 0) + goto err; + + foo.cte_format = 0; + foo.cte_bits = 4; + foo.cte_offset = 4; + if ((slice = ctf_add_slice (fp, CTF_ADD_ROOT, base, &foo)) == CTF_ERR) + goto err; + + foo.cte_bits = 6; + foo.cte_offset = 2; + if ((slice2 = ctf_add_slice (fp, CTF_ADD_ROOT, slice, &foo)) == CTF_ERR) + goto err; + + if (ctf_add_variable (fp, "foo", slice) < 0) + goto err; + + if (ctf_enum_value (fp, slice, "a", &val) < 0) + { + fprintf (stderr, "Cannot look up value of sliced enum: %s\n", ctf_errmsg (ctf_errno (fp))); + return 1; + } + if (val != 1) + { + fprintf (stderr, "sliced enum value is wrong\n"); + return 1; + } + + if (ctf_enum_value (fp, slice2, "b", &val) < 0) + { + fprintf (stderr, "Cannot look up value of sliced sliced enum: %s\n", ctf_errmsg (ctf_errno (fp))); + return 1; + } + if (val != 0) + { + fprintf (stderr, "sliced sliced enum value is wrong\n"); + return 1; + } + + ctf_dict_close (fp); + fprintf (stderr, "All done.\n"); + return 0; + + err: + fprintf (stderr, "cannot populate: %s\n", ctf_errmsg (ctf_errno (fp))); + return 1; +} diff --git a/libctf/testsuite/libctf-writable/slice-of-slice.lk b/libctf/testsuite/libctf-writable/slice-of-slice.lk new file mode 100644 index 0000000..b944f73 --- /dev/null +++ b/libctf/testsuite/libctf-writable/slice-of-slice.lk @@ -0,0 +1 @@ +All done. |