de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore/*
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * This file and its contents are supplied under the terms of the
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Common Development and Distribution License ("CDDL"), version 1.0.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * You may only use this file in accordance with the terms of version
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * 1.0 of the CDDL.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore *
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * A full copy of the text of the CDDL should have accompanied this
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * source. A copy of the CDDL is also available via the Internet at
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * http://www.illumos.org/license/CDDL.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore/*
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Copyright 2015 Garrett D'Amore <garrett@damore.org>
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * Copyright 2016 Joyent, Inc.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore/*
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * This program tests symbol visibility in different compilation environments.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#include <stdio.h>
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#include <stdlib.h>
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#include <string.h>
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#include <errno.h>
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#include <err.h>
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#include <unistd.h>
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#include <sys/types.h>
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#include <sys/stat.h>
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#include <note.h>
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi#include <libcmdutils.h>
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#include <sys/wait.h>
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#include "test_common.h"
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorechar *dname;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorechar *cfile;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorechar *ofile;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorechar *lfile;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorechar *efile;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreconst char *sym = NULL;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int good_count = 0;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int fail_count = 0;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int full_count = 0;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int extra_debug = 0;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic char *compilation = "compilation.cfg";
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#if defined(_LP64)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#define MFLAG "-m64"
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#elif defined(_ILP32)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#define MFLAG "-m32"
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#endif
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreconst char *compilers[] = {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore "cc",
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore "gcc",
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore "/opt/SUNWspro/bin/cc",
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore "/opt/gcc/4.4.4/bin/gcc",
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore "/opt/sunstudio12.1/bin/cc",
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore "/opt/sfw/bin/gcc",
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore "/usr/local/bin/gcc",
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore NULL
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore};
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorechar *compiler = NULL;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreconst char *c89flags = NULL;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreconst char *c99flags = NULL;
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchiconst char *c11flags = NULL;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#define MAXENV 64 /* maximum number of environments (bitmask width) */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#define MAXHDR 10 /* maximum # headers to require to access symbol */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#define MAXARG 20 /* maximum # of arguments */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore#define WS " \t"
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int next_env = 0;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestruct compile_env {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *ce_name;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *ce_lang;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *ce_defs;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int ce_index;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore};
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic struct compile_env compile_env[MAXENV];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestruct env_group {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *eg_name;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore uint64_t eg_mask;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore struct env_group *eg_next;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore};
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchitypedef enum {
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi SYM_TYPE,
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi SYM_VALUE,
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi SYM_DEFINE,
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi SYM_FUNC
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi} sym_type_t;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestruct sym_test {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *st_name;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore sym_type_t st_type;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *st_hdrs[MAXHDR];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *st_rtype;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *st_atypes[MAXARG];
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi char *st_defval;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore uint64_t st_test_mask;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore uint64_t st_need_mask;
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi const char *st_prog;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore struct sym_test *st_next;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore};
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestruct env_group *env_groups = NULL;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestruct sym_test *sym_tests = NULL;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestruct sym_test **sym_insert = &sym_tests;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic char *
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoremystrdup(const char *s)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *r;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if ((r = strdup(s)) == NULL) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore perror("strdup");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore exit(1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (r);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic void *
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoremyzalloc(size_t sz)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore void *buf;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if ((buf = calloc(1, sz)) == NULL) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore perror("calloc");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore exit(1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (buf);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic void
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoremyasprintf(char **buf, const char *fmt, ...)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int rv;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore va_list va;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore va_start(va, fmt);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore rv = vasprintf(buf, fmt, va);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore va_end(va);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (rv < 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore perror("vasprintf");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore exit(1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic void
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreappend_sym_test(struct sym_test *st)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore *sym_insert = st;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore sym_insert = &st->st_next;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorefind_env_mask(const char *name, uint64_t *mask)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (int i = 0; i < MAXENV; i++) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (compile_env[i].ce_name != NULL &&
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore strcmp(compile_env[i].ce_name, name) == 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore *mask |= (1ULL << i);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (0);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (struct env_group *eg = env_groups; eg != NULL; eg = eg->eg_next) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (strcmp(name, eg->eg_name) == 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore *mask |= eg->eg_mask;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (0);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreexpand_env(char *list, uint64_t *mask, char **erritem)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *item;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (item = strtok(list, WS); item != NULL; item = strtok(NULL, WS)) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (find_env_mask(item, mask) < 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (erritem != NULL) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore *erritem = item;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (0);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreexpand_env_list(char *list, uint64_t *test, uint64_t *need, char **erritem)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore uint64_t mask = 0;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int act;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *item;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (item = strtok(list, WS); item != NULL; item = strtok(NULL, WS)) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore switch (item[0]) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore case '+':
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore act = 1;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore item++;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore break;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore case '-':
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore act = 0;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore item++;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore break;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore default:
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore act = 1;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore break;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore mask = 0;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (find_env_mask(item, &mask) < 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (erritem != NULL) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore *erritem = item;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore *test |= mask;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (act) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore *need |= mask;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore } else {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore *need &= ~(mask);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (0);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoredo_env(char **fields, int nfields, char **err)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *name;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *lang;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *defs;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (nfields != 3) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore myasprintf(err, "number of fields (%d) != 3", nfields);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (next_env >= MAXENV) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore myasprintf(err, "too many environments");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore name = fields[0];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore lang = fields[1];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore defs = fields[2];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore compile_env[next_env].ce_name = mystrdup(name);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore compile_env[next_env].ce_lang = mystrdup(lang);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore compile_env[next_env].ce_defs = mystrdup(defs);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore compile_env[next_env].ce_index = next_env;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore next_env++;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (0);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoredo_env_group(char **fields, int nfields, char **err)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *name;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *list;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore struct env_group *eg;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore uint64_t mask;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *item;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (nfields != 2) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore myasprintf(err, "number of fields (%d) != 2", nfields);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore name = fields[0];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore list = fields[1];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore mask = 0;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (expand_env(list, &mask, &item) < 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore myasprintf(err, "reference to undefined env %s", item);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore eg = myzalloc(sizeof (*eg));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore eg->eg_name = mystrdup(name);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore eg->eg_mask = mask;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore eg->eg_next = env_groups;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore env_groups = eg;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (0);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchistatic custr_t *st_custr;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic void
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreaddprogch(char c)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi if (custr_appendc(st_custr, c) == -1) {
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi perror("custr_appendc");
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi exit(1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic void
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreaddprogstr(char *s)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi if (custr_append(st_custr, s) == -1) {
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi perror("custr_append");
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi exit(1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic void
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreaddprogfmt(const char *fmt, ...)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore va_list va;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore va_start(va, fmt);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi if (custr_append_vprintf(st_custr, fmt, va) == -1) {
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi perror("custr_append_vprintf");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore exit(1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore va_end(va);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic void
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoremkprog(struct sym_test *st)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi char *s = NULL;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi custr_reset(st_custr);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (int i = 0; i < MAXHDR && st->st_hdrs[i] != NULL; i++) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogfmt("#include <%s>\n", st->st_hdrs[i]);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi if (st->st_rtype != NULL) {
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi for (s = st->st_rtype; *s; s++) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogch(*s);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi if (*s == '(') {
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi s++;
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi addprogch(*s);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi s++;
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi break;
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi addprogch(' ');
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore /* for function pointers, s is closing suffix, otherwise empty */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore switch (st->st_type) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore case SYM_TYPE:
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogstr("test_type;");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore break;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore case SYM_VALUE:
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogfmt("test_value%s;\n", s); /* s usually empty */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogstr("void\ntest_func(void)\n{\n");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogfmt("\ttest_value = %s;\n}", st->st_name);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore break;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi case SYM_DEFINE:
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi addprogfmt("#if !defined(%s)", st->st_name);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi if (st->st_defval != NULL)
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi addprogfmt("|| %s != %s", st->st_name, st->st_defval);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi addprogfmt("\n#error %s is not defined or has the wrong value",
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi st->st_name);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi addprogfmt("\n#endif\n");
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi break;
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore case SYM_FUNC:
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogstr("\ntest_func(");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (int i = 0; st->st_atypes[i] != NULL && i < MAXARG; i++) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int didname = 0;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (i > 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogstr(", ");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (strcmp(st->st_atypes[i], "void") == 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore didname = 1;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (strcmp(st->st_atypes[i], "") == 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore didname = 1;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogstr("void");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore /* print the argument list */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (char *a = st->st_atypes[i]; *a; a++) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (*a == '(' && a[1] == '*' && !didname) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogfmt("(*a%d", i);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore didname = 1;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore a++;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore } else if (*a == '[' && !didname) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogfmt("a%d[", i);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore didname = 1;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore } else {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogch(*a);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (!didname) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogfmt(" a%d", i);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (st->st_atypes[0] == NULL) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogstr("void");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore /*
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Close argument list, and closing ")" for func ptrs.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Note that for non-function pointers, s will be empty
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * below, otherwise it points to the trailing argument
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * list.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogfmt(")%s\n{\n\t", s);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (strcmp(st->st_rtype, "") != 0 &&
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore strcmp(st->st_rtype, "void") != 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogstr("return ");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore /* add the function call */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogfmt("%s(", st->st_name);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (int i = 0; st->st_atypes[i] != NULL && i < MAXARG; i++) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (strcmp(st->st_atypes[i], "") != 0 &&
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore strcmp(st->st_atypes[i], "void") != 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogfmt("%sa%d", i > 0 ? ", " : "", i);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogstr(");\n}");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore break;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore addprogch('\n');
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi st->st_prog = custr_cstr(st_custr);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreadd_envs(struct sym_test *st, char *envs, char **err)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *item;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (expand_env_list(envs, &st->st_test_mask, &st->st_need_mask,
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore &item) < 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore myasprintf(err, "bad env action %s", item);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (0);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreadd_headers(struct sym_test *st, char *hdrs, char **err)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int i = 0;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (char *h = strsep(&hdrs, ";"); h != NULL; h = strsep(&hdrs, ";")) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (i >= MAXHDR) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore myasprintf(err, "too many headers");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_trim(&h);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore st->st_hdrs[i++] = mystrdup(h);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (0);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreadd_arg_types(struct sym_test *st, char *atype, char **err)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int i = 0;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *a;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (a = strsep(&atype, ";"); a != NULL; a = strsep(&atype, ";")) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (i >= MAXARG) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore myasprintf(err, "too many arguments");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_trim(&a);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore st->st_atypes[i++] = mystrdup(a);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (0);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoredo_type(char **fields, int nfields, char **err)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *decl;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *hdrs;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *envs;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore struct sym_test *st;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (nfields != 3) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore myasprintf(err, "number of fields (%d) != 3", nfields);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore decl = fields[0];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore hdrs = fields[1];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore envs = fields[2];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore st = myzalloc(sizeof (*st));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore st->st_type = SYM_TYPE;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore st->st_name = mystrdup(decl);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore st->st_rtype = mystrdup(decl);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if ((add_envs(st, envs, err) < 0) ||
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (add_headers(st, hdrs, err) < 0)) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore append_sym_test(st);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (0);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoredo_value(char **fields, int nfields, char **err)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *name;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *type;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *hdrs;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *envs;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore struct sym_test *st;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (nfields != 4) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore myasprintf(err, "number of fields (%d) != 4", nfields);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore name = fields[0];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore type = fields[1];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore hdrs = fields[2];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore envs = fields[3];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore st = myzalloc(sizeof (*st));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore st->st_type = SYM_VALUE;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore st->st_name = mystrdup(name);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore st->st_rtype = mystrdup(type);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if ((add_envs(st, envs, err) < 0) ||
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (add_headers(st, hdrs, err) < 0)) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore append_sym_test(st);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (0);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchistatic int
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchido_define(char **fields, int nfields, char **err)
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi{
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi char *name, *value, *hdrs, *envs;
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi struct sym_test *st;
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi if (nfields != 4) {
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi myasprintf(err, "number of fields (%d) != 4", nfields);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi return (-1);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi }
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi name = fields[0];
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi value = fields[1];
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi hdrs = fields[2];
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi envs = fields[3];
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi st = myzalloc(sizeof (*st));
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi st->st_type = SYM_DEFINE;
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi st->st_name = mystrdup(name);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi /*
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * A value to compare against is optional. trim will leave it as a null
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi * pointer if there's nothing there.
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi */
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi test_trim(&value);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi if (*value != '\0')
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi st->st_defval = mystrdup(value);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi if ((add_envs(st, envs, err) < 0) ||
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi (add_headers(st, hdrs, err) < 0)) {
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi return (-1);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi }
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi append_sym_test(st);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi return (0);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi}
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoredo_func(char **fields, int nfields, char **err)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *name;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *rtype;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *atype;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *hdrs;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *envs;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore struct sym_test *st;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (nfields != 5) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore myasprintf(err, "number of fields (%d) != 5", nfields);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore name = fields[0];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore rtype = fields[1];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore atype = fields[2];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore hdrs = fields[3];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore envs = fields[4];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore st = myzalloc(sizeof (*st));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore st->st_type = SYM_FUNC;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore st->st_name = mystrdup(name);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore st->st_rtype = mystrdup(rtype);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if ((add_envs(st, envs, err) < 0) ||
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (add_headers(st, hdrs, err) < 0) ||
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (add_arg_types(st, atype, err) < 0)) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore append_sym_test(st);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (0);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestruct sym_test *
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorenext_sym_test(struct sym_test *st)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (st == NULL ? sym_tests : st->st_next);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreconst char *
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoresym_test_prog(struct sym_test *st)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (st->st_prog == NULL) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore mkprog(st);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (st->st_prog);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreconst char *
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoresym_test_name(struct sym_test *st)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (st->st_name);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore/*
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Iterate through tests. Pass in NULL for cenv to begin the iteration. For
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * subsequent iterations, use the return value from the previous iteration.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore * Returns NULL when there are no more environments.
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestruct compile_env *
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoresym_test_env(struct sym_test *st, struct compile_env *cenv, int *need)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int i = cenv ? cenv->ce_index + 1: 0;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore uint64_t b = 1ULL << i;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore while ((i < MAXENV) && (b != 0)) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore cenv = &compile_env[i];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (b & st->st_test_mask) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore *need = (st->st_need_mask & b) ? 1 : 0;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (cenv);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore b <<= 1;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore i++;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (NULL);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreconst char *
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreenv_name(struct compile_env *cenv)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (cenv->ce_name);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreconst char *
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreenv_lang(struct compile_env *cenv)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (cenv->ce_lang);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreconst char *
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreenv_defs(struct compile_env *cenv)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (cenv->ce_defs);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic void
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreshow_file(test_t t, const char *path)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore FILE *f;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *buf = NULL;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore size_t cap = 0;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int line = 1;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore f = fopen(path, "r");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (f == NULL) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_debugf(t, "fopen(%s): %s", path, strerror(errno));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_debugf(t, "----->> begin (%s) <<------", path);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore while (getline(&buf, &cap, f) >= 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) strtok(buf, "\r\n");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_debugf(t, "%d: %s", line, buf);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore line++;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_debugf(t, "----->> end (%s) <<------", path);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fclose(f);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic void
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorecleanup(void)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (ofile != NULL) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) unlink(ofile);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore free(ofile);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore ofile = NULL;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (lfile != NULL) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) unlink(lfile);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore free(lfile);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore lfile = NULL;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (cfile != NULL) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) unlink(cfile);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore free(cfile);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore cfile = NULL;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (efile != NULL) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) unlink(efile);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore free(efile);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore efile = NULL;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (dname) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) rmdir(dname);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore free(dname);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore dname = NULL;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorestatic int
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoremkworkdir(void)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char b[32];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *d;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore cleanup();
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) strlcpy(b, "/tmp/symbols_testXXXXXX", sizeof (b));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if ((d = mkdtemp(b)) == NULL) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore perror("mkdtemp");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore dname = mystrdup(d);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore myasprintf(&cfile, "%s/compile_test.c", d);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore myasprintf(&ofile, "%s/compile_test.o", d);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore myasprintf(&lfile, "%s/compile_test.log", d);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore myasprintf(&efile, "%s/compile_test.exe", d);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (0);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorevoid
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorefind_compiler(void)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_t t;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int i;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore FILE *cf;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore t = test_start("finding compiler");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if ((cf = fopen(cfile, "w+")) == NULL) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_failed(t, "Unable to open %s for write: %s", cfile,
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore strerror(errno));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fprintf(cf, "#include <stdio.h>\n");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fprintf(cf, "int main(int argc, char **argv) {\n");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fprintf(cf, "#if defined(__SUNPRO_C)\n");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fprintf(cf, "exit(51);\n");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fprintf(cf, "#elif defined(__GNUC__)\n");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fprintf(cf, "exit(52);\n");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fprintf(cf, "#else\n");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fprintf(cf, "exit(99)\n");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fprintf(cf, "#endif\n}\n");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fclose(cf);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (i = 0; compilers[i] != NULL; i++) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char cmd[256];
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int rv;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) snprintf(cmd, sizeof (cmd),
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore "%s %s %s -o %s >/dev/null 2>&1",
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore compilers[i], MFLAG, cfile, efile);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_debugf(t, "trying %s", cmd);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore rv = system(cmd);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_debugf(t, "result: %d", rv);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if ((rv < 0) || !WIFEXITED(rv) || WEXITSTATUS(rv) != 0)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore continue;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore rv = system(efile);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (rv >= 0 && WIFEXITED(rv)) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore rv = WEXITSTATUS(rv);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore } else {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore rv = -1;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore switch (rv) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore case 51: /* STUDIO */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_debugf(t, "Found Studio C");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore c89flags = "-Xc -errwarn=%all -v -xc99=%none " MFLAG;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore c99flags = "-Xc -errwarn=%all -v -xc99=%all " MFLAG;
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi c11flags = NULL;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (extra_debug) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_debugf(t, "c89flags: %s", c89flags);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_debugf(t, "c99flags: %s", c99flags);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_passed(t);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore break;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore case 52: /* GCC */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_debugf(t, "Found GNU C");
b599bd937c305a895426e8c412ca920ce7824850Robert Mustacchi c89flags = "-Wall -Werror -std=c89 -nostdinc "
b599bd937c305a895426e8c412ca920ce7824850Robert Mustacchi "-isystem /usr/include " MFLAG;
b599bd937c305a895426e8c412ca920ce7824850Robert Mustacchi c99flags = "-Wall -Werror -std=c99 -nostdinc "
b599bd937c305a895426e8c412ca920ce7824850Robert Mustacchi "-isystem /usr/include " MFLAG;
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi c11flags = "-Wall -Werror -std=c11 -nostdinc "
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi "-isystem /usr/include " MFLAG;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (extra_debug) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_debugf(t, "c89flags: %s", c89flags);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_debugf(t, "c99flags: %s", c99flags);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_passed(t);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore break;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore case 99:
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_debugf(t, "Found unknown (unsupported) compiler");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore continue;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore default:
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore continue;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore myasprintf(&compiler, "%s", compilers[i]);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_debugf(t, "compiler: %s", compiler);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_failed(t, "No compiler found.");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreint
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoredo_compile(test_t t, struct sym_test *st, struct compile_env *cenv, int need)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore char *cmd;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore FILE *logf;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore FILE *dotc;
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi const char *prog, *cflags, *lang;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore full_count++;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if ((dotc = fopen(cfile, "w+")) == NULL) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_failed(t, "fopen(%s): %s", cfile, strerror(errno));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore prog = sym_test_prog(st);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (fwrite(prog, 1, strlen(prog), dotc) < strlen(prog)) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_failed(t, "fwrite: %s", strerror(errno));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fclose(dotc);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (fclose(dotc) < 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_failed(t, "fclose: %s", strerror(errno));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) unlink(ofile);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi if (strcmp(env_lang(cenv), "c99") == 0) {
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi lang = "c99";
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi cflags = c99flags;
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi } else if (strcmp(env_lang(cenv), "c11") == 0) {
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi lang = "c11";
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi cflags = c11flags;
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi } else {
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi lang = "c89";
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi cflags = c89flags;
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi }
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi if (cflags == NULL) {
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi test_failed(t, "compiler %s does not support %s", compiler,
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi lang);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi return (-1);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi }
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore myasprintf(&cmd, "%s %s %s -c %s -o %s >>%s 2>&1",
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi compiler, cflags, env_defs(cenv), cfile, ofile, lfile);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (extra_debug) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_debugf(t, "command: %s", cmd);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if ((logf = fopen(lfile, "w+")) == NULL) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_failed(t, "fopen: %s", strerror(errno));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fprintf(logf, "===================\n");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fprintf(logf, "PROGRAM:\n%s\n", sym_test_prog(st));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fprintf(logf, "COMMAND: %s\n", cmd);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fprintf(logf, "EXPECT: %s\n", need ? "OK" : "FAIL");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fclose(logf);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore switch (system(cmd)) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore case -1:
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_failed(t, "error compiling in %s: %s", env_name(cenv),
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore strerror(errno));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore case 0:
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (!need) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore fail_count++;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore show_file(t, lfile);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_failed(t, "symbol visible in %s", env_name(cenv));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore break;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore default:
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (need) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore fail_count++;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore show_file(t, lfile);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_failed(t, "error compiling in %s", env_name(cenv));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (-1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore break;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore good_count++;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore return (0);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amorevoid
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoretest_compile(void)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore struct sym_test *st;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore struct compile_env *cenv;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_t t;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int need;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (st = next_sym_test(NULL); st; st = next_sym_test(st)) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if ((sym != NULL) && strcmp(sym, sym_test_name(st))) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore continue;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore /* XXX: we really want a sym_test_desc() */
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore for (cenv = sym_test_env(st, NULL, &need);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore cenv != NULL;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore cenv = sym_test_env(st, cenv, &need)) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore t = test_start("%s : %c%s", sym_test_name(st),
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore need ? '+' : '-', env_name(cenv));
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (do_compile(t, st, cenv, need) == 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_passed(t);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (full_count > 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_summary();
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoreint
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amoremain(int argc, char **argv)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore{
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int optc;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore int optC = 0;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore while ((optc = getopt(argc, argv, "DdfCs:c:")) != EOF) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore switch (optc) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore case 'd':
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_set_debug();
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore break;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore case 'f':
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_set_force();
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore break;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore case 'D':
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_set_debug();
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore extra_debug++;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore break;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore case 'c':
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore compilation = optarg;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore break;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore case 'C':
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore optC++;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore break;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore case 's':
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore sym = optarg;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore break;
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore default:
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore (void) fprintf(stderr, "Usage: %s [-df]\n", argv[0]);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore exit(1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (test_load_config(NULL, compilation,
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore "env", do_env, "env_group", do_env_group, NULL) < 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore exit(1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore while (optind < argc) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (test_load_config(NULL, argv[optind++],
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore "type", do_type,
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore "value", do_value,
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi "define", do_define,
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore "func", do_func,
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore NULL) < 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore exit(1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (atexit(cleanup) != 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore perror("atexit");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore exit(1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi if (custr_alloc(&st_custr) == -1) {
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi perror("custr");
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi exit(1);
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi }
fc2512cfb727d49529d8ed99164db871f4829b73Robert Mustacchi
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (mkworkdir() < 0) {
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore perror("mkdir");
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore exit(1);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore }
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore find_compiler();
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore if (!optC)
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore test_compile();
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore exit(0);
de572d98af8238405c5d1292a788b1a85b0c68ebGarrett D'Amore}