Skip to content

Commit

Permalink
12229 fix ctf test check-qualifiers for clang
Browse files Browse the repository at this point in the history
12230 clang optimizer defeats ctf test suite
12231 ctf tests should not pass -h directly to clang
12232 fix clang compiler warnings in the ctf test suite
13348 ctftest should skip known failures with clang
13350 some ctf tests still rely on default compiler arch
13349 ctf tests should specify -fcommon when needed
Reviewed by: Andy Fiddaman <andy@omnios.org>
Reviewed by: Toomas Soome <tsoome@me.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
  • Loading branch information
rmustacc committed Dec 15, 2020
1 parent 1381033 commit 3cec982
Show file tree
Hide file tree
Showing 17 changed files with 239 additions and 49 deletions.
16 changes: 8 additions & 8 deletions usr/src/test/util-tests/tests/ctf/Makefile.ctftest.com
Expand Up @@ -56,33 +56,33 @@ BINS = $(CONV32) \
build: $(BINS)

$(BUILDDIR)/%.32.c.o: %.c
$(CC) $(CFLAGS32) $(DEBUGFLAGS) -o $@ -c $<
$(CC) $(CFLAGS32) $(TEST_CFLAGS32) $(DEBUGFLAGS) -o $@ -c $<

$(BUILDDIR)/%.64.c.o: %.c
$(CC) $(CFLAGS64) $(DEBUGFLAGS) -o $@ -c $<
$(CC) $(CFLAGS64) $(TEST_CFLAGS64) $(DEBUGFLAGS) -o $@ -c $<

$(BUILDDIR)/%.32.m.o: %.c
$(CC) $(CFLAGS32) $(DEBUGFLAGS) -o $@ -c $<
$(CC) $(CFLAGS32) $(TEST_CFLAGS32) $(DEBUGFLAGS) -o $@ -c $<
$(CTFCONVERT) $@

$(BUILDDIR)/%.64.m.o: %.c
$(CC) $(CFLAGS64) $(DEBUGFLAGS) -o $@ -c $<
$(CC) $(CFLAGS64) $(TEST_CFLAGS64) $(DEBUGFLAGS) -o $@ -c $<
$(CTFCONVERT) $@

$(CONV32): $(OBJS_C_32)
$(CC) $(CFLAGS32) $(DEBUGFLAGS) -o $@ $(OBJS_C_32)
$(CC) $(CFLAGS32) $(TEST_CFLAGS32) $(DEBUGFLAGS) -o $@ $(OBJS_C_32)
$(CTFCONVERT) $@

$(CONV64): $(OBJS_C_64)
$(CC) $(CFLAGS64) $(DEBUGFLAGS) -o $@ $(OBJS_C_64)
$(CC) $(CFLAGS64) $(TEST_CFLAGS64) $(DEBUGFLAGS) -o $@ $(OBJS_C_64)
$(CTFCONVERT) $@

$(MERGE32): $(OBJS_M_32)
$(CC) $(CFLAGS32) $(DEBUGFLAGS) -o $@ $(OBJS_M_32)
$(CC) $(CFLAGS32) $(TEST_CFLAGS32) $(DEBUGFLAGS) -o $@ $(OBJS_M_32)
$(CTFMERGE) -t -o $@ $(OBJS_M_32)

$(MERGE64): $(OBJS_M_64)
$(CC) $(CFLAGS64) $(DEBUGFLAGS) -o $@ $(OBJS_M_64)
$(CC) $(CFLAGS64) $(TEST_CFLAGS64) $(DEBUGFLAGS) -o $@ $(OBJS_M_64)
$(CTFMERGE) -t -o $@ $(OBJS_M_64)

run-test:
Expand Down
26 changes: 26 additions & 0 deletions usr/src/test/util-tests/tests/ctf/check-common.c
Expand Up @@ -142,6 +142,12 @@ ctftest_check_numbers(ctf_file_t *fp, const check_number_t *tests)
ctf_id_t id;
ctf_encoding_t enc;

if (ctftest_skip(tests[i].cn_skips)) {
warnx("skipping check numbers test %s due to known "
"compiler issue", tests[i].cn_tname);
continue;
}

id = ctftest_lookup_type(fp, tests[i].cn_tname);
if (id == CTF_ERR) {
warnx("failed to look up %s", tests[i].cn_tname);
Expand Down Expand Up @@ -842,3 +848,23 @@ ctftest_duplicates(ctf_file_t *fp)

return (d.ctd_ret);
}

