Skip to content

Commit

Permalink
OS-7386 Want primordial CTF test suite
Browse files Browse the repository at this point in the history
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: John Levon <john.levon@joyent.com>
Approved by: John Levon <john.levon@joyent.com>
  • Loading branch information
rmustacc committed Mar 21, 2019
1 parent 554f80e commit d8fc647
Show file tree
Hide file tree
Showing 50 changed files with 4,694 additions and 2 deletions.
4 changes: 2 additions & 2 deletions usr/src/test/util-tests/tests/Makefile
Expand Up @@ -14,11 +14,11 @@
# Copyright 2014 Garrett D'Amore <garrett@damore.org>
# Copyright 2014 Nexenta Systems, Inc. All rights reserved.
# Copyright 2017 Jason King
# Copyright 2018 Joyent, Inc.
# Copyright 2019 Joyent, Inc.
#

SUBDIRS = date dis dladm iconv libnvpair_json libsff printf xargs grep_xpg4
SUBDIRS += demangle mergeq workq chown
SUBDIRS += bunyan awk smbios libjedec
SUBDIRS += bunyan awk smbios libjedec ctf

include $(SRC)/test/Makefile.com
149 changes: 149 additions & 0 deletions usr/src/test/util-tests/tests/ctf/Makefile
@@ -0,0 +1,149 @@
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright (c) 2019, Joyent, Inc.
#

include $(SRC)/Makefile.master

ROOTOPTPKG = $(ROOT)/opt/util-tests
TESTDIR = $(ROOTOPTPKG)/tests/ctf

SCRIPTS = ctftest.ksh

TESTS = test-float.c \
test-reference.c \
test-int.c \
test-array.c \
test-enum.c \
test-forward.c \
test-sou.c \
test-function.c \
test-merge-static/Makefile.ctftest \
test-merge-static/test-a.c \
test-merge-static/test-b.c \
test-merge-static/test-c.c \
test-merge-static/test-d.c \
test-merge-static/test-main.c \
test-merge-forward/Makefile.ctftest \
test-merge-forward/test-impl.c \
test-merge-forward/test-merge.c \
test-merge-dedup/Makefile.ctftest \
test-merge-dedup/test-merge-1.c \
test-merge-dedup/test-merge-2.c \
test-merge-dedup/test-merge-3.c \
test-merge-dedup/test-merge-dedup.c \
test-merge-reduction/Makefile.ctftest \
test-merge-reduction/mapfile-vers \
test-merge-reduction/test-global.c \
test-merge-reduction/test-scoped.c \
test-merge-weak/Makefile.ctftest \
test-merge-weak/test-merge-weak.c \
test-weak.c \
Makefile.ctftest.com

MAKEDIRS = test-merge-static \
test-merge-forward \
test-merge-dedup \
test-merge-reduction \
test-merge-weak

CHECKS = check-float-32 \
check-float-64 \
check-int-32 \
check-int-64 \
check-reference \
check-array \
check-enum \
check-sou-32 \
check-sou-64 \
check-forward-32 \
check-forward-64 \
check-function \
check-merge-static \
check-merge-forward-32 \
check-merge-forward-64 \
check-merge-dedup \
check-merge-reduction \
check-merge-weak \
check-weak

COMMON_OBJS = check-common.o
ALL_OBJS = $(CHECKS:%=%.o) $(CHECKS:%-32=%.32.o) $(CHECKS:%-64=%.64.o) $(COMMON_OBJS)

ROOTTESTS = $(TESTS:%=$(TESTDIR)/%)
ROOTMAKEDIRS = $(MAKEDIRS:%=$(TESTDIR)/%)
ROOTCHECKS = $(CHECKS:%=$(TESTDIR)/%)
ROOTSCRIPTS = $(SCRIPTS:%.ksh=$(TESTDIR)/%)

ROOTTESTS := FILEMODE = 0444
ROOTCHECKS := FILEMODE = 0555
ROOTSCRIPTS := FILEMODE = 0555

include $(SRC)/cmd/Makefile.cmd
include $(SRC)/test/Makefile.com

LDLIBS += -lctf

check-merge-static := LDLIBS += -lelf

all: $(CHECKS)

install: all $(ROOTTESTS) $(ROOTCHECKS) $(ROOTSCRIPTS)

$(CHECKS): $(COMMON_OBJS)

clean:
$(RM) $(ALL_OBJS)

clobber: clean
$(RM) $(CHECKS)