boolean_t
ctftest_skip(check_skip_t skip)
{
const char *compiler;

if (skip == 0) {
return (B_FALSE);
}

compiler = getenv("ctf_cc_type");
if (compiler == NULL) {
return (B_FALSE);
}

if ((skip & SKIP_CLANG) != 0 && strcmp(compiler, "clang") == 0)
return (B_TRUE);

return (B_FALSE);
}
17 changes: 17 additions & 0 deletions usr/src/test/util-tests/tests/ctf/check-common.h
Expand Up @@ -31,12 +31,23 @@
extern "C" {
#endif

/*
* A set of bits that can be set on tests to indicate that the test should be
* skipped when dealing with a certain compiler. These should be added as
* needed. Right now this is here because of the clang bitfield bug that is
* triggered by check-sou.c.
*/
typedef enum {
SKIP_CLANG = 1 << 0
} check_skip_t;

typedef struct check_number {
const char *cn_tname;
uint_t cn_kind;
uint_t cn_flags;
uint_t cn_offset;
uint_t cn_size;
check_skip_t cn_skips;
} check_number_t;

typedef struct check_symbol {
Expand Down Expand Up @@ -77,6 +88,7 @@ typedef struct check_member_test {
int cmt_kind;
size_t cmt_size;
const check_member_t *cmt_members;
check_skip_t cmt_skips;
} check_member_test_t;

typedef struct check_function_test {
Expand Down Expand Up @@ -144,6 +156,11 @@ extern boolean_t ctftest_check_size(const char *, ctf_file_t *, size_t);
*/
extern boolean_t ctftest_duplicates(ctf_file_t *);

/*
* Determine whether or not we should skip a given test.
*/
extern boolean_t ctftest_skip(check_skip_t);

#ifdef __cplusplus
}
#endif
Expand Down
43 changes: 43 additions & 0 deletions usr/src/test/util-tests/tests/ctf/check-qualifiers.c
Expand Up @@ -120,9 +120,18 @@ static check_descent_t check_descent_cv_int_array_gcc7[] = {
{ NULL }
};

static check_descent_t check_descent_cv_int_array_clang9[] = {
{ "const volatile int [13]", CTF_K_ARRAY, "const volatile int", 13 },
{ "const volatile int", CTF_K_CONST },
{ "volatile int", CTF_K_VOLATILE },
{ "int", CTF_K_INTEGER },
{ NULL }
};

static check_descent_test_t alt_descents_cv_int_array[] = {
{ "cv_int_array", check_descent_cv_int_array_gcc4 },
{ "cv_int_array", check_descent_cv_int_array_gcc7 },
{ "cv_int_array", check_descent_cv_int_array_clang9 },
{ NULL }
};

Expand All @@ -142,9 +151,18 @@ static check_descent_t check_descent_vc_int_array_gcc7[] = {
{ NULL }
};

static check_descent_t check_descent_vc_int_array_clang9[] = {
{ "const volatile int [15]", CTF_K_ARRAY, "const volatile int", 15 },
{ "const volatile int", CTF_K_CONST },
{ "volatile int", CTF_K_VOLATILE },
{ "int", CTF_K_INTEGER },
{ NULL }
};

static check_descent_test_t alt_descents_vc_int_array[] = {
{ "vc_int_array", check_descent_vc_int_array_gcc4 },
{ "vc_int_array", check_descent_vc_int_array_gcc7 },
{ "vc_int_array", check_descent_vc_int_array_clang9 },
{ NULL }
};

Expand All @@ -164,9 +182,19 @@ static check_descent_t check_descent_vc_int_array2_gcc7[] = {
{ NULL }
};

static check_descent_t check_descent_vc_int_array2_clang9[] = {
{ "const volatile int [17]", CTF_K_ARRAY, "const volatile int", 17 },
{ "const volatile int", CTF_K_CONST },
{ "volatile int", CTF_K_VOLATILE },
{ "int", CTF_K_INTEGER },
{ NULL }
};


static check_descent_test_t alt_descents_vc_int_array2[] = {
{ "vc_int_array2", check_descent_vc_int_array2_gcc4 },
{ "vc_int_array2", check_descent_vc_int_array2_gcc7 },
{ "vc_int_array2", check_descent_vc_int_array2_clang9 },
{ NULL }
};

Expand Down Expand Up @@ -214,9 +242,24 @@ static check_descent_t check_descent_cv_3d_array_gcc7[] = {
{ NULL }
};

static check_descent_t check_descent_cv_3d_array_clang9[] = {
{ "const volatile int [3][2][1]", CTF_K_ARRAY,
"const volatile int [2][1]", 3 },
{ "const volatile int [2][1]", CTF_K_ARRAY,
"const volatile int [1]", 2 },
{ "const volatile int [1]", CTF_K_ARRAY,
"const volatile int", 1 },
{ "const volatile int", CTF_K_CONST },
{ "volatile int", CTF_K_VOLATILE },
{ "int", CTF_K_INTEGER },
{ NULL }
};


static check_descent_test_t alt_descents_cv_3d_array[] = {
{ "cv_3d_array", check_descent_cv_3d_array_gcc4 },
{ "cv_3d_array", check_descent_cv_3d_array_gcc7 },
{ "cv_3d_array", check_descent_cv_3d_array_clang9 },
{ NULL }
};

Expand Down
19 changes: 17 additions & 2 deletions usr/src/test/util-tests/tests/ctf/check-sou.c
Expand Up @@ -41,7 +41,11 @@ static check_number_t check_bitfields[] = {
#endif
{ "unsigned short:1", CTF_K_INTEGER, 0, 0, 1 },
{ "unsigned int:7", CTF_K_INTEGER, 0, 0, 7 },
{ "unsigned int:32", CTF_K_INTEGER, 0, 0, 32 },
/*
* Skipped on clang as it doesn't process csts correctly. See
* check_members_csts.
*/
{ "unsigned int:32", CTF_K_INTEGER, 0, 0, 32, SKIP_CLANG },
{ "int:3", CTF_K_INTEGER, CTF_INT_SIGNED, 0, 3 },
{ NULL }
};
Expand Down Expand Up @@ -233,6 +237,10 @@ static check_member_t check_member_rings[] = {
{ NULL }
};

/*
* Unfortunately this test case fails with clang in at least versions 8-10. See
* https://bugs.llvm.org/show_bug.cgi?id=44601 for more information on the bug.
*/
static check_member_t check_member_csts[] = {
{ "rdy", "unsigned int:7", 0 },
{ "csts", "unsigned int:32", 7 },
Expand Down Expand Up @@ -317,7 +325,7 @@ static check_member_test_t members[] = {
{ "struct stats", CTF_K_STRUCT, 16, check_member_stats },
{ "struct fellowship", CTF_K_STRUCT, 2, check_member_fellowship },
{ "struct rings", CTF_K_STRUCT, 8, check_member_rings },
{ "struct csts", CTF_K_STRUCT, 5, check_member_csts },
{ "struct csts", CTF_K_STRUCT, 5, check_member_csts, SKIP_CLANG },
{ "union jrpg", CTF_K_UNION, 32, check_member_jrpg },
{ "struct android", CTF_K_STRUCT, 4, check_member_android },
{ "union nier", CTF_K_UNION, 4, check_member_nier },
Expand Down Expand Up @@ -422,6 +430,13 @@ main(int argc, char *argv[])
}

for (j = 0; members[j].cmt_type != NULL; j++) {
if (ctftest_skip(members[j].cmt_skips)) {
warnx("skipping members test %s due to "
"known compiler issue",
members[j].cmt_type);
continue;
}

if (!ctftest_check_members(members[j].cmt_type, fp,
members[j].cmt_kind, members[j].cmt_size,
members[j].cmt_members)) {
Expand Down
46 changes: 27 additions & 19 deletions usr/src/test/util-tests/tests/ctf/ctftest-convert-no-dwarf.ksh
Expand Up @@ -18,6 +18,14 @@ result=0

progname=$(basename $0)

#
# The assembler and compiler may not end up using the same architecture
# (e.g. 32-bit or 64-bit) by default. So we force this to always be
# consistent.
#
cflags="-m64"
asflags="--64"

fail()
{
echo "Failed: $*" 2>&1
Expand Down Expand Up @@ -62,12 +70,12 @@ has_ctf()
cat <<EOF >file1.c
#include <stdio.h>
struct foo { int a; };
int main(void) { struct foo foo = { 4 }; printf("%d\n", foo.a); }
int main(void) { struct foo foo = { 4 }; printf("%d\n", foo.a); return (0); }
EOF

cat <<EOF >file2.c
#include <stdio.h>
char myfunc(int a) { printf("%d\n", a); }
char myfunc(int a) { printf("%d\n", a); return ('a'); }
EOF

cat <<EOF >file3.cc
Expand All @@ -86,34 +94,34 @@ EOF
echo "$progname: An empty file should fail conversion due to no DWARF"
echo >emptyfile.c

$ctf_cc -c -o emptyfile.o emptyfile.c
$ctf_cc $cflags -c -o emptyfile.o emptyfile.c
fail_no_debug emptyfile.o
$ctf_cc -c -o emptyfile.o emptyfile.c
$ctf_cc $cflags -c -o emptyfile.o emptyfile.c
$ctf_convert -m emptyfile.o

$ctf_cc $ctf_debugflags -c -o emptyfile.o emptyfile.c
$ctf_cc $cflags $ctf_debugflags -c -o emptyfile.o emptyfile.c
fail_no_debug emptyfile.o
$ctf_cc $ctf_debugflags -c -o emptyfile.o emptyfile.c
$ctf_cc $cflags $ctf_debugflags -c -o emptyfile.o emptyfile.c
$ctf_convert -m emptyfile.o

echo "$progname: A file missing DWARF should fail conversion"

$ctf_cc -c -o file1.o file1.c
$ctf_cc $cflags -c -o file1.o file1.c
fail_no_debug file1.o
$ctf_cc -c -o file1.o file1.c
$ctf_cc $cflags -c -o file1.o file1.c
$ctf_convert -m file1.o

echo "$progname: A binary with DWARF but 0 debug dies should fail conversion"

$ctf_cc -o mybin file1.c
$ctf_cc $cflags -o mybin file1.c
fail_no_debug mybin
$ctf_cc -o mybin file1.c
$ctf_cc $cflags -o mybin file1.c
$ctf_convert -m mybin

echo "$progname: One C file missing DWARF should fail ctfconvert"

$ctf_cc -c -o file1.o file1.c
$ctf_cc $ctf_debugflags -c -o file2.o file2.c
$ctf_cc $cflags -c -o file1.o file1.c
$ctf_cc $cflags $ctf_debugflags -c -o file2.o file2.c
ld -r -o files.o file2.o file1.o
fail_no_debug files.o
ld -r -o files.o file2.o file1.o
Expand All @@ -122,18 +130,18 @@ has_ctf files.o

echo "$progname: One .cc file missing DWARF should pass"

$ctf_cc $ctf_debugflags -c -o file1.o file1.c
$ctf_cc $ctf_debugflags -c -o file2.o file2.c
$ctf_cxx -c -o file3.o file3.cc
$ctf_cc $cflags $ctf_debugflags -c -o file1.o file1.c
$ctf_cc $cflags $ctf_debugflags -c -o file2.o file2.c
$ctf_cxx $cflags -c -o file3.o file3.cc
ld -r -o files.o file1.o file2.o file3.o
$ctf_convert files.o
has_ctf files.o

echo "$progname: One .s file missing DWARF should pass"
$ctf_cc $ctf_debugflags -c -o file1.o file1.c
$ctf_cc $ctf_debugflags -c -o file2.o file2.c
$ctf_as -o file4.o file4.s
$ctf_cc -o mybin file1.o file2.o file4.o
$ctf_cc $cflags $ctf_debugflags -c -o file1.o file1.c
$ctf_cc $cflags $ctf_debugflags -c -o file2.o file2.c
$ctf_as $asflags -o file4.o file4.s
$ctf_cc $cflags -o mybin file1.o file2.o file4.o
$ctf_convert mybin
has_ctf mybin

Expand Down
Expand Up @@ -59,7 +59,7 @@ no_ctf()
cat <<EOF >file1.c
#include <stdio.h>
struct foo { int a; };
int main(void) { struct foo foo = { 4 }; printf("%d\n", foo.a); }
int main(void) { struct foo foo = { 4 }; printf("%d\n", foo.a); return (0); }
EOF

cat <<EOF >file2.cc
Expand Down

0 comments on commit 3cec982

Please sign in to comment.