$(ROOTTESTS): $(TESTDIR) $(ROOTMAKEDIRS) $(TESTS)
$(ROOTCHECKS): $(TESTDIR) $(CHECKS)
$(ROOTSCRIPTS): $(TESTDIR) $(SCRIPTS)

$(TESTDIR):
$(INS.dir)

$(ROOTMAKEDIRS):
$(INS.dir)

$(TESTDIR)/%: %
$(INS.file)

$(TESTDIR)/%: %.ksh
$(INS.rename)

%.o: %.c
$(COMPILE.c) -o $@ $<
$(POST_PROCESS_O)

%.32.o: %.c
$(COMPILE.c) -o $@ $<
$(POST_PROCESS_O)

%.64.o: %.c
$(COMPILE.c) -DTARGET_LP64 -o $@ $<
$(POST_PROCESS_O)

%-32: %.32.o
$(LINK.c) -o $@ $< $(COMMON_OBJS) $(LDLIBS)
$(POST_PROCESS)

%-64: %.64.o
$(LINK.c) -o $@ $< $(COMMON_OBJS) $(LDLIBS)
$(POST_PROCESS)

%: %.o
$(LINK.c) -o $@ $< $(COMMON_OBJS) $(LDLIBS)
$(POST_PROCESS)
92 changes: 92 additions & 0 deletions usr/src/test/util-tests/tests/ctf/Makefile.ctftest.com
@@ -0,0 +1,92 @@
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright 2019 Joyent, Inc.
#

#
# This Makefile is installed onto the target system and is used as part
# of the running tests. It is not used as part of the build.
#
# This makefile could be simplified substantially. However, it does
# everything explicitly to try and work with a wide variety of different
# makes.
#
# The following values should be passed in by the invoker of the
# Makefile:
#
# CC C Compiler to use
# CFLAGS32 32-bit CFLAGS
# CFLAGS64 64-bit CFLAGS
# CTFCONVERT Path to ctfconvert
# CTFMERGE Path to ctfmerge
# DEBUGFLAGS The set of debug flags to use
# BUILDDIR Directory things should be built in
# CHECK32 Program to check 32-bit output
# CHECK64 Program to check 64-bit output
#
# The following values should be set before building this:
#
# TEST The name of the test program
# OBJS_C_32 32-bit convert objects
# OBJS_C_64 64-bit convert objects
# OBJS_M_32 32-bit merge objects
# OBJS_M_64 64-bit merge objects
#

CONV32 = $(BUILDDIR)/$(TEST)-32c
CONV64 = $(BUILDDIR)/$(TEST)-64c
MERGE32 = $(BUILDDIR)/$(TEST)-32m
MERGE64 = $(BUILDDIR)/$(TEST)-64m

BINS = $(CONV32) \
$(CONV64) \
$(MERGE32) \
$(MERGE64)

build: $(BINS)

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

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

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

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

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

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

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

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

run-test:
$(CHECK32) $(CONV32)
$(CHECK64) $(CONV64)
$(CHECK32) $(MERGE32)
$(CHECK64) $(MERGE64)
54 changes: 54 additions & 0 deletions usr/src/test/util-tests/tests/ctf/README
@@ -0,0 +1,54 @@
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright (c) 2019, Joyent, Inc.
#

CTF Tests
---------

This directory contains a series of tests for the Compact C Type Format
(CTF). For each test program, there is a corresponding C program that
goes through and checks the CTF for various aspects. Due to the fact
that the CTF generated by compilers can change slightly, the tests have
been designed this way to try and make it work with as wide a variety of
programs as possible.

The test suite requires the following:

1. make
2. C Compiler (defaults to gcc)
3. A copy of ctfconvert

The source for a given program will be compiled on the target system and
then converted. This allows us to try the CTF tools against a wide
variety of different compilers or DWARF standards.

Caveats
-------

Right now the tests only pass when using gcc 4.x. The following are
known issues with the tests:

1. gcc7+ generates some different DWARF ordering, which causes some
tests to spuriously fail. These tests should be improved.

2. There are cases where gcc7+ appears to attribute things as being const
twice in DWARF which throw off the tests. The CTF tools likely should
work around this if we confirm that this is intentional.

3. Many tests will cause clang not to emit DWARF information because
clang infers that they cannot be used. The tests should be cleaned up in
these cases.

4. clang generated DWARF can confuse the CTF tools. The tools should be
fixed and additional regression tests should be added.

0 comments on commit d8fc647

Please sign in to comment